@liujitcn/kratos-admin-core 0.0.88 → 0.0.89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,6 +42,8 @@ export interface UserInfoForm {
42
42
  tenant_code: string;
43
43
  /** 租户名称 */
44
44
  tenant_name: string;
45
+ /** 当前用户所属租户ID */
46
+ tenant_id: number;
45
47
  }
46
48
  /** 获取个人中心用户信息请求参数 */
47
49
  export interface GetUserProfileRequest {
@@ -11,6 +11,8 @@ export declare function requestTenantCodeOptions(): Promise<{
11
11
  export interface TenantScope {
12
12
  /** 当前账号是否为默认租户。 */
13
13
  isDefaultTenant: ComputedRef<boolean>;
14
+ /** 当前账号所属租户编号。 */
15
+ currentTenantId: ComputedRef<number | undefined>;
14
16
  /** 当前账号可用的租户选项。 */
15
17
  tenantOptions: Ref<SelectOptionResponse_Option[]>;
16
18
  /** 租户选项名称映射。 */
@@ -90,19 +90,20 @@ watch(
90
90
  );
91
91
 
92
92
  /** 退出登录并清理当前登录态。 */
93
- const logout = () => {
94
- ElMessageBox.confirm(t("core.layout.logout_confirm"), t("common.title.warning"), {
93
+ const logout = async () => {
94
+ const confirmed = await ElMessageBox.confirm(t("core.layout.logout_confirm"), t("common.title.warning"), {
95
95
  confirmButtonText: t("common.action.confirm"),
96
96
  cancelButtonText: t("common.action.cancel"),
97
97
  type: "warning"
98
- }).then(async () => {
99
- // 1.执行退出登录接口并清理本地状态
100
- await userStore.logout();
98
+ }).then(() => true).catch(() => false);
99
+ if (!confirmed) return;
101
100
 
102
- // 2.重定向到登录页
103
- router.replace(LOGIN_URL);
104
- ElMessage.success(t("core.layout.logout_success"));
105
- });
101
+ // 1.执行退出登录接口并清理本地状态
102
+ await userStore.logout();
103
+
104
+ // 2.等待重定向到登录页完成
105
+ await router.replace(LOGIN_URL);
106
+ ElMessage.success(t("core.layout.logout_success"));
106
107
  };
107
108
 
108
109
  /** 头像加载失败时兜底显示默认头像,避免出现破图。 */
@@ -54,6 +54,8 @@ export interface UserInfoForm {
54
54
  tenant_code: string;
55
55
  /** 租户名称 */
56
56
  tenant_name: string;
57
+ /** 当前用户所属租户ID */
58
+ tenant_id: number;
57
59
  }
58
60
 
59
61
  /** 获取个人中心用户信息请求参数 */
@@ -11,6 +11,7 @@ import { useDictStoreHook } from "../../stores/modules/dict";
11
11
  import { useLockScreenStore } from "../../stores/modules/lockScreen";
12
12
  import { useAuthStore } from "../../stores/modules/auth";
13
13
  import { useConfigStore } from "../../stores/modules/config";
14
+ import { invalidateTenantOptions } from "../../utils/tenant";
14
15
 
15
16
  const defaultUserInfo: UserInfoForm = {
16
17
  user_name: "",
@@ -24,7 +25,8 @@ const defaultUserInfo: UserInfoForm = {
24
25
  role_name: "",
25
26
  dept_name: "",
26
27
  tenant_code: "",
27
- tenant_name: ""
28
+ tenant_name: "",
29
+ tenant_id: 0
28
30
  };
29
31
 
30
32
  export const useUserStore = defineStore("admin-user", {
@@ -99,6 +101,7 @@ export const useUserStore = defineStore("admin-user", {
99
101
  clearAuthData() {
100
102
  // 清理登录态时同步清空字典缓存,避免切换账号后读到旧字典。
101
103
  useDictStoreHook().clearDictionaryCache();
104
+ invalidateTenantOptions();
102
105
  useLockScreenStore().clearLock();
103
106
  useAuthStore().$reset();
104
107
  useConfigStore().resetI18nCustom();
@@ -29,6 +29,8 @@ export async function requestTenantCodeOptions() {
29
29
  export interface TenantScope {
30
30
  /** 当前账号是否为默认租户。 */
31
31
  isDefaultTenant: ComputedRef<boolean>;
32
+ /** 当前账号所属租户编号。 */
33
+ currentTenantId: ComputedRef<number | undefined>;
32
34
  /** 当前账号可用的租户选项。 */
33
35
  tenantOptions: Ref<SelectOptionResponse_Option[]>;
34
36
  /** 租户选项名称映射。 */
@@ -87,6 +89,10 @@ export interface TenantColumnOptions {
87
89
  export function useTenantScope(): TenantScope {
88
90
  const userStore = useUserStore();
89
91
  const isDefaultTenant = computed(() => userStore.userInfo.tenant_code === DEFAULT_TENANT_CODE);
92
+ const currentTenantId = computed(() => {
93
+ const tenantId = Number(userStore.userInfo.tenant_id);
94
+ return Number.isFinite(tenantId) && tenantId > 0 ? tenantId : undefined;
95
+ });
90
96
  const tenantOptions = ref<SelectOptionResponse_Option[]>([]);
91
97
  const tenantNameMap = computed(() => new Map(tenantOptions.value.map(item => [String(item.value), item.label] as const)));
92
98
 
@@ -155,6 +161,7 @@ export function useTenantScope(): TenantScope {
155
161
 
156
162
  return {
157
163
  isDefaultTenant,
164
+ currentTenantId,
158
165
  tenantOptions,
159
166
  tenantNameMap,
160
167
  loadTenantOptions,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@liujitcn/kratos-admin-core",
3
3
  "private": false,
4
- "version": "0.0.88",
4
+ "version": "0.0.89",
5
5
  "type": "module",
6
6
  "description": "kratos-admin frontend runtime and base modules",
7
7
  "author": {