mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-12 20:36:43 +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,52 +19,57 @@ import errorCode from '@/utils/errorCode'
|
|||||||
|
|
||||||
|
|
||||||
// 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
|
||||||
/**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 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_CESOURCE_BASE_API,
|
// baseURL: process.env.VUE_APP_CESOURCE_BASE_API,
|
||||||
//超时
|
//超时
|
||||||
timeout: 60000,
|
timeout: 60000,
|
||||||
})
|
})
|
||||||
//发送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 === 401){
|
if (code === 401) {
|
||||||
//Message({message: msg, type: 'error'});
|
//Message({message: msg, type: 'error'});
|
||||||
store.dispatch('LogOut').then(() => {
|
store.dispatch('LogOut').then(() => {
|
||||||
location.href = this.webBaseUrl + ReLoginUrl;
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
|
top.location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
|
} else {
|
||||||
|
window.location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
|
}
|
||||||
|
// location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
})
|
})
|
||||||
}else if(code===403){
|
} else if (code === 403) {
|
||||||
var msg='当前操作没有权限';
|
var msg = '当前操作没有权限';
|
||||||
Message({message: msg, type: 'error'});
|
Message({ message: msg, type: 'error' });
|
||||||
return Promise.reject(new Error(msg))
|
return Promise.reject(new Error(msg))
|
||||||
}else{
|
} else {
|
||||||
//Message({message: res.data.message, type: 'error'});
|
//Message({message: res.data.message, type: 'error'});
|
||||||
//console.log('err' + res.data.error);
|
//console.log('err' + res.data.error);
|
||||||
return res.data
|
return res.data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log('err' + error)
|
console.log('err' + error)
|
||||||
let { message } = error;
|
let { message } = error;
|
||||||
@@ -84,22 +89,22 @@ const formRequest=axios.create({
|
|||||||
})
|
})
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* request请求,可以自定义参数
|
* request请求,可以自定义参数
|
||||||
*/
|
*/
|
||||||
const request=formRequest.request;
|
const request = formRequest.request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get请求 ,只有url
|
* get请求 ,只有url
|
||||||
*/
|
*/
|
||||||
const get = function(baseURL,url){
|
const get = function (baseURL, url) {
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url: url,
|
url: url,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
headers:{'Content-Type':'application/x-www-form-urlencoded'}
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,60 +113,60 @@ const get = function(baseURL,url){
|
|||||||
* @param {Object} url
|
* @param {Object} url
|
||||||
* @param {Object} postData
|
* @param {Object} postData
|
||||||
*/
|
*/
|
||||||
const post=function(baseURL,url,postData){
|
const post = function (baseURL, url, postData) {
|
||||||
if(postData){
|
if (postData) {
|
||||||
postData=qs.stringify(postData);
|
postData = qs.stringify(postData);
|
||||||
}
|
}
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url: url,
|
url: url,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data:postData,
|
data: postData,
|
||||||
headers:{'Content-Type':'application/x-www-form-urlencoded'}
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
//post请求
|
//post请求
|
||||||
const postForm=function(baseURL,url,data){
|
const postForm = function (baseURL, url, data) {
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url,
|
url,
|
||||||
data,
|
data,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
headers:{'Content-Type':'application/x-www-form-urlencoded'}
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// const postJson=jsonRequest.post;
|
// const postJson=jsonRequest.post;
|
||||||
|
|
||||||
const postJson=function(baseURL,url,postData){
|
const postJson = function (baseURL, url, postData) {
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url: url,
|
url: url,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data:postData,
|
data: postData,
|
||||||
headers:{'Content-Type':'application/json;charset=utf-8'},
|
headers: { 'Content-Type': 'application/json;charset=utf-8' },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const postPdf=function(baseURL,url,postData){
|
const postPdf = function (baseURL, url, postData) {
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url: url,
|
url: url,
|
||||||
responseType: 'blob',
|
responseType: 'blob',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data:postData,
|
data: postData,
|
||||||
headers:{'Content-Type':'application/pdf'},
|
headers: { 'Content-Type': 'application/pdf' },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导出文件请求定义
|
// 导出文件请求定义
|
||||||
const postJsonToFile=function(baseURL,url,postData){
|
const postJsonToFile = function (baseURL, url, postData) {
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url: url,
|
url: url,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data:postData,
|
data: postData,
|
||||||
headers:{'Content-Type':'application/json;charset=utf-8'},
|
headers: { 'Content-Type': 'application/json;charset=utf-8' },
|
||||||
responseType: 'blob'
|
responseType: 'blob'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -170,33 +175,33 @@ const postJsonToFile=function(baseURL,url,postData){
|
|||||||
/**
|
/**
|
||||||
* put请求
|
* put请求
|
||||||
*/
|
*/
|
||||||
const put=function(baseURL,url,data){
|
const put = function (baseURL, url, data) {
|
||||||
if(data){
|
if (data) {
|
||||||
data=qs.stringify(data);
|
data = qs.stringify(data);
|
||||||
}
|
}
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url: url,
|
url: url,
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data:data,
|
data: data,
|
||||||
headers:{'Content-Type':'application/x-www-form-urlencoded'}
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const putJson=function(baseURL,url,data){
|
const putJson = function (baseURL, url, data) {
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url: url,
|
url: url,
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data:data,
|
data: data,
|
||||||
headers:{'Content-Type':'application/json;charset=utf-8'},
|
headers: { 'Content-Type': 'application/json;charset=utf-8' },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
tokenName:TokenName,
|
tokenName: TokenName,
|
||||||
request,
|
request,
|
||||||
get,
|
get,
|
||||||
post,
|
post,
|
||||||
|
|||||||
@@ -19,56 +19,61 @@ import errorCode from '@/utils/errorCode'
|
|||||||
|
|
||||||
|
|
||||||
// const ReLoginUrl=process.env.VUE_APP_LOGIN_URL;
|
// const ReLoginUrl=process.env.VUE_APP_LOGIN_URL;
|
||||||
const TokenName='token';
|
const TokenName = '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
|
||||||
/**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 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_CESOURCE_BASE_API,
|
// baseURL: process.env.VUE_APP_CESOURCE_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
|
||||||
let curToken=getToken();
|
let curToken = getToken();
|
||||||
//curToken='eyJ0eXBlIjoidG9rZW4iLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC91LmJvZS5jb20iLCJpYXQiOjE2NzIzMTE2MTIsImV4cCI6MTY3MjMxODgxMiwiR2l2ZW5OYW1lIjoiYm9ldSIsInVzZXJJZCI6IjZCMDQ5RkFGLUMzMTQtN0NDRi0wRDI4LTBEMjNGNEM0MjUzMSIsInVJZCI6Ijk2NTM0MjAyNzQ5NzYwNzE2OCIsInBlcm1pc3Npb24iOiIifQ==.a4f41376e994c5fcd3ab537ce17572ef4c633863f87785cf7b6ffa353e2ed51c';
|
//curToken='eyJ0eXBlIjoidG9rZW4iLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC91LmJvZS5jb20iLCJpYXQiOjE2NzIzMTE2MTIsImV4cCI6MTY3MjMxODgxMiwiR2l2ZW5OYW1lIjoiYm9ldSIsInVzZXJJZCI6IjZCMDQ5RkFGLUMzMTQtN0NDRi0wRDI4LTBEMjNGNEM0MjUzMSIsInVJZCI6Ijk2NTM0MjAyNzQ5NzYwNzE2OCIsInBlcm1pc3Npb24iOiIifQ==.a4f41376e994c5fcd3ab537ce17572ef4c633863f87785cf7b6ffa353e2ed51c';
|
||||||
if (curToken && !isToken) {
|
if (curToken && !isToken) {
|
||||||
config.headers[TokenName] = curToken // 让每个请求携带自定义token 请根据实际情况自行修改
|
config.headers[TokenName] = curToken // 让每个请求携带自定义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 => {
|
||||||
//console.log(res);
|
//console.log(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 === 401){
|
if (code === 401) {
|
||||||
store.dispatch('LogOut').then(() => {
|
store.dispatch('LogOut').then(() => {
|
||||||
location.href = this.webBaseUrl + ReLoginUrl;
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
|
top.location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
|
} else {
|
||||||
|
window.location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
|
}
|
||||||
|
// location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
})
|
})
|
||||||
}else if(code===403){
|
} else if (code === 403) {
|
||||||
var msg='当前操作没有权限';
|
var msg = '当前操作没有权限';
|
||||||
Message({message: msg, type: 'error'});
|
Message({ message: msg, type: 'error' });
|
||||||
return Promise.reject(new Error(msg))
|
return Promise.reject(new Error(msg))
|
||||||
}else{
|
} else {
|
||||||
//Message({message: res.data.message, type: 'error'});
|
//Message({message: res.data.message, type: 'error'});
|
||||||
//console.log('err' + res.data.error);
|
//console.log('err' + res.data.error);
|
||||||
return res.data
|
return res.data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log('err',error)
|
console.log('err', error)
|
||||||
let { message } = error;
|
let { message } = error;
|
||||||
if (message == "Network Error") {
|
if (message == "Network Error") {
|
||||||
message = "网络异常,请稍后重试";
|
message = "网络异常,请稍后重试";
|
||||||
@@ -86,22 +91,22 @@ const formRequest=axios.create({
|
|||||||
})
|
})
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* request请求,可以自定义参数
|
* request请求,可以自定义参数
|
||||||
*/
|
*/
|
||||||
const request=formRequest.request;
|
const request = formRequest.request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get请求 ,只有url
|
* get请求 ,只有url
|
||||||
*/
|
*/
|
||||||
const get = function(baseURL,url){
|
const get = function (baseURL, url) {
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url: url,
|
url: url,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
headers:{'Content-Type':'application/x-www-form-urlencoded'}
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,48 +115,48 @@ const get = function(baseURL,url){
|
|||||||
* @param {Object} url
|
* @param {Object} url
|
||||||
* @param {Object} postData
|
* @param {Object} postData
|
||||||
*/
|
*/
|
||||||
const post=function(baseURL,url,postData){
|
const post = function (baseURL, url, postData) {
|
||||||
if(postData){
|
if (postData) {
|
||||||
postData=qs.stringify(postData);
|
postData = qs.stringify(postData);
|
||||||
}
|
}
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url: url,
|
url: url,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data:postData,
|
data: postData,
|
||||||
headers:{'Content-Type':'application/x-www-form-urlencoded'}
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
//post请求
|
//post请求
|
||||||
const postForm=function(baseURL,url,data){
|
const postForm = function (baseURL, url, data) {
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url,
|
url,
|
||||||
data,
|
data,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
headers:{'Content-Type':'application/x-www-form-urlencoded'}
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// const postJson=jsonRequest.post;
|
// const postJson=jsonRequest.post;
|
||||||
|
|
||||||
const postJson=function(baseURL,url,postData){
|
const postJson = function (baseURL, url, postData) {
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url: url,
|
url: url,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data:postData,
|
data: postData,
|
||||||
headers:{'Content-Type':'application/json'},
|
headers: { 'Content-Type': 'application/json' },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导出文件请求定义
|
// 导出文件请求定义
|
||||||
const postJsonToFile=function(baseURL,url,postData){
|
const postJsonToFile = function (baseURL, url, postData) {
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url: url,
|
url: url,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data:postData,
|
data: postData,
|
||||||
headers:{'Content-Type':'application/json;charset=utf-8'},
|
headers: { 'Content-Type': 'application/json;charset=utf-8' },
|
||||||
responseType: 'blob'
|
responseType: 'blob'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -160,33 +165,33 @@ const postJsonToFile=function(baseURL,url,postData){
|
|||||||
/**
|
/**
|
||||||
* put请求
|
* put请求
|
||||||
*/
|
*/
|
||||||
const put=function(baseURL,url,data){
|
const put = function (baseURL, url, data) {
|
||||||
if(data){
|
if (data) {
|
||||||
data=qs.stringify(data);
|
data = qs.stringify(data);
|
||||||
}
|
}
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url: url,
|
url: url,
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data:data,
|
data: data,
|
||||||
headers:{'Content-Type':'application/x-www-form-urlencoded'}
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const putJson=function(baseURL,url,data){
|
const putJson = function (baseURL, url, data) {
|
||||||
return request({
|
return request({
|
||||||
baseURL,
|
baseURL,
|
||||||
url: url,
|
url: url,
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data:data,
|
data: data,
|
||||||
headers:{'Content-Type':'application/json;charset=utf-8'},
|
headers: { 'Content-Type': 'application/json;charset=utf-8' },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
tokenName:TokenName,
|
tokenName: TokenName,
|
||||||
request,
|
request,
|
||||||
get,
|
get,
|
||||||
post,
|
post,
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ import errorCode from '@/utils/errorCode'
|
|||||||
*delete请求 axios.delete(url[, config])
|
*delete请求 axios.delete(url[, config])
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const ReLoginUrl=process.env.VUE_APP_LOGIN_URL;
|
const ReLoginUrl = process.env.VUE_APP_LOGIN_URL;
|
||||||
const TokenName='token';
|
const TokenName = '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_BOE_BASE_API,
|
baseURL: process.env.VUE_APP_BOE_BASE_API,
|
||||||
//超时
|
//超时
|
||||||
@@ -47,27 +47,32 @@ jsonRequest.interceptors.request.use(config => {
|
|||||||
jsonRequest.interceptors.response.use(res => {
|
jsonRequest.interceptors.response.use(res => {
|
||||||
|
|
||||||
const code1 = res.data.status || 200;
|
const code1 = res.data.status || 200;
|
||||||
const code=parseInt(code1);
|
const code = parseInt(code1);
|
||||||
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 {
|
||||||
|
window.location.href = ReLoginUrl;
|
||||||
|
}
|
||||||
|
// location.href = ReLoginUrl;
|
||||||
})
|
})
|
||||||
}else if(code===403){
|
} else if (code === 403) {
|
||||||
var msg='当前操作没有权限';
|
var msg = '当前操作没有权限';
|
||||||
Message({message: msg, type: 'error'});
|
Message({ message: msg, type: 'error' });
|
||||||
return Promise.reject(new Error(msg))
|
return Promise.reject(new Error(msg))
|
||||||
//return res.data;
|
//return res.data;
|
||||||
}else{
|
} else {
|
||||||
//Message({message: res.data.message, type: 'error'});
|
//Message({message: res.data.message, type: 'error'});
|
||||||
//console.log('err:' + res.data.error);
|
//console.log('err:' + res.data.error);
|
||||||
//return Promise.reject(new Error(res.data.message))
|
//return Promise.reject(new Error(res.data.message))
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log('err' + error)
|
console.log('err' + error)
|
||||||
let { message } = error;
|
let { message } = error;
|
||||||
@@ -91,8 +96,8 @@ jsonRequest.interceptors.response.use(res => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
//用于普通的发送请求
|
//用于普通的发送请求
|
||||||
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_BOE_BASE_API,
|
baseURL: process.env.VUE_APP_BOE_BASE_API,
|
||||||
//超时
|
//超时
|
||||||
@@ -112,25 +117,30 @@ formRequest.interceptors.request.use(config => {
|
|||||||
});
|
});
|
||||||
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 {
|
||||||
|
window.location.href = ReLoginUrl;
|
||||||
|
}
|
||||||
|
// location.href = ReLoginUrl;
|
||||||
})
|
})
|
||||||
}else if(code===403){
|
} else if (code === 403) {
|
||||||
var msg='当前操作没有权限';
|
var msg = '当前操作没有权限';
|
||||||
Message({message: msg, type: 'error'});
|
Message({ message: msg, type: 'error' });
|
||||||
return Promise.reject(new Error(msg))
|
return Promise.reject(new Error(msg))
|
||||||
}else{
|
} else {
|
||||||
//Message({message: res.data.message, type: 'error'});
|
//Message({message: res.data.message, type: 'error'});
|
||||||
//console.log('err' + res.data.error);
|
//console.log('err' + res.data.error);
|
||||||
//return Promise.reject(new Error(res.data.message))
|
//return Promise.reject(new Error(res.data.message))
|
||||||
return res.data;//返回给用户做业务处理
|
return res.data;//返回给用户做业务处理
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log('err' + error)
|
console.log('err' + error)
|
||||||
let { message } = error;
|
let { message } = error;
|
||||||
@@ -154,44 +164,44 @@ formRequest.interceptors.response.use(res => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
//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);
|
||||||
}
|
}
|
||||||
//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 {
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ import errorCode from '@/utils/errorCode'
|
|||||||
*delete请求 axios.delete(url[, config])
|
*delete请求 axios.delete(url[, config])
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const ReLoginUrl="/login";
|
const ReLoginUrl = "/login";
|
||||||
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_CESOURCE_BASE_API,
|
baseURL: process.env.VUE_APP_CESOURCE_BASE_API,
|
||||||
//超时
|
//超时
|
||||||
@@ -45,25 +45,30 @@ jsonRequest.interceptors.request.use(config => {
|
|||||||
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 === 401){
|
if (code === 401) {
|
||||||
store.dispatch('LogOut').then(() => {
|
store.dispatch('LogOut').then(() => {
|
||||||
location.href = this.webBaseUrl + ReLoginUrl;
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
|
top.location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
|
} else {
|
||||||
|
window.location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
|
}
|
||||||
|
// location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
})
|
})
|
||||||
}else if(code===403){
|
} else if (code === 403) {
|
||||||
var msg='当前操作没有权限';
|
var msg = '当前操作没有权限';
|
||||||
Message({message: msg, type: 'error'});
|
Message({ message: msg, type: 'error' });
|
||||||
return Promise.reject(new Error(msg))
|
return Promise.reject(new Error(msg))
|
||||||
}else{
|
} else {
|
||||||
//Message({message: res.data.message, type: 'error'});
|
//Message({message: res.data.message, type: 'error'});
|
||||||
//console.log('err:' + res.data.error);
|
//console.log('err:' + res.data.error);
|
||||||
return res.data;
|
return res.data;
|
||||||
//return Promise.reject(new Error(res.data.message))
|
//return Promise.reject(new Error(res.data.message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log('err' + error)
|
console.log('err' + error)
|
||||||
let { message } = error;
|
let { message } = error;
|
||||||
@@ -86,8 +91,8 @@ jsonRequest.interceptors.response.use(res => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
//用于普通的发送请求
|
//用于普通的发送请求
|
||||||
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_CESOURCE_BASE_API,
|
baseURL: process.env.VUE_APP_CESOURCE_BASE_API,
|
||||||
//超时
|
//超时
|
||||||
@@ -107,24 +112,29 @@ formRequest.interceptors.request.use(config => {
|
|||||||
});
|
});
|
||||||
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 === 401){
|
if (code === 401) {
|
||||||
store.dispatch('LogOut').then(() => {
|
store.dispatch('LogOut').then(() => {
|
||||||
location.href = this.webBaseUrl + ReLoginUrl;
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
|
top.location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
|
} else {
|
||||||
|
window.location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
|
}
|
||||||
|
// location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
})
|
})
|
||||||
}else if(code===403){
|
} else if (code === 403) {
|
||||||
var msg='当前操作没有权限';
|
var msg = '当前操作没有权限';
|
||||||
Message({message: msg, type: 'error'});
|
Message({ message: msg, type: 'error' });
|
||||||
return Promise.reject(new Error(msg))
|
return Promise.reject(new Error(msg))
|
||||||
}else{
|
} else {
|
||||||
//Message({message: res.data.message, type: 'error'});
|
//Message({message: res.data.message, type: 'error'});
|
||||||
//console.log('err' + res.data.error);
|
//console.log('err' + res.data.error);
|
||||||
return res.data
|
return res.data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log('err' + error)
|
console.log('err' + error)
|
||||||
let { message } = error;
|
let { message } = error;
|
||||||
@@ -147,44 +157,44 @@ formRequest.interceptors.response.use(res => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
//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);
|
||||||
}
|
}
|
||||||
//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 {
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ import errorCode from '@/utils/errorCode'
|
|||||||
*delete请求 axios.delete(url[, config])
|
*delete请求 axios.delete(url[, config])
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const ReLoginUrl="/login";
|
const ReLoginUrl = "/login";
|
||||||
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_STAT_BASE_API,
|
baseURL: process.env.VUE_APP_STAT_BASE_API,
|
||||||
//超时
|
//超时
|
||||||
@@ -45,25 +45,30 @@ jsonRequest.interceptors.request.use(config => {
|
|||||||
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 === 401){
|
if (code === 401) {
|
||||||
store.dispatch('LogOut').then(() => {
|
store.dispatch('LogOut').then(() => {
|
||||||
location.href = this.webBaseUrl + ReLoginUrl;
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
|
top.location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
|
} else {
|
||||||
|
window.location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
|
}
|
||||||
|
// location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
})
|
})
|
||||||
}else if(code===403){
|
} else if (code === 403) {
|
||||||
var msg='当前操作没有权限';
|
var msg = '当前操作没有权限';
|
||||||
Message({message: msg, type: 'error'});
|
Message({ message: msg, type: 'error' });
|
||||||
return Promise.reject(new Error(msg))
|
return Promise.reject(new Error(msg))
|
||||||
}else{
|
} else {
|
||||||
//Message({message: res.data.message, type: 'error'});
|
//Message({message: res.data.message, type: 'error'});
|
||||||
//console.log('err:' + res.data.error);
|
//console.log('err:' + res.data.error);
|
||||||
return res.data;
|
return res.data;
|
||||||
//return Promise.reject(new Error(res.data.message))
|
//return Promise.reject(new Error(res.data.message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log('err' + error)
|
console.log('err' + error)
|
||||||
let { message } = error;
|
let { message } = error;
|
||||||
@@ -86,8 +91,8 @@ jsonRequest.interceptors.response.use(res => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
//用于普通的发送请求
|
//用于普通的发送请求
|
||||||
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_STAT_BASE_API,
|
baseURL: process.env.VUE_APP_STAT_BASE_API,
|
||||||
//超时
|
//超时
|
||||||
@@ -107,24 +112,29 @@ formRequest.interceptors.request.use(config => {
|
|||||||
});
|
});
|
||||||
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 === 401){
|
if (code === 401) {
|
||||||
store.dispatch('LogOut').then(() => {
|
store.dispatch('LogOut').then(() => {
|
||||||
location.href = this.webBaseUrl + ReLoginUrl;
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
|
top.location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
|
} else {
|
||||||
|
window.location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
|
}
|
||||||
|
// location.href = this.webBaseUrl + ReLoginUrl;
|
||||||
})
|
})
|
||||||
}else if(code===403){
|
} else if (code === 403) {
|
||||||
var msg='当前操作没有权限';
|
var msg = '当前操作没有权限';
|
||||||
Message({message: msg, type: 'error'});
|
Message({ message: msg, type: 'error' });
|
||||||
return Promise.reject(new Error(msg))
|
return Promise.reject(new Error(msg))
|
||||||
}else{
|
} else {
|
||||||
//Message({message: res.data.message, type: 'error'});
|
//Message({message: res.data.message, type: 'error'});
|
||||||
//console.log('err' + res.data.error);
|
//console.log('err' + res.data.error);
|
||||||
return res.data
|
return res.data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log('err' + error)
|
console.log('err' + error)
|
||||||
let { message } = error;
|
let { message } = error;
|
||||||
@@ -147,44 +157,44 @@ formRequest.interceptors.response.use(res => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
//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);
|
||||||
}
|
}
|
||||||
//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 {
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ import xpage from '@/utils/xpage'
|
|||||||
|
|
||||||
NProgress.configure({ showSpinner: false })
|
NProgress.configure({ showSpinner: false })
|
||||||
|
|
||||||
const whiteList = ['/login','/logout','/loading','/pc/loading','/500','/auth-redirect','/forget','/reset/password']
|
const whiteList = ['/login', '/logout', '/loading', '/pc/loading', '/500', '/auth-redirect', '/forget', '/reset/password']
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
watermark.set("");
|
watermark.set("");
|
||||||
//动态计算文件的路径
|
//动态计算文件的路径
|
||||||
let configPath=process.env.VUE_APP_FILE_RELATIVE_PATH;
|
let configPath = process.env.VUE_APP_FILE_RELATIVE_PATH;
|
||||||
if(configPath.startsWith('http')){
|
if (configPath.startsWith('http')) {
|
||||||
xpage.constants.fileBaseUrl=configPath;
|
xpage.constants.fileBaseUrl = configPath;
|
||||||
}else{
|
} else {
|
||||||
xpage.constants.fileBaseUrl=window.location.protocol+'//'+window.location.host+configPath;
|
xpage.constants.fileBaseUrl = window.location.protocol + '//' + window.location.host + configPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
NProgress.start();
|
NProgress.start();
|
||||||
@@ -28,21 +28,21 @@ router.beforeEach((to, from, next) => {
|
|||||||
if (whiteList.indexOf(to.path) !== -1) {
|
if (whiteList.indexOf(to.path) !== -1) {
|
||||||
// 在免登录白名单,直接进入
|
// 在免登录白名单,直接进入
|
||||||
next()
|
next()
|
||||||
}else{
|
} else {
|
||||||
if(getToken()){
|
if (getToken()) {
|
||||||
if(to.path === '/login'){
|
if (to.path === '/login') {
|
||||||
// 如果是外部用户,把配置的路由跳转到个人中心
|
// 如果是外部用户,把配置的路由跳转到个人中心
|
||||||
if(store.getters.userInfo.role === 2){
|
if (store.getters.userInfo.role === 2) {
|
||||||
next({ path: process.env.VUE_APP_PUBLIC_PATH+'/uc/study/courses' })
|
next({ path: process.env.VUE_APP_PUBLIC_PATH + '/uc/study/courses' })
|
||||||
}else{
|
} else {
|
||||||
next({ path: process.env.VUE_APP_PUBLIC_PATH+'/index' })
|
next({ path: process.env.VUE_APP_PUBLIC_PATH + '/index' })
|
||||||
}
|
}
|
||||||
NProgress.done();
|
NProgress.done();
|
||||||
} else {
|
} else {
|
||||||
//console.log('store.getters.userInfo:',store.getters.userInfo.role)
|
//console.log('store.getters.userInfo:',store.getters.userInfo.role)
|
||||||
// 如果是外部用户,把配置的路由跳转到个人中心
|
// 如果是外部用户,把配置的路由跳转到个人中心
|
||||||
if(store.getters.userInfo.role === 2){
|
if (store.getters.userInfo.role === 2) {
|
||||||
if(to.path === '/index' || to.path === '/course' || to.path === '/case' || to.path === '/article' ) location.href = '/pc/uc/study/task'
|
if (to.path === '/index' || to.path === '/course' || to.path === '/case' || to.path === '/article') location.href = '/pc/uc/study/task'
|
||||||
}
|
}
|
||||||
//后续这里需要增加一定的控制
|
//后续这里需要增加一定的控制
|
||||||
if (!store.getters.init) {
|
if (!store.getters.init) {
|
||||||
@@ -56,17 +56,17 @@ router.beforeEach((to, from, next) => {
|
|||||||
store.dispatch('resOwner/loadResOwners');
|
store.dispatch('resOwner/loadResOwners');
|
||||||
store.dispatch('sysType/loadSysTypes');
|
store.dispatch('sysType/loadSysTypes');
|
||||||
|
|
||||||
store.commit('app/SET_INITDATA',true);
|
store.commit('app/SET_INITDATA', true);
|
||||||
//routers数据先使用固定的,以后在初始化接口中返回
|
//routers数据先使用固定的,以后在初始化接口中返回
|
||||||
let myRouters=routers();
|
let myRouters = routers();
|
||||||
store.dispatch('GenerateRoutes',{routers:myRouters}).then(accessRoutes=>{
|
store.dispatch('GenerateRoutes', { routers: myRouters }).then(accessRoutes => {
|
||||||
router.addRoutes(accessRoutes) // 动态添加可访问路由表
|
router.addRoutes(accessRoutes) // 动态添加可访问路由表
|
||||||
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
|
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
|
||||||
});
|
});
|
||||||
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
store.commit('app/SET_INITDATA',false);
|
store.commit('app/SET_INITDATA', false);
|
||||||
//如果初始化错误,就不再执行了,不然会一直循环下去
|
//如果初始化错误,就不再执行了,不然会一直循环下去
|
||||||
next({ path: '/500' })
|
next({ path: '/500' })
|
||||||
//NProgress.done();
|
//NProgress.done();
|
||||||
@@ -78,7 +78,7 @@ router.beforeEach((to, from, next) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
//next();
|
//next();
|
||||||
}else{
|
} else {
|
||||||
|
|
||||||
//next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
|
//next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
|
||||||
//设置之前的路径
|
//设置之前的路径
|
||||||
@@ -86,7 +86,12 @@ router.beforeEach((to, from, next) => {
|
|||||||
//console.log(location.href,'location.href');
|
//console.log(location.href,'location.href');
|
||||||
//let urlPre=window.location.protocol+'//'+window.location.host;
|
//let urlPre=window.location.protocol+'//'+window.location.host;
|
||||||
//let backUrl=location.href.substring(urlPre.length); encodeURIComponent()
|
//let backUrl=location.href.substring(urlPre.length); encodeURIComponent()
|
||||||
location.href=process.env.VUE_APP_LOGIN_URL+"?returnUrl="+encodeURIComponent(location.href);
|
if (top !== window) { // 判断当前是否在iframe内
|
||||||
|
top.location.href = process.env.VUE_APP_LOGIN_URL + "?returnUrl=" + encodeURIComponent(location.href);
|
||||||
|
} else {
|
||||||
|
window.location.href = process.env.VUE_APP_LOGIN_URL + "?returnUrl=" + encodeURIComponent(location.href);
|
||||||
|
}
|
||||||
|
// location.href=process.env.VUE_APP_LOGIN_URL+"?returnUrl="+encodeURIComponent(location.href);
|
||||||
NProgress.done()
|
NProgress.done()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,56 +5,61 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Cookies from 'vue-cookies'
|
import Cookies from "vue-cookies";
|
||||||
import apiLogin from '@/api/login.js'
|
import apiLogin from "@/api/login.js";
|
||||||
import { getToken,setToken } from '@/utils/token'
|
import { getToken, setToken } from "@/utils/token";
|
||||||
export default{
|
export default {
|
||||||
mounted(){
|
mounted() {
|
||||||
this.toUrl=this.$route.query.returnUrl;
|
this.toUrl = this.$route.query.returnUrl;
|
||||||
let token=getToken();
|
let token = getToken();
|
||||||
let $this=this;
|
let $this = this;
|
||||||
if(!token){
|
if (!token) {
|
||||||
//console.log(token,'未获取token');
|
//console.log(token,'未获取token');
|
||||||
setTimeout(function(){
|
setTimeout(function () {
|
||||||
$this.curToken=getToken();
|
$this.curToken = getToken();
|
||||||
if(!$this.curToken){
|
if (!$this.curToken) {
|
||||||
//console.log(token,'第二次未获取token');
|
//console.log(token,'第二次未获取token');
|
||||||
location.href = process.env.VUE_APP_LOGIN_URL;
|
if (top !== window) {
|
||||||
}else{
|
// 判断当前是否在iframe内
|
||||||
|
top.location.href = process.env.VUE_APP_LOGIN_URL;
|
||||||
|
} else {
|
||||||
|
window.location.href = process.env.VUE_APP_LOGIN_URL;
|
||||||
|
}
|
||||||
|
// location.href = process.env.VUE_APP_LOGIN_URL;
|
||||||
|
} else {
|
||||||
$this.boeLogin();
|
$this.boeLogin();
|
||||||
}
|
}
|
||||||
|
}, 500);
|
||||||
},500);
|
} else {
|
||||||
}else{
|
this.curToken = token;
|
||||||
this.curToken=token;
|
|
||||||
this.boeLogin();
|
this.boeLogin();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data(){
|
data() {
|
||||||
return {
|
return {
|
||||||
curToken:'',
|
curToken: "",
|
||||||
toUrl:''
|
toUrl: "",
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
methods:{
|
methods: {
|
||||||
boeLogin(){
|
boeLogin() {
|
||||||
apiLogin.boeLogin(this.curToken).then(rs=>{
|
apiLogin.boeLogin(this.curToken).then((rs) => {
|
||||||
if(rs.status==200){
|
if (rs.status == 200) {
|
||||||
//setToken(rs.result.access_token);
|
//setToken(rs.result.access_token);
|
||||||
localStorage.setItem(this.$xpage.constants.newLoginKey,1);
|
localStorage.setItem(this.$xpage.constants.newLoginKey, 1);
|
||||||
if(this.toUrl){
|
if (this.toUrl) {
|
||||||
location.href=this.toUrl;
|
location.href = this.toUrl;
|
||||||
}else{
|
} else {
|
||||||
this.$router.push({ path: "/index" })
|
this.$router.push({ path: "/index" });
|
||||||
}
|
}
|
||||||
//this.$router.push({ path: "/index" })
|
//this.$router.push({ path: "/index" })
|
||||||
}else{
|
} else {
|
||||||
this.$message.error("登录失败:"+rs.message);
|
this.$message.error("登录失败:" + rs.message);
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
Reference in New Issue
Block a user