diff --git a/pages/profile/index/index.vue b/pages/profile/index/index.vue index 3e29196..358b9a4 100644 --- a/pages/profile/index/index.vue +++ b/pages/profile/index/index.vue @@ -70,8 +70,8 @@ export default { }, { idx: 6, - title: "清理缓存", - icon: require("static/images/profile_menu_about.png"), + title: "清除缓存", + icon: require("static/images/profile_menu_account.png"), }, { idx: 7, @@ -110,6 +110,9 @@ export default { uni.removeStorage({ key: "BusinessToken", }); + uni.removeStorage({ + key: 'oaToken' + }) }) .catch((err) => console.log(err)) .finally(() => { @@ -178,6 +181,36 @@ export default { url: `/pages/common/userOrGroupQrCode/index`, }); }, + clearCache() { + uni.showModal({ + title: "提示", + content: "确定要清除缓存吗?这将清除oaToken等缓存数据。", + confirmText: "确认", + cancelText: "取消", + success: (res) => { + if (res.confirm) { + // 清除oaToken + uni.removeStorage({ + key: 'oaToken', + success: () => { + console.log('oaToken已清除'); + }, + fail: (err) => { + console.log('清除oaToken失败:', err); + } + }); + + // 可以在这里添加其他需要清除的缓存 + // 例如清除其他相关的存储数据 + + uni.showToast({ + icon: "success", + title: "缓存清除成功", + }); + } + }, + }); + }, showUpdateOptions() { const ignoredVersion = uni.$updateManager.getIgnoredVersion(); let content = '选择更新操作:'; @@ -213,82 +246,6 @@ export default { } }); }, - clearCache() { - uni.showModal({ - title: "清理缓存", - content: "确定要清理应用缓存吗?清理后需要重新登录。", - confirmText: "确认清理", - cancelText: "取消", - success: (res) => { - if (res.confirm) { - uni.showLoading({ - title: '清理中...' - }); - - // 清理本地存储 - const clearStorageKeys = [ - 'IMToken', - 'BusinessToken', - 'userInfo', - 'conversationList', - 'messageList', - 'contactList' - ]; - - clearStorageKeys.forEach(key => { - try { - uni.removeStorageSync(key); - } catch (e) { - console.log(`清理缓存失败: ${key}`, e); - } - }); - - // 清理文件缓存 - uni.getSavedFileList({ - success: (fileRes) => { - if (fileRes.fileList && fileRes.fileList.length > 0) { - fileRes.fileList.forEach(file => { - uni.removeSavedFile({ - filePath: file.filePath, - success: () => { - console.log('文件缓存清理成功:', file.filePath); - }, - fail: (err) => { - console.log('文件缓存清理失败:', file.filePath, err); - } - }); - }); - } - }, - fail: (err) => { - console.log('获取文件列表失败:', err); - } - }); - - // 清理图片缓存 - uni.getImageInfo({ - src: '/static/images/default_avatar.png', - success: () => { - // 这里可以添加更多图片缓存清理逻辑 - } - }); - - setTimeout(() => { - uni.hideLoading(); - uni.showToast({ - title: '缓存清理完成', - icon: 'success' - }); - - // 清理完成后跳转到登录页 - setTimeout(() => { - uni.$u.route("/pages/login/index"); - }, 1500); - }, 1000); - } - } - }); - }, }, }; diff --git a/pages/workbench/index/index.vue b/pages/workbench/index/index.vue index d02a9cc..dfb5ef6 100644 --- a/pages/workbench/index/index.vue +++ b/pages/workbench/index/index.vue @@ -24,12 +24,31 @@ diff --git a/util/oaRequest.js b/util/oaRequest.js index 1adab92..35c9b0e 100644 --- a/util/oaRequest.js +++ b/util/oaRequest.js @@ -1,12 +1,25 @@ import { getToken } from './auth' import errorCode from './errorCode' -import { toast, showConfirm, tansParams } from './common' +import { toast, tansParams } from './common' import { getSMSCodeFromOa, loginOaByPhone } from '../api/oa/login' let timeout = 10000 const baseUrl = 'http://110.41.139.73:8080' // const baseUrl = 'http://localhost:8080' +// 显示loading提示 +const showLoading = (title = '正在重新登录...') => { + uni.showLoading({ + title: title, + mask: true + }) +} + +// 隐藏loading提示 +const hideLoading = () => { + uni.hideLoading() +} + const request = config => { // 是否需要设置 token const isToken = (config.headers || {}).isToken === false @@ -50,30 +63,25 @@ const request = config => { const code = res.data.code || 200 const msg = errorCode[code] || res.data.msg || errorCode['default'] if (code === 401) { - showConfirm('登录状态已过期,是否刷新登录状态').then(async res => { - if (res.confirm) { - // 从store中获取phoneNumber,并依次调用getSMSCodeFromOa和loginOaByPhone - const store = require('@/store').default - const phoneNumber = store.getters.storeSelfInfo?.phoneNumber - if (phoneNumber) { - try { - await getSMSCodeFromOa(phoneNumber) - await loginOaByPhone(phoneNumber) - const pages = getCurrentPages(); - const page = pages[pages.length - 1]; - // 重新加载当前页面 - if (page && page.onLoad) { - page.onLoad(page.options || {}); - } - } catch (e) { - console.log('OA自动登录失败', e) - toast('OA自动登录失败') - } - } else { - toast('无法获取手机号,OA自动登录失败') - } + // 显示loading提示 + showLoading() + // 从store中获取phoneNumber,并依次调用getSMSCodeFromOa和loginOaByPhone + const store = require('@/store').default + const phoneNumber = store.getters.storeSelfInfo?.phoneNumber + if (phoneNumber) { + try { + await getSMSCodeFromOa(phoneNumber) + await loginOaByPhone(phoneNumber) + hideLoading() + } catch (e) { + hideLoading() + console.log('OA自动登录失败', e) + toast('OA自动登录失败') } - }) + } else { + hideLoading() + toast('无法获取手机号,OA自动登录失败') + } reject('无效的会话,或者会话已过期,请重新登录。') } else if (code === 500) { toast(msg)