oa自动登录
This commit is contained in:
@@ -70,8 +70,8 @@ export default {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
idx: 6,
|
idx: 6,
|
||||||
title: "清理缓存",
|
title: "清除缓存",
|
||||||
icon: require("static/images/profile_menu_about.png"),
|
icon: require("static/images/profile_menu_account.png"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
idx: 7,
|
idx: 7,
|
||||||
@@ -110,6 +110,9 @@ export default {
|
|||||||
uni.removeStorage({
|
uni.removeStorage({
|
||||||
key: "BusinessToken",
|
key: "BusinessToken",
|
||||||
});
|
});
|
||||||
|
uni.removeStorage({
|
||||||
|
key: 'oaToken'
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.catch((err) => console.log(err))
|
.catch((err) => console.log(err))
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
@@ -178,6 +181,36 @@ export default {
|
|||||||
url: `/pages/common/userOrGroupQrCode/index`,
|
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() {
|
showUpdateOptions() {
|
||||||
const ignoredVersion = uni.$updateManager.getIgnoredVersion();
|
const ignoredVersion = uni.$updateManager.getIgnoredVersion();
|
||||||
let content = '选择更新操作:';
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -24,12 +24,31 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import CustomNavBar from '@/components/CustomNavBar/index.vue';
|
import CustomNavBar from '@/components/CustomNavBar/index.vue';
|
||||||
|
import { getUserProfile } from '@/api/oa/user.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "WorkbenchIndex",
|
name: "WorkbenchIndex",
|
||||||
components: {
|
components: {
|
||||||
CustomNavBar,
|
CustomNavBar,
|
||||||
},
|
},
|
||||||
|
onShow() {
|
||||||
|
console.log('页面onLoad被调用');
|
||||||
|
// 页面加载时调用getUserProfile
|
||||||
|
this.fetchUserProfile();
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
// 获取用户个人信息
|
||||||
|
async fetchUserProfile() {
|
||||||
|
console.log('fetchUserProfile方法开始执行');
|
||||||
|
try {
|
||||||
|
console.log('开始调用getUserProfile API');
|
||||||
|
const response = await getUserProfile();
|
||||||
|
console.log('用户个人信息:', response);
|
||||||
|
// 这里可以根据需要处理返回的用户信息
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取用户个人信息失败:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
goReportWork() {
|
goReportWork() {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/workbench/reportWork/reportWork'
|
url: '/pages/workbench/reportWork/reportWork'
|
||||||
@@ -45,7 +64,7 @@ export default {
|
|||||||
url: '/pages/workbench/task/task'
|
url: '/pages/workbench/task/task'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,25 @@
|
|||||||
import { getToken } from './auth'
|
import { getToken } from './auth'
|
||||||
import errorCode from './errorCode'
|
import errorCode from './errorCode'
|
||||||
import { toast, showConfirm, tansParams } from './common'
|
import { toast, tansParams } from './common'
|
||||||
import { getSMSCodeFromOa, loginOaByPhone } from '../api/oa/login'
|
import { getSMSCodeFromOa, loginOaByPhone } from '../api/oa/login'
|
||||||
|
|
||||||
let timeout = 10000
|
let timeout = 10000
|
||||||
const baseUrl = 'http://110.41.139.73:8080'
|
const baseUrl = 'http://110.41.139.73:8080'
|
||||||
// const baseUrl = 'http://localhost:8080'
|
// const baseUrl = 'http://localhost:8080'
|
||||||
|
|
||||||
|
// 显示loading提示
|
||||||
|
const showLoading = (title = '正在重新登录...') => {
|
||||||
|
uni.showLoading({
|
||||||
|
title: title,
|
||||||
|
mask: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 隐藏loading提示
|
||||||
|
const hideLoading = () => {
|
||||||
|
uni.hideLoading()
|
||||||
|
}
|
||||||
|
|
||||||
const request = config => {
|
const request = config => {
|
||||||
// 是否需要设置 token
|
// 是否需要设置 token
|
||||||
const isToken = (config.headers || {}).isToken === false
|
const isToken = (config.headers || {}).isToken === false
|
||||||
@@ -50,30 +63,25 @@ const request = config => {
|
|||||||
const code = res.data.code || 200
|
const code = res.data.code || 200
|
||||||
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
||||||
if (code === 401) {
|
if (code === 401) {
|
||||||
showConfirm('登录状态已过期,是否刷新登录状态').then(async res => {
|
// 显示loading提示
|
||||||
if (res.confirm) {
|
showLoading()
|
||||||
// 从store中获取phoneNumber,并依次调用getSMSCodeFromOa和loginOaByPhone
|
// 从store中获取phoneNumber,并依次调用getSMSCodeFromOa和loginOaByPhone
|
||||||
const store = require('@/store').default
|
const store = require('@/store').default
|
||||||
const phoneNumber = store.getters.storeSelfInfo?.phoneNumber
|
const phoneNumber = store.getters.storeSelfInfo?.phoneNumber
|
||||||
if (phoneNumber) {
|
if (phoneNumber) {
|
||||||
try {
|
try {
|
||||||
await getSMSCodeFromOa(phoneNumber)
|
await getSMSCodeFromOa(phoneNumber)
|
||||||
await loginOaByPhone(phoneNumber)
|
await loginOaByPhone(phoneNumber)
|
||||||
const pages = getCurrentPages();
|
hideLoading()
|
||||||
const page = pages[pages.length - 1];
|
} catch (e) {
|
||||||
// 重新加载当前页面
|
hideLoading()
|
||||||
if (page && page.onLoad) {
|
console.log('OA自动登录失败', e)
|
||||||
page.onLoad(page.options || {});
|
toast('OA自动登录失败')
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log('OA自动登录失败', e)
|
|
||||||
toast('OA自动登录失败')
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast('无法获取手机号,OA自动登录失败')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
|
hideLoading()
|
||||||
|
toast('无法获取手机号,OA自动登录失败')
|
||||||
|
}
|
||||||
reject('无效的会话,或者会话已过期,请重新登录。')
|
reject('无效的会话,或者会话已过期,请重新登录。')
|
||||||
} else if (code === 500) {
|
} else if (code === 500) {
|
||||||
toast(msg)
|
toast(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user