mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-02-02 18:28:40 +08:00
perf: Improve the use of store in the app
This commit is contained in:
parent
ad6ae1d21d
commit
8042e2b044
@ -51,16 +51,25 @@ export class MockService implements OnModuleInit {
|
|||||||
|
|
||||||
// 密码哈希
|
// 密码哈希
|
||||||
const hashPassword = await bcrypt.hash('123456', 10);
|
const hashPassword = await bcrypt.hash('123456', 10);
|
||||||
|
|
||||||
await this.addItem('users', {
|
await this.addItem('users', {
|
||||||
id: 0,
|
id: 0,
|
||||||
password: hashPassword,
|
password: hashPassword,
|
||||||
realName: 'Vben',
|
realName: 'Vben',
|
||||||
roles: ['admin'],
|
roles: ['super'],
|
||||||
username: 'vben',
|
username: 'vben',
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.addItem('users', {
|
await this.addItem('users', {
|
||||||
id: 1,
|
id: 1,
|
||||||
password: hashPassword,
|
password: hashPassword,
|
||||||
|
realName: 'Admin',
|
||||||
|
roles: ['admin'],
|
||||||
|
username: 'admin',
|
||||||
|
});
|
||||||
|
await this.addItem('users', {
|
||||||
|
id: 2,
|
||||||
|
password: hashPassword,
|
||||||
realName: 'Jack',
|
realName: 'Jack',
|
||||||
roles: ['user'],
|
roles: ['user'],
|
||||||
username: 'jack',
|
username: 'jack',
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
import type { AxiosResponse } from '@vben-core/request';
|
import type { AxiosResponse } from '@vben-core/request';
|
||||||
|
|
||||||
import { RequestClient, isCancelError } from '@vben-core/request';
|
import { RequestClient, isCancelError } from '@vben-core/request';
|
||||||
import { useAccessStore } from '@vben-core/stores';
|
import { useCoreAccessStore } from '@vben-core/stores';
|
||||||
|
|
||||||
import { message } from 'ant-design-vue';
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
@ -30,7 +30,8 @@ function createRequestClient() {
|
|||||||
makeAuthorization: () => {
|
makeAuthorization: () => {
|
||||||
return {
|
return {
|
||||||
handler: () => {
|
handler: () => {
|
||||||
const accessStore = useAccessStore();
|
// 这里不能用 useAccessStore,因为 useAccessStore 会导致循环引用
|
||||||
|
const accessStore = useCoreAccessStore();
|
||||||
return {
|
return {
|
||||||
refreshToken: `Bearer ${accessStore.getRefreshToken}`,
|
refreshToken: `Bearer ${accessStore.getRefreshToken}`,
|
||||||
token: `Bearer ${accessStore.getAccessToken}`,
|
token: `Bearer ${accessStore.getAccessToken}`,
|
||||||
|
@ -4,16 +4,16 @@ import type { NotificationItem } from '@vben/widgets';
|
|||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
import { LOGIN_PATH } from '@vben/constants';
|
||||||
import { IcRoundCreditScore, MdiDriveDocument, MdiGithub } from '@vben/icons';
|
import { IcRoundCreditScore, MdiDriveDocument, MdiGithub } from '@vben/icons';
|
||||||
import { BasicLayout } from '@vben/layouts';
|
import { BasicLayout } from '@vben/layouts';
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
import { openWindow } from '@vben/utils';
|
import { openWindow } from '@vben/utils';
|
||||||
import { Notification, UserDropdown } from '@vben/widgets';
|
import { Notification, UserDropdown } from '@vben/widgets';
|
||||||
import { preferences } from '@vben-core/preferences';
|
import { preferences } from '@vben-core/preferences';
|
||||||
import { useRequest } from '@vben-core/request';
|
|
||||||
import { useAccessStore } from '@vben-core/stores';
|
|
||||||
|
|
||||||
import { getUserInfo } from '#/apis';
|
import { resetRoutes } from '#/router';
|
||||||
|
import { useAppStore } from '#/store';
|
||||||
|
|
||||||
// https://avatar.vercel.sh/vercel.svg?text=Vaa
|
// https://avatar.vercel.sh/vercel.svg?text=Vaa
|
||||||
// https://avatar.vercel.sh/1
|
// https://avatar.vercel.sh/1
|
||||||
@ -80,20 +80,22 @@ const menus = computed(() => [
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const accessStore = useAccessStore();
|
const appStore = useAppStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
// // 每次刷新页面都会进行用户信息获取
|
||||||
|
// // 如果不需要,可以删除
|
||||||
|
// const { runAsync: runGetUserInfo } = useRequest(getUserInfo, {
|
||||||
|
// manual: true,
|
||||||
|
// });
|
||||||
|
|
||||||
const { runAsync: runGetUserInfo } = useRequest(getUserInfo, {
|
// runGetUserInfo().then((userInfo) => {
|
||||||
manual: true,
|
// accessStore.setUserInfo(userInfo);
|
||||||
});
|
// });
|
||||||
|
|
||||||
runGetUserInfo().then((userInfo) => {
|
async function handleLogout() {
|
||||||
accessStore.setUserInfo(userInfo);
|
await appStore.resetAppState();
|
||||||
});
|
resetRoutes();
|
||||||
|
router.replace(LOGIN_PATH);
|
||||||
function handleLogout() {
|
|
||||||
accessStore.$reset();
|
|
||||||
router.replace('/auth/login');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleNoticeClear() {
|
function handleNoticeClear() {
|
||||||
|
@ -4,12 +4,12 @@ import { LOGIN_PATH } from '@vben/constants';
|
|||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
import { startProgress, stopProgress } from '@vben/utils';
|
import { startProgress, stopProgress } from '@vben/utils';
|
||||||
import { preferences } from '@vben-core/preferences';
|
import { preferences } from '@vben-core/preferences';
|
||||||
import { useAccessStore } from '@vben-core/stores';
|
|
||||||
|
|
||||||
import { useTitle } from '@vueuse/core';
|
import { useTitle } from '@vueuse/core';
|
||||||
|
|
||||||
import { generateAccess } from '#/forward/access';
|
import { generateAccess } from '#/forward/access';
|
||||||
import { dynamicRoutes, essentialsRouteNames } from '#/router/routes';
|
import { dynamicRoutes, essentialsRouteNames } from '#/router/routes';
|
||||||
|
import { useAccessStore } from '#/store';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用守卫配置
|
* 通用守卫配置
|
||||||
@ -57,7 +57,7 @@ function setupCommonGuard(router: Router) {
|
|||||||
function setupAccessGuard(router: Router) {
|
function setupAccessGuard(router: Router) {
|
||||||
router.beforeEach(async (to, from) => {
|
router.beforeEach(async (to, from) => {
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useAccessStore();
|
||||||
const accessToken = accessStore.getAccessToken;
|
const accessToken = accessStore.accessToken;
|
||||||
|
|
||||||
// accessToken 检查
|
// accessToken 检查
|
||||||
if (!accessToken) {
|
if (!accessToken) {
|
||||||
@ -83,7 +83,7 @@ function setupAccessGuard(router: Router) {
|
|||||||
return to;
|
return to;
|
||||||
}
|
}
|
||||||
|
|
||||||
const accessRoutes = accessStore.getAccessRoutes;
|
const accessRoutes = accessStore.accessRoutes;
|
||||||
|
|
||||||
// 是否已经生成过动态路由
|
// 是否已经生成过动态路由
|
||||||
if (accessRoutes && accessRoutes.length > 0) {
|
if (accessRoutes && accessRoutes.length > 0) {
|
||||||
@ -92,7 +92,10 @@ function setupAccessGuard(router: Router) {
|
|||||||
|
|
||||||
// 生成路由表
|
// 生成路由表
|
||||||
// 当前登录用户拥有的角色标识列表
|
// 当前登录用户拥有的角色标识列表
|
||||||
const userRoles = accessStore.getUserRoles;
|
const userInfo =
|
||||||
|
accessStore.userInfo || (await accessStore.fetchUserInfo());
|
||||||
|
|
||||||
|
const userRoles = userInfo.roles ?? [];
|
||||||
|
|
||||||
// 生成菜单和路由
|
// 生成菜单和路由
|
||||||
const { accessibleMenus, accessibleRoutes } = await generateAccess({
|
const { accessibleMenus, accessibleRoutes } = await generateAccess({
|
||||||
|
@ -77,6 +77,17 @@ const routes: RouteRecordRaw[] = [
|
|||||||
title: $t('page.demos.access.access-test-2'),
|
title: $t('page.demos.access.access-test-2'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'AccessFrontendTest3',
|
||||||
|
path: 'access-test-3',
|
||||||
|
component: () =>
|
||||||
|
import('#/views/demos/access/frontend/access-test-3.vue'),
|
||||||
|
meta: {
|
||||||
|
authority: ['super'],
|
||||||
|
icon: 'mdi:button-cursor',
|
||||||
|
title: $t('page.demos.access.access-test-3'),
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,7 @@ import type { InitStoreOptions } from '@vben-core/stores';
|
|||||||
|
|
||||||
import type { App } from 'vue';
|
import type { App } from 'vue';
|
||||||
|
|
||||||
import { initStore, useAccessStore, useTabbarStore } from '@vben-core/stores';
|
import { initStore } from '@vben-core/stores';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @zh_CN 初始化pinia
|
* @zh_CN 初始化pinia
|
||||||
@ -13,4 +13,7 @@ async function setupStore(app: App, options: InitStoreOptions) {
|
|||||||
app.use(pinia);
|
app.use(pinia);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { setupStore, useAccessStore, useTabbarStore };
|
export { setupStore };
|
||||||
|
|
||||||
|
export { useAccessStore } from './modules/access';
|
||||||
|
export { useAppStore } from './modules/app';
|
||||||
|
99
apps/web-antd/src/store/modules/access.ts
Normal file
99
apps/web-antd/src/store/modules/access.ts
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
import type { MenuRecordRaw, UserInfo } from '@vben/types';
|
||||||
|
import type { LoginAndRegisterParams } from '@vben/universal-ui';
|
||||||
|
import type { RouteRecordRaw } from 'vue-router';
|
||||||
|
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
import { DEFAULT_HOME_PATH } from '@vben/constants';
|
||||||
|
import { useCoreAccessStore } from '@vben-core/stores';
|
||||||
|
|
||||||
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
|
import { getUserInfo, userLogin } from '#/apis';
|
||||||
|
|
||||||
|
export const useAccessStore = defineStore('access', () => {
|
||||||
|
const coreStoreAccess = useCoreAccessStore();
|
||||||
|
const router = useRouter();
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
|
const accessToken = computed(() => coreStoreAccess.getAccessToken);
|
||||||
|
const userRoles = computed(() => coreStoreAccess.getUserRoles);
|
||||||
|
const userInfo = computed(() => coreStoreAccess.getUserInfo);
|
||||||
|
const accessRoutes = computed(() => coreStoreAccess.getAccessRoutes);
|
||||||
|
|
||||||
|
function setAccessMenus(menus: MenuRecordRaw[]) {
|
||||||
|
coreStoreAccess.setAccessMenus(menus);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setAccessRoutes(routes: RouteRecordRaw[]) {
|
||||||
|
coreStoreAccess.setAccessRoutes(routes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步处理登录操作
|
||||||
|
* Asynchronously handle the login process
|
||||||
|
* @param params 登录表单数据
|
||||||
|
*/
|
||||||
|
async function authLogin(
|
||||||
|
params: LoginAndRegisterParams,
|
||||||
|
onSuccess?: () => Promise<void>,
|
||||||
|
) {
|
||||||
|
// 异步处理用户登录操作并获取 accessToken
|
||||||
|
let userInfo: UserInfo | null = null;
|
||||||
|
try {
|
||||||
|
loading.value = true;
|
||||||
|
const { accessToken, refreshToken } = await userLogin(params);
|
||||||
|
|
||||||
|
// 如果成功获取到 accessToken
|
||||||
|
// If accessToken is successfully obtained
|
||||||
|
if (accessToken) {
|
||||||
|
// 将 accessToken 存储到 accessStore 中
|
||||||
|
// Store the accessToken in accessStore
|
||||||
|
coreStoreAccess.setAccessToken(accessToken);
|
||||||
|
coreStoreAccess.setRefreshToken(refreshToken);
|
||||||
|
|
||||||
|
// 获取用户信息并存储到 accessStore 中
|
||||||
|
// Get user information and store it in accessStore
|
||||||
|
userInfo = await fetchUserInfo();
|
||||||
|
|
||||||
|
coreStoreAccess.setUserInfo(userInfo);
|
||||||
|
|
||||||
|
onSuccess
|
||||||
|
? await onSuccess?.()
|
||||||
|
: await router.push(userInfo.homePath || DEFAULT_HOME_PATH);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
accessToken,
|
||||||
|
userInfo,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchUserInfo() {
|
||||||
|
let userInfo: UserInfo | null = null;
|
||||||
|
userInfo = await getUserInfo();
|
||||||
|
coreStoreAccess.setUserInfo(userInfo);
|
||||||
|
return userInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
coreStoreAccess.$reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
accessRoutes,
|
||||||
|
accessToken,
|
||||||
|
authLogin,
|
||||||
|
fetchUserInfo,
|
||||||
|
loading,
|
||||||
|
reset,
|
||||||
|
setAccessMenus,
|
||||||
|
setAccessRoutes,
|
||||||
|
userInfo,
|
||||||
|
userRoles,
|
||||||
|
};
|
||||||
|
});
|
20
apps/web-antd/src/store/modules/app.ts
Normal file
20
apps/web-antd/src/store/modules/app.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { useCoreAccessStore, useCoreTabbarStore } from '@vben-core/stores';
|
||||||
|
|
||||||
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
|
export const useAppStore = defineStore('app', () => {
|
||||||
|
const coreStoreAccess = useCoreAccessStore();
|
||||||
|
const coreTabbarStore = useCoreTabbarStore();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置所有 状态
|
||||||
|
*/
|
||||||
|
async function resetAppState() {
|
||||||
|
coreStoreAccess.$reset();
|
||||||
|
coreTabbarStore.$reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
resetAppState,
|
||||||
|
};
|
||||||
|
});
|
@ -1,17 +0,0 @@
|
|||||||
import { createPinia, setActivePinia } from 'pinia';
|
|
||||||
import { beforeEach, describe, expect, it } from 'vitest';
|
|
||||||
|
|
||||||
import { useCounterStore } from './example';
|
|
||||||
|
|
||||||
describe('useCounterStore', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
setActivePinia(createPinia());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('count test', () => {
|
|
||||||
setActivePinia(createPinia());
|
|
||||||
const counterStore = useCounterStore();
|
|
||||||
|
|
||||||
expect(counterStore.count).toBe(0);
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,14 +0,0 @@
|
|||||||
import { defineStore } from 'pinia';
|
|
||||||
|
|
||||||
export const useCounterStore = defineStore('counter', {
|
|
||||||
actions: {
|
|
||||||
increment() {
|
|
||||||
this.count++;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
getters: {
|
|
||||||
double: (state) => state.count * 2,
|
|
||||||
},
|
|
||||||
persist: [],
|
|
||||||
state: () => ({ count: 0 }),
|
|
||||||
});
|
|
@ -1,80 +1,36 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { LoginAndRegisterParams } from '@vben/universal-ui';
|
import type { LoginAndRegisterParams } from '@vben/universal-ui';
|
||||||
|
|
||||||
import { computed } from 'vue';
|
|
||||||
import { useRouter } from 'vue-router';
|
|
||||||
|
|
||||||
import { DEFAULT_HOME_PATH } from '@vben/constants';
|
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
import { AuthenticationLogin } from '@vben/universal-ui';
|
import { AuthenticationLogin } from '@vben/universal-ui';
|
||||||
import { useRequest } from '@vben-core/request';
|
|
||||||
import { useAccessStore } from '@vben-core/stores';
|
|
||||||
|
|
||||||
import { App } from 'ant-design-vue';
|
import { App } from 'ant-design-vue';
|
||||||
|
|
||||||
import { getUserInfo, userLogin } from '#/apis';
|
import { useAccessStore } from '#/store';
|
||||||
|
|
||||||
defineOptions({ name: 'Login' });
|
defineOptions({ name: 'Login' });
|
||||||
|
|
||||||
const router = useRouter();
|
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useAccessStore();
|
||||||
const { notification } = App.useApp();
|
const { notification } = App.useApp();
|
||||||
|
|
||||||
const { loading, runAsync: runUserLogin } = useRequest(userLogin, {
|
|
||||||
manual: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { loading: userInfoLoading, runAsync: runGetUserInfo } = useRequest(
|
|
||||||
getUserInfo,
|
|
||||||
{
|
|
||||||
manual: true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步处理登录操作
|
* @param params 登录表单数据
|
||||||
* Asynchronously handle the login process
|
|
||||||
* @param values 登录表单数据
|
|
||||||
*/
|
*/
|
||||||
async function handleLogin(values: LoginAndRegisterParams) {
|
async function handleLogin(params: LoginAndRegisterParams) {
|
||||||
// 异步处理用户登录操作并获取 accessToken
|
const { userInfo } = await accessStore.authLogin(params);
|
||||||
// Asynchronously handle the user login operation and obtain the accessToken
|
if (userInfo?.realName) {
|
||||||
|
|
||||||
const { accessToken, refreshToken } = await runUserLogin(values);
|
|
||||||
|
|
||||||
// 如果成功获取到 accessToken
|
|
||||||
// If accessToken is successfully obtained
|
|
||||||
if (accessToken) {
|
|
||||||
// 将 accessToken 存储到 accessStore 中
|
|
||||||
// Store the accessToken in accessStore
|
|
||||||
accessStore.setAccessToken(accessToken);
|
|
||||||
accessStore.setRefreshToken(refreshToken);
|
|
||||||
|
|
||||||
// 获取用户信息并存储到 accessStore 中
|
|
||||||
// Get user information and store it in accessStore
|
|
||||||
const userInfo = await runGetUserInfo();
|
|
||||||
|
|
||||||
accessStore.setUserInfo(userInfo);
|
|
||||||
|
|
||||||
// 跳转到用户信息中定义的 homePath 路径
|
|
||||||
// Redirect to the homePath defined in the user information
|
|
||||||
await router.push(userInfo.homePath || DEFAULT_HOME_PATH);
|
|
||||||
notification.success({
|
notification.success({
|
||||||
description: `${$t('authentication.login-success-desc')}:${userInfo.realName}`,
|
description: `${$t('authentication.login-success-desc')}:${userInfo?.realName}`,
|
||||||
duration: 3,
|
duration: 3,
|
||||||
message: $t('authentication.login-success'),
|
message: $t('authentication.login-success'),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const loginLoading = computed(() => {
|
|
||||||
return loading.value || userInfoLoading.value;
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<AuthenticationLogin
|
<AuthenticationLogin
|
||||||
:loading="loginLoading"
|
:loading="accessStore.loading"
|
||||||
password-placeholder="123456"
|
password-placeholder="123456"
|
||||||
username-placeholder="vben"
|
username-placeholder="vben"
|
||||||
@submit="handleLogin"
|
@submit="handleLogin"
|
||||||
|
@ -24,7 +24,7 @@ import AnalyticsVisitsSource from '../analytics/analytics-visits-source.vue';
|
|||||||
|
|
||||||
defineOptions({ name: 'Workspace' });
|
defineOptions({ name: 'Workspace' });
|
||||||
|
|
||||||
const { userInfo } = useAccessStore();
|
const accessStore = useAccessStore();
|
||||||
|
|
||||||
const projectItems: WorkbenchProjectItem[] = [
|
const projectItems: WorkbenchProjectItem[] = [
|
||||||
{
|
{
|
||||||
@ -203,10 +203,10 @@ const trendItems: WorkbenchTrendItem[] = [
|
|||||||
<template>
|
<template>
|
||||||
<div class="p-5">
|
<div class="p-5">
|
||||||
<WorkbenchHeader
|
<WorkbenchHeader
|
||||||
:avatar="userInfo?.avatar || preferences.app.defaultAvatar"
|
:avatar="accessStore.userInfo?.avatar || preferences.app.defaultAvatar"
|
||||||
>
|
>
|
||||||
<template #title>
|
<template #title>
|
||||||
早安, {{ userInfo?.realName }}, 开始您一天的工作吧!
|
早安, {{ accessStore.userInfo?.realName }}, 开始您一天的工作吧!
|
||||||
</template>
|
</template>
|
||||||
<template #description> 今日晴,20℃ - 32℃! </template>
|
<template #description> 今日晴,20℃ - 32℃! </template>
|
||||||
</WorkbenchHeader>
|
</WorkbenchHeader>
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { Fallback } from '@vben/universal-ui';
|
||||||
|
|
||||||
|
defineOptions({ name: 'AccessFrontendAccessTest1' });
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Fallback
|
||||||
|
description="当前页面仅 Super 角色可见"
|
||||||
|
status="comming-soon"
|
||||||
|
title="页面访问测试"
|
||||||
|
/>
|
||||||
|
</template>
|
@ -1,16 +1,48 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import type { LoginAndRegisterParams } from '@vben/universal-ui';
|
||||||
|
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { useAccess } from '@vben/access';
|
import { useAccess } from '@vben/access';
|
||||||
import { useAccessStore } from '@vben-core/stores';
|
|
||||||
|
|
||||||
import { Button } from 'ant-design-vue';
|
import { Button } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { useAccessStore, useAppStore } from '#/store';
|
||||||
|
|
||||||
defineOptions({ name: 'AccessBackend' });
|
defineOptions({ name: 'AccessBackend' });
|
||||||
|
|
||||||
const { currentAccessMode } = useAccess();
|
const { accessMode } = useAccess();
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useAccessStore();
|
||||||
|
const appStore = useAppStore();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
function roleButtonType(role: string) {
|
function roleButtonType(role: string) {
|
||||||
return accessStore.getUserRoles.includes(role) ? 'primary' : 'default';
|
return accessStore.userRoles.includes(role) ? 'primary' : 'default';
|
||||||
|
}
|
||||||
|
|
||||||
|
async function changeAccount(role: string) {
|
||||||
|
if (accessStore.userRoles.includes(role)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const accounts: Record<string, LoginAndRegisterParams> = {
|
||||||
|
admin: {
|
||||||
|
password: '123456',
|
||||||
|
username: 'admin',
|
||||||
|
},
|
||||||
|
super: {
|
||||||
|
password: '123456',
|
||||||
|
username: 'vben',
|
||||||
|
},
|
||||||
|
user: {
|
||||||
|
password: '123456',
|
||||||
|
username: 'jack',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const account = accounts[role];
|
||||||
|
await appStore.resetAppState();
|
||||||
|
await accessStore.authLogin(account, async () => {
|
||||||
|
router.go(0);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -19,26 +51,39 @@ function roleButtonType(role: string) {
|
|||||||
<div class="card-box p-5">
|
<div class="card-box p-5">
|
||||||
<h1 class="text-xl font-semibold">前端页面访问演示</h1>
|
<h1 class="text-xl font-semibold">前端页面访问演示</h1>
|
||||||
<div class="text-foreground/80 mt-2">
|
<div class="text-foreground/80 mt-2">
|
||||||
由于刷新的时候会请求用户信息接口,会根据接口重置角色信息,所以刷新后界面会恢复原样。如果不需要,可以注释对应的代码。
|
切换不同的账号,观察左侧菜单变化。
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<template v-if="currentAccessMode === 'frontend'">
|
<template v-if="accessMode === 'frontend'">
|
||||||
<div class="card-box mt-5 p-5 font-semibold">
|
<div class="card-box mt-5 p-5 font-semibold">
|
||||||
当前权限模式:
|
当前权限模式:
|
||||||
<span class="text-primary mx-4">{{ currentAccessMode }}</span>
|
<span class="text-primary mx-4">{{ accessMode }}</span>
|
||||||
<Button type="primary">切换权限模式</Button>
|
<Button type="primary">切换权限模式</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-box mt-5 p-5 font-semibold">
|
<div class="card-box mt-5 p-5 font-semibold">
|
||||||
当前用户角色:
|
<div class="mb-3">
|
||||||
<span class="text-primary mx-4">{{ accessStore.getUserRoles }}</span>
|
当前账号:
|
||||||
<Button :type="roleButtonType('admin')"> 切换为 Admin 角色 </Button>
|
<span class="text-primary mx-4">
|
||||||
<Button :type="roleButtonType('user')" class="mx-4">
|
{{ accessStore.userRoles }}
|
||||||
切换为 User 角色
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button :type="roleButtonType('super')" @click="changeAccount('super')">
|
||||||
|
切换为 Super 账号
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<div class="text-foreground/80 mt-2">角色后请查看左侧菜单变化</div>
|
<Button
|
||||||
|
:type="roleButtonType('admin')"
|
||||||
|
class="mx-4"
|
||||||
|
@click="changeAccount('admin')"
|
||||||
|
>
|
||||||
|
切换为 Admin 账号
|
||||||
|
</Button>
|
||||||
|
<Button :type="roleButtonType('user')" @click="changeAccount('user')">
|
||||||
|
切换为 User 账号
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
"eslint-config-prettier": "^9.1.0",
|
"eslint-config-prettier": "^9.1.0",
|
||||||
"eslint-plugin-eslint-comments": "^3.2.0",
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
||||||
"eslint-plugin-i": "^2.29.1",
|
"eslint-plugin-i": "^2.29.1",
|
||||||
"eslint-plugin-jsdoc": "^48.5.0",
|
"eslint-plugin-jsdoc": "^48.5.2",
|
||||||
"eslint-plugin-jsonc": "^2.16.0",
|
"eslint-plugin-jsonc": "^2.16.0",
|
||||||
"eslint-plugin-n": "^17.9.0",
|
"eslint-plugin-n": "^17.9.0",
|
||||||
"eslint-plugin-no-only-tests": "^3.1.0",
|
"eslint-plugin-no-only-tests": "^3.1.0",
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { createPinia, setActivePinia } from 'pinia';
|
import { createPinia, setActivePinia } from 'pinia';
|
||||||
import { beforeEach, describe, expect, it } from 'vitest';
|
import { beforeEach, describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
import { useAccessStore } from './access';
|
import { useCoreAccessStore } from './access';
|
||||||
|
|
||||||
describe('useAccessStore', () => {
|
describe('useCoreAccessStore', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
setActivePinia(createPinia());
|
setActivePinia(createPinia());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates accessMenus state', () => {
|
it('updates accessMenus state', () => {
|
||||||
const store = useAccessStore();
|
const store = useCoreAccessStore();
|
||||||
expect(store.accessMenus).toEqual([]);
|
expect(store.accessMenus).toEqual([]);
|
||||||
store.setAccessMenus([{ name: 'Dashboard', path: '/dashboard' }]);
|
store.setAccessMenus([{ name: 'Dashboard', path: '/dashboard' }]);
|
||||||
expect(store.accessMenus).toEqual([
|
expect(store.accessMenus).toEqual([
|
||||||
@ -18,7 +18,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('updates userInfo and userRoles state', () => {
|
it('updates userInfo and userRoles state', () => {
|
||||||
const store = useAccessStore();
|
const store = useCoreAccessStore();
|
||||||
expect(store.userInfo).toBeNull();
|
expect(store.userInfo).toBeNull();
|
||||||
expect(store.userRoles).toEqual([]);
|
expect(store.userRoles).toEqual([]);
|
||||||
|
|
||||||
@ -30,14 +30,14 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns correct userInfo', () => {
|
it('returns correct userInfo', () => {
|
||||||
const store = useAccessStore();
|
const store = useCoreAccessStore();
|
||||||
const userInfo: any = { name: 'Jane Doe', roles: [{ value: 'user' }] };
|
const userInfo: any = { name: 'Jane Doe', roles: [{ value: 'user' }] };
|
||||||
store.setUserInfo(userInfo);
|
store.setUserInfo(userInfo);
|
||||||
expect(store.getUserInfo).toEqual(userInfo);
|
expect(store.getUserInfo).toEqual(userInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates accessToken state correctly', () => {
|
it('updates accessToken state correctly', () => {
|
||||||
const store = useAccessStore();
|
const store = useCoreAccessStore();
|
||||||
expect(store.accessToken).toBeNull(); // 初始状态
|
expect(store.accessToken).toBeNull(); // 初始状态
|
||||||
store.setAccessToken('abc123');
|
store.setAccessToken('abc123');
|
||||||
expect(store.accessToken).toBe('abc123');
|
expect(store.accessToken).toBe('abc123');
|
||||||
@ -45,7 +45,7 @@ describe('useAccessStore', () => {
|
|||||||
|
|
||||||
// 测试重置用户信息时的行为
|
// 测试重置用户信息时的行为
|
||||||
it('clears userInfo and userRoles when setting null userInfo', () => {
|
it('clears userInfo and userRoles when setting null userInfo', () => {
|
||||||
const store = useAccessStore();
|
const store = useCoreAccessStore();
|
||||||
store.setUserInfo({
|
store.setUserInfo({
|
||||||
roles: [{ roleName: 'User', value: 'user' }],
|
roles: [{ roleName: 'User', value: 'user' }],
|
||||||
} as any);
|
} as any);
|
||||||
@ -58,27 +58,27 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns the correct accessToken', () => {
|
it('returns the correct accessToken', () => {
|
||||||
const store = useAccessStore();
|
const store = useCoreAccessStore();
|
||||||
store.setAccessToken('xyz789');
|
store.setAccessToken('xyz789');
|
||||||
expect(store.getAccessToken).toBe('xyz789');
|
expect(store.getAccessToken).toBe('xyz789');
|
||||||
});
|
});
|
||||||
|
|
||||||
// 测试在没有用户角色时返回空数组
|
// 测试在没有用户角色时返回空数组
|
||||||
it('returns an empty array for userRoles if not set', () => {
|
it('returns an empty array for userRoles if not set', () => {
|
||||||
const store = useAccessStore();
|
const store = useCoreAccessStore();
|
||||||
expect(store.getUserRoles).toEqual([]);
|
expect(store.getUserRoles).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 测试设置空的访问菜单列表
|
// 测试设置空的访问菜单列表
|
||||||
it('handles empty accessMenus correctly', () => {
|
it('handles empty accessMenus correctly', () => {
|
||||||
const store = useAccessStore();
|
const store = useCoreAccessStore();
|
||||||
store.setAccessMenus([]);
|
store.setAccessMenus([]);
|
||||||
expect(store.accessMenus).toEqual([]);
|
expect(store.accessMenus).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 测试设置空的访问路由列表
|
// 测试设置空的访问路由列表
|
||||||
it('handles empty accessRoutes correctly', () => {
|
it('handles empty accessRoutes correctly', () => {
|
||||||
const store = useAccessStore();
|
const store = useCoreAccessStore();
|
||||||
store.setAccessRoutes([]);
|
store.setAccessRoutes([]);
|
||||||
expect(store.accessRoutes).toEqual([]);
|
expect(store.accessRoutes).toEqual([]);
|
||||||
});
|
});
|
||||||
|
@ -58,7 +58,7 @@ interface AccessState {
|
|||||||
/**
|
/**
|
||||||
* @zh_CN 访问权限相关
|
* @zh_CN 访问权限相关
|
||||||
*/
|
*/
|
||||||
const useAccessStore = defineStore('access', {
|
const useCoreAccessStore = defineStore('core-access', {
|
||||||
actions: {
|
actions: {
|
||||||
setAccessMenus(menus: MenuRecordRaw[]) {
|
setAccessMenus(menus: MenuRecordRaw[]) {
|
||||||
this.accessMenus = menus;
|
this.accessMenus = menus;
|
||||||
@ -72,7 +72,7 @@ const useAccessStore = defineStore('access', {
|
|||||||
setRefreshToken(token: AccessToken) {
|
setRefreshToken(token: AccessToken) {
|
||||||
this.refreshToken = token;
|
this.refreshToken = token;
|
||||||
},
|
},
|
||||||
setUserInfo(userInfo: BasicUserInfo) {
|
setUserInfo(userInfo: BasicUserInfo | null) {
|
||||||
// 设置用户信息
|
// 设置用户信息
|
||||||
this.userInfo = userInfo;
|
this.userInfo = userInfo;
|
||||||
// 设置角色信息
|
// 设置角色信息
|
||||||
@ -105,7 +105,7 @@ const useAccessStore = defineStore('access', {
|
|||||||
},
|
},
|
||||||
persist: {
|
persist: {
|
||||||
// 持久化
|
// 持久化
|
||||||
paths: ['accessToken', 'refreshToken', 'userRoles', 'userInfo'],
|
paths: ['accessToken', 'refreshToken'],
|
||||||
},
|
},
|
||||||
state: (): AccessState => ({
|
state: (): AccessState => ({
|
||||||
accessMenus: [],
|
accessMenus: [],
|
||||||
@ -120,7 +120,7 @@ const useAccessStore = defineStore('access', {
|
|||||||
// 解决热更新问题
|
// 解决热更新问题
|
||||||
const hot = import.meta.hot;
|
const hot = import.meta.hot;
|
||||||
if (hot) {
|
if (hot) {
|
||||||
hot.accept(acceptHMRUpdate(useAccessStore, hot));
|
hot.accept(acceptHMRUpdate(useCoreAccessStore, hot));
|
||||||
}
|
}
|
||||||
|
|
||||||
export { useAccessStore };
|
export { useCoreAccessStore };
|
||||||
|
@ -3,9 +3,9 @@ import { createRouter, createWebHistory } from 'vue-router';
|
|||||||
import { createPinia, setActivePinia } from 'pinia';
|
import { createPinia, setActivePinia } from 'pinia';
|
||||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
|
|
||||||
import { useTabbarStore } from './tabbar';
|
import { useCoreTabbarStore } from './tabbar';
|
||||||
|
|
||||||
describe('useAccessStore', () => {
|
describe('useCoreAccessStore', () => {
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(),
|
history: createWebHistory(),
|
||||||
routes: [],
|
routes: [],
|
||||||
@ -18,7 +18,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('adds a new tab', () => {
|
it('adds a new tab', () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
const tab: any = {
|
const tab: any = {
|
||||||
fullPath: '/home',
|
fullPath: '/home',
|
||||||
meta: {},
|
meta: {},
|
||||||
@ -31,7 +31,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('adds a new tab if it does not exist', () => {
|
it('adds a new tab if it does not exist', () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
const newTab: any = {
|
const newTab: any = {
|
||||||
fullPath: '/new',
|
fullPath: '/new',
|
||||||
meta: {},
|
meta: {},
|
||||||
@ -43,7 +43,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('updates an existing tab instead of adding a new one', () => {
|
it('updates an existing tab instead of adding a new one', () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
const initialTab: any = {
|
const initialTab: any = {
|
||||||
fullPath: '/existing',
|
fullPath: '/existing',
|
||||||
meta: {},
|
meta: {},
|
||||||
@ -59,7 +59,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('closes all tabs', async () => {
|
it('closes all tabs', async () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
store.tabs = [
|
store.tabs = [
|
||||||
{ fullPath: '/home', meta: {}, name: 'Home', path: '/home' },
|
{ fullPath: '/home', meta: {}, name: 'Home', path: '/home' },
|
||||||
] as any;
|
] as any;
|
||||||
@ -72,7 +72,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns all tabs including affix tabs', () => {
|
it('returns all tabs including affix tabs', () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
store.tabs = [
|
store.tabs = [
|
||||||
{ fullPath: '/home', meta: {}, name: 'Home', path: '/home' },
|
{ fullPath: '/home', meta: {}, name: 'Home', path: '/home' },
|
||||||
] as any;
|
] as any;
|
||||||
@ -86,7 +86,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('closes a non-affix tab', () => {
|
it('closes a non-affix tab', () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
const tab: any = {
|
const tab: any = {
|
||||||
fullPath: '/closable',
|
fullPath: '/closable',
|
||||||
meta: {},
|
meta: {},
|
||||||
@ -99,7 +99,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not close an affix tab', () => {
|
it('does not close an affix tab', () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
const affixTab: any = {
|
const affixTab: any = {
|
||||||
fullPath: '/affix',
|
fullPath: '/affix',
|
||||||
meta: { affixTab: true },
|
meta: { affixTab: true },
|
||||||
@ -112,14 +112,14 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns all cache tabs', () => {
|
it('returns all cache tabs', () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
store.cacheTabs.add('Home');
|
store.cacheTabs.add('Home');
|
||||||
store.cacheTabs.add('About');
|
store.cacheTabs.add('About');
|
||||||
expect(store.getCacheTabs).toEqual(['Home', 'About']);
|
expect(store.getCacheTabs).toEqual(['Home', 'About']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns all tabs, including affix tabs', () => {
|
it('returns all tabs, including affix tabs', () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
const normalTab: any = {
|
const normalTab: any = {
|
||||||
fullPath: '/normal',
|
fullPath: '/normal',
|
||||||
meta: {},
|
meta: {},
|
||||||
@ -139,7 +139,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('navigates to a specific tab', async () => {
|
it('navigates to a specific tab', async () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
const tab: any = { meta: {}, name: 'Dashboard', path: '/dashboard' };
|
const tab: any = { meta: {}, name: 'Dashboard', path: '/dashboard' };
|
||||||
|
|
||||||
await store._goToTab(tab, router);
|
await store._goToTab(tab, router);
|
||||||
@ -152,7 +152,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('closes multiple tabs by paths', async () => {
|
it('closes multiple tabs by paths', async () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
store.addTab({
|
store.addTab({
|
||||||
fullPath: '/home',
|
fullPath: '/home',
|
||||||
meta: {},
|
meta: {},
|
||||||
@ -179,7 +179,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('closes all tabs to the left of the specified tab', async () => {
|
it('closes all tabs to the left of the specified tab', async () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
store.addTab({
|
store.addTab({
|
||||||
fullPath: '/home',
|
fullPath: '/home',
|
||||||
meta: {},
|
meta: {},
|
||||||
@ -207,7 +207,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('closes all tabs except the specified tab', async () => {
|
it('closes all tabs except the specified tab', async () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
store.addTab({
|
store.addTab({
|
||||||
fullPath: '/home',
|
fullPath: '/home',
|
||||||
meta: {},
|
meta: {},
|
||||||
@ -235,7 +235,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('closes all tabs to the right of the specified tab', async () => {
|
it('closes all tabs to the right of the specified tab', async () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
const targetTab: any = {
|
const targetTab: any = {
|
||||||
fullPath: '/home',
|
fullPath: '/home',
|
||||||
meta: {},
|
meta: {},
|
||||||
@ -263,7 +263,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('closes the tab with the specified key', async () => {
|
it('closes the tab with the specified key', async () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
const keyToClose = '/about';
|
const keyToClose = '/about';
|
||||||
store.addTab({
|
store.addTab({
|
||||||
fullPath: '/home',
|
fullPath: '/home',
|
||||||
@ -293,7 +293,7 @@ describe('useAccessStore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('refreshes the current tab', async () => {
|
it('refreshes the current tab', async () => {
|
||||||
const store = useTabbarStore();
|
const store = useCoreTabbarStore();
|
||||||
const currentTab: any = {
|
const currentTab: any = {
|
||||||
fullPath: '/dashboard',
|
fullPath: '/dashboard',
|
||||||
meta: { name: 'Dashboard' },
|
meta: { name: 'Dashboard' },
|
||||||
@ -302,7 +302,7 @@ describe('useAccessStore', () => {
|
|||||||
};
|
};
|
||||||
router.currentRoute.value = currentTab;
|
router.currentRoute.value = currentTab;
|
||||||
|
|
||||||
await store.refreshTab(router);
|
await store.refresh(router);
|
||||||
|
|
||||||
expect(store.excludeCacheTabs.has('Dashboard')).toBe(false);
|
expect(store.excludeCacheTabs.has('Dashboard')).toBe(false);
|
||||||
expect(store.renderRouteView).toBe(true);
|
expect(store.renderRouteView).toBe(true);
|
||||||
|
@ -62,7 +62,7 @@ interface TabsState {
|
|||||||
/**
|
/**
|
||||||
* @zh_CN 访问权限相关
|
* @zh_CN 访问权限相关
|
||||||
*/
|
*/
|
||||||
const useTabbarStore = defineStore('tabbar', {
|
const useCoreTabbarStore = defineStore('core-tabbar', {
|
||||||
actions: {
|
actions: {
|
||||||
/**
|
/**
|
||||||
* Close tabs in bulk
|
* Close tabs in bulk
|
||||||
@ -290,7 +290,7 @@ const useTabbarStore = defineStore('tabbar', {
|
|||||||
/**
|
/**
|
||||||
* 刷新标签页
|
* 刷新标签页
|
||||||
*/
|
*/
|
||||||
async refreshTab(router: Router) {
|
async refresh(router: Router) {
|
||||||
const { currentRoute } = router;
|
const { currentRoute } = router;
|
||||||
const { name } = currentRoute.value;
|
const { name } = currentRoute.value;
|
||||||
|
|
||||||
@ -395,7 +395,7 @@ const useTabbarStore = defineStore('tabbar', {
|
|||||||
// 解决热更新问题
|
// 解决热更新问题
|
||||||
const hot = import.meta.hot;
|
const hot = import.meta.hot;
|
||||||
if (hot) {
|
if (hot) {
|
||||||
hot.accept(acceptHMRUpdate(useTabbarStore, hot));
|
hot.accept(acceptHMRUpdate(useCoreTabbarStore, hot));
|
||||||
}
|
}
|
||||||
|
|
||||||
export { useTabbarStore };
|
export { useCoreTabbarStore };
|
||||||
|
@ -39,10 +39,12 @@
|
|||||||
"@vue/shared": "^3.4.31",
|
"@vue/shared": "^3.4.31",
|
||||||
"clsx": "2.1.1",
|
"clsx": "2.1.1",
|
||||||
"defu": "^6.1.4",
|
"defu": "^6.1.4",
|
||||||
|
"lodash.clonedeep": "^4.5.0",
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
"tailwind-merge": "^2.3.0"
|
"tailwind-merge": "^2.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/lodash.clonedeep": "^4.5.9",
|
||||||
"@types/nprogress": "^0.2.3"
|
"@types/nprogress": "^0.2.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,3 +10,4 @@ export * from './tree';
|
|||||||
export * from './unique';
|
export * from './unique';
|
||||||
export * from './update-css-variables';
|
export * from './update-css-variables';
|
||||||
export * from './window';
|
export * from './window';
|
||||||
|
export { default as cloneDepp } from 'lodash.clonedeep';
|
||||||
|
@ -3,6 +3,8 @@ import type { RouteRecordRaw } from 'vue-router';
|
|||||||
|
|
||||||
import type { GeneratorMenuAndRoutesOptions } from '../types';
|
import type { GeneratorMenuAndRoutesOptions } from '../types';
|
||||||
|
|
||||||
|
import { cloneDepp } from '@vben-core/toolkit';
|
||||||
|
|
||||||
import { generateMenus } from './generate-menus';
|
import { generateMenus } from './generate-menus';
|
||||||
import { generateRoutesByBackend } from './generate-routes-backend';
|
import { generateRoutesByBackend } from './generate-routes-backend';
|
||||||
import { generateRoutesByFrontend } from './generate-routes-frontend';
|
import { generateRoutesByFrontend } from './generate-routes-frontend';
|
||||||
@ -12,6 +14,8 @@ async function generateMenusAndRoutes(
|
|||||||
options: GeneratorMenuAndRoutesOptions,
|
options: GeneratorMenuAndRoutesOptions,
|
||||||
) {
|
) {
|
||||||
const { router } = options;
|
const { router } = options;
|
||||||
|
|
||||||
|
options.routes = cloneDepp(options.routes);
|
||||||
// 生成路由
|
// 生成路由
|
||||||
const accessibleRoutes = await generateRoutes(mode, options);
|
const accessibleRoutes = await generateRoutes(mode, options);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export { default as Authority } from './authority.vue';
|
|
||||||
export * from './generate-menu-and-routes';
|
export * from './generate-menu-and-routes';
|
||||||
|
export { default as RoleAuthority } from './role-authority.vue';
|
||||||
export type * from './types';
|
export type * from './types';
|
||||||
export * from './use-access';
|
export * from './use-access';
|
||||||
|
@ -9,15 +9,15 @@ interface Props {
|
|||||||
* - When the permission mode is 'backend', the value can be a code permission value.
|
* - When the permission mode is 'backend', the value can be a code permission value.
|
||||||
* @default ''
|
* @default ''
|
||||||
*/
|
*/
|
||||||
value?: string[];
|
roles?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'Authority',
|
name: 'FrontendAuthority',
|
||||||
});
|
});
|
||||||
|
|
||||||
withDefaults(defineProps<Props>(), {
|
withDefaults(defineProps<Props>(), {
|
||||||
value: undefined,
|
roles: undefined,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -1,28 +1,13 @@
|
|||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
|
||||||
import { preferences } from '@vben-core/preferences';
|
import { preferences } from '@vben-core/preferences';
|
||||||
import { useAccessStore } from '@vben-core/stores';
|
|
||||||
|
|
||||||
function useAccess() {
|
function useAccess() {
|
||||||
const accessStore = useAccessStore();
|
const accessMode = computed(() => {
|
||||||
const currentAccessMode = computed(() => {
|
|
||||||
return preferences.app.accessMode;
|
return preferences.app.accessMode;
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
return { accessMode };
|
||||||
* 更改账号角色
|
|
||||||
* @param roles
|
|
||||||
*/
|
|
||||||
async function changeRoles(roles: string[]): Promise<void> {
|
|
||||||
if (preferences.app.accessMode !== 'frontend') {
|
|
||||||
throw new Error(
|
|
||||||
'The current access mode is not frontend, so the role cannot be changed',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
accessStore.setUserRoles(roles);
|
|
||||||
}
|
|
||||||
|
|
||||||
return { changeRoles, currentAccessMode };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { useAccess };
|
export { useAccess };
|
||||||
|
@ -3,14 +3,14 @@ import type { RouteLocationNormalizedLoaded } from 'vue-router';
|
|||||||
|
|
||||||
import { preferences, usePreferences } from '@vben-core/preferences';
|
import { preferences, usePreferences } from '@vben-core/preferences';
|
||||||
import { Spinner } from '@vben-core/shadcn-ui';
|
import { Spinner } from '@vben-core/shadcn-ui';
|
||||||
import { storeToRefs, useTabbarStore } from '@vben-core/stores';
|
import { storeToRefs, useCoreTabbarStore } from '@vben-core/stores';
|
||||||
|
|
||||||
import { IFrameRouterView } from '../../iframe';
|
import { IFrameRouterView } from '../../iframe';
|
||||||
import { useContentSpinner } from './use-content-spinner';
|
import { useContentSpinner } from './use-content-spinner';
|
||||||
|
|
||||||
defineOptions({ name: 'LayoutContent' });
|
defineOptions({ name: 'LayoutContent' });
|
||||||
|
|
||||||
const tabsStore = useTabbarStore();
|
const tabsStore = useCoreTabbarStore();
|
||||||
const { keepAlive } = usePreferences();
|
const { keepAlive } = usePreferences();
|
||||||
const { spinning } = useContentSpinner();
|
const { spinning } = useContentSpinner();
|
||||||
|
|
||||||
@ -64,7 +64,11 @@ function getTransitionName(route: RouteLocationNormalizedLoaded) {
|
|||||||
:key="route.fullPath"
|
:key="route.fullPath"
|
||||||
/>
|
/>
|
||||||
</KeepAlive>
|
</KeepAlive>
|
||||||
<component :is="Component" v-else :key="route.fullPath" />
|
<component
|
||||||
|
:is="Component"
|
||||||
|
v-else-if="renderRouteView"
|
||||||
|
:key="route.fullPath"
|
||||||
|
/>
|
||||||
</Transition>
|
</Transition>
|
||||||
</RouterView>
|
</RouterView>
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import { GlobalSearch, LanguageToggle, ThemeToggle } from '@vben/widgets';
|
import { GlobalSearch, LanguageToggle, ThemeToggle } from '@vben/widgets';
|
||||||
import { usePreferences } from '@vben-core/preferences';
|
import { usePreferences } from '@vben-core/preferences';
|
||||||
import { VbenFullScreen } from '@vben-core/shadcn-ui';
|
import { VbenFullScreen } from '@vben-core/shadcn-ui';
|
||||||
import { useAccessStore } from '@vben-core/stores';
|
import { useCoreAccessStore } from '@vben-core/stores';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
/**
|
/**
|
||||||
@ -19,7 +19,7 @@ withDefaults(defineProps<Props>(), {
|
|||||||
theme: 'light',
|
theme: 'light',
|
||||||
});
|
});
|
||||||
|
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useCoreAccessStore();
|
||||||
const { globalSearchShortcutKey } = usePreferences();
|
const { globalSearchShortcutKey } = usePreferences();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -5,12 +5,12 @@ import { useRoute } from 'vue-router';
|
|||||||
|
|
||||||
import { findRootMenuByPath } from '@vben-core/helpers';
|
import { findRootMenuByPath } from '@vben-core/helpers';
|
||||||
import { preferences } from '@vben-core/preferences';
|
import { preferences } from '@vben-core/preferences';
|
||||||
import { useAccessStore } from '@vben-core/stores';
|
import { useCoreAccessStore } from '@vben-core/stores';
|
||||||
|
|
||||||
import { useNavigation } from './use-navigation';
|
import { useNavigation } from './use-navigation';
|
||||||
|
|
||||||
function useExtraMenu() {
|
function useExtraMenu() {
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useCoreAccessStore();
|
||||||
const { navigation } = useNavigation();
|
const { navigation } = useNavigation();
|
||||||
|
|
||||||
const menus = computed(() => accessStore.getAccessMenus);
|
const menus = computed(() => accessStore.getAccessMenus);
|
||||||
|
@ -5,12 +5,12 @@ import { useRoute } from 'vue-router';
|
|||||||
|
|
||||||
import { findRootMenuByPath } from '@vben-core/helpers';
|
import { findRootMenuByPath } from '@vben-core/helpers';
|
||||||
import { preferences, usePreferences } from '@vben-core/preferences';
|
import { preferences, usePreferences } from '@vben-core/preferences';
|
||||||
import { useAccessStore } from '@vben-core/stores';
|
import { useCoreAccessStore } from '@vben-core/stores';
|
||||||
|
|
||||||
import { useNavigation } from './use-navigation';
|
import { useNavigation } from './use-navigation';
|
||||||
|
|
||||||
function useMixedMenu() {
|
function useMixedMenu() {
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useCoreAccessStore();
|
||||||
const { navigation } = useNavigation();
|
const { navigation } = useNavigation();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const splitSideMenus = ref<MenuRecordRaw[]>([]);
|
const splitSideMenus = ref<MenuRecordRaw[]>([]);
|
||||||
|
@ -19,14 +19,18 @@ import {
|
|||||||
MdiPin,
|
MdiPin,
|
||||||
MdiPinOff,
|
MdiPinOff,
|
||||||
} from '@vben-core/iconify';
|
} from '@vben-core/iconify';
|
||||||
import { storeToRefs, useAccessStore, useTabbarStore } from '@vben-core/stores';
|
import {
|
||||||
|
storeToRefs,
|
||||||
|
useCoreAccessStore,
|
||||||
|
useCoreTabbarStore,
|
||||||
|
} from '@vben-core/stores';
|
||||||
import { filterTree } from '@vben-core/toolkit';
|
import { filterTree } from '@vben-core/toolkit';
|
||||||
|
|
||||||
function useTabs() {
|
function useTabs() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useCoreAccessStore();
|
||||||
const tabsStore = useTabbarStore();
|
const tabbarStore = useCoreTabbarStore();
|
||||||
const { accessMenus } = storeToRefs(accessStore);
|
const { accessMenus } = storeToRefs(accessStore);
|
||||||
|
|
||||||
const currentActive = computed(() => {
|
const currentActive = computed(() => {
|
||||||
@ -35,7 +39,7 @@ function useTabs() {
|
|||||||
|
|
||||||
const { locale } = useI18n();
|
const { locale } = useI18n();
|
||||||
const currentTabs = ref<RouteLocationNormalizedGeneric[]>();
|
const currentTabs = ref<RouteLocationNormalizedGeneric[]>();
|
||||||
watch([() => tabsStore.getTabs, () => locale.value], ([tabs, _]) => {
|
watch([() => tabbarStore.getTabs, () => locale.value], ([tabs, _]) => {
|
||||||
currentTabs.value = tabs.map((item) => wrapperTabLocale(item));
|
currentTabs.value = tabs.map((item) => wrapperTabLocale(item));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -46,7 +50,7 @@ function useTabs() {
|
|||||||
const affixTabs = filterTree(router.getRoutes(), (route) => {
|
const affixTabs = filterTree(router.getRoutes(), (route) => {
|
||||||
return !!route.meta?.affixTab;
|
return !!route.meta?.affixTab;
|
||||||
});
|
});
|
||||||
tabsStore.setAffixTabs(affixTabs);
|
tabbarStore.setAffixTabs(affixTabs);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 点击tab,跳转路由
|
// 点击tab,跳转路由
|
||||||
@ -56,7 +60,7 @@ function useTabs() {
|
|||||||
|
|
||||||
// 关闭tab
|
// 关闭tab
|
||||||
const handleClose = async (key: string) => {
|
const handleClose = async (key: string) => {
|
||||||
await tabsStore.closeTabByKey(key, router);
|
await tabbarStore.closeTabByKey(key, router);
|
||||||
};
|
};
|
||||||
|
|
||||||
function wrapperTabLocale(tab: RouteLocationNormalizedGeneric) {
|
function wrapperTabLocale(tab: RouteLocationNormalizedGeneric) {
|
||||||
@ -80,14 +84,14 @@ function useTabs() {
|
|||||||
watch(
|
watch(
|
||||||
() => route.path,
|
() => route.path,
|
||||||
() => {
|
() => {
|
||||||
tabsStore.addTab(route as RouteLocationNormalized);
|
tabbarStore.addTab(route as RouteLocationNormalized);
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
const createContextMenus = (tab: TabItem) => {
|
const createContextMenus = (tab: TabItem) => {
|
||||||
const tabs = tabsStore.getTabs;
|
const tabs = tabbarStore.getTabs;
|
||||||
const affixTabs = tabsStore.affixTabs;
|
const affixTabs = tabbarStore.affixTabs;
|
||||||
const index = tabs.findIndex((item) => item.path === tab.path);
|
const index = tabs.findIndex((item) => item.path === tab.path);
|
||||||
|
|
||||||
const disabled = tabs.length <= 1;
|
const disabled = tabs.length <= 1;
|
||||||
@ -109,7 +113,7 @@ function useTabs() {
|
|||||||
{
|
{
|
||||||
disabled: !isCurrentTab,
|
disabled: !isCurrentTab,
|
||||||
handler: async () => {
|
handler: async () => {
|
||||||
await tabsStore.refreshTab(router);
|
await tabbarStore.refresh(router);
|
||||||
},
|
},
|
||||||
icon: IcRoundRefresh,
|
icon: IcRoundRefresh,
|
||||||
key: 'reload',
|
key: 'reload',
|
||||||
@ -118,7 +122,7 @@ function useTabs() {
|
|||||||
{
|
{
|
||||||
disabled: !!affixTab || disabled,
|
disabled: !!affixTab || disabled,
|
||||||
handler: async () => {
|
handler: async () => {
|
||||||
await tabsStore.closeTab(tab, router);
|
await tabbarStore.closeTab(tab, router);
|
||||||
},
|
},
|
||||||
icon: IcRoundClose,
|
icon: IcRoundClose,
|
||||||
key: 'close',
|
key: 'close',
|
||||||
@ -127,8 +131,8 @@ function useTabs() {
|
|||||||
{
|
{
|
||||||
handler: async () => {
|
handler: async () => {
|
||||||
await (affixTab
|
await (affixTab
|
||||||
? tabsStore.unPushPinTab(tab)
|
? tabbarStore.unPushPinTab(tab)
|
||||||
: tabsStore.pushPinTab(tab));
|
: tabbarStore.pushPinTab(tab));
|
||||||
},
|
},
|
||||||
icon: affixTab ? MdiPinOff : MdiPin,
|
icon: affixTab ? MdiPinOff : MdiPin,
|
||||||
key: 'affix',
|
key: 'affix',
|
||||||
@ -140,7 +144,7 @@ function useTabs() {
|
|||||||
{
|
{
|
||||||
disabled: closeLeftDisabled,
|
disabled: closeLeftDisabled,
|
||||||
handler: async () => {
|
handler: async () => {
|
||||||
await tabsStore.closeLeftTabs(tab);
|
await tabbarStore.closeLeftTabs(tab);
|
||||||
},
|
},
|
||||||
icon: MdiFormatHorizontalAlignLeft,
|
icon: MdiFormatHorizontalAlignLeft,
|
||||||
key: 'close-left',
|
key: 'close-left',
|
||||||
@ -149,7 +153,7 @@ function useTabs() {
|
|||||||
{
|
{
|
||||||
disabled: closeRightDisabled,
|
disabled: closeRightDisabled,
|
||||||
handler: async () => {
|
handler: async () => {
|
||||||
await tabsStore.closeRightTabs(tab);
|
await tabbarStore.closeRightTabs(tab);
|
||||||
},
|
},
|
||||||
icon: MdiFormatHorizontalAlignRight,
|
icon: MdiFormatHorizontalAlignRight,
|
||||||
key: 'close-right',
|
key: 'close-right',
|
||||||
@ -159,7 +163,7 @@ function useTabs() {
|
|||||||
{
|
{
|
||||||
disabled: closeOtherDisabled,
|
disabled: closeOtherDisabled,
|
||||||
handler: async () => {
|
handler: async () => {
|
||||||
await tabsStore.closeOtherTabs(tab);
|
await tabbarStore.closeOtherTabs(tab);
|
||||||
},
|
},
|
||||||
icon: MdiArrowExpandHorizontal,
|
icon: MdiArrowExpandHorizontal,
|
||||||
key: 'close-other',
|
key: 'close-other',
|
||||||
@ -168,7 +172,7 @@ function useTabs() {
|
|||||||
{
|
{
|
||||||
disabled,
|
disabled,
|
||||||
handler: async () => {
|
handler: async () => {
|
||||||
await tabsStore.closeAllTabs(router);
|
await tabbarStore.closeAllTabs(router);
|
||||||
},
|
},
|
||||||
icon: IcRoundMultipleStop,
|
icon: IcRoundMultipleStop,
|
||||||
key: 'close-all',
|
key: 'close-all',
|
||||||
@ -187,7 +191,7 @@ function useTabs() {
|
|||||||
* 取消固定标签页
|
* 取消固定标签页
|
||||||
*/
|
*/
|
||||||
const handleUnPushPin = async (tab: TabItem) => {
|
const handleUnPushPin = async (tab: TabItem) => {
|
||||||
await tabsStore.unPushPinTab(tab);
|
await tabbarStore.unPushPinTab(tab);
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -6,12 +6,12 @@ import { useRoute } from 'vue-router';
|
|||||||
|
|
||||||
import { preferences } from '@vben-core/preferences';
|
import { preferences } from '@vben-core/preferences';
|
||||||
import { Spinner } from '@vben-core/shadcn-ui';
|
import { Spinner } from '@vben-core/shadcn-ui';
|
||||||
import { useTabbarStore } from '@vben-core/stores';
|
import { useCoreTabbarStore } from '@vben-core/stores';
|
||||||
|
|
||||||
defineOptions({ name: 'IFrameRouterView' });
|
defineOptions({ name: 'IFrameRouterView' });
|
||||||
|
|
||||||
const spinningList = ref<boolean[]>([]);
|
const spinningList = ref<boolean[]>([]);
|
||||||
const tabsStore = useTabbarStore();
|
const tabsStore = useCoreTabbarStore();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
const enableTabbar = computed(() => preferences.tabbar.enable);
|
const enableTabbar = computed(() => preferences.tabbar.enable);
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
"@vben-core/design": "workspace:*",
|
"@vben-core/design": "workspace:*",
|
||||||
"@vben-core/iconify": "workspace:*",
|
"@vben-core/iconify": "workspace:*",
|
||||||
"@vben-core/shadcn-ui": "workspace:*",
|
"@vben-core/shadcn-ui": "workspace:*",
|
||||||
|
"@vben/constants": "workspace:*",
|
||||||
"@vben/locales": "workspace:*",
|
"@vben/locales": "workspace:*",
|
||||||
"@vben/types": "workspace:*",
|
"@vben/types": "workspace:*",
|
||||||
"@vueuse/integrations": "^10.11.0",
|
"@vueuse/integrations": "^10.11.0",
|
||||||
|
@ -4,6 +4,7 @@ import type { LoginCodeEmits } from './typings';
|
|||||||
import { computed, onBeforeUnmount, reactive, ref } from 'vue';
|
import { computed, onBeforeUnmount, reactive, ref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
import { LOGIN_PATH } from '@vben/constants';
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
import { VbenButton, VbenInput, VbenPinInput } from '@vben-core/shadcn-ui';
|
import { VbenButton, VbenInput, VbenPinInput } from '@vben-core/shadcn-ui';
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ defineOptions({
|
|||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
loading: false,
|
loading: false,
|
||||||
loginPath: '/auth/login',
|
loginPath: LOGIN_PATH,
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import { computed, reactive } from 'vue';
|
import { computed, reactive } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
import { LOGIN_PATH } from '@vben/constants';
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
import { VbenButton, VbenInput } from '@vben-core/shadcn-ui';
|
import { VbenButton, VbenInput } from '@vben-core/shadcn-ui';
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ defineOptions({
|
|||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
loading: false,
|
loading: false,
|
||||||
loginPath: '/auth/login',
|
loginPath: LOGIN_PATH,
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
import { LOGIN_PATH } from '@vben/constants';
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
import { VbenButton } from '@vben-core/shadcn-ui';
|
import { VbenButton } from '@vben-core/shadcn-ui';
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ defineOptions({
|
|||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
loading: false,
|
loading: false,
|
||||||
loginPath: '/auth/login',
|
loginPath: LOGIN_PATH,
|
||||||
});
|
});
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
@ -4,6 +4,7 @@ import type { RegisterEmits } from './typings';
|
|||||||
import { computed, reactive } from 'vue';
|
import { computed, reactive } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
import { LOGIN_PATH } from '@vben/constants';
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
import {
|
import {
|
||||||
VbenButton,
|
VbenButton,
|
||||||
@ -31,7 +32,7 @@ defineOptions({
|
|||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
loading: false,
|
loading: false,
|
||||||
loginPath: '/auth/login',
|
loginPath: LOGIN_PATH,
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
|
@ -9,8 +9,9 @@ page:
|
|||||||
page: Page visit
|
page: Page visit
|
||||||
button: Button control
|
button: Button control
|
||||||
loading-menu: In the loading menu
|
loading-menu: In the loading menu
|
||||||
access-test-1: Access test page 1
|
access-test-1: Admin visit
|
||||||
access-test-2: Access test page 2
|
access-test-2: User visit
|
||||||
|
access-test-3: Super visit
|
||||||
nested:
|
nested:
|
||||||
title: Nested Menu
|
title: Nested Menu
|
||||||
menu1: Menu 1
|
menu1: Menu 1
|
||||||
|
@ -8,8 +8,9 @@ page:
|
|||||||
backend-control: 后端控制
|
backend-control: 后端控制
|
||||||
page: 页面访问
|
page: 页面访问
|
||||||
button: 按钮控制
|
button: 按钮控制
|
||||||
access-test-1: 权限测试页1
|
access-test-1: Admin 角色可见
|
||||||
access-test-2: 权限测试页2
|
access-test-2: User 角色可见
|
||||||
|
access-test-3: Super 角色可见
|
||||||
|
|
||||||
nested:
|
nested:
|
||||||
title: 嵌套菜单
|
title: 嵌套菜单
|
||||||
|
37
pnpm-lock.yaml
generated
37
pnpm-lock.yaml
generated
@ -293,8 +293,8 @@ importers:
|
|||||||
specifier: ^2.29.1
|
specifier: ^2.29.1
|
||||||
version: 2.29.1(@typescript-eslint/parser@7.15.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0)
|
version: 2.29.1(@typescript-eslint/parser@7.15.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0)
|
||||||
eslint-plugin-jsdoc:
|
eslint-plugin-jsdoc:
|
||||||
specifier: ^48.5.0
|
specifier: ^48.5.2
|
||||||
version: 48.5.0(eslint@8.57.0)
|
version: 48.5.2(eslint@8.57.0)
|
||||||
eslint-plugin-jsonc:
|
eslint-plugin-jsonc:
|
||||||
specifier: ^2.16.0
|
specifier: ^2.16.0
|
||||||
version: 2.16.0(eslint@8.57.0)
|
version: 2.16.0(eslint@8.57.0)
|
||||||
@ -666,6 +666,9 @@ importers:
|
|||||||
defu:
|
defu:
|
||||||
specifier: ^6.1.4
|
specifier: ^6.1.4
|
||||||
version: 6.1.4
|
version: 6.1.4
|
||||||
|
lodash.clonedeep:
|
||||||
|
specifier: ^4.5.0
|
||||||
|
version: 4.5.0
|
||||||
nprogress:
|
nprogress:
|
||||||
specifier: ^0.2.0
|
specifier: ^0.2.0
|
||||||
version: 0.2.0
|
version: 0.2.0
|
||||||
@ -673,6 +676,9 @@ importers:
|
|||||||
specifier: ^2.3.0
|
specifier: ^2.3.0
|
||||||
version: 2.3.0
|
version: 2.3.0
|
||||||
devDependencies:
|
devDependencies:
|
||||||
|
'@types/lodash.clonedeep':
|
||||||
|
specifier: ^4.5.9
|
||||||
|
version: 4.5.9
|
||||||
'@types/nprogress':
|
'@types/nprogress':
|
||||||
specifier: ^0.2.3
|
specifier: ^0.2.3
|
||||||
version: 0.2.3
|
version: 0.2.3
|
||||||
@ -888,6 +894,9 @@ importers:
|
|||||||
'@vben-core/shadcn-ui':
|
'@vben-core/shadcn-ui':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../@core/ui-kit/shadcn-ui
|
version: link:../../@core/ui-kit/shadcn-ui
|
||||||
|
'@vben/constants':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../constants
|
||||||
'@vben/locales':
|
'@vben/locales':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../locales
|
version: link:../../locales
|
||||||
@ -3051,7 +3060,6 @@ packages:
|
|||||||
|
|
||||||
'@ls-lint/ls-lint@2.2.3':
|
'@ls-lint/ls-lint@2.2.3':
|
||||||
resolution: {integrity: sha512-ekM12jNm/7O2I/hsRv9HvYkRdfrHpiV1epVuI2NP+eTIcEgdIdKkKCs9KgQydu/8R5YXTov9aHdOgplmCHLupw==}
|
resolution: {integrity: sha512-ekM12jNm/7O2I/hsRv9HvYkRdfrHpiV1epVuI2NP+eTIcEgdIdKkKCs9KgQydu/8R5YXTov9aHdOgplmCHLupw==}
|
||||||
cpu: [x64, arm64, s390x]
|
|
||||||
os: [darwin, linux, win32]
|
os: [darwin, linux, win32]
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
@ -3559,6 +3567,12 @@ packages:
|
|||||||
'@types/linkify-it@5.0.0':
|
'@types/linkify-it@5.0.0':
|
||||||
resolution: {integrity: sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==}
|
resolution: {integrity: sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==}
|
||||||
|
|
||||||
|
'@types/lodash.clonedeep@4.5.9':
|
||||||
|
resolution: {integrity: sha512-19429mWC+FyaAhOLzsS8kZUsI+/GmBAQ0HFiCPsKGU+7pBXOQWhyrY6xNNDwUSX8SMZMJvuFVMF9O5dQOlQK9Q==}
|
||||||
|
|
||||||
|
'@types/lodash@4.17.6':
|
||||||
|
resolution: {integrity: sha512-OpXEVoCKSS3lQqjx9GGGOapBeuW5eUboYHRlHP9urXPX25IKZ6AnP5ZRxtVf63iieUbsHxLn8NQ5Nlftc6yzAA==}
|
||||||
|
|
||||||
'@types/markdown-it@14.1.1':
|
'@types/markdown-it@14.1.1':
|
||||||
resolution: {integrity: sha512-4NpsnpYl2Gt1ljyBGrKMxFYAYvpqbnnkgP/i/g+NLpjEUa3obn1XJCur9YbEXKDAkaXqsR1LbDnGEJ0MmKFxfg==}
|
resolution: {integrity: sha512-4NpsnpYl2Gt1ljyBGrKMxFYAYvpqbnnkgP/i/g+NLpjEUa3obn1XJCur9YbEXKDAkaXqsR1LbDnGEJ0MmKFxfg==}
|
||||||
|
|
||||||
@ -5226,8 +5240,8 @@ packages:
|
|||||||
peerDependencies:
|
peerDependencies:
|
||||||
eslint: ^7.2.0 || ^8
|
eslint: ^7.2.0 || ^8
|
||||||
|
|
||||||
eslint-plugin-jsdoc@48.5.0:
|
eslint-plugin-jsdoc@48.5.2:
|
||||||
resolution: {integrity: sha512-ukXPNpGby3KjCveCizIS8t1EbuJEHYEu/tBg8GCbn/YbHcXwphyvYCdvRZ/oMRfTscGSSzfsWoZ+ZkAP0/6YMQ==}
|
resolution: {integrity: sha512-VXBJFviQz30rynlOEQ+dNWLmeopjoAgutUVrWOZwm6Ki4EVDm4XkyIqAV/Zhf7FcDr0AG0aGmRn5FxxCtAF0tA==}
|
||||||
engines: {node: '>=18'}
|
engines: {node: '>=18'}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
eslint: ^7.0.0 || ^8.0.0 || ^9.0.0
|
eslint: ^7.0.0 || ^8.0.0 || ^9.0.0
|
||||||
@ -6436,6 +6450,9 @@ packages:
|
|||||||
lodash.castarray@4.4.0:
|
lodash.castarray@4.4.0:
|
||||||
resolution: {integrity: sha512-aVx8ztPv7/2ULbArGJ2Y42bG1mEQ5mGjpdvrbJcJFU3TbYybe+QlLS4pst9zV52ymy2in1KpFPiZnAOATxD4+Q==}
|
resolution: {integrity: sha512-aVx8ztPv7/2ULbArGJ2Y42bG1mEQ5mGjpdvrbJcJFU3TbYybe+QlLS4pst9zV52ymy2in1KpFPiZnAOATxD4+Q==}
|
||||||
|
|
||||||
|
lodash.clonedeep@4.5.0:
|
||||||
|
resolution: {integrity: sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==}
|
||||||
|
|
||||||
lodash.debounce@4.0.8:
|
lodash.debounce@4.0.8:
|
||||||
resolution: {integrity: sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==}
|
resolution: {integrity: sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==}
|
||||||
|
|
||||||
@ -12265,6 +12282,12 @@ snapshots:
|
|||||||
|
|
||||||
'@types/linkify-it@5.0.0': {}
|
'@types/linkify-it@5.0.0': {}
|
||||||
|
|
||||||
|
'@types/lodash.clonedeep@4.5.9':
|
||||||
|
dependencies:
|
||||||
|
'@types/lodash': 4.17.6
|
||||||
|
|
||||||
|
'@types/lodash@4.17.6': {}
|
||||||
|
|
||||||
'@types/markdown-it@14.1.1':
|
'@types/markdown-it@14.1.1':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/linkify-it': 5.0.0
|
'@types/linkify-it': 5.0.0
|
||||||
@ -14271,7 +14294,7 @@ snapshots:
|
|||||||
- eslint-import-resolver-webpack
|
- eslint-import-resolver-webpack
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
eslint-plugin-jsdoc@48.5.0(eslint@8.57.0):
|
eslint-plugin-jsdoc@48.5.2(eslint@8.57.0):
|
||||||
dependencies:
|
dependencies:
|
||||||
'@es-joy/jsdoccomment': 0.43.1
|
'@es-joy/jsdoccomment': 0.43.1
|
||||||
are-docs-informative: 0.0.2
|
are-docs-informative: 0.0.2
|
||||||
@ -15647,6 +15670,8 @@ snapshots:
|
|||||||
|
|
||||||
lodash.castarray@4.4.0: {}
|
lodash.castarray@4.4.0: {}
|
||||||
|
|
||||||
|
lodash.clonedeep@4.5.0: {}
|
||||||
|
|
||||||
lodash.debounce@4.0.8: {}
|
lodash.debounce@4.0.8: {}
|
||||||
|
|
||||||
lodash.get@4.4.2: {}
|
lodash.get@4.4.2: {}
|
||||||
|
Loading…
Reference in New Issue
Block a user