fix: allow bound tenant option loading
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user