From c0a92a5694f361b616564437cef32b69d6b9a3bc Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 22 Apr 2025 22:17:41 +0800 Subject: [PATCH] =?UTF-8?q?refactor=EF=BC=9A=E5=9F=BA=E4=BA=8E=20lint=20?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=8E=92=E7=89=88=EF=BC=88=E6=A1=86=E6=9E=B6?= =?UTF-8?q?=E5=B1=82=E9=9D=A2=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitee/ISSUE_TEMPLATE/bug.yml | 2 +- .gitee/ISSUE_TEMPLATE/config.yml | 2 +- apps/web-antd/src/adapter/vxe-table.ts | 23 +++++++-------- apps/web-antd/src/router/access.ts | 5 ++-- apps/web-antd/src/store/auth.ts | 28 ++++++++++++++----- .../src/request-client/request-client.ts | 2 +- packages/stores/src/modules/access.ts | 4 +-- packages/stores/src/modules/user.ts | 10 +++---- packages/types/src/user.ts | 6 +--- packages/utils/src/helpers/generate-menus.ts | 16 ++++++++--- 10 files changed, 59 insertions(+), 39 deletions(-) diff --git a/.gitee/ISSUE_TEMPLATE/bug.yml b/.gitee/ISSUE_TEMPLATE/bug.yml index 6431c01cc..13f7d3b10 100644 --- a/.gitee/ISSUE_TEMPLATE/bug.yml +++ b/.gitee/ISSUE_TEMPLATE/bug.yml @@ -7,7 +7,7 @@ body: attributes: value: | 感谢对项目的支持与关注。在提出问题之前,请确保你已查看相关开发或使用文档: - - http://vben-doc.x-surge.com/ + - https://doc.iocoder.cn/ - type: checkboxes attributes: label: 这个问题是否已经存在? diff --git a/.gitee/ISSUE_TEMPLATE/config.yml b/.gitee/ISSUE_TEMPLATE/config.yml index dd74c56f5..43d96710b 100644 --- a/.gitee/ISSUE_TEMPLATE/config.yml +++ b/.gitee/ISSUE_TEMPLATE/config.yml @@ -1,5 +1,5 @@ blank_issues_enabled: false contact_links: - name: 项目开发文档 - url: http://vben-doc.x-surge.com/ + url: https://doc.iocoder.cn/ about: 提供项目启动、开发的相关文档 diff --git a/apps/web-antd/src/adapter/vxe-table.ts b/apps/web-antd/src/adapter/vxe-table.ts index c773cea4a..545245a78 100644 --- a/apps/web-antd/src/adapter/vxe-table.ts +++ b/apps/web-antd/src/adapter/vxe-table.ts @@ -1,3 +1,5 @@ +import type { Recordable } from '@vben/types'; + import { h } from 'vue'; import { IconifyIcon } from '@vben/icons'; @@ -6,12 +8,11 @@ import { setupVbenVxeTable, useVbenVxeGrid } from '@vben/plugins/vxe-table'; import { isFunction, isString } from '@vben/utils'; import { Button, Image, Popconfirm, Switch } from 'ant-design-vue'; + import { DictTag } from '#/components/dict-tag'; +import { $t } from '#/locales'; import { useVbenForm } from './form'; -import type { Recordable } from '@vben/types'; - -import { $t } from '#/locales'; setupVbenVxeTable({ configVxeTable: (vxeUI) => { @@ -162,10 +163,10 @@ setupVbenVxeTable({ return presets[opt] ? { code: opt, ...presets[opt], ...defaultProps } : { - code: opt, - text: $te(`common.${opt}`) ? $t(`common.${opt}`) : opt, - ...defaultProps, - }; + code: opt, + text: $te(`common.${opt}`) ? $t(`common.${opt}`) : opt, + ...defaultProps, + }; } else { return { ...defaultProps, ...presets[opt.code], ...opt }; } @@ -188,10 +189,10 @@ setupVbenVxeTable({ icon: undefined, onClick: listen ? () => - attrs?.onClick?.({ - code: opt.code, - row, - }) + attrs?.onClick?.({ + code: opt.code, + row, + }) : undefined, }, { diff --git a/apps/web-antd/src/router/access.ts b/apps/web-antd/src/router/access.ts index 9d37b9142..de84f93f9 100644 --- a/apps/web-antd/src/router/access.ts +++ b/apps/web-antd/src/router/access.ts @@ -5,11 +5,11 @@ import type { import { generateAccessible } from '@vben/access'; import { preferences } from '@vben/preferences'; - -import { BasicLayout, IFrameView } from '#/layouts'; import { useAccessStore } from '@vben/stores'; import { convertServerMenuToRouteRecordStringComponent } from '@vben/utils'; +import { BasicLayout, IFrameView } from '#/layouts'; + const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue'); async function generateAccess(options: GenerateMenuAndRoutesOptions) { @@ -26,6 +26,7 @@ async function generateAccess(options: GenerateMenuAndRoutesOptions) { fetchMenuListAsync: async () => { // 由于 yudao 通过 accessStore 读取,所以不在进行 message.loading 提示 const accessMenus = accessStore.accessMenus; + // TODO @芋艿:爆红!!! return convertServerMenuToRouteRecordStringComponent(accessMenus); }, // 可以指定没有权限跳转403页面 diff --git a/apps/web-antd/src/store/auth.ts b/apps/web-antd/src/store/auth.ts index 4807dfcd8..2089ea0c4 100644 --- a/apps/web-antd/src/store/auth.ts +++ b/apps/web-antd/src/store/auth.ts @@ -1,4 +1,6 @@ -import type { AuthPermissionInfo, Recordable, UserInfo} from '@vben/types'; +import type { AuthPermissionInfo, Recordable, UserInfo } from '@vben/types'; + +import type { AuthApi } from '#/api'; import { ref } from 'vue'; import { useRouter } from 'vue-router'; @@ -9,7 +11,14 @@ import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores'; import { notification } from 'ant-design-vue'; import { defineStore } from 'pinia'; -import { type AuthApi, getAuthPermissionInfoApi, loginApi, logoutApi, smsLogin, register, socialLogin } from '#/api'; +import { + getAuthPermissionInfoApi, + loginApi, + logoutApi, + register, + smsLogin, + socialLogin, +} from '#/api'; import { $t } from '#/locales'; export const useAuthStore = defineStore('auth', () => { @@ -27,7 +36,7 @@ export const useAuthStore = defineStore('auth', () => { * @param onSuccess 登录成功后的回调函数 */ async function authLogin( - type: 'mobile' | 'username' | 'register' | 'social', + type: 'mobile' | 'register' | 'social' | 'username', params: Recordable, onSuccess?: () => Promise | void, ) { @@ -35,10 +44,15 @@ export const useAuthStore = defineStore('auth', () => { let userInfo: null | UserInfo = null; try { loginLoading.value = true; - const { accessToken, refreshToken } = type === 'mobile' ? await smsLogin(params as AuthApi.SmsLoginParams) - : type === 'register' ? await register(params as AuthApi.RegisterParams) - : type === 'social' ? await socialLogin(params as AuthApi.SocialLoginParams) - : await loginApi(params); + const { accessToken, refreshToken } = + type === 'mobile' + ? await smsLogin(params as AuthApi.SmsLoginParams) + : type === 'register' + ? await register(params as AuthApi.RegisterParams) + : // eslint-disable-next-line unicorn/no-nested-ternary + type === 'social' + ? await socialLogin(params as AuthApi.SocialLoginParams) + : await loginApi(params); // 如果成功获取到 accessToken if (accessToken) { diff --git a/packages/effects/request/src/request-client/request-client.ts b/packages/effects/request/src/request-client/request-client.ts index b9e90dabd..e9adca6d3 100644 --- a/packages/effects/request/src/request-client/request-client.ts +++ b/packages/effects/request/src/request-client/request-client.ts @@ -61,7 +61,7 @@ class RequestClient { responseReturn: 'raw', // 默认超时时间 timeout: 10_000, - paramsSerializer: 'repeat' + paramsSerializer: 'repeat', }; const { ...axiosConfig } = options; const requestConfig = merge(axiosConfig, defaultConfig); diff --git a/packages/stores/src/modules/access.ts b/packages/stores/src/modules/access.ts index 81790b634..db0922ddd 100644 --- a/packages/stores/src/modules/access.ts +++ b/packages/stores/src/modules/access.ts @@ -88,7 +88,7 @@ export const useAccessStore = defineStore('core-access', { }, setTenantId(tenantId: null | number) { this.tenantId = tenantId; - } + }, }, persist: { // 持久化 @@ -102,7 +102,7 @@ export const useAccessStore = defineStore('core-access', { isAccessChecked: false, loginExpired: false, refreshToken: null, - tenantId: null + tenantId: null, }), }); diff --git a/packages/stores/src/modules/user.ts b/packages/stores/src/modules/user.ts index 60ed3f87e..14a4f6f93 100644 --- a/packages/stores/src/modules/user.ts +++ b/packages/stores/src/modules/user.ts @@ -6,6 +6,10 @@ interface BasicUserInfo { * 头像 */ avatar: string; + /** + * 用户邮箱 + */ + email?: string; /** * 用户昵称 */ @@ -18,10 +22,6 @@ interface BasicUserInfo { * 用户名 */ username: string; - /** - * 用户邮箱 - */ - email?: string; } interface AccessState { @@ -50,7 +50,7 @@ export const useUserStore = defineStore('core-user', { state: (): AccessState => ({ userInfo: null, userRoles: [], - }) + }), }); // 解决热更新问题 diff --git a/packages/types/src/user.ts b/packages/types/src/user.ts index 478141537..46d08abc5 100644 --- a/packages/types/src/user.ts +++ b/packages/types/src/user.ts @@ -2,22 +2,18 @@ import type { AppRouteRecordRaw, BasicUserInfo } from '@vben-core/typings'; /** 用户信息 */ interface UserInfo extends BasicUserInfo { - /** * 首页地址 */ homePath: string; - } /** 权限信息 */ interface AuthPermissionInfo { - user: UserInfo; roles: string[]; permissions: string[]; menus: AppRouteRecordRaw[]; - } -export type { UserInfo, AuthPermissionInfo }; +export type { AuthPermissionInfo, UserInfo }; diff --git a/packages/utils/src/helpers/generate-menus.ts b/packages/utils/src/helpers/generate-menus.ts index a4e453a45..f38fc25f9 100644 --- a/packages/utils/src/helpers/generate-menus.ts +++ b/packages/utils/src/helpers/generate-menus.ts @@ -1,8 +1,13 @@ import type { Router, RouteRecordRaw } from 'vue-router'; -import type { ExRouteRecordRaw, MenuRecordRaw, RouteRecordStringComponent, AppRouteRecordRaw } from '@vben-core/typings'; +import type { + AppRouteRecordRaw, + ExRouteRecordRaw, + MenuRecordRaw, + RouteRecordStringComponent, +} from '@vben-core/typings'; -import { filterTree, mapTree, isHttpUrl } from '@vben-core/shared/utils'; +import { filterTree, isHttpUrl, mapTree } from '@vben-core/shared/utils'; /** * 根据 routes 生成菜单列表 @@ -142,7 +147,10 @@ function convertServerMenuToRouteRecordStringComponent( }; if (menu.children && menu.children.length > 0) { - buildMenu.children = convertServerMenuToRouteRecordStringComponent(menu.children, menu.path); + buildMenu.children = convertServerMenuToRouteRecordStringComponent( + menu.children, + menu.path, + ); } menus.push(buildMenu); @@ -150,4 +158,4 @@ function convertServerMenuToRouteRecordStringComponent( return menus; } -export { generateMenus, convertServerMenuToRouteRecordStringComponent }; +export { convertServerMenuToRouteRecordStringComponent, generateMenus };