From a9f80d6a3926768ae3d53a8138978c0b778c9899 Mon Sep 17 00:00:00 2001 From: dataeaseShu Date: Thu, 14 Mar 2024 17:46:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=95=B0=E6=8D=AE=E9=9B=86):=20=E5=BD=93?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=95=B0=E6=8D=AE=E9=9B=86=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E6=95=B0=E6=8D=AE=E9=9B=86=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E5=90=8E=EF=BC=8C=E9=82=A3=E4=B9=88=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=BC=B9=E5=87=BA=E5=8F=B3=E4=BE=A7=E7=9A=84=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../visualized/data/dataset/form/AddSql.vue | 23 ++++++++--- .../data/dataset/form/CodeMirror.vue | 14 ++++++- .../data/dataset/form/DatasetUnion.vue | 39 +++++++++++++++++-- .../visualized/data/dataset/form/index.vue | 18 ++------- .../visualized/data/dataset/form/util.ts | 7 ++++ 5 files changed, 78 insertions(+), 23 deletions(-) diff --git a/core/core-frontend/src/views/visualized/data/dataset/form/AddSql.vue b/core/core-frontend/src/views/visualized/data/dataset/form/AddSql.vue index 58d5f04a89..fa5f8090d2 100644 --- a/core/core-frontend/src/views/visualized/data/dataset/form/AddSql.vue +++ b/core/core-frontend/src/views/visualized/data/dataset/form/AddSql.vue @@ -7,9 +7,8 @@ import { ElMessage, ElMessageBox, ElIcon } from 'element-plus-secondary' import { Icon } from '@/components/icon-custom' import { getTableField } from '@/api/dataset' 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 type { DataSource } from './index.vue' import GridTable from '@/components/grid-table/src/GridTable.vue' import { EmptyBackground } from '@/components/empty-background' import { timestampFormatDate, defaultValueScopeList, fieldOptions } from './util' @@ -19,6 +18,7 @@ export interface SqlNode { tableName: string datasourceId: string id: string + changeFlag?: boolean variables?: Array<{ variableName: string defaultValue: string @@ -106,7 +106,7 @@ const referenceSetting = () => { onMounted(() => { 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(() => { @@ -211,8 +211,10 @@ getDatasource() const emits = defineEmits(['close', 'save']) let changeFlag = false +const changeFlagCode = ref(false) const setFlag = () => { changeFlag = true + changeFlagCode.value = true } let sql = '' @@ -224,6 +226,7 @@ const save = (cb?: () => void) => { parseVariable() sql = codeCom.value.state.doc.toString() + sqlNode.value.changeFlag = true if (!sql.trim()) { ElMessage.error('SQL不能为空') return @@ -264,9 +267,11 @@ const handleClose = () => { }).then(() => { close() changeFlag = false + changeFlagCode.value = false }) } else { close() + changeFlagCode.value = false } } @@ -387,6 +392,7 @@ const parseVariable = () => { const saveVariable = () => { state.variables = JSON.parse(JSON.stringify(state.variablesTmp)) showVariableMgm.value = false + changeFlagCode.value = true ElMessage.success('参数设置成功') } const mousedownDrag = () => { @@ -414,7 +420,9 @@ const mousedownDrag = () => { 参数设置 - 保存 + + 保存 @@ -579,7 +587,12 @@ const mousedownDrag = () => {
- +
diff --git a/core/core-frontend/src/views/visualized/data/dataset/form/CodeMirror.vue b/core/core-frontend/src/views/visualized/data/dataset/form/CodeMirror.vue index 0fab22db5a..7f7d239c55 100644 --- a/core/core-frontend/src/views/visualized/data/dataset/form/CodeMirror.vue +++ b/core/core-frontend/src/views/visualized/data/dataset/form/CodeMirror.vue @@ -19,6 +19,8 @@ const props = defineProps({ dimensionMap: propTypes.arrayOf(String).def(() => []) }) +const emits = defineEmits(['change']) + const codeComInit = (doc: string, sqlMode?: boolean) => { function _optionalChain(ops) { let lastAccessLHS = undefined @@ -112,7 +114,17 @@ const codeComInit = (doc: string, sqlMode?: boolean) => { } } 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])] return new EditorView({ doc, diff --git a/core/core-frontend/src/views/visualized/data/dataset/form/DatasetUnion.vue b/core/core-frontend/src/views/visualized/data/dataset/form/DatasetUnion.vue index 0e062efa24..038a9fc44b 100644 --- a/core/core-frontend/src/views/visualized/data/dataset/form/DatasetUnion.vue +++ b/core/core-frontend/src/views/visualized/data/dataset/form/DatasetUnion.vue @@ -133,8 +133,14 @@ const delNode = (id, arr) => { }) } +const changeSqlId = ref([]) +const changedNodeId = ref([]) 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) { Object.assign(state.visualNode, { info: JSON.stringify({ table: tableName, sql }), @@ -173,6 +179,11 @@ const saveSqlNode = (val: SqlNode, cb) => { 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 = () => { if (state.visualNode?.confirm) { nextTick(() => { @@ -495,10 +506,26 @@ const dfsNodeShadow = (arr, { tableName, id }, position, parent) => { } 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: '' } ;(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({ from, + sqlChangeFlag: loaclSqlChangeFlag && sqlChangeFlag, isShadow: ele.isShadow || item.isShadow, to: { ...ele @@ -773,7 +800,8 @@ defineExpose({ setStateBack, notConfirm, dfsNodeFieldBack, - initState + initState, + setChangeStatus }) const handleActiveNode = ele => { @@ -853,7 +881,12 @@ const emits = defineEmits(['addComplete', 'joinEditor', 'updateAllfields']) width="32" height="32" > -
+
diff --git a/core/core-frontend/src/views/visualized/data/dataset/form/index.vue b/core/core-frontend/src/views/visualized/data/dataset/form/index.vue index 2c7ee687da..837e151f8e 100644 --- a/core/core-frontend/src/views/visualized/data/dataset/form/index.vue +++ b/core/core-frontend/src/views/visualized/data/dataset/form/index.vue @@ -24,7 +24,7 @@ import { useRoute, useRouter } from 'vue-router' import UnionEdit from './UnionEdit.vue' import type { FormInstance } from 'element-plus-secondary' 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 { cancelMap } from '@/config/axios/service' import { @@ -41,18 +41,6 @@ import { cloneDeep, debounce } from 'lodash-es' interface DragEvent extends MouseEvent { 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 { fieldShortName: string @@ -755,7 +743,8 @@ const setFieldAll = () => { } const confirmEditUnion = () => { const { node, parent } = fieldUnion.value - + const to = node.id + const from = parent.id let unionFieldsLost = node.unionFields.some(ele => { const { currentField, parentField } = ele return !currentField || !parentField @@ -774,6 +763,7 @@ const confirmEditUnion = () => { setFieldAll() editUnion.value = false addComplete() + datasetDrag.value.setChangeStatus(to, from) } const updateAllfields = () => { diff --git a/core/core-frontend/src/views/visualized/data/dataset/form/util.ts b/core/core-frontend/src/views/visualized/data/dataset/form/util.ts index 1d596529f3..06bf494065 100644 --- a/core/core-frontend/src/views/visualized/data/dataset/form/util.ts +++ b/core/core-frontend/src/views/visualized/data/dataset/form/util.ts @@ -149,10 +149,17 @@ interface Field { id: string } +interface DataSource { + id: string + name: string + children?: DataSource[] +} + export { NodeType, UnionType, UnionField, + DataSource, Node, Field, timestampFormatDate,