数据分类还原成一次获取所有分类(实现了无限层级)

dev
yujialong 3 years ago
parent 8adefc799e
commit 1fae5f0fab
  1. 97
      src/pages/data/list/index.vue

@ -194,11 +194,10 @@ export default {
}
},
methods: {
getType(id = 0) {
getType() {
//
this.$post(`${this.api.getLevel}?parentId=${id}`).then(res => {
const list = res.list
let typeId = this.typeId // id
this.$post(this.api.getTableByClassification).then(res => {
let typeId = this.typeId // id
let introduce = ''// children
let dataSource = '' //
let action
@ -217,25 +216,20 @@ export default {
if (i) isFirst = false
if (typeId && e.id == typeId) {// id
action = String(e.id)
if (e.children && e.children.length) {//
if (e.children.length) {//
if (!e.children[0].children.length) {//
action = String(e.children[0].id)
} else {//
action = String(e.children[0].children[0].id)
}
}
} else if (e.children && e.children.length) { // id
} else if (e.children.length) { // id
actionId(e.children)
}
})
}
if (id) {
this.typeList[0].children = list
} else {
this.typeList = list
}
console.log(11, this.typeList)
actionId(list)
this.typeList = res
actionId(res)
this.defaultType = action
this.introduce = introduce
this.dataSource = dataSource
@ -281,45 +275,44 @@ export default {
let introduce = ''
let dataSource = ''
this.keyword = ''
this.getType(index)
// let list = this.typeList
// let select = ''
// // id
// function getDeepest(data) {
// if (data[0].children && data[0].children.length) {
// getDeepest(data[0].children)
// } else {
// select = data[0].id
// if (data[0].introduce) introduce = data[0].introduce
// if (data[0].dataSource) dataSource = data[0].dataSource
// }
// }
// function handleData(data) {
// data.map((n, i) => {
// //
// if (n.id == index) {
// // idid
// if (n.children.length) {
// getDeepest(n.children)
// } else {
// select = index
// if (n.introduce) introduce = n.introduce
// if (n.dataSource) dataSource = n.dataSource
// }
// } else {
// handleData(n.children)
// }
// })
// }
// handleData(list)
// if (!introduce) introduce = list.find(n => n.id == indexPath[0]).introduce
// if (!dataSource) dataSource = list.find(n => n.id == indexPath[0]).dataSource
// this.defaultType = select
// this.introduce = introduce
// this.dataSource = dataSource
// this.previewHead = []
// this.previewData = []
// this.initData()
let list = this.typeList
let select = ''
// id
function getDeepest(data) {
if (data[0].children && data[0].children.length) {
getDeepest(data[0].children)
} else {
select = data[0].id
if (data[0].introduce) introduce = data[0].introduce
if (data[0].dataSource) dataSource = data[0].dataSource
}
}
function handleData(data) {
data.map((n, i) => {
//
if (n.id == index) {
// idid
if (n.children.length) {
getDeepest(n.children)
} else {
select = index
if (n.introduce) introduce = n.introduce
if (n.dataSource) dataSource = n.dataSource
}
} else {
handleData(n.children)
}
})
}
handleData(list)
if (!introduce) introduce = list.find(n => n.id == indexPath[0]).introduce
if (!dataSource) dataSource = list.find(n => n.id == indexPath[0]).dataSource
this.defaultType = select
this.introduce = introduce
this.dataSource = dataSource
this.previewHead = []
this.previewData = []
this.initData()
},
previewCurrentChange(val) {
this.currentRow = val

Loading…
Cancel
Save