1- // The Vue build version to load with the `import` command
2- // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
31import 'babel-polyfill'
42import 'eventsource-polyfill'
53import Vue from "vue" ;
64import frame from "./frame.vue" ;
7- import VueRouter from "vue-router" ;
8- import routeConfig from "./router" ;
9- import { sync } from "vuex-router-sync" ;
5+ import router from "./router" ;
106import store from "./store" ;
11- import axios from "axios" ;
7+ import axios from "./ axios" ;
128import filters from "./filters" ;
139import VueProgressBar from "vue-progressbar" ;
14- import types from "./store/mutation-types" ;
15- import auth from "./auth" ;
1610import Element from "element-ui" ;
1711// import 'element-ui/lib/theme-default/index.css';
1812import "./css/theme/index.css" ;
1913import ImpPanel from "./components/panel.vue" ;
2014
15+ Vue . use ( axios ) ;
2116
2217Vue . use ( Element ) ;
2318
24- function getBaseUrl ( url ) {
25- var reg = / ^ ( ( \w + ) : \/ \/ ( [ ^ \/ : ] * ) (?: : ( \d + ) ) ? ) ( .* ) / ;
26- reg . exec ( url ) ;
27- return RegExp . $1 ;
28- }
29-
30- // axios.defaults.baseURL = 'https://www.baidu.com';
31- axios . defaults . baseURL = getBaseUrl ( window . location . href ) ;
32- axios . defaults . headers . common [ 'authUid' ] = auth . getUid ( ) ;
33- axios . defaults . headers . common [ 'authSid' ] = auth . getSid ( ) ;
34-
35- Vue . prototype . $http = axios
36- Vue . axios = axios
37-
38-
39- //加载路由中间件
40- Vue . use ( VueRouter )
41-
4219Vue . component ( ImpPanel . name , ImpPanel ) ;
4320
4421Vue . use ( VueProgressBar , {
@@ -54,47 +31,6 @@ Vue.use(VueProgressBar, {
5431 inverse : false
5532} )
5633
57- //定义路由
58- const router = new VueRouter ( {
59- routes : routeConfig ,
60- //mode: 'history'
61- } )
62-
63- sync ( store , router )
64-
65- const { state} = store
66-
67- router . beforeEach ( ( route , redirect , next ) => {
68- if ( state . device . isMobile && state . sidebar . opened ) {
69- store . commit ( types . TOGGLE_SIDEBAR , false )
70- }
71- if ( ! auth . loggedIn ( ) && route . path !== '/login' ) {
72- next ( {
73- path : '/login' ,
74- query : { redirect : route . fullPath }
75- } )
76- } else {
77- next ( )
78- }
79- } )
80-
81- axios . interceptors . response . use (
82- response => {
83- if ( response . data && response . data . code ) {
84- if ( response . data . code === '2001' ) {
85- auth . logout ( )
86- }
87- }
88- return response ;
89- } ,
90- error => {
91- if ( error . response ) {
92- //全局ajax错误信息提示
93- Element . MessageBox ( { type :"error" , message :error . response . data , title :"温馨提示" } ) ;
94- }
95- return Promise . reject ( error ) ;
96- } ) ;
97-
9834
9935Object . keys ( filters ) . forEach ( key => {
10036 Vue . filter ( key , filters [ key ] )
0 commit comments