|
@ -1,202 +1,94 @@ |
|
|
import Vue from 'vue' |
|
|
import Vue from 'vue' |
|
|
import axios from 'axios' |
|
|
import axios from 'axios' |
|
|
import qs from 'qs' |
|
|
import SystemConfiguration from './SystemConfiguration.js'; |
|
|
import md5 from 'js-md5'; |
|
|
|
|
|
import constant from './constant.js'; |
|
|
|
|
|
|
|
|
|
|
|
// #ifdef H5
|
|
|
let baseURL = SystemConfiguration.constant |
|
|
let baseURL = constant.H5 |
|
|
|
|
|
let key = constant.H5_KEY |
|
|
|
|
|
// #endif
|
|
|
|
|
|
// #ifdef APP-PLUS
|
|
|
|
|
|
let baseURL = constant.APP |
|
|
|
|
|
let key = constant.APP_KEY |
|
|
|
|
|
// #endif
|
|
|
|
|
|
const service = axios.create({ |
|
|
const service = axios.create({ |
|
|
withCredentials: true, |
|
|
withCredentials: false, //表示跨域请求时是否需要使用凭证
|
|
|
crossDomain: true, |
|
|
crossDomain: true, |
|
|
baseURL, |
|
|
// baseURL,
|
|
|
timeout: 160000 |
|
|
timeout: 160000 |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
// request拦截器,在请求之前做一些处理
|
|
|
// request请求拦截器,在请求之前做一些处理
|
|
|
// service.interceptors.request.use(
|
|
|
service.interceptors.request.use( |
|
|
// config => {
|
|
|
config => { |
|
|
// // console.log('showDialog' + Vue.prototype.$showDialog)
|
|
|
|
|
|
// if (Vue.prototype.$showDialog) {
|
|
|
|
|
|
// uni.showLoading({
|
|
|
|
|
|
// title: 'loading',
|
|
|
|
|
|
// mask: true
|
|
|
|
|
|
// })
|
|
|
|
|
|
// }
|
|
|
|
|
|
// const ticket = uni.getStorageSync('ticket')
|
|
|
|
|
|
// let dataStr = [];
|
|
|
|
|
|
// if (config.method == 'get') {
|
|
|
|
|
|
// if (config.url.split('?').length > 1) {
|
|
|
|
|
|
// dataStr = config.url.split('?')[1].split('&');
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (config.method == 'post') {
|
|
|
|
|
|
// dataStr = qs.stringify(config.data).split('&');
|
|
|
|
|
|
// // dataStr = JSON.stringify(config.data);
|
|
|
|
|
|
// // dataStr = config.data;
|
|
|
|
|
|
|
|
|
|
|
|
// // dataStr = config.data.name;
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
// config.data = {};
|
|
|
|
|
|
// dataStr.forEach(function(e) {
|
|
|
|
|
|
// console.log(e,666666)
|
|
|
|
|
|
// config.data[e.split('=')[0]] = e.split('=')[1];
|
|
|
|
|
|
// });
|
|
|
|
|
|
// // console.log(ticket)
|
|
|
|
|
|
// if (ticket != '') {
|
|
|
|
|
|
// config.data['ticket'] = ticket
|
|
|
|
|
|
// }
|
|
|
|
|
|
// var keys = [];
|
|
|
|
|
|
// let sign = '';
|
|
|
|
|
|
// for (var k in config.data)
|
|
|
|
|
|
// keys.push(k);
|
|
|
|
|
|
// keys.sort(function(a, b) {
|
|
|
|
|
|
// return a < b ? -1 : 1;
|
|
|
|
|
|
// })
|
|
|
|
|
|
// // console.log("keys===========");
|
|
|
|
|
|
// keys.forEach(function(e) {
|
|
|
|
|
|
// if (config.data[e] || config.data[e] == '') {
|
|
|
|
|
|
// sign += e + '=' + config.data[e] + '&'
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
// // console.log("签名参数===========");
|
|
|
|
|
|
// // console.log(config.url);
|
|
|
|
|
|
// // console.log(sign + key);
|
|
|
|
|
|
// sign = md5(sign + key);
|
|
|
|
|
|
// // console.log("提交参数===========");
|
|
|
|
|
|
// // console.log(qs.stringify(config.data));
|
|
|
|
|
|
// if (config.method == 'post') {
|
|
|
|
|
|
// // console.log(config.data,666666)
|
|
|
|
|
|
// config.data['sign'] = sign
|
|
|
|
|
|
// config.data = qs.stringify(config.data)
|
|
|
|
|
|
// // config.data = config.data.replace(/(\w+)\s*, \s*(\w+)/, "$2 $1");
|
|
|
|
|
|
// // if(config.url == ){
|
|
|
|
|
|
|
|
|
|
|
|
// // #ifdef H5
|
|
|
|
|
|
// if(config.url=='/api/index/goodsList'){
|
|
|
|
|
|
// config.data = config.data.replaceAll('20', "");
|
|
|
|
|
|
// config.data = config.data.replaceAll('26', "");
|
|
|
|
|
|
// config.data = config.data.replaceAll('2F', "/");
|
|
|
|
|
|
// config.data = config.data.replaceAll('28', "");
|
|
|
|
|
|
// config.data = config.data.replaceAll('29', "");
|
|
|
|
|
|
// // config.data = config.data.replaceAll('%C2%AE', "®");
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // #endif
|
|
|
|
|
|
// // #ifdef APP-PLUS
|
|
|
|
|
|
// if(config.url=='/api/index/goodsList'){
|
|
|
|
|
|
// config.data = config.data.replace(new RegExp('20',"gm"), "");
|
|
|
|
|
|
// config.data = config.data.replace(new RegExp('26',"gm"), "");
|
|
|
|
|
|
// config.data = config.data.replace(new RegExp('2F',"gm"), "/");
|
|
|
|
|
|
// config.data = config.data.replace(new RegExp('28',"gm"), "");
|
|
|
|
|
|
// config.data = config.data.replace(new RegExp('29',"gm"), "");
|
|
|
|
|
|
// // config.data = config.data.replaceAll('%C2%AE', "®");
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // #endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // config.data = config.data.replaceAll('2528',"(");
|
|
|
|
|
|
// // config.data = config.data.replaceAll('2529',")");
|
|
|
|
|
|
// // config.data = config.data.replaceAll('252',"%2F");
|
|
|
|
|
|
|
|
|
|
|
|
// // }
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (config.method == 'get') {
|
|
|
|
|
|
// if (ticket != '') {
|
|
|
|
|
|
// config.url = config.url + '&ticket=' + ticket + '&sign=' + sign
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// config.url = config.url + '?sign=' + sign
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // console.log(config)
|
|
|
|
|
|
// return config;
|
|
|
|
|
|
// },
|
|
|
|
|
|
// error => {
|
|
|
|
|
|
// // console.log(error); // for debug
|
|
|
|
|
|
// return Promise.reject(error);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
// //配置成功后的拦截器
|
|
|
console.log(config) |
|
|
// service.interceptors.response.use(res => {
|
|
|
uni.showLoading({ |
|
|
// console.log('过期了吗')
|
|
|
title: 'loading', |
|
|
// uni.hideLoading()
|
|
|
mask: true |
|
|
// // console.log(res)
|
|
|
}) |
|
|
// // console.log(res.data)
|
|
|
console.log('============================') |
|
|
// // console.log(res.data.data[0].nameAlias)
|
|
|
if (config.urlType == 'eth') { |
|
|
// if (res.data.success || res.data.errCode === 'USER.0017') {
|
|
|
config.url = baseURL.serverUrl + config.url |
|
|
// // console.log(res.data.success)
|
|
|
console.log(config.url) |
|
|
// return res.data
|
|
|
} else { |
|
|
// } else {
|
|
|
|
|
|
// uni.showToast({
|
|
|
|
|
|
// title: res.data.errMsg,
|
|
|
|
|
|
// icon: 'none',
|
|
|
|
|
|
// duration: 1500
|
|
|
|
|
|
// })
|
|
|
|
|
|
// if (res.data.errCode === 'USER.0010') {
|
|
|
|
|
|
|
|
|
|
|
|
// uni.removeStorage({
|
|
|
config.url = baseURL.serverUrl + config.url |
|
|
// key: 'logInfo',
|
|
|
} |
|
|
// success: function (res) {
|
|
|
|
|
|
// uni.reLaunch({url: '/pages/login/index'})
|
|
|
|
|
|
// },
|
|
|
|
|
|
// fail: (err) => {
|
|
|
|
|
|
// }
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // #ifdef H5
|
|
|
// if (token) {
|
|
|
// var url = location.href;
|
|
|
// // config.headers['Authori-zation'] = token
|
|
|
// if(url.indexOf('pages')>-1){
|
|
|
// config.headers['Authorization'] = token
|
|
|
// uni.setStorage({
|
|
|
|
|
|
// key: 'url',
|
|
|
|
|
|
// data: url,
|
|
|
|
|
|
// success: function() {
|
|
|
|
|
|
// console.log('success')
|
|
|
|
|
|
// }
|
|
|
// }
|
|
|
// });
|
|
|
// console.log(config)
|
|
|
// }else{
|
|
|
// if (store.state.token) {
|
|
|
// uni.removeStorageSync('url')
|
|
|
// // 给请求头添加user-token
|
|
|
|
|
|
// config.headers["user-token"] = store.state.token;
|
|
|
// }
|
|
|
// }
|
|
|
// // #endif
|
|
|
console.log('请求之前成功') |
|
|
|
|
|
return config; |
|
|
|
|
|
}, |
|
|
|
|
|
error => { |
|
|
|
|
|
console.log(error); // for debug
|
|
|
|
|
|
return Promise.reject(error); |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// 配置成功后的响应拦截器
|
|
|
|
|
|
service.interceptors.response.use(res => { |
|
|
|
|
|
uni.hideLoading() |
|
|
|
|
|
console.log(res) |
|
|
|
|
|
if (res.status == 200) { |
|
|
|
|
|
return res.data |
|
|
|
|
|
} else { |
|
|
|
|
|
return Promise.reject(res.msg); |
|
|
|
|
|
} |
|
|
|
|
|
}, error => { |
|
|
|
|
|
// if (error.response.status) {
|
|
|
|
|
|
// switch (error.response.status) {
|
|
|
|
|
|
// case 401:
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// default:
|
|
|
|
|
|
// break;
|
|
|
// }
|
|
|
// }
|
|
|
// uni.$emit('refreshQrCode')
|
|
|
|
|
|
// return Promise.reject(res.data.errMsg);
|
|
|
|
|
|
// }
|
|
|
// }
|
|
|
// }, error => {
|
|
|
return Promise.reject(error) |
|
|
// return Promise.reject(error)
|
|
|
}) |
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
axios.defaults.adapter = function(config) { //自己定义个适配器,用来适配uniapp的语法
|
|
|
// 在main.js中放入这段自定义适配器的代码,就可以实现uniapp的app和小程序开发中能使用axios进行跨域网络请求,并支持携带cookie
|
|
|
|
|
|
axios.defaults.adapter = function(config) { |
|
|
return new Promise((resolve, reject) => { |
|
|
return new Promise((resolve, reject) => { |
|
|
// console.log(config)
|
|
|
console.log(config) |
|
|
var settle = require('axios/lib/core/settle'); |
|
|
var settle = require('axios/lib/core/settle'); |
|
|
var buildURL = require('axios/lib/helpers/buildURL'); |
|
|
var buildURL = require('axios/lib/helpers/buildURL'); |
|
|
|
|
|
|
|
|
|
|
|
if(config.baseURL == SystemConfiguration.constant.tronChainUrl){ |
|
|
|
|
|
// return;
|
|
|
|
|
|
config.url = config.baseURL + '/' + config.url |
|
|
|
|
|
// console.log(config.url)
|
|
|
|
|
|
} |
|
|
uni.request({ |
|
|
uni.request({ |
|
|
method: config.method.toUpperCase(), |
|
|
method: config.method.toUpperCase(), |
|
|
// url: config.baseURL + buildURL(config.url, config.params, config.paramsSerializer),
|
|
|
url: buildURL(config.url, config.params, config.paramsSerializer), |
|
|
url: config.baseURL + '/' + config.url, |
|
|
|
|
|
header: config.headers, |
|
|
header: config.headers, |
|
|
data: config.data, |
|
|
data: config.data, |
|
|
dataType: config.dataType, |
|
|
dataType: config.dataType, |
|
|
responseType: config.responseType, |
|
|
responseType: config.responseType, |
|
|
sslVerify: config.sslVerify, |
|
|
sslVerify: config.sslVerify, |
|
|
complete: function complete(response) { |
|
|
complete: function complete(response) { |
|
|
//console.log("执行完成:",config.baseURL + buildURL(config.url, config.params, config.paramsSerializer),response.data)
|
|
|
|
|
|
response = { |
|
|
response = { |
|
|
data: response.data, |
|
|
data: response.data, |
|
|
status: response.statusCode, |
|
|
status: response.statusCode, |
|
@ -204,17 +96,12 @@ axios.defaults.adapter = function(config) { //自己定义个适配器,用来 |
|
|
header: response.header, |
|
|
header: response.header, |
|
|
config: config |
|
|
config: config |
|
|
}; |
|
|
}; |
|
|
|
|
|
// console.log(response)
|
|
|
settle(resolve, reject, response); |
|
|
settle(resolve, reject, response); |
|
|
}, |
|
|
|
|
|
fail: res => { |
|
|
|
|
|
uni.showToast({ |
|
|
|
|
|
title: res, |
|
|
|
|
|
icon: 'none', |
|
|
|
|
|
duration: 1500 |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default service |
|
|
export default service |
|
|