一单四制优化及加入工作流

This commit is contained in:
王利强
2026-07-27 09:27:22 +08:00
parent 455fd4fc07
commit 7c3285ed5a
725 changed files with 19668 additions and 2921 deletions

56
utils/identitySwitch.js Normal file
View File

@@ -0,0 +1,56 @@
import { switchIdentity } from '@/request/identity.js';
import { getProfileDetail } from '@/request/three_one_api/info.js';
import { saveUserInfoToStorage } from '@/utils/userInfo.js';
function unwrapPayload(res) {
if (!res) return {};
const data = res.data;
if (data && typeof data === 'object' && (
data.token ||
data.identities ||
data.currentIdentity ||
data.roles
)) {
return data;
}
return res;
}
/** 根据个人信息接口刷新本地 userInfo */
export async function refreshUserInfoStorage() {
const res = await getProfileDetail();
if (res.code === 0 && res.data) {
return saveUserInfoToStorage(res.data);
}
return null;
}
/** 执行身份切换:更新 token再通过 profile 接口刷新 userInfo */
export async function performIdentitySwitch(identityId) {
const res = await switchIdentity(identityId);
const payload = unwrapPayload(res);
if (payload.token) {
uni.setStorageSync('token', payload.token);
}
if (payload.currentIdentity) {
uni.setStorageSync('currentIdentity', JSON.stringify(payload.currentIdentity));
}
await refreshUserInfoStorage();
return payload;
}
/** 切换成功后重启到首页,清空页面栈 */
export function reLaunchAfterSwitch() {
uni.showToast({
title: '身份切换成功',
icon: 'success'
});
setTimeout(() => {
uni.reLaunch({
url: '/pages/index/index'
});
}, 1500);
}