chengdu
yujialong 4 years ago
parent 2bbae985fe
commit e1b82ec8a5
  1. BIN
      src.rar
  2. 1
      src/components/page/ClientLogin.vue
  3. 12
      src/components/page/Login.vue
  4. 4
      src/store/index.js
  5. 34
      src/utils/http.js

Binary file not shown.

@ -207,6 +207,7 @@ export default {
this.studentId = this.schoolList[0].studentId this.studentId = this.schoolList[0].studentId
// this.getRole() // this.getRole()
this.roleId = 4 this.roleId = 4
this.$store.commit("tokenData", {loginToken: res.message.loginToken})
this.submitForm(form) this.submitForm(form)
}else{ }else{
this.$message.error('账号不存在') this.$message.error('账号不存在')

@ -110,11 +110,17 @@ export default {
this.$store.commit("dataTime", { dataTime : res.message.user.dataTime}); this.$store.commit("dataTime", { dataTime : res.message.user.dataTime});
this.loadIns.close() this.loadIns.close()
this.$router.replace('/dashboard') 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()
})
} }
} }
} }

@ -22,6 +22,7 @@ const store = new Vuex.Store({
accountRole: '', accountRole: '',
userName:'', userName:'',
token: '', token: '',
loginToken: '',
avatar:'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png', avatar:'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png',
courseId:'', courseId:'',
assesmentId: '', assesmentId: '',
@ -84,6 +85,9 @@ const store = new Vuex.Store({
state.schoolId = payload.schoolId state.schoolId = payload.schoolId
state.token = payload.token state.token = payload.token
}, },
tokenData (state, payload) {
state.loginToken = payload.loginToken
},
assesmentData (state, payload) { assesmentData (state, payload) {
state.assesmentId = payload.assesmentId state.assesmentId = payload.assesmentId
}, },

@ -23,7 +23,7 @@ axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';
// 请求拦截器 // 请求拦截器
axios.interceptors.request.use(config => { axios.interceptors.request.use(config => {
let token = store.state.token let token = store.state.loginToken
if(token){ if(token){
config.headers.token = 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请求 * get方法对应get请求
*/ */
@ -129,6 +140,11 @@ export function get(url, params){
params: params params: params
}) })
.then(res => { .then(res => {
if(typeof res.data == 'number'){
this.$message.error(tokenStatus[res.data])
setTimeout(logouts,1500)
return false
}
if(res.data.code == 99999){ if(res.data.code == 99999){
this.$message.error( this.$message.error(
res.data.message res.data.message
@ -149,6 +165,7 @@ export function get(url, params){
this.$message.error( this.$message.error(
res.data.errmessage res.data.errmessage
); );
reject(res.data)
break; break;
case 500: case 500:
this.$message.error( this.$message.error(
@ -209,6 +226,11 @@ export function post(url, params) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.post(url,params) axios.post(url,params)
.then(res => { .then(res => {
if(typeof res.data == 'number'){
this.$message.error(tokenStatus[res.data])
setTimeout(logouts,1500)
return false
}
if(res.data.code == 99999){ if(res.data.code == 99999){
this.$message.error( this.$message.error(
res.data.message res.data.message
@ -284,6 +306,11 @@ export function post(url, params) {
params: params params: params
}) })
.then(res => { .then(res => {
if(typeof res.data == 'number'){
this.$message.error(tokenStatus[res.data])
setTimeout(logouts,1500)
return false
}
if(res.data.code == 99999){ if(res.data.code == 99999){
this.$message.error( this.$message.error(
res.data.message res.data.message
@ -357,6 +384,11 @@ export function put(url, params){
return new Promise((resolve, reject) =>{ return new Promise((resolve, reject) =>{
axios.put(url, params) axios.put(url, params)
.then(res => { .then(res => {
if(typeof res.data == 'number'){
this.$message.error(tokenStatus[res.data])
setTimeout(logouts,1500)
return false
}
if(res.data.code == 99999){ if(res.data.code == 99999){
this.$message.error( this.$message.error(
res.data.message res.data.message

Loading…
Cancel
Save