From 1315f5489cab1264c70040b2fd222310c59f9d04 Mon Sep 17 00:00:00 2001 From: Jo <479214531@qq.com> Date: Sun, 21 Nov 2021 23:28:19 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E6=94=B9=E6=88=90=E6=87=92=E5=8A=A0=E8=BD=BD=EF=BC=88=E6=9C=AA?= =?UTF-8?q?=E5=AE=8C=E6=88=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/api.js | 1 + src/views/data/Framework.vue | 68 +++++++++--------- src/views/data/Introduce.vue | 56 +++++---------- src/views/data/Product.vue | 131 ++++++++++++++--------------------- 4 files changed, 103 insertions(+), 153 deletions(-) diff --git a/src/utils/api.js b/src/utils/api.js index e322202..ffc1e86 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -163,6 +163,7 @@ export default { staticPreview: `${host}/data/data/staticPreview`, editTableName: `${host}/data/data/table/editTableName`, updateTableCommit: `${host}/data/data/updateTableCommit`, + getLevel: `${host}/data/category/getLevel`, // 产品管理 deleteProduct: `${host}/data/data/product/delete`, diff --git a/src/views/data/Framework.vue b/src/views/data/Framework.vue index 6ae93cb..9dff693 100644 --- a/src/views/data/Framework.vue +++ b/src/views/data/Framework.vue @@ -5,7 +5,7 @@
- + {{ node.label }} @@ -70,7 +70,8 @@
{ - // 递归赋值,同时添加层级标识 - function handleId(data,level = 0){ - data.map(n => { - n.id = String(n.id) - n.label = n.categoryName - n.level = level + 1 - if(n.children.length){ - handleId(n.children,n.level) - } - }) - } - handleId(res) - - this.typeList = res - if (!this.added) { - if(res[0].children.length){ - this.categoryId = res[0].children[0].id - this.defaultActive = [res[0].children[0].id] - }else{ - this.categoryId = res[0].id - this.defaultActive = [res[0].id] - } - // 取第一个分类的id + getType(node, resolve){ + this.$post(`${this.api.getLevel}?parentId=${node.level ? node.data.id : 0}`).then(res => { + const list = res.list + this.node = node + this.resolve = resolve + resolve(list) + // 取第一个分类的id + if (!this.added && list.length) { + this.categoryId = list[0].id + this.defaultActive = [list[0].id] this.$nextTick(() => { - this.$refs.type.setCurrentKey(res[0].children[0].id) + this.$refs.type.setCurrentKey(list[0].id) }) } this.added = false @@ -274,6 +260,7 @@ export default { this.getData() }, addType(row){ + this.categoryId = row.data.id if (row) this.defaultActive = [row.data.id] this.typeVisible = true this.levelId = row ? row.data.id : 0 @@ -282,6 +269,8 @@ export default { this.typeVisible = true this.id = row.data.id this.categoryName = row.data.categoryName + this.curNode = row + this.categoryId = row.data.id }, delType(row){ // 该分类下的数据表已存在于产品管理中,是否确认删除? @@ -291,7 +280,7 @@ export default { this.added = true this.$post(`${this.api.deleteCategory}?categoryId=${row.data.id}`).then(res => { this.$message.success('删除成功') - this.getType() + this.$refs.type.remove(row) }).catch(res => {}) }).catch(() => {}) }, @@ -305,7 +294,9 @@ export default { categoryName: this.categoryName }).then(res => { this.$message.success('编辑成功') - this.getType() + this.curNode.data.categoryName = this.categoryName + this.$refs.type.updateKeyChildren(this.id, this.curNode) + this.getType(this.node, this.resolve) this.typeVisible = false setTimeout(() => { this.submited = false @@ -319,7 +310,10 @@ export default { categoryName: this.categoryName }).then(res => { this.$message.success('添加成功') - this.getType() + this.getType(this.node, this.resolve) + let node = this.$refs.type.getNode(this.categoryId) + node.loaded = false + node.expand() this.typeVisible = false setTimeout(() => { this.submited = false diff --git a/src/views/data/Introduce.vue b/src/views/data/Introduce.vue index 66e5f3d..45e9c05 100644 --- a/src/views/data/Introduce.vue +++ b/src/views/data/Introduce.vue @@ -2,7 +2,7 @@
- + @@ -56,10 +56,9 @@ export default { data() { return { - typeList: [], defaultProps: { children: 'children', - label: 'label' + label: 'categoryName' }, defaultActive: [], editing: false, @@ -69,7 +68,10 @@ export default { introduceText: '', categoryId: '', keywordList: [], - newKeyword: '' + newKeyword: '', + node: [], + resolve: null, + curNode: {} }; }, watch: { @@ -80,42 +82,22 @@ export default { },500) } }, - mounted(){ - this.getData() - }, + mounted(){}, methods: { - getData(){ + getData(node, resolve){ // 获取分类 - this.$post(this.api.getTableByClassification).then(res => { - // 递归处理id和label - function handleId(data){ - data.map(n => { - n.id = String(n.id) - n.label = n.categoryName - if(n.children.length){ - handleId(n.children) - } - }) - } - handleId(res) - - this.typeList = res + this.$post(`${this.api.getLevel}?parentId=${node.level ? node.data.id : 0}`).then(res => { + const list = res.list + this.node = node + this.resolve = resolve + resolve(list) // 取首个的id和简介 - if (!this.edited) { - if(res[0].children.length){ - let item = res[0].children[0] - this.categoryId = item.id - this.dataSource = res[0].children[0].dataSource - this.defaultActive = [item.id] - this.introduceText = item.introduce - this.introduce = item.introduce - }else{ - this.categoryId = res[0].id - this.dataSource = res[0].dataSource - this.defaultActive = [res[0].id] - this.introduceText = res[0].introduce - this.introduce = res[0].introduce - } + if (!this.edited && list.length) { + this.categoryId = list[0].id + this.dataSource = list[0].dataSource + this.defaultActive = [list[0].id] + this.introduceText = list[0].introduce + this.introduce = list[0].introduce } this.getKeyword() }).catch(res => {}) diff --git a/src/views/data/Product.vue b/src/views/data/Product.vue index 0838271..01b1523 100644 --- a/src/views/data/Product.vue +++ b/src/views/data/Product.vue @@ -81,14 +81,10 @@ - 配置数据权限 -
- - - {{ node.label }} - - -
+ 配置数据权限 + + +
@@ -100,7 +96,7 @@ - + {{ node.label }} @@ -185,7 +181,7 @@ export default { typeList: [], defaultProps: { children: 'children', - label: 'label' + label: 'categoryName' }, checkedIds: [], isDetail: false, @@ -203,7 +199,6 @@ export default { configIds: [], updateTime: '', keywordConfig: '', - typeConfigList: [], pageConfig: 1, pageSizeConfig: 10, totalConfig: 0, @@ -260,7 +255,7 @@ export default { this.getData() }, getTable(n,isConcat){ - this.$post(`${this.api.getIdQueryTable}?categoryId=${n.originId}&showName=&pageNum=${n.typePage}&pageSize=${this.typeUnit}&updateTime=`).then(res => { + this.$post(`${this.api.getIdQueryTable}?categoryId=${n.id}&showName=&pageNum=${n.typePage}&pageSize=${this.typeUnit}&updateTime=`).then(res => { let list = res.pageList.records list.map(n => { n.label = n.showName @@ -278,40 +273,25 @@ export default { }).catch(res => {}) }, // 获取分类 - getType(){ - this.productVisible = true - this.$post(this.api.getTableByClassification).then(res => { + getType(node, resolve){ + this.$post(`${this.api.getLevel}?parentId=${node.level ? node.data.id : 0}`).then(res => { const that = this - function handleId(data){ - data.map(n => { - n.originId = n.id - n.id = String(++that.typeIndex) - n.label = n.categoryName - n.disabled = true - if(n.children.length){ - handleId(n.children) - } - }) - } - handleId(res) - + const list = res.list + this.node = node + this.resolve = resolve + resolve(list) // 获取分类下的表 function getTable(data){ data.map(n => { - if(n.children.length){ + if(n.children && n.children.length){ getTable(n.children) }else{ n.typePage = 1 - n.disabled = true that.getTable(n) } }) } - getTable(res) - - setTimeout(() => { - this.typeList = res - },500) + getTable(list) this.importVisible = true }).catch(res => {}) }, @@ -382,17 +362,20 @@ export default { this.productName = data.productName this.market = data.market this.configChecked = data.tableId - this.checkedIds = this.handleType(data.tableId.split(','),this.typeList) - this.$refs.type.setCheckedNodes(this.checkedIds) + // this.checkedIds = this.handleType(data.tableId.split(','),this.typeList) + this.configIds = data.tableId.split(',') + console.log('getDetail', this.configIds) + // this.$refs.type.setCheckedNodes(this.checkedIds) }).catch(res => {}) }, add(){ - this.getType() + this.productVisible = true this.id = '' this.checkedIds = [] }, edit(row){ - this.getType() + this.productVisible = true + // this.getType() this.id = row.id this.userId = row.userId this.getDetail() @@ -416,7 +399,8 @@ export default { }, preview(row){ this.isDetail = true - this.getType() + this.productVisible = true + // this.getType() this.id = row.id this.getDetail() }, @@ -476,7 +460,7 @@ export default { list.map((n,i) => { 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 => { + this.$post(`${this.api.getIdQueryTable}?categoryId=${n.id}&showName=&pageNum=1&pageSize=10000&updateTime=`).then(res => { let tableList = res.pageList.records tableList.map(n => { this.tableId.push(String(n.id)) @@ -498,25 +482,26 @@ export default { if(!this.productName) return this.$message.warning('请输入数据产品名称') if(!this.market) return this.$message.warning('请输入市场价格') if(isNaN(this.market)) return this.$message.warning('市场价格请输入数字') - if(!this.$refs.type.getCheckedNodes().length) return this.$message.warning('请选择数据') + if(!this.checkedIds.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('请选择数据') + // this.getIds().then(() => { + // let tableId = Array.from(new Set(this.tableId)) + // if(!tableId.length) return this.$message.warning('请选择数据') + // return console.log(333, this.checkedIds) let data = { id: this.id, productName: this.productName, market: this.market, - tableId: tableId.join(), + tableId: this.checkedIds.join(), userId: this.userId, userName: this.userName, createTime: '', orderNum: '', status: '', - tableNum: tableId.length, - updateTime: '', + tableNum: this.checkedIds.length, + updateTime: '' } if(this.id){ this.$post(this.api.updateProduct,data).then(res => { @@ -537,19 +522,19 @@ export default { this.submited = false }) } - }) + // }) }, 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 + if (this.id) { + // let list = this.$refs.type.getCheckedNodes() + // let configIds = [] + // list.map(n => { + // if(!n.name) configIds.push(n.id) + // }) + // this.configIds = configIds + } }, typeConfigClick(data,node){ this.categoryId = data.id @@ -560,23 +545,12 @@ export default { this.$refs.typeConfig.setCheckedNodes([]) }, // 获取配置数据里面的分类 - getConfigType(){ - this.$post(this.api.getTableByClassification).then(res => { - function handleId(data){ - data.map(n => { - n.id = String(n.id) - n.label = n.categoryName - if(n.children.length){ - handleId(n.children) - } - }) - } - handleId(res) - this.typeConfigList = res - if(res[0].children.length){ - this.categoryId = res[0].children[0].id - }else{ - this.categoryId = res[0].id + getConfigType(node, resolve){ + this.$post(`${this.api.getLevel}?parentId=${node.level ? node.data.id : 0}`).then(res => { + const list = res.list + resolve(list) + if(list.length){ + this.categoryId = list[0].id } this.getConfigTable() }).catch(res => {}) @@ -626,7 +600,7 @@ export default { list.map(n => { if(n.children && n.children.length){ this.getTableId(n.children) - if(checked.includes(n.originId) && n.children[0].name){ + if(checked.includes(n.id) && n.children[0].name){ this.configCheckedTableId = [...this.configCheckedTableId,...n.children.map(n => n.id)] }else{ this.getTableId(n.children) @@ -635,11 +609,10 @@ export default { }) }, confirmConfig(){ - this.configChecked = this.$refs.typeConfig.getCheckedKeys().map(n => Number(n)) - this.getTableId(this.typeList) - this.checkedIds = Array.from(new Set(this.configCheckedTableId)) + this.checkedIds = this.$refs.typeConfig.getCheckedKeys().map(n => Number(n)) this.configVisible = false - this.$refs.type.setCheckedNodes(this.checkedIds) + console.log(22, this.$refs.typeConfig.getCheckedNodes()) + this.typeList = this.$refs.typeConfig.getCheckedNodes() } } }; From 79746ba66051d34eeddbe0f16c6a0497478927e8 Mon Sep 17 00:00:00 2001 From: Jo <479214531@qq.com> Date: Tue, 23 Nov 2021 07:28:16 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BA=A7=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/api.js | 1 + src/views/data/Product.vue | 172 +++++++++++++++++++++---------------- 2 files changed, 98 insertions(+), 75 deletions(-) diff --git a/src/utils/api.js b/src/utils/api.js index ffc1e86..761f3aa 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -172,6 +172,7 @@ export default { saveProduct: `${host}/data/data/product/save`, updateProduct: `${host}/data/data/product/update`, saveRecord: `${host}/data/data/dataRecord/saveRecord`, + getAllTableIdBycategoryId: `${host}/data/data/product/getAllTableIdBycategoryId`, // 关键词 addKeyword: `${host}/data/keyword/addKeyword`, diff --git a/src/views/data/Product.vue b/src/views/data/Product.vue index 01b1523..744a48f 100644 --- a/src/views/data/Product.vue +++ b/src/views/data/Product.vue @@ -81,10 +81,14 @@ - 配置数据权限 - - - + 配置数据权限 +
+ + + {{ node.label }} + + +
@@ -96,7 +100,7 @@ - + {{ node.label }} @@ -181,7 +185,7 @@ export default { typeList: [], defaultProps: { children: 'children', - label: 'categoryName' + label: 'label' }, checkedIds: [], isDetail: false, @@ -199,6 +203,7 @@ export default { configIds: [], updateTime: '', keywordConfig: '', + typeConfigList: [], pageConfig: 1, pageSizeConfig: 10, totalConfig: 0, @@ -255,7 +260,7 @@ export default { this.getData() }, getTable(n,isConcat){ - this.$post(`${this.api.getIdQueryTable}?categoryId=${n.id}&showName=&pageNum=${n.typePage}&pageSize=${this.typeUnit}&updateTime=`).then(res => { + this.$post(`${this.api.getIdQueryTable}?categoryId=${n.originId}&showName=&pageNum=${n.typePage}&pageSize=${this.typeUnit}&updateTime=`).then(res => { let list = res.pageList.records list.map(n => { n.label = n.showName @@ -273,25 +278,40 @@ export default { }).catch(res => {}) }, // 获取分类 - getType(node, resolve){ - this.$post(`${this.api.getLevel}?parentId=${node.level ? node.data.id : 0}`).then(res => { + getType(){ + this.productVisible = true + this.$post(this.api.getTableByClassification).then(res => { const that = this - const list = res.list - this.node = node - this.resolve = resolve - resolve(list) + function handleId(data){ + data.map(n => { + n.originId = n.id + n.id = String(++that.typeIndex) + n.label = n.categoryName + n.disabled = true + if(n.children.length){ + handleId(n.children) + } + }) + } + handleId(res) + // 获取分类下的表 function getTable(data){ data.map(n => { - if(n.children && n.children.length){ + if(n.children.length){ getTable(n.children) }else{ n.typePage = 1 + n.disabled = true that.getTable(n) } }) } - getTable(list) + getTable(res) + + setTimeout(() => { + this.typeList = res + },500) this.importVisible = true }).catch(res => {}) }, @@ -362,20 +382,17 @@ export default { this.productName = data.productName this.market = data.market this.configChecked = data.tableId - // this.checkedIds = this.handleType(data.tableId.split(','),this.typeList) - this.configIds = data.tableId.split(',') - console.log('getDetail', this.configIds) - // this.$refs.type.setCheckedNodes(this.checkedIds) + 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.productVisible = true - // this.getType() + this.getType() this.id = row.id this.userId = row.userId this.getDetail() @@ -399,8 +416,7 @@ export default { }, preview(row){ this.isDetail = true - this.productVisible = true - // this.getType() + this.getType() this.id = row.id this.getDetail() }, @@ -450,58 +466,47 @@ export default { // 获取tableId,提交的时候需要 getIds(){ // 获取已经勾选的分类 - 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) => { - if(n.tableLen && n.tableLen > n.children.length){ - // pageSize传10000是要查询全部表,后续如果数据多了,则按需调整 - this.$post(`${this.api.getIdQueryTable}?categoryId=${n.id}&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() - } - }) + let list = this.checkedIds + this.tableId = [] + const proList = [] + list.map(e => { + proList.push(new Promise((resolve,reject) => { + this.$get(`${this.api.getAllTableIdBycategoryId}?categoryId=${e}`).then(res => { + res.tableId && this.tableId.push(...res.tableId.split(',')) + resolve() + }).catch(res => { + this.submited = false + }) + })) }) + return Promise.all(proList).then(res => { + resolve() + }).catch(err => {}) }, confirm(){ 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.checkedIds.length) return this.$message.warning('请选择数据') + 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('请选择数据') - // return console.log(333, this.checkedIds) + this.getIds().then(() => { + let tableId = Array.from(new Set(this.tableId)) + if(!tableId.length) return this.$message.warning('请选择数据') let data = { id: this.id, productName: this.productName, market: this.market, - tableId: this.checkedIds.join(), + tableId: tableId.join(), userId: this.userId, userName: this.userName, createTime: '', orderNum: '', status: '', - tableNum: this.checkedIds.length, - updateTime: '' + tableNum: tableId.length, + updateTime: '', } if(this.id){ this.$post(this.api.updateProduct,data).then(res => { @@ -522,18 +527,19 @@ export default { this.submited = false }) } - // }) + }) }, configData(){ this.configVisible = true + this.getConfigType() if (this.id) { - // let list = this.$refs.type.getCheckedNodes() - // let configIds = [] - // list.map(n => { - // if(!n.name) configIds.push(n.id) - // }) - // this.configIds = configIds + let list = this.$refs.type.getCheckedNodes() + let configIds = [] + list.map(n => { + if(!n.name) configIds.push(n.originId) + }) + this.configIds = configIds } }, typeConfigClick(data,node){ @@ -545,12 +551,23 @@ export default { this.$refs.typeConfig.setCheckedNodes([]) }, // 获取配置数据里面的分类 - getConfigType(node, resolve){ - this.$post(`${this.api.getLevel}?parentId=${node.level ? node.data.id : 0}`).then(res => { - const list = res.list - resolve(list) - if(list.length){ - this.categoryId = list[0].id + getConfigType(){ + this.$post(this.api.getTableByClassification).then(res => { + function handleId(data){ + data.map(n => { + n.id = String(n.id) + n.label = n.categoryName + if(n.children.length){ + handleId(n.children) + } + }) + } + handleId(res) + this.typeConfigList = res + if(res[0].children.length){ + this.categoryId = res[0].children[0].id + }else{ + this.categoryId = res[0].id } this.getConfigTable() }).catch(res => {}) @@ -600,7 +617,7 @@ export default { list.map(n => { if(n.children && n.children.length){ this.getTableId(n.children) - if(checked.includes(n.id) && n.children[0].name){ + if(checked.includes(n.originId) && n.children[0].name){ this.configCheckedTableId = [...this.configCheckedTableId,...n.children.map(n => n.id)] }else{ this.getTableId(n.children) @@ -609,10 +626,15 @@ export default { }) }, confirmConfig(){ - this.checkedIds = this.$refs.typeConfig.getCheckedKeys().map(n => Number(n)) - this.configVisible = false - console.log(22, this.$refs.typeConfig.getCheckedNodes()) - this.typeList = this.$refs.typeConfig.getCheckedNodes() + this.configChecked = this.$refs.typeConfig.getCheckedKeys().map(n => n) + // this.getTableId(this.typeList) + this.checkedIds = this.configChecked + console.log(44, this.checkedIds, this.configChecked, this.typeList) + this.getIds().then(() => { + this.configVisible = false + console.log(33, this.tableId) + this.$refs.type.setCheckedNodes([...this.tableId, ...this.checkedIds]) + }) } } }; From f1ecd77ff699146f8eaf20a7cf2c31a9dadda06b Mon Sep 17 00:00:00 2001 From: yujialong <479214531@qq.com> Date: Tue, 23 Nov 2021 11:33:07 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BA=A7=E5=93=81=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=94=B9=E6=88=90=E4=BC=A0=E5=88=86=E7=B1=BB?= =?UTF-8?q?id=EF=BC=8C=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E5=85=A8?= =?UTF-8?q?=E9=83=A8tableId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/data/Product.vue | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/views/data/Product.vue b/src/views/data/Product.vue index 744a48f..7aef0fc 100644 --- a/src/views/data/Product.vue +++ b/src/views/data/Product.vue @@ -80,9 +80,10 @@ 元/账号 - + 配置数据权限 -
+ +