Commit fee2dee1 authored by Damon's avatar Damon

请求更新逻辑

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