fix: allow bound tenant option loading

This commit is contained in:
richjohnrambo
2026-09-25 23:27:11 +08:00
parent fce8dbbe32
commit 9e01f95a61
3 changed files with 38 additions and 13 deletions
+8 -13
View File
@@ -31,17 +31,8 @@ export async function loadImTenantOptions(
// 登录用户已绑定商户租户:仅返回自己商户选项(与后端 resolveImAdminScope 强制范围一致)
if (boundTenantId > 0) {
let tenant: any = null;
try {
const res = await TenantList({ ...params, id: boundTenantId, page: 1, perPage: 1 });
tenant = (res?.list || []).find((item) => Number(item.id) === boundTenantId);
} catch {
tenant = null;
}
if (!tenant) {
const info = readTokenUserInfo(useUserStore().getToken);
tenant = { id: boundTenantId, name: info?.tenantName, code: info?.tenantCode };
}
const info = readCurrentUserInfo();
const tenant = { id: boundTenantId, name: info?.tenantName, code: info?.tenantCode };
target.value = [toTenantOption(tenant)];
return target.value;
}
@@ -58,8 +49,7 @@ export async function loadImTenantOptions(
// 登录用户绑定的商户租户ID(按绑定租户判定,与后端 resolveImAdminScope 的范围逻辑一致)
export function getBoundTenantId(): number {
const userStore = useUserStore();
const userInfo = { ...readTokenUserInfo(userStore.getToken), ...(userStore.getUserInfo as any) };
const userInfo = readCurrentUserInfo();
return Number(userInfo?.tenantId || userInfo?.tenantID || 0);
}
@@ -109,6 +99,11 @@ function toTenantOption(item: any): ImTenantOption {
};
}
function readCurrentUserInfo() {
const userStore = useUserStore();
return { ...readTokenUserInfo(userStore.getToken), ...(userStore.getUserInfo as any) };
}
function readTokenUserInfo(token: string) {
try {
const payload = token.split('.')[1];