diff --git a/src/components/page/ClientLogin.vue b/src/components/page/ClientLogin.vue index fa1b43a..b657a5d 100644 --- a/src/components/page/ClientLogin.vue +++ b/src/components/page/ClientLogin.vue @@ -207,6 +207,7 @@ export default { this.studentId = this.schoolList[0].studentId // this.getRole() this.roleId = 4 + this.$store.commit("tokenData", {loginToken: res.message.loginToken}) this.submitForm(form) }else{ this.$message.error('账号不存在') @@ -283,7 +284,7 @@ export default { this.$post(this.api.updateLogInNumber,{userId: this.userId}).then(res => {}).catch(res => {}); this.$message.success('登录成功'); sessionStorage.setItem('kd_client_username', this.activeName == '0' ? this.loginForm.username : this.phoneParam.userphone); - this.$store.commit("userLoginData", { userId : this.userId,accountRole: this.roleId,studentId : this.studentId,schoolId: this.schoolId,token: res.message.user.token}); + this.$store.commit("userLoginData", { userId : this.userId,accountRole: this.roleId,studentId : this.studentId,schoolId: this.schoolId,token: res.message.user.token}) res.message.user.userAvatars && this.$store.commit("userPhoto", { avatar : res.message.user.userAvatars}); this.$store.commit("userName", { userName : res.message.user.userName}); this.$store.commit("dataTime", { dataTime : res.message.user.dataTime}); diff --git a/src/store/index.js b/src/store/index.js index 06ebff1..c351c54 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -21,6 +21,7 @@ const store = new Vuex.Store({ userId: '', accountRole: '', userName:'', + loginToken: '', token: '', avatar:'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png', courseId:'', @@ -87,6 +88,9 @@ const store = new Vuex.Store({ state.schoolId = payload.schoolId state.token = payload.token }, + tokenData (state, payload) { + state.loginToken = payload.loginToken + }, assesmentData (state, payload) { state.assesmentId = payload.assesmentId }, diff --git a/src/utils/http.js b/src/utils/http.js index 4555056..c7e62f8 100644 --- a/src/utils/http.js +++ b/src/utils/http.js @@ -23,7 +23,7 @@ axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; // 请求拦截器 axios.interceptors.request.use(config => { - let token = store.state.token + let token = store.state.loginToken if(token){ config.headers.token = token } @@ -126,6 +126,16 @@ export function getToken(){ } } +function logouts(){ + store.replaceState({}) + sessionStorage.removeItem('kd_client_username') + location.reload() +} + +let tokenStatus = { + 0: '用户未登录,请登录后操作!', + 1: 'token错误,请重新登录!' +} /** * get方法,对应get请求 */ @@ -136,6 +146,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.code == 99999){ this.$message.error( res.data.message @@ -216,6 +231,11 @@ export function post(url, params) { return new Promise((resolve, reject) => { axios.post(url,params) .then(res => { + if(typeof res.data == 'number'){ + this.$message.error(tokenStatus[res.data]) + setTimeout(logouts,1500) + return false + } if(res.data.code == 99999){ this.$message.error( res.data.message @@ -291,6 +311,11 @@ export function post(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.code == 99999){ this.$message.error( res.data.message @@ -364,6 +389,11 @@ export function put(url, params){ return new Promise((resolve, reject) =>{ axios.put(url, params) .then(res => { + if(typeof res.data == 'number'){ + this.$message.error(tokenStatus[res.data]) + setTimeout(logouts,1500) + return false + } if(res.data.code == 99999){ this.$message.error( res.data.message