完成表结构和联合查询的配置

master
面包骑士 2024-09-01 10:43:34 +08:00
parent 8434767a7a
commit 0a302cb1d9
5 changed files with 182 additions and 183 deletions

View File

@ -24,7 +24,7 @@
</div> </div>
<div align="center"> <div align="center">
<el-button @click="disp.findFlag = false">确认</el-button> <el-button @click="disp.findFlag = false">确认</el-button>
<el-button type="primary" @click="this.disp.updFlag = true">修改配置</el-button> <el-button type="primary" @click="disp.updFlag = true">修改配置</el-button>
</div> </div>
</div> </div>
</template> </template>
@ -57,11 +57,12 @@ export default {
computed: {}, computed: {},
// - 访this", // - 访this",
created() { created() {
this.init()
}, },
// ", // ",
methods: { methods: {
// , //
getInfo() { info() {
console.log(this.data) console.log(this.data)
console.log(this.node) console.log(this.node)
}, },

View File

@ -1,53 +1,26 @@
<template> <template>
<div @click="csh"> <div>
<div style="padding-left: 10px;padding-right: 10px;"> <el-row :gutter="10" class="mb8">
<el-form ref="queryForm" :inline="true" :model="queryParams" size="small"> <el-col :span="1.5">
<el-form-item label="数据库名称" prop="dbName"> <span v-if="reqDispData && reqDispData.dbTableName">:
<el-select v-model="queryParams.dbName" placeholder="请选择数据库" clearable @change="handleQuery"> <span v-for="item in reqDispData.dbTableName">{{ item }} &nbsp; &nbsp; </span>
<el-option v-for="item in dbNameOptions" :key="item" :label="item" :value="item"/> </span>
</el-select> <span v-else></span>
</el-form-item> </el-col>
<el-form-item label="表名称" prop="tableName"> </el-row>
<el-input <span>
v-model="queryParams.tableName" <el-table ref="table" :data="reqDispData.fields" height="300px"
clearable @row-click="clickRow" @selection-change="handleSelectionChange">
@change="handleQuery" <el-table-column type="selection" width="55" />
placeholder="请输入表名称" /> <el-table-column :show-overflow-tooltip="true" label="字段名称" prop="fieldName" />
</el-form-item> <el-table-column :show-overflow-tooltip="true" label="字段描述" prop="fieldComment" />
<el-form-item label="表描述" prop="tableComment"> <el-table-column :show-overflow-tooltip="true" label="字段类型" prop="fieldType" />
<el-input </el-table>
v-model="queryParams.tableComment" </span>
clearable <br><br>
@change="handleQuery" <div align="center">
placeholder="请输入表描述" /> <el-button type="primary" @click="toSelectResp"> </el-button>
</el-form-item> <el-button @click="disp.updFlag = false"> </el-button>
<el-form-item>
<el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery"></el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery"></el-button>
</el-form-item>
</el-form>
<el-table ref="table" :data="tableOptions" height="300px">
<el-table-column :show-overflow-tooltip="true" label="表名称" prop="tableName" />
<el-table-column :show-overflow-tooltip="true" label="表描述" prop="tableComment" />
<el-table-column label="操作" width="50px">
<template slot-scope="scope">
<el-button type="text" @click="selectTable(scope.row)"></el-button>
</template>
</el-table-column>
</el-table>
<el-divider content-position="left">选择字段 v</el-divider>
<el-table ref="table" :data="fieldsOptions" height="300px"
@row-click="clickRow" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column :show-overflow-tooltip="true" label="字段名称" prop="columnName" />
<el-table-column :show-overflow-tooltip="true" label="字段描述" prop="columnComment" />
<el-table-column :show-overflow-tooltip="true" label="字段类型" prop="columnType" />
</el-table>
<br><br>
<div align="center">
<el-button type="primary" @click="saveDisposition"> </el-button>
<el-button @click="disp.updFlag = false"> </el-button>
</div>
</div> </div>
</div> </div>
</template> </template>
@ -55,13 +28,14 @@
<script> <script>
// jsjsjson, // jsjsjson,
// import from ', // import from ',
import {listDbTableAll, selDbNameAll, selectDbTableColumnsByName} from "@/api/tool/gen"; import {listDisposition} from "@/api/quest/disposition";
import {batchAddUpd} from "@/api/quest/disposition";
export default { export default {
// import使" // import使"
name: 'tableUpd', name: 'exporUpd',
props: { props: {
data: {},
node: {},
disp: { disp: {
nodeCode: undefined, nodeCode: undefined,
nodeType: undefined, nodeType: undefined,
@ -71,120 +45,37 @@ export default {
db: {}, db: {},
fields: [] fields: []
} }
} },
}, },
data() { data() {
// " // "
return { return {
// //
dbNameOptions: [], preNodeId: [],
// //
tableOptions: [], preNodeDisp: [],
// //
fieldsOptions: [], selectDisp: [],
// //
tableList: [], reqDispData: {
queryParams: {} dbTableName: [],
fields: []
},
respDispData: {
dbTableName: [],
fields: []
}
} }
}, },
// data", // data",
computed: {}, computed: {},
// - 访this", // - 访this",
created() { created() {
this.init()
}, },
// ", // ",
methods: { methods: {
/** 搜索按钮操作 */
handleQuery() {
this.tableOptions = []
this.tableList.forEach(table => {
const params = this.queryParams
if ((table.dbName === params.dbName || !params.dbName) &&
(table.tableName.includes(params.tableName) || !params.tableName) &&
(table.tableComment.includes(params.tableComment) || !params.tableComment)){
this.tableOptions.push(table)
}
})
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/** 表字段查询*/
selectTable(row) {
this.disp.formData.db = row
selectDbTableColumnsByName(row.dbName, row.tableName).then(res => {
this.fieldsOptions = res.data
})
},
clickRow(row) {
this.$refs.table.toggleRowSelection(row);
},
//
handleSelectionChange(selection) {
this.disp.formData.fields = selection.map(item => {
return {
fieldName: item.columnName,
fieldType: item.columnType,
fieldComment: item.columnComment
};
});
},
//
selDbNameList() {
selDbNameAll().then(res => {
this.dbNameOptions = res.data
})
},
//
getListAll() {
listDbTableAll().then(res => {
this.tableList = res.data;
this.tableOptions = res.data;
});
},
// csh() {
// this.selDbNameList()
// this.getListAll()
// },
//
saveDisposition() {
const dispData = this.disp.formData
const dispList = this.getMysqlDisp(dispData.db,dispData.fields)
batchAddUpd(dispList, this.disp.nodeCode).then(res => {
this.$message.success(res.msg)
this.disp.updFlag = false
})
},
/** 类型转换 vue -> mysql*/
getMysqlDisp(db, fields) {
const dispList = []
dispList.push({
nodeCode: this.disp.nodeCode,
dispKey: 'db',
dispLabel: '数据库',
dispValue: db.dbName,
dispType: 'string'
},{
nodeCode: this.disp.nodeCode,
dispKey: 'table',
dispLabel: db.tableComment,
dispValue: db.tableName,
dispType: 'string'
})
fields.forEach(field => {
dispList.push({
nodeCode: this.disp.nodeCode,
dispKey: 'fields',
dispLabel: field.fieldComment,
dispValue: field.fieldName,
dispType: field.fieldType
})
})
return dispList;
},
} }
} }

View File

@ -16,7 +16,7 @@
<br><br> <br><br>
<div align="center"> <div align="center">
<el-button @click="disp.findFlag = false">确认</el-button> <el-button @click="disp.findFlag = false">确认</el-button>
<el-button type="primary" @click="this.disp.updFlag = true">修改配置</el-button> <el-button type="primary" @click="disp.updFlag = true">修改配置</el-button>
</div> </div>
</div> </div>
</template> </template>
@ -53,6 +53,9 @@ export default {
}, },
// ", // ",
methods: { methods: {
toUpd() {
this.disp.updFlag = true
}
} }
} }
</script> </script>

