|
|
|
@ -5,7 +5,7 @@ |
|
|
|
|
<div class="plus"> |
|
|
|
|
<i class="el-icon-circle-plus-outline" @click.stop="addType(0)"></i> |
|
|
|
|
</div> |
|
|
|
|
<el-tree ref="type" :data="typeList" node-key="id" accordion :default-expanded-keys="defaultActive" :current-node-key="categoryId" :props="defaultProps" :highlight-current="true" @current-change="typeClick"> |
|
|
|
|
<el-tree ref="type" :load="getType" lazy node-key="id" accordion :default-expanded-keys="defaultActive" :current-node-key="categoryId" :props="defaultProps" :highlight-current="true" @current-change="typeClick"> |
|
|
|
|
<span class="custom-tree-node" slot-scope="{ node, data }"> |
|
|
|
|
<span :title="node.label">{{ node.label }}</span> |
|
|
|
|
<span class="actions"> |
|
|
|
@ -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 |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
</script> |
|
|
|
|