perf: Improve the use of store in the app
This commit is contained in:
@@ -3,6 +3,8 @@ import type { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
import type { GeneratorMenuAndRoutesOptions } from '../types';
|
||||
|
||||
import { cloneDepp } from '@vben-core/toolkit';
|
||||
|
||||
import { generateMenus } from './generate-menus';
|
||||
import { generateRoutesByBackend } from './generate-routes-backend';
|
||||
import { generateRoutesByFrontend } from './generate-routes-frontend';
|
||||
@@ -12,6 +14,8 @@ async function generateMenusAndRoutes(
|
||||
options: GeneratorMenuAndRoutesOptions,
|
||||
) {
|
||||
const { router } = options;
|
||||
|
||||
options.routes = cloneDepp(options.routes);
|
||||
// 生成路由
|
||||
const accessibleRoutes = await generateRoutes(mode, options);
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
export { default as Authority } from './authority.vue';
|
||||
export * from './generate-menu-and-routes';
|
||||
export { default as RoleAuthority } from './role-authority.vue';
|
||||
export type * from './types';
|
||||
export * from './use-access';
|
||||
|
@@ -9,15 +9,15 @@ interface Props {
|
||||
* - When the permission mode is 'backend', the value can be a code permission value.
|
||||
* @default ''
|
||||
*/
|
||||
value?: string[];
|
||||
roles?: string[];
|
||||
}
|
||||
|
||||
defineOptions({
|
||||
name: 'Authority',
|
||||
name: 'FrontendAuthority',
|
||||
});
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
value: undefined,
|
||||
roles: undefined,
|
||||
});
|
||||
</script>
|
||||
|
@@ -1,28 +1,13 @@
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { preferences } from '@vben-core/preferences';
|
||||
import { useAccessStore } from '@vben-core/stores';
|
||||
|
||||
function useAccess() {
|
||||
const accessStore = useAccessStore();
|
||||
const currentAccessMode = computed(() => {
|
||||
const accessMode = computed(() => {
|
||||
return preferences.app.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 };
|
||||
return { accessMode };
|
||||
}
|
||||
|
||||
export { useAccess };
|
||||
|
Reference in New Issue
Block a user