diff --git a/core/core-backend/src/main/java/io/dataease/visualization/manage/CoreVisualizationManage.java b/core/core-backend/src/main/java/io/dataease/visualization/manage/CoreVisualizationManage.java index d4979bc207..26aae651f9 100644 --- a/core/core-backend/src/main/java/io/dataease/visualization/manage/CoreVisualizationManage.java +++ b/core/core-backend/src/main/java/io/dataease/visualization/manage/CoreVisualizationManage.java @@ -56,6 +56,7 @@ public class CoreVisualizationManage { } QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("delete_flag", false); + queryWrapper.ne("pid",-1); queryWrapper.eq(ObjectUtils.isNotEmpty(request.getLeaf()), "node_type", ObjectUtils.isNotEmpty(request.getLeaf()) && request.getLeaf() ? "leaf" : "folder"); queryWrapper.eq("type", request.getBusiFlag()); queryWrapper.orderByDesc("create_time"); @@ -108,6 +109,10 @@ public class CoreVisualizationManage { @XpackInteract(value = "visualizationResourceTree", before = false) public Long innerSave(DataVisualizationInfo visualizationInfo) { + return preInnerSave(visualizationInfo); + } + + public Long preInnerSave(DataVisualizationInfo visualizationInfo){ if (visualizationInfo.getId() == null) { Long id = IDUtils.snowID(); visualizationInfo.setId(id); diff --git a/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java b/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java index ba43f7c297..fefd404e02 100644 --- a/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java +++ b/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java @@ -122,18 +122,24 @@ public class DataVisualizationServer implements DataVisualizationApi { } DataVisualizationInfo visualizationInfo = new DataVisualizationInfo(); BeanUtils.copyBean(visualizationInfo, request); - - // 检查当前节点的pid是否一致如果不一致 需要调用move 接口(预存 可能会出现pid =-1的情况) - if (request.getPid() != -1) { - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("pid", request.getPid()); - queryWrapper.eq("id", dvId); - if (!visualizationInfoMapper.exists(queryWrapper)) { - request.setMoveFromUpdate(true); - coreVisualizationManage.move(request); + if(DataVisualizationConstants.RESOURCE_OPT_TYPE.COPY.equals(request.getOptType())){ + // 复制更新 新建权限插入 + visualizationInfoMapper.deleteById(dvId); + visualizationInfo.setNodeType(DataVisualizationConstants.NODE_TYPE.LEAF); + coreVisualizationManage.innerSave(visualizationInfo); + }else{ + // 检查当前节点的pid是否一致如果不一致 需要调用move 接口(预存 可能会出现pid =-1的情况) + if (request.getPid() != -1) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("pid", request.getPid()); + queryWrapper.eq("id", dvId); + if (!visualizationInfoMapper.exists(queryWrapper)) { + request.setMoveFromUpdate(true); + coreVisualizationManage.move(request); + } } + coreVisualizationManage.innerEdit(visualizationInfo); } - coreVisualizationManage.innerEdit(visualizationInfo); //保存视图信 chartDataManage.saveChartViewFromVisualization(request.getComponentData(), dvId, request.getCanvasViewInfo()); } @@ -214,8 +220,10 @@ public class DataVisualizationServer implements DataVisualizationApi { extDataVisualizationMapper.copyLinkJump(copyId); extDataVisualizationMapper.copyLinkJumpInfo(copyId); extDataVisualizationMapper.copyLinkJumpTargetInfo(copyId); - - coreVisualizationManage.innerSave(newDv); + DataVisualizationInfo visualizationInfoTarget = new DataVisualizationInfo(); + BeanUtils.copyBean(visualizationInfoTarget,newDv); + visualizationInfoTarget.setPid(-1L); + coreVisualizationManage.preInnerSave(visualizationInfoTarget); return String.valueOf(newDvId); } @@ -321,6 +329,7 @@ public class DataVisualizationServer implements DataVisualizationApi { } wrapper.eq("delete_flag", 0); wrapper.eq("pid", request.getPid()); + wrapper.ne("pid", -1); wrapper.eq("name", request.getName().trim()); wrapper.eq("node_type", request.getNodeType()); wrapper.eq("type", request.getType()); diff --git a/core/core-frontend/src/store/modules/data-visualization/dvMain.ts b/core/core-frontend/src/store/modules/data-visualization/dvMain.ts index 1ac36ccf3c..36268cbac7 100644 --- a/core/core-frontend/src/store/modules/data-visualization/dvMain.ts +++ b/core/core-frontend/src/store/modules/data-visualization/dvMain.ts @@ -52,6 +52,7 @@ export const dvMainStore = defineStore('dataVisualization', { // 大屏基础信息 dvInfo: { dataState: null, + optType: null, id: null, name: null, pid: null, @@ -845,6 +846,7 @@ export const dvMainStore = defineStore('dataVisualization', { resetDvInfo() { this.dvInfo = { dataState: null, + optType: null, id: null, name: null, pid: null, @@ -871,6 +873,7 @@ export const dvMainStore = defineStore('dataVisualization', { updateDvInfoId(newId) { if (this.dvInfo) { this.dvInfo.dataState = 'ready' + this.dvInfo.optType = null this.dvInfo.id = newId } }, @@ -878,6 +881,7 @@ export const dvMainStore = defineStore('dataVisualization', { const optName = dvType === 'dashboard' ? '新建仪表板' : '新建数据大屏' this.dvInfo = { dataState: 'prepare', + optType: null, id: resourceId, name: optName, pid: pid, @@ -899,6 +903,7 @@ export const dvMainStore = defineStore('dataVisualization', { this.componentData = [] this.dvInfo = { dataState: null, + optType: null, id: null, name: null, pid: null, diff --git a/core/core-frontend/src/utils/canvasUtils.ts b/core/core-frontend/src/utils/canvasUtils.ts index bbacdce160..c5a2bb84f4 100644 --- a/core/core-frontend/src/utils/canvasUtils.ts +++ b/core/core-frontend/src/utils/canvasUtils.ts @@ -289,7 +289,7 @@ export function filterEmptyFolderTree(nodes) { export function findParentIdByChildIdRecursive(tree, targetChildId) { function findParentId(node, targetChildId) { - if (node.type === 'folder' && node.children) { + if (node.children) { for (const childNode of node.children) { if (childNode.id === targetChildId) { return node.id // 找到匹配的子节点,返回其父节点的 ID diff --git a/core/core-frontend/src/views/common/DeResourceTree.vue b/core/core-frontend/src/views/common/DeResourceTree.vue index 7aefe562ce..7e16495c8d 100644 --- a/core/core-frontend/src/views/common/DeResourceTree.vue +++ b/core/core-frontend/src/views/common/DeResourceTree.vue @@ -244,9 +244,9 @@ const operation = (cmd: string, data: BusiTreeNode, nodeType: string) => { copyResource(params).then(data => { const baseUrl = curCanvasType.value === 'dataV' - ? '#/dvCanvas?opt=copy&dvId=' - : '#/dashboard?opt=copy&resourceId=' - window.open(baseUrl + data.data, '_blank') + ? `#/dvCanvas?opt=copy&pid=${params.pid}&dvId=${data.data}` + : `#/dashboard?opt=copy&pid=${params.pid}&resourceId=${data.data}` + window.open(baseUrl, '_blank') }) } } diff --git a/core/core-frontend/src/views/dashboard/index.vue b/core/core-frontend/src/views/dashboard/index.vue index f229923c55..06f8353244 100644 --- a/core/core-frontend/src/views/dashboard/index.vue +++ b/core/core-frontend/src/views/dashboard/index.vue @@ -28,8 +28,15 @@ const eventCheck = e => { const dvMainStore = dvMainStoreWithOut() const snapshotStore = snapshotStoreWithOut() -const { componentData, curComponent, canvasStyleData, canvasViewInfo, editMode, batchOptStatus } = - storeToRefs(dvMainStore) +const { + componentData, + curComponent, + canvasStyleData, + canvasViewInfo, + editMode, + batchOptStatus, + dvInfo +} = storeToRefs(dvMainStore) const dataInitState = ref(false) const state = reactive({ @@ -62,6 +69,14 @@ onMounted(() => { dataInitState.value = false initCanvasData(resourceId, 'dashboard', function () { dataInitState.value = true + if (dvInfo.value && opt === 'copy') { + dvInfo.value.dataState = 'prepare' + dvInfo.value.optType = 'copy' + dvInfo.value.pid = pid + setTimeout(() => { + snapshotStore.recordSnapshotCache() + }, 1500) + } }) } else if (opt && opt === 'create') { dataInitState.value = false diff --git a/core/core-frontend/src/views/data-visualization/index.vue b/core/core-frontend/src/views/data-visualization/index.vue index d8ad1e2c52..545893cd68 100644 --- a/core/core-frontend/src/views/data-visualization/index.vue +++ b/core/core-frontend/src/views/data-visualization/index.vue @@ -193,13 +193,18 @@ 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) snapshotStore.recordSnapshotCache('renderChart') + if (dvInfo.value && opt === 'copy') { + dvInfo.value.dataState = 'prepare' + dvInfo.value.optType = 'copy' + dvInfo.value.pid = pid + setTimeout(() => { + snapshotStore.recordSnapshotCache('renderChart') + }, 1500) + } }) }) } else if (opt && opt === 'create') {