From 65ff633cd4a3212033ba75bae314d2f960f957c0 Mon Sep 17 00:00:00 2001 From: e <2432808546@qq.com> Date: Fri, 22 Oct 2021 19:24:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A7=E5=93=81=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/data/Introduce.vue | 9 ++-- src/views/data/Product.vue | 98 ++++++++++++++++++++---------------- 2 files changed, 61 insertions(+), 46 deletions(-) diff --git a/src/views/data/Introduce.vue b/src/views/data/Introduce.vue index 1afe752..69571b0 100644 --- a/src/views/data/Introduce.vue +++ b/src/views/data/Introduce.vue @@ -22,7 +22,7 @@

数据源

- +
@@ -64,7 +64,7 @@ export default { defaultActive: [], editing: false, introduce: '', - source: '', + dataSource: '', introduceText: '', categoryId: '', keywordList: [], @@ -98,6 +98,7 @@ export default { this.typeList = res // 取首个的id和简介 + this.dataSource = res[0].dataSource if(res[0].children.length){ let item = res[0].children[0] this.categoryId = item.id @@ -118,6 +119,7 @@ export default { this.categoryId = data.id this.introduceText = data.introduce this.introduce = data.introduce + this.dataSource = data.dataSource this.getKeyword() }, getKeyword(){ @@ -134,7 +136,8 @@ export default { confirmEdit(){ this.$post(this.api.updateCategory,{ id: this.categoryId, - introduce: this.introduce + introduce: this.introduce, + dataSource: this.dataSource }).then(res => { this.$message.success(this.introduceText ? '编辑成功' : '新增成功') this.introduceText = this.introduce diff --git a/src/views/data/Product.vue b/src/views/data/Product.vue index 8f58281..4cf09ff 100644 --- a/src/views/data/Product.vue +++ b/src/views/data/Product.vue @@ -83,7 +83,7 @@ 配置数据权限
- + {{ node.label }} @@ -93,7 +93,7 @@ 取 消 - 确 定 + 确 定 @@ -211,7 +211,7 @@ export default { previewVisible: false, previewHead: [], previewData: [], - loading: false + submited: false, }; }, watch: { @@ -265,6 +265,7 @@ export default { list.map(n => { n.label = n.showName n.id = String(n.id) + n.disabled = true }) // 如果是懒加载的情况,则拼接 if(isConcat){ @@ -286,6 +287,7 @@ export default { n.originId = n.id n.id = String(++that.typeIndex) n.label = n.categoryName + n.disabled = true if(n.children.length){ handleId(n.children) } @@ -300,6 +302,7 @@ export default { getTable(n.children) }else{ n.typePage = 1 + n.disabled = true that.getTable(n) } }) @@ -307,6 +310,7 @@ export default { getTable(res) setTimeout(() => { + console.log(11, res) this.typeList = res },500) this.importVisible = true @@ -376,17 +380,20 @@ export default { }, getDetail(){ this.$post(`${this.api.findById}?id=${this.id}`).then(res => { - this.productVisible = true let data = res.product this.productName = data.productName this.market = data.market + this.checkedIds = this.handleType(data.tableId.split(','),this.typeList) + this.$refs.type.setCheckedNodes(this.checkedIds) }).catch(res => {}) }, add(){ - this.productVisible = true + this.getType() this.id = '' + this.checkedIds = [] }, edit(row){ + this.getType() this.id = row.id this.userId = row.userId this.getDetail() @@ -410,7 +417,7 @@ export default { }, preview(row){ this.isDetail = true - // this.getType() + this.getType() this.id = row.id this.getDetail() }, @@ -455,34 +462,46 @@ export default { this.typeIndex = 100000 this.typeList = [] this.tableId = [] - this.configIds = [] }, // 获取tableId,提交的时候需要 getIds(){ // 获取已经勾选的分类 - let list = this.configIds - let len = list.length + let list = this.$refs.type.getCheckedNodes() return new Promise((resolve,reject) => { + let getLen = 0 + list.map(n => { + // 如果tableLen大于子级的数量,则表示这个分类下的子级是没有全部加载出来的,要在下面去查询出来,这里先记载要查询的分类数量 + if(n.tableLen && n.tableLen > n.children.length) getLen++ + }) list.map((n,i) => { - this.$post(`${this.api.getIdQueryTable}?categoryId=${n}&showName=&pageNum=1&pageSize=10000&updateTime=`).then(res => { - res.pageList.records.map(n => { - this.tableId.push(String(n.id)) - }) - // 查询完1个,则数量-1 - len-- - // 清0后,才执行resolve - if(!len) resolve() - }).catch(res => {}) + if(n.tableLen && n.tableLen > n.children.length){ + // pageSize传10000是要查询全部表,后续如果数据多了,则按需调整 + this.$post(`${this.api.getIdQueryTable}?categoryId=${n.originId}&showName=&pageNum=1&pageSize=10000&updateTime=`).then(res => { + let tableList = res.pageList.records + tableList.map(n => { + this.tableId.push(String(n.id)) + }) + // 查询完1个,则数量-1 + getLen-- + // 清0后,才执行resolve + if(!getLen) resolve() + }).catch(res => {}) + }else if(n.name && !this.tableId.includes(n.id)){ // 如果是表,并且没重复,则添加进去 + this.tableId.push(n.id) + if(!getLen) resolve() + } }) }) }, confirm(){ - if(this.loading) return false + if(this.submited) return false if(!this.productName) return this.$message.warning('请输入数据产品名称') if(!this.market) return this.$message.warning('请输入市场价格') if(isNaN(this.market)) return this.$message.warning('市场价格请输入数字') - if(!this.configIds.length) return this.$message.warning('请选择数据') - this.loading = true + if(!this.$refs.type.getCheckedNodes().length) return this.$message.warning('请选择数据') + + this.submited = true + this.getIds().then(() => { let tableId = Array.from(new Set(this.tableId)) if(!tableId.length) return this.$message.warning('请选择数据') @@ -499,24 +518,23 @@ export default { tableNum: tableId.length, updateTime: '', } - this.$refs.typeConfig.setCheckedNodes([]) if(this.id){ this.$post(this.api.updateProduct,data).then(res => { this.$message.success('新增成功') this.productVisible = false this.getData() - this.loading = false + this.submited = false }).catch(res => { - this.loading = false + this.submited = false }) }else{ this.$post(this.api.saveProduct,data).then(res => { this.$message.success('新增成功') this.productVisible = false this.getData() - this.loading = false + this.submited = false }).catch(res => { - this.loading = false + this.submited = false }) } }) @@ -525,6 +543,13 @@ export default { configData(){ this.configVisible = true this.getConfigType() + + let list = this.$refs.type.getCheckedNodes() + let configIds = [] + list.map(n => { + if(!n.name) configIds.push(n.originId) + }) + this.configIds = configIds }, typeConfigClick(data,node){ this.categoryId = data.id @@ -610,24 +635,11 @@ export default { }) }, confirmConfig(){ - this.configIds = this.$refs.typeConfig.getCheckedKeys() - const list = this.$refs.typeConfig.getCheckedNodes() - function uniqData(e, i) { - e.children.map(n => { - const index = list.findIndex(e => e.id === n.id) - if (index) { - list.splice(index, 1) - } - if (n.children && n.children.length) { - uniqData(n, i) - } - }) - } - list.map((e, i) => { - uniqData(e, i) - }) - this.typeList = list + this.configChecked = this.$refs.typeConfig.getCheckedKeys().map(n => Number(n)) + this.getTableId(this.typeList) + this.checkedIds = Array.from(new Set(this.configCheckedTableId)) this.configVisible = false + this.$refs.type.setCheckedNodes(this.checkedIds) } } };