Skip to content

Commit 5bcea67

Browse files
李宗李宗
authored andcommitted
release 0.3.1 version
1 parent 2bcc95c commit 5bcea67

File tree

7 files changed

+1060
-1114
lines changed

7 files changed

+1060
-1114
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33
## 0.1.0 / 2018-11-14
44

55
- 支持在小程序中使用axios
6+
7+
8+
## 0.3.1 / 2020-07-07
9+
10+
- fix: 修复在支付宝中 headers 设置无效的bug
11+
- change: 默认打包成 commonJs 模块

dist/index.aio.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* axios-miniprogram-adapter 0.2.4 (https://github.com/bigMeow/axios-miniprogram-adapter)
2+
* axios-miniprogram-adapter 0.3.1 (https://github.com/bigMeow/axios-miniprogram-adapter)
33
* API https://github.com/bigMeow/axios-miniprogram-adapter/blob/master/doc/api.md
44
* Copyright 2018-2020 bigMeow. All Rights Reserved
55
* Licensed under MIT (https://github.com/bigMeow/axios-miniprogram-adapter/blob/master/LICENSE)
@@ -8,14 +8,14 @@
88
(function (global, factory) {
99
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('axios/lib/utils'), require('axios/lib/core/settle'), require('axios/lib/helpers/buildURL'), require('axios/lib/core/buildFullPath'), require('axios/lib/core/createError')) :
1010
typeof define === 'function' && define.amd ? define(['axios/lib/utils', 'axios/lib/core/settle', 'axios/lib/helpers/buildURL', 'axios/lib/core/buildFullPath', 'axios/lib/core/createError'], factory) :
11-
(global['axios-miniprogram-adapter'] = factory(global.utils,global.settle,global.buildURL,global.buildFullPath,global.createError));
12-
}(this, (function (utils,settle,buildURL,buildFullPath,createError) { 'use strict';
11+
(global = global || self, global['axios-miniprogram-adapter'] = factory(global.utils, global.settle, global.buildURL, global.buildFullPath, global.createError));
12+
}(this, (function (utils, settle, buildURL, buildFullPath, createError) { 'use strict';
1313

14-
utils = utils && utils.hasOwnProperty('default') ? utils['default'] : utils;
15-
settle = settle && settle.hasOwnProperty('default') ? settle['default'] : settle;
16-
buildURL = buildURL && buildURL.hasOwnProperty('default') ? buildURL['default'] : buildURL;
17-
buildFullPath = buildFullPath && buildFullPath.hasOwnProperty('default') ? buildFullPath['default'] : buildFullPath;
18-
createError = createError && createError.hasOwnProperty('default') ? createError['default'] : createError;
14+
utils = utils && Object.prototype.hasOwnProperty.call(utils, 'default') ? utils['default'] : utils;
15+
settle = settle && Object.prototype.hasOwnProperty.call(settle, 'default') ? settle['default'] : settle;
16+
buildURL = buildURL && Object.prototype.hasOwnProperty.call(buildURL, 'default') ? buildURL['default'] : buildURL;
17+
buildFullPath = buildFullPath && Object.prototype.hasOwnProperty.call(buildFullPath, 'default') ? buildFullPath['default'] : buildFullPath;
18+
createError = createError && Object.prototype.hasOwnProperty.call(createError, 'default') ? createError['default'] : createError;
1919

2020
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
2121
// encoder
@@ -56,6 +56,14 @@
5656
platFormName = 'baidu';
5757
return swan.request.bind(swan);
5858
case typeof my === 'object':
59+
/**
60+
* remark:
61+
* 支付宝客户端已不再维护 my.httpRequest,建议使用 my.request。另外,钉钉客户端尚不支持 my.request。若在钉钉客户端开发小程序,则需要使用 my.httpRequest。
62+
* my.httpRequest的请求头默认值为{'content-type': 'application/x-www-form-urlencoded'}。
63+
* my.request的请求头默认值为{'content-type': 'application/json'}。
64+
* TODO: 区分支付宝和钉钉环境
65+
* 还有个 dd.httpRequest WFK!!! https://ding-doc.dingtalk.com/doc#/dev/httprequest
66+
*/
5967
platFormName = 'alipay';
6068
return (my.request || my.httpRequest).bind(my);
6169
default:
@@ -129,6 +137,17 @@
129137
reject(createError('Network Error', config, null, ''));
130138
break;
131139
}
140+
}
141+
/**
142+
* 将axios的请求配置,转换成各个平台都支持的请求config
143+
* @param config
144+
*/
145+
function transformConfig(config) {
146+
if (platFormName === 'alipay') {
147+
config.headers = config.header;
148+
delete config.header;
149+
}
150+
return config;
132151
}
133152

134153
var warn = console.warn;
@@ -207,7 +226,7 @@
207226
if (requestData !== undefined) {
208227
mpRequestOption.data = requestData;
209228
}
210-
requestTask = request(mpRequestOption);
229+
requestTask = request(transformConfig(mpRequestOption));
211230
});
212231
}
213232

dist/index.esm.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* axios-miniprogram-adapter 0.2.4 (https://github.com/bigMeow/axios-miniprogram-adapter)
2+
* axios-miniprogram-adapter 0.3.1 (https://github.com/bigMeow/axios-miniprogram-adapter)
33
* API https://github.com/bigMeow/axios-miniprogram-adapter/blob/master/doc/api.md
44
* Copyright 2018-2020 bigMeow. All Rights Reserved
55
* Licensed under MIT (https://github.com/bigMeow/axios-miniprogram-adapter/blob/master/LICENSE)
@@ -50,6 +50,14 @@ function getRequest() {
5050
platFormName = 'baidu';
5151
return swan.request.bind(swan);
5252
case typeof my === 'object':
53+
/**
54+
* remark:
55+
* 支付宝客户端已不再维护 my.httpRequest,建议使用 my.request。另外,钉钉客户端尚不支持 my.request。若在钉钉客户端开发小程序,则需要使用 my.httpRequest。
56+
* my.httpRequest的请求头默认值为{'content-type': 'application/x-www-form-urlencoded'}。
57+
* my.request的请求头默认值为{'content-type': 'application/json'}。
58+
* TODO: 区分支付宝和钉钉环境
59+
* 还有个 dd.httpRequest WFK!!! https://ding-doc.dingtalk.com/doc#/dev/httprequest
60+
*/
5361
platFormName = 'alipay';
5462
return (my.request || my.httpRequest).bind(my);
5563
default:
@@ -123,6 +131,17 @@ function transformError(error, reject, config) {
123131
reject(createError('Network Error', config, null, ''));
124132
break;
125133
}
134+
}
135+
/**
136+
* 将axios的请求配置,转换成各个平台都支持的请求config
137+
* @param config
138+
*/
139+
function transformConfig(config) {
140+
if (platFormName === 'alipay') {
141+
config.headers = config.header;
142+
delete config.header;
143+
}
144+
return config;
126145
}
127146

128147
var warn = console.warn;
@@ -201,7 +220,7 @@ function mpAdapter(config) {
201220
if (requestData !== undefined) {
202221
mpRequestOption.data = requestData;
203222
}
204-
requestTask = request(mpRequestOption);
223+
requestTask = request(transformConfig(mpRequestOption));
205224
});
206225
}
207226

dist/index.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* axios-miniprogram-adapter 0.2.4 (https://github.com/bigMeow/axios-miniprogram-adapter)
2+
* axios-miniprogram-adapter 0.3.1 (https://github.com/bigMeow/axios-miniprogram-adapter)
33
* API https://github.com/bigMeow/axios-miniprogram-adapter/blob/master/doc/api.md
44
* Copyright 2018-2020 bigMeow. All Rights Reserved
55
* Licensed under MIT (https://github.com/bigMeow/axios-miniprogram-adapter/blob/master/LICENSE)
@@ -54,6 +54,14 @@ function getRequest() {
5454
platFormName = 'baidu';
5555
return swan.request.bind(swan);
5656
case typeof my === 'object':
57+
/**
58+
* remark:
59+
* 支付宝客户端已不再维护 my.httpRequest,建议使用 my.request。另外,钉钉客户端尚不支持 my.request。若在钉钉客户端开发小程序,则需要使用 my.httpRequest。
60+
* my.httpRequest的请求头默认值为{'content-type': 'application/x-www-form-urlencoded'}。
61+
* my.request的请求头默认值为{'content-type': 'application/json'}。
62+
* TODO: 区分支付宝和钉钉环境
63+
* 还有个 dd.httpRequest WFK!!! https://ding-doc.dingtalk.com/doc#/dev/httprequest
64+
*/
5765
platFormName = 'alipay';
5866
return (my.request || my.httpRequest).bind(my);
5967
default:
@@ -127,6 +135,17 @@ function transformError(error, reject, config) {
127135
reject(createError('Network Error', config, null, ''));
128136
break;
129137
}
138+
}
139+
/**
140+
* 将axios的请求配置,转换成各个平台都支持的请求config
141+
* @param config
142+
*/
143+
function transformConfig(config) {
144+
if (platFormName === 'alipay') {
145+
config.headers = config.header;
146+
delete config.header;
147+
}
148+
return config;
130149
}
131150

132151
var warn = console.warn;
@@ -205,7 +224,7 @@ function mpAdapter(config) {
205224
if (requestData !== undefined) {
206225
mpRequestOption.data = requestData;
207226
}
208-
requestTask = request(mpRequestOption);
227+
requestTask = request(transformConfig(mpRequestOption));
209228
});
210229
}
211230

0 commit comments

Comments
 (0)