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

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

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

Loading…
Cancel
Save