fix:禁用localstorage存储仪表盘数据 容易导致浏览器本地存储越界

This commit is contained in:
wangjiahao 2021-04-08 17:46:02 +08:00
parent 8d61299f3e
commit ff02cb9a1f
6 changed files with 24 additions and 40 deletions

View File

@ -42,8 +42,8 @@ export default {
methods: {
edit() {
//
localStorage.setItem('canvasDataEditTmp', JSON.stringify(this.componentData))
localStorage.setItem('canvasStyleEditTmp', JSON.stringify(this.canvasStyleData))
this.$store.dispatch('panel/setComponentDataTemp', JSON.stringify(this.componentData))
this.$store.dispatch('panel/setCanvasStyleDataTemp', JSON.stringify(this.canvasStyleData))
if (this.curComponent.component === 'user-view') {
this.$store.dispatch('chart/setViewId', null)
this.$store.dispatch('chart/setViewId', this.curComponent.propValue.viewId)

View File

@ -197,8 +197,6 @@ export default {
},
save() {
localStorage.setItem('canvasData', JSON.stringify(this.componentData))
localStorage.setItem('canvasStyle', JSON.stringify(this.canvasStyleData))
//
const requestInfo = {
id: this.$store.state.panel.panelInfo.id,
@ -218,8 +216,6 @@ export default {
},
clickPreview() {
localStorage.setItem('canvasData', JSON.stringify(this.componentData))
localStorage.setItem('canvasStyle', JSON.stringify(this.canvasStyleData))
const url = '#/preview'
window.open(url, '_blank')
}

View File

@ -6,7 +6,9 @@ const getDefaultState = () => {
id: null,
name: '',
preStyle: null
}
},
canvasStyleDataTemp: null, // 页面全局临时存储数据
componentDataTemp: null // 画布组件临时存储数据
}
}
@ -18,6 +20,12 @@ const mutations = {
},
setPanelInfo: (state, panelInfo) => {
state.panelInfo = panelInfo
},
setCanvasStyleDataTemp: (state, canvasStyleDataTemp) => {
state.canvasStyleDataTemp = canvasStyleDataTemp
},
setComponentDataTemp: (state, componentDataTemp) => {
state.componentDataTemp = componentDataTemp
}
}
@ -27,6 +35,12 @@ const actions = {
},
setPanelInfo({ commit }, panelInfo) {
commit('setPanelInfo', panelInfo)
},
setCanvasStyleDataTemp({ commit }, canvasStyleDataTemp) {
commit('setCanvasStyleDataTemp', canvasStyleDataTemp)
},
setComponentDataTemp({ commit }, componentDataTemp) {
commit('setComponentDataTemp', componentDataTemp)
}
}

View File

@ -195,24 +195,18 @@ export default {
},
methods: {
init(panelId) {
//
localStorage.setItem('canvasData', null)
localStorage.setItem('canvasStyle', null)
// 使
if (localStorage.getItem('canvasDataEditTmp') && localStorage.getItem('canvasStyleEditTmp')) {
localStorage.setItem('canvasData', localStorage.getItem('canvasDataEditTmp'))
localStorage.setItem('canvasStyle', localStorage.getItem('canvasStyleEditTmp'))
const componentDataTemp = this.$store.state.panel.componentDataTemp
const canvasStyleDataTemp = this.$store.state.panel.canvasStyleDataTemp
if (componentDataTemp && canvasStyleDataTemp) {
this.$store.commit('setComponentData', this.resetID(JSON.parse(componentDataTemp)))
this.$store.commit('setCanvasStyle', JSON.parse(canvasStyleDataTemp))
} else if (panelId) {
get('panel/group/findOne/' + panelId).then(response => {
localStorage.setItem('canvasData', response.data.panelData)
localStorage.setItem('canvasStyle', response.data.panelStyle)
this.$store.commit('setComponentData', this.resetID(response.data.panelData))
this.$store.commit('setCanvasStyle', response.data.panelStyle)
})
}
//
localStorage.setItem('canvasDataEditTmp', null)
localStorage.setItem('canvasStyleEditTmp', null)
this.restore()
},
save() {
@ -244,19 +238,6 @@ export default {
})
},
//
restore() {
//
let canvasData = null
if ((canvasData = localStorage.getItem('canvasData')) !== null && canvasData !== 'null') {
this.$store.commit('setComponentData', this.resetID(JSON.parse(canvasData)))
}
if (canvasData && canvasData !== 'null') {
this.$store.commit('setCanvasStyle', JSON.parse(localStorage.getItem('canvasStyle')))
}
},
resetID(data) {
data.forEach(item => {
item.id = uuid.v1()

View File

@ -420,8 +420,6 @@ export default {
if (data.nodeType === 'panel') {
//
this.$nextTick(() => {
localStorage.setItem('canvasData', null)
localStorage.setItem('canvasStyle', null)
get('panel/group/findOne/' + data.id).then(response => {
this.$store.commit('setComponentData', this.resetID(JSON.parse(response.data.panelData)))
this.$store.commit('setCanvasStyle', JSON.parse(response.data.panelStyle))
@ -522,8 +520,6 @@ export default {
},
edit(data) {
//
localStorage.setItem('canvasDataEditTmp', null)
localStorage.setItem('canvasStyleEditTmp', null)
this.$store.dispatch('panel/setPanelInfo', data)
bus.$emit('PanelSwitchComponent', { name: 'PanelEdit' })
},

View File

@ -48,9 +48,6 @@ export default {
},
methods: {
clickPreview() {
debugger
localStorage.setItem('canvasData', JSON.stringify(this.componentData))
localStorage.setItem('canvasStyle', JSON.stringify(this.canvasStyleData))
const url = '#/preview/' + this.$store.state.panel.panelInfo.id
window.open(url, '_blank')
}