数据架构导入

dev_2022-03-03
yujialong 3 years ago
commit fbb64f6dcf
  1. 179
      src/views/data/Framework.vue

@ -1,6 +1,7 @@
<template> <template>
<div class="wrap"> <div class="wrap">
<el-container> <el-container>
<!-- 左边的分类 -->
<el-aside width="300px"> <el-aside width="300px">
<div class="plus"> <div class="plus">
<i class="el-icon-circle-plus-outline" @click.stop="addType(0)"></i> <i class="el-icon-circle-plus-outline" @click.stop="addType(0)"></i>
@ -16,7 +17,7 @@
</span> </span>
</el-tree> </el-tree>
</el-aside> </el-aside>
<!-- 右边的表 -->
<el-main style="padding-top: 0"> <el-main style="padding-top: 0">
<el-card class="main-wrap" shadow="hover"> <el-card class="main-wrap" shadow="hover">
<el-form label-width="80px" class="flex-between mgb20"> <el-form label-width="80px" class="flex-between mgb20">
@ -64,7 +65,7 @@
</el-card> </el-card>
</el-main> </el-main>
</el-container> </el-container>
<!-- 导入数据 -->
<el-dialog title="导入" :visible.sync="importVisible" width="80%" center @close="closeImport" class="dialog" :close-on-click-modal="false"> <el-dialog title="导入" :visible.sync="importVisible" width="80%" center @close="closeImport" class="dialog" :close-on-click-modal="false">
<el-container style="padding: 20px 0 20px 20px;background-color: #f0f0f0;"> <el-container style="padding: 20px 0 20px 20px;background-color: #f0f0f0;">
<div style="overflow:auto;height: 558px;width:330px;padding:15px;background:#fff" ref="typeTreeWrap" @scroll="loadType"> <div style="overflow:auto;height: 558px;width:330px;padding:15px;background:#fff" ref="typeTreeWrap" @scroll="loadType">
@ -104,7 +105,7 @@
<el-button type="primary" :loading="submited" @click="confirmImport"> </el-button> <el-button type="primary" :loading="submited" @click="confirmImport"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
<!-- 新增编辑分类 -->
<el-dialog :title="id ? '编辑分类' : '新增分类'" :visible.sync="typeVisible" width="24%" center @close="closeType" :close-on-click-modal="false"> <el-dialog :title="id ? '编辑分类' : '新增分类'" :visible.sync="typeVisible" width="24%" center @close="closeType" :close-on-click-modal="false">
<el-input placeholder="请输入分类名称" v-model="categoryName"></el-input> <el-input placeholder="请输入分类名称" v-model="categoryName"></el-input>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
@ -112,14 +113,14 @@
<el-button type="primary" @click="confirmType"> </el-button> <el-button type="primary" @click="confirmType"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
<!-- 预览 -->
<el-dialog title="预览" :visible.sync="previewVisible" width="60%" center :close-on-click-modal="false"> <el-dialog title="预览" :visible.sync="previewVisible" width="60%" center :close-on-click-modal="false">
<el-table :data="previewData" class="table" stripe header-align="center" row-key="id"> <el-table :data="previewData" class="table" stripe header-align="center" row-key="id">
<el-table-column type="index" width="100" label="序号" align="center"></el-table-column> <el-table-column type="index" width="100" label="序号" align="center"></el-table-column>
<el-table-column v-for="(item,index) in previewHead" :prop="item.field" :key="index" :label="item.comment" align="center"></el-table-column> <el-table-column v-for="(item,index) in previewHead" :prop="item.field" :key="index" :label="item.comment" align="center"></el-table-column>
</el-table> </el-table>
</el-dialog> </el-dialog>
<!-- 编辑产品数据表名称 -->
<el-dialog title="编辑产品数据表名称" :visible.sync="nameVisible" width="24%" center :close-on-click-modal="false"> <el-dialog title="编辑产品数据表名称" :visible.sync="nameVisible" width="24%" center :close-on-click-modal="false">
<el-input placeholder="请输入产品数据表名称" v-model="curRow.showName"></el-input> <el-input placeholder="请输入产品数据表名称" v-model="curRow.showName"></el-input>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
@ -127,7 +128,7 @@
<el-button type="primary" @click="confirmName"> </el-button> <el-button type="primary" @click="confirmName"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
<!-- 自定义表头 -->
<el-dialog title="自定义表头" :visible.sync="headVisible" width="60%" center :close-on-click-modal="false"> <el-dialog title="自定义表头" :visible.sync="headVisible" width="60%" center :close-on-click-modal="false">
<el-table :data="previewData" class="table" stripe header-align="center" row-key="id" :key="editIndex"> <el-table :data="previewData" class="table" stripe header-align="center" row-key="id" :key="editIndex">
<el-table-column type="index" width="100" label="序号" align="center"> <el-table-column type="index" width="100" label="序号" align="center">
@ -162,7 +163,7 @@ export default {
label: 'label' label: 'label'
}, },
defaultActive: [], defaultActive: [],
added: false, addEd: false,
typeVisible: false, typeVisible: false,
categoryName: '', categoryName: '',
categoryId: '', categoryId: '',
@ -194,7 +195,7 @@ export default {
previewData: [], previewData: [],
curComment: [], curComment: [],
submited: false, submited: false,
names: [], categorys: [],
nameVisible: false, nameVisible: false,
curRow: {}, curRow: {},
headVisible: false, headVisible: false,
@ -216,6 +217,7 @@ export default {
this.getType() this.getType()
}, },
methods: { methods: {
//
getType(){ getType(){
this.$post(this.api.getTableByClassification).then(res => { this.$post(this.api.getTableByClassification).then(res => {
// , // ,
@ -230,29 +232,31 @@ export default {
}) })
} }
handleId(res) handleId(res)
this.typeList = res this.typeList = res
if (!this.added) { // addEd
if(res[0].children.length){ if (!this.addEd) {
if(res[0].children.length){ //
this.categoryId = res[0].children[0].id this.categoryId = res[0].children[0].id
this.defaultActive = [res[0].children[0].id] this.defaultActive = [res[0].children[0].id]
}else{ }else{
this.categoryId = res[0].id this.categoryId = res[0].id
this.defaultActive = [res[0].id] this.defaultActive = [res[0].id]
} }
// id //
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.type.setCurrentKey(res[0].children[0].id) this.$refs.type.setCurrentKey(this.categoryId)
}) })
} }
this.added = false this.addEd = false // false
this.getData() this.getData()
}).catch(res => {}) }).catch(res => {})
}, },
//
getData(){ getData(){
this.$post(`${this.api.getIdQueryTable}?categoryId=${this.categoryId}&showName=${this.keyword}&pageNum=${this.page}&pageSize=${this.pageSize}&updateTime=${this.updateTime ? this.updateTime : ''}`).then(res => { this.$post(`${this.api.getIdQueryTable}?categoryId=${this.categoryId}&showName=${this.keyword}&pageNum=${this.page}&pageSize=${this.pageSize}&updateTime=${this.updateTime ? this.updateTime : ''}`).then(res => {
const list = res.pageList.records const list = res.pageList.records
list.map(e => { list.map(e => {
//
const startTime = e.startTime ? e.startTime.slice(0, 10) : '' const startTime = e.startTime ? e.startTime.slice(0, 10) : ''
const endTime = e.endTime ? e.endTime.slice(0, 10) : '' const endTime = e.endTime ? e.endTime.slice(0, 10) : ''
if (startTime && endTime) { if (startTime && endTime) {
@ -267,40 +271,46 @@ export default {
this.total = res.pageList.total this.total = res.pageList.total
}).catch(res => {}) }).catch(res => {})
}, },
// 1
initData(){ initData(){
this.page = 1 this.page = 1
this.getData() this.getData()
}, },
//
typeClick(data,node){ typeClick(data,node){
this.categoryId = data.id this.categoryId = data.id
this.getData() this.getData()
}, },
//
addType(row){ addType(row){
if (row) this.defaultActive = [row.data.id] if (row) this.defaultActive = [row.data.id] // idrow0
this.typeVisible = true this.typeVisible = true
this.levelId = row ? row.data.id : 0 this.levelId = row ? row.data.id : 0 // levelIdidid0
}, },
//
editType(row){ editType(row){
this.typeVisible = true this.typeVisible = true
this.id = row.data.id this.id = row.data.id
this.categoryName = row.data.categoryName this.categoryName = row.data.categoryName
}, },
//
delType(row){ delType(row){
// //
this.$confirm('确定要删除吗?', '提示', { this.$confirm('确定要删除吗?', '提示', {
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.added = true this.addEd = true
this.$post(`${this.api.deleteCategory}?categoryId=${row.data.id}`).then(res => { this.$post(`${this.api.deleteCategory}?categoryId=${row.data.id}`).then(res => {
this.$message.success('删除成功') this.$message.success('删除成功')
this.getType() this.getType()
}).catch(res => {}) }).catch(res => {})
}).catch(() => {}) }).catch(() => {})
}, },
//
confirmType(){ confirmType(){
if(this.submited) return false if(this.submited) return false //
this.submited = true this.submited = true
this.added = true this.addEd = true
if(this.id){ if(this.id){
this.$post(this.api.updateCategory,{ this.$post(this.api.updateCategory,{
id: this.id, id: this.id,
@ -331,22 +341,30 @@ export default {
}) })
} }
}, },
//
closeType(){ closeType(){
this.id = 0 this.id = 0
this.levelId = 0 this.levelId = 0
this.categoryName = '' this.categoryName = ''
}, },
/**
* 表预览
* @param row 行数据
* @param isEdit 是否是从自定义表头进来的
*/
preview(row, isEdit){ preview(row, isEdit){
this.$get(`${this.api.previewData}?tableName=${row.name}&tableId=${row.id}`).then(res => { this.$get(`${this.api.previewData}?tableName=${row.name}&tableId=${row.id}`).then(res => {
let comment = res.comment let comment = res.comment
let previewHead = [] let previewHead = []
this.curComment = comment this.curComment = comment //
comment.map(n => { comment.map(n => {
// id
n.field != 'id' && n.field != 'operation_time' && previewHead.push(n) n.field != 'id' && n.field != 'operation_time' && previewHead.push(n)
}) })
this.previewHead = previewHead this.previewHead = previewHead
let data = res.data let data = res.data
// custom
isEdit && data.unshift({ isEdit && data.unshift({
custom: true custom: true
}) })
@ -357,9 +375,10 @@ export default {
} }
}) })
this.previewData = data this.previewData = data
if (!isEdit) this.previewVisible = true if (!isEdit) this.previewVisible = true //
}).catch(res => {}) }).catch(res => {})
}, },
//
delTable(row){ delTable(row){
this.$confirm('确定要删除吗?', '提示', { this.$confirm('确定要删除吗?', '提示', {
type: 'warning' type: 'warning'
@ -370,10 +389,12 @@ export default {
}).catch(res => {}) }).catch(res => {})
}).catch(() => {}) }).catch(() => {})
}, },
//
editName(row){ editName(row){
this.curRow = JSON.parse(JSON.stringify(row)) this.curRow = JSON.parse(JSON.stringify(row))
this.nameVisible = true this.nameVisible = true
}, },
//
confirmName(){ confirmName(){
this.$post(this.api.editTableName, { this.$post(this.api.editTableName, {
id: this.curRow.id, id: this.curRow.id,
@ -384,12 +405,14 @@ export default {
this.getData() this.getData()
}).catch(res => {}) }).catch(res => {})
}, },
//
editHead(row){ editHead(row){
this.curRow = JSON.parse(JSON.stringify(row)) this.curRow = JSON.parse(JSON.stringify(row))
this.preview(row, 1) this.preview(row, 1)
this.editIndex++ this.editIndex++ //
this.headVisible = true this.headVisible = true
}, },
//
confirmHead(){ confirmHead(){
let data = JSON.parse(JSON.stringify(this.curComment)) let data = JSON.parse(JSON.stringify(this.curComment))
this.$post(`${this.api.updateTableCommit}?tableName=${this.curRow.name}`, data).then(res => { this.$post(`${this.api.updateTableCommit}?tableName=${this.curRow.name}`, data).then(res => {
@ -487,9 +510,12 @@ export default {
n.typeTreePage++ n.typeTreePage++
}).catch(res => {}) }).catch(res => {})
}, },
//
batchImport(){ batchImport(){
//
this.$post(this.api.originalList).then(res => { this.$post(this.api.originalList).then(res => {
const that = this const that = this
// idlabelnamekeylabelnamekey
function handleId(data){ function handleId(data){
data.map(n => { data.map(n => {
that.importTypeIndex++ that.importTypeIndex++
@ -503,10 +529,12 @@ export default {
}) })
} }
handleId(res) handleId(res)
// pageSize3000
this.$post(`${this.api.getIdQueryTable}?categoryId=${this.categoryId}&showName=${this.keyword}&pageNum=1&pageSize=3000&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 let list = res1.pageList.records
this.defaultTypeChecked = list.map(n => n.copyId) this.defaultTypeChecked = list.map(n => n.copyId) // copyIdidid
const that = this const that = this
//
function handleId(data){ function handleId(data){
data.map(n => { data.map(n => {
if(n.children.length){ if(n.children.length){
@ -519,7 +547,17 @@ export default {
}) })
} }
handleId(res) handleId(res)
//
function handleDisabled (list) {
list.map(e => {
if (e.children && e.children.length) {
if (e.children.every(e => e.disabled)) e.disabled = true
handleDisabled(e.children)
}
})
}
setTimeout(() => { setTimeout(() => {
handleDisabled(res)
this.importTypeList = res this.importTypeList = res
},500) },500)
}).catch(res => {}) }).catch(res => {})
@ -527,6 +565,7 @@ export default {
this.importVisible = true this.importVisible = true
}).catch(res => {}) }).catch(res => {})
}, },
//
getFields(){ getFields(){
this.$get(`${this.api.staticPreview}?tableName=${this.tableName}`).then(res => { this.$get(`${this.api.staticPreview}?tableName=${this.tableName}`).then(res => {
let comment = res.comment let comment = res.comment
@ -548,6 +587,7 @@ export default {
}).catch(res => {}) }).catch(res => {})
this.importVisible = true this.importVisible = true
}, },
//
importTypeClick(data){ importTypeClick(data){
// ,, // ,,
if(data.name){ if(data.name){
@ -561,48 +601,74 @@ export default {
this.curExpand = obj.id this.curExpand = obj.id
this.renderChecked() this.renderChecked()
}, },
//
closeImport(){ closeImport(){
this.$refs.typeTree.setCheckedKeys([]) this.$refs.typeTree.setCheckedKeys([])
this.names = [] this.categorys = []
}, },
// namesshowNames, // id
getNames(list){ getNames(list){
const categoryId = Number(this.categoryId) const categoryId = Number(this.categoryId)
return new Promise((resolve,reject) => { return new Promise((resolve,reject) => {
// idid
this.$get(`${this.api.getAllTableInfoByCategoryId}?categoryId=${list.join()}`).then(res => { this.$get(`${this.api.getAllTableInfoByCategoryId}?categoryId=${list.join()}`).then(res => {
const list = res.tableInfo const list = res.tableInfo
list.map(e => { list.map(e => {
delete e.id delete e.id // id
e.categoryId = categoryId e.categoryId = categoryId
}) })
this.names = list this.categorys = list
resolve() resolve()
}).catch(res => {}) }).catch(res => {})
}) })
}, },
//
saveSuccess() {
this.$message.success('导入成功')
this.getData()
this.importVisible = false
setTimeout(() => {
this.submited = false
},1000)
},
//
confirmImport(){ confirmImport(){
if(this.submited) return false if(this.submited) return false //
const checked = this.$refs.typeTree.getCheckedNodes() // const checked = this.$refs.typeTree.getCheckedNodes().filter(e => !e.disabled) //
// //
if(!checked.length) return this.$message.warning('请选择数据') if(!checked.length) return this.$message.warning('请选择数据')
this.submited = true this.submited = true
const typeIds = checked.filter(e => !e.name).map(e => e.realId) // idid // ididid
const tableIds = checked.filter(e => e.name) const typeIds = checked.filter(e => !e.name).map(e => e.realId) // idnamenameididididrealIdid
const categoryId = Number(this.categoryId) const tableIds = checked.filter(e => e.name) //
const categoryId = Number(this.categoryId) //
// categoryId
tableIds.map(e => { tableIds.map(e => {
delete e.id delete e.id
e.categoryId = categoryId e.categoryId = categoryId
}) })
/**
* 根据某个值给数组对象去重
* @param arr 要处理的数组
* @param val 去重依据的值
*/
function uniq (arr, val) {
const res = new Map()
return arr.filter(e => !res.has(e[val]) && res.set(e[val], 1))
}
// ididid
if (typeIds.length) { if (typeIds.length) {
this.getNames(typeIds).then(() => { this.getNames(typeIds).then(() => {
const data = this.names const allIds = [...this.categorys, ...tableIds] // idid
const data = uniq(allIds, 'name')
const dataList = [] const dataList = []
// 2000
for (let i = 0, len = data.length; i < len; i += 2000) { for (let i = 0, len = data.length; i < len; i += 2000) {
dataList.push(data.slice(i, i + 2000)) dataList.push(data.slice(i, i + 2000))
} }
const promiseList = [] const promiseList = []
dataList.map(e => { // 2000item6item6item2000item6item6item2000666
if (dataList.length > 6) {
dataList.slice(0, 6).map(e => {
promiseList.push(new Promise((resolve,reject) => { promiseList.push(new Promise((resolve,reject) => {
this.$post(this.api.saveTable, e).then(res => { this.$post(this.api.saveTable, e).then(res => {
resolve() resolve()
@ -612,24 +678,43 @@ export default {
})) }))
}) })
Promise.all(promiseList).then(res => { Promise.all(promiseList).then(res => {
this.$message.success('导入成功') dataList.slice(6).map(e => {
this.getData() promiseList.push(new Promise((resolve,reject) => {
this.importVisible = false this.$post(this.api.saveTable, e).then(res => {
setTimeout(() => { resolve()
this.submited = false }).catch(res => {
},1000) reject()
})
}))
})
Promise.all(promiseList).then(res => {
this.saveSuccess()
}).catch(err => { }).catch(err => {
this.submited = false this.submited = false
}) })
}).catch(err => {
this.submited = false
}) })
} else { } else {
this.$post(this.api.saveTable, tableIds).then(res => { dataList.map(e => {
this.$message.success('导入成功') promiseList.push(new Promise((resolve,reject) => {
this.getData() this.$post(this.api.saveTable, e).then(res => {
this.importVisible = false resolve()
setTimeout(() => { }).catch(res => {
reject()
})
}))
})
Promise.all(promiseList).then(res => {
this.saveSuccess()
}).catch(err => {
this.submited = false this.submited = false
},1000) })
}
})
} else { //
this.$post(this.api.saveTable, tableIds).then(res => {
this.saveSuccess()
}).catch(res => { }).catch(res => {
this.submited = false this.submited = false
}) })

Loading…
Cancel
Save