@liujitcn/kratos-admin-core 0.0.87 → 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.
- package/dist/package/declarations/src/rpc/system/admin/v1/auth.d.ts +2 -0
- package/dist/package/declarations/src/tenant.d.ts +2 -0
- package/dist/package/src/layouts/components/Header/components/Avatar.vue +10 -9
- package/dist/package/src/rpc/system/admin/v1/auth.ts +2 -0
- package/dist/package/src/stores/modules/user.ts +4 -1
- package/dist/package/src/tenant.ts +7 -0
- package/dist/package/src/utils/request.ts +13 -1
- package/package.json +1 -1
|
@@ -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(
|
|
99
|
-
|
|
100
|
-
await userStore.logout();
|
|
98
|
+
}).then(() => true).catch(() => false);
|
|
99
|
+
if (!confirmed) return;
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
/** 头像加载失败时兜底显示默认头像,避免出现破图。 */
|
|
@@ -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,
|
|
@@ -59,6 +59,18 @@ const AUTH_EXPIRED_EXCLUDED_URL_SET = new Set([
|
|
|
59
59
|
MFA_ENROLLMENT_CONFIRM_URL
|
|
60
60
|
]);
|
|
61
61
|
|
|
62
|
+
/** 删除查询参数中表示“未选择”的租户项目零值。 */
|
|
63
|
+
function compactTenantProjectQueryParams(value: unknown): unknown {
|
|
64
|
+
if (Array.isArray(value)) return value.map(item => compactTenantProjectQueryParams(item));
|
|
65
|
+
if (!value || typeof value !== "object") return value;
|
|
66
|
+
const result: Record<string, unknown> = {};
|
|
67
|
+
for (const [key, nested] of Object.entries(value as Record<string, unknown>)) {
|
|
68
|
+
if ((key === "tenant_id" || key === "project_id" || key.endsWith(".tenant_id") || key.endsWith(".project_id")) && nested === 0) continue;
|
|
69
|
+
result[key] = compactTenantProjectQueryParams(nested);
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
62
74
|
/** 支持自动重试的 Axios 请求配置。 */
|
|
63
75
|
type RetryableRequestConfig = InternalAxiosRequestConfig & {
|
|
64
76
|
/** 标记当前请求已经因认证失败重试过,避免刷新失败时递归重放。 */
|
|
@@ -109,7 +121,7 @@ const service = axios.create({
|
|
|
109
121
|
baseURL: requestBaseURL,
|
|
110
122
|
timeout: 50000,
|
|
111
123
|
headers: { "Content-Type": "application/json;charset=utf-8" },
|
|
112
|
-
paramsSerializer: params => qs.stringify(params),
|
|
124
|
+
paramsSerializer: params => qs.stringify(compactTenantProjectQueryParams(params)),
|
|
113
125
|
withCredentials: true
|
|
114
126
|
});
|
|
115
127
|
|