From 4c4f7640263fd66ac621602334115888b0ffd17e Mon Sep 17 00:00:00 2001 From: 梁保满 Date: Thu, 1 Dec 2022 11:07:25 +0800 Subject: [PATCH] 路由表,路由前端文件 --- public/favicon.ico | Bin 0 -> 8082 bytes src/api/apis/login.js | 6 +++++- src/api/index.js | 2 +- src/router/index.js | 4 ++-- src/router/permission.js | 95 +++++++++++++++++------------------------------------------------------------------------------ src/store/index.js | 330 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------- src/store/modules/role.js | 32 -------------------------------- src/store/modules/routerData.js | 40 ---------------------------------------- src/views/ask/analysis.vue | 13 +++++++++++++ src/views/ask/index.vue | 16 ++++++++++++++++ src/views/card/index.vue | 13 +++++++++++++ src/views/dataSync/index.vue | 13 +++++++++++++ src/views/device/index.vue | 13 +++++++++++++ src/views/down/client.vue | 13 +++++++++++++ src/views/down/index.vue | 15 +++++++++++++++ src/views/examinationPaper/add.vue | 13 +++++++++++++ src/views/examinationPaper/edit.vue | 13 +++++++++++++ src/views/examinationPaper/index.vue | 18 ++++++++++++++++++ src/views/examinationPaper/recycle.vue | 13 +++++++++++++ src/views/index/mainIndex.vue | 12 +----------- src/views/layout/aside/aside.vue | 24 ++++++++++++++++-------- src/views/layout/header/header.vue | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------- src/views/login/index.vue | 28 +--------------------------- src/views/portrait/index.vue | 13 +++++++++++++ src/views/setUp/account.vue | 13 +++++++++++++ src/views/setUp/conglomerate.vue | 13 +++++++++++++ src/views/setUp/school.vue | 13 +++++++++++++ src/views/setUp/student.vue | 13 +++++++++++++ src/views/setUp/teacher.vue | 13 +++++++++++++ src/views/test/analysis.vue | 13 +++++++++++++ src/views/test/index.vue | 16 ++++++++++++++++ 31 files changed, 716 insertions(+), 265 deletions(-) create mode 100644 public/favicon.ico delete mode 100644 src/store/modules/role.js delete mode 100644 src/store/modules/routerData.js create mode 100644 src/views/ask/analysis.vue create mode 100644 src/views/ask/index.vue create mode 100644 src/views/card/index.vue create mode 100644 src/views/dataSync/index.vue create mode 100644 src/views/device/index.vue create mode 100644 src/views/down/client.vue create mode 100644 src/views/down/index.vue create mode 100644 src/views/examinationPaper/add.vue create mode 100644 src/views/examinationPaper/edit.vue create mode 100644 src/views/examinationPaper/index.vue create mode 100644 src/views/examinationPaper/recycle.vue create mode 100644 src/views/portrait/index.vue create mode 100644 src/views/setUp/account.vue create mode 100644 src/views/setUp/conglomerate.vue create mode 100644 src/views/setUp/school.vue create mode 100644 src/views/setUp/student.vue create mode 100644 src/views/setUp/teacher.vue create mode 100644 src/views/test/analysis.vue create mode 100644 src/views/test/index.vue diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..cfc0a3c Binary files /dev/null and b/public/favicon.ico differ diff --git a/src/api/apis/login.js b/src/api/apis/login.js index 930141b..1956ac0 100644 --- a/src/api/apis/login.js +++ b/src/api/apis/login.js @@ -5,6 +5,10 @@ import loginUrls from "../urls/login" export default { // 账号密码登陆 fetchLogin (data) { - return axios.post(loginUrls.login, data) + // return axios.post(loginUrls.login, data) + return { + status:200, + data:[] + } } } diff --git a/src/api/index.js b/src/api/index.js index ce6c9b3..f83b67f 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -4,5 +4,5 @@ const modules = modulesFiles.keys().reduce((modules, modulePath) => { modules = Object.assign(modules, value.default) return modules }, {}) - +console.log(modules) export default modules diff --git a/src/router/index.js b/src/router/index.js index dec8e9a..5eaa2fe 100755 --- a/src/router/index.js +++ b/src/router/index.js @@ -32,8 +32,8 @@ let defaultRouter = [ }, { path: "/index", - iconCls: "fa fa-dashboard", // 图标样式class - name: "首页", + iconCls: "fa fa-home", // 图标样式class + name: "应用首页", component: Layout, alone: true, children: [ diff --git a/src/router/permission.js b/src/router/permission.js index d93fbd7..e898dec 100644 --- a/src/router/permission.js +++ b/src/router/permission.js @@ -1,97 +1,36 @@ import NProgress from "nprogress" -import en from "../i18n/lang/en" -import Layout from "@/views/layout/layout" -import CommerViews from "@/views/commerViews" + import router from "./index" import store from "../store" -let routeName = en.routeName - -const Erji = () => import("@/views/duoji/erji") -const Sanji = () => import("@/views/duoji/sanji") - let addrouters = [ //测试用,后续后端获取 - - { - path: "/", - iconCls: "fa fa-server", - // name: routeName.multiDirectory, - name: '多级', - component: Layout, - children: [ - { - path: "/erji1", - iconCls: "fa fa-server", - // name: routeName["menu2-1"], - name: '二级', - component: Erji, - meta:{ - role:['admin'] - }, - children: [] - }, - { - path: "/erji3", - iconCls: "fa fa-server", - name: "三级", - component: CommerViews, // 无限极菜单的容器 - children: [ - { - path: "/sanji1", - iconCls: "fa fa-server", - name: "三级子页面", - component: Sanji, - children: [] - }, - ] - } - ] - }, - - { path: "*", - redirect: "/404", - hidden: true, - children: [] - } -] - // 获取角色信息,根据用户权限动态加载路由 router.beforeEach((to, from, next) => { NProgress.start() if (store.getters.token) { if (to.path === "/login") { - next({path: "/"}) + next() } else { - if (!store.getters.info.role) { - !(async function getAddRouters () { - // 省略 axios 请求代码 通过 token 向后台请求用户权限等信息,这里用假数据赋值 - await store.dispatch("setInfo", { - role: "superAdmin", - permissions: "超级管理员", - name:"张老师", - }) - await store.dispatch("newRoutes",addrouters) - let newAddRouters = store.getters.addRouters - await router.addRoutes(newAddRouters) - next({path: to.path}) - }()) - } else { - let is404 = to.matched.some(record => { - if (record.meta.role) { - return store.getters.info.authorityRouter === -1 - } - }) - if (is404) { - next({path: "/404"}) - return false - } + // if (!store.getters.info.permissions) { + // next({ path: to.path }) + // } else { + // let is404 = to.matched.some(record => { + // if (record.meta.role) { + // return store.getters.info.authorityRouter === -1 + // } + // }) + // if (is404) { + // next({ path: "/404" }) + // return false + // } next() - } + // } } } else { if (to.path === "/login") { next() } - next({path: "/login"}) + next({ path: "/login" }) + } }) diff --git a/src/store/index.js b/src/store/index.js index de0206f..6d85e79 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,45 +1,331 @@ import Vue from "vue" import Vuex from "vuex" import Cookies from "js-cookie" -import routerData from "./modules/routerData" -import role from "./modules/role" -import layout from "./modules/layout/index" +import layoutStore from "./modules/layout/index" +import { defaultRouter } from "@/router/index" + +import request from "@/api/index" +import router from "@/router/index" + +import Layout from "@/views/layout/layout" +import CommerViews from "@/views/commerViews" +const ExaminationPaper = () => import("@/views/examinationPaper/index") +const ExaminationPaperAdd = () => import("@/views/examinationPaper/add") +const ExaminationPaperEdit = () => import("@/views/examinationPaper/edit") +const ExaminationPaperRecycle = () => import("@/views/examinationPaper/recycle") +const Ask = () => import("@/views/ask/index") +const AskAnalysis = () => import("@/views/ask/analysis") +const Test = () => import("@/views/test/index") +const TestAnalysis = () => import("@/views/test/analysis") +const DataSync = () => import("@/views/dataSync/index") +const Portrait = () => import("@/views/portrait/index") +const Card = () => import("@/views/card/index") +const Device = () => import("@/views/device/index") +const Down = () => import("@/views/down/index") +const DownClient = () => import("@/views/down/client") +const SetUpAccount = () => import("@/views/setUp/account") +const SetUpConglomerate = () => import("@/views/setUp/conglomerate") +const SetUpSchool = () => import("@/views/setUp/school") +const SetUpStudent = () => import("@/views/setUp/student") +const SetUpTeacher = () => import("@/views/setUp/teacher") +let addrouters = [ //测试用,后续后端获取 + { + path: "/examinationPaper", + iconCls: "fa fa-file-text", // 图标样式class + name: "备题组卷", + component: Layout, + alone: true, + children: [ + { + path: "/examinationPaper", + iconCls: "fa fa-file-text", // 图标样式class + name: "", + component: ExaminationPaper, + children: [] + }, + { + path: "/examinationPaperAdd", + iconCls: "", // 图标样式class + name: "添加答题卡", + component: ExaminationPaperAdd, + children: [] + }, + { + path: "/examinationPaperEdit", + iconCls: "", // 图标样式class + name: "修改答题卡", + component: ExaminationPaperEdit, + children: [] + }, + { + path: "/examinationPaperRecycle", + iconCls: "", // 图标样式class + name: "已归档答题卡", + component: ExaminationPaperRecycle, + children: [] + }, + ] + }, + { + path: "/ask", + iconCls: "fa fa-bar-chart", // 图标样式class + name: "随堂问报表", + component: Layout, + alone: true, + children: [ + { + path: "/ask", + iconCls: "fa fa-bar-chart", // 图标样式class + name: "", + component: Ask, + children: [] + + }, + { + path: "/askAnalysis", + iconCls: "", // 图标样式class + name: "随堂问报表分析", + component: AskAnalysis, + children: [] + } + ] + }, + { + path: "/test", + iconCls: "fa fa-pie-chart", // 图标样式class + name: "即时测报表", + component: Layout, + alone: true, + children: [ + { + path: "/test", + iconCls: "fa fa-pie-chart", // 图标样式class + name: "", + component: Test, + children: [] + }, + { + path: "/testAnalysis", + iconCls: "", // 图标样式class + name: "即时测报表分析", + component: TestAnalysis, + children: [] + } + + ] + }, + { + path: "/portrait", + iconCls: "fa fa-users", // 图标样式class + name: "学生画像", + component: Layout, + alone: true, + children: [ + { + path: "/portrait", + iconCls: "fa fa-users", // 图标样式class + name: "", + component: Portrait, + children: [] + } + ] + }, + { + path: "/dataSync", + iconCls: "fa fa-random", // 图标样式class + name: "数据同步", + component: Layout, + alone: true, + children: [ + { + path: "/dataSync", + iconCls: "fa fa-random", // 图标样式class + name: "", + component: DataSync, + children: [] + } + ] + }, + { + path: "/", + iconCls: "fa fa-cog", + name: '信息管理', + component: Layout, + children: [ + { + path: "/setUpAccount", + iconCls: "fa fa-id-card-o", + name: '账号管理', + component: SetUpAccount, + children: [] + }, + { + path: "/setUpConglomerate", + iconCls: "fa fa-building", + name: '集团管理', + component: SetUpConglomerate, + children: [] + }, + { + path: "/setUpSchool", + iconCls: "fa fa-calculator", + name: '学校管理', + component: SetUpSchool, + children: [] + }, + { + path: "/setUpTeacher", + iconCls: "fa fa-male", + name: '教师管理', + component: SetUpTeacher, + children: [] + }, + { + path: "/setUpStudent", + iconCls: "fa fa-mortar-board", + name: '学生管理', + component: SetUpStudent, + children: [] + }, + ] + }, + { + path: "/card", + iconCls: "fa fa-id-card", // 图标样式class + name: "发卡记录", + component: Layout, + alone: true, + children: [ + { + path: "/card", + iconCls: "fa fa-id-card", // 图标样式class + name: "", + component: Card, + children: [] + } + ] + }, + { + path: "/device", + iconCls: "fa fa-dashboard", // 图标样式class + name: "设备状态", + component: Layout, + alone: true, + children: [ + { + path: "/device", + iconCls: "fa fa-dashboard", // 图标样式class + name: "", + component: Device, + children: [] + } + ] + }, + { + path: "/down", + iconCls: "fa fa-download", // 图标样式class + name: "软件下载", + component: Layout, + alone: true, + children: [ + { + path: "/down", + iconCls: "fa fa-download", // 图标样式class + name: "", + component: Down, + children: [] + }, + { + path: "/downClient", + iconCls: "", // 图标样式class + name: "", + component: DownClient, + children: [] + } + ] + }, + + { + path: "*", + redirect: "/404", + hidden: true, + children: [] + } +] Vue.use(Vuex) const store = new Vuex.Store({ state: { - token: Cookies.get("token") + token: Cookies.get("token"), + info: "", // 每次刷新都要通过token请求个人信息来筛选动态路由 + routers: [], + addRouters: [], }, mutations: { - setToken (state, token) { + setToken(state, token) { state.token = token Cookies.set("token", token, { expires: 1 / 24 }) - } + }, + setInfo(state, data) { + state.info = { + role: data.role, + permissions: data.permissions, + name: data.name, + authorityRouter: data.authorityRouter, + avatar: data.avatar ? data.avatar : "", + uid: data.id + } + localStorage.setItem("info", JSON.stringify(store.getters.info)) + }, + setRouters: (state, routers) => { + state.addRouters = routers // 保存动态路由用来addRouter + state.routers = defaultRouter.concat(routers) // 所有有权限的路由表,用来生成菜单列表 + }, }, actions: { - setToken ({commit}, token) { - return new Promise((resolve, reject) => { - commit("setToken", token) - resolve() - }) + Login({ commit }, that) { + console.log(that.$router) + debugger + // request.fetchLogin(that.loginForm).then(res => { + // if (res.status == 200) { + commit("setToken", "xxxx") + commit("setInfo", { + permissions: [ + { + role: "superAdmin", + roleName: "超级管理员", + }, + ], + name: "张老师", + // avatar: data.avatar ? data.avatar : "", + // uid: data.id, + // authorityRouter:[], + }); + commit("setRouters", addrouters) + // let newAddRouters = getters.addRouters; + // await router.addRoutes(newAddRouters) + addrouters.forEach((res) => { + that.$router.addRoute(res); + }); + that.$router.push({ path: "/" }) + // } + // }) } }, getters: { - addRouters: state => state.routerData.addRouters, + addRouters: state => state.addRouters, token: state => state.token, - info: state => state.role.info, - routers: state => state.routerData.routers, - logoShow: state => state.layout.logoShow, - isCollapse: state => state.layout.isCollapse, - uniquerouter: state => state.layout.uniquerouter, - tabnavBox: state => state.layout.tabnavBox, - rightNav: state => state.layout.rightNav + info: state => state.info, + routers: state => state.routers, + logoShow: state => state.layoutStore.logoShow, + isCollapse: state => state.layoutStore.isCollapse, + uniquerouter: state => state.layoutStore.uniquerouter, + tabnavBox: state => state.layoutStore.tabnavBox, + rightNav: state => state.layoutStore.rightNav }, modules: { - routerData, - role, - layout + layoutStore } }) diff --git a/src/store/modules/role.js b/src/store/modules/role.js deleted file mode 100644 index ccfdc55..0000000 --- a/src/store/modules/role.js +++ /dev/null @@ -1,32 +0,0 @@ -import store from "../index" -import router from "../../router/index" -export default { - state: { - info: "" // 每次刷新都要通过token请求个人信息来筛选动态路由 - }, - mutations: { - setInfo (state, data) { - if (data.authorityRouter) { - data.authorityRouter = data.authorityRouter.indexOf(",") !== -1 ? data.authorityRouter.split(",") : new Array(data.authorityRouter) - } else { - data.authorityRouter = [] - } - - - - state.info = { - role: data.role, - name: data.name, - authorityRouter: data.authorityRouter, - avatar: data.avatar ? data.avatar : "", - uid: data.id - } - localStorage.setItem("info", JSON.stringify(store.getters.info)) - } - }, - actions: { - setInfo ({commit}, data) { - commit("setInfo", data) - } - } -} diff --git a/src/store/modules/routerData.js b/src/store/modules/routerData.js deleted file mode 100644 index 01987c0..0000000 --- a/src/store/modules/routerData.js +++ /dev/null @@ -1,40 +0,0 @@ -import {defaultRouter} from "@/router/index" - -const routerData = { - state: { - routers: [], - addRouters: [], - }, - mutations: { - setRouters: (state, routers) => { - state.addRouters = routers // 保存动态路由用来addRouter - state.routers = defaultRouter.concat(routers) // 所有有权限的路由表,用来生成菜单列表 - }, - }, - actions: { - newRoutes ({commit},addRouter) { - // 通过递归路由表,删除掉没有权限的路由 - function eachSelect (routers) { - for (let i = 0; i < routers.length; i++) { - if (routers[i].meta && routers[i].meta.role.length && routers[i].meta.role.indexOf(userRole) === -1) { - routers.splice(i, 1) - i = i !== 0 ? i - 1 : i - } - if (routers[i].children && routers[i].children.length) { - eachSelect(routers[i].children, userRole) - } - } - } - // 仅限演示 - let newArr = [...addRouter] // 拷贝这个数组是因为做权限测试的时候可以从低级切回到高级角色,仅限演示,正式开发时省略这步直接使用 addRouter - // eachSelect(newArr) - commit("setRouters", newArr) - - // 正式开发 - // eachSelect(addRouter, role) - // commit('setRouters', addRouter) - } - } -} - -export default routerData diff --git a/src/views/ask/analysis.vue b/src/views/ask/analysis.vue new file mode 100644 index 0000000..89c9741 --- /dev/null +++ b/src/views/ask/analysis.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/views/ask/index.vue b/src/views/ask/index.vue new file mode 100644 index 0000000..aa7cb81 --- /dev/null +++ b/src/views/ask/index.vue @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/src/views/card/index.vue b/src/views/card/index.vue new file mode 100644 index 0000000..18784ae --- /dev/null +++ b/src/views/card/index.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/views/dataSync/index.vue b/src/views/dataSync/index.vue new file mode 100644 index 0000000..46208cb --- /dev/null +++ b/src/views/dataSync/index.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/views/device/index.vue b/src/views/device/index.vue new file mode 100644 index 0000000..d151be4 --- /dev/null +++ b/src/views/device/index.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/views/down/client.vue b/src/views/down/client.vue new file mode 100644 index 0000000..2c99891 --- /dev/null +++ b/src/views/down/client.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/views/down/index.vue b/src/views/down/index.vue new file mode 100644 index 0000000..bc17f2f --- /dev/null +++ b/src/views/down/index.vue @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/src/views/examinationPaper/add.vue b/src/views/examinationPaper/add.vue new file mode 100644 index 0000000..abfb84c --- /dev/null +++ b/src/views/examinationPaper/add.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/views/examinationPaper/edit.vue b/src/views/examinationPaper/edit.vue new file mode 100644 index 0000000..3567db9 --- /dev/null +++ b/src/views/examinationPaper/edit.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/views/examinationPaper/index.vue b/src/views/examinationPaper/index.vue new file mode 100644 index 0000000..760f495 --- /dev/null +++ b/src/views/examinationPaper/index.vue @@ -0,0 +1,18 @@ + + + + + \ No newline at end of file diff --git a/src/views/examinationPaper/recycle.vue b/src/views/examinationPaper/recycle.vue new file mode 100644 index 0000000..252625d --- /dev/null +++ b/src/views/examinationPaper/recycle.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/views/index/mainIndex.vue b/src/views/index/mainIndex.vue index 0e5652e..982e4c6 100644 --- a/src/views/index/mainIndex.vue +++ b/src/views/index/mainIndex.vue @@ -1,20 +1,10 @@ + + \ No newline at end of file diff --git a/src/views/setUp/account.vue b/src/views/setUp/account.vue new file mode 100644 index 0000000..258fce6 --- /dev/null +++ b/src/views/setUp/account.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/views/setUp/conglomerate.vue b/src/views/setUp/conglomerate.vue new file mode 100644 index 0000000..1177ff2 --- /dev/null +++ b/src/views/setUp/conglomerate.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/views/setUp/school.vue b/src/views/setUp/school.vue new file mode 100644 index 0000000..b5b28ff --- /dev/null +++ b/src/views/setUp/school.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/views/setUp/student.vue b/src/views/setUp/student.vue new file mode 100644 index 0000000..d4fbe5f --- /dev/null +++ b/src/views/setUp/student.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/views/setUp/teacher.vue b/src/views/setUp/teacher.vue new file mode 100644 index 0000000..7390e44 --- /dev/null +++ b/src/views/setUp/teacher.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/views/test/analysis.vue b/src/views/test/analysis.vue new file mode 100644 index 0000000..89c9741 --- /dev/null +++ b/src/views/test/analysis.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/views/test/index.vue b/src/views/test/index.vue new file mode 100644 index 0000000..2d65aed --- /dev/null +++ b/src/views/test/index.vue @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file -- libgit2 0.21.4