pull/19/head^2
parent
4cda1a53c6
commit
4acef527e7
3 changed files with 92 additions and 89 deletions
@ -1,40 +1,45 @@ |
|||||||
const getDefaultState = () => { |
const getDefaultState = () => { |
||||||
return { |
return { |
||||||
name: "admin", |
name: 'admin', |
||||||
avatar: "", |
avatar: '', |
||||||
auth: null, |
auth: null, |
||||||
companyType: 0, |
companyType: 0, |
||||||
companyId: "", |
companyId: '' |
||||||
}; |
} |
||||||
}; |
} |
||||||
|
|
||||||
const state = getDefaultState(); |
const state = getDefaultState() |
||||||
|
|
||||||
const mutations = { |
const mutations = { |
||||||
SET_NAME: (state, name) => { |
SET_NAME: (state, name) => { |
||||||
state.name = name; |
state.name = name |
||||||
}, |
}, |
||||||
SET_AUTH: (state, auth) => { |
SET_AUTH: (state, auth) => { |
||||||
state.auth = auth; |
state.auth = auth |
||||||
}, |
}, |
||||||
SET_COMPANYTYPE: (state, data) => { |
SET_COMPANYTYPE: (state, data) => { |
||||||
//chainParentMark 1:总公司 0:分公司
|
//chainParentMark 1:总公司 0:分公司
|
||||||
state.companyType = data.chainParentMark; |
state.companyType = data.chainParentMark |
||||||
state.companyId = data.userCompany; |
state.companyId = data.userCompany |
||||||
}, |
} |
||||||
}; |
} |
||||||
|
|
||||||
const actions = { |
const actions = { |
||||||
info({ commit }, data) { |
info({ commit }, data) { |
||||||
commit("SET_AUTH", data.authList); |
commit('SET_AUTH', data.authList) |
||||||
commit("SET_NAME", data.name); |
commit('SET_NAME', data.name) |
||||||
commit("SET_COMPANYTYPE", data); |
commit('SET_COMPANYTYPE', data) |
||||||
}, |
}, |
||||||
}; |
removeInfo({ commit }) { |
||||||
|
commit('SET_AUTH', null) |
||||||
|
commit('SET_NAME', '') |
||||||
|
commit('SET_COMPANYTYPE', 0) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
export default { |
export default { |
||||||
namespaced: true, |
namespaced: true, |
||||||
state, |
state, |
||||||
mutations, |
mutations, |
||||||
actions, |
actions |
||||||
}; |
} |
||||||
|
@ -1,89 +1,89 @@ |
|||||||
import Vue from "vue"; |
import Vue from 'vue' |
||||||
import axios from "axios"; |
import axios from 'axios' |
||||||
import utils from "@/utils/encode"; |
import utils from '@/utils/encode' |
||||||
//加密白名单
|
//加密白名单
|
||||||
const encryptWhite = []; |
const encryptWhite = [] |
||||||
const env = process.env.VUE_APP_ENV; |
const env = process.env.VUE_APP_ENV |
||||||
|
|
||||||
const service = axios.create({ |
const service = axios.create({ |
||||||
baseURL: process.env.VUE_APP_BASE_API, |
baseURL: process.env.VUE_APP_BASE_API, |
||||||
timeout: 20000, |
timeout: 20000 |
||||||
}); |
}) |
||||||
// 请求拦截
|
// 请求拦截
|
||||||
service.interceptors.request.use( |
service.interceptors.request.use( |
||||||
(config) => { |
config => { |
||||||
let token = localStorage.getItem("businessToken"); |
let token = localStorage.getItem('businessToken') |
||||||
|
|
||||||
if (token) { |
if (token) { |
||||||
config.headers["Authorization"] = token; |
config.headers['Authorization'] = token |
||||||
} else delete config.headers["Authorization"]; |
} else delete config.headers['Authorization'] |
||||||
|
|
||||||
const JSESSIONID = utils.uuid(); |
const JSESSIONID = utils.uuid() |
||||||
config.headers["JSESSIONID"] = JSESSIONID; |
config.headers['JSESSIONID'] = JSESSIONID |
||||||
config.headers["token"] = utils.bcrypt(JSESSIONID); |
config.headers['token'] = utils.bcrypt(JSESSIONID) |
||||||
config.headers['dataSources'] = 'WEB' |
config.headers['dataSources'] = 'WEB' |
||||||
if (env === "development") { |
if (env === 'development') { |
||||||
return config; |
return config |
||||||
} |
} |
||||||
if (env === "production" || ebv === "test") { |
if (env === 'production' || env === 'test') { |
||||||
//加密
|
//加密
|
||||||
config.data = { |
config.data = { |
||||||
params: utils.encrypt(JSON.stringify(config.data)), |
params: utils.encrypt(JSON.stringify(config.data)) |
||||||
}; |
} |
||||||
} |
} |
||||||
|
|
||||||
if (config.responseType === "blob" && !encryptWhite.includes(config.url)) { |
// if (config.responseType === 'blob' && !encryptWhite.includes(config.url)) {
|
||||||
const data = { |
// const data = {
|
||||||
params: utils.encrypt(JSON.stringify(config.data)), |
// params: utils.encrypt(JSON.stringify(config.data))
|
||||||
}; |
// }
|
||||||
config.data = data; |
// config.data = data
|
||||||
} |
// }
|
||||||
return config; |
return config |
||||||
}, |
}, |
||||||
(error) => { |
error => { |
||||||
console.log("axios request error:", error); |
console.log('axios request error:', error) |
||||||
return Promise.reject(); |
return Promise.reject() |
||||||
} |
} |
||||||
); |
) |
||||||
// 响应拦截
|
// 响应拦截
|
||||||
service.interceptors.response.use( |
service.interceptors.response.use( |
||||||
(response) => { |
response => { |
||||||
const res = response.data; |
const res = response.data |
||||||
const contentType = response.headers["content-type"]; |
const contentType = response.headers['content-type'] |
||||||
//流文件
|
//流文件
|
||||||
if (!contentType.includes("application/json")) return res; |
if (!contentType.includes('application/json')) return res |
||||||
|
|
||||||
if (env === "production" || env === "test") { |
if (env === 'production' || env === 'test') { |
||||||
if (res.encrypt === 1) { |
if (res.encrypt === 1) { |
||||||
const dataParam = JSON.parse(utils.decrypt(res.data)); |
const dataParam = JSON.parse(utils.decrypt(res.data)) |
||||||
res.data = JSON.stringify(dataParam) === "{}" ? null : dataParam; |
res.data = JSON.stringify(dataParam) === '{}' ? null : dataParam |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
if (res && res.code) { |
if (res && res.code) { |
||||||
if (res.code === 42011) { |
if (res.code === 42011) { |
||||||
Vue.prototype.$message.error(res.msg || "您的登录已失效,请重新登录"); |
Vue.prototype.$message.error(res.msg || '您的登录已失效,请重新登录') |
||||||
localStorage.removeItem("businessToken"); |
localStorage.removeItem('businessToken') |
||||||
setTimeout(() => { |
setTimeout(() => { |
||||||
window.location.reload(); |
window.location.reload() |
||||||
}, 1000); |
}, 1000) |
||||||
return; |
return |
||||||
} |
} |
||||||
// 白名单
|
// 白名单
|
||||||
if (![20000, 42014, 46001].includes(res.code)) { |
if (![20000, 42014, 46001].includes(res.code)) { |
||||||
console.log("code码:" + res.code); |
console.log('code码:' + res.code) |
||||||
Vue.prototype.$message.error(res.msg); |
Vue.prototype.$message.error(res.msg) |
||||||
return Promise.reject(); |
return Promise.reject() |
||||||
} else { |
} else { |
||||||
return res; |
return res |
||||||
} |
} |
||||||
} |
} |
||||||
}, |
}, |
||||||
(error) => { |
error => { |
||||||
Vue.prototype.$message.error("请求失败"); |
Vue.prototype.$message.error('请求失败') |
||||||
console.log("axios response error:", error); |
console.log('axios response error:', error) |
||||||
return Promise.reject(error); |
return Promise.reject(error) |
||||||
} |
} |
||||||
); |
) |
||||||
|
|
||||||
export default service; |
export default service |
||||||
|
Loading…
Reference in new issue