| | |
| | | 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) |
| | | } |
| | | } |
| | | } |
| | | } |