数据模型修改

This commit is contained in:
aixianling
2023-04-04 17:29:39 +08:00
parent 89c406d802
commit 0d309a158e
2 changed files with 20 additions and 14 deletions

View File

@@ -79,7 +79,7 @@ export default {
} }
}, },
computed: { computed: {
isEdit: v => !!v.$route.query.name, isEdit: v => !!v.$route.query.id,
pageTitle: v => v.isEdit ? "编辑数据关联模型" : "新增数据关联模型", pageTitle: v => v.isEdit ? "编辑数据关联模型" : "新增数据关联模型",
}, },
methods: { methods: {
@@ -90,9 +90,9 @@ export default {
}, },
getDetail() { getDetail() {
const {id} = this.$route.query 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) { if (res?.data) {
const json = JSON.parse(res.data.json) const json = JSON.parse(res.data.config || null)
this.form = {...res.data, json} this.form = {...res.data, json}
this.$load(this.diagram).then(() => { this.$load(this.diagram).then(() => {
this.diagram.render(json) this.diagram.render(json)
@@ -103,9 +103,9 @@ export default {
}, },
submit() { submit() {
const jsonData = this.diagram.getGraphData() 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() 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 => { .then(res => {
if (res?.code == 0) { if (res?.code == 0) {
this.$message.success("提交成功") this.$message.success("提交成功")
@@ -133,8 +133,13 @@ export default {
this.diagram.on('node:click', this.onNodeClick) this.diagram.on('node:click', this.onNodeClick)
this.diagram.on('node:dnd-add', this.onNodeClick) this.diagram.on('node:dnd-add', this.onNodeClick)
this.diagram.on('anchor:drop', ({edgeModel}) => { this.diagram.on('anchor:drop', ({edgeModel}) => {
const {sourceAnchorId, targetAnchorId, targetNodeId} = edgeModel const {sourceAnchorId, sourceNodeId, targetAnchorId, targetNodeId} = edgeModel
edgeModel.setProperties({joinField: targetAnchorId.split("@").at(-1), mainField: sourceAnchorId.split("@").at(-1), tableName: targetNodeId}) edgeModel.setProperties({
relationField: targetAnchorId.split("@").at(-1),
idField: sourceAnchorId.split("@").at(-1),
relationTableName: targetNodeId,
tableName: sourceNodeId
})
}) })
this.diagram.render() this.diagram.render()
}, },
@@ -223,7 +228,8 @@ export default {
.dataModel { .dataModel {
height: 100vh; height: 100vh;
} }
.dndPanel{
.dndPanel {
left: 16px; left: 16px;
top: 16px; top: 16px;
} }

View File

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