From 1fae5f0fab4ea8f6d25bb68d7a6c86a1574c9dcf Mon Sep 17 00:00:00 2001 From: yujialong <479214531@qq.com> Date: Tue, 23 Nov 2021 15:25:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=86=E7=B1=BB=E8=BF=98?= =?UTF-8?q?=E5=8E=9F=E6=88=90=E4=B8=80=E6=AC=A1=E8=8E=B7=E5=8F=96=E6=89=80?= =?UTF-8?q?=E6=9C=89=E5=88=86=E7=B1=BB=EF=BC=88=E5=AE=9E=E7=8E=B0=E4=BA=86?= =?UTF-8?q?=E6=97=A0=E9=99=90=E5=B1=82=E7=BA=A7=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/data/list/index.vue | 97 ++++++++++++++++------------------- 1 file changed, 45 insertions(+), 52 deletions(-) diff --git a/src/pages/data/list/index.vue b/src/pages/data/list/index.vue index 098782b..9e3a123 100644 --- a/src/pages/data/list/index.vue +++ b/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) { - // // 如果有子级,则递归取到最下面的第一级子级id,如果没有子级,则取当前id - // 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) { + // 如果有子级,则递归取到最下面的第一级子级id,如果没有子级,则取当前id + 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