2022-09-08 18:02:12 +08:00
|
|
|
<template>
|
2022-09-19 16:13:39 +08:00
|
|
|
<div class="de-dataset-form">
|
|
|
|
<div class="top" v-if="table.id && !createDataset">
|
|
|
|
<span class="name">
|
|
|
|
<i @click="back" class="el-icon-arrow-left"></i>
|
|
|
|
<svg-icon
|
|
|
|
style="margin: 0 9.5px 0 16.2px"
|
|
|
|
:icon-class="`de-${datasetType}-new`"
|
|
|
|
/>
|
|
|
|
<template v-if="showInput">
|
|
|
|
<el-input @blur="nameBlur" v-model="table.name"></el-input>
|
2022-09-19 17:51:06 +08:00
|
|
|
<div v-if="nameExsit" style="left: 55px" class="el-form-item__error">
|
|
|
|
{{ $t('deDataset.already_exists') }}
|
|
|
|
</div>
|
2022-09-19 16:13:39 +08:00
|
|
|
</template>
|
|
|
|
<span
|
|
|
|
:class="[{ 'show-point': ['sql', 'union'].includes(datasetType) }]"
|
|
|
|
v-else
|
|
|
|
@click="handleClick"
|
|
|
|
>{{ datasetName }}</span
|
|
|
|
>
|
|
|
|
</span>
|
|
|
|
<span class="oprate">
|
|
|
|
<span
|
|
|
|
class="table-num"
|
|
|
|
v-if="['db', 'excel', 'api'].includes(datasetType)"
|
2022-09-19 17:51:06 +08:00
|
|
|
>{{ $t('deDataset.selected') }} {{ tableNum }}
|
2022-09-20 15:56:02 +08:00
|
|
|
{{ $t('deDataset.table') }}</span
|
2022-09-19 16:13:39 +08:00
|
|
|
>
|
2022-09-19 17:51:06 +08:00
|
|
|
<deBtn @click="datasetSave" type="primary">{{
|
|
|
|
$t('commons.save')
|
|
|
|
}}</deBtn>
|
2022-09-19 16:13:39 +08:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div class="container">
|
|
|
|
<component
|
|
|
|
@setTableNum="(val) => (tableNum = val)"
|
|
|
|
v-if="table.name || !createDataset"
|
|
|
|
:param="table"
|
|
|
|
:is="component"
|
|
|
|
ref="addDataset"
|
|
|
|
:nameList="nameList"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<el-dialog
|
|
|
|
:title="dialogTitle"
|
|
|
|
class="de-dialog-form"
|
|
|
|
:visible.sync="createDataset"
|
|
|
|
width="600px"
|
|
|
|
v-loading="loading"
|
|
|
|
:before-close="beforeClose"
|
|
|
|
>
|
|
|
|
<el-form
|
|
|
|
ref="datasetForm"
|
|
|
|
class="de-form-item"
|
|
|
|
:model="datasetForm"
|
|
|
|
:rules="datasetFormRules"
|
|
|
|
>
|
|
|
|
<el-form-item
|
|
|
|
v-if="datasetFormRules.name"
|
|
|
|
:label="$t('dataset.name')"
|
|
|
|
prop="name"
|
|
|
|
>
|
|
|
|
<el-input v-model="datasetForm.name" />
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item :label="$t('deDataset.folder')" prop="id">
|
|
|
|
<el-popover
|
|
|
|
placement="bottom"
|
|
|
|
popper-class="user-popper dataset-filed"
|
|
|
|
width="552"
|
|
|
|
trigger="click"
|
|
|
|
>
|
|
|
|
<el-tree
|
|
|
|
:data="tData"
|
|
|
|
ref="tree"
|
|
|
|
node-key="id"
|
|
|
|
class="de-tree"
|
|
|
|
:expand-on-click-node="false"
|
|
|
|
highlight-current
|
|
|
|
:filter-node-method="filterNode"
|
|
|
|
@node-click="nodeClick"
|
|
|
|
>
|
|
|
|
<span slot-scope="{ data }" class="custom-tree-node-dataset">
|
|
|
|
<span v-if="data.type === 'group'">
|
|
|
|
<svg-icon icon-class="scene" class="ds-icon-scene" />
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
style="
|
|
|
|
margin-left: 6px;
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
"
|
|
|
|
:title="data.name"
|
|
|
|
>{{ data.name }}</span
|
|
|
|
>
|
|
|
|
</span>
|
|
|
|
</el-tree>
|
|
|
|
<el-select
|
|
|
|
v-model="datasetForm.id"
|
|
|
|
slot="reference"
|
|
|
|
filterable
|
|
|
|
popper-class="tree-select-dataset"
|
|
|
|
style="width: 100%"
|
|
|
|
:filter-method="filterMethod"
|
|
|
|
:placeholder="$t('commons.please_select')"
|
|
|
|
>
|
|
|
|
<el-option
|
|
|
|
v-for="item in selectDatasets"
|
|
|
|
:key="item.label"
|
|
|
|
:label="item.label"
|
|
|
|
:value="item.id"
|
|
|
|
/>
|
|
|
|
</el-select>
|
|
|
|
</el-popover>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
<div slot="footer" class="dialog-footer">
|
2022-09-19 17:51:06 +08:00
|
|
|
<deBtn secondary @click="close">{{ $t('dataset.cancel') }}</deBtn>
|
2022-09-19 16:13:39 +08:00
|
|
|
<deBtn type="primary" @click="saveDataset"
|
2022-09-19 17:51:06 +08:00
|
|
|
>{{ $t('dataset.confirm') }}
|
2022-09-19 16:13:39 +08:00
|
|
|
</deBtn>
|
|
|
|
</div>
|
|
|
|
</el-dialog>
|
|
|
|
</div>
|
2022-09-08 18:02:12 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-09-19 17:51:06 +08:00
|
|
|
import AddDB from './add/AddDB'
|
|
|
|
import AddApi from './add/AddApi'
|
|
|
|
import AddSQL from './add/AddSQL'
|
|
|
|
import AddExcel from './add/AddExcel'
|
|
|
|
import AddUnion from '@/views/dataset/add/AddUnion'
|
|
|
|
import { post } from '@/api/dataset/dataset'
|
|
|
|
import { groupTree } from '@/api/dataset/dataset'
|
2022-09-08 18:02:12 +08:00
|
|
|
export default {
|
2022-09-19 17:51:06 +08:00
|
|
|
name: 'DatasetForm',
|
2022-09-19 16:13:39 +08:00
|
|
|
components: { AddDB, AddSQL, AddExcel, AddApi, AddUnion },
|
2022-09-08 18:02:12 +08:00
|
|
|
data() {
|
|
|
|
return {
|
2022-09-19 17:51:06 +08:00
|
|
|
sceneId: '',
|
|
|
|
originName: '',
|
2022-09-19 16:13:39 +08:00
|
|
|
tableNum: 0,
|
|
|
|
showInput: false,
|
2022-09-19 17:51:06 +08:00
|
|
|
editType: '',
|
2022-09-19 16:13:39 +08:00
|
|
|
loading: false,
|
|
|
|
selectDatasets: [],
|
|
|
|
tData: [],
|
2022-09-19 17:51:06 +08:00
|
|
|
filterText: '',
|
|
|
|
dialogTitle: '',
|
2022-09-19 16:13:39 +08:00
|
|
|
createDataset: false,
|
2022-09-19 17:51:06 +08:00
|
|
|
datasetType: '',
|
|
|
|
component: '',
|
2022-09-19 16:13:39 +08:00
|
|
|
table: {},
|
|
|
|
nameExsit: false,
|
|
|
|
nameList: [],
|
|
|
|
datasetForm: {
|
2022-09-19 17:51:06 +08:00
|
|
|
id: '',
|
|
|
|
name: '',
|
|
|
|
sceneName: ''
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
datasetFormRules: {
|
|
|
|
name: [
|
|
|
|
{
|
|
|
|
required: true,
|
2022-09-19 17:51:06 +08:00
|
|
|
message: this.$t('commons.input_content'),
|
|
|
|
trigger: 'change'
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
max: 50,
|
2022-09-19 17:51:06 +08:00
|
|
|
message: this.$t('commons.char_can_not_more_50'),
|
|
|
|
trigger: 'change'
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
2022-09-19 17:51:06 +08:00
|
|
|
{ required: true, trigger: 'blur', validator: this.nameValidator }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
datasetName() {
|
|
|
|
if (+this.editType === 0) {
|
2022-09-19 17:51:06 +08:00
|
|
|
return this.$t('dataset.excel_replace') + this.$t('chart.chart_data')
|
2022-09-19 16:13:39 +08:00
|
|
|
}
|
2022-09-08 18:02:12 +08:00
|
|
|
|
2022-09-19 16:13:39 +08:00
|
|
|
if (+this.editType === 1) {
|
2022-09-19 17:51:06 +08:00
|
|
|
return this.$t('dataset.excel_add') + this.$t('chart.chart_data')
|
2022-09-19 16:13:39 +08:00
|
|
|
}
|
2022-09-19 17:51:06 +08:00
|
|
|
return this.table.name || this.dialogTitle
|
|
|
|
}
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
created() {
|
2022-09-19 17:51:06 +08:00
|
|
|
const { datasetType, sceneId, id, editType } = this.$route.query
|
|
|
|
this.datasetType = datasetType
|
|
|
|
this.editType = editType
|
|
|
|
this.sceneId = sceneId
|
2022-09-19 16:13:39 +08:00
|
|
|
if (id) {
|
2022-09-19 17:51:06 +08:00
|
|
|
this.initTable(id)
|
2022-09-19 16:13:39 +08:00
|
|
|
} else {
|
2022-09-19 17:51:06 +08:00
|
|
|
this.tree(sceneId)
|
|
|
|
this.createDataset = true
|
2022-09-08 18:02:12 +08:00
|
|
|
}
|
2022-09-19 17:51:06 +08:00
|
|
|
this.switchComponent(datasetType)
|
2022-09-08 18:02:12 +08:00
|
|
|
},
|
|
|
|
methods: {
|
2022-09-19 16:13:39 +08:00
|
|
|
back() {
|
2022-09-19 17:51:06 +08:00
|
|
|
this.$router.back()
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
nameBlur() {
|
2022-09-19 17:51:06 +08:00
|
|
|
this.nameExsitValidator()
|
|
|
|
this.showInput = this.nameExsit
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
getDatasetNameFromGroup(sceneId) {
|
|
|
|
post(`/dataset/table/getDatasetNameFromGroup/${sceneId}`, null).then(
|
|
|
|
(res) => {
|
2022-09-19 17:51:06 +08:00
|
|
|
this.nameList = res.data
|
2022-09-19 16:13:39 +08:00
|
|
|
}
|
2022-09-19 17:51:06 +08:00
|
|
|
)
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
datasetSave() {
|
2022-09-19 17:51:06 +08:00
|
|
|
if (['sql', 'union'].includes(this.datasetType)) {
|
|
|
|
this.nameExsitValidator()
|
2022-09-19 16:13:39 +08:00
|
|
|
if (this.nameExsit) {
|
2022-09-19 17:51:06 +08:00
|
|
|
return
|
2022-09-19 16:13:39 +08:00
|
|
|
}
|
|
|
|
}
|
2022-09-19 17:51:06 +08:00
|
|
|
this.$refs.addDataset.save()
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
handleClick() {
|
2022-09-19 17:51:06 +08:00
|
|
|
if (['sql', 'union'].includes(this.datasetType)) {
|
|
|
|
this.showInput = true
|
2022-09-19 16:13:39 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
nodeClick({ id, label }) {
|
|
|
|
this.selectDatasets = [
|
|
|
|
{
|
|
|
|
id,
|
2022-09-19 17:51:06 +08:00
|
|
|
label
|
|
|
|
}
|
|
|
|
]
|
2022-09-19 16:13:39 +08:00
|
|
|
this.$nextTick(() => {
|
2022-09-19 17:51:06 +08:00
|
|
|
this.datasetForm.id = id
|
|
|
|
})
|
|
|
|
this.getDatasetNameFromGroup(id)
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
tree(sceneId) {
|
2022-09-19 17:51:06 +08:00
|
|
|
this.loading = true
|
2022-09-19 16:13:39 +08:00
|
|
|
groupTree({
|
2022-09-19 17:51:06 +08:00
|
|
|
name: '',
|
|
|
|
pid: '0',
|
2022-09-19 16:13:39 +08:00
|
|
|
level: 0,
|
2022-09-19 17:51:06 +08:00
|
|
|
type: 'group',
|
2022-09-19 16:13:39 +08:00
|
|
|
children: [],
|
2022-09-19 17:51:06 +08:00
|
|
|
sort: 'type desc,name asc'
|
2022-09-19 16:13:39 +08:00
|
|
|
}).then((res) => {
|
2022-09-19 17:51:06 +08:00
|
|
|
this.tData = res.data
|
2022-09-19 16:13:39 +08:00
|
|
|
if (sceneId) {
|
2022-09-19 17:51:06 +08:00
|
|
|
this.dfsTree(res.data, sceneId)
|
2022-09-19 16:13:39 +08:00
|
|
|
}
|
2022-09-19 17:51:06 +08:00
|
|
|
this.loading = false
|
|
|
|
})
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
dfsTree(arr, sceneId) {
|
|
|
|
arr.some((ele) => {
|
|
|
|
if (sceneId === ele.id) {
|
2022-09-19 17:51:06 +08:00
|
|
|
this.nodeClick(ele)
|
2022-09-19 16:13:39 +08:00
|
|
|
} else if (ele.children?.length) {
|
2022-09-19 17:51:06 +08:00
|
|
|
this.dfsTree(ele.children, sceneId)
|
2022-09-19 16:13:39 +08:00
|
|
|
}
|
2022-09-19 17:51:06 +08:00
|
|
|
return false
|
|
|
|
})
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
filterMethod(val) {
|
2022-09-19 17:51:06 +08:00
|
|
|
if (!val) this.$refs.tree.filter(val)
|
|
|
|
this.$refs.tree.filter(val)
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
filterNode(value, data) {
|
2022-09-19 17:51:06 +08:00
|
|
|
if (!value) return true
|
|
|
|
return data.name.indexOf(value) !== -1
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
beforeClose() {
|
2022-09-19 17:51:06 +08:00
|
|
|
this.close()
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
nameRepeat(value) {
|
|
|
|
if (!this.nameList || this.nameList.length === 0) {
|
2022-09-19 17:51:06 +08:00
|
|
|
return false
|
2022-09-19 16:13:39 +08:00
|
|
|
}
|
2022-09-19 17:51:06 +08:00
|
|
|
return this.nameList.some((name) => name === value)
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
nameValidator(rule, value, callback) {
|
|
|
|
if (this.nameRepeat(value)) {
|
2022-09-19 17:51:06 +08:00
|
|
|
callback(new Error(this.$t('deDataset.already_exists')))
|
2022-09-19 16:13:39 +08:00
|
|
|
} else {
|
2022-09-19 17:51:06 +08:00
|
|
|
callback()
|
2022-09-19 16:13:39 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
nameExsitValidator() {
|
|
|
|
if (!this.nameList || this.nameList.length === 0) {
|
2022-09-19 17:51:06 +08:00
|
|
|
this.nameExsit = false
|
|
|
|
return
|
2022-09-19 16:13:39 +08:00
|
|
|
}
|
2022-09-19 17:51:06 +08:00
|
|
|
this.nameExsit = this.nameList.some(
|
|
|
|
(name) => name === this.table.name && name !== this.originName
|
|
|
|
)
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
close() {
|
2022-09-19 17:51:06 +08:00
|
|
|
this.$router.back()
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
saveDataset() {
|
|
|
|
this.$refs.datasetForm.validate((result) => {
|
|
|
|
if (result) {
|
2022-09-19 17:51:06 +08:00
|
|
|
const { name, id } = this.datasetForm
|
2022-09-19 16:13:39 +08:00
|
|
|
this.table = {
|
|
|
|
id,
|
2022-09-19 17:51:06 +08:00
|
|
|
name
|
|
|
|
}
|
|
|
|
this.createDataset = false
|
|
|
|
this.getDatasetNameFromGroup(id)
|
2022-09-19 16:13:39 +08:00
|
|
|
}
|
2022-09-19 17:51:06 +08:00
|
|
|
})
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
initTable(id) {
|
2022-09-19 17:51:06 +08:00
|
|
|
post('/dataset/table/getWithPermission/' + id, null)
|
2022-09-19 16:13:39 +08:00
|
|
|
.then((response) => {
|
2022-09-19 17:51:06 +08:00
|
|
|
const { sceneId: id, id: tableId, name } = response.data || {}
|
2022-09-19 16:13:39 +08:00
|
|
|
this.table = {
|
|
|
|
id,
|
|
|
|
tableId,
|
|
|
|
table: response.data,
|
2022-09-19 17:51:06 +08:00
|
|
|
name
|
|
|
|
}
|
|
|
|
this.getDatasetNameFromGroup(id)
|
|
|
|
this.originName = name
|
|
|
|
if (this.datasetType === 'excel') {
|
|
|
|
this.table.editType = +this.editType
|
2022-09-19 16:13:39 +08:00
|
|
|
}
|
|
|
|
})
|
2022-09-19 17:51:06 +08:00
|
|
|
.catch(() => {})
|
2022-09-19 16:13:39 +08:00
|
|
|
},
|
|
|
|
switchComponent(c) {
|
2022-09-19 17:51:06 +08:00
|
|
|
let type = ''
|
|
|
|
if (['db', 'excel', 'api'].includes(c)) {
|
|
|
|
this.datasetFormRules = {}
|
2022-09-19 16:13:39 +08:00
|
|
|
}
|
|
|
|
switch (c) {
|
2022-09-19 17:51:06 +08:00
|
|
|
case 'db':
|
|
|
|
type = 'deDataset.database'
|
|
|
|
this.component = AddDB
|
|
|
|
break
|
|
|
|
case 'sql':
|
|
|
|
type = 'SQL'
|
|
|
|
this.component = AddSQL
|
|
|
|
break
|
|
|
|
case 'excel':
|
|
|
|
type = 'EXCEL'
|
|
|
|
this.component = AddExcel
|
|
|
|
break
|
|
|
|
case 'union':
|
|
|
|
type = 'dataset.union'
|
|
|
|
this.component = AddUnion
|
|
|
|
break
|
|
|
|
case 'api':
|
|
|
|
type = 'API'
|
|
|
|
this.component = AddApi
|
|
|
|
break
|
2022-09-19 16:13:39 +08:00
|
|
|
default:
|
2022-09-19 17:51:06 +08:00
|
|
|
break
|
2022-09-19 16:13:39 +08:00
|
|
|
}
|
|
|
|
this.dialogTitle =
|
2022-09-19 17:51:06 +08:00
|
|
|
this.$t('commons.create') + this.$t(type) + this.$t('auth.datasetAuth')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-19 16:13:39 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.de-dataset-form {
|
|
|
|
.top {
|
|
|
|
height: 56px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
padding: 0 24px;
|
|
|
|
box-shadow: 0 2px 2px 0 rgb(0 0 0 / 10%);
|
|
|
|
|
|
|
|
.show-point {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.name {
|
|
|
|
font-family: PingFang SC;
|
|
|
|
font-size: 16px;
|
|
|
|
font-weight: 500;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
width: 50%;
|
|
|
|
position: relative;
|
2022-09-08 18:02:12 +08:00
|
|
|
|
2022-09-19 16:13:39 +08:00
|
|
|
.el-input {
|
|
|
|
min-width: 96px;
|
|
|
|
.el-input__inner {
|
|
|
|
line-height: 24px;
|
|
|
|
height: 24px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.oprate {
|
|
|
|
.table-num {
|
|
|
|
font-family: PingFang SC;
|
|
|
|
font-size: 14px;
|
|
|
|
font-weight: 400;
|
|
|
|
margin-right: 16px;
|
|
|
|
color: var(--deTextPrimary, #1f2329);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.container {
|
|
|
|
width: 100%;
|
|
|
|
height: calc(100vh - 56px);
|
2022-09-08 18:02:12 +08:00
|
|
|
}
|
|
|
|
}
|
2022-09-19 16:13:39 +08:00
|
|
|
|
|
|
|
.dataset-filed {
|
|
|
|
height: 400px;
|
|
|
|
overflow-y: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.tree-select-dataset {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
</style>
|