feat(数据集): 关联数据集

This commit is contained in:
junjie 2021-11-30 15:19:51 +08:00
parent d19f0f2a24
commit c7aa73cdd0
7 changed files with 170 additions and 12 deletions

View File

@ -1161,7 +1161,9 @@ export default {
edit_union_relation: 'Edit Union Relation', edit_union_relation: 'Edit Union Relation',
add_union_relation: 'Add Union Relation', add_union_relation: 'Add Union Relation',
field_select: 'Select Field', 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 uniondo not union repeat'
}, },
datasource: { datasource: {
datasource: 'Data Source', datasource: 'Data Source',

View File

@ -1162,7 +1162,9 @@ export default {
edit_union_relation: '編輯關聯關系', edit_union_relation: '編輯關聯關系',
add_union_relation: '新建關聯關系', add_union_relation: '新建關聯關系',
field_select: '字段選擇', field_select: '字段選擇',
add_union_field: '添加關聯字段' add_union_field: '添加關聯字段',
union_error: '關聯關系與關聯字段不能為空',
union_repeat: '當前數據集已被關聯,請勿重復關聯'
}, },
datasource: { datasource: {
datasource: '數據源', datasource: '數據源',

View File

@ -1164,7 +1164,9 @@ export default {
edit_union_relation: '编辑关联关系', edit_union_relation: '编辑关联关系',
add_union_relation: '新建关联关系', add_union_relation: '新建关联关系',
field_select: '字段选择', field_select: '字段选择',
add_union_field: '添加关联字段' add_union_field: '添加关联字段',
union_error: '关联关系与关联字段不能为空',
union_repeat: '当前数据集已被关联,请勿重复关联'
}, },
datasource: { datasource: {
datasource: '数据源', datasource: '数据源',

View File

@ -8,7 +8,7 @@
<el-button size="mini" @click="cancel"> <el-button size="mini" @click="cancel">
{{ $t('dataset.cancel') }} {{ $t('dataset.cancel') }}
</el-button> </el-button>
<el-button size="mini" type="primary" @click="save"> <el-button :disabled="!name" size="mini" type="primary" @click="save">
{{ $t('dataset.confirm') }} {{ $t('dataset.confirm') }}
</el-button> </el-button>
</el-row> </el-row>
@ -17,7 +17,7 @@
<div> <div>
<el-form :inline="true"> <el-form :inline="true">
<el-form-item class="form-item"> <el-form-item class="form-item">
<el-input v-model="name" size="mini" :placeholder="$t('commons.name')" /> <el-input v-model="name" size="mini" :placeholder="$t('commons.name')" clearable />
</el-form-item> </el-form-item>
</el-form> </el-form>
<!--添加第一个数据集按钮--> <!--添加第一个数据集按钮-->
@ -78,6 +78,7 @@ import UnionNode from '@/views/dataset/add/union/UnionNode'
import NodeItem from '@/views/dataset/add/union/NodeItem' import NodeItem from '@/views/dataset/add/union/NodeItem'
import DatasetGroupSelectorTree from '@/views/dataset/common/DatasetGroupSelectorTree' import DatasetGroupSelectorTree from '@/views/dataset/common/DatasetGroupSelectorTree'
import UnionEdit from '@/views/dataset/add/union/UnionEdit' import UnionEdit from '@/views/dataset/add/union/UnionEdit'
import { getTable, post } from '@/api/dataset/dataset'
export default { export default {
name: 'AddUnion', name: 'AddUnion',
components: { UnionEdit, DatasetGroupSelectorTree, NodeItem, UnionNode }, components: { UnionEdit, DatasetGroupSelectorTree, NodeItem, UnionNode },
@ -126,7 +127,7 @@ export default {
}, },
allChildCount: 0 allChildCount: 0
}, },
name: '', name: '关联数据集',
customType: ['db', 'sql', 'excel'], customType: ['db', 'sql', 'excel'],
selectDsDialog: false, selectDsDialog: false,
// //
@ -135,11 +136,45 @@ export default {
unionParam: {} unionParam: {}
} }
}, },
watch: {
'param.tableId': function() {
this.initTableData()
}
},
mounted() { mounted() {
this.initTableData()
}, },
methods: { methods: {
save() { 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() { cancel() {
if (this.param.tableId) { if (this.param.tableId) {
@ -198,11 +233,46 @@ export default {
} }
}, },
confirmEditUnion() { 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) { cancelUnion(val) {
this.dataset = 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
})
}
} }
} }
} }

View File

