diff --git a/src/request/http.js b/src/request/http.js index 67add3d3b8d747166468cf8dfb5b848f0bf0c2c1..3d67c79ed17fbd2635bbcbd99284d8013e3b07ba 100644 --- a/src/request/http.js +++ b/src/request/http.js @@ -1,7 +1,7 @@ import axios from 'axios' import globalFunction from '@/globalFunction.js' import router from '@/router/router' -import { MessageBox } from 'element-ui'; +import { MessageBox, Message } from 'element-ui'; // 登录提醒 const loginTip = function() { @@ -52,9 +52,18 @@ axios.interceptors.response.use( if (error.response.status) { console.log(error.response) switch(error.response.status) { + case 404: + Message.warning('接口不存在,请刷新重试或联系管理员') + break case 401: loginTip() break + case 500: + Message.error('服务异常,请稍后刷新重试或联系管理员') + break + case 502: + Message.error('服务异常,请稍后刷新重试或联系管理员') + break default: return Promise.reject(error.response) } diff --git a/src/router/before.js b/src/router/before.js index 46ef97eadeb42ef0e4a5a35abbe0e14d3e2c53de..cf99291dc216317bf9cb3b1019f3cbd937063abe 100644 --- a/src/router/before.js +++ b/src/router/before.js @@ -1,33 +1,33 @@ -import router from '@/router/router' -import store from '@/store' - -// 路由全局前置守卫 -router.beforeEach((to, from, next) => { - store.dispatch('getUserInfo').then(() => { - if (to.matched.some((m) => m.meta.requireAuth)) { - if (!store.getters.isLogin) { - // 没有登录 - next({ - path: '/login', - query: { Rurl: to.fullPath } // 将to参数中的url传递给login页面进行操作 - }) - } else { - next() // 正常跳转到你设置好的页面 - } - } else { - next() // 正常跳转到你设置好的页面 - } - // 路由发生变化修改页面title - if (to.meta.title) { - document.title = to.meta.title - } - // 路由发生变化修改页面meta - if (to.meta.content) { - let head = document.getElementsByTagName('head') - let meta = document.createElement('meta') - document.querySelector('meta[name="description"]').setAttribute('content', to.meta.content.description) - meta.content = to.meta.content - head[0].appendChild(meta) - } - }) -}) +import router from '@/router/router' +import store from '@/store' + +// 路由全局前置守卫 +router.beforeEach((to, from, next) => { + if (to.matched.some((m) => m.meta.requireAuth)) { + store.dispatch('getUserInfo').then(() => { + if (!store.getters.isLogin) { + // 没有登录 + next({ + path: '/login', + query: { Rurl: to.fullPath } // 将to参数中的url传递给login页面进行操作 + }) + } else { + next() // 正常跳转到你设置好的页面 + } + }) + } else { + next() // 正常跳转到你设置好的页面 + } + // 路由发生变化修改页面title + if (to.meta.title) { + document.title = to.meta.title + } + // 路由发生变化修改页面meta + if (to.meta.content) { + let head = document.getElementsByTagName('head') + let meta = document.createElement('meta') + document.querySelector('meta[name="description"]').setAttribute('content', to.meta.content.description) + meta.content = to.meta.content + head[0].appendChild(meta) + } +}) diff --git a/src/router/router.js b/src/router/router.js index a7a6b57326ad74ae01e523ef75f24b3b3dce86cc..a332eb94a21ada2fe0469d86274ea376dfc2df58 100644 --- a/src/router/router.js +++ b/src/router/router.js @@ -1,58 +1,57 @@ -import Vue from 'vue' -import Router from 'vue-router' - -Vue.use(Router) - -export default new Router({ - mode: 'history', - base: process.env.BASE_URL, - routes: [ - { - path: '/', - name: 'Home', - redirect: { name: 'Stock' } - }, - { - path: '/login', - name: 'Login', - component: () => import(/* webpackChunkName: "login" */ '@/views/Login.vue'), - meta: { title: '登录 - 奇文股票' } - }, - { - path: '/register', - name: 'Register', - component: () => import(/* webpackChunkName: "register" */ '@/views/Register.vue'), - meta: { title: '注册 - 奇文股票' } - }, - { - path: '/stock', - name: 'Stock', - component: () => import(/* webpackChunkName: "stock_list" */ '@/views/Stock/StockList.vue'), - meta: { - requireAuth: true, - title: '奇文股票', - content: { - description: - '基于Springboot + Vue CLI@3 框架开发的股票分析系统,包含数据爬取,指标计算,数据分析,数据展示,复盘回顾,数据预测等功能' - } - } - }, - { - path: '/stock/detail/:stocknum', - name: 'StockDetail', - component: () => import(/* webpackChunkName: "stock_detail" */ '@/views/Stock/StockDetail.vue'), - meta: { title: '股票详情 - 奇文股票' } - }, - { - path: '*', - name: 'Error_404', - component: () => import(/* webpackChunkName: "404" */ '@/views/ErrorPage/404.vue'), - meta: { title: '404 - 奇文股票' } - } - ] -}) - -const originalPush = Router.prototype.push -Router.prototype.push = function push(location) { - return originalPush.call(this, location).catch((err) => err) -} +import Vue from 'vue' +import Router from 'vue-router' + +Vue.use(Router) + +export default new Router({ + mode: 'history', + base: process.env.BASE_URL, + routes: [ + { + path: '/', + name: 'Home', + redirect: { name: 'Stock' } + }, + { + path: '/login', + name: 'Login', + component: () => import(/* webpackChunkName: "login" */ '@/views/Login.vue'), + meta: { title: '登录 - 奇文股票' } + }, + { + path: '/register', + name: 'Register', + component: () => import(/* webpackChunkName: "register" */ '@/views/Register.vue'), + meta: { title: '注册 - 奇文股票' } + }, + { + path: '/stock', + name: 'Stock', + component: () => import(/* webpackChunkName: "stock_list" */ '@/views/Stock/StockList.vue'), + meta: { + title: '奇文股票', + content: { + description: + '基于Springboot + Vue CLI@3 框架开发的股票分析系统,包含数据爬取,指标计算,数据分析,数据展示,复盘回顾,数据预测等功能' + } + } + }, + { + path: '/stock/detail/:stocknum', + name: 'StockDetail', + component: () => import(/* webpackChunkName: "stock_detail" */ '@/views/Stock/StockDetail.vue'), + meta: { title: '股票详情 - 奇文股票' } + }, + { + path: '*', + name: 'Error_404', + component: () => import(/* webpackChunkName: "404" */ '@/views/ErrorPage/404.vue'), + meta: { title: '404 - 奇文股票' } + } + ] +}) + +const originalPush = Router.prototype.push +Router.prototype.push = function push(location) { + return originalPush.call(this, location).catch((err) => err) +}