forked from github/dataease
refactor: 优化视图标题校验
This commit is contained in:
parent
162b51ee1a
commit
4ea6c83fa2
@ -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());
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
|
@ -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 {
|
||||
this.$error(this.$t('chart.title_repeat'))
|
||||
this.titleForm.title = this.chart.title
|
||||
return
|
||||
}
|
||||
})
|
||||
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()
|
||||
|
@ -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
|
||||
|
@ -661,6 +661,8 @@ export default {
|
||||
initPanelData(panelId, function() {
|
||||
// 初始化视图缓存
|
||||
initViewCache(panelId)
|
||||
// 初始化记录的视图信息
|
||||
_this.$store.commit('setComponentViewsData')
|
||||
// 初始化保存状态
|
||||
setTimeout(() => {
|
||||
_this.$store.commit('refreshSaveStatus')
|
||||
|
Loading…
Reference in New Issue
Block a user