141 lines
5.3 KiB
JavaScript
141 lines
5.3 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const request_identity = require("../../request/identity.js");
|
|
const utils_identitySwitch = require("../../utils/identitySwitch.js");
|
|
if (!Array) {
|
|
const _easycom_u_loading_icon2 = common_vendor.resolveComponent("u-loading-icon");
|
|
_easycom_u_loading_icon2();
|
|
}
|
|
const _easycom_u_loading_icon = () => "../../uni_modules/uview-plus/components/u-loading-icon/u-loading-icon.js";
|
|
if (!Math) {
|
|
_easycom_u_loading_icon();
|
|
}
|
|
const _sfc_main = {
|
|
__name: "identity",
|
|
setup(__props) {
|
|
const loading = common_vendor.ref(false);
|
|
const switchingId = common_vendor.ref(null);
|
|
const identityList = common_vendor.ref([]);
|
|
const currentIdentity = common_vendor.ref(null);
|
|
function unwrapIdentityData(res) {
|
|
if (!res)
|
|
return { identities: [], currentIdentity: null };
|
|
const data = res.data && typeof res.data === "object" ? res.data : res;
|
|
return {
|
|
identities: data.identities || [],
|
|
currentIdentity: data.currentIdentity || null
|
|
};
|
|
}
|
|
function getIdentityTitle(item) {
|
|
return item.identityName || item.roleName || "未命名身份";
|
|
}
|
|
function getIdentitySubtitle(item) {
|
|
const parts = [];
|
|
if (item.deptName)
|
|
parts.push(item.deptName);
|
|
if (item.roleName && item.roleName !== item.identityName)
|
|
parts.push(item.roleName);
|
|
return parts.join(" · ") || "-";
|
|
}
|
|
function isCurrentIdentity(item) {
|
|
if (item.current)
|
|
return true;
|
|
return currentIdentity.value && currentIdentity.value.identityId === item.identityId;
|
|
}
|
|
async function fetchIdentityList() {
|
|
loading.value = true;
|
|
try {
|
|
const res = await request_identity.getMyIdentity();
|
|
if (res.code === 0 || res.code === 200) {
|
|
const { identities, currentIdentity: current } = unwrapIdentityData(res);
|
|
identityList.value = identities;
|
|
currentIdentity.value = current;
|
|
} else {
|
|
identityList.value = [];
|
|
currentIdentity.value = null;
|
|
common_vendor.index.showToast({ title: res.msg || "获取身份列表失败", icon: "none" });
|
|
}
|
|
} catch (e) {
|
|
common_vendor.index.__f__("error", "at pages/personalcenter/identity.vue:123", "获取身份列表失败:", e);
|
|
identityList.value = [];
|
|
currentIdentity.value = null;
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
async function handleSwitch(item) {
|
|
if (isCurrentIdentity(item) || switchingId.value)
|
|
return;
|
|
const identityName = getIdentityTitle(item);
|
|
const confirmMsg = `确认切换到「${identityName}」吗?切换后数据将按新身份刷新。`;
|
|
common_vendor.index.showModal({
|
|
title: "切换身份",
|
|
content: confirmMsg,
|
|
confirmText: "确认切换",
|
|
success: async (modalRes) => {
|
|
if (!modalRes.confirm)
|
|
return;
|
|
switchingId.value = item.identityId;
|
|
try {
|
|
await utils_identitySwitch.performIdentitySwitch(item.identityId);
|
|
utils_identitySwitch.reLaunchAfterSwitch();
|
|
} catch (e) {
|
|
common_vendor.index.__f__("error", "at pages/personalcenter/identity.vue:149", "身份切换失败:", e);
|
|
} finally {
|
|
switchingId.value = null;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
common_vendor.onShow(() => {
|
|
fetchIdentityList();
|
|
});
|
|
return (_ctx, _cache) => {
|
|
return common_vendor.e({
|
|
a: currentIdentity.value
|
|
}, currentIdentity.value ? {
|
|
b: common_vendor.t(getIdentityTitle(currentIdentity.value)),
|
|
c: common_vendor.t(getIdentitySubtitle(currentIdentity.value))
|
|
} : {}, {
|
|
d: loading.value
|
|
}, loading.value ? {
|
|
e: common_vendor.p({
|
|
mode: "circle",
|
|
color: "#007aff"
|
|
})
|
|
} : !identityList.value.length ? {} : {
|
|
g: common_vendor.f(identityList.value, (item, k0, i0) => {
|
|
return common_vendor.e({
|
|
a: common_vendor.t(getIdentityTitle(item)),
|
|
b: isCurrentIdentity(item)
|
|
}, isCurrentIdentity(item) ? {} : {}, {
|
|
c: item.isDefault
|
|
}, item.isDefault ? {} : {}, {
|
|
d: common_vendor.t(item.deptName || "-"),
|
|
e: common_vendor.t(item.roleName || "-"),
|
|
f: common_vendor.t(item.roleKey || "-"),
|
|
g: item.postName
|
|
}, item.postName ? {
|
|
h: common_vendor.t(item.postName)
|
|
} : {}, {
|
|
i: common_vendor.t(isCurrentIdentity(item) ? "当前使用中" : "切换到此身份"),
|
|
j: isCurrentIdentity(item) ? 1 : "",
|
|
k: switchingId.value === item.identityId,
|
|
l: isCurrentIdentity(item) || !!switchingId.value,
|
|
m: common_vendor.o(($event) => handleSwitch(item), item.identityId),
|
|
n: item.identityId,
|
|
o: isCurrentIdentity(item) ? 1 : "",
|
|
p: item.isDefault ? 1 : ""
|
|
});
|
|
})
|
|
}, {
|
|
f: !identityList.value.length,
|
|
h: common_vendor.gei(_ctx, "")
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-a3555b62"]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/personalcenter/identity.js.map
|