From c6b0c60392e721b876dd8dab4baac28b15c2c780 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 3 Dec 2024 16:46:39 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=90=88=E5=B9=B6=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E6=A1=86=E6=9E=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 - README.md | 2 +- package.json | 2 +- src/hooks/business/auth.ts | 17 +- src/hooks/business/captcha.ts | 16 +- src/hooks/common/router.ts | 13 +- src/layouts/modules/global-footer/index.vue | 4 +- .../global-header/components/user-avatar.vue | 14 +- src/layouts/modules/global-header/index.vue | 7 +- src/locales/langs/en-us.ts | 35 +- src/locales/langs/zh-cn.ts | 35 +- src/router/elegant/routes.ts | 162 ++++-- src/router/elegant/transform.ts | 25 +- src/router/guard/route.ts | 4 +- src/router/routes/index.ts | 59 +- src/service/api/auth.ts | 18 +- src/store/modules/auth/index.ts | 33 +- src/store/modules/route/index.ts | 73 +-- src/store/modules/route/shared.ts | 2 +- src/theme/settings.ts | 2 +- src/typings/api.d.ts | 6 + src/typings/app.d.ts | 403 +------------- src/typings/auto-imports.d.ts | 1 + src/typings/components.d.ts | 1 - src/typings/env.d.ts | 3 +- .../_builtin/login/modules/pwd-login.vue | 12 +- src/views/_builtin/login/modules/register.vue | 502 +++++++++++------- src/views/manage/role/modules/menu-auth.vue | 24 +- .../role/modules/role-operate-drawer.vue | 26 +- vite.config.ts | 2 +- 30 files changed, 631 insertions(+), 874 deletions(-) diff --git a/.env b/.env index 6a529a8..5823e02 100644 --- a/.env +++ b/.env @@ -35,5 +35,3 @@ VITE_SERVICE_EXPIRED_TOKEN_CODES=403 VITE_SERVICE_SERVER_ERROR_CODE=500 -# when the route mode is static, the defined super role -VITE_STATIC_SUPER_ROLE=R_SUPER diff --git a/README.md b/README.md index 8e04369..124f99c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# WANFI 用户平台 +# WANFI 客户平台 ## 使用 diff --git a/package.json b/package.json index 7e28132..d21781c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "vue-antd", + "name": "wanfi-system", "type": "module", "version": "1.0.0", "scripts": { diff --git a/src/hooks/business/auth.ts b/src/hooks/business/auth.ts index f8fc749..d324223 100644 --- a/src/hooks/business/auth.ts +++ b/src/hooks/business/auth.ts @@ -1,4 +1,4 @@ -import { useAuthStore } from '@/store/modules/auth'; +import {useAuthStore} from '@/store/modules/auth'; export function useAuth() { const authStore = useAuthStore(); @@ -15,7 +15,20 @@ export function useAuth() { return codes.some(code => authStore.userInfo.buttons.includes(code)); } + function hasRole(role: string | string[]) { + if (!authStore.isLogin) { + return false; + } + + if (typeof role === 'string') { + return authStore.userInfo.roles.includes(role); + } + + return role.some(code => authStore.userInfo.roles.includes(code)); + } + return { - hasAuth + hasAuth, + hasRole, }; } diff --git a/src/hooks/business/captcha.ts b/src/hooks/business/captcha.ts index 3f27072..3290b3b 100644 --- a/src/hooks/business/captcha.ts +++ b/src/hooks/business/captcha.ts @@ -1,8 +1,8 @@ import { computed } from 'vue'; import { useCountDown, useLoading } from '@sa/hooks'; import { $t } from '@/locales'; -import {REG_EMAIL} from '@/constants/reg'; -import {useAuthStore} from "@/store/modules/auth"; +import { REG_EMAIL } from '@/constants/reg'; +import { useAuthStore } from '@/store/modules/auth'; export function useCaptcha() { const { loading, startLoading, endLoading } = useLoading(); @@ -39,20 +39,17 @@ export function useCaptcha() { return true; } + //获取验证码方法 async function getCaptcha(email: string) { - console.log(email) - //const valid = isPhoneValid(phone); - const valid = isEmailValid(email); + const valid = isEmailValid(email); if (!valid || loading.value) { - return; + return null; } startLoading(); - await authStore.captcha( - email, - ); + const data = await authStore.captcha(email); await new Promise(resolve => { setTimeout(resolve, 500); }); @@ -62,6 +59,7 @@ export function useCaptcha() { start(); endLoading(); + return data; } return { diff --git a/src/hooks/common/router.ts b/src/hooks/common/router.ts index bc5277d..ef4529e 100644 --- a/src/hooks/common/router.ts +++ b/src/hooks/common/router.ts @@ -1,7 +1,7 @@ -import { useRouter } from 'vue-router'; -import type { RouteLocationRaw } from 'vue-router'; -import type { RouteKey } from '@elegant-router/types'; -import { router as globalRouter } from '@/router'; +import type {RouteLocationRaw} from 'vue-router'; +import {useRouter} from 'vue-router'; +import type {RouteKey} from '@elegant-router/types'; +import {router as globalRouter} from '@/router'; /** * Router push @@ -24,7 +24,7 @@ export function useRouterPush(inSetup = true) { } async function routerPushByKey(key: RouteKey, options?: RouterPushOptions) { - const { query, params } = options || {}; + const {query, params} = options || {}; const routeLocation: RouteLocationRaw = { name: key @@ -53,7 +53,6 @@ export function useRouterPush(inSetup = true) { */ async function toLogin(loginModule?: UnionKey.LoginModule, redirectUrl?: string) { const module = loginModule || 'pwd-login'; - const options: RouterPushOptions = { params: { module @@ -77,7 +76,7 @@ export function useRouterPush(inSetup = true) { async function toggleLoginModule(module: UnionKey.LoginModule) { const query = route.value.query as Record; - return routerPushByKey('login', { query, params: { module } }); + return routerPushByKey('login', {query, params: {module}}); } /** Redirect from login */ diff --git a/src/layouts/modules/global-footer/index.vue b/src/layouts/modules/global-footer/index.vue index 26273b5..67f8bee 100644 --- a/src/layouts/modules/global-footer/index.vue +++ b/src/layouts/modules/global-footer/index.vue @@ -6,8 +6,8 @@ defineOptions({ diff --git a/src/layouts/modules/global-header/components/user-avatar.vue b/src/layouts/modules/global-header/components/user-avatar.vue index 8bfaf93..a8900c6 100644 --- a/src/layouts/modules/global-header/components/user-avatar.vue +++ b/src/layouts/modules/global-header/components/user-avatar.vue @@ -37,13 +37,13 @@ function logout() { diff --git a/src/views/_builtin/login/modules/register.vue b/src/views/_builtin/login/modules/register.vue index 62afc6c..6489f6a 100644 --- a/src/views/_builtin/login/modules/register.vue +++ b/src/views/_builtin/login/modules/register.vue @@ -1,24 +1,26 @@