chengdu
yujialong 4 years ago
parent 64d5e6ffbe
commit 2e2553d969
  1. 3
      src/components/page/ClientLogin.vue
  2. 4
      src/store/index.js
  3. 32
      src/utils/http.js

@ -224,6 +224,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('账号不存在')
@ -300,7 +301,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});

@ -21,6 +21,7 @@ const store = new Vuex.Store({
userId: '',
accountRole: '',
userName:'',
loginToken: '',
token: '',
avatar:'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png',
courseId:'',
@ -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
},

@ -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,16 @@ export function getToken(){
}
}
function logouts(){
store.replaceState({})
sessionStorage.removeItem('kd_client_username')
location.reload()
}
let tokenStatus = {
0: '用户未登录,请登录后操作!',
1: 'token错误,请重新登录!'
}
/**
* get方法对应get请求
*/
@ -129,6 +139,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
@ -209,6 +224,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 +304,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 +382,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

Loading…
Cancel
Save