diff --git a/apps/web-antd/src/api/core/auth.ts b/apps/web-antd/src/api/core/auth.ts index a2207aac..53cf9ebc 100644 --- a/apps/web-antd/src/api/core/auth.ts +++ b/apps/web-antd/src/api/core/auth.ts @@ -6,6 +6,7 @@ export namespace AuthApi { account: string; password?: string; code?: string; + admin_id?: number; /** @deprecated 兼容旧客户端 */ login_method?: 'phone' | 'login_account' | 'job_number'; username?: string; @@ -15,8 +16,23 @@ export namespace AuthApi { } /** 登录接口返回值 */ + export interface AccountOption { + account_type?: string; + id: number; + nick_name: string; + role_name: string; + store_name: string; + login_account?: string; + is_current?: boolean; + password_matched?: boolean; + } + export interface LoginResult { - token: string; + token?: string; + need_select?: boolean; + accounts?: AccountOption[]; + default_account_id?: number; + default_account_type?: string; } export interface RefreshTokenResult { @@ -28,6 +44,9 @@ export namespace AuthApi { export interface SendCodeResult { code?: string; need_select?: boolean; + accounts?: AccountOption[]; + default_account_id?: number; + default_account_type?: string; } } @@ -40,6 +59,7 @@ export async function loginApi(data: AuthApi.LoginParams) { account: data.account, password: data.password, code: data.code, + admin_id: data.admin_id, }); } @@ -66,6 +86,7 @@ export async function loginApi(data: AuthApi.LoginParams) { export async function sendVerificationCode(params: { account?: string; password?: string; + admin_id?: number; login_method?: 'phone' | 'login_account' | 'job_number'; username?: string; phone?: string; @@ -75,6 +96,7 @@ export async function sendVerificationCode(params: { if (params.account) { return requestClient.post('send-verification-code', { account: params.account, + admin_id: params.admin_id, }); } @@ -120,3 +142,19 @@ export async function logoutApi() { export async function getAccessCodesApi() { return requestClient.get('auth/codes'); } + +/** + * 同手机号可切换的管理员账号 + */ +export async function getSiblingAccountsApi() { + return requestClient.get('auth/sibling-accounts'); +} + +/** + * 切换管理员账号 + */ +export async function switchAccountApi(data: { + admin_id: number; +}) { + return requestClient.post('auth/switch-account', data); +} diff --git a/apps/web-antd/src/layouts/basic.vue b/apps/web-antd/src/layouts/basic.vue index aa11ff26..654e12b3 100644 --- a/apps/web-antd/src/layouts/basic.vue +++ b/apps/web-antd/src/layouts/basic.vue @@ -23,17 +23,20 @@ import { Bell, CalendarClock, Megaphone, + Users, } from 'lucide-vue-next'; // import { $t } from '#/locales'; import { useAuthStore } from '#/store'; import LoginForm from '#/views/_core/authentication/login.vue'; +import SwitchAccountModal from '#/layouts/components/SwitchAccountModal.vue'; import { useRouter } from 'vue-router'; import {getNoticeListApi, readAllApi} from "#/views/notice/api"; import {formatTimeToRelative} from "#/util/tool"; import {notification} from "ant-design-vue"; const router = useRouter(); +const switchAccountModalRef = ref>(); // 样式相关 const typeIcons = { @@ -177,41 +180,13 @@ const showDot = computed(() => ); const menus = computed(() => [ - // TODO 后续放个人中心 - // { - // handler: () => { - // UpdatePasswordModalApi.open(); - // }, - // icon: 'carbon:password', - // text: '修改密码', - // }, - // { - // handler: () => { - // openWindow(VBEN_DOC_URL, { - // target: '_blank', - // }); - // }, - // icon: BookOpenText, - // text: $t('ui.widgets.document'), - // }, - // { - // handler: () => { - // openWindow(VBEN_GITHUB_URL, { - // target: '_blank', - // }); - // }, - // icon: MdiGithub, - // text: 'GitHub', - // }, - // { - // handler: () => { - // openWindow(`${VBEN_GITHUB_URL}/issues`, { - // target: '_blank', - // }); - // }, - // icon: CircleHelp, - // text: $t('ui.widgets.qa'), - // }, + { + handler: () => { + switchAccountModalRef.value?.openModal(); + }, + icon: Users, + text: '切换账号', + }, ]); const avatar = computed(() => { @@ -285,6 +260,7 @@ watch( > +