Merge pull request #11291 from dataease/pr@dev-v2_st

fix(数据集): 计算字段删除二次确认
This commit is contained in:
dataeaseShu 2024-07-31 15:27:55 +08:00 committed by GitHub
commit 925d7d1729
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 220 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import { reactive, computed, ref, nextTick, inject, type Ref, watch, unref } fro
import AddSql from './AddSql.vue'
import { useI18n } from '@/hooks/web/useI18n'
import zeroNodeImg from '@/assets/img/drag.png'
import { ElMessageBox, type Action } from 'element-plus-secondary'
import { guid } from './util'
import { HandleMore } from '@/components/handle-more'
import { propTypes } from '@/utils/propTypes'
@ -113,7 +114,7 @@ const dfsForDsId = (arr, datasourceId) => {
if (ele.children?.length) {
return dfsForDsId(ele.children, datasourceId)
}
return ele.datasourceId === datasourceId || !ele.datasourceId
return ele.datasourceId === datasourceId
})
}
@ -162,6 +163,29 @@ const delNode = (id, arr) => {
return false
})
}
let fakeDelId = []
const collectId = arr => {
arr.forEach(ele => {
fakeDelId = [...fakeDelId, ...ele.currentDsFields.map(itx => itx.id)]
if (ele.children?.length) {
collectId(ele.children)
}
})
}
const delNodeFake = (id, arr) => {
arr.forEach(ele => {
if (id === ele.id) {
fakeDelId = [...ele.currentDsFields.map(itx => itx.id)]
if (ele.children?.length) {
collectId(ele.children)
}
} else if (ele.children?.length) {
delNodeFake(id, ele.children)
}
})
}
const changeSqlId = ref([])
const changedNodeId = ref([])
@ -306,8 +330,71 @@ const delUpdateDsFields = (id, arr: Node[]) => {
return false
})
}
const delUpdateDsFieldsFake = (id, arr: Node[]) => {
arr.forEach(ele => {
if (id === ele.id) {
fakeDelId = [...ele.currentDsFields.map(itx => itx.id)]
}
if (ele.children?.length) {
delUpdateDsFieldsFake(id, ele.children)
}
})
}
const confirmEditUnion = () => {
delUpdateDsFieldsFake(currentNode.value.id, state.nodeList)
const currentIds = currentNode.value.currentDsFields.map(ele => ele.id)
let ids = fakeDelId.filter(ele => !currentIds.includes(ele))
fakeDelId = []
if (!!ids.length) {
const idArr = allfields.value.reduce((pre, next) => {
if (next.extField === 2) {
const idMap = next.originName.match(/\[(.+?)\]/g)
const result = idMap.map(itm => {
return itm.slice(1, -1)
})
result.forEach(ele => {
if (ids.includes(ele)) {
pre.push(ele)
}
})
}
return pre
}, [])
if (!!idArr.length) {
ElMessageBox.confirm(
`字段${allfields.value
.filter(ele => [...new Set(idArr)].includes(ele.id) && ele.extField !== 2)
.map(ele => ele.name)
.join(',')}未被选择其相关的新建字段将被删除是否继续`,
{
confirmButtonText: t('dataset.confirm'),
cancelButtonText: t('common.cancel'),
showCancelButton: true,
confirmButtonType: 'danger',
type: 'warning',
autofocus: false,
showClose: false,
callback: (action: Action) => {
if (action === 'confirm') {
delUpdateDsFields(currentNode.value.id, state.nodeList)
const [fir] = state.nodeList
if (fir.isShadow) {
delete fir.isShadow
}
closeEditUnion()
nextTick(() => {
emits('updateAllfields')
})
}
}
}
)
return
}
}
delUpdateDsFields(currentNode.value.id, state.nodeList)
const [fir] = state.nodeList
if (fir.isShadow) {
@ -345,6 +432,53 @@ const handleCommand = (ele, command) => {
}
if (command === 'del') {
delNodeFake(ele.id, state.nodeList)
if (!!fakeDelId.length) {
const idArr = allfields.value.reduce((pre, next) => {
if (next.extField === 2) {
const idMap = next.originName.match(/\[(.+?)\]/g)
const result = idMap.map(itm => {
return itm.slice(1, -1)
})
result.forEach(ele => {
if (fakeDelId.includes(ele)) {
pre.push(ele)
}
})
}
return pre
}, [])
fakeDelId = []
if (!!idArr.length) {
ElMessageBox.confirm(
`字段${allfields.value
.filter(ele => [...new Set(idArr)].includes(ele.id) && ele.extField !== 2)
.map(ele => ele.name)
.join(',')}未被选择其相关的新建字段将被删除是否继续`,
{
confirmButtonText: t('dataset.confirm'),
cancelButtonText: t('common.cancel'),
showCancelButton: true,
confirmButtonType: 'danger',
type: 'warning',
autofocus: false,
showClose: false,
callback: (action: Action) => {
if (action === 'confirm') {
delNode(ele.id, state.nodeList)
nextTick(() => {
emits('addComplete')
emits('updateAllfields')
})
}
}
}
)
return
}
}
delNode(ele.id, state.nodeList)
nextTick(() => {
emits('addComplete')

View File

@ -25,6 +25,7 @@ import CalcFieldEdit from './CalcFieldEdit.vue'
import { useRoute, useRouter } from 'vue-router'
import UnionEdit from './UnionEdit.vue'
import type { FormInstance } from 'element-plus-secondary'
import type { BusiTreeNode } from '@/models/tree/TreeNode'
import CreatDsGroup from './CreatDsGroup.vue'
import { guid, getFieldName, timeTypes, type DataSource } from './util'
import { fieldType } from '@/utils/attr'
@ -439,6 +440,32 @@ const delFieldById = arr => {
}
}
const delFieldByIdFake = (arr, fakeAllfields) => {
const delId = [...arr]
let idList = []
while (delId.length) {
const [targetId] = delId
delId.shift()
fakeAllfields = fakeAllfields.filter(ele => ele.id !== targetId)
const allfieldsId = fakeAllfields.map(ele => ele.id)
fakeAllfields = fakeAllfields.filter(ele => {
if (ele.extField !== 2) return true
const idMap = ele.originName.match(/\[(.+?)\]/g)
if (!idMap) return true
const result = idMap.every(itm => {
const id = itm.slice(1, -1)
return allfieldsId.includes(id)
})
if (result) return true
delId.push(ele.id)
idList.push(ele.id)
return false
})
}
return idList
}
const deleteField = item => {
ElMessageBox.confirm(t('dataset.confirm_delete'), {
confirmButtonText: t('dataset.confirm'),
@ -776,6 +803,18 @@ const dfsNode = (arr, id) => {
return pre
}, [])
}
const dfsFieldsTips = (arr, list, idArr) => {
list.forEach(ele => {
if (ele.children?.length) {
dfsFieldsTips(arr, ele.children, idArr)
}
if (!idArr.includes(ele.id)) {
const { currentDsFields } = ele
arr.push(...cloneDeep(currentDsFields))
}
})
}
const confirmEditUnion = () => {
const { node, parent } = fieldUnion.value
const to = node.id
@ -797,6 +836,52 @@ const confirmEditUnion = () => {
setGuid(parent.currentDsFields, parent.id, parent.datasourceId, parentOldCurrentDsFields)
const top = cloneDeep(node)
const bottom = cloneDeep(parent)
let arr = []
dfsFieldsTips(arr, datasetDrag.value.getNodeList(), [node.id, parent.id])
arr = [...arr, ...node.currentDsFields, ...parent.currentDsFields]
const delIdArr = getDelIdArr(arr, allfields.value)
let fakeAllfields = diffArr(arr, allfields.value)
const idList = delFieldByIdFake(delIdArr, fakeAllfields)
if (!!idList.length) {
const idArr = allfields.value.reduce((pre, next) => {
if (idList.includes(next.id)) {
const idMap = next.originName.match(/\[(.+?)\]/g)
const result = idMap.map(itm => {
return itm.slice(1, -1)
})
pre = [...result, ...pre]
}
return pre
}, [])
ElMessageBox.confirm(
`字段${allfields.value
.filter(ele => [...new Set(idArr)].includes(ele.id) && ele.extField !== 2)
.map(ele => ele.name)
.join(',')}未被选择其相关的新建字段将被删除是否继续`,
{
confirmButtonText: t('dataset.confirm'),
cancelButtonText: t('common.cancel'),
showCancelButton: true,
confirmButtonType: 'danger',
type: 'warning',
autofocus: false,
showClose: false,
callback: (action: Action) => {
if (action === 'confirm') {
datasetDrag.value.setStateBack(top, bottom)
setFieldAll()
editUnion.value = false
addComplete()
datasetDrag.value.setChangeStatus(to, from)
}
}
}
)
return
}
datasetDrag.value.setStateBack(top, bottom)
setFieldAll()
editUnion.value = false