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) {
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.setId(UUID.randomUUID().toString());
chartView.setCreateBy(AuthUtils.getUser().getUsername());

View File

@ -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)

View File

@ -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
}
}

View File

@ -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)
},

View File

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

View File

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

View File

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