Commit 1dc9a745 authored by Jenny's avatar Jenny

feat: 数据缓存

parent 1286a517
......@@ -14,12 +14,14 @@ export default {
}
},
methods: {
setStorageData() {
uni.setStorageSync(this.elementInfo.id, JSON.stringify(this.elementData.dataList))
},
/**
* 静态数据
*/
handleStaticData(value) {
this.elementData.dataList = JSON.parse(JSON.stringify({...value.dataList}))
this.initChart()
},
/**
* 动态数据
......@@ -36,7 +38,6 @@ export default {
} else {
that.elementData.dataList = JSON.parse(JSON.stringify(res.data.Result))
}
this.initChart()
},
/**
* 全局数据
......@@ -49,7 +50,6 @@ export default {
} else {
this.elementData.dataList = this.vuex_globalData
}
this.initChart()
},
/**
* 配置数据 - 数据集
......@@ -65,7 +65,6 @@ export default {
} else {
that.elementData.dataList = res.data.Result
}
this.initChart()
} else {
that.$u.toast(Msg)
}
......@@ -82,7 +81,6 @@ export default {
const { Status, Msg, Result } = res.data
if (Status === 'true') {
that.elementData.dataList = Result
this.initChart()
}else {
message.warning(Msg)
}
......@@ -117,6 +115,10 @@ export default {
'elementInfo.data': {
handler(newVal) {
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 (newVal.dataType === 'static') {
that.handleStaticData(newVal)
......@@ -159,6 +161,14 @@ export default {
*/
'vuex_globalData' () {
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 @@
// detail页面也会监听这两个事件,所有index页面需要在onShow里面增加监听,在onHide里面移除监听
onShow() {
const that = this
if(uni.getStorageSync('reportInfo')) {
this.reportInfo = JSON.parse(uni.getStorageSync('reportInfo'))
}
/**
* 组件交互 - 参数
*/
......@@ -222,6 +225,7 @@
}
}
that.reportInfo = res.data.Result
uni.setStorageSync('reportInfo', JSON.stringify(res.data.Result))
that.getStickyTables()
}
},
......
......@@ -12,7 +12,7 @@ try {
}
// 需要永久存储,且在下次 APP 启动需要取出的,在 state 中的变量名。
let saveStateKeys = ['vuex_token']
let saveStateKeys = ['vuex_token', 'vuex_globalData']
// 保存变量到本地存储中
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