From c124cc7c7d326044d9165c88445353f8e0fa98c9 Mon Sep 17 00:00:00 2001 From: fit2cloudrd Date: Wed, 20 Apr 2022 19:05:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E9=A2=98=E6=A0=A1=E9=AA=8C=20(#2148)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 优化视图标题校验 * refactor: 优化视图标题校验 Co-authored-by: wangjiahao <1522128093@qq.com> --- .../service/chart/ChartViewService.java | 7 ------ .../canvas/custom-component/UserView.vue | 8 ++++++- frontend/src/components/canvas/utils/utils.js | 23 +++++++++++++++++++ frontend/src/store/index.js | 6 +++++ .../component-style/TitleSelector.vue | 23 ++++++++----------- .../component-style/TitleSelectorAntV.vue | 19 ++++++--------- frontend/src/views/chart/group/Group.vue | 10 ++++++++ frontend/src/views/panel/edit/index.vue | 2 ++ 8 files changed, 65 insertions(+), 33 deletions(-) diff --git a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java index c4ae8443aa..f8dc176372 100644 --- a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java +++ b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java @@ -128,13 +128,6 @@ public class ChartViewService { public ChartViewWithBLOBs newOne(ChartViewWithBLOBs chartView) { long timestamp = System.currentTimeMillis(); - // 校验名称 - ChartViewExample queryExample = new ChartViewExample(); - queryExample.createCriteria().andSceneIdEqualTo(chartView.getSceneId()).andNameEqualTo(chartView.getName()); - List result = chartViewMapper.selectByExample(queryExample); - if (CollectionUtils.isNotEmpty(result)) { - DEException.throwException(Translator.get("theme_name_repeat")); - } chartView.setUpdateTime(timestamp); chartView.setId(UUID.randomUUID().toString()); chartView.setCreateBy(AuthUtils.getUser().getUsername()); diff --git a/frontend/src/components/canvas/custom-component/UserView.vue b/frontend/src/components/canvas/custom-component/UserView.vue index c94aa72b4f..0e8f35793e 100644 --- a/frontend/src/components/canvas/custom-component/UserView.vue +++ b/frontend/src/components/canvas/custom-component/UserView.vue @@ -291,7 +291,8 @@ export default { 'previewCanvasScale', 'mobileLayoutStatus', 'componentData', - 'panelViewDetailsInfo' + 'panelViewDetailsInfo', + 'componentViewsData' ]) }, @@ -478,6 +479,11 @@ export default { // 将视图传入echart组件 if (response.success) { this.chart = response.data + if (this.isEdit) { + this.componentViewsData[this.chart.id] = { + 'title': this.chart.title + } + } this.chart['position'] = this.inTab ? 'tab' : 'panel' // 记录当前数据 this.panelViewDetailsInfo[id] = JSON.stringify(this.chart) diff --git a/frontend/src/components/canvas/utils/utils.js b/frontend/src/components/canvas/utils/utils.js index 0789e81d58..624e7a9515 100644 --- a/frontend/src/components/canvas/utils/utils.js +++ b/frontend/src/components/canvas/utils/utils.js @@ -133,3 +133,26 @@ export function matrixBaseChange(component) { return component } +export function checkViewTitle(opt, id, tile) { + try { + const curPanelViewsData = store.state.componentViewsData + const curComponentViewNames = [] + store.state.componentData.forEach(item => { + if (item.type === 'view' && item.propValue && item.propValue.viewId) { + // 更新时自己的title不加入比较 + if ((opt === 'update' && id !== item.propValue.viewId) || opt === 'new') { + curComponentViewNames.push(curPanelViewsData[item.propValue.viewId].title) + } + } + }) + if (curComponentViewNames.includes(tile)) { + return true + } else { + return false + } + } catch (e) { + console.log('checkViewTitle error', e) + return false + } +} + diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index dd84cf41e8..9aaef94971 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -50,6 +50,8 @@ const data = { componentDataCache: null, // 当前展示画布组件数据 componentData: [], + // 当前展示画布视图信息 + componentViewsData: {}, // PC布局画布组件数据 pcComponentData: [], // 移动端布局画布组件数据 @@ -180,6 +182,10 @@ const data = { Vue.set(state, 'componentData', componentData) }, + setComponentViewsData(state, componentViewsData = {}) { + Vue.set(state, 'componentViewsData', componentViewsData) + }, + setPcComponentData(state, pcComponentData = []) { Vue.set(state, 'pcComponentData', pcComponentData) }, diff --git a/frontend/src/views/chart/components/component-style/TitleSelector.vue b/frontend/src/views/chart/components/component-style/TitleSelector.vue index edbe488e67..a3ae0d42f7 100644 --- a/frontend/src/views/chart/components/component-style/TitleSelector.vue +++ b/frontend/src/views/chart/components/component-style/TitleSelector.vue @@ -50,7 +50,7 @@