Commit fee2dee1 authored by Damon's avatar Damon

请求更新逻辑

parent ac2fe61f
......@@ -8,7 +8,7 @@ import {
AnalysysAgent
} from '@/utils/analysys_paas.js'
import util from '@/utils/util.js'
import cache from '@/common/cache.js'
export default {
globalData: {
......@@ -123,7 +123,8 @@ export default {
}
},
// 用户信息
tempUserInfo: '', // 临时用户选项
tempUserInfo: '', // 临时用户选项
cacheUpdate: false, // 是否更新缓存
},
onLaunch: function () {
......@@ -185,7 +186,9 @@ export default {
content: '新版本已经准备好,是否重启应用?',
success(res) {
if (res.confirm) {
uni.clearStorageSync() // 清空本地缓存
const version = cache.getCache('version')
uni.clearStorageSync() // 清空本地缓存
cache.setCache('version', version) // 保存图片更新的版本号
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
......
......@@ -18,6 +18,7 @@
</template>
<script>
import cache from '../../common/cache.js'
export default {
data() {
return {
......@@ -68,6 +69,7 @@
},
onLoad(e) {
getApp().trackPage('选择产品页')
this.getPhotoUpdate()
this.getRelationDictionaryV2()
},
onShareAppMessage(res) {
......@@ -81,6 +83,20 @@
return shareObj
},
methods: {
getPhotoUpdate: function() {
const globalData = getApp().globalData
const version = cache.getCache('version')
this.$u.cloudApi.isUpdateImageCache({version: version || 0}).then(res=>{
if (res.result) {
if (!version) {
cache.setCache('version', 1)
} else {
cache.setCache('version', parseInt(version) + 1)
}
globalData.cacheUpdate = true
}
})
},
getRelationDictionaryV2: function() {
this.$u.cloudApi.getRelationDictionaryV2().then(res => {
if (res && res.result) {
......
......@@ -140,19 +140,20 @@
},
methods: {
checkData: function() {
const checkResult = cache.checkCache(this.systemId)
const checkResult = cache.checkCache(this.systemId) // 没有缓存数据则请求
if (!checkResult) {
this.getListData()
return
}
const data = cache.getCache(this.systemId)
const validityTime = 3600000 * 24 * 30 // 30天重新获取一次最新规范
const globalData = getApp().globalData
this.loading = false
if (data.loadTime - Date.now() < validityTime) { // 有效期内,读取缓存
if (!globalData.cacheUpdate) { // 无需更新,读取缓存
this.loading = false
this.handleData(data.result)
} else {
globalData.cacheUpdate = false // 重置更新
this.getListData()
}
......
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