refactor: 【web-ant】重构认证模块并移除未使用的组件和功能【0fed9472】(剩余 request、present)

pull/62/head
YunaiV 2025-03-26 07:36:12 +08:00
parent e65469b5ea
commit c881a47ffd
12 changed files with 80 additions and 13 deletions

View File

@ -20,6 +20,17 @@ setupVbenVxeTable({
// 全局禁用vxe-table的表单配置使用formOptions // 全局禁用vxe-table的表单配置使用formOptions
enabled: false, enabled: false,
}, },
toolbarConfig: {
import: true,
export: true,
refresh: true,
print: true,
zoom: true,
custom: true,
},
customConfig: {
mode: 'modal',
},
proxyConfig: { proxyConfig: {
autoLoad: true, autoLoad: true,
response: { response: {
@ -29,6 +40,12 @@ setupVbenVxeTable({
showActiveMsg: true, showActiveMsg: true,
showResponseMsg: false, showResponseMsg: false,
}, },
pagerConfig: {
enabled: true,
},
sortConfig: {
multiple: true,
},
round: true, round: true,
showOverflow: true, showOverflow: true,
size: 'small', size: 'small',

View File

@ -64,21 +64,21 @@ export async function logoutApi() {
} }
/** 获取权限信息 */ /** 获取权限信息 */
export function getAuthPermissionInfoApi() { export async function getAuthPermissionInfoApi() {
return requestClient.get<AuthPermissionInfo>( return requestClient.get<AuthPermissionInfo>(
'/system/auth/get-permission-info', '/system/auth/get-permission-info',
); );
} }
/** 获取租户列表 */ /** 获取租户列表 */
export function getTenantSimpleList() { export async function getTenantSimpleList() {
return requestClient.get<AuthApi.TenantResult[]>( return requestClient.get<AuthApi.TenantResult[]>(
`/system/tenant/simple-list`, `/system/tenant/simple-list`,
); );
} }
/** 使用租户域名,获得租户信息 */ /** 使用租户域名,获得租户信息 */
export 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}`);
} }

View File

@ -125,10 +125,11 @@ watch(
<template> <template>
<BasicLayout @clear-preferences-and-logout="handleLogout"> <BasicLayout @clear-preferences-and-logout="handleLogout">
<template #user-dropdown> <template #user-dropdown>
<!-- TODO @芋艿去掉 ann.vben@gmail.com -->
<UserDropdown <UserDropdown
:avatar :avatar
:menus :menus
:text="userStore.userInfo?.realName" :text="userStore.userInfo?.nickname"
description="ann.vben@gmail.com" description="ann.vben@gmail.com"
tag-text="Pro" tag-text="Pro"
@logout="handleLogout" @logout="handleLogout"

View File

@ -57,9 +57,9 @@ export const useAuthStore = defineStore('auth', () => {
: await router.push(userInfo.homePath || DEFAULT_HOME_PATH); : await router.push(userInfo.homePath || DEFAULT_HOME_PATH);
} }
if (userInfo?.realName) { if (userInfo?.nickname) {
notification.success({ notification.success({
description: `${$t('authentication.loginSuccessDesc')}:${userInfo?.realName}`, description: `${$t('authentication.loginSuccessDesc')}:${userInfo?.nickname}`,
duration: 3, duration: 3,
message: $t('authentication.loginSuccess'), message: $t('authentication.loginSuccess'),
}); });
@ -99,7 +99,7 @@ export const useAuthStore = defineStore('auth', () => {
let authPermissionInfo: AuthPermissionInfo | null = null; let authPermissionInfo: AuthPermissionInfo | null = null;
authPermissionInfo = await getAuthPermissionInfoApi(); authPermissionInfo = await getAuthPermissionInfoApi();
// userStore // userStore
userStore.setUserInfo(authPermissionInfo.user); userStore.setUserInfo(authPermissionInfo.user); // TODO @芋艿:这里有报错
userStore.setUserRoles(authPermissionInfo.roles); userStore.setUserRoles(authPermissionInfo.roles);
// accessStore // accessStore
accessStore.setAccessMenus(authPermissionInfo.menus); accessStore.setAccessMenus(authPermissionInfo.menus);

View File

@ -15,7 +15,7 @@ interface BasicUserInfo {
/** /**
* *
*/ */
realName: string; nickname: string;
/** /**
* *
*/ */

View File

@ -18,9 +18,10 @@ export function useAppConfig(
const { VITE_APP_CAPTCHA_ENABLE, VITE_APP_TENANT_ENABLE, VITE_GLOB_API_URL } = const { VITE_APP_CAPTCHA_ENABLE, VITE_APP_TENANT_ENABLE, VITE_GLOB_API_URL } =
config; config;
// TODO @芋艿:貌似 VITE_APP_CAPTCHA_ENABLE 读取的是字符串,所以这里暂时这么转换
return { return {
apiURL: VITE_GLOB_API_URL, apiURL: VITE_GLOB_API_URL,
captchaEnable: VITE_APP_CAPTCHA_ENABLE, captchaEnable: VITE_APP_CAPTCHA_ENABLE === 'true',
tenantEnable: VITE_APP_TENANT_ENABLE, tenantEnable: VITE_APP_TENANT_ENABLE === 'true',
}; };
} }

View File

@ -22,9 +22,11 @@
"dependencies": { "dependencies": {
"@vben/locales": "workspace:*", "@vben/locales": "workspace:*",
"@vben/utils": "workspace:*", "@vben/utils": "workspace:*",
"axios": "catalog:" "axios": "catalog:",
"qs": "catalog:"
}, },
"devDependencies": { "devDependencies": {
"axios-mock-adapter": "catalog:" "axios-mock-adapter": "catalog:",
"@types/qs": "catalog:"
} }
} }

View File

@ -5,6 +5,7 @@ import type { RequestClientConfig, RequestClientOptions } from './types';
import { bindMethods, merge } from '@vben/utils'; import { bindMethods, merge } from '@vben/utils';
import axios from 'axios'; import axios from 'axios';
import qs from 'qs';
import { FileDownloader } from './modules/downloader'; import { FileDownloader } from './modules/downloader';
import { InterceptorManager } from './modules/interceptor'; import { InterceptorManager } from './modules/interceptor';
@ -36,6 +37,10 @@ class RequestClient {
responseReturn: 'raw', responseReturn: 'raw',
// 默认超时时间 // 默认超时时间
timeout: 10_000, timeout: 10_000,
// 处理请求参数 默认使用 qs 库处理
paramsSerializer: (params) => {
return qs.stringify(params, { arrayFormat: 'repeat' });
},
}; };
const { ...axiosConfig } = options; const { ...axiosConfig } = options;
const requestConfig = merge(axiosConfig, defaultConfig); const requestConfig = merge(axiosConfig, defaultConfig);

View File

@ -52,12 +52,25 @@ interface HttpResponse<T = any> {
*/ */
code: number; code: number;
data: T; data: T;
message: string; msg: string;
}
interface PageParam {
[key: string]: any;
pageNo: number;
pageSize: number;
}
interface PageResult<T> {
list: T[];
total: number;
} }
export type { export type {
HttpResponse, HttpResponse,
MakeErrorMessageFn, MakeErrorMessageFn,
PageParam,
PageResult,
RequestClientConfig, RequestClientConfig,
RequestClientOptions, RequestClientOptions,
RequestContentType, RequestContentType,

View File

@ -55,6 +55,7 @@ export const useUserStore = defineStore('core-user', {
userInfo: null, userInfo: null,
userRoles: [], userRoles: [],
}), }),
// TODO @芋艿pick: ['userInfo', 'userRoles'], 是否要持久化
}); });
// 解决热更新问题 // 解决热更新问题

View File

@ -111,6 +111,9 @@ catalogs:
'@types/qrcode': '@types/qrcode':
specifier: ^1.5.5 specifier: ^1.5.5
version: 1.5.5 version: 1.5.5
'@types/qs':
specifier: ^6.9.17
version: 6.9.18
'@types/sortablejs': '@types/sortablejs':
specifier: ^1.15.8 specifier: ^1.15.8
version: 1.15.8 version: 1.15.8
@ -369,6 +372,9 @@ catalogs:
qrcode: qrcode:
specifier: ^1.5.4 specifier: ^1.5.4
version: 1.5.4 version: 1.5.4
qs:
specifier: ^6.13.1
version: 6.14.0
radix-vue: radix-vue:
specifier: ^1.9.17 specifier: ^1.9.17
version: 1.9.17 version: 1.9.17
@ -1714,7 +1720,13 @@ importers:
axios: axios:
specifier: 'catalog:' specifier: 'catalog:'
version: 1.8.2 version: 1.8.2
qs:
specifier: 'catalog:'
version: 6.14.0
devDependencies: devDependencies:
'@types/qs':
specifier: 'catalog:'
version: 6.9.18
axios-mock-adapter: axios-mock-adapter:
specifier: 'catalog:' specifier: 'catalog:'
version: 2.1.0(axios@1.8.2) version: 2.1.0(axios@1.8.2)
@ -4331,6 +4343,9 @@ packages:
'@types/qrcode@1.5.5': '@types/qrcode@1.5.5':
resolution: {integrity: sha512-CdfBi/e3Qk+3Z/fXYShipBT13OJ2fDO2Q2w5CIP5anLTLIndQG9z6P1cnm+8zCWSpm5dnxMFd/uREtb0EXuQzg==} resolution: {integrity: sha512-CdfBi/e3Qk+3Z/fXYShipBT13OJ2fDO2Q2w5CIP5anLTLIndQG9z6P1cnm+8zCWSpm5dnxMFd/uREtb0EXuQzg==}
'@types/qs@6.9.18':
resolution: {integrity: sha512-kK7dgTYDyGqS+e2Q4aK9X3D7q234CIZ1Bv0q/7Z5IwRDoADNU81xXJK/YVyLbLTZCoIwUoDoffFeF+p/eIklAA==}
'@types/readdir-glob@1.1.5': '@types/readdir-glob@1.1.5':
resolution: {integrity: sha512-raiuEPUYqXu+nvtY2Pe8s8FEmZ3x5yAH4VkLdihcPdalvsHltomrRC9BzuStrJ9yk06470hS0Crw0f1pXqD+Hg==} resolution: {integrity: sha512-raiuEPUYqXu+nvtY2Pe8s8FEmZ3x5yAH4VkLdihcPdalvsHltomrRC9BzuStrJ9yk06470hS0Crw0f1pXqD+Hg==}
@ -8650,6 +8665,10 @@ packages:
engines: {node: '>=10.13.0'} engines: {node: '>=10.13.0'}
hasBin: true hasBin: true
qs@6.14.0:
resolution: {integrity: sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==}
engines: {node: '>=0.6'}
quansync@0.2.8: quansync@0.2.8:
resolution: {integrity: sha512-4+saucphJMazjt7iOM27mbFCk+D9dd/zmgMDCzRZ8MEoBfYp7lAvoN38et/phRQF6wOPMy/OROBGgoWeSKyluA==} resolution: {integrity: sha512-4+saucphJMazjt7iOM27mbFCk+D9dd/zmgMDCzRZ8MEoBfYp7lAvoN38et/phRQF6wOPMy/OROBGgoWeSKyluA==}
@ -13160,6 +13179,8 @@ snapshots:
dependencies: dependencies:
'@types/node': 22.13.10 '@types/node': 22.13.10
'@types/qs@6.9.18': {}
'@types/readdir-glob@1.1.5': '@types/readdir-glob@1.1.5':
dependencies: dependencies:
'@types/node': 22.13.10 '@types/node': 22.13.10
@ -17949,6 +17970,10 @@ snapshots:
pngjs: 5.0.0 pngjs: 5.0.0
yargs: 15.4.1 yargs: 15.4.1
qs@6.14.0:
dependencies:
side-channel: 1.1.0
quansync@0.2.8: {} quansync@0.2.8: {}
queue-microtask@1.2.3: {} queue-microtask@1.2.3: {}

View File

@ -49,6 +49,7 @@ catalog:
'@types/nprogress': ^0.2.3 '@types/nprogress': ^0.2.3
'@types/postcss-import': ^14.0.3 '@types/postcss-import': ^14.0.3
'@types/qrcode': ^1.5.5 '@types/qrcode': ^1.5.5
'@types/qs': ^6.9.17
'@types/sortablejs': ^1.15.8 '@types/sortablejs': ^1.15.8
'@types/crypto-js': ^4.2.2 '@types/crypto-js': ^4.2.2
'@typescript-eslint/eslint-plugin': ^8.26.0 '@typescript-eslint/eslint-plugin': ^8.26.0
@ -139,6 +140,7 @@ catalog:
prettier-plugin-tailwindcss: ^0.6.11 prettier-plugin-tailwindcss: ^0.6.11
publint: ^0.2.12 publint: ^0.2.12
qrcode: ^1.5.4 qrcode: ^1.5.4
qs: ^6.13.1
radix-vue: ^1.9.17 radix-vue: ^1.9.17
resolve.exports: ^2.0.3 resolve.exports: ^2.0.3
rimraf: ^6.0.1 rimraf: ^6.0.1