View File

@ -114,6 +114,7 @@ export default {
}, },
/** 表字段查询*/ /** 表字段查询*/
selectTable(row) { selectTable(row) {
this.disp.formData.fields = []
this.disp.formData.db = row this.disp.formData.db = row
selectDbTableColumnsByName(row.dbName, row.tableName).then(res => { selectDbTableColumnsByName(row.dbName, row.tableName).then(res => {
this.fieldsOptions = res.data this.fieldsOptions = res.data

View File

@ -15,27 +15,28 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="连接条件"> <el-form-item label="连接条件">
<el-select v-model="respDispData.joinData.form" placeholder="请选择一号表字段"> <el-select v-model="respDispData.joinData.form.fieldName" placeholder="请选择一号表字段">
<el-option v-for="item in reqDispData.fieldList[0]" :label="item.columnName+'('+item.columnComment+')'" :value="item.columnName" /> <el-option v-for="item in reqDispData.fields[0]" :label="item.tableName+'.'+item.fieldName+'('+item.fieldComment+')'" :value="item.fieldName" />
</el-select> </el-select>
&nbsp;&nbsp; &nbsp;&nbsp;
<el-select v-model="respDispData.joinData.to" placeholder="请选择二号表字段"> <el-select v-model="respDispData.joinData.to.fieldName" placeholder="请选择二号表字段">
<el-option v-for="item in reqDispData.fieldList[1]" :label="item.columnName+'('+item.columnComment+')'" :value="item.columnName" /> <el-option v-for="item in reqDispData.fields[1]" :label="item.tableName+'.'+item.fieldName+'('+item.fieldComment+')'" :value="item.fieldName" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button @click="disp.findFlag = false">返回</el-button> <el-button @click="disp.findFlag = false">返回</el-button>
<el-button type="primary" @click="checkFieldsFlag = true">下一步</el-button> <el-button type="primary" @click="checkFields"></el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
<el-dialog title="选择字段" :visible.sync="checkFieldsFlag" width="60%" append-to-body> <el-dialog title="选择字段" :visible.sync="checkFieldsFlag" width="70%" append-to-body>
<el-table ref="table" :data="reqDispData.fields" height="300px" <el-table ref="table" :data="reqDispData.fieldList" height="450px"
@row-click="clickRow" @selection-change="handleSelectionChange"> @row-click="clickRow" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" /> <el-table-column type="selection" width="55" />
<el-table-column :show-overflow-tooltip="true" label="字段名称" prop="columnName" /> <el-table-column :show-overflow-tooltip="true" label="字段名称" prop="fieldName" />
<el-table-column :show-overflow-tooltip="true" label="字段描述" prop="columnComment" /> <el-table-column :show-overflow-tooltip="true" label="字段描述" prop="fieldComment" />
<el-table-column :show-overflow-tooltip="true" label="字段类型" prop="columnType" /> <el-table-column :show-overflow-tooltip="true" label="字段类型" prop="fieldType" />
<el-table-column :show-overflow-tooltip="true" label="字段所属表" prop="tableName" />
</el-table> </el-table>
<br><br> <br><br>
<div align="center"> <div align="center">
@ -51,6 +52,7 @@
// import from ', // import from ',
import {listDisposition} from "@/api/quest/disposition"; import {listDisposition} from "@/api/quest/disposition";
import {selectDbTableColumnsByName} from "@/api/tool/gen"; import {selectDbTableColumnsByName} from "@/api/tool/gen";
import {batchAddUpd} from "@/api/quest/disposition";
export default { export default {
// import使" // import使"
@ -82,8 +84,8 @@ export default {
fields: [], fields: [],
join: '', join: '',
joinData: { joinData: {
form: '', form: {},
to: '' to: {}
} }
}, },
formData: {}, formData: {},
@ -135,19 +137,39 @@ export default {
this.respDispData.join = data.join this.respDispData.join = data.join
}else{ }else{
this.reqDispData.db.push(data.db) this.reqDispData.db.push(data.db)
this.respDispData.fields.push(data.fields) this.reqDispData.fields.push(data.fields)
selectDbTableColumnsByName(data.db.dbName,data.db.tableName).then(res => {
this.reqDispData.fieldList.push(res.data)
})
} }
}) })
}, },
//
checkFields() {
this.respDispData.db = this.reqDispData.db
this.reqDispData.fieldList = []
this.reqDispData.fieldList.push(...this.reqDispData.fields[0])
this.reqDispData.fieldList.push(...this.reqDispData.fields[1])
//
this.reqDispData.fields[0].forEach(field => {
if (this.respDispData.joinData.form.fieldName === field.fieldName){
this.respDispData.joinData.form = field
}
})
this.reqDispData.fields[1].forEach(field => {
if (this.respDispData.joinData.to.fieldName === field.fieldName){
this.respDispData.joinData.to = field
}
})
this.checkFieldsFlag = true
},
// //
save() { save() {
console.log('reqDispData',this.reqDispData) console.log('reqDispData',this.reqDispData)
console.log('respDispData',this.respDispData) console.log('respDispData',this.respDispData)
this.checkFieldsFlag = false const dispList = this.getMysqlDisp(this.respDispData)
this.disp.findFlag = false batchAddUpd(dispList, this.disp.nodeCode).then(res => {
this.$message.success(res.msg)
this.checkFieldsFlag = false
})
// this.disp.findFlag = false
}, },
clickRow(row) { clickRow(row) {
this.$refs.table.toggleRowSelection(row); this.$refs.table.toggleRowSelection(row);
@ -156,9 +178,11 @@ export default {
handleSelectionChange(selection) { handleSelectionChange(selection) {
this.respDispData.fields = selection.map(item => { this.respDispData.fields = selection.map(item => {
return { return {
fieldName: item.columnName, tableName: item.tableName,
fieldType: item.columnType, fieldName: item.fieldName,
fieldComment: item.columnComment fieldType: item.fieldType,
fieldComment: item.fieldComment,
fieldDesc: item.fieldDesc
}; };
}); });
}, },
@ -166,6 +190,7 @@ export default {
getVueDisp(dispList) { getVueDisp(dispList) {
const db = {} const db = {}
const fields = [] const fields = []
let tableName = ''
let join = '' let join = ''
let joinData = { let joinData = {
form: '', form: '',
@ -179,27 +204,105 @@ export default {
db.tableName = disp.dispValue db.tableName = disp.dispValue
db.tableComment = disp.dispLabel db.tableComment = disp.dispLabel
} }
tableName = db.dbName+'.'+db.tableName
db.dbTable = db.dbName+'.'+db.tableName+'('+db.tableComment +')'
if (disp.dispKey === 'fields') { if (disp.dispKey === 'fields') {
fields.push({ fields.push({
tableName: tableName,
fieldName: disp.dispValue, fieldName: disp.dispValue,
fieldType: disp.dispType, fieldType: disp.dispType,
fieldComment: disp.dispLabel fieldComment: disp.dispLabel,
fieldDesc: disp.fieldDesc
}) })
} }
db.dbTable = db.dbName+'.'+db.tableName+'('+db.tableComment +')'
if (disp.dispKey === 'joinDataForm') { if (disp.dispKey === 'joinDataForm') {
joinData.form = disp.dispValue joinData.form.push({
tableName: tableName,
fieldName: disp.dispValue,
fieldType: disp.dispType,
fieldComment: disp.dispLabel,
fieldDesc: disp.fieldDesc
})
} }
if (disp.dispKey === 'joinDataTo') { if (disp.dispKey === 'joinDataTo') {
joinData.to = disp.dispValue joinData.to.push({
tableName: tableName,
fieldName: disp.dispValue,
fieldType: disp.dispType,
fieldComment: disp.dispLabel,
fieldDesc: disp.fieldDesc
})
} }
if (disp.dispKey === 'join') { if (disp.dispKey === 'join') {
join = disp.dispValue join = disp.dispValue
return {db, fields, join, joinData}
} }
}) })
if (join !== '') {
return {db, fields, join, joinData}
}
return {db, fields} return {db, fields}
}, },
/** 节点配置--unite 类型转换 vue -> mysql*/
getMysqlDisp(resp) {
const db = resp.db
const fields = resp.fields
const join = resp.join
const form = resp.joinData.form
const to = resp.joinData.to
//
const dispList = []
//
db.forEach(item => {
dispList.push({
nodeCode: this.node.id, //
dispKey: 'db', //
dispLabel: item.tableComment, //
dispValue: item.dbName, //
dispType: 'string', //
dispDesc: item.dbTable //
})
})
//
fields.forEach(field => {
dispList.push({
nodeCode: this.node.id,
dispKey: 'fields',
dispLabel: field.fieldComment,
dispValue: field.fieldName,
dispType: field.fieldType,
dispDesc: field.tableName
})
})
//
dispList.push({
nodeCode: this.node.id,
dispKey: 'join',
dispLabel: join,
dispValue: join,
dispType: 'String',
dispDesc: ''
})
// 1
dispList.push({
nodeCode: this.node.id,
dispKey: 'joinDataForm',
dispLabel: form.fieldComment,
dispValue: form.fieldName,
dispType: form.fieldType,
dispDesc: form.tableName
})
// 2
dispList.push({
nodeCode: this.node.id,
dispKey: 'joinDataTo',
dispLabel: to.fieldComment,
dispValue: to.fieldName,
dispType: to.fieldType,
dispDesc: to.tableName
})
return dispList
}
} }
} }