mirror of
https://gitee.com/bootx/dax-pay-ui.git
synced 2025-09-02 10:26:32 +00:00
perf 字典初始化提早到项目加载时
This commit is contained in:
270
mock/sys/menu.ts
270
mock/sys/menu.ts
@@ -1,270 +0,0 @@
|
||||
import { resultSuccess, resultError, getRequestToken, requestParams } from '../_util'
|
||||
import { MockMethod } from 'vite-plugin-mock'
|
||||
import { createFakeUserList } from './user'
|
||||
|
||||
// single
|
||||
const dashboardRoute = {
|
||||
path: '/dashboard',
|
||||
name: 'Dashboard',
|
||||
component: 'LAYOUT',
|
||||
redirect: '/dashboard/analysis',
|
||||
meta: {
|
||||
title: 'routes.dashboard.dashboard',
|
||||
hideChildrenInMenu: true,
|
||||
icon: 'bx:bx-home',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'analysis',
|
||||
name: 'Analysis',
|
||||
component: '/dashboard/analysis/index',
|
||||
meta: {
|
||||
hideMenu: true,
|
||||
hideBreadcrumb: true,
|
||||
title: 'routes.dashboard.analysis',
|
||||
currentActiveMenu: '/dashboard',
|
||||
icon: 'bx:bx-home',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'workbench',
|
||||
name: 'Workbench',
|
||||
component: '/dashboard/workbench/index',
|
||||
meta: {
|
||||
hideMenu: true,
|
||||
hideBreadcrumb: true,
|
||||
title: 'routes.dashboard.workbench',
|
||||
currentActiveMenu: '/dashboard',
|
||||
icon: 'bx:bx-home',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const backRoute = {
|
||||
path: 'back',
|
||||
name: 'PermissionBackDemo',
|
||||
meta: {
|
||||
title: 'routes.demo.permission.back',
|
||||
},
|
||||
|
||||
children: [
|
||||
{
|
||||
path: 'page',
|
||||
name: 'BackAuthPage',
|
||||
component: '/demo/permission/back/index',
|
||||
meta: {
|
||||
title: 'routes.demo.permission.backPage',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'btn',
|
||||
name: 'BackAuthBtn',
|
||||
component: '/demo/permission/back/Btn',
|
||||
meta: {
|
||||
title: 'routes.demo.permission.backBtn',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const authRoute = {
|
||||
path: '/permission',
|
||||
name: 'Permission',
|
||||
component: 'LAYOUT',
|
||||
redirect: '/permission/front/page',
|
||||
meta: {
|
||||
icon: 'carbon:user-role',
|
||||
title: 'routes.demo.permission.permission',
|
||||
},
|
||||
children: [backRoute],
|
||||
}
|
||||
|
||||
const levelRoute = {
|
||||
path: '/level',
|
||||
name: 'Level',
|
||||
component: 'LAYOUT',
|
||||
redirect: '/level/menu1/menu1-1',
|
||||
meta: {
|
||||
icon: 'carbon:user-role',
|
||||
title: 'routes.demo.level.level',
|
||||
},
|
||||
|
||||
children: [
|
||||
{
|
||||
path: 'menu1',
|
||||
name: 'Menu1Demo',
|
||||
meta: {
|
||||
title: 'Menu1',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'menu1-1',
|
||||
name: 'Menu11Demo',
|
||||
meta: {
|
||||
title: 'Menu1-1',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'menu1-1-1',
|
||||
name: 'Menu111Demo',
|
||||
component: '/demo/level/Menu111',
|
||||
meta: {
|
||||
title: 'Menu111',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: 'menu1-2',
|
||||
name: 'Menu12Demo',
|
||||
component: '/demo/level/Menu12',
|
||||
meta: {
|
||||
title: 'Menu1-2',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: 'menu2',
|
||||
name: 'Menu2Demo',
|
||||
component: '/demo/level/Menu2',
|
||||
meta: {
|
||||
title: 'Menu2',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const sysRoute = {
|
||||
path: '/system',
|
||||
name: 'System',
|
||||
component: 'LAYOUT',
|
||||
redirect: '/system/account',
|
||||
meta: {
|
||||
icon: 'ion:settings-outline',
|
||||
title: 'routes.demo.system.moduleName',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'account',
|
||||
name: 'AccountManagement',
|
||||
meta: {
|
||||
title: 'routes.demo.system.account',
|
||||
ignoreKeepAlive: true,
|
||||
},
|
||||
component: '/demo/system/account/index',
|
||||
},
|
||||
{
|
||||
path: 'account_detail/:id',
|
||||
name: 'AccountDetail',
|
||||
meta: {
|
||||
hideMenu: true,
|
||||
title: 'routes.demo.system.account_detail',
|
||||
ignoreKeepAlive: true,
|
||||
showMenu: false,
|
||||
currentActiveMenu: '/system/account',
|
||||
},
|
||||
component: '/demo/system/account/AccountDetail',
|
||||
},
|
||||
{
|
||||
path: 'role',
|
||||
name: 'RoleManagement',
|
||||
meta: {
|
||||
title: 'routes.demo.system.role',
|
||||
ignoreKeepAlive: true,
|
||||
},
|
||||
component: '/demo/system/role/index',
|
||||
},
|
||||
|
||||
{
|
||||
path: 'menu',
|
||||
name: 'MenuManagement',
|
||||
meta: {
|
||||
title: 'routes.demo.system.menu',
|
||||
ignoreKeepAlive: true,
|
||||
},
|
||||
component: '/demo/system/menu/index',
|
||||
},
|
||||
{
|
||||
path: 'dept',
|
||||
name: 'DeptManagement',
|
||||
meta: {
|
||||
title: 'routes.demo.system.dept',
|
||||
ignoreKeepAlive: true,
|
||||
},
|
||||
component: '/demo/system/dept/index',
|
||||
},
|
||||
{
|
||||
path: 'changePassword',
|
||||
name: 'ChangePassword',
|
||||
meta: {
|
||||
title: 'routes.demo.system.password',
|
||||
ignoreKeepAlive: true,
|
||||
},
|
||||
component: '/demo/system/password/index',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const linkRoute = {
|
||||
path: '/link',
|
||||
name: 'Link',
|
||||
component: 'LAYOUT',
|
||||
meta: {
|
||||
icon: 'ion:tv-outline',
|
||||
title: 'routes.demo.iframe.frame',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'doc',
|
||||
name: 'Doc',
|
||||
meta: {
|
||||
title: 'routes.demo.iframe.doc',
|
||||
frameSrc: 'https://vvbin.cn/doc-next/',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'https://vvbin.cn/doc-next/',
|
||||
name: 'DocExternal',
|
||||
component: 'LAYOUT',
|
||||
meta: {
|
||||
title: 'routes.demo.iframe.docExternal',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
export default [
|
||||
{
|
||||
url: '/basic-api/getMenuList',
|
||||
timeout: 1000,
|
||||
method: 'get',
|
||||
response: (request: requestParams) => {
|
||||
const token = getRequestToken(request)
|
||||
if (!token) {
|
||||
return resultError('Invalid token!')
|
||||
}
|
||||
const checkUser = createFakeUserList().find((item) => item.token === token)
|
||||
if (!checkUser) {
|
||||
return resultError('Invalid user token!')
|
||||
}
|
||||
const id = checkUser.userId
|
||||
let menu: Object[]
|
||||
switch (id) {
|
||||
case '1':
|
||||
dashboardRoute.redirect = dashboardRoute.path + '/' + dashboardRoute.children[0].path
|
||||
menu = [dashboardRoute, authRoute, levelRoute, sysRoute, linkRoute]
|
||||
break
|
||||
case '2':
|
||||
dashboardRoute.redirect = dashboardRoute.path + '/' + dashboardRoute.children[1].path
|
||||
menu = [dashboardRoute, authRoute, levelRoute, linkRoute]
|
||||
break
|
||||
default:
|
||||
menu = []
|
||||
}
|
||||
|
||||
return resultSuccess(menu)
|
||||
},
|
||||
},
|
||||
] as MockMethod[]
|
120
mock/sys/user.ts
120
mock/sys/user.ts
@@ -1,120 +0,0 @@
|
||||
import { MockMethod } from 'vite-plugin-mock'
|
||||
import { resultError, resultSuccess, getRequestToken, requestParams } from '../_util'
|
||||
|
||||
export function createFakeUserList() {
|
||||
return [
|
||||
{
|
||||
userId: '1',
|
||||
username: 'vben',
|
||||
realName: 'Vben Admin',
|
||||
avatar: 'https://q1.qlogo.cn/g?b=qq&nk=190848757&s=640',
|
||||
desc: 'manager',
|
||||
password: '123456',
|
||||
token: 'fakeToken1',
|
||||
homePath: '/dashboard/analysis',
|
||||
roles: [
|
||||
{
|
||||
roleName: 'Super Admin',
|
||||
value: 'super',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
userId: '2',
|
||||
username: 'test',
|
||||
password: '123456',
|
||||
realName: 'test user',
|
||||
avatar: 'https://q1.qlogo.cn/g?b=qq&nk=339449197&s=640',
|
||||
desc: 'tester',
|
||||
token: 'fakeToken2',
|
||||
homePath: '/dashboard/workbench',
|
||||
roles: [
|
||||
{
|
||||
roleName: 'Tester',
|
||||
value: 'test',
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
const fakeCodeList: any = {
|
||||
'1': ['1000', '3000', '5000'],
|
||||
|
||||
'2': ['2000', '4000', '6000'],
|
||||
}
|
||||
export default [
|
||||
// mock user login
|
||||
{
|
||||
url: '/api/login',
|
||||
timeout: 200,
|
||||
method: 'post',
|
||||
response: ({ body }) => {
|
||||
const { username, password } = body
|
||||
const checkUser = createFakeUserList().find((item) => item.username === username && password === item.password)
|
||||
if (!checkUser) {
|
||||
return resultError('Incorrect account or password!')
|
||||
}
|
||||
const { userId, username: _username, token, realName, desc, roles } = checkUser
|
||||
return resultSuccess({
|
||||
roles,
|
||||
userId,
|
||||
username: _username,
|
||||
token,
|
||||
realName,
|
||||
desc,
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
url: '/api/getUserInfo',
|
||||
method: 'get',
|
||||
response: (request: requestParams) => {
|
||||
const token = getRequestToken(request)
|
||||
if (!token) return resultError('Invalid token')
|
||||
const checkUser = createFakeUserList().find((item) => item.token === token)
|
||||
if (!checkUser) {
|
||||
return resultError('The corresponding user information was not obtained!')
|
||||
}
|
||||
return resultSuccess(checkUser)
|
||||
},
|
||||
},
|
||||
{
|
||||
url: '/basic-api/getPermCode',
|
||||
timeout: 200,
|
||||
method: 'get',
|
||||
response: (request: requestParams) => {
|
||||
const token = getRequestToken(request)
|
||||
if (!token) return resultError('Invalid token')
|
||||
const checkUser = createFakeUserList().find((item) => item.token === token)
|
||||
if (!checkUser) {
|
||||
return resultError('Invalid token!')
|
||||
}
|
||||
const codeList = fakeCodeList[checkUser.userId]
|
||||
|
||||
return resultSuccess(codeList)
|
||||
},
|
||||
},
|
||||
{
|
||||
url: '/basic-api/logout',
|
||||
timeout: 200,
|
||||
method: 'get',
|
||||
response: (request: requestParams) => {
|
||||
const token = getRequestToken(request)
|
||||
if (!token) return resultError('Invalid token')
|
||||
const checkUser = createFakeUserList().find((item) => item.token === token)
|
||||
if (!checkUser) {
|
||||
return resultError('Invalid token!')
|
||||
}
|
||||
return resultSuccess(undefined, { message: 'Token has been destroyed' })
|
||||
},
|
||||
},
|
||||
{
|
||||
url: '/basic-api/testRetry',
|
||||
statusCode: 405,
|
||||
method: 'get',
|
||||
response: () => {
|
||||
return resultError('Error!')
|
||||
},
|
||||
},
|
||||
] as MockMethod[]
|
@@ -1,13 +1,13 @@
|
||||
import { useDictStoreWithOut } from '/@/store/modules/dict'
|
||||
import { useDictStore } from '/@/store/modules/dict'
|
||||
import { LabeledValue } from 'ant-design-vue/lib/select'
|
||||
|
||||
const useDictStore = useDictStoreWithOut()
|
||||
const dictStore = useDictStore()
|
||||
|
||||
/**
|
||||
* 字典项转换
|
||||
*/
|
||||
function dictConvert(dictCode: string, code) {
|
||||
const dictList = useDictStore.getDict
|
||||
const dictList = dictStore.getDict
|
||||
const item = dictList.filter((dict) => {
|
||||
return dictCode === dict.dictCode && dict.code === String(code)
|
||||
})
|
||||
@@ -22,7 +22,7 @@ function dictConvert(dictCode: string, code) {
|
||||
* 获取字典项列表
|
||||
*/
|
||||
export function dictItems(dictCode: string) {
|
||||
const dictList = useDictStore.getDict
|
||||
const dictList = dictStore.getDict
|
||||
return dictList
|
||||
.filter((dict) => dictCode === dict.dictCode)
|
||||
.map((item) => {
|
||||
@@ -34,7 +34,7 @@ export function dictItems(dictCode: string) {
|
||||
* 获取字典项列表(code值为数字)
|
||||
*/
|
||||
export function dictItemsNumber(dictCode: string) {
|
||||
const dictList = useDictStore.getDict
|
||||
const dictList = dictStore.getDict
|
||||
return dictList
|
||||
.filter((dict) => dictCode === dict.dictCode)
|
||||
.map((item) => {
|
||||
@@ -46,7 +46,7 @@ export function dictItemsNumber(dictCode: string) {
|
||||
* 获取字典下拉框数据列表
|
||||
*/
|
||||
function dictDropDown(dictCode: string): LabeledValue[] {
|
||||
const list = useDictStore.getDict
|
||||
const list = dictStore.getDict
|
||||
return list
|
||||
.filter((dict) => dictCode === dict.dictCode)
|
||||
.map((o) => {
|
||||
@@ -57,7 +57,7 @@ function dictDropDown(dictCode: string): LabeledValue[] {
|
||||
* 获取字典下拉框数据列表
|
||||
*/
|
||||
function dictDropDownNumber(dictCode: string): LabeledValue[] {
|
||||
const list = useDictStore.getDict
|
||||
const list = dictStore.getDict
|
||||
return list
|
||||
.filter((dict) => dictCode === dict.dictCode)
|
||||
.map((o) => {
|
||||
|
@@ -8,7 +8,7 @@ import { useUserStoreWithOut } from '/@/store/modules/user'
|
||||
import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic'
|
||||
|
||||
import { RootRoute } from '/@/router/routes'
|
||||
import { useDictStoreWithOut } from '/@/store/modules/dict'
|
||||
// import { useDictStoreWithOut } from '/@/store/modules/dict'
|
||||
|
||||
const LOGIN_PATH = PageEnum.BASE_LOGIN
|
||||
|
||||
@@ -23,7 +23,7 @@ const whitePathList: PageEnum[] = [LOGIN_PATH]
|
||||
export function createPermissionGuard(router: Router) {
|
||||
const userStore = useUserStoreWithOut()
|
||||
const permissionStore = usePermissionStoreWithOut()
|
||||
const useDictStore = useDictStoreWithOut()
|
||||
// const useDictStore = useDictStoreWithOut()
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
// if (
|
||||
// from.path === ROOT_PATH &&
|
||||
@@ -103,9 +103,9 @@ export function createPermissionGuard(router: Router) {
|
||||
console.log('重载菜单')
|
||||
const routes = await permissionStore.buildRoutesAction()
|
||||
|
||||
// 初始化字典
|
||||
console.log('初始化字典')
|
||||
await useDictStore.initDict()
|
||||
// 初始化字典 改到项目加载的时候进行初始化
|
||||
// console.log('初始化字典')
|
||||
// await useDictStore.initDict()
|
||||
|
||||
routes.forEach((route) => {
|
||||
router.addRoute(route as unknown as RouteRecordRaw)
|
||||
|
@@ -6,6 +6,10 @@ import { usePermissionStore } from '/@/store/modules/permission'
|
||||
import { PageEnum } from '/@/enums/pageEnum'
|
||||
import { removeTabChangeListener } from '/@/logics/mitt/routeChange'
|
||||
|
||||
/**
|
||||
* 创建路由守卫
|
||||
* @param router
|
||||
*/
|
||||
export function createStateGuard(router: Router) {
|
||||
router.afterEach((to) => {
|
||||
// Just enter the login page and clear the authentication information
|
||||
@@ -22,3 +26,8 @@ export function createStateGuard(router: Router) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 在项目未登录的时候刷新时加载或刷新一系列数据
|
||||
*/
|
||||
function notLonginInitData() {}
|
||||
|
@@ -34,3 +34,6 @@ export const useDictStore = defineStore({
|
||||
export function useDictStoreWithOut() {
|
||||
return useDictStore(store)
|
||||
}
|
||||
|
||||
// 初始化字典
|
||||
useDictStoreWithOut().initDict()
|
||||
|
@@ -12,12 +12,7 @@ import projectSetting from '/@/settings/projectSetting'
|
||||
|
||||
import { PermissionModeEnum } from '/@/enums/appEnum'
|
||||
|
||||
import {
|
||||
DASHBOARD,
|
||||
ERROR_LOG_ROUTE,
|
||||
PAGE_NOT_FOUND_ROUTE,
|
||||
PROJECT_BASE
|
||||
} from "/@/router/routes/basic";
|
||||
import { DASHBOARD, ERROR_LOG_ROUTE, PAGE_NOT_FOUND_ROUTE, PROJECT_BASE } from '/@/router/routes/basic'
|
||||
|
||||
import { filter } from '/@/utils/helper/treeHelper'
|
||||
|
||||
|
Reference in New Issue
Block a user