From dca74c76b85c5ece7b87beae9d9f921883b55564 Mon Sep 17 00:00:00 2001 From: zhangyanpeng <bob.zhang@highdatas.com> Date: 星期四, 07 五月 2020 14:45:39 +0800 Subject: [PATCH] 调整cookies --- src/main.ts | 62 ++++++++++++++++++++---------- 1 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/main.ts b/src/main.ts index e7612ac..8002fc4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,5 @@ import Vue from "vue"; import App from "./App.vue"; -import axios from 'axios' import "./registerServiceWorker"; import router from "./router"; @@ -8,16 +7,37 @@ import ElementUI from "element-ui"; import "element-ui/lib/theme-chalk/index.css"; import Axios from 'axios'; +//npm i moment --save +import moment from 'moment'; +import echarts from 'echarts' +import VueCookies from 'vue-cookies' +Vue.prototype.$echarts = echarts Vue.use(ElementUI); +Vue.prototype.$moment = moment;//璧嬪�间娇鐢� +Vue.use(VueCookies); Vue.config.productionTip = false; Vue.prototype.$axios = Axios; Axios.defaults.baseURL = '/api'; Axios.defaults.headers.post['Content-Type'] = 'application/json'; -Vue.prototype.axios = axios; +/* Axios.interceptors.request.use( + config => { + let userId_ = localStorage.getItem('userId'); + if (!userId_) { // + router.replace({ + path: 'login', + + }) + } + return config; + }, + err => { + return Promise.reject(err); + }); */ + new Vue({ router, @@ -25,23 +45,23 @@ render: h => h(App) }).$mount("#app"); -//鏃ユ湡鏍煎紡鍖� -Date.prototype.Format = function(fmt){ - var o = { - "M+": this.getMonth() + 1, - "d+": this.getDate(), - "H+": this.getHours(), - "m+": this.getMinutes(), - "s+": this.getSeconds(), - "S+": this.getMilliseconds() - }; - if(/(y+)/.test(fmt)){ - fmt=fmt.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length)); + +Axios.interceptors.request.use(function (config) { + // let userId_ = localStorage.getItem('userId'); + if(config.url == "/api/user/login") { + + } + else { + //let userId_ = Vue.VueCookies.get('userId');//localStorage.getItem('userId'); + let userId_ = Vue.$cookies.get('userId');//localStorage.getItem('userId'); + if (!userId_ && config.url != "/api/user/login") { + router.replace('/login'); } - for(var k in o){ - if (new RegExp("(" + k +")").test(fmt)){ - fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(String(o[k]).length))); - } - } - return fmt; -}; + config.headers.common['userId'] = userId_; + } + return config; +}, function (error) { + // console.info("error: "); + // console.info(error); + return Promise.reject(error); +}); \ No newline at end of file -- Gitblit v1.8.0