This commit is contained in:
yanran200730
2023-04-06 10:02:35 +08:00
2 changed files with 34 additions and 27 deletions

View File

@@ -3,9 +3,9 @@
<ai-title slot="title" :title="pageTitle" isShowBottomBorder isShowBack @back="back"/>
<template #content>
<el-form size="small" :model="form" label-width="80px" :rules="rules" ref="DataModelForm">
<ai-card title="主表实体">
<ai-card title="模型信息">
<div flex>
<el-form-item label="主表" prop="name" class="fill">
<el-form-item label="模型主体" prop="name" class="fill">
<ai-select v-model="form.name" :selectList="entries" placeholder="指定主表实体模型,更换主表会清空设计模型" filterable @select="initMainModel" :disabled="isEdit"/>
</el-form-item>
<el-form-item label="模型别名" prop="alias" class="fill mar-l16">
@@ -15,7 +15,7 @@
</ai-card>
<ai-card title="设计模型" panel>
<el-button slot="right" type="text" @click="fullscreen=true">全屏</el-button>
<el-form-item prop="json" label-width="0" class="diagram" :class="{fullscreen}">
<el-form-item prop="config" label-width="0" class="diagram" :class="{fullscreen}">
<div ref="DataModel" class="dataModel"/>
<div class="dndPanel pad-8">
<div class="iconfont iconxinxiguanli pad-h8" v-text="`表实体`" @mousedown="handleAddModel"/>
@@ -29,7 +29,7 @@
<el-form class="pad-h16" :model="current" ref="ModelSettingForm" size="small" label-position="top">
<template v-if="current.type=='model'">
<el-form-item label="实体名称">
<ai-select v-model="current.id" :selectList="entries" placeholder="请选择实体对象" filterable @select="changeModel"/>
<ai-select v-model="current.name" :selectList="entries" placeholder="请选择实体对象" filterable @select="changeModel"/>
</el-form-item>
<el-form-item label="实体属性">
<ai-table :tableData="current.props" :colConfigs="currentCols" :is-show-pagination="false" tableSize="small" height="70vh"/>
@@ -79,7 +79,7 @@ export default {
}
},
computed: {
isEdit: v => !!v.$route.query.name,
isEdit: v => !!v.$route.query.id,
pageTitle: v => v.isEdit ? "编辑数据关联模型" : "新增数据关联模型",
},
methods: {
@@ -90,12 +90,12 @@ export default {
},
getDetail() {
const {id} = this.$route.query
id && this.instance.post("/app/appdatamodelconfig/queryDetailById", null, {params: {id}}).then(res => {
id && this.instance.post("/app/appdatamodel/queryDetailById", null, {params: {id}}).then(res => {
if (res?.data) {
const json = JSON.parse(res.data.json)
this.form = {...res.data, json}
const config = JSON.parse(res.data.config || null)
this.form = {...res.data, config}
this.$load(this.diagram).then(() => {
this.diagram.render(json)
this.diagram.render(config)
this.diagram.focusOn({id: this.form.name})
})
}
@@ -103,9 +103,9 @@ export default {
},
submit() {
const jsonData = this.diagram.getGraphData()
this.form.relationNodes = jsonData.edges.map(e => e.properties)
this.form.configs = jsonData.edges.map(e => e.properties)
this.$refs.DataModelForm.validate()
.then(() => this.instance.post("/app/appdatamodelconfig/addOrUpdate", {...this.form, config: JSON.stringify(jsonData)}))
.then(() => this.instance.post("/app/appdatamodel/addOrUpdate", {...this.form, config: JSON.stringify(jsonData)}))
.then(res => {
if (res?.code == 0) {
this.$message.success("提交成功")
@@ -133,8 +133,13 @@ export default {
this.diagram.on('node:click', this.onNodeClick)
this.diagram.on('node:dnd-add', this.onNodeClick)
this.diagram.on('anchor:drop', ({edgeModel}) => {
const {sourceAnchorId, targetAnchorId, targetNodeId} = edgeModel
edgeModel.setProperties({joinField: targetAnchorId.split("@").at(-1), mainField: sourceAnchorId.split("@").at(-1), tableName: targetNodeId})
const {sourceAnchorId, sourceNodeId, targetAnchorId, targetNodeId} = edgeModel
edgeModel.setProperties({
relationField: targetAnchorId.split("@").at(-1),
idField: sourceAnchorId.split("@").at(-1),
relationTableName: targetNodeId,
tableName: sourceNodeId
})
})
this.diagram.render()
},
@@ -157,29 +162,30 @@ export default {
},
initMainModel(v) {
this.diagram.clearData()
if (!!v?.id) {
if (!!v?.tableName) {
this.getTableFields(v).then(list => {
this.diagram.addNode({
type: 'main',
x: 200,
y: 60,
id: v.id,
properties: {id: v.id, props: list}
id: v.tableName,
properties: {id: v.tableName, props: list}
})
this.diagram.focusOn({id: v.id})
this.diagram.focusOn({id: v.tableName})
})
}
},
changeModel(v) {
if (!!v?.id) {
this.current.name = v.id
if (!!v?.tableName) {
this.current.id = v.tableName
this.getTableFields(v).then((list = []) => this.current.props = list)
}
},
getEntries() {
this.instance.get("/app/v2/api-docs").then(res => {
if (res?.definitions) {
this.entries = Object.entries(res.definitions).filter(([id]) => id?.startsWith("App"))?.map(([id, e]) => ({...e, id, label: id})) || []
this.entries = Object.entries(res.definitions).filter(([id]) => id?.startsWith("App"))
?.map(([id, e]) => ({...e, id, label: id, tableName: id.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase()})) || []
}
})
},
@@ -223,7 +229,8 @@ export default {
.dataModel {
height: 100vh;
}
.dndPanel{
.dndPanel {
left: 16px;
top: 16px;
}

View File

@@ -39,28 +39,28 @@ export default {
total: 0,
tableData: [],
colConfigs: [
{label: "数据模型主表", prop: "tableName"},
{label: "关联表单", prop: "relationTables"},
{label: "数据模型主表", prop: "name"},
{label: "数据模型别名", prop: "alias"},
]
}
},
methods: {
getTableData() {
this.instance.post("/app/appdatamodelconfig/list", null, {
this.instance.post("/app/appdatamodel/list", null, {
params: {...this.page, ...this.search}
}).then(res => {
if (res?.data) {
this.tableData = res.data.records.map(e => ({...e, relationTables: e.relations.map(r => r.tableName)?.toString()}))
this.tableData = res.data.records
this.total = res.data.total
}
})
},
handleAdd(id) {
id && this.$router.push({hash: "#add", query: {id}})
this.$router.push({hash: "#add", query: {id}})
},
@confirm("是否要删除该模型?")
handleDelete(ids) {
this.instance.post("/app/appdatamodelconfig/delete", null, {
this.instance.post("/app/appdatamodel/delete", null, {
params: {ids}
}).then(res => {
if (res?.code == 0) {