diff --git a/src/views/data/Framework.vue b/src/views/data/Framework.vue index a60879e..a984f0f 100644 --- a/src/views/data/Framework.vue +++ b/src/views/data/Framework.vue @@ -5,7 +5,7 @@
- + {{ node.label }} @@ -156,9 +156,10 @@ export default { data() { return { + typeList: [], defaultProps: { children: 'children', - label: 'categoryName' + label: 'label' }, defaultActive: [], added: false, @@ -211,20 +212,37 @@ export default { },500) } }, - mounted(){}, + mounted(){ + this.getType() + }, methods: { - 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] + 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 this.$nextTick(() => { - this.$refs.type.setCurrentKey(list[0].id) + this.$refs.type.setCurrentKey(res[0].children[0].id) }) } this.added = false @@ -258,7 +276,6 @@ 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 @@ -267,8 +284,6 @@ 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){ // 该分类下的数据表已存在于产品管理中,是否确认删除? @@ -278,7 +293,7 @@ export default { this.added = true this.$post(`${this.api.deleteCategory}?categoryId=${row.data.id}`).then(res => { this.$message.success('删除成功') - this.$refs.type.remove(row) + this.getType() }).catch(res => {}) }).catch(() => {}) }, @@ -292,9 +307,7 @@ export default { categoryName: this.categoryName }).then(res => { this.$message.success('编辑成功') - this.curNode.data.categoryName = this.categoryName - this.$refs.type.updateKeyChildren(this.id, this.curNode) - this.getType(this.node, this.resolve) + this.getType() this.typeVisible = false setTimeout(() => { this.submited = false @@ -308,10 +321,7 @@ export default { categoryName: this.categoryName }).then(res => { this.$message.success('添加成功') - this.getType(this.node, this.resolve) - let node = this.$refs.type.getNode(this.categoryId) - node.loaded = false - node.expand() + this.getType() this.typeVisible = false setTimeout(() => { this.submited = false @@ -578,33 +588,52 @@ export default { 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() - }) - })) + const tableIds = checked.filter(e => e.name) + const categoryId = Number(this.categoryId) + tableIds.map(e => { + delete e.id + e.categoryId = categoryId + }) + if (typeIds.length) { + 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() + }) + })) + }) + Promise.all(promiseList).then(res => { + this.$message.success('导入成功') + this.getData() + this.importVisible = false + setTimeout(() => { + this.submited = false + },1000) + }).catch(err => { + this.submited = false + }) }) - Promise.all(promiseList).then(res => { + } else { + this.$post(this.api.saveTable, tableIds).then(res => { this.$message.success('导入成功') this.getData() this.importVisible = false setTimeout(() => { this.submited = false },1000) - }).catch(err => { + }).catch(res => { this.submited = false }) - }) + } } } }; diff --git a/src/views/data/Introduce.vue b/src/views/data/Introduce.vue index 45e9c05..66e5f3d 100644 --- a/src/views/data/Introduce.vue +++ b/src/views/data/Introduce.vue @@ -2,7 +2,7 @@
- + @@ -56,9 +56,10 @@ export default { data() { return { + typeList: [], defaultProps: { children: 'children', - label: 'categoryName' + label: 'label' }, defaultActive: [], editing: false, @@ -68,10 +69,7 @@ export default { introduceText: '', categoryId: '', keywordList: [], - newKeyword: '', - node: [], - resolve: null, - curNode: {} + newKeyword: '' }; }, watch: { @@ -82,22 +80,42 @@ export default { },500) } }, - mounted(){}, + mounted(){ + this.getData() + }, methods: { - getData(node, resolve){ + getData(){ // 获取分类 - 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) + 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 // 取首个的id和简介 - 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 + 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 + } } this.getKeyword() }).catch(res => {}) diff --git a/src/views/data/Product.vue b/src/views/data/Product.vue index d9cd532..4730d41 100644 --- a/src/views/data/Product.vue +++ b/src/views/data/Product.vue @@ -82,7 +82,7 @@ 配置数据权限 -