Revert "feat: 本地开发默认 website"

This reverts commit 198cd6912c.
pull/63/head
puhui999 2025-04-03 21:03:54 +08:00
parent ba82401cd4
commit 6ecfcb07bd
5 changed files with 22 additions and 51 deletions

View File

@ -7,8 +7,6 @@ VITE_BASE=/
VITE_GLOB_API_URL=/admin-api VITE_GLOB_API_URL=/admin-api
# 是否打开 devtoolstrue 为打开false 为关闭 # 是否打开 devtoolstrue 为打开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

View File

@ -1,6 +1,5 @@
import type { AuthPermissionInfo } from '@vben/types';
import { baseRequestClient, requestClient } from '#/api/request'; import { baseRequestClient, requestClient } from '#/api/request';
import type { AuthPermissionInfo } from '@vben/types';
export namespace AuthApi { export namespace AuthApi {
/** 登录接口参数 */ /** 登录接口参数 */
@ -35,6 +34,7 @@ export namespace AuthApi {
mobile: string; mobile: string;
code: string; code: string;
} }
} }
/** 登录 */ /** 登录 */
@ -44,22 +44,16 @@ export async function loginApi(data: AuthApi.LoginParams) {
/** 刷新 accessToken */ /** 刷新 accessToken */
export async function refreshTokenApi(refreshToken: string) { export async function refreshTokenApi(refreshToken: string) {
return baseRequestClient.post( return baseRequestClient.post(`/system/auth/refresh-token?refreshToken=${refreshToken}`);
`/system/auth/refresh-token?refreshToken=${refreshToken}`,
);
} }
/** 退出登录 */ /** 退出登录 */
export async function logoutApi(accessToken: string) { export async function logoutApi(accessToken: string) {
return baseRequestClient.post( return baseRequestClient.post('/system/auth/logout', {}, {
'/system/auth/logout', headers: {
{}, Authorization: `Bearer ${accessToken}`,
{ }
headers: { });
Authorization: `Bearer ${accessToken}`,
},
},
);
} }
/** 获取权限信息 */ /** 获取权限信息 */
@ -78,9 +72,7 @@ export async function getTenantSimpleList() {
/** 使用租户域名,获得租户信息 */ /** 使用租户域名,获得租户信息 */
export async function getTenantByWebsite(website: string) { export async function getTenantByWebsite(website: string) {
return requestClient.get<AuthApi.TenantResult>( return requestClient.get<AuthApi.TenantResult>(`/system/tenant/get-by-website?website=${website}`);
`/system/tenant/get-by-website?website=${website}`,
);
} }
/** 获取验证码 */ /** 获取验证码 */

View File

@ -1,31 +1,21 @@
<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 type { AuthApi } from '#/api/core/auth'; import { computed, markRaw, onMounted, ref } from 'vue';
import { computed, onMounted, ref } from 'vue';
import { AuthenticationLogin, Verification, z } from '@vben/common-ui'; import { AuthenticationLogin, Verification, z } from '@vben/common-ui';
import { useAppConfig } from '@vben/hooks';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { useAppConfig } from '@vben/hooks';
import { useAuthStore } from '#/store';
import { useAccessStore } from '@vben/stores'; import { useAccessStore } from '@vben/stores';
import { import { getTenantSimpleList, getTenantByWebsite } from '#/api/core/auth';
checkCaptcha, const { tenantEnable, captchaEnable } = useAppConfig(import.meta.env, import.meta.env.PROD);
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();
@ -42,13 +32,11 @@ const fetchTenantList = async () => {
} }
try { try {
// //
const websiteTenantPromise = getTenantByWebsite( const websiteTenantPromise = getTenantByWebsite(window.location.hostname);
isProduction ? window.location.hostname : website, // 使
);
tenantList.value = await getTenantSimpleList(); tenantList.value = await getTenantSimpleList();
// > store > // > store >
let tenantId: null | number = null; let tenantId: number | null = null;
const websiteTenant = await websiteTenantPromise; const websiteTenant = await websiteTenantPromise;
if (websiteTenant?.id) { if (websiteTenant?.id) {
tenantId = websiteTenant.id; tenantId = websiteTenant.id;
@ -80,7 +68,7 @@ const handleLogin = async (values: any) => {
// //
await authStore.authLogin(values); await authStore.authLogin(values);
}; }
/** 验证码通过,执行登录 */ /** 验证码通过,执行登录 */
const handleVerifySuccess = async ({ captchaVerification }: any) => { const handleVerifySuccess = async ({ captchaVerification }: any) => {

View File

@ -15,18 +15,13 @@ export function useAppConfig(
? window._VBEN_ADMIN_PRO_APP_CONF_ ? window._VBEN_ADMIN_PRO_APP_CONF_
: (env as VbenAdminProAppConfigRaw); : (env as VbenAdminProAppConfigRaw);
const { const { VITE_APP_CAPTCHA_ENABLE, VITE_APP_TENANT_ENABLE, VITE_GLOB_API_URL } =
VITE_APP_CAPTCHA_ENABLE, config;
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,
}; };
} }

View File

@ -11,14 +11,12 @@ 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 {