mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-27 03:45:08 +08:00
refactor(project): re-adjust the overall folder
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { UserApi } from '../types';
|
||||
|
||||
import { requestClient } from '#/forward';
|
||||
import { requestClient } from '#/apis/request';
|
||||
|
||||
/**
|
||||
* 登录
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import type { RouteRecordStringComponent } from '@vben/types';
|
||||
|
||||
import { requestClient } from '#/forward';
|
||||
import { requestClient } from '#/apis/request';
|
||||
|
||||
/**
|
||||
* 获取用户所有菜单
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import type { UserInfo } from '@vben/types';
|
||||
|
||||
import { requestClient } from '#/forward';
|
||||
import { requestClient } from '#/apis/request';
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { requestClient } from '#/forward';
|
||||
import { requestClient } from '#/apis/request';
|
||||
|
||||
/**
|
||||
* 模拟任意状态码
|
||||
|
@@ -1,10 +1,10 @@
|
||||
/**
|
||||
* 该文件可自行根据业务逻辑进行调整
|
||||
*/
|
||||
import type { HttpResponse } from '@vben-core/request';
|
||||
import type { HttpResponse } from '@vben/request';
|
||||
|
||||
import { preferences } from '@vben-core/preferences';
|
||||
import { RequestClient } from '@vben-core/request';
|
||||
import { preferences } from '@vben/preferences';
|
||||
import { RequestClient } from '@vben/request';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
@@ -2,7 +2,7 @@
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { GlobalProvider } from '@vben/common-ui';
|
||||
import { preferences, usePreferences } from '@vben-core/preferences';
|
||||
import { preferences, usePreferences } from '@vben/preferences';
|
||||
|
||||
import { App, ConfigProvider, theme } from 'ant-design-vue';
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { createApp } from 'vue';
|
||||
|
||||
import { preferences } from '@vben/preferences';
|
||||
import '@vben/styles';
|
||||
import '@vben/styles/antd';
|
||||
import { preferences } from '@vben-core/preferences';
|
||||
|
||||
import { loadMessages, setupI18n } from '#/locales';
|
||||
import { setupStore } from '#/store';
|
||||
|
@@ -1,11 +0,0 @@
|
||||
# forward
|
||||
|
||||
用于扩展、转发大仓的包以及其他功能,方便在app内自定义不同的逻辑
|
||||
|
||||
## request
|
||||
|
||||
用于扩展请求的功能,例如添加header、错误响应等
|
||||
|
||||
## locale
|
||||
|
||||
用于扩展国际化的功能,例如扩展 dayjs、antd组件库的多语言切换
|
@@ -1,2 +0,0 @@
|
||||
export * from './access';
|
||||
export * from './request';
|
@@ -12,12 +12,12 @@ import {
|
||||
NotificationItem,
|
||||
UserDropdown,
|
||||
} from '@vben/layouts';
|
||||
import { preferences } from '@vben/preferences';
|
||||
import { openWindow } from '@vben/utils';
|
||||
import { preferences } from '@vben-core/preferences';
|
||||
|
||||
import { $t } from '#/locales';
|
||||
import { resetRoutes } from '#/router';
|
||||
import { storeToRefs, useAccessStore, useAppStore } from '#/store';
|
||||
import { resetAllStores, storeToRefs, useAccessStore } from '#/store';
|
||||
|
||||
const notifications = ref<NotificationItem[]>([
|
||||
{
|
||||
@@ -84,10 +84,8 @@ const menus = computed(() => [
|
||||
},
|
||||
]);
|
||||
|
||||
const appStore = useAppStore();
|
||||
const accessStore = useAccessStore();
|
||||
|
||||
const { isLockScreen, lockScreenPassword } = storeToRefs(appStore);
|
||||
const {
|
||||
loading: loginLoading,
|
||||
openLoginExpiredModal,
|
||||
@@ -101,8 +99,7 @@ const avatar = computed(() => {
|
||||
const router = useRouter();
|
||||
|
||||
async function handleLogout() {
|
||||
appStore.resetAppState();
|
||||
appStore.unlockScreen();
|
||||
resetAllStores();
|
||||
resetRoutes();
|
||||
await router.replace(LOGIN_PATH);
|
||||
}
|
||||
@@ -114,10 +111,6 @@ function handleNoticeClear() {
|
||||
function handleMakeAll() {
|
||||
notifications.value.forEach((item) => (item.isRead = true));
|
||||
}
|
||||
|
||||
function handleLockScreen(password: string) {
|
||||
appStore.lockScreen(password);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -129,7 +122,6 @@ function handleLockScreen(password: string) {
|
||||
:text="userInfo?.realName"
|
||||
description="ann.vben@gmail.com"
|
||||
tag-text="Pro"
|
||||
@lock-screen="handleLockScreen"
|
||||
@logout="handleLogout"
|
||||
/>
|
||||
</template>
|
||||
@@ -152,13 +144,7 @@ function handleLockScreen(password: string) {
|
||||
/>
|
||||
</template>
|
||||
<template #lock-screen>
|
||||
<LockScreen
|
||||
v-if="isLockScreen"
|
||||
:avatar
|
||||
:cached-password="lockScreenPassword"
|
||||
@to-login="handleLogout"
|
||||
@unlock="appStore.unlockScreen"
|
||||
/>
|
||||
<LockScreen :avatar @to-login="handleLogout" />
|
||||
</template>
|
||||
</BasicLayout>
|
||||
</template>
|
||||
|
@@ -3,7 +3,7 @@ import type { Locale } from 'ant-design-vue/es/locale';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { $t, loadLocalesMap, setupI18n } from '@vben-core/locales';
|
||||
import { $t, loadLocalesMap, setupI18n } from '@vben/locales';
|
||||
|
||||
import antdEnLocale from 'ant-design-vue/es/locale/en_US';
|
||||
import antdDefaultLocale from 'ant-design-vue/es/locale/zh_CN';
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { preferencesManager } from '@vben-core/preferences';
|
||||
import { initPreferences } from '@vben/preferences';
|
||||
|
||||
import { overridesPreferences } from './preferences';
|
||||
|
||||
@@ -12,7 +12,7 @@ async function initApplication() {
|
||||
const namespace = `${import.meta.env.VITE_APP_NAMESPACE}-${env}`;
|
||||
|
||||
// app偏好设置初始化
|
||||
await preferencesManager.initPreferences({
|
||||
await initPreferences({
|
||||
namespace,
|
||||
overrides: overridesPreferences,
|
||||
});
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { defineOverridesPreferences } from '@vben-core/preferences';
|
||||
import { defineOverridesPreferences } from '@vben/preferences';
|
||||
|
||||
/**
|
||||
* @description 项目配置文件
|
||||
|
@@ -4,7 +4,7 @@ import type {
|
||||
} from '@vben/types';
|
||||
|
||||
import { generateAccessible } from '@vben/access';
|
||||
import { preferences } from '@vben-core/preferences';
|
||||
import { preferences } from '@vben/preferences';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
@@ -1,16 +1,17 @@
|
||||
import type { Router } from 'vue-router';
|
||||
|
||||
import { LOGIN_PATH } from '@vben/constants';
|
||||
import { preferences } from '@vben/preferences';
|
||||
import { startProgress, stopProgress } from '@vben/utils';
|
||||
import { preferences } from '@vben-core/preferences';
|
||||
|
||||
import { useTitle } from '@vueuse/core';
|
||||
|
||||
import { generateAccess } from '#/forward';
|
||||
import { $t } from '#/locales';
|
||||
import { coreRouteNames, dynamicRoutes } from '#/router/routes';
|
||||
import { useAccessStore } from '#/store';
|
||||
|
||||
import { generateAccess } from './access';
|
||||
|
||||
/**
|
||||
* 通用守卫配置
|
||||
* @param router
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
import { traverseTreeValues } from '@vben/utils';
|
||||
import { mergeRouteModules } from '@vben-core/helpers';
|
||||
import { mergeRouteModules, traverseTreeValues } from '@vben/utils';
|
||||
|
||||
import { coreRoutes, fallbackNotFoundRoute } from './core';
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import type { InitStoreOptions } from '@vben-core/stores';
|
||||
import type { InitStoreOptions } from '@vben/stores';
|
||||
|
||||
import type { App } from 'vue';
|
||||
|
||||
import { initStore, storeToRefs } from '@vben-core/stores';
|
||||
import { initStore, resetAllStores, storeToRefs } from '@vben/stores';
|
||||
|
||||
/**
|
||||
* @zh_CN 初始化pinia
|
||||
@@ -13,7 +13,6 @@ async function setupStore(app: App, options: InitStoreOptions) {
|
||||
app.use(pinia);
|
||||
}
|
||||
|
||||
export { setupStore, storeToRefs };
|
||||
export { resetAllStores, setupStore, storeToRefs };
|
||||
|
||||
export { useAccessStore } from './modules/access';
|
||||
export { useAppStore } from './modules/app';
|
||||
|
@@ -6,7 +6,7 @@ import { computed, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import { DEFAULT_HOME_PATH, LOGIN_PATH } from '@vben/constants';
|
||||
import { useCoreAccessStore } from '@vben-core/stores';
|
||||
import { resetAllStores, useCoreAccessStore } from '@vben/stores';
|
||||
|
||||
import { notification } from 'ant-design-vue';
|
||||
import { defineStore } from 'pinia';
|
||||
@@ -50,7 +50,7 @@ export const useAccessStore = defineStore('access', () => {
|
||||
onSuccess?: () => Promise<void> | void,
|
||||
) {
|
||||
// 异步处理用户登录操作并获取 accessToken
|
||||
let userInfo: UserInfo | null = null;
|
||||
let userInfo: null | UserInfo = null;
|
||||
try {
|
||||
loading.value = true;
|
||||
const { accessToken, refreshToken } = await login(params);
|
||||
@@ -102,7 +102,7 @@ export const useAccessStore = defineStore('access', () => {
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
coreStoreAccess.$reset();
|
||||
resetAllStores();
|
||||
openLoginExpiredModal.value = false;
|
||||
|
||||
// 回登陆页带上当前路由地址
|
||||
@@ -115,17 +115,19 @@ export const useAccessStore = defineStore('access', () => {
|
||||
}
|
||||
|
||||
async function fetchUserInfo() {
|
||||
let userInfo: UserInfo | null = null;
|
||||
let userInfo: null | UserInfo = null;
|
||||
userInfo = await getUserInfo();
|
||||
coreStoreAccess.setUserInfo(userInfo);
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
function reset() {
|
||||
coreStoreAccess.$reset();
|
||||
function $reset() {
|
||||
loading.value = false;
|
||||
openLoginExpiredModal.value = false;
|
||||
}
|
||||
|
||||
return {
|
||||
$reset,
|
||||
accessRoutes,
|
||||
accessToken,
|
||||
authLogin,
|
||||
@@ -134,7 +136,6 @@ export const useAccessStore = defineStore('access', () => {
|
||||
logout,
|
||||
openLoginExpiredModal,
|
||||
refreshToken,
|
||||
reset,
|
||||
setAccessMenus,
|
||||
setAccessRoutes,
|
||||
setAccessToken,
|
||||
|
@@ -1,38 +0,0 @@
|
||||
import { useCoreTabbarStore } from '@vben-core/stores';
|
||||
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
import { useAccessStore } from './access';
|
||||
|
||||
interface AppState {
|
||||
isLockScreen: boolean;
|
||||
lockScreenPassword?: string;
|
||||
}
|
||||
|
||||
export const useAppStore = defineStore('app', {
|
||||
actions: {
|
||||
lockScreen(password: string) {
|
||||
this.isLockScreen = true;
|
||||
this.lockScreenPassword = password;
|
||||
},
|
||||
|
||||
resetAppState() {
|
||||
const accessStore = useAccessStore();
|
||||
const coreTabbarStore = useCoreTabbarStore();
|
||||
accessStore.reset();
|
||||
coreTabbarStore.$reset();
|
||||
},
|
||||
|
||||
unlockScreen() {
|
||||
this.isLockScreen = false;
|
||||
this.lockScreenPassword = undefined;
|
||||
},
|
||||
},
|
||||
persist: {
|
||||
paths: ['isLockScreen', 'lockScreenPassword'],
|
||||
},
|
||||
state: (): AppState => ({
|
||||
isLockScreen: false,
|
||||
lockScreenPassword: undefined,
|
||||
}),
|
||||
});
|
@@ -4,6 +4,7 @@ import type { LoginCodeParams } from '@vben/common-ui';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { AuthenticationCodeLogin } from '@vben/common-ui';
|
||||
import { LOGIN_PATH } from '@vben/constants';
|
||||
|
||||
defineOptions({ name: 'CodeLogin' });
|
||||
|
||||
@@ -21,5 +22,9 @@ async function handleLogin(values: LoginCodeParams) {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AuthenticationCodeLogin :loading="loading" @submit="handleLogin" />
|
||||
<AuthenticationCodeLogin
|
||||
:loading="loading"
|
||||
:login-path="LOGIN_PATH"
|
||||
@submit="handleLogin"
|
||||
/>
|
||||
</template>
|
||||
|
@@ -2,6 +2,7 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { AuthenticationForgetPassword } from '@vben/common-ui';
|
||||
import { LOGIN_PATH } from '@vben/constants';
|
||||
|
||||
defineOptions({ name: 'ForgetPassword' });
|
||||
|
||||
@@ -14,5 +15,9 @@ function handleSubmit(value: string) {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AuthenticationForgetPassword :loading="loading" @submit="handleSubmit" />
|
||||
<AuthenticationForgetPassword
|
||||
:loading="loading"
|
||||
:login-path="LOGIN_PATH"
|
||||
@submit="handleSubmit"
|
||||
/>
|
||||
</template>
|
||||
|
@@ -1,9 +1,10 @@
|
||||
<script lang="ts" setup>
|
||||
import { AuthenticationQrCodeLogin } from '@vben/common-ui';
|
||||
import { LOGIN_PATH } from '@vben/constants';
|
||||
|
||||
defineOptions({ name: 'QrCodeLogin' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AuthenticationQrCodeLogin />
|
||||
<AuthenticationQrCodeLogin :login-path="LOGIN_PATH" />
|
||||
</template>
|
||||
|
@@ -4,6 +4,7 @@ import type { LoginAndRegisterParams } from '@vben/common-ui';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { AuthenticationRegister } from '@vben/common-ui';
|
||||
import { LOGIN_PATH } from '@vben/constants';
|
||||
|
||||
defineOptions({ name: 'Register' });
|
||||
|
||||
@@ -16,5 +17,9 @@ function handleSubmit(value: LoginAndRegisterParams) {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AuthenticationRegister :loading="loading" @submit="handleSubmit" />
|
||||
<AuthenticationRegister
|
||||
:loading="loading"
|
||||
:login-path="LOGIN_PATH"
|
||||
@submit="handleSubmit"
|
||||
/>
|
||||
</template>
|
||||
|
@@ -16,7 +16,7 @@ import {
|
||||
WorkbenchTodo,
|
||||
WorkbenchTrends,
|
||||
} from '@vben/common-ui';
|
||||
import { preferences } from '@vben-core/preferences';
|
||||
import { preferences } from '@vben/preferences';
|
||||
|
||||
import { useAccessStore } from '#/store';
|
||||
|
||||
|
@@ -7,7 +7,7 @@ import { AccessControl, useAccess } from '@vben/access';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
|
||||
import { useAccessStore, useAppStore } from '#/store';
|
||||
import { resetAllStores, useAccessStore } from '#/store';
|
||||
|
||||
defineOptions({ name: 'AccessButtonControl' });
|
||||
|
||||
@@ -28,7 +28,6 @@ const accounts: Record<string, LoginAndRegisterParams> = {
|
||||
|
||||
const { accessMode, hasAccessByCodes } = useAccess();
|
||||
const accessStore = useAccessStore();
|
||||
const appStore = useAppStore();
|
||||
const router = useRouter();
|
||||
|
||||
function roleButtonType(role: string) {
|
||||
@@ -41,7 +40,7 @@ async function changeAccount(role: string) {
|
||||
}
|
||||
|
||||
const account = accounts[role];
|
||||
appStore.resetAppState();
|
||||
resetAllStores();
|
||||
await accessStore.authLogin(account, async () => {
|
||||
router.go(0);
|
||||
});
|
||||
|
@@ -7,7 +7,7 @@ import { useAccess } from '@vben/access';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
|
||||
import { useAccessStore, useAppStore } from '#/store';
|
||||
import { resetAllStores, useAccessStore } from '#/store';
|
||||
|
||||
defineOptions({ name: 'Access' });
|
||||
|
||||
@@ -28,7 +28,6 @@ const accounts: Record<string, LoginAndRegisterParams> = {
|
||||
|
||||
const { accessMode, toggleAccessMode } = useAccess();
|
||||
const accessStore = useAccessStore();
|
||||
const appStore = useAppStore();
|
||||
const router = useRouter();
|
||||
|
||||
function roleButtonType(role: string) {
|
||||
@@ -41,7 +40,7 @@ async function changeAccount(role: string) {
|
||||
}
|
||||
|
||||
const account = accounts[role];
|
||||
appStore.resetAppState();
|
||||
resetAllStores();
|
||||
await accessStore.authLogin(account, async () => {
|
||||
router.go(0);
|
||||
});
|
||||
@@ -49,7 +48,8 @@ async function changeAccount(role: string) {
|
||||
|
||||
async function handleToggleAccessMode() {
|
||||
await toggleAccessMode();
|
||||
appStore.resetAppState();
|
||||
resetAllStores();
|
||||
|
||||
await accessStore.authLogin(accounts.super, async () => {
|
||||
router.go(0);
|
||||
});
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import type { LoginExpiredModeType } from '@vben/types';
|
||||
|
||||
import { preferences, updatePreferences } from '@vben-core/preferences';
|
||||
import { preferences, updatePreferences } from '@vben/preferences';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
|
||||
|
Reference in New Issue
Block a user