|
|
|
|
@ -1,4 +1,3 @@
|
|
|
|
|
|
|
|
|
|
import axios from 'axios'
|
|
|
|
|
import qs from 'qs'
|
|
|
|
|
// import store from '../store'
|
|
|
|
|
@ -7,112 +6,122 @@ import commonUtils from '../utils/Common'
|
|
|
|
|
|
|
|
|
|
// http://mf.kiisoo.com:58080/
|
|
|
|
|
// axios.defaults.baseURL = 'https://wxtk.bsdits.com/kiisoo-ic/';
|
|
|
|
|
axios.defaults.baseURL = '/kiisoo-ic';
|
|
|
|
|
axios.defaults.baseURL = '/kiisoo-ic'
|
|
|
|
|
|
|
|
|
|
//响应时间
|
|
|
|
|
axios.defaults.timeout = 120000;
|
|
|
|
|
axios.defaults.withCredentials=true;
|
|
|
|
|
axios.defaults.timeout = 120000
|
|
|
|
|
axios.defaults.withCredentials = true
|
|
|
|
|
|
|
|
|
|
//配置请求头
|
|
|
|
|
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
|
|
|
|
|
axios.defaults.headers.post['Content-Type'] =
|
|
|
|
|
'application/x-www-form-urlencoded;charset=UTF-8'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* POST传参序列化(添加请求拦截器)
|
|
|
|
|
*/
|
|
|
|
|
axios.interceptors.request.use((config) => {
|
|
|
|
|
config.headers['X-Requested-With'] = 'XMLHttpRequest';
|
|
|
|
|
config.headers['Content-Type'] = 'application/json;charset=UTF-8;';
|
|
|
|
|
axios.interceptors.request.use(
|
|
|
|
|
(config) => {
|
|
|
|
|
config.headers['X-Requested-With'] = 'XMLHttpRequest'
|
|
|
|
|
config.headers['Content-Type'] = 'application/json;charset=UTF-8;'
|
|
|
|
|
// config.headers['Authorization'] = sessionStorage.getItem("sessionId");
|
|
|
|
|
|
|
|
|
|
//在发送请求之前做某件事
|
|
|
|
|
if(config.method === 'post'){
|
|
|
|
|
if(config.data.isGetActivityInfo === true) {
|
|
|
|
|
config.headers['Content-Type'] = 'application/json;charset=UTF-8;';
|
|
|
|
|
} else if (Object.prototype.toString.call(config.data) === '[object FormData]') {
|
|
|
|
|
config.headers['Content-Type'] = 'multipart/form-data';
|
|
|
|
|
if (config.method === 'post') {
|
|
|
|
|
if (config.data.isGetActivityInfo === true) {
|
|
|
|
|
config.headers['Content-Type'] = 'application/json;charset=UTF-8;'
|
|
|
|
|
} else if (
|
|
|
|
|
Object.prototype.toString.call(config.data) === '[object FormData]'
|
|
|
|
|
) {
|
|
|
|
|
config.headers['Content-Type'] = 'multipart/form-data'
|
|
|
|
|
} else {
|
|
|
|
|
config.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
|
|
|
|
|
var str = qs.stringify(config.data);
|
|
|
|
|
config.data = str;
|
|
|
|
|
config.headers['Content-Type'] =
|
|
|
|
|
'application/x-www-form-urlencoded;charset=UTF-8'
|
|
|
|
|
var str = qs.stringify(config.data)
|
|
|
|
|
config.data = str
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return config;
|
|
|
|
|
},(error) =>{
|
|
|
|
|
return config
|
|
|
|
|
},
|
|
|
|
|
(error) => {
|
|
|
|
|
// console.log('错误的传参')
|
|
|
|
|
return Promise.reject(error);
|
|
|
|
|
});
|
|
|
|
|
return Promise.reject(error)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回状态判断(添加响应拦截器)
|
|
|
|
|
*/
|
|
|
|
|
axios.interceptors.response.use((res) =>{
|
|
|
|
|
let data = res.data.results;
|
|
|
|
|
axios.interceptors.response.use(
|
|
|
|
|
(res) => {
|
|
|
|
|
let data = res.data.results
|
|
|
|
|
|
|
|
|
|
if(res.data.code === '9999' || sessionStorage.getItem("logout")){
|
|
|
|
|
if (res.data.code === '9999' || sessionStorage.getItem('logout')) {
|
|
|
|
|
// iView.Message.error('会话超时,请重新登录');
|
|
|
|
|
// store.commit('LOGOUT');
|
|
|
|
|
commonUtils.goToLogin();
|
|
|
|
|
return Promise.resolve(res);
|
|
|
|
|
commonUtils.goToLogin()
|
|
|
|
|
return Promise.resolve(res)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//对响应数据做些事
|
|
|
|
|
if(!data){
|
|
|
|
|
return Promise.resolve(res);
|
|
|
|
|
if (!data) {
|
|
|
|
|
return Promise.resolve(res)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(data.code === "1001"){
|
|
|
|
|
if (data.code === '1001') {
|
|
|
|
|
// iView.Message.error("账号不存在");
|
|
|
|
|
return Promise.resolve(res);
|
|
|
|
|
return Promise.resolve(res)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(data.code === "1002"){
|
|
|
|
|
if (data.code === '1002') {
|
|
|
|
|
// iView.Message.error("账号已停用");
|
|
|
|
|
return Promise.resolve(res);
|
|
|
|
|
return Promise.resolve(res)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(data.code === "1003"){
|
|
|
|
|
if (data.code === '1003') {
|
|
|
|
|
// iView.Message.error("密码错误");
|
|
|
|
|
return Promise.resolve(res);
|
|
|
|
|
return Promise.resolve(res)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(data.code === "1004"){
|
|
|
|
|
if (data.code === '1004') {
|
|
|
|
|
// iView.Message.error("账号已注销");
|
|
|
|
|
return Promise.resolve(res);
|
|
|
|
|
return Promise.resolve(res)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(data.code === "1005"){
|
|
|
|
|
if (data.code === '1005') {
|
|
|
|
|
// iView.Message.error("账号未绑定品牌");
|
|
|
|
|
return Promise.resolve(res);
|
|
|
|
|
return Promise.resolve(res)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(data.code === "1006"){
|
|
|
|
|
if (data.code === '1006') {
|
|
|
|
|
// iView.Message.error("账号未绑定店铺");
|
|
|
|
|
return Promise.resolve(res);
|
|
|
|
|
return Promise.resolve(res)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(data.code === "1007"){
|
|
|
|
|
if (data.code === '1007') {
|
|
|
|
|
// iView.Message.error("账号无权限");
|
|
|
|
|
return Promise.resolve(res);
|
|
|
|
|
return Promise.resolve(res)
|
|
|
|
|
}
|
|
|
|
|
if(data.code === "1009"){
|
|
|
|
|
if (data.code === '1009') {
|
|
|
|
|
// iView.Message.error("账号已过时");
|
|
|
|
|
return Promise.resolve(res);
|
|
|
|
|
return Promise.resolve(res)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(data.code === "0001"){
|
|
|
|
|
if (data.code === '0001') {
|
|
|
|
|
// this.$Message.error("系统繁忙,请重试");
|
|
|
|
|
return Promise.resolve(res);
|
|
|
|
|
return Promise.resolve(res)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(data.code !== "0000") {
|
|
|
|
|
if (data.code !== '0000') {
|
|
|
|
|
// this.$Message.error(data.errorMsg);
|
|
|
|
|
return Promise.resolve(res);
|
|
|
|
|
return Promise.resolve(res)
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}, (error) => {
|
|
|
|
|
return res
|
|
|
|
|
},
|
|
|
|
|
(error) => {
|
|
|
|
|
// iView.Message.error('网络异常');
|
|
|
|
|
return Promise.reject(error);
|
|
|
|
|
});
|
|
|
|
|
return Promise.reject(error)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回一个Promise(发送get请求)
|
|
|
|
|
@ -123,14 +132,18 @@ axios.interceptors.response.use((res) =>{
|
|
|
|
|
export function get(url, param) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
// iView.LoadingBar.start();
|
|
|
|
|
axios.get(url, {params: param})
|
|
|
|
|
.then(response => {
|
|
|
|
|
axios
|
|
|
|
|
.get(url, { params: param })
|
|
|
|
|
.then(
|
|
|
|
|
(response) => {
|
|
|
|
|
// iView.LoadingBar.finish();
|
|
|
|
|
resolve(response)
|
|
|
|
|
}, err => {
|
|
|
|
|
},
|
|
|
|
|
(err) => {
|
|
|
|
|
// iView.LoadingBar.finish();
|
|
|
|
|
reject(err)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
// iView.LoadingBar.finish();
|
|
|
|
|
reject(error)
|
|
|
|
|
@ -138,7 +151,6 @@ export function get(url, param) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回一个Promise(发送post请求)
|
|
|
|
|
* @param url
|
|
|
|
|
@ -148,14 +160,18 @@ export function get(url, param) {
|
|
|
|
|
export function post(url, params) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
// iView.LoadingBar.start();
|
|
|
|
|
axios.post(url, params)
|
|
|
|
|
.then(response => {
|
|
|
|
|
axios
|
|
|
|
|
.post(url, params)
|
|
|
|
|
.then(
|
|
|
|
|
(response) => {
|
|
|
|
|
// iView.LoadingBar.finish();
|
|
|
|
|
resolve(response);
|
|
|
|
|
}, err => {
|
|
|
|
|
resolve(response)
|
|
|
|
|
},
|
|
|
|
|
(err) => {
|
|
|
|
|
// iView.LoadingBar.finish();
|
|
|
|
|
reject(err);
|
|
|
|
|
})
|
|
|
|
|
reject(err)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
// iView.LoadingBar.finish();
|
|
|
|
|
reject(error)
|
|
|
|
|
@ -166,14 +182,18 @@ export function post(url, params) {
|
|
|
|
|
export function put(url, params) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
// iView.LoadingBar.start();
|
|
|
|
|
axios.put(url, params)
|
|
|
|
|
.then(response => {
|
|
|
|
|
axios
|
|
|
|
|
.put(url, params)
|
|
|
|
|
.then(
|
|
|
|
|
(response) => {
|
|
|
|
|
// iView.LoadingBar.finish();
|
|
|
|
|
resolve(response);
|
|
|
|
|
}, err => {
|
|
|
|
|
resolve(response)
|
|
|
|
|
},
|
|
|
|
|
(err) => {
|
|
|
|
|
// iView.LoadingBar.finish();
|
|
|
|
|
reject(err);
|
|
|
|
|
})
|
|
|
|
|
reject(err)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
// iView.LoadingBar.finish();
|
|
|
|
|
reject(error)
|
|
|
|
|
@ -184,14 +204,18 @@ export function put(url, params) {
|
|
|
|
|
export function fetchDelete(url, params) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
// iView.LoadingBar.start();
|
|
|
|
|
axios.delete(url, params)
|
|
|
|
|
.then(response => {
|
|
|
|
|
axios
|
|
|
|
|
.delete(url, params)
|
|
|
|
|
.then(
|
|
|
|
|
(response) => {
|
|
|
|
|
// iView.LoadingBar.finish();
|
|
|
|
|
resolve(response);
|
|
|
|
|
}, err => {
|
|
|
|
|
resolve(response)
|
|
|
|
|
},
|
|
|
|
|
(err) => {
|
|
|
|
|
// iView.LoadingBar.finish();
|
|
|
|
|
reject(err);
|
|
|
|
|
})
|
|
|
|
|
reject(err)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
// iView.LoadingBar.finish();
|
|
|
|
|
reject(error)
|
|
|
|
|
@ -199,19 +223,19 @@ export function fetchDelete(url, params) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function downloadZip(url,filename, options = {}) {
|
|
|
|
|
export function downloadZip(url, filename, options = {}) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
axios.defaults.headers['content-type'] = 'application/json;charset=UTF-8'
|
|
|
|
|
axios({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: url, // 请求地址
|
|
|
|
|
data: options, // 参数
|
|
|
|
|
responseType: 'blob' // 表明返回服务器返回的数据类型
|
|
|
|
|
responseType: 'blob', // 表明返回服务器返回的数据类型
|
|
|
|
|
}).then(
|
|
|
|
|
response => {
|
|
|
|
|
(response) => {
|
|
|
|
|
resolve(response.data)
|
|
|
|
|
let blob = new Blob([response.data], {
|
|
|
|
|
type: 'application/zip'
|
|
|
|
|
type: 'application/zip',
|
|
|
|
|
})
|
|
|
|
|
console.log(blob)
|
|
|
|
|
let fileName = filename + '.zip'
|
|
|
|
|
@ -228,31 +252,32 @@ export function downloadZip(url,filename, options = {}) {
|
|
|
|
|
window.URL.revokeObjectURL(link.href)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
err => {
|
|
|
|
|
(err) => {
|
|
|
|
|
reject(err)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
export function downloadExcel(url,filename, options = {}) {
|
|
|
|
|
let split = filename.split(",");
|
|
|
|
|
if (split.length != 1){
|
|
|
|
|
filename = "店铺发起申请数报表";
|
|
|
|
|
}else{
|
|
|
|
|
filename = "零售公司拓客报表";
|
|
|
|
|
export function downloadExcel(url, filename, options = {}) {
|
|
|
|
|
let split = filename.split(',')
|
|
|
|
|
if (split.length != 1) {
|
|
|
|
|
filename = '店铺发起申请数报表'
|
|
|
|
|
} else {
|
|
|
|
|
filename = '零售公司拓客报表'
|
|
|
|
|
}
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
axios.defaults.headers['content-type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
|
|
|
|
|
axios.defaults.headers['content-type'] =
|
|
|
|
|
'application/x-www-form-urlencoded;charset=UTF-8'
|
|
|
|
|
axios({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: url, // 请求地址
|
|
|
|
|
data: options, // 参数
|
|
|
|
|
responseType: 'blob' // 表明返回服务器返回的数据类型
|
|
|
|
|
responseType: 'blob', // 表明返回服务器返回的数据类型
|
|
|
|
|
}).then(
|
|
|
|
|
response => {
|
|
|
|
|
(response) => {
|
|
|
|
|
resolve(response.data)
|
|
|
|
|
let blob = new Blob([response.data], {
|
|
|
|
|
type: 'application/vnd.ms-excel'
|
|
|
|
|
type: 'application/vnd.ms-excel',
|
|
|
|
|
})
|
|
|
|
|
console.log(blob)
|
|
|
|
|
let fileName = filename + '.xls'
|
|
|
|
|
@ -269,27 +294,27 @@ export function downloadExcel(url,filename, options = {}) {
|
|
|
|
|
window.URL.revokeObjectURL(link.href)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
err => {
|
|
|
|
|
(err) => {
|
|
|
|
|
reject(err)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function downloadImg(url,filename, options = {}) {
|
|
|
|
|
export function downloadImg(url, filename, options = {}) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
axios.defaults.headers['content-type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
|
|
|
|
|
axios.defaults.headers['content-type'] =
|
|
|
|
|
'application/x-www-form-urlencoded;charset=UTF-8'
|
|
|
|
|
axios({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: url, // 请求地址
|
|
|
|
|
data: options, // 参数
|
|
|
|
|
responseType: 'blob' // 表明返回服务器返回的数据类型
|
|
|
|
|
responseType: 'blob', // 表明返回服务器返回的数据类型
|
|
|
|
|
}).then(
|
|
|
|
|
response => {
|
|
|
|
|
(response) => {
|
|
|
|
|
resolve(response.data)
|
|
|
|
|
let blob = new Blob([response.data], {
|
|
|
|
|
type: 'application/png'
|
|
|
|
|
type: 'application/png',
|
|
|
|
|
})
|
|
|
|
|
console.log(blob)
|
|
|
|
|
let fileName = filename + '.png'
|
|
|
|
|
@ -306,24 +331,24 @@ export function downloadImg(url,filename, options = {}) {
|
|
|
|
|
window.URL.revokeObjectURL(link.href)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
err => {
|
|
|
|
|
(err) => {
|
|
|
|
|
reject(err)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function downloadFileToExcel(url,filename, options) {
|
|
|
|
|
export function downloadFileToExcel(url, filename, options) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
axios.defaults.headers['content-type'] = 'application/json'
|
|
|
|
|
axios.get(url, {params: options, responseType: 'blob'}).then(
|
|
|
|
|
response => {
|
|
|
|
|
resolve({success: true});
|
|
|
|
|
axios.get(url, { params: options, responseType: 'blob' }).then(
|
|
|
|
|
(response) => {
|
|
|
|
|
resolve({ success: true })
|
|
|
|
|
let blob = new Blob([response.data], {
|
|
|
|
|
type: 'application/vnd.ms-excel'
|
|
|
|
|
type: 'application/vnd.ms-excel',
|
|
|
|
|
})
|
|
|
|
|
console.log(blob)
|
|
|
|
|
let fileName = filename + '.xls';
|
|
|
|
|
let fileName = filename + '.xls'
|
|
|
|
|
if (window.navigator.msSaveOrOpenBlob) {
|
|
|
|
|
// console.log(2)
|
|
|
|
|
navigator.msSaveBlob(blob, fileName)
|
|
|
|
|
@ -336,9 +361,8 @@ export function downloadFileToExcel(url,filename, options) {
|
|
|
|
|
//释放内存
|
|
|
|
|
window.URL.revokeObjectURL(link.href)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
err => {
|
|
|
|
|
(err) => {
|
|
|
|
|
reject(err)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
@ -346,7 +370,7 @@ export function downloadFileToExcel(url,filename, options) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getBaseUrl() {
|
|
|
|
|
return axios.defaults.baseURL;
|
|
|
|
|
return axios.defaults.baseURL
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
@ -358,5 +382,5 @@ export default {
|
|
|
|
|
put,
|
|
|
|
|
fetchDelete,
|
|
|
|
|
getBaseUrl,
|
|
|
|
|
downloadFileToExcel
|
|
|
|
|
downloadFileToExcel,
|
|
|
|
|
}
|
|
|
|
|
|