Commit 06f09782 authored by leon's avatar leon

feat:add data localstoarge

parent 97847911
......@@ -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,18 @@
}
}
that.reportInfo = res.data.Result
// 清除数据
if(uni.getStorageSync('reportInfo')) {
let info = JSON.parse(uni.getStorageSync('reportInfo'))
info.list.forEach(item => {
// 如果本地缓存的数组在接口请求的数组中不存在,则删除
if(!that.reportInfo.list.some(idx => idx.id == item.id)) {
uni.removeStorageSync(item.id)
}
})
}
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