From 4438dbfe4d11357b5274a0525685ff8ac30ff2c6 Mon Sep 17 00:00:00 2001 From: hezhidong <1531792767@qq.com> Date: Tue, 30 Jan 2024 10:55:56 +0800 Subject: [PATCH] 1 --- src/layout/navBars/breadcrumb/user.vue | 24 +- src/router/index.js | 130 ++---- src/utils/request.js | 37 +- .../PaymentSystem/CreatePayment/index.vue | 385 +++++++++--------- src/views/home/index.vue | 64 ++- src/views/login/index.vue | 184 ++++----- 6 files changed, 328 insertions(+), 496 deletions(-) diff --git a/src/layout/navBars/breadcrumb/user.vue b/src/layout/navBars/breadcrumb/user.vue index 3d09406..83bee96 100644 --- a/src/layout/navBars/breadcrumb/user.vue +++ b/src/layout/navBars/breadcrumb/user.vue @@ -87,17 +87,17 @@ - {{ UserInformation.name }} + {{ getUserInfos.userName === "" ? "test" : getUserInfos.userName }} {{ $t("message.user.dropdown1") }} - + }} {{ $t("message.user.dropdown5") }} @@ -132,14 +132,13 @@ export default { isShowUserNewsPopover: false, disabledI18n: "zh-cn", disabledSize: "", - UserInformation: {}, }; }, computed: { // 获取用户信息 - // getUserInfos() { - // return this.$store.state.userInfos.userInfosDD; - // }, + getUserInfos() { + return this.$store.state.userInfos.userInfos; + }, // 设置弹性盒子布局 flex layoutUserFlexNum() { let { layout, isClassicSplitMenu } = this.$store.state.themeConfig.themeConfig; @@ -155,13 +154,11 @@ export default { }, }, mounted() { - this.resetUserInformation(); if (Local.get("themeConfigPrev")) { this.initI18n(); this.initComponentSize(); } }, - methods: { // 搜索点击 onSearchClick() { @@ -269,16 +266,11 @@ export default { .catch(() => {}); }, 150); } else if (path === "wareHouse") { - window.open("http://www.baidu.com"); + window.open("https://gitee.com/lyt-top/vue-next-admin"); } else { this.$router.push(path); } }, - // 重置DD用户信息 - resetUserInformation() { - let res = Session.get("userInfoDD"); - this.UserInformation = res; - }, }, }; diff --git a/src/router/index.js b/src/router/index.js index a020ecc..caa9a39 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -6,9 +6,7 @@ import 'nprogress/nprogress.css'; import { Session } from '@/utils/storage'; import { PrevLoading } from '@/utils/loading.js'; import { useMenuApi } from '@/api/menu'; -import adminbendirout from '../../public/admin' -// import config from "/package.json"; - +import adminbendirout from '../../public/admin'; const menuApi = useMenuApi(); @@ -45,7 +43,6 @@ const staticRoutes = [ title: '登录', }, }, - { path: '/404', name: 'notFound', @@ -67,24 +64,11 @@ const staticRoutes = [ // 加载静态路由 const createRouter = () => new VueRouter({ - // mode: 'history', routes: staticRoutes, - base: '/', }); // 创建路由 const router = createRouter(); -// 处理错误路由 -router.onError((error) => { - const pattern = /Loading chunk (\d)+ failed/g; - const isChunkLoadFailed = error.message.match(pattern); - if (isChunkLoadFailed) { - window.location.reload(); - router.replace(router.history.pending.fullPath); - }else{ - console.log(error) - } - }); // 加载 loading PrevLoading.start(); @@ -189,38 +173,6 @@ export function dynamicRouter(routes) { }); } -// 处理后端传来的路由表进行过滤操作 -// 定义一个函数,用于过滤本地路由表 -function filterLocalRoutes(localRoutes, backendRoutes) { - const backendPaths = getRoutePaths(backendRoutes); - function filterRoutes(routes) { - return routes.filter((route) => { - if (backendPaths.includes(route.path)) { - return true; - } else if (route.children) { - route.children = filterRoutes(route.children); - return route.children.length > 0; - } else { - return false; - } - }); - } - return filterRoutes(localRoutes); - } - // 获取后端路由中所有的 path 值数组 - function getRoutePaths(routes) { - const paths = []; - routes.forEach((route) => { - if (route.path) { - paths.push(route.path); - } - if (route.children && route.children.length > 0) { - paths.push(...getRoutePaths(route.children)); - } - }); - return paths; - } - // 添加路由,模拟数据与方法,可自行进行修改 admin // 添加动态路由,`{ path: '*', redirect: '/404' }` 防止页面刷新,静态路由丢失问题 // next({ ...to, replace: true }) 动态路由 addRoute 完毕后才放行,防止刷新时 NProgress 进度条加载2次 @@ -228,61 +180,35 @@ function filterLocalRoutes(localRoutes, backendRoutes) { export function adminUser(router, to, next) { resetRouter(); // 发请求获取路由表操作 - // let parameter = { - // clientName:config.name, - // version:config.version, - // } // menuApi - // .getMenuAdmin(parameter) - // .then(async (res) => { - // // 获取路由表 - // console.log(res.data); - // // 读取用户信息,获取对应权限进行判断 - // store.dispatch('userInfos/setUserInfos'); - // store.dispatch('routesList/setRoutesList', setFilterMenuFun(res.data, store.state.userInfos.userInfos.roles)); - // dynamicRoutes[0].children = res.data; - // const awaitRoute = await dynamicRouter(dynamicRoutes); - // [...awaitRoute, { path: '*', redirect: '/404' }].forEach((route) => { - // router.addRoute({ ...route }); - // }); - // setCacheTagsViewRoutes(JSON.parse(JSON.stringify(res.data))); - // next({ ...to, replace: true }); - // }) - // .catch(() => {}); + // .getMenuAdmin() + // .then(async (res) => { + // // 获取路由表 + // console.log(res.data); + // // 读取用户信息,获取对应权限进行判断 + // store.dispatch('userInfos/setUserInfos'); + // store.dispatch('routesList/setRoutesList', setFilterMenuFun(res.data, store.state.userInfos.userInfos.roles)); + // dynamicRoutes[0].children = res.data; + // const awaitRoute = await dynamicRouter(dynamicRoutes); + // [...awaitRoute, { path: '*', redirect: '/404' }].forEach((route) => { + // router.addRoute({ ...route }); + // }); + // setCacheTagsViewRoutes(JSON.parse(JSON.stringify(res.data))); + // next({ ...to, replace: true }); + // }) + // .catch(() => {}); + // 本地数据路由表操作 - let routingTable = sessionStorage.getItem('smart-campus:userInfoDD') - let value = JSON.parse(routingTable); - console.log(value.authorities); - - let filteredLocalRoutes = filterLocalRoutes(adminbendirout.data, value.authorities) - let home ={ - path: "/home", - name: "home", - component: "home", - meta: { - "title": "message.router.home", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": true, - "isIframe": false, - "roles": ["admin", "common"], - "icon": "iconfont icon-shouye" - } - } - filteredLocalRoutes.unshift(home) - console.log(filteredLocalRoutes);; - - - store.dispatch('userInfos/setUserInfos'); - store.dispatch('routesList/setRoutesList', setFilterMenuFun(filteredLocalRoutes, store.state.userInfos.userInfos.roles)); - dynamicRoutes[0].children = filteredLocalRoutes; - const awaitRoute = dynamicRouter(dynamicRoutes); - [...awaitRoute, { path: '*', redirect: '/404' }].forEach((route) => { - router.addRoute({ ...route }); - }); - setCacheTagsViewRoutes(JSON.parse(JSON.stringify(filteredLocalRoutes))); - next({ ...to, replace: true }); + console.log(adminbendirout); + store.dispatch('userInfos/setUserInfos'); + store.dispatch('routesList/setRoutesList', setFilterMenuFun(adminbendirout.data, store.state.userInfos.userInfos.roles)); + dynamicRoutes[0].children = adminbendirout.data; + const awaitRoute = dynamicRouter(dynamicRoutes); + [...awaitRoute, { path: '*', redirect: '/404' }].forEach((route) => { + router.addRoute({ ...route }); + }); + setCacheTagsViewRoutes(JSON.parse(JSON.stringify(adminbendirout.data))); + next({ ...to, replace: true }); } // 添加路由,模拟数据与方法,可自行进行修改 test diff --git a/src/utils/request.js b/src/utils/request.js index ad73402..c5ba030 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -3,30 +3,21 @@ import router, { resetRouter } from '@/router/index'; import axios from 'axios'; import { Message, MessageBox } from 'element-ui'; import { Session } from '@/utils/storage'; -import { setTimeout } from 'core-js'; + // 创建 axios 实例 const service = axios.create({ baseURL: process.env.VUE_APP_BASE_API, timeout: 50000, headers: { 'Content-Type': 'application/json' }, }); + // 添加请求拦截器 service.interceptors.request.use( (config) => { // 在发送请求之前做些什么 token if (Session.get('token')) { - // 带头部token config.headers.common['Authorization'] = `${Session.get('token')}`; } - let params = config.params - let newData = {} - for( let key in params){ - if( params[key] !== null && params[key] !== ''){ - newData[key] = params[key] - } - } - config.params = newData - console.log(config) return config; }, (error) => { @@ -40,9 +31,7 @@ service.interceptors.response.use( (response) => { // 对响应数据做点什么 const res = response.data; - // 根据后端状态码判断 - if (res.code) { - // if (res.code && res.code !== 0 ) { + if (res.code && res.code !== 0) { // `token` 过期或者账号已在别处登录 if (res.code === 401 || res.code === 4001) { // 清除浏览器全部临时缓存 @@ -54,35 +43,23 @@ service.interceptors.response.use( .then(() => {}) .catch(() => {}); } - return response.data; + return Promise.reject(service.interceptors.response.error); } else { - return Promise.reject(response.data); + return response.data; } }, (error) => { - console.log(error); + // 对响应错误做点什么 if (error.message.indexOf('timeout') != -1) { Message.error('网络超时'); } else if (error.message == 'Network Error') { Message.error('网络连接错误'); - // 错误thenk失效 } else { - // 清除浏览器全部临时缓存 - // Session.clear(); - // router.push('/login'); - // store.commit('setMenuData', {}); - // resetRouter(); // 重置路由 - // MessageBox.alert('你已被登出,请重新登录', '提示', {}) - // .then(() => {}) - // .catch(() => {}); - Message.error(error.response.data.msg || '错误'); + Message.error(error.response.data.message); } return Promise.reject(error); } ); - - - // 导出 axios 实例 export default service; diff --git a/src/views/PaymentSystem/CreatePayment/index.vue b/src/views/PaymentSystem/CreatePayment/index.vue index f132372..2666727 100644 --- a/src/views/PaymentSystem/CreatePayment/index.vue +++ b/src/views/PaymentSystem/CreatePayment/index.vue @@ -3,35 +3,35 @@
- + - - - - - - - - - - + + + + + + + + + - + @@ -41,11 +41,11 @@ v-model="query.date" type="date" value-format="yyyy-MM-dd" - placeholder="选择开始时间"> + placeholder="选择开始时间" + > - @@ -58,17 +58,23 @@ :columns="columns" :data="data" > - - + - + @@ -100,14 +107,14 @@ > - + + > @@ -123,34 +130,40 @@

已缴费名单

-
-
{{item.name}}
+
+
+ {{ item.name }}
-
- 暂无缴费名单 -
-

未缴费名单

-
-
{{item.name}}
-
-
- 暂无缴费名单 -
- +
暂无缴费名单
+

未缴费名单

+
+
+ {{ item.name }}
+
+
暂无缴费名单
+
- -
- diff --git a/src/views/home/index.vue b/src/views/home/index.vue index 0365bff..db4e699 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -2,38 +2,40 @@
- +
{{ $t("message.card.title1") }}
- +
{{ currentTime }},{{ userInformation.name }},{{ dailyMessage }} + >{{ currentTime }},{{ getUserInfos.userName }},{{ dailyMessage }}
昵称:
-
{{ userInformation.name }}
+
小柒
身份:
- {{ identity }} + {{ userInfo.userName === "admin" ? "超级管理" : "普通用户" }}
-
电话:
-
- {{ userInformation.mobile }} -
+
IP:
+
192.168.1.1
+
+ +
时间:
+
{{ userInfo.time }}
@@ -49,8 +51,7 @@
- - + +
{{ $t("message.card.title1") }}
+