diff --git a/src/components/page/Configure.vue b/src/components/page/Configure.vue index 4c3be34..5e709e5 100644 --- a/src/components/page/Configure.vue +++ b/src/components/page/Configure.vue @@ -145,7 +145,7 @@ export default { }, getIntoProject(row){ window.location.href = `http://39.108.250.202/Projectmanagement/#/?userId=${this.userId}&systemId=${row.systemId}&systemName=${row.systemName}` - // window.location.href = `http://192.168.31.154:8081/#/?userId=${this.userId}&systemId=${row.systemId}&systemName=${row.systemName}` + // window.location.href = `http://192.168.31.154:8083/#/?userId=${this.userId}&systemId=${row.systemId}&systemName=${row.systemName}` }, getIntoJudgement(row){ this.setCookie("userId",this.userId) diff --git a/src/components/page/Login.vue b/src/components/page/Login.vue index 016d058..a67a092 100644 --- a/src/components/page/Login.vue +++ b/src/components/page/Login.vue @@ -66,6 +66,7 @@ export default { this.$message.success('登录成功'); localStorage.setItem('ms_username', this.param.username); this.$store.commit("userLoginData", { userLogin_id : res.message.retvalue.userId}); + this.$store.commit("tokenData", {loginToken: res.message.retvalue.loginToken}) this.$router.push('/dashboard'); }else{ this.$message.error('该用户没有权限'); diff --git a/src/store/index.js b/src/store/index.js index 928046e..3f87e58 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -12,7 +12,8 @@ const store = new Vuex.Store({ configId: '', systemId: '', orderId: '', - userLoginId: '' + userLoginId: '', + loginToken: '' }, mutations:{ userData (state, payload) { @@ -39,7 +40,10 @@ const store = new Vuex.Store({ }, userLoginData (state, payload) { state.userLoginId = payload.userLogin_id - } + }, + tokenData (state, payload) { + state.loginToken = payload.loginToken + }, } }); diff --git a/src/utils/http.js b/src/utils/http.js index c9154a3..4b58f4b 100644 --- a/src/utils/http.js +++ b/src/utils/http.js @@ -1,6 +1,6 @@ import axios from 'axios'; import QS from 'qs'; -// import store from '../store/index' +import store from '../store/index' import { Message } from 'element-ui' import router from '../router/index' @@ -20,21 +20,21 @@ axios.defaults.timeout = 30000; axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; // 请求拦截器 - // axios.interceptors.request.use(config => { - // if (sessionStorage.getItem('token')) { - // // 存在将token写入 request header - // config.headers.Authorization = `${sessionStorage.getItem('token')}`; - // } - // return config; - // }, err => { - // Message.error({ - // message: '退出登陆', - // onClose: function () { - // router.push({name: 'login'}); - // } - // }) - // return Promise.reject(err); - // }) +axios.interceptors.request.use(config => { + let token = store.state.loginToken + if(token){ + config.headers.token = token + } + return config; + }, err => { + Message.error({ + message: '退出登陆', + onClose: function () { + router.push({name: 'login'}); + } + }) + return Promise.reject(err); +}) // 响应拦截器 // axios.interceptors.response.use( @@ -99,6 +99,17 @@ axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; // } // ); + +function logouts(){ + store.replaceState({}) + localStorage.removeItem('ms_username') + location.reload() +} + +let tokenStatus = { + 0: '用户未登录,请登录后操作!', + 1: 'token错误,请重新登录!' +} /** * get方法,对应get请求 */ @@ -108,6 +119,11 @@ export function get(url, params){ params: params }) .then(res => { + if(typeof res.data == 'number'){ + this.$message.error(tokenStatus[res.data]) + setTimeout(logouts,1500) + return false + } if (res.data.status) { switch (res.data.status) { case 200: