| | |
| | | import store from '@/store' |
| | | import { getToken } from '@/utils/auth' |
| | | import { getUnreadCount } from '@/api/message' |
| | | import storage from '@/utils/storage' |
| | | |
| | | export default { |
| | | data() { |
| | |
| | | onLaunch: function() { |
| | | this.lastToken = getToken() |
| | | this.initApp() |
| | | |
| | | // 检查并清理存储空间 |
| | | this.checkStorage() |
| | | |
| | | // 监听用户登录事件 |
| | | uni.$on('user-login', () => { |
| | |
| | | clearInterval(this.messagePollingTimer) |
| | | this.messagePollingTimer = null |
| | | } |
| | | }, |
| | | |
| | | // 检查存储空间 |
| | | checkStorage() { |
| | | try { |
| | | // 获取存储信息 |
| | | const info = storage.getStorageInfo() |
| | | |
| | | if (info) { |
| | | const usagePercent = (info.currentSize / info.limitSize) * 100 |
| | | console.log(`💾 存储使用情况: ${usagePercent.toFixed(2)}% (${info.currentSize}KB / ${info.limitSize}KB)`) |
| | | |
| | | // 如果使用超过 80%,自动清理 |
| | | if (usagePercent > 80) { |
| | | console.warn('⚠️ 存储空间使用超过 80%,开始自动清理...') |
| | | storage.checkAndClean() |
| | | |
| | | // 再次检查 |
| | | const newInfo = storage.getStorageInfo() |
| | | if (newInfo) { |
| | | const newUsagePercent = (newInfo.currentSize / newInfo.limitSize) * 100 |
| | | console.log(`✅ 清理后使用情况: ${newUsagePercent.toFixed(2)}%`) |
| | | } |
| | | } |
| | | } |
| | | } catch (e) { |
| | | console.error('检查存储失败:', e) |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | "urlCheck" : false, |
| | | "es6" : false, |
| | | "minified" : true, |
| | | "postcss" : true |
| | | "postcss" : true, |
| | | "ignoreDevUnusedFiles" : false, |
| | | "ignoreUploadUnusedFiles" : false |
| | | }, |
| | | "optimization" : { |
| | | "subPackages" : true |
| | |
| | | "scope.userLocation" : { |
| | | "desc" : "需要自动获得当前用户位置,以判断司机是否在常驻地还是在目的地" |
| | | } |
| | | } |
| | | }, |
| | | "cloudfunctionRoot" : "", |
| | | "lazyCodeLoading" : "requiredComponents" |
| | | }, |
| | | "vueVersion" : "2", |
| | | "h5" : { |
| | |
| | | |
| | | // 第一步:从后端获取AccessToken |
| | | getWechatAccessToken().then(tokenResponse => { |
| | | const accessToken = tokenResponse.data || tokenResponse |
| | | // 接口返回格式:{"msg":"token值","code":200} |
| | | console.log('获取AccessToken成功:', tokenResponse) |
| | | const accessToken = tokenResponse.msg || tokenResponse.data || tokenResponse |
| | | if (!accessToken) { |
| | | uni.hideLoading() |
| | | that.$modal.showToast('获取AccessToken失败') |
| | | console.error('获取AccessToken失败,响应数据:', tokenResponse) |
| | | return |
| | | } |
| | | |
| | | console.log('获取到AccessToken:', accessToken) |
| | | |
| | | // 第二步:上传到微信服务器 |
| | | const uploadUrl = `https://api.weixin.qq.com/cgi-bin/media/upload?access_token=${accessToken}&type=image` |
| | | |
| | |
| | | }, |
| | | clean: function() { |
| | | uni.removeStorageSync(storageKey) |
| | | }, |
| | | // 新增:获取存储信息 |
| | | getStorageInfo: function() { |
| | | try { |
| | | const info = uni.getStorageInfoSync() |
| | | console.log('💾 存储信息:', { |
| | | keys: info.keys, |
| | | currentSize: info.currentSize, |
| | | limitSize: info.limitSize, |
| | | usage: ((info.currentSize / info.limitSize) * 100).toFixed(2) + '%' |
| | | }) |
| | | return info |
| | | } catch (e) { |
| | | console.error('获取存储信息失败:', e) |
| | | return null |
| | | } |
| | | }, |
| | | // 新增:清理所有存储(慎用) |
| | | clearAll: function() { |
| | | try { |
| | | uni.clearStorageSync() |
| | | console.log('✅ 清理所有存储成功') |
| | | } catch (e) { |
| | | console.error('清理存储失败:', e) |
| | | } |
| | | }, |
| | | // 新增:检查并清理过期数据 |
| | | checkAndClean: function() { |
| | | try { |
| | | const info = uni.getStorageInfoSync() |
| | | const usagePercent = (info.currentSize / info.limitSize) * 100 |
| | | |
| | | // 如果使用超过 80%,提示用户 |
| | | if (usagePercent > 80) { |
| | | console.warn('⚠️ 存储空间使用超过 80%:', usagePercent.toFixed(2) + '%') |
| | | |
| | | // 自动清理非必要的缓存 |
| | | const keysToKeep = [storageKey, 'token', 'uni-id-pages-userInfo'] |
| | | info.keys.forEach(key => { |
| | | if (!keysToKeep.includes(key)) { |
| | | try { |
| | | uni.removeStorageSync(key) |
| | | console.log('🗑️ 清理缓存:', key) |
| | | } catch (e) { |
| | | console.error('清理失败:', key, e) |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | } catch (e) { |
| | | console.error('检查存储失败:', e) |
| | | } |
| | | } |
| | | } |
| | | |