refactor: 优化视图标题校验

This commit is contained in:
wangjiahao 2022-04-20 18:50:37 +08:00
parent 162b51ee1a
commit 4ea6c83fa2
7 changed files with 58 additions and 21 deletions

View File

@ -128,13 +128,6 @@ public class ChartViewService {
public ChartViewWithBLOBs newOne(ChartViewWithBLOBs chartView) { public ChartViewWithBLOBs newOne(ChartViewWithBLOBs chartView) {
long timestamp = System.currentTimeMillis(); long timestamp = System.currentTimeMillis();
// 校验名称
ChartViewExample queryExample = new ChartViewExample();
queryExample.createCriteria().andSceneIdEqualTo(chartView.getSceneId()).andNameEqualTo(chartView.getName());
List<ChartView> result = chartViewMapper.selectByExample(queryExample);
if (CollectionUtils.isNotEmpty(result)) {
DEException.throwException(Translator.get("theme_name_repeat"));
}
chartView.setUpdateTime(timestamp); chartView.setUpdateTime(timestamp);
chartView.setId(UUID.randomUUID().toString()); chartView.setId(UUID.randomUUID().toString());
chartView.setCreateBy(AuthUtils.getUser().getUsername()); chartView.setCreateBy(AuthUtils.getUser().getUsername());

View File

@ -291,7 +291,8 @@ export default {
'previewCanvasScale', 'previewCanvasScale',
'mobileLayoutStatus', 'mobileLayoutStatus',
'componentData', 'componentData',
'panelViewDetailsInfo' 'panelViewDetailsInfo',
'componentViewsData'
]) ])
}, },
@ -478,6 +479,11 @@ export default {
// echart // echart
if (response.success) { if (response.success) {
this.chart = response.data this.chart = response.data
if (this.isEdit) {
this.componentViewsData[this.chart.id] = {
'title': this.chart.title
}
}
this.chart['position'] = this.inTab ? 'tab' : 'panel' this.chart['position'] = this.inTab ? 'tab' : 'panel'
// //
this.panelViewDetailsInfo[id] = JSON.stringify(this.chart) this.panelViewDetailsInfo[id] = JSON.stringify(this.chart)

View File

@ -133,3 +133,26 @@ export function matrixBaseChange(component) {
return 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
}
}

View File

@ -50,6 +50,8 @@ const data = {
componentDataCache: null, componentDataCache: null,
// 当前展示画布组件数据 // 当前展示画布组件数据
componentData: [], componentData: [],
// 当前展示画布视图信息
componentViewsData: {},
// PC布局画布组件数据 // PC布局画布组件数据
pcComponentData: [], pcComponentData: [],
// 移动端布局画布组件数据 // 移动端布局画布组件数据
@ -180,6 +182,10 @@ const data = {
Vue.set(state, 'componentData', componentData) Vue.set(state, 'componentData', componentData)
}, },
setComponentViewsData(state, componentViewsData = {}) {
Vue.set(state, 'componentViewsData', componentViewsData)
},
setPcComponentData(state, pcComponentData = []) { setPcComponentData(state, pcComponentData = []) {
Vue.set(state, 'pcComponentData', pcComponentData) Vue.set(state, 'pcComponentData', pcComponentData)
}, },

View File

@ -50,7 +50,7 @@
<script> <script>
import { COLOR_PANEL, DEFAULT_TITLE_STYLE } from '../../chart/chart' import { COLOR_PANEL, DEFAULT_TITLE_STYLE } from '../../chart/chart'
import { checkTitle } from '@/api/chart/chart' import { checkViewTitle } from '@/components/canvas/utils/utils'
export default { export default {
name: 'TitleSelector', name: 'TitleSelector',
@ -115,18 +115,15 @@ export default {
this.titleForm.title = this.chart.title this.titleForm.title = this.chart.title
return return
} }
checkTitle({ id: this.chart.id, title: this.titleForm.title, sceneId: this.chart.sceneId }).then((rsp) => { if (checkViewTitle('update', this.chart.id, this.titleForm.title)) {
if (rsp.data === 'success') {
if (!this.titleForm.show) {
this.isSetting = false
}
this.$emit('onTextChange', this.titleForm)
} else {
this.$error(this.$t('chart.title_repeat')) this.$error(this.$t('chart.title_repeat'))
this.titleForm.title = this.chart.title this.titleForm.title = this.chart.title
return return
} }
}) if (!this.titleForm.show) {
this.isSetting = false
}
this.$emit('onTextChange', this.titleForm)
}, },
inputOnInput: function(e) { inputOnInput: function(e) {
this.$forceUpdate() this.$forceUpdate()

View File

@ -314,6 +314,7 @@ import {
DEFAULT_THRESHOLD, DEFAULT_THRESHOLD,
DEFAULT_TOTAL DEFAULT_TOTAL
} from '../chart/chart' } from '../chart/chart'
import { checkViewTitle } from '@/components/canvas/utils/utils'
export default { export default {
name: 'Group', name: 'Group',
@ -772,6 +773,15 @@ export default {
}) })
return return
} }
if (checkViewTitle('new', null, this.chartName)) {
this.$message({
showClose: true,
message: this.$t('chart.title_repeat'),
type: 'error'
})
return
}
const view = {} const view = {}
view.name = this.chartName view.name = this.chartName
view.title = this.chartName view.title = this.chartName

View File

@ -661,6 +661,8 @@ export default {
initPanelData(panelId, function() { initPanelData(panelId, function() {
// //
initViewCache(panelId) initViewCache(panelId)
//
_this.$store.commit('setComponentViewsData')
// //
setTimeout(() => { setTimeout(() => {
_this.$store.commit('refreshSaveStatus') _this.$store.commit('refreshSaveStatus')