refactor: 复制等资源树操作优化
This commit is contained in:
parent
8dfe8fb77d
commit
eaa0610432
@ -1185,7 +1185,9 @@ const userViewEnlargeOpen = (opt, item) => {
|
||||
}
|
||||
|
||||
const initSnapshotTimer = () => {
|
||||
console.log('check1==')
|
||||
snapshotTimer.value = setInterval(() => {
|
||||
console.log('check2==')
|
||||
snapshotStore.snapshotCatchToStore()
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
@ -286,3 +286,29 @@ export function filterEmptyFolderTree(nodes) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function findParentIdByChildIdRecursive(tree, targetChildId) {
|
||||
function findParentId(node, targetChildId) {
|
||||
if (node.type === 'folder' && node.children) {
|
||||
for (const childNode of node.children) {
|
||||
if (childNode.id === targetChildId) {
|
||||
return node.id // 找到匹配的子节点,返回其父节点的 ID
|
||||
}
|
||||
const parentId = findParentId(childNode, targetChildId)
|
||||
if (parentId !== null) {
|
||||
return parentId // 在子节点中找到匹配的父节点
|
||||
}
|
||||
}
|
||||
}
|
||||
return null // 没有找到匹配的子节点
|
||||
}
|
||||
|
||||
for (const node of tree) {
|
||||
const parentId = findParentId(node, targetChildId)
|
||||
if (parentId !== null) {
|
||||
return parentId // 在整个树中找到匹配的父节点
|
||||
}
|
||||
}
|
||||
|
||||
return null // 没有找到匹配的子节点
|
||||
}
|
||||
|
||||
@ -276,7 +276,9 @@ const saveResource = () => {
|
||||
ElMessage.success('保存成功')
|
||||
if (cmd.value === 'copy') {
|
||||
const baseUrl =
|
||||
curCanvasType.value === 'dataV' ? '#/dvCanvas?dvId=' : '#/dashboard?resourceId='
|
||||
curCanvasType.value === 'dataV'
|
||||
? '#/dvCanvas?opt=copy&dvId='
|
||||
: '#/dashboard?opt=copy&resourceId='
|
||||
window.open(baseUrl + data.data, '_blank')
|
||||
}
|
||||
})
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref, toRefs, watch, nextTick, computed } from 'vue'
|
||||
import { deleteLogic } from '@/api/visualization/dataVisualization'
|
||||
import { copyResource, deleteLogic, ResourceOrFolder } from '@/api/visualization/dataVisualization'
|
||||
import { ElIcon, ElMessage, ElMessageBox, ElScrollbar } from 'element-plus-secondary'
|
||||
import { Icon } from '@/components/icon-custom'
|
||||
import { HandleMore } from '@/components/handle-more'
|
||||
@ -17,6 +17,7 @@ import _ from 'lodash'
|
||||
import DeResourceCreateOpt from '@/views/common/DeResourceCreateOpt.vue'
|
||||
import DeResourceCreateOptV2 from '@/views/common/DeResourceCreateOptV2.vue'
|
||||
import { useCache } from '@/hooks/web/useCache'
|
||||
import { findParentIdByChildIdRecursive } from '@/utils/canvasUtils'
|
||||
const { wsCache } = useCache()
|
||||
|
||||
const dvMainStore = dvMainStoreWithOut()
|
||||
@ -232,7 +233,21 @@ const operation = (cmd: string, data: BusiTreeNode, nodeType: string) => {
|
||||
} else if (cmd === 'edit') {
|
||||
resourceEdit(data.id)
|
||||
} else {
|
||||
resourceGroupOpt.value.optInit(nodeType, data, cmd, ['copy'].includes(cmd))
|
||||
const targetPid = findParentIdByChildIdRecursive(state.resourceTree, data.id)
|
||||
const params: ResourceOrFolder = {
|
||||
nodeType: nodeType as 'folder' | 'leaf',
|
||||
name: data.name + '-copy',
|
||||
type: curCanvasType.value,
|
||||
id: data.id,
|
||||
pid: targetPid || '0'
|
||||
}
|
||||
copyResource(params).then(data => {
|
||||
const baseUrl =
|
||||
curCanvasType.value === 'dataV'
|
||||
? '#/dvCanvas?opt=copy&dvId='
|
||||
: '#/dashboard?opt=copy&resourceId='
|
||||
window.open(baseUrl + data.data, '_blank')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -41,8 +41,15 @@ const dvMainStore = dvMainStoreWithOut()
|
||||
const snapshotStore = snapshotStoreWithOut()
|
||||
const contextmenuStore = contextmenuStoreWithOut()
|
||||
const composeStore = composeStoreWithOut()
|
||||
const { componentData, curComponent, isClickComponent, canvasStyleData, canvasViewInfo, editMode } =
|
||||
storeToRefs(dvMainStore)
|
||||
const {
|
||||
componentData,
|
||||
curComponent,
|
||||
isClickComponent,
|
||||
canvasStyleData,
|
||||
canvasViewInfo,
|
||||
editMode,
|
||||
dvInfo
|
||||
} = storeToRefs(dvMainStore)
|
||||
const { editorMap } = storeToRefs(composeStore)
|
||||
const canvasOut = ref(null)
|
||||
const canvasInner = ref(null)
|
||||
@ -186,6 +193,9 @@ onMounted(() => {
|
||||
state.canvasInitStatus = false
|
||||
initCanvasData(dvId, 'dataV', function () {
|
||||
state.canvasInitStatus = true
|
||||
if (dvInfo.value && opt === 'copy') {
|
||||
dvInfo.value.dataState = 'prepare'
|
||||
}
|
||||
// afterInit
|
||||
nextTick(() => {
|
||||
dvMainStore.setDataPrepareState(true)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user