From c7aa73cdd0cf9eb817ed2a2f796ef3a1c01d050f Mon Sep 17 00:00:00 2001 From: junjie Date: Tue, 30 Nov 2021 15:19:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=95=B0=E6=8D=AE=E9=9B=86):=20=E5=85=B3?= =?UTF-8?q?=E8=81=94=E6=95=B0=E6=8D=AE=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/lang/en.js | 4 +- frontend/src/lang/tw.js | 4 +- frontend/src/lang/zh.js | 4 +- frontend/src/views/dataset/add/AddUnion.vue | 82 +++++++++++++++++-- .../src/views/dataset/add/union/NodeItem.vue | 54 +++++++++++- .../src/views/dataset/add/union/UnionNode.vue | 28 ++++++- frontend/src/views/dataset/data/ViewTable.vue | 6 ++ 7 files changed, 170 insertions(+), 12 deletions(-) diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index 1287b31817..6fd1c23b63 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -1161,7 +1161,9 @@ export default { edit_union_relation: 'Edit Union Relation', add_union_relation: 'Add Union Relation', field_select: 'Select Field', - add_union_field: 'Add Union Field' + add_union_field: 'Add Union Field', + union_error: 'Union relation and field can not be empty', + union_repeat: 'This dataset is already union,do not union repeat' }, datasource: { datasource: 'Data Source', diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index 88c26ca89b..b0d44416c0 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -1162,7 +1162,9 @@ export default { edit_union_relation: '編輯關聯關系', add_union_relation: '新建關聯關系', field_select: '字段選擇', - add_union_field: '添加關聯字段' + add_union_field: '添加關聯字段', + union_error: '關聯關系與關聯字段不能為空', + union_repeat: '當前數據集已被關聯,請勿重復關聯' }, datasource: { datasource: '數據源', diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index 5ac145263c..13f643642d 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -1164,7 +1164,9 @@ export default { edit_union_relation: '编辑关联关系', add_union_relation: '新建关联关系', field_select: '字段选择', - add_union_field: '添加关联字段' + add_union_field: '添加关联字段', + union_error: '关联关系与关联字段不能为空', + union_repeat: '当前数据集已被关联,请勿重复关联' }, datasource: { datasource: '数据源', diff --git a/frontend/src/views/dataset/add/AddUnion.vue b/frontend/src/views/dataset/add/AddUnion.vue index 0308b798c5..60954cab02 100644 --- a/frontend/src/views/dataset/add/AddUnion.vue +++ b/frontend/src/views/dataset/add/AddUnion.vue @@ -8,7 +8,7 @@ {{ $t('dataset.cancel') }} - + {{ $t('dataset.confirm') }} @@ -17,7 +17,7 @@
- + @@ -78,6 +78,7 @@ import UnionNode from '@/views/dataset/add/union/UnionNode' import NodeItem from '@/views/dataset/add/union/NodeItem' import DatasetGroupSelectorTree from '@/views/dataset/common/DatasetGroupSelectorTree' import UnionEdit from '@/views/dataset/add/union/UnionEdit' +import { getTable, post } from '@/api/dataset/dataset' export default { name: 'AddUnion', components: { UnionEdit, DatasetGroupSelectorTree, NodeItem, UnionNode }, @@ -126,7 +127,7 @@ export default { }, allChildCount: 0 }, - name: '', + name: '关联数据集', customType: ['db', 'sql', 'excel'], selectDsDialog: false, // 弹框临时选中的数据集 @@ -135,11 +136,45 @@ export default { unionParam: {} } }, + watch: { + 'param.tableId': function() { + this.initTableData() + } + }, mounted() { + this.initTableData() }, methods: { save() { - + if (!this.name || this.name === '') { + this.$message({ + showClose: true, + message: this.$t('dataset.pls_input_name'), + type: 'error' + }) + return + } + if (this.name.length > 50) { + this.$message({ + showClose: true, + message: this.$t('dataset.char_can_not_more_50'), + type: 'error' + }) + return + } + const table = { + id: this.param.tableId, + name: this.name, + sceneId: this.param.id, + dataSourceId: this.dataset[0].currentDs.dataSourceId, + type: 'union', + mode: this.dataset[0].currentDs.mode, + info: '{"list":' + JSON.stringify(this.dataset) + '}' + } + post('/dataset/table/update', table).then(response => { + this.$emit('saveSuccess', table) + this.cancel() + }) }, cancel() { if (this.param.tableId) { @@ -198,11 +233,46 @@ export default { } }, confirmEditUnion() { - // todo 校验关联关系与字段,必填 - this.editUnion = false + // 校验关联关系与字段,必填 + if (this.checkUnion()) { + this.editUnion = false + } else { + this.$message({ + message: this.$t('dataset.union_error'), + type: 'error', + showClose: true + }) + } }, cancelUnion(val) { this.dataset = val + }, + + checkUnion() { + const union = this.unionParam.node.unionToParent + if (!union.unionType) { + return false + } + if (!union.unionFields || union.unionFields.length < 1) { + return false + } + for (let i = 0; i < union.unionFields.length; i++) { + const ele = union.unionFields[i] + if (!ele.parentField || !ele.parentField.id || !ele.currentField || !ele.currentField.id) { + return false + } + } + return true + }, + + initTableData() { + if (this.param.tableId) { + getTable(this.param.tableId).then(response => { + const table = JSON.parse(JSON.stringify(response.data)) + this.name = table.name + this.dataset = JSON.parse(table.info).list + }) + } } } } diff --git a/frontend/src/views/dataset/add/union/NodeItem.vue b/frontend/src/views/dataset/add/union/NodeItem.vue index 753aa4465e..bd96645d46 100644 --- a/frontend/src/views/dataset/add/union/NodeItem.vue +++ b/frontend/src/views/dataset/add/union/NodeItem.vue @@ -13,7 +13,7 @@ - + {{ $t('dataset.union') }} @@ -29,7 +29,7 @@ - +