fix(数据集): 当编辑数据集时,修改了数据集内容后,那么自动弹出右侧的字段列表

This commit is contained in:
dataeaseShu 2024-03-14 17:46:57 +08:00
parent 0a485e0a08
commit a9f80d6a39
5 changed files with 78 additions and 23 deletions

View File

@ -7,9 +7,8 @@ import { ElMessage, ElMessageBox, ElIcon } from 'element-plus-secondary'
import { Icon } from '@/components/icon-custom' import { Icon } from '@/components/icon-custom'
import { getTableField } from '@/api/dataset' import { getTableField } from '@/api/dataset'
import CodeMirror from './CodeMirror.vue' import CodeMirror from './CodeMirror.vue'
import type { Field } from './UnionFieldList.vue' import type { Field, DataSource } from './util'
import { getDatasourceList, getTables, getPreviewSql } from '@/api/dataset' import { getDatasourceList, getTables, getPreviewSql } from '@/api/dataset'
import type { DataSource } from './index.vue'
import GridTable from '@/components/grid-table/src/GridTable.vue' import GridTable from '@/components/grid-table/src/GridTable.vue'
import { EmptyBackground } from '@/components/empty-background' import { EmptyBackground } from '@/components/empty-background'
import { timestampFormatDate, defaultValueScopeList, fieldOptions } from './util' import { timestampFormatDate, defaultValueScopeList, fieldOptions } from './util'
@ -19,6 +18,7 @@ export interface SqlNode {
tableName: string tableName: string
datasourceId: string datasourceId: string
id: string id: string
changeFlag?: boolean
variables?: Array<{ variables?: Array<{
variableName: string variableName: string
defaultValue: string defaultValue: string
@ -106,7 +106,7 @@ const referenceSetting = () => {
onMounted(() => { onMounted(() => {
dsChange(sqlNode.value.datasourceId) dsChange(sqlNode.value.datasourceId)
codeCom.value = myCm.value.codeComInit(Base64.decode(sqlNode.value.sql)) codeCom.value = myCm.value.codeComInit(Base64.decode(sqlNode.value.sql), true)
}) })
onBeforeUnmount(() => { onBeforeUnmount(() => {
@ -211,8 +211,10 @@ getDatasource()
const emits = defineEmits(['close', 'save']) const emits = defineEmits(['close', 'save'])
let changeFlag = false let changeFlag = false
const changeFlagCode = ref(false)
const setFlag = () => { const setFlag = () => {
changeFlag = true changeFlag = true
changeFlagCode.value = true
} }
let sql = '' let sql = ''
@ -224,6 +226,7 @@ const save = (cb?: () => void) => {
parseVariable() parseVariable()
sql = codeCom.value.state.doc.toString() sql = codeCom.value.state.doc.toString()
sqlNode.value.changeFlag = true
if (!sql.trim()) { if (!sql.trim()) {
ElMessage.error('SQL不能为空') ElMessage.error('SQL不能为空')
return return
@ -264,9 +267,11 @@ const handleClose = () => {
}).then(() => { }).then(() => {
close() close()
changeFlag = false changeFlag = false
changeFlagCode.value = false
}) })
} else { } else {
close() close()
changeFlagCode.value = false
} }
} }
@ -387,6 +392,7 @@ const parseVariable = () => {
const saveVariable = () => { const saveVariable = () => {
state.variables = JSON.parse(JSON.stringify(state.variablesTmp)) state.variables = JSON.parse(JSON.stringify(state.variablesTmp))
showVariableMgm.value = false showVariableMgm.value = false
changeFlagCode.value = true
ElMessage.success('参数设置成功') ElMessage.success('参数设置成功')
} }
const mousedownDrag = () => { const mousedownDrag = () => {
@ -414,7 +420,9 @@ const mousedownDrag = () => {
</template> </template>
参数设置 参数设置
</el-button> </el-button>
<el-button @click="save(() => {})" type="primary"> 保存</el-button> <el-button :disabled="!changeFlagCode" @click="save(() => {})" type="primary">
保存</el-button
>
<el-divider direction="vertical" /> <el-divider direction="vertical" />
<el-icon class="hover-icon" @click="handleClose"> <el-icon class="hover-icon" @click="handleClose">
<Icon name="icon_close_outlined"></Icon> <Icon name="icon_close_outlined"></Icon>
@ -579,7 +587,12 @@ const mousedownDrag = () => {
</div> </div>
</div> </div>
<div class="sql-code-right" :style="{ width: `calc(100% - ${showLeft ? LeftWidth : 0}px)` }"> <div class="sql-code-right" :style="{ width: `calc(100% - ${showLeft ? LeftWidth : 0}px)` }">
<code-mirror :height="`${dragHeight}px`" dom-id="sql-editor" ref="myCm"></code-mirror> <code-mirror
@change="changeFlagCode = true"
:height="`${dragHeight}px`"
dom-id="sql-editor"
ref="myCm"
></code-mirror>
<div class="sql-result" :style="{ height: `calc(100% - ${dragHeight}px)` }"> <div class="sql-result" :style="{ height: `calc(100% - ${dragHeight}px)` }">
<div class="sql-title"> <div class="sql-title">
<span class="drag" @mousedown="mousedownDragH" /> <span class="drag" @mousedown="mousedownDragH" />

View File

@ -19,6 +19,8 @@ const props = defineProps({
dimensionMap: propTypes.arrayOf(String).def(() => []) dimensionMap: propTypes.arrayOf(String).def(() => [])
}) })
const emits = defineEmits(['change'])
const codeComInit = (doc: string, sqlMode?: boolean) => { const codeComInit = (doc: string, sqlMode?: boolean) => {
function _optionalChain(ops) { function _optionalChain(ops) {
let lastAccessLHS = undefined let lastAccessLHS = undefined
@ -112,7 +114,17 @@ const codeComInit = (doc: string, sqlMode?: boolean) => {
} }
} }
const extensionsAttach = sqlMode const extensionsAttach = sqlMode
? [basicSetup, sql(), placeholders, keymap.of([indentWithTab])] ? [
basicSetup,
sql(),
placeholders,
keymap.of([indentWithTab]),
EditorView.updateListener.of(v => {
if (v.docChanged) {
emits('change')
}
})
]
: [basicSetup, placeholders, keymap.of([indentWithTab])] : [basicSetup, placeholders, keymap.of([indentWithTab])]
return new EditorView({ return new EditorView({
doc, doc,

View File

@ -133,8 +133,14 @@ const delNode = (id, arr) => {
}) })
} }
const changeSqlId = ref([])
const changedNodeId = ref([])
const saveSqlNode = (val: SqlNode, cb) => { const saveSqlNode = (val: SqlNode, cb) => {
const { tableName, id, sql, datasourceId, sqlVariableDetails = null } = val const { tableName, id, sql, datasourceId, sqlVariableDetails = null, changeFlag = false } = val
if (changeFlag) {
changedNodeId.value = changedNodeId.value.filter(itx => itx.from !== id && id !== itx.to)
!changeSqlId.value.includes(id) && changeSqlId.value.push(id)
}
if (state.visualNode) { if (state.visualNode) {
Object.assign(state.visualNode, { Object.assign(state.visualNode, {
info: JSON.stringify({ table: tableName, sql }), info: JSON.stringify({ table: tableName, sql }),
@ -173,6 +179,11 @@ const saveSqlNode = (val: SqlNode, cb) => {
dfsNodeBack([obj], [id], state.nodeList) dfsNodeBack([obj], [id], state.nodeList)
} }
const setChangeStatus = (to, from) => {
if (changedNodeId.value.some(ele => ele.from === from && ele.to === to)) return
changedNodeId.value.push({ from, to })
}
const closeSqlNode = () => { const closeSqlNode = () => {
if (state.visualNode?.confirm) { if (state.visualNode?.confirm) {
nextTick(() => { nextTick(() => {
@ -495,10 +506,26 @@ const dfsNodeShadow = (arr, { tableName, id }, position, parent) => {
} }
const flatLine = (item, flatNodeList) => { const flatLine = (item, flatNodeList) => {
let sqlChangeFlag = changeSqlId.value.includes(item.id)
if (item.children?.length) {
sqlChangeFlag = item.children.some(itx => changeSqlId.value.includes(itx.id)) || sqlChangeFlag
}
const from = { ...item, d: '' } const from = { ...item, d: '' }
;(item.children || []).forEach(ele => { ;(item.children || []).forEach(ele => {
let loaclSqlChangeFlag = true
changedNodeId.value.some(element => {
if (
(element.from === item.id && ele.id === element.to) ||
(element.from === ele.id && item.id === element.to)
) {
loaclSqlChangeFlag = false
return true
}
return false
})
flatNodeList.push({ flatNodeList.push({
from, from,
sqlChangeFlag: loaclSqlChangeFlag && sqlChangeFlag,
isShadow: ele.isShadow || item.isShadow, isShadow: ele.isShadow || item.isShadow,
to: { to: {
...ele ...ele
@ -773,7 +800,8 @@ defineExpose({
setStateBack, setStateBack,
notConfirm, notConfirm,
dfsNodeFieldBack, dfsNodeFieldBack,
initState initState,
setChangeStatus
}) })
const handleActiveNode = ele => { const handleActiveNode = ele => {
@ -853,7 +881,12 @@ const emits = defineEmits(['addComplete', 'joinEditor', 'updateAllfields'])
width="32" width="32"
height="32" height="32"
> >
<div v-if="!ele.isShadow" @click="handlePathClick(ele)" class="path-union"> <div
v-if="!ele.isShadow"
@click="handlePathClick(ele)"
class="path-union"
:style="{ borderColor: ele.sqlChangeFlag ? '#F54A45' : '' }"
>
<el-icon> <el-icon>
<Icon :name="iconName[ele.to.unionType]"></Icon> <Icon :name="iconName[ele.to.unionType]"></Icon>
</el-icon> </el-icon>

View File

@ -24,7 +24,7 @@ import { useRoute, useRouter } from 'vue-router'
import UnionEdit from './UnionEdit.vue' import UnionEdit from './UnionEdit.vue'
import type { FormInstance } from 'element-plus-secondary' import type { FormInstance } from 'element-plus-secondary'
import CreatDsGroup from './CreatDsGroup.vue' import CreatDsGroup from './CreatDsGroup.vue'
import { guid, getFieldName, timeTypes } from './util' import { guid, getFieldName, timeTypes, type DataSource } from './util'
import { fieldType } from '@/utils/attr' import { fieldType } from '@/utils/attr'
import { cancelMap } from '@/config/axios/service' import { cancelMap } from '@/config/axios/service'
import { import {
@ -41,18 +41,6 @@ import { cloneDeep, debounce } from 'lodash-es'
interface DragEvent extends MouseEvent { interface DragEvent extends MouseEvent {
dataTransfer: DataTransfer dataTransfer: DataTransfer
} }
export interface Position {
x: number
y: number
}
export type PointerType = 'mouse' | 'touch' | 'pen'
export interface DataSource {
id: string
name: string
children?: DataSource[]
}
interface Field { interface Field {
fieldShortName: string fieldShortName: string
@ -755,7 +743,8 @@ const setFieldAll = () => {
} }
const confirmEditUnion = () => { const confirmEditUnion = () => {
const { node, parent } = fieldUnion.value const { node, parent } = fieldUnion.value
const to = node.id
const from = parent.id
let unionFieldsLost = node.unionFields.some(ele => { let unionFieldsLost = node.unionFields.some(ele => {
const { currentField, parentField } = ele const { currentField, parentField } = ele
return !currentField || !parentField return !currentField || !parentField
@ -774,6 +763,7 @@ const confirmEditUnion = () => {
setFieldAll() setFieldAll()
editUnion.value = false editUnion.value = false
addComplete() addComplete()
datasetDrag.value.setChangeStatus(to, from)
} }
const updateAllfields = () => { const updateAllfields = () => {

View File

@ -149,10 +149,17 @@ interface Field {
id: string id: string
} }
interface DataSource {
id: string
name: string
children?: DataSource[]
}
export { export {
NodeType, NodeType,
UnionType, UnionType,
UnionField, UnionField,
DataSource,
Node, Node,
Field, Field,
timestampFormatDate, timestampFormatDate,