48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../common/vendor.js");
|
|
const request_identity = require("../request/identity.js");
|
|
const request_three_one_api_info = require("../request/three_one_api/info.js");
|
|
const utils_userInfo = require("./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;
|
|
}
|
|
async function refreshUserInfoStorage() {
|
|
const res = await request_three_one_api_info.getProfileDetail();
|
|
if (res.code === 0 && res.data) {
|
|
return utils_userInfo.saveUserInfoToStorage(res.data);
|
|
}
|
|
return null;
|
|
}
|
|
async function performIdentitySwitch(identityId) {
|
|
const res = await request_identity.switchIdentity(identityId);
|
|
const payload = unwrapPayload(res);
|
|
if (payload.token) {
|
|
common_vendor.index.setStorageSync("token", payload.token);
|
|
}
|
|
if (payload.currentIdentity) {
|
|
common_vendor.index.setStorageSync("currentIdentity", JSON.stringify(payload.currentIdentity));
|
|
}
|
|
await refreshUserInfoStorage();
|
|
return payload;
|
|
}
|
|
function reLaunchAfterSwitch() {
|
|
common_vendor.index.showToast({
|
|
title: "身份切换成功",
|
|
icon: "success"
|
|
});
|
|
setTimeout(() => {
|
|
common_vendor.index.reLaunch({
|
|
url: "/pages/index/index"
|
|
});
|
|
}, 1500);
|
|
}
|
|
exports.performIdentitySwitch = performIdentitySwitch;
|
|
exports.reLaunchAfterSwitch = reLaunchAfterSwitch;
|
|
//# sourceMappingURL=../../.sourcemap/mp-weixin/utils/identitySwitch.js.map
|