master
yujialong 4 years ago
parent 6607dd287b
commit 4745552933
  1. 1
      src/components/page/Login.vue
  2. 4
      src/store/index.js
  3. 31
      src/utils/http.js

@ -103,6 +103,7 @@ export default {
sessionStorage.setItem('kd_server_username', this.activeName == '0' ? this.param.username : this.phoneParam.userphone); sessionStorage.setItem('kd_server_username', this.activeName == '0' ? this.param.username : this.phoneParam.userphone);
res.message.retvalue.userAvatars && this.$store.commit("userPhoto", { avatar : res.message.retvalue.userAvatars}) res.message.retvalue.userAvatars && this.$store.commit("userPhoto", { avatar : res.message.retvalue.userAvatars})
this.$store.commit("dataTime", { dataTime : res.message.retvalue.dataTime}); this.$store.commit("dataTime", { dataTime : res.message.retvalue.dataTime});
this.$store.commit("tokenData", {loginToken: data.loginToken})
this.$store.commit("userLoginData", { userLogin_id : data.userId,userRole_id: data.roleId,schoolId: data.schoolId,token: data.token,userName: data.userName}); this.$store.commit("userLoginData", { userLogin_id : data.userId,userRole_id: data.roleId,schoolId: data.schoolId,token: data.token,userName: data.userName});
let redirect = decodeURIComponent(this.$route.query.redirect || '/dashboard') let redirect = decodeURIComponent(this.$route.query.redirect || '/dashboard')

@ -22,6 +22,7 @@ const store = new Vuex.Store({
id: '', id: '',
name: '' name: ''
}, },
loginToken: '',
token: '', token: '',
userName: '', userName: '',
routes: [], routes: [],
@ -65,6 +66,9 @@ const store = new Vuex.Store({
state.token = payload.token state.token = payload.token
state.userName = payload.userName state.userName = payload.userName
}, },
tokenData (state, payload) {
state.loginToken = payload.loginToken
},
addClassData (state, payload) { addClassData (state, payload) {
state.addClass = payload.addClass state.addClass = payload.addClass
}, },

@ -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
} }
@ -124,6 +124,10 @@ export function getToken(){
} }
} }
let tokenStatus = {
0: '用户未登录,请登录后操作!',
1: 'token错误,请重新登录!'
}
/** /**
* get方法对应get请求 * get方法对应get请求
*/ */
@ -134,6 +138,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
@ -228,6 +237,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
@ -325,6 +339,11 @@ export function post(url, params) {
return new Promise((resolve, reject) =>{ return new Promise((resolve, reject) =>{
axios.delete(url, {params}) axios.delete(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
@ -408,6 +427,11 @@ export function delbody(url, params){
return new Promise((resolve, reject) =>{ return new Promise((resolve, reject) =>{
axios.delete(url, {data: params}) axios.delete(url, {data: 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
@ -496,6 +520,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