diff --git a/src.rar b/src.rar deleted file mode 100644 index c7ce100..0000000 Binary files a/src.rar and /dev/null differ diff --git a/src/components/page/ClientLogin.vue b/src/components/page/ClientLogin.vue index fa1b43a..0c6a122 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('账号不存在') diff --git a/src/components/page/Login.vue b/src/components/page/Login.vue index 4275ccf..bc2804c 100644 --- a/src/components/page/Login.vue +++ b/src/components/page/Login.vue @@ -110,11 +110,17 @@ export default { this.$store.commit("dataTime", { dataTime : res.message.user.dataTime}); this.loadIns.close() this.$router.replace('/dashboard') - }).catch(res => {}) + }).catch(res => { + this.loadIns.close() + }) } } - }).catch(res => {}) - }).catch(res => {}) + }).catch(res => { + this.loadIns.close() + }) + }).catch(res => { + this.loadIns.close() + }) } } } diff --git a/src/store/index.js b/src/store/index.js index 09c4d01..c4ee321 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -22,6 +22,7 @@ const store = new Vuex.Store({ accountRole: '', userName:'', token: '', + loginToken: '', avatar:'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png', courseId:'', assesmentId: '', @@ -84,6 +85,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 43adbac..fbc3bf1 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 } @@ -119,6 +119,17 @@ export function getToken(){ } } +function logouts(){ + store.replaceState({}) + sessionStorage.removeItem('kd_client_username') + location.reload() +} + +let tokenStatus = { + 0: '用户未登录,请登录后操作!', + 1: 'token错误,请重新登录!' +} + /** * get方法,对应get请求 */ @@ -129,6 +140,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 @@ -149,6 +165,7 @@ export function get(url, params){ this.$message.error( res.data.errmessage ); + reject(res.data) break; case 500: this.$message.error( @@ -209,6 +226,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 @@ -284,6 +306,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 @@ -357,6 +384,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