@ -13,7 +13,7 @@
<el-button icon="el-icon-more" type="text" size="small" /> <el-button icon="el-icon-more" type="text" size="small" />
</span> </span>
<el-dropdown-menu slot="dropdown"> <el-dropdown-menu slot="dropdown">
<el-dropdown-item icon="el-icon-copy-document" :command="beforeNodeMenuClick('union',currentNode)"> <el-dropdown-item :disabled="currentNode.currentDs.mode === 0 && currentNode.currentDs.modelInnerType === 'sql'" icon="el-icon-copy-document" :command="beforeNodeMenuClick('union',currentNode)">
<span style="font-size: 12px;">{{ $t('dataset.union') }}</span> <span style="font-size: 12px;">{{ $t('dataset.union') }}</span>
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item icon="el-icon-edit-outline" :command="beforeNodeMenuClick('edit',currentNode)"> <el-dropdown-item icon="el-icon-edit-outline" :command="beforeNodeMenuClick('edit',currentNode)">
@ -29,7 +29,7 @@
<!--选择数据集--> <!--选择数据集-->
<el-dialog v-dialogDrag :title="$t('chart.select_dataset')" :visible="selectDsDialog" :show-close="false" width="360px" class="dialog-css" destroy-on-close> <el-dialog v-dialogDrag :title="$t('chart.select_dataset')" :visible="selectDsDialog" :show-close="false" width="360px" class="dialog-css" destroy-on-close>
<dataset-group-selector-tree :fix-height="true" show-mode="union" :custom-type="customType" @getTable="firstDs" /> <dataset-group-selector-tree :fix-height="true" show-mode="union" :custom-type="customType" :mode="currentNode.currentDs.mode" @getTable="firstDs" />
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button size="mini" @click="closeSelectDs()">{{ $t('dataset.cancel') }}</el-button> <el-button size="mini" @click="closeSelectDs()">{{ $t('dataset.cancel') }}</el-button>
<el-button :disabled="!tempDs.id" type="primary" size="mini" @click="confirmSelectDs()">{{ $t('dataset.confirm') }}</el-button> <el-button :disabled="!tempDs.id" type="primary" size="mini" @click="confirmSelectDs()">{{ $t('dataset.confirm') }}</el-button>
@ -127,6 +127,16 @@ export default {
}, },
selectDs() { selectDs() {
// node
if (this.currentNode.currentDs.mode === 1) {
this.customType = ['db', 'sql', 'excel']
} else if (this.currentNode.currentDs.mode === 0) {
if (this.currentNode.currentDs.modelInnerType === 'db') {
this.customType = ['db']
} else {
this.customType = []
}
}
this.selectDsDialog = true this.selectDsDialog = true
}, },
// //
@ -138,6 +148,27 @@ export default {
this.tempDs = {} this.tempDs = {}
}, },
confirmSelectDs() { confirmSelectDs() {
//
if (this.tempDs.mode === 0) {
if (this.tempDs.dataSourceId !== this.tempParentDs.currentDs.dataSourceId) {
this.$message({
type: 'error',
message: this.$t('dataset.can_not_union_diff_datasource'),
showClose: true
})
return
}
}
const arr = this.getAllDs()
if (arr.indexOf(this.tempDs.id) > -1) {
this.$message({
type: 'error',
message: this.$t('dataset.union_repeat'),
showClose: true
})
return
}
// check over
const ds = JSON.parse(JSON.stringify(this.unionItem)) const ds = JSON.parse(JSON.stringify(this.unionItem))
ds.currentDs = this.tempDs ds.currentDs = this.tempDs
this.tempParentDs.childrenDs.push(ds) this.tempParentDs.childrenDs.push(ds)
@ -163,6 +194,25 @@ export default {
}, },
confirmEditField() { confirmEditField() {
this.editField = false this.editField = false
},
getAllDs() {
const arr = []
for (let i = 0; i < this.originData.length; i++) {
arr.push(this.originData[0].currentDs.id)
if (this.originData[0].childrenDs && this.originData[0].childrenDs.length > 0) {
this.getDs(this.originData[0].childrenDs, arr)
}
}
return arr
},
getDs(dsList, arr) {
for (let i = 0; i < dsList.length; i++) {
arr.push(dsList[i].currentDs.id)
if (dsList[i].childrenDs && dsList[i].childrenDs.length > 0) {
this.getDs(dsList[i].childrenDs, arr)
}
}
} }
} }
} }

View File

@ -191,11 +191,37 @@ export default {
} }
}, },
confirmEditUnion() { confirmEditUnion() {
this.editUnion = false //
if (this.checkUnion()) {
this.editUnion = false
} else {
this.$message({
message: this.$t('dataset.union_error'),
type: 'error',
showClose: true
})
}
}, },
// //
cancelUnion(val) { cancelUnion(val) {
this.$emit('cancelUnionEdit', val) this.$emit('cancelUnionEdit', 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
} }
} }
} }

View File

@ -36,6 +36,9 @@
<el-button v-if="table.type ==='sql'" size="mini" @click="editSql"> <el-button v-if="table.type ==='sql'" size="mini" @click="editSql">
{{ $t('dataset.edit_sql') }} {{ $t('dataset.edit_sql') }}
</el-button> </el-button>
<el-button v-if="table.type ==='union'" size="mini" @click="editUnion">
{{ $t('dataset.edit_union') }}
</el-button>
<!-- <el-button size="mini" @click="edit">--> <!-- <el-button size="mini" @click="edit">-->
<!-- {{ $t('dataset.edit_field') }}--> <!-- {{ $t('dataset.edit_field') }}-->
<!-- </el-button>--> <!-- </el-button>-->
@ -168,6 +171,9 @@ export default {
editCustom() { editCustom() {
this.$emit('switchComponent', { name: 'AddCustom', param: { id: this.table.sceneId, tableId: this.table.id, table: this.table }}) this.$emit('switchComponent', { name: 'AddCustom', param: { id: this.table.sceneId, tableId: this.table.id, table: this.table }})
}, },
editUnion() {
this.$emit('switchComponent', { name: 'AddUnion', param: { id: this.table.sceneId, tableId: this.table.id, table: this.table }})
},
reSearch(val) { reSearch(val) {
this.tableViewRowForm = val.form this.tableViewRowForm = val.form