feat: 本地开发默认 website
parent
14f06c98ef
commit
198cd6912c
|
@ -7,6 +7,8 @@ VITE_BASE=/
|
|||
VITE_GLOB_API_URL=/admin-api
|
||||
# 是否打开 devtools,true 为打开,false 为关闭
|
||||
VITE_DEVTOOLS=false
|
||||
# 本地开发默认 website
|
||||
VITE_APP_WEBSITE=www.iocoder.cn
|
||||
|
||||
# 是否注入全局loading
|
||||
VITE_INJECT_APP_LOADING=true
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { baseRequestClient, requestClient } from '#/api/request';
|
||||
import type { AuthPermissionInfo } from '@vben/types';
|
||||
|
||||
import { baseRequestClient, requestClient } from '#/api/request';
|
||||
|
||||
export namespace AuthApi {
|
||||
/** 登录接口参数 */
|
||||
export interface LoginParams {
|
||||
|
@ -34,7 +35,6 @@ export namespace AuthApi {
|
|||
mobile: string;
|
||||
code: string;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** 登录 */
|
||||
|
@ -44,16 +44,22 @@ export async function loginApi(data: AuthApi.LoginParams) {
|
|||
|
||||
/** 刷新 accessToken */
|
||||
export async function refreshTokenApi(refreshToken: string) {
|
||||
return baseRequestClient.post(`/system/auth/refresh-token?refreshToken=${refreshToken}`);
|
||||
return baseRequestClient.post(
|
||||
`/system/auth/refresh-token?refreshToken=${refreshToken}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 退出登录 */
|
||||
export async function logoutApi(accessToken: string) {
|
||||
return baseRequestClient.post('/system/auth/logout', {}, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
}
|
||||
});
|
||||
return baseRequestClient.post(
|
||||
'/system/auth/logout',
|
||||
{},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/** 获取权限信息 */
|
||||
|
@ -72,7 +78,9 @@ export async function getTenantSimpleList() {
|
|||
|
||||
/** 使用租户域名,获得租户信息 */
|
||||
export async function getTenantByWebsite(website: string) {
|
||||
return requestClient.get<AuthApi.TenantResult>(`/system/tenant/get-by-website?website=${website}`);
|
||||
return requestClient.get<AuthApi.TenantResult>(
|
||||
`/system/tenant/get-by-website?website=${website}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 获取验证码 */
|
||||
|
|
|
@ -1,21 +1,31 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VbenFormSchema } from '@vben/common-ui';
|
||||
import {type AuthApi, checkCaptcha, getCaptcha } from '#/api/core/auth';
|
||||
|
||||
import { computed, markRaw, onMounted, ref } from 'vue';
|
||||
import type { AuthApi } from '#/api/core/auth';
|
||||
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { AuthenticationLogin, Verification, z } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { useAppConfig } from '@vben/hooks';
|
||||
|
||||
import { useAuthStore } from '#/store';
|
||||
import { $t } from '@vben/locales';
|
||||
import { useAccessStore } from '@vben/stores';
|
||||
|
||||
import { getTenantSimpleList, getTenantByWebsite } from '#/api/core/auth';
|
||||
const { tenantEnable, captchaEnable } = useAppConfig(import.meta.env, import.meta.env.PROD);
|
||||
import {
|
||||
checkCaptcha,
|
||||
getCaptcha,
|
||||
getTenantByWebsite,
|
||||
getTenantSimpleList,
|
||||
} from '#/api/core/auth';
|
||||
import { useAuthStore } from '#/store';
|
||||
|
||||
defineOptions({ name: 'Login' });
|
||||
|
||||
const isProduction = import.meta.env.PROD;
|
||||
const { tenantEnable, captchaEnable, website } = useAppConfig(
|
||||
import.meta.env,
|
||||
isProduction,
|
||||
);
|
||||
|
||||
const authStore = useAuthStore();
|
||||
const accessStore = useAccessStore();
|
||||
|
||||
|
@ -32,11 +42,13 @@ const fetchTenantList = async () => {
|
|||
}
|
||||
try {
|
||||
// 获取租户列表、域名对应租户
|
||||
const websiteTenantPromise = getTenantByWebsite(window.location.hostname);
|
||||
const websiteTenantPromise = getTenantByWebsite(
|
||||
isProduction ? window.location.hostname : website, // 生成环境使用真实域名开发环境固定
|
||||
);
|
||||
tenantList.value = await getTenantSimpleList();
|
||||
|
||||
// 选中租户:域名 > store 中的租户 > 首个租户
|
||||
let tenantId: number | null = null;
|
||||
let tenantId: null | number = null;
|
||||
const websiteTenant = await websiteTenantPromise;
|
||||
if (websiteTenant?.id) {
|
||||
tenantId = websiteTenant.id;
|
||||
|
@ -68,7 +80,7 @@ const handleLogin = async (values: any) => {
|
|||
|
||||
// 无验证码,直接登录
|
||||
await authStore.authLogin(values);
|
||||
}
|
||||
};
|
||||
|
||||
/** 验证码通过,执行登录 */
|
||||
const handleVerifySuccess = async ({ captchaVerification }: any) => {
|
||||
|
|
|
@ -15,13 +15,18 @@ export function useAppConfig(
|
|||
? window._VBEN_ADMIN_PRO_APP_CONF_
|
||||
: (env as VbenAdminProAppConfigRaw);
|
||||
|
||||
const { VITE_APP_CAPTCHA_ENABLE, VITE_APP_TENANT_ENABLE, VITE_GLOB_API_URL } =
|
||||
config;
|
||||
const {
|
||||
VITE_APP_CAPTCHA_ENABLE,
|
||||
VITE_APP_TENANT_ENABLE,
|
||||
VITE_GLOB_API_URL,
|
||||
VITE_APP_WEBSITE,
|
||||
} = config;
|
||||
|
||||
// TODO @芋艿:貌似 VITE_APP_CAPTCHA_ENABLE 读取的是字符串,所以这里暂时这么转换
|
||||
return {
|
||||
apiURL: VITE_GLOB_API_URL,
|
||||
captchaEnable: VITE_APP_CAPTCHA_ENABLE === 'true',
|
||||
tenantEnable: VITE_APP_TENANT_ENABLE === 'true',
|
||||
website: VITE_APP_WEBSITE,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -11,12 +11,14 @@ export interface VbenAdminProAppConfigRaw {
|
|||
VITE_GLOB_API_URL: string;
|
||||
VITE_APP_TENANT_ENABLE: boolean;
|
||||
VITE_APP_CAPTCHA_ENABLE: boolean;
|
||||
VITE_APP_WEBSITE: string;
|
||||
}
|
||||
|
||||
export interface ApplicationConfig {
|
||||
apiURL: string;
|
||||
captchaEnable: boolean;
|
||||
tenantEnable: boolean;
|
||||
website: string;
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
|
Loading…
Reference in New Issue