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