wangfukang 2 weeks ago
parent
commit
bd540499a5
  1. 23
      components/tab-bar/myCenter.vue

23
components/tab-bar/myCenter.vue

@ -276,7 +276,7 @@
}) })
}, },
userName() { userName() {
return uni.getStorageSync('nickName') || uni.getStorageSync('nickname') || uni.getStorageSync('userName') || '张昊雯' return uni.getStorageSync('nickName') || uni.getStorageSync('nickname') || uni.getStorageSync('userName') || '半径同学'
}, },
avatarText() { avatarText() {
return (this.userName || '张').slice(0, 1) return (this.userName || '张').slice(0, 1)
@ -421,8 +421,24 @@
saveMyCenterImageCache(cache) { saveMyCenterImageCache(cache) {
uni.setStorageSync(MY_CENTER_IMAGE_CACHE_KEY, cache) uni.setStorageSync(MY_CENTER_IMAGE_CACHE_KEY, cache)
}, },
isSavedFileExists(filePath) {
if (!filePath || filePath.indexOf('__tmp__') !== -1) return false
try {
const fs = (uni.getFileSystemManager && uni.getFileSystemManager())
|| (typeof wx !== 'undefined' && wx.getFileSystemManager ? wx.getFileSystemManager() : null)
if (fs && fs.accessSync) {
fs.accessSync(filePath)
return true
}
} catch (e) {
return false
}
return true
},
isMyCenterImageCacheValid(cacheItem) { isMyCenterImageCacheValid(cacheItem) {
return !!(cacheItem && cacheItem.path && cacheItem.path.indexOf('__tmp__') === -1 && Date.now() - Number(cacheItem.savedAt || 0) < MY_CENTER_IMAGE_CACHE_TTL) return !!(cacheItem
&& Date.now() - Number(cacheItem.savedAt || 0) < MY_CENTER_IMAGE_CACHE_TTL
&& this.isSavedFileExists(cacheItem.path))
}, },
applyCachedMyCenterImages() { applyCachedMyCenterImages() {
const cache = this.getMyCenterImageCache() const cache = this.getMyCenterImageCache()
@ -433,6 +449,9 @@
this.$set(this.myCenterImages, key, cacheItem.path) this.$set(this.myCenterImages, key, cacheItem.path)
return return
} }
if (cacheItem && cacheItem.path) {
delete cache[imageUrl]
}
this.$set(this.myCenterImages, key, imageUrl) this.$set(this.myCenterImages, key, imageUrl)
this.cacheMyCenterImage(key, imageUrl) this.cacheMyCenterImage(key, imageUrl)
}) })

Loading…
Cancel
Save