diff --git a/src/utils/api.js b/src/utils/api.js index e322202..9783b3a 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -163,6 +163,8 @@ export default { staticPreview: `${host}/data/data/staticPreview`, editTableName: `${host}/data/data/table/editTableName`, updateTableCommit: `${host}/data/data/updateTableCommit`, + getLevel: `${host}/data/category/getLevel`, + getAllTableInfoByCategoryId: `${host}/data/data/product/getAllTableInfoByCategoryId`, // 产品管理 deleteProduct: `${host}/data/data/product/delete`, @@ -171,6 +173,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/Framework.vue b/src/views/data/Framework.vue index 6ae93cb..a60879e 100644 --- a/src/views/data/Framework.vue +++ b/src/views/data/Framework.vue @@ -5,7 +5,7 @@
- + {{ node.label }} @@ -156,10 +156,9 @@ export default { data() { return { - typeList: [], defaultProps: { children: 'children', - label: 'label' + label: 'categoryName' }, defaultActive: [], added: false, @@ -195,11 +194,13 @@ export default { curComment: [], submited: false, names: [], - showNames: [], nameVisible: false, curRow: {}, headVisible: false, - editIndex: 0 + editIndex: 0, + node: [], + resolve: null, + curNode: {} }; }, watch: { @@ -210,37 +211,20 @@ export default { },500) } }, - mounted(){ - this.getType() - }, + mounted(){}, methods: { - getType(){ - this.$post(this.api.getTableByClassification).then(res => { - // 递归赋值,同时添加层级标识 - 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 +258,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 +267,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 +278,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 +292,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 +308,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 @@ -492,7 +484,7 @@ export default { data.map(n => { that.importTypeIndex++ n.realId = n.id - // 分类id跟表id可能是冲突,所以就加了个基数,后续再优化 + // 分类id跟表id可能会冲突,所以就加了个基数 n.id = String(that.importTypeIndex + n.id) n.label = n.categoryName if(n.children.length){ @@ -501,7 +493,7 @@ export default { }) } handleId(res) - this.$post(`${this.api.getIdQueryTable}?categoryId=${this.categoryId}&showName=${this.keyword}&pageNum=1&pageSize=10000&updateTime=${this.updateTime ? this.updateTime : ''}`).then(res1 => { + this.$post(`${this.api.getIdQueryTable}?categoryId=${this.categoryId}&showName=${this.keyword}&pageNum=1&pageSize=3000&updateTime=${this.updateTime ? this.updateTime : ''}`).then(res1 => { let list = res1.pageList.records this.defaultTypeChecked = list.map(n => n.copyId) const that = this @@ -562,74 +554,58 @@ export default { closeImport(){ this.$refs.typeTree.setCheckedKeys([]) this.names = [] - this.showNames = [] }, // 获取names和showNames,提交的时候需要 - getNames(){ - // 获取已经勾选的分类 - let list = this.$refs.typeTree.getCheckedNodes() + getNames(list){ + const categoryId = Number(this.categoryId) 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.originalListById}?categoryId=${n.realId}&pageNum=1&pageSize=10000`).then(res => { - let tableList = res.list.records - // 查询完1个,则数量-1 - getLen-- - tableList.map(n => { - // 如果是默认没有的表,则添加进去 - if(!this.defaultTypeChecked.includes(String(n.id))){ - this.names.push(n.name) - this.showNames.push(n.showName) - } - }) - // 清0后,才执行resolve - if(!getLen) resolve() - }).catch(res => {}) - }else if(n.name && !n.disabled && !this.names.includes(n.name)){ // 如果是表,并且不是存在于分类下了的表,并且没重复,则添加进去 - this.names.push(n.name) - this.showNames.push(n.showName) - if(!getLen) resolve() - } - }) + // 根据选择的分类id查询下面的表id + this.$get(`${this.api.getAllTableInfoByCategoryId}?categoryId=${list.join()}`).then(res => { + const list = res.tableInfo + list.map(e => { + delete e.id + e.categoryId = categoryId + }) + this.names = list + resolve() + }).catch(res => {}) }) }, confirmImport(){ if(this.submited) return false + const checked = this.$refs.typeTree.getCheckedNodes() // 勾选的数据 // 如果没有选择任何数据 - if(!this.$refs.typeTree.getCheckedNodes().length) return this.$message.warning('请选择数据') - this.getNames().then(() => { - let names = Array.from(new Set(this.names)) - let showNames = Array.from(new Set(this.showNames)) - if(!names.length) return this.$message.warning('请选择数据') - - this.submited = true - let data = [] - let categoryId = Number(this.categoryId) - names.map((n,i) => { - data.push({ - categoryId, - name: n, - showName: showNames[i], - }) + if(!checked.length) return this.$message.warning('请选择数据') + this.submited = true + const typeIds = checked.filter(e => !e.name).map(e => e.realId) // 先筛选出分类id,再获取分类真正的id + this.getNames(typeIds).then(() => { + const data = this.names + const dataList = [] + for (let i = 0, len = data.length; i < len; i += 2000) { + dataList.push(data.slice(i, i + 2000)) + } + const promiseList = [] + dataList.map(e => { + promiseList.push(new Promise((resolve,reject) => { + this.$post(this.api.saveTable, e).then(res => { + resolve() + }).catch(res => { + reject() + }) + })) }) - this.$post(this.api.saveTable,data).then(res => { + Promise.all(promiseList).then(res => { this.$message.success('导入成功') this.getData() this.importVisible = false setTimeout(() => { this.submited = false },1000) - }).catch(res => { + }).catch(err => { 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..d9cd532 100644 --- a/src/views/data/Product.vue +++ b/src/views/data/Product.vue @@ -80,9 +80,9 @@ 元/账号 - + 配置数据权限 -
+