mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-11 03:46:44 +08:00
Merge branch '20251121-fix-1298' of https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal into 20251121-fix-1298
This commit is contained in:
@@ -19,215 +19,255 @@ import errorCode from '@/utils/errorCode'
|
|||||||
|
|
||||||
//const ReLoginUrl="/login";
|
//const ReLoginUrl="/login";
|
||||||
|
|
||||||
const ReLoginUrl=process.env.VUE_APP_LOGIN_URL;
|
const ReLoginUrl = process.env.VUE_APP_LOGIN_URL;
|
||||||
|
|
||||||
const TokenName='XBOE-Access-Token';
|
const TokenName = 'XBOE-Access-Token';
|
||||||
/**axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded'**/
|
/**axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded'**/
|
||||||
//只是用于发送json对象数据时使用post,put,patch
|
//只是用于发送json对象数据时使用post,put,patch
|
||||||
const jsonRequest=axios.create({
|
const jsonRequest = axios.create({
|
||||||
headers:{'Content-Type':'application/json;charset=utf-8'},
|
headers: { 'Content-Type': 'application/json;charset=utf-8' },
|
||||||
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
||||||
baseURL: process.env.VUE_APP_BASE_API,
|
baseURL: process.env.VUE_APP_BASE_API,
|
||||||
//超时
|
//超时
|
||||||
timeout: 60000,
|
timeout: 60000,
|
||||||
});
|
});
|
||||||
//发送json对象的拦截器
|
//发送json对象的拦截器
|
||||||
jsonRequest.interceptors.request.use(config => {
|
jsonRequest.interceptors.request.use(config => {
|
||||||
//是否需要设置 token
|
//是否需要设置 token
|
||||||
const isToken = (config.headers || {}).isToken === false
|
const isToken = (config.headers || {}).isToken === false
|
||||||
if (getToken() && !isToken) {
|
if (getToken() && !isToken) {
|
||||||
config.headers[TokenName] = getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
config.headers[TokenName] = getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
}, error => {
|
}, error => {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
Promise.reject(error)
|
Promise.reject(error)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 响应拦截器
|
// 响应拦截器
|
||||||
jsonRequest.interceptors.response.use(res => {
|
jsonRequest.interceptors.response.use(res => {
|
||||||
|
|
||||||
const code = res.data.status || 200;
|
const code = res.data.status || 200;
|
||||||
if(code===200){
|
if (code === 200) {
|
||||||
return res.data
|
return res.data
|
||||||
}else{
|
} else {
|
||||||
if(code == 6001){ //针对于老系统的处理
|
if (code == 6001) { //针对于老系统的处理
|
||||||
store.dispatch('LogOut').then(() => {
|
store.dispatch('LogOut').then(() => {
|
||||||
location.href = ReLoginUrl;
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
})
|
top.location.href = ReLoginUrl;
|
||||||
}else if(code === 401){
|
} else {
|
||||||
store.dispatch('LogOut').then(() => {
|
window.location.href = ReLoginUrl;
|
||||||
location.href = ReLoginUrl;
|
}
|
||||||
})
|
// location.href = ReLoginUrl;
|
||||||
}else if(code === 402){
|
})
|
||||||
store.dispatch('LogOut').then(() => {
|
} else if (code === 401) {
|
||||||
location.href = ReLoginUrl;
|
store.dispatch('LogOut').then(() => {
|
||||||
})
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
}else if(code===403){
|
top.location.href = ReLoginUrl;
|
||||||
var msg='当前操作没有权限';
|
} else {
|
||||||
Message({message: msg, type: 'error'});
|
window.location.href = ReLoginUrl;
|
||||||
return Promise.reject(new Error(msg))
|
}
|
||||||
//return res.data;
|
// location.href = ReLoginUrl;
|
||||||
}else if(code===302){
|
})
|
||||||
location.href = ReLoginUrl;
|
} else if (code === 402) {
|
||||||
}else{
|
store.dispatch('LogOut').then(() => {
|
||||||
//Message({message: res.data.message, type: 'error'});
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
//console.log('err:' + res.data.error);
|
top.location.href = ReLoginUrl;
|
||||||
//return Promise.reject(new Error(res.data.message))
|
} else {
|
||||||
return res.data;
|
window.location.href = ReLoginUrl;
|
||||||
|
}
|
||||||
|
// location.href = ReLoginUrl;
|
||||||
|
})
|
||||||
|
} else if (code === 403) {
|
||||||
|
var msg = '当前操作没有权限';
|
||||||
|
Message({ message: msg, type: 'error' });
|
||||||
|
return Promise.reject(new Error(msg))
|
||||||
|
//return res.data;
|
||||||
|
} else if (code === 302) {
|
||||||
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
|
top.location.href = ReLoginUrl;
|
||||||
|
} else {
|
||||||
|
window.location.href = ReLoginUrl;
|
||||||
}
|
}
|
||||||
}
|
// location.href = ReLoginUrl;
|
||||||
},
|
} else {
|
||||||
error => {
|
//Message({message: res.data.message, type: 'error'});
|
||||||
console.log('err' + error)
|
//console.log('err:' + res.data.error);
|
||||||
let { message } = error;
|
//return Promise.reject(new Error(res.data.message))
|
||||||
if (message == "Network Error") {
|
return res.data;
|
||||||
message = "网络异常,请稍后重试";
|
}
|
||||||
}
|
}
|
||||||
else if (message.includes("timeout")) {
|
},
|
||||||
message = "系统接口请求超时";
|
error => {
|
||||||
//location.href = this.webBaseUrl + ReLoginUrl;
|
console.log('err' + error)
|
||||||
}
|
let { message } = error;
|
||||||
else if (message.includes("Request failed with status code")) {
|
if (message == "Network Error") {
|
||||||
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
message = "网络异常,请稍后重试";
|
||||||
}
|
}
|
||||||
Message({
|
else if (message.includes("timeout")) {
|
||||||
message: message,
|
message = "系统接口请求超时";
|
||||||
type: 'error',
|
//location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
duration: 5 * 1000
|
}
|
||||||
})
|
else if (message.includes("Request failed with status code")) {
|
||||||
return Promise.reject(error)
|
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
||||||
}
|
}
|
||||||
|
Message({
|
||||||
|
message: message,
|
||||||
|
type: 'error',
|
||||||
|
duration: 5 * 1000
|
||||||
|
})
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
//用于普通的发送请求
|
//用于普通的发送请求
|
||||||
const formRequest=axios.create({
|
const formRequest = axios.create({
|
||||||
headers:{'Content-Type':'application/x-www-form-urlencoded'},
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
||||||
baseURL: process.env.VUE_APP_BASE_API,
|
baseURL: process.env.VUE_APP_BASE_API,
|
||||||
//超时
|
//超时
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
})
|
})
|
||||||
//发送json对象的拦截器
|
//发送json对象的拦截器
|
||||||
formRequest.interceptors.request.use(config => {
|
formRequest.interceptors.request.use(config => {
|
||||||
//是否需要设置 token
|
//是否需要设置 token
|
||||||
const isToken = (config.headers || {}).isToken === false
|
const isToken = (config.headers || {}).isToken === false
|
||||||
if (getToken() && !isToken) {
|
if (getToken() && !isToken) {
|
||||||
config.headers[TokenName] = getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
config.headers[TokenName] = getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
}, error => {
|
}, error => {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
Promise.reject(error)
|
Promise.reject(error)
|
||||||
});
|
});
|
||||||
formRequest.interceptors.response.use(res => {
|
formRequest.interceptors.response.use(res => {
|
||||||
const code = res.data.status || 200;
|
const code = res.data.status || 200;
|
||||||
if(code===200){
|
if (code === 200) {
|
||||||
return res.data
|
return res.data
|
||||||
}else{
|
} else {
|
||||||
if(code == 6001){ //针对于老系统的处理,因为老系统是字符串,所以这里不使用三等于号
|
if (code == 6001) { //针对于老系统的处理,因为老系统是字符串,所以这里不使用三等于号
|
||||||
store.dispatch('LogOut').then(() => {
|
store.dispatch('LogOut').then(() => {
|
||||||
location.href = ReLoginUrl;
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
})
|
top.location.href = ReLoginUrl;
|
||||||
}else if(code === 401){
|
} else {
|
||||||
store.dispatch('LogOut').then(() => {
|
window.location.href = ReLoginUrl;
|
||||||
location.href = ReLoginUrl;
|
}
|
||||||
})
|
// location.href = ReLoginUrl;
|
||||||
}else if(code === 402){
|
})
|
||||||
store.dispatch('LogOut').then(() => {
|
} else if (code === 401) {
|
||||||
location.href = ReLoginUrl;
|
store.dispatch('LogOut').then(() => {
|
||||||
})
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
}else if(code===403){
|
top.location.href = ReLoginUrl;
|
||||||
var msg='当前操作没有权限';
|
} else {
|
||||||
Message({message: msg, type: 'error'});
|
window.location.href = ReLoginUrl;
|
||||||
return Promise.reject(new Error(msg))
|
}
|
||||||
}else if(code===302){
|
// location.href = ReLoginUrl;
|
||||||
location.href = ReLoginUrl;
|
})
|
||||||
}else{
|
} else if (code === 402) {
|
||||||
//Message({message: res.data.message, type: 'error'});
|
store.dispatch('LogOut').then(() => {
|
||||||
//console.log('err' + res.data.error);
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
//return Promise.reject(new Error(res.data.message))
|
top.location.href = ReLoginUrl;
|
||||||
return res.data;//返回给用户做业务处理
|
} else {
|
||||||
|
window.location.href = ReLoginUrl;
|
||||||
|
}
|
||||||
|
// location.href = ReLoginUrl;
|
||||||
|
})
|
||||||
|
} else if (code === 403) {
|
||||||
|
var msg = '当前操作没有权限';
|
||||||
|
Message({ message: msg, type: 'error' });
|
||||||
|
return Promise.reject(new Error(msg))
|
||||||
|
} else if (code === 302) {
|
||||||
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
|
top.location.href = ReLoginUrl;
|
||||||
|
} else {
|
||||||
|
window.location.href = ReLoginUrl;
|
||||||
}
|
}
|
||||||
}
|
// location.href = ReLoginUrl;
|
||||||
},
|
} else {
|
||||||
error => {
|
//Message({message: res.data.message, type: 'error'});
|
||||||
console.log('err' + error)
|
//console.log('err' + res.data.error);
|
||||||
let { message } = error;
|
//return Promise.reject(new Error(res.data.message))
|
||||||
if (message == "Network Error") {
|
return res.data;//返回给用户做业务处理
|
||||||
message = "网络异常,请稍后重试";
|
}
|
||||||
}
|
}
|
||||||
else if (message.includes("timeout")) {
|
},
|
||||||
message = "系统接口请求超时";
|
error => {
|
||||||
//location.href = this.webBaseUrl + ReLoginUrl;
|
console.log('err' + error)
|
||||||
}
|
let { message } = error;
|
||||||
else if (message.includes("Request failed with status code")) {
|
if (message == "Network Error") {
|
||||||
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
message = "网络异常,请稍后重试";
|
||||||
}
|
}
|
||||||
Message({
|
else if (message.includes("timeout")) {
|
||||||
message: message,
|
message = "系统接口请求超时";
|
||||||
type: 'error',
|
//location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
duration: 5 * 1000
|
}
|
||||||
})
|
else if (message.includes("Request failed with status code")) {
|
||||||
return Promise.reject(error)
|
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
||||||
}
|
}
|
||||||
|
Message({
|
||||||
|
message: message,
|
||||||
|
type: 'error',
|
||||||
|
duration: 5 * 1000
|
||||||
|
})
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
//request请求
|
//request请求
|
||||||
const request=function(cfg){
|
const request = function (cfg) {
|
||||||
if(cfg.data){
|
if (cfg.data) {
|
||||||
cfg.data=qs.stringify(cfg.data);
|
cfg.data = qs.stringify(cfg.data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//requestJson请求
|
//requestJson请求
|
||||||
const requestJson=jsonRequest.request;
|
const requestJson = jsonRequest.request;
|
||||||
//get请求
|
//get请求
|
||||||
const get=formRequest.request;
|
const get = formRequest.request;
|
||||||
//post请求
|
//post请求
|
||||||
const post=function(url,data,config){
|
const post = function (url, data, config) {
|
||||||
if(data){
|
if (data) {
|
||||||
data=qs.stringify(data);
|
data = qs.stringify(data);
|
||||||
}
|
}
|
||||||
return formRequest.post(url,data,config);
|
return formRequest.post(url, data, config);
|
||||||
}
|
}
|
||||||
//post请求
|
//post请求
|
||||||
const postForm=function(url,data,config){
|
const postForm = function (url, data, config) {
|
||||||
return formRequest.post(url,data,config);
|
return formRequest.post(url, data, config);
|
||||||
}
|
}
|
||||||
//postJson请求
|
//postJson请求
|
||||||
const postJson=jsonRequest.post;
|
const postJson = jsonRequest.post;
|
||||||
//put请求
|
//put请求
|
||||||
const put=function(url,data,config){
|
const put = function (url, data, config) {
|
||||||
if(data){
|
if (data) {
|
||||||
data=qs.stringify(data);
|
data = qs.stringify(data);
|
||||||
}
|
}
|
||||||
return formRequest.put(url,data,config);
|
return formRequest.put(url, data, config);
|
||||||
}
|
}
|
||||||
//putJson请求
|
//putJson请求
|
||||||
const putJson=jsonRequest.put;
|
const putJson = jsonRequest.put;
|
||||||
//patch请求
|
//patch请求
|
||||||
const patch=function(url,data,config){
|
const patch = function (url, data, config) {
|
||||||
if(data){
|
if (data) {
|
||||||
data=qs.stringify(data);
|
data = qs.stringify(data);
|
||||||
}
|
}
|
||||||
return formRequest.patch(url,data,config);
|
return formRequest.patch(url, data, config);
|
||||||
}
|
}
|
||||||
//patchJson请求
|
//patchJson请求
|
||||||
const patchJson=jsonRequest.patch;
|
const patchJson = jsonRequest.patch;
|
||||||
//delete请求
|
//delete请求
|
||||||
const del=formRequest.delete;
|
const del = formRequest.delete;
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
request,
|
request,
|
||||||
requestJson,
|
requestJson,
|
||||||
get,
|
get,
|
||||||
post,
|
post,
|
||||||
postJson,
|
postJson,
|
||||||
put,
|
put,
|
||||||
putJson,
|
putJson,
|
||||||
patch,
|
patch,
|
||||||
patchJson,
|
patchJson,
|
||||||
del,
|
del,
|
||||||
postForm
|
postForm
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user