Commit 1dc9a745 authored by Jenny's avatar Jenny

feat: 数据缓存

parent 1286a517
...@@ -14,12 +14,14 @@ export default { ...@@ -14,12 +14,14 @@ export default {
} }
}, },
methods: { methods: {
setStorageData() {
uni.setStorageSync(this.elementInfo.id, JSON.stringify(this.elementData.dataList))
},
/** /**
* 静态数据 * 静态数据
*/ */
handleStaticData(value) { handleStaticData(value) {
this.elementData.dataList = JSON.parse(JSON.stringify({...value.dataList})) this.elementData.dataList = JSON.parse(JSON.stringify({...value.dataList}))
this.initChart()
}, },
/** /**
* 动态数据 * 动态数据
...@@ -36,7 +38,6 @@ export default { ...@@ -36,7 +38,6 @@ export default {
} else { } else {
that.elementData.dataList = JSON.parse(JSON.stringify(res.data.Result)) that.elementData.dataList = JSON.parse(JSON.stringify(res.data.Result))
} }
this.initChart()
}, },
/** /**
* 全局数据 * 全局数据
...@@ -49,7 +50,6 @@ export default { ...@@ -49,7 +50,6 @@ export default {
} else { } else {
this.elementData.dataList = this.vuex_globalData this.elementData.dataList = this.vuex_globalData
} }
this.initChart()
}, },
/** /**
* 配置数据 - 数据集 * 配置数据 - 数据集
...@@ -65,7 +65,6 @@ export default { ...@@ -65,7 +65,6 @@ export default {
} else { } else {
that.elementData.dataList = res.data.Result that.elementData.dataList = res.data.Result
} }
this.initChart()
} else { } else {
that.$u.toast(Msg) that.$u.toast(Msg)
} }
...@@ -82,7 +81,6 @@ export default { ...@@ -82,7 +81,6 @@ export default {
const { Status, Msg, Result } = res.data const { Status, Msg, Result } = res.data
if (Status === 'true') { if (Status === 'true') {
that.elementData.dataList = Result that.elementData.dataList = Result
this.initChart()
}else { }else {
message.warning(Msg) message.warning(Msg)
} }
...@@ -117,6 +115,10 @@ export default { ...@@ -117,6 +115,10 @@ export default {
'elementInfo.data': { 'elementInfo.data': {
handler(newVal) { handler(newVal) {
const that = this const that = this
const storageData = uni.getStorageSync(this.elementInfo.id)
if(storageData && newVal.dataType !== 'static') {
this.elementData.dataList = JSON.parse(storageData)
}
if(that.elementInfo.hide) return false if(that.elementInfo.hide) return false
if (newVal.dataType === 'static') { if (newVal.dataType === 'static') {
that.handleStaticData(newVal) that.handleStaticData(newVal)
...@@ -159,6 +161,14 @@ export default { ...@@ -159,6 +161,14 @@ export default {
*/ */
'vuex_globalData' () { 'vuex_globalData' () {
if (this.elementInfo.data.dataType === 'public') this.handlePublicData(this.elementInfo.data) if (this.elementInfo.data.dataType === 'public') this.handlePublicData(this.elementInfo.data)
},
'elementData.dataList': {
handler(newVal) {
this.setStorageData()
this.initChart()
},
deep: true,
immediate: true
} }
} }
} }
...@@ -104,6 +104,9 @@ ...@@ -104,6 +104,9 @@
// detail页面也会监听这两个事件,所有index页面需要在onShow里面增加监听,在onHide里面移除监听 // detail页面也会监听这两个事件,所有index页面需要在onShow里面增加监听,在onHide里面移除监听
onShow() { onShow() {
const that = this const that = this
if(uni.getStorageSync('reportInfo')) {
this.reportInfo = JSON.parse(uni.getStorageSync('reportInfo'))
}
/** /**
* 组件交互 - 参数 * 组件交互 - 参数
*/ */
...@@ -222,6 +225,7 @@ ...@@ -222,6 +225,7 @@
} }
} }
that.reportInfo = res.data.Result that.reportInfo = res.data.Result
uni.setStorageSync('reportInfo', JSON.stringify(res.data.Result))
that.getStickyTables() that.getStickyTables()
} }
}, },
......
...@@ -12,7 +12,7 @@ try { ...@@ -12,7 +12,7 @@ try {
} }
// 需要永久存储,且在下次 APP 启动需要取出的,在 state 中的变量名。 // 需要永久存储,且在下次 APP 启动需要取出的,在 state 中的变量名。
let saveStateKeys = ['vuex_token'] let saveStateKeys = ['vuex_token', 'vuex_globalData']
// 保存变量到本地存储中 // 保存变量到本地存储中
const saveLifeData = function(key, value) { const saveLifeData = function(key, value) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment