2
0

perf: 合并用户平台框架修改

This commit is contained in:
TsMask
2024-12-03 16:46:39 +08:00
parent 13ee5a3849
commit c6b0c60392
30 changed files with 631 additions and 874 deletions

View File

@@ -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,
};
}

View File

@@ -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 {

View File

@@ -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<string, string>;
return routerPushByKey('login', { query, params: { module } });
return routerPushByKey('login', {query, params: {module}});
}
/** Redirect from login */