diff --git a/src/router/dynamicRouter.ts b/src/router/dynamicRouter.ts
index 15e606ba45b6cd6c2484923f111eeb63891d2da7..8d46e66e4c8ad31a2976ea26bf589a66212c0203 100644
--- a/src/router/dynamicRouter.ts
+++ b/src/router/dynamicRouter.ts
@@ -1,10 +1,91 @@
-import layout from '@/layout/index.vue'
+import { Router, RouteRecordRaw } from 'vue-router'
+import { Menu } from '@/types/menu'
+import pinia from '@/store'
+import { useLoginStore } from '@/store/modules/login'
+import { useUserStore } from '@/store/modules/user'
-const dynamicRouter = [
- {
+const modules = import.meta.glob('../views/**/*.vue')
+const layout = import.meta.glob('../layout/*.vue')
+
+const getComponent = (childElement: Menu) => {
+ let component = {}
+ if (childElement.viewPath) {
+ const viewPath = modules[`../views${childElement.viewPath}.vue`]
+ if (!viewPath) {
+ console.error(
+ `Menu view path configuration error or view does not exist ../views${childElement.viewPath}.vue`
+ )
+ } else {
+ component = viewPath
+ }
+ } else {
+ const path = modules[`../views${childElement.path}/index.vue`]
+ if (!path) {
+ console.error(
+ `Menu routing path configuration error or view does not exist ../views${childElement.path}/index.vue`
+ )
+ } else {
+ component = path
+ }
+ }
+ return component
+}
+const formatRouter = (data: Menu[]) => {
+ const arr: RouteRecordRaw[] = []
+ const firstMenuArr: Menu[] = []
+ const secondMenuArr: Menu[] = []
+ data.forEach((element: Menu) => {
+ if (element.menuType === 0) {
+ firstMenuArr.push(element)
+ } else if (element.menuType === 1) {
+ secondMenuArr.push(element)
+ }
+ })
+ firstMenuArr.forEach((element) => {
+ const routerObj: RouteRecordRaw = {
+ name: element.menuId,
+ path: element.path,
+ component: layout['../layout/index.vue'],
+ redirect: '',
+ children: [],
+ meta: {
+ title: element.menuName,
+ icon: element.icon,
+ link: element.link,
+ },
+ }
+ const childMenu = secondMenuArr.filter((x) => x.pid === element.id)
+ if (childMenu.length > 0) {
+ routerObj.redirect = childMenu[0].path
+ childMenu.forEach((childElement: Menu) => {
+ const component = getComponent(childElement)
+ const childRouterObj: RouteRecordRaw = {
+ name: childElement.menuId,
+ path: childElement.path,
+ component,
+ meta: {
+ title: childElement.menuName,
+ icon: childElement.icon,
+ link: childElement.link,
+ },
+ }
+ if (routerObj.children) {
+ routerObj.children.push(childRouterObj)
+ }
+ })
+ }
+ arr.push(routerObj)
+ })
+ return arr
+}
+export const addRoutes = (router: Router) => {
+ const userStore = useUserStore(pinia)
+ const menuList = userStore.getPermissionMenuList
+ const routerData = formatRouter(menuList)
+ router.addRoute({
path: '/',
name: 'fist',
- component: layout,
+ component: layout['../layout/index.vue'],
redirect: '/home',
children: [
{
@@ -13,6 +94,8 @@ const dynamicRouter = [
component: () => import('@/views/home/index.vue'),
},
],
- },
-]
-export default dynamicRouter
+ })
+ routerData.forEach((element) => {
+ router.addRoute(element)
+ })
+}
diff --git a/src/router/index.ts b/src/router/index.ts
index 5b9391bce29b75c338026a7dcfe9ef1ce29cc5f7..e48783bdc66e54eaf9e91dff28956a8c17bcb8f0 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -1,93 +1,24 @@
-import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
+import { createRouter, createWebHashHistory } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import pinia from '@/store'
import { useLoginStore } from '@/store/modules/login'
-import { useUserStore } from '@/store/modules/user'
-import { Menu } from '@/types/menu'
import staticRouter from './staticRouter'
-import dynamicRouter from './dynamicRouter'
+import { addRoutes } from './dynamicRouter'
export const router = createRouter({
history: createWebHashHistory(),
- routes: [...staticRouter, ...dynamicRouter],
+ routes: [...staticRouter],
})
-const modules = import.meta.glob('../views/**/*.vue')
-const layout = import.meta.glob('../layout/*.vue')
-
-export const formatRouter = (data: Menu[]) => {
- const arr: RouteRecordRaw[] = []
- const firstMenuArr: Menu[] = []
- const secondMenuArr: Menu[] = []
- data.forEach((element: Menu) => {
- if (element.menuType === 0) {
- firstMenuArr.push(element)
- } else if (element.menuType === 1) {
- secondMenuArr.push(element)
- }
- })
- firstMenuArr.forEach((element) => {
- const routerObj: RouteRecordRaw = {
- name: element.menuId,
- path: element.path,
- component: layout['../layout/index.vue'],
- redirect: '',
- children: [],
- meta: {
- title: element.menuName,
- icon: element.icon,
- link: element.link,
- },
- }
- const childMenu = secondMenuArr.filter((x) => x.pid === element.id)
- if (childMenu.length > 0) {
- routerObj.redirect = childMenu[0].path
- childMenu.forEach((childElement) => {
- const childRouterObj: RouteRecordRaw = {
- name: childElement.menuId,
- path: childElement.path,
- component: modules[`../views/${childElement.path}/index.vue`],
- meta: {
- title: childElement.menuName,
- icon: childElement.icon,
- link: childElement.link,
- },
- }
- routerObj.children.push(childRouterObj)
- })
- }
- arr.push(routerObj)
- })
- return arr
-}
-
-const addRoutes = async () => {
- const loginStore = useLoginStore(pinia)
- const userStore = useUserStore(pinia)
- const user = await userStore.getUserInfo(loginStore.userName)
- const { id } = user
- await userStore.getPermission(id.toString())
- const dt = JSON.parse(JSON.stringify(userStore.getPermissionMenuList))
- const routerData = formatRouter(dt)
- routerData.forEach((element) => {
- router.addRoute(element)
- })
-}
-let isRefresh = true
-router.beforeEach(async (to, from, next) => {
+router.beforeEach((to, from, next) => {
NProgress.start()
const loginStore = useLoginStore(pinia)
if (loginStore.getToken) {
- if (to.path === '/login') {
- isRefresh = true
- next()
- } else if (to.name && !isRefresh) {
- isRefresh = true
- next()
- } else {
- isRefresh = false
- await addRoutes()
+ if (!to.name) {
+ addRoutes(router)
next({ ...to, replace: true })
+ } else {
+ next()
}
} else if (to.path === '/login') {
next()
@@ -95,6 +26,6 @@ router.beforeEach(async (to, from, next) => {
next('/login')
}
})
-router.afterEach((to, from) => {
+router.afterEach(() => {
NProgress.done()
})
diff --git a/src/router/staticRouter.ts b/src/router/staticRouter.ts
index e706befac05310fc5d5a21d4fdc0d2ecaafdb1b3..1f92049a331ef44deb25f7c440a8d07c368f91c1 100644
--- a/src/router/staticRouter.ts
+++ b/src/router/staticRouter.ts
@@ -3,7 +3,6 @@ import layout from '../layout/index.vue'
const staticRouter = [
{
path: '/:catchAll(.*)',
- // name: '404',
component: () => import('@/pages/404/index.vue'),
},
{
diff --git a/src/store/modules/login.ts b/src/store/modules/login.ts
index dee3bd52702b694865a88c2c8f7070a29a89a9e7..a9e4064b123a4cf401a6442ab8b9f14d30c70b42 100644
--- a/src/store/modules/login.ts
+++ b/src/store/modules/login.ts
@@ -41,7 +41,6 @@ export const useLoginStore = defineStore('loginStore', {
userPassword: quickMd5(userPassword),
})
.then((res) => {
- router.push('/')
const { data: loginData } = res
const { token } = loginData
if (token) {
diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts
index 2cbb193151ed159575da558418ddfa3719673ddd..984400b6a318a1e05ac8926a817e3251d5cb5525 100644
--- a/src/store/modules/user.ts
+++ b/src/store/modules/user.ts
@@ -1,5 +1,5 @@
import { defineStore } from 'pinia'
-import { menuFormat } from '@/utils/index'
+import { listToTree, menuFormat } from '@/utils/index'
import { router } from '@/router'
import { User } from '@/types/user'
import { QuickResponseData } from '@/utils/request'
@@ -45,7 +45,12 @@ export const useUserStore = defineStore('userStore', {
const { data: userPermissionMenuList } = res
this.permissionMenuList = userPermissionMenuList
const dt = JSON.parse(JSON.stringify(userPermissionMenuList))
- const userMenuList = menuFormat(dt)
+ // const userMenuList = menuFormat(dt)
+ const dtNew = dt.filter((x) => x.menuType !== 2)
+ const userMenuList = listToTree(dtNew, 0, {
+ pId: 'pid',
+ })
+
const m = JSON.parse(JSON.stringify(userMenuList))
this.menuList = m
resolve(res)
diff --git a/src/types/form.ts b/src/types/form.ts
index ca9ec75742b0c396a55a2421c5d7b5f5d7c0a6df..c53dc30e6e7ef840722118f1d3a1379a3f5f9652 100644
--- a/src/types/form.ts
+++ b/src/types/form.ts
@@ -29,9 +29,11 @@ export interface FormItem {
imgUrl?: string
prop?: string
rules?: any
+ width?: string
maxLength?: string
format?: () => any
change?: (value: string) => void
+ select?: (value: string) => void
success?: () => void
beforeUpload?: () => void
}
diff --git a/src/types/menu.ts b/src/types/menu.ts
index cade909afddab1cb4df0b7caafcdc425a4a5ac97..b5b17ec7785f7459409630235737c3b2dfb2f101 100644
--- a/src/types/menu.ts
+++ b/src/types/menu.ts
@@ -1,13 +1,15 @@
export interface Menu {
- id: string
+ id: number
menuId: string
menuName: string
path: string
+ viewPath: string
menuType: number
icon: string
sort: number
- pid: string
+ pid: number
link: number
+ linkUrl: string
enabled: number
status: number
}
diff --git a/src/types/options.ts b/src/types/options.ts
index 4a77a3490888cbd85930407f9d594f881a3a8174..de255faa0f8efae94ce8b7e959e269634c337292 100644
--- a/src/types/options.ts
+++ b/src/types/options.ts
@@ -1,6 +1,6 @@
export interface Options {
label?: string
- value?: string
+ value?: string | number
}
export interface TreeOptions {
id?: string
diff --git a/src/utils/index.ts b/src/utils/index.ts
index 358972039d1db99eb5bfffbd85a0fe259a1d3f2c..223fbec5844f5da7e01f0fd6ebdb8959e168a798 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -69,15 +69,12 @@ export const treeFormat = (data: any, options: TreeOptions) => {
})
return arr
}
-export const listToTableTree = (data: any, pId = '0') => {
+export const listToTableTree = (data: any, pId = 0) => {
const arr = []
const parentData = data.filter((x: any) => x.pId === pId)
- parentData.forEach((item) => {
- // if(item.id){}
+ parentData.forEach((item: any) => {
const obj = item
obj.children = listToTableTree(data, item.id)
- // const childData = data.filter((x: any) => x.pId === item.id)
- // listToTableTree(data, item.id)
arr.push(obj)
})
return arr
@@ -173,3 +170,24 @@ export const toTuofeng = (str: string) => {
return str1
})
}
+export const listToTree = (data, pId, options) => {
+ const defaultOptions = {
+ id: 'id',
+ pId: 'pId',
+ sort: 'sort',
+ }
+ const value = options && options.id ? options.id : defaultOptions.id
+ const parentId = options && options.pId ? options.pId : defaultOptions.pId
+ const sort = options && options.sort ? options.sort : defaultOptions.sort
+ const arr = []
+ let children = []
+ const nodeData = data.filter((x) => x[parentId] === pId)
+ const nodeSort = nodeData.sort((a, b) => {
+ return a[sort] - b[sort]
+ })
+ nodeSort.forEach((element) => {
+ children = listToTree(data, element[value], options)
+ arr.push({ ...element, children })
+ })
+ return arr
+}
diff --git a/src/utils/request.ts b/src/utils/request.ts
index 0a4000f805ee77b3433e342b40ec575fb471cd59..194fb7cf541a5fb38fbd1318c941a23909bf42d6 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -1,3 +1,4 @@
+import { ElMessage } from 'element-plus'
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'
import { toTuofeng } from './index'
import { Page } from '@/types/page'
@@ -43,10 +44,9 @@ quickRequest.interceptors.response.use(
console.log('response', res)
const { data } = res
const { status, data: payload, page, msg } = data as QuickResponseData
- if (status === 0) {
- // if (!payload) {
- // return Promise.reject(msg)
- // }
+ if (status === 1) {
+ ElMessage.error(msg)
+ } else {
const jsonStr = toTuofeng(JSON.stringify(payload))
const result = JSON.parse(jsonStr)
return Promise.resolve({
@@ -57,7 +57,7 @@ quickRequest.interceptors.response.use(
return Promise.reject(msg)
},
(error) => {
- console.error(error)
+ ElMessage.error(error)
return Promise.reject(error)
}
)
diff --git a/src/views/dept/index.vue b/src/views/dept/index.vue
index ae8d311216f6cbdc0d56d6320b905cf8d922f965..65b93f1252ba0bbbd088579cda549095b4a56d9d 100644
--- a/src/views/dept/index.vue
+++ b/src/views/dept/index.vue
@@ -1,29 +1,20 @@
+
+
+
diff --git a/src/views/log/operate.vue b/src/views/log/operate.vue
new file mode 100644
index 0000000000000000000000000000000000000000..a269961432ea1e62c8dc867fccf9b973cdb75b88
--- /dev/null
+++ b/src/views/log/operate.vue
@@ -0,0 +1,145 @@
+
+
+
+
diff --git a/src/views/menu/index.vue b/src/views/menu/index.vue
index 27d252c626bf1228a441f999efb7cc9902d10344..48457a69a316dc0300e17b84277b4372b53856bd 100644
--- a/src/views/menu/index.vue
+++ b/src/views/menu/index.vue
@@ -1,14 +1,16 @@
diff --git a/src/views/permission/assignUser/index.vue b/src/views/permission/assignUser/index.vue
new file mode 100644
index 0000000000000000000000000000000000000000..ad3d944d0380237626064c0c76c8990049284ba4
--- /dev/null
+++ b/src/views/permission/assignUser/index.vue
@@ -0,0 +1,199 @@
+
+
+
+
diff --git a/src/views/permission/rolePermission/index.vue b/src/views/permission/rolePermission/index.vue
new file mode 100644
index 0000000000000000000000000000000000000000..df86919e2c2e41b8061947351c2faad1b2a90a95
--- /dev/null
+++ b/src/views/permission/rolePermission/index.vue
@@ -0,0 +1,186 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/views/rolePermission/index.vue b/src/views/rolePermission/index.vue
index adc8f8f347387b88af099d2f1c3ad45d931aef59..e23fd7af1258a30acfd9efa6c2bbe1fb55e179d9 100644
--- a/src/views/rolePermission/index.vue
+++ b/src/views/rolePermission/index.vue
@@ -1,7 +1,7 @@
+
+
+
diff --git a/src/views/system/dictionary/index.vue b/src/views/system/dictionary/index.vue
new file mode 100644
index 0000000000000000000000000000000000000000..7b45410b2de247c41f2e6432041d9d96ed8f5215
--- /dev/null
+++ b/src/views/system/dictionary/index.vue
@@ -0,0 +1,222 @@
+
+
+
+
diff --git a/src/views/system/dictionaryType/index.vue b/src/views/system/dictionaryType/index.vue
new file mode 100644
index 0000000000000000000000000000000000000000..cc4e24874bfe9efbeb32b88b7873bde8c1912712
--- /dev/null
+++ b/src/views/system/dictionaryType/index.vue
@@ -0,0 +1,151 @@
+
+
+
+
diff --git a/src/views/system/log/error.vue b/src/views/system/log/error.vue
new file mode 100644
index 0000000000000000000000000000000000000000..a269961432ea1e62c8dc867fccf9b973cdb75b88
--- /dev/null
+++ b/src/views/system/log/error.vue
@@ -0,0 +1,145 @@
+
+
+
+
diff --git a/src/views/system/log/operate.vue b/src/views/system/log/operate.vue
new file mode 100644
index 0000000000000000000000000000000000000000..a269961432ea1e62c8dc867fccf9b973cdb75b88
--- /dev/null
+++ b/src/views/system/log/operate.vue
@@ -0,0 +1,145 @@
+
+
+
+
diff --git a/src/views/system/menu/index.vue b/src/views/system/menu/index.vue
new file mode 100644
index 0000000000000000000000000000000000000000..a062c197c0b9dba9516728a3e9f65fd8af9a703c
--- /dev/null
+++ b/src/views/system/menu/index.vue
@@ -0,0 +1,345 @@
+
+
+
+
diff --git a/src/views/system/role/index.vue b/src/views/system/role/index.vue
new file mode 100644
index 0000000000000000000000000000000000000000..a269961432ea1e62c8dc867fccf9b973cdb75b88
--- /dev/null
+++ b/src/views/system/role/index.vue
@@ -0,0 +1,145 @@
+
+
+
+
diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue
new file mode 100644
index 0000000000000000000000000000000000000000..1866cc5b8c71d41d5fcbc851e08ee77ccf7723b1
--- /dev/null
+++ b/src/views/system/user/index.vue
@@ -0,0 +1,433 @@
+
+
+
+
diff --git a/tsconfig.json b/tsconfig.json
index 9c0e2500e75bc013350db3078d426c0f1dd45d35..35933cf57eb618fe00e7f2859f0e7ba0fccdb3d2 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -17,8 +17,8 @@
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
- },
- "type": ["pinia-plugin-persist"]
+ }
+ // "type": ["pinia-plugin-persist"]
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
diff --git a/vite.config.ts b/vite.config.ts
index 25137546384a7953d2add4f2769c4bbab737d202..5847f7fc3f6a916b8932b2d81e46b683349a5da2 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -48,8 +48,8 @@ export default ({ command, mode }) => {
open: true,
proxy: {
[VITE_APP_BASE_URL]: {
- // target: 'http://localhost:3102/', // 代理的目标地址-本地
- target: 'http://110.42.130.88:3102/', // 代理的目标地址-线上
+ target: 'http://localhost:3102/', // 代理的目标地址-本地
+ // target: 'http://110.42.130.88:3102/', // 代理的目标地址-线上
changeOrigin: false, // 开发模式,默认的origin是真实的 origin:localhost:3000 代理服务会把origin修改为目标地址
secure: false, // 是否https接口
ws: false, // 是否代理websockets