@10yun/cv-mobile-ui 0.5.29 → 0.5.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugins/luch-request/adapters/index.js +131 -0
- package/plugins/luch-request/core/InterceptorManager.js +50 -0
- package/plugins/luch-request/core/Request.js +199 -0
- package/plugins/luch-request/core/buildFullPath.js +20 -0
- package/plugins/luch-request/core/defaults.js +32 -0
- package/plugins/luch-request/core/dispatchRequest.js +5 -0
- package/plugins/luch-request/core/mergeConfig.js +125 -0
- package/plugins/luch-request/core/settle.js +16 -0
- package/plugins/luch-request/helpers/buildURL.js +71 -0
- package/plugins/luch-request/helpers/combineURLs.js +12 -0
- package/plugins/luch-request/helpers/isAbsoluteURL.js +14 -0
- package/plugins/luch-request/index.d.ts +197 -0
- package/plugins/luch-request/index.js +2 -0
- package/plugins/luch-request/readme.md +3 -0
- package/plugins/luch-request/utils/clone.js +264 -0
- package/plugins/luch-request/utils.js +131 -0
- package/plugins/request.js +2 -2
- package/ui-cv/components/cv-form-item/cv-form-item.vue +1 -1
- package/ui-fireui/fui-actionsheet/fui-actionsheet.vue +202 -0
- package/ui-fireui/fui-alert/fui-alert.vue +141 -0
- package/ui-fireui/fui-badge/fui-badge.vue +158 -0
- package/ui-fireui/fui-bottom-navigation/fui-bottom-navigation.vue +390 -0
- package/ui-fireui/fui-bottom-popup/fui-bottom-popup.vue +100 -0
- package/ui-fireui/fui-bubble-popup/fui-bubble-popup.vue +236 -0
- package/ui-fireui/fui-button/fui-button.vue +424 -0
- package/ui-fireui/fui-calendar/fui-calendar.js +915 -0
- package/ui-fireui/fui-calendar/fui-calendar.vue +868 -0
- package/ui-fireui/fui-card/fui-card.vue +231 -0
- package/ui-fireui/fui-cascade-selection/fui-cascade-selection.vue +538 -0
- package/ui-fireui/fui-circular-progress/fui-circular-progress.vue +261 -0
- package/ui-fireui/fui-collapse/fui-collapse.vue +179 -0
- package/ui-fireui/fui-countdown/fui-countdown.vue +301 -0
- package/ui-fireui/fui-datetime/fui-datetime.vue +570 -0
- package/ui-fireui/fui-divider/fui-divider.vue +118 -0
- package/ui-fireui/fui-drawer/fui-drawer.vue +103 -0
- package/ui-fireui/fui-dropdown-list/fui-dropdown-list.vue +70 -0
- package/ui-fireui/fui-fab/fui-fab.vue +284 -0
- package/ui-fireui/fui-footer/fui-footer.vue +131 -0
- package/ui-fireui/fui-grid/fui-grid.vue +42 -0
- package/ui-fireui/fui-grid-item/fui-grid-item.vue +142 -0
- package/ui-fireui/fui-icon/fui-icon.vue +820 -0
- package/ui-fireui/fui-image-cropper/fui-image-cropper.vue +1058 -0
- package/ui-fireui/fui-image-group/fui-image-group.vue +149 -0
- package/ui-fireui/fui-keyboard/fui-keyboard.vue +254 -0
- package/ui-fireui/fui-keyboard-input/fui-keyboard-input.vue +78 -0
- package/ui-fireui/fui-list-cell/fui-list-cell.vue +178 -0
- package/ui-fireui/fui-list-view/fui-list-view.vue +87 -0
- package/ui-fireui/fui-loading/fui-loading.vue +78 -0
- package/ui-fireui/fui-loadmore/fui-loadmore.vue +163 -0
- package/ui-fireui/fui-modal/fui-modal.vue +392 -0
- package/ui-fireui/fui-navigation-bar/fui-navigation-bar.vue +180 -0
- package/ui-fireui/fui-no-data/fui-no-data.vue +116 -0
- package/ui-fireui/fui-nomore/fui-nomore.vue +116 -0
- package/ui-fireui/fui-numberbox/fui-numberbox.vue +234 -0
- package/ui-fireui/fui-numberbox-border/fui-numberbox-border.vue +232 -0
- package/ui-fireui/fui-picture-cropper/fui-picture-cropper.vue +682 -0
- package/ui-fireui/fui-picture-cropper/fui-picture-cropper.wxs +560 -0
- package/ui-fireui/fui-rate/fui-rate.vue +167 -0
- package/ui-fireui/fui-round-progress/fui-round-progress.vue +306 -0
- package/ui-fireui/fui-scroll-top/fui-scroll-top.vue +189 -0
- package/ui-fireui/fui-sharemodel/fui-sharemodel.vue +181 -0
- package/ui-fireui/fui-skeleton/fui-skeleton.vue +248 -0
- package/ui-fireui/fui-steps/fui-steps.vue +214 -0
- package/ui-fireui/fui-sticky/fui-sticky.vue +155 -0
- package/ui-fireui/fui-sticky-wxs/fui-sticky-wxs.vue +133 -0
- package/ui-fireui/fui-sticky-wxs/fui-sticky.wxs +44 -0
- package/ui-fireui/fui-swipe-action/fui-swipe-action.vue +301 -0
- package/ui-fireui/fui-tabbar/fui-tabbar.vue +283 -0
- package/ui-fireui/fui-tabs/fui-tabs.vue +284 -0
- package/ui-fireui/fui-tabs2/fui-tabs2.vue +284 -0
- package/ui-fireui/fui-tag/fui-tag.vue +374 -0
- package/ui-fireui/fui-time-axis/fui-time-axis.vue +36 -0
- package/ui-fireui/fui-timeaxis-item/fui-timeaxis-item.vue +48 -0
- package/ui-fireui/fui-tips/fui-tips.vue +161 -0
- package/ui-fireui/fui-toast/fui-toast.vue +117 -0
- package/ui-fireui/fui-top-dropdown/fui-top-dropdown.vue +129 -0
- package/ui-fireui/fui-upload/fui-upload.vue +446 -0
- package/ui-fireui/fui-uploadsamll/fui-uploadsamll.vue +472 -0
- package/uview-plus/README.md +1 -1
- package/uview-plus/changelog-wu-tool.md +21 -0
- package/uview-plus/changelog-wu.md +91 -0
- package/uview-plus/components/u-action-sheet/_doc/changelog.md +12 -0
- package/uview-plus/components/u-action-sheet/_doc/package.json +92 -0
- package/uview-plus/components/u-action-sheet/_doc/readme.md +16 -0
- package/uview-plus/components/u-app-update/_doc/changelog.md +26 -0
- package/uview-plus/components/u-app-update/_doc/package.json +89 -0
- package/uview-plus/components/u-app-update/_doc/readme.md +16 -0
- package/uview-plus/components/u-app-update/config.js +120 -0
- package/uview-plus/components/u-app-update/img/act.png +0 -0
- package/uview-plus/components/u-app-update/img/appUploadAlertBoxBg.png +0 -0
- package/uview-plus/components/u-app-update/img/close.png +0 -0
- package/uview-plus/components/u-app-update/js-sdk/checkVersion.js +81 -0
- package/uview-plus/components/u-app-update/js-sdk/silentlyAppUpdate.js +41 -0
- package/uview-plus/components/u-app-update/pages/index.vue +8 -0
- package/uview-plus/components/u-app-update/u-app-update.vue +583 -0
- package/uview-plus/components/u-button-wu/_doc/changelog.md +6 -0
- package/uview-plus/components/u-button-wu/_doc/package.json +89 -0
- package/uview-plus/components/u-button-wu/_doc/readme.md +16 -0
- package/uview-plus/components/u-button-wu/u-button-wu.vue +522 -0
- package/uview-plus/components/u-button-wu/vue.scss +81 -0
- package/uview-plus/components/u-calendar-wu/_doc/changelog.md +145 -0
- package/uview-plus/components/u-calendar-wu/_doc/package.json +90 -0
- package/uview-plus/components/u-calendar-wu/_doc/readme.md +16 -0
- package/uview-plus/components/u-calendar-wu/calendar.js +664 -0
- package/uview-plus/components/u-calendar-wu/i18n/en.json +14 -0
- package/uview-plus/components/u-calendar-wu/i18n/index.js +8 -0
- package/uview-plus/components/u-calendar-wu/i18n/zh-Hans.json +14 -0
- package/uview-plus/components/u-calendar-wu/i18n/zh-Hant.json +14 -0
- package/uview-plus/components/u-calendar-wu/props.js +166 -0
- package/uview-plus/components/u-calendar-wu/style.css +196 -0
- package/uview-plus/components/u-calendar-wu/u-calendar-wu.vue +921 -0
- package/uview-plus/components/u-calendar-wu/util.js +552 -0
- package/uview-plus/components/u-calendar-wu/wu-calendar-block/props.js +73 -0
- package/uview-plus/components/u-calendar-wu/wu-calendar-block/wu-calendar-block.vue +122 -0
- package/uview-plus/components/u-calendar-wu/wu-calendar-item/props.js +55 -0
- package/uview-plus/components/u-calendar-wu/wu-calendar-item/wu-calendar-item.vue +293 -0
- package/uview-plus/components/u-cell/_doc/changelog.md +6 -0
- package/uview-plus/components/u-cell/_doc/package.json +89 -0
- package/uview-plus/components/u-cell/_doc/readme.md +25 -0
- package/uview-plus/components/u-checkbox/_doc/changelog.md +8 -0
- package/uview-plus/components/u-checkbox/_doc/package.json +88 -0
- package/uview-plus/components/u-checkbox/_doc/readme.md +25 -0
- package/uview-plus/components/u-code/_doc/changelog.md +6 -0
- package/uview-plus/components/u-code/_doc/package.json +86 -0
- package/uview-plus/components/u-code/_doc/readme.md +16 -0
- package/uview-plus/components/u-drag-sort/_doc/changelog.md +0 -0
- package/uview-plus/components/u-drag-sort/_doc/package.json +85 -0
- package/uview-plus/components/u-drag-sort/_doc/readme.md +16 -0
- package/uview-plus/components/u-drag-sort/u-drag-sort.vue +3 -0
- package/uview-plus/components/u-empty/u-empty.vue +27 -1
- package/uview-plus/components/u-gap/_doc/changelog.md +4 -0
- package/uview-plus/components/u-gap/_doc/package.json +86 -0
- package/uview-plus/components/u-gap/_doc/readme.md +22 -0
- package/uview-plus/components/u-icon/_doc/changelog.md +10 -0
- package/uview-plus/components/u-icon/_doc/package.json +85 -0
- package/uview-plus/components/u-icon/_doc/readme.md +10 -0
- package/uview-plus/components/u-icon/icon.js +23 -25
- package/uview-plus/components/u-icon/icons.js +213 -213
- package/uview-plus/components/u-icon/style.css +3 -3
- package/uview-plus/components/u-icon/u-icon2.vue +149 -0
- package/uview-plus/components/u-image-wu/_doc/changelog.md +21 -0
- package/uview-plus/components/u-image-wu/_doc/package.json +88 -0
- package/uview-plus/components/u-image-wu/_doc/readme.md +11 -0
- package/uview-plus/components/u-image-wu/props.js +94 -0
- package/uview-plus/components/u-image-wu/u-image-wu.vue +243 -0
- package/uview-plus/components/u-input/_doc/changelog.md +6 -0
- package/uview-plus/components/u-input/_doc/package.json +88 -0
- package/uview-plus/components/u-input/_doc/readme.md +16 -0
- package/uview-plus/components/u-line/_doc/changelog.md +8 -0
- package/uview-plus/components/u-line/_doc/package.json +86 -0
- package/uview-plus/components/u-line/_doc/readme.md +16 -0
- package/uview-plus/components/u-link/_doc/changelog.md +8 -0
- package/uview-plus/components/u-link/_doc/package.json +86 -0
- package/uview-plus/components/u-link/_doc/readme.md +20 -0
- package/uview-plus/components/u-loading-icon/_doc/changelog.md +12 -0
- package/uview-plus/components/u-loading-icon/_doc/package.json +86 -0
- package/uview-plus/components/u-loading-icon/_doc/readme.md +16 -0
- package/uview-plus/components/u-loading-icon/props.js +1 -1
- package/uview-plus/components/u-navbar/_doc/changelog.md +6 -0
- package/uview-plus/components/u-navbar/_doc/package.json +89 -0
- package/uview-plus/components/u-navbar/_doc/readme.md +16 -0
- package/uview-plus/components/u-navbar-wu/props.js +102 -0
- package/uview-plus/components/u-navbar-wu/u-navbar-wu.vue +196 -0
- package/uview-plus/components/u-number-box/_doc/changelog.md +19 -0
- package/uview-plus/components/u-number-box/_doc/package.json +88 -0
- package/uview-plus/components/u-number-box/_doc/readme.md +16 -0
- package/uview-plus/components/u-overlay/_doc/changelog.md +4 -0
- package/uview-plus/components/u-overlay/_doc/package.json +88 -0
- package/uview-plus/components/u-overlay/_doc/readme.md +16 -0
- package/uview-plus/components/u-popup/_doc/changelog.md +4 -0
- package/uview-plus/components/u-popup/_doc/package.json +92 -0
- package/uview-plus/components/u-popup/_doc/readme.md +16 -0
- package/uview-plus/components/u-popup-wu/keypress.js +45 -0
- package/uview-plus/components/u-popup-wu/u-popup-wu.vue +519 -0
- package/uview-plus/components/u-radio/_doc/changelog.md +6 -0
- package/uview-plus/components/u-radio/_doc/package.json +88 -0
- package/uview-plus/components/u-radio/_doc/readme.md +25 -0
- package/uview-plus/components/u-row/_doc/changelog.md +8 -0
- package/uview-plus/components/u-row/_doc/package.json +86 -0
- package/uview-plus/components/u-row/_doc/readme.md +16 -0
- package/uview-plus/components/u-safe-bottom/_doc/changelog.md +6 -0
- package/uview-plus/components/u-safe-bottom/_doc/package.json +86 -0
- package/uview-plus/components/u-safe-bottom/_doc/readme.md +16 -0
- package/uview-plus/components/u-sku-wu/_doc/changelog.md +27 -0
- package/uview-plus/components/u-sku-wu/_doc/package.json +93 -0
- package/uview-plus/components/u-sku-wu/_doc/readme.md +16 -0
- package/uview-plus/components/u-sku-wu/props.js +86 -0
- package/uview-plus/components/u-sku-wu/style.css +271 -0
- package/uview-plus/components/u-sku-wu/u-sku-wu.vue +864 -0
- package/uview-plus/components/u-status-bar/_doc/changelog.md +4 -0
- package/uview-plus/components/u-status-bar/_doc/package.json +86 -0
- package/uview-plus/components/u-status-bar/_doc/readme.md +16 -0
- package/uview-plus/components/u-text/_doc/changelog.md +10 -0
- package/uview-plus/components/u-text/_doc/package.json +89 -0
- package/uview-plus/components/u-text/_doc/readme.md +20 -0
- package/uview-plus/components/u-textarea/_doc/changelog.md +6 -0
- package/uview-plus/components/u-textarea/_doc/package.json +86 -0
- package/uview-plus/components/u-textarea/_doc/readme.md +25 -0
- package/uview-plus/components/u-transition/_doc/changelog.md +14 -0
- package/uview-plus/components/u-transition/_doc/package.json +86 -0
- package/uview-plus/components/u-transition/_doc/readme.md +16 -0
- package/uview-plus/components/u-transition-wu/createAnimation.js +148 -0
- package/uview-plus/components/u-transition-wu/props.js +32 -0
- package/uview-plus/components/u-transition-wu/u-transition.vue +300 -0
- package/uview-plus/components/u-verification-code/u-verification-code.vue +161 -0
- package/uview-plus/index.js +107 -94
- package/uview-plus/libs/config/config.js +46 -48
- package/uview-plus/libs/css/color.scss +32 -311
- package/uview-plus/libs/css/components-wu.scss +30 -0
- package/uview-plus/libs/css/vue.scss +10 -10
- package/uview-plus/libs/function/calc.js +61 -55
- package/uview-plus/libs/function/cc.js +66 -0
- package/uview-plus/libs/function/color/color-convert/CHANGELOG.md +54 -0
- package/uview-plus/libs/function/color/color-convert/LICENSE +21 -0
- package/uview-plus/libs/function/color/color-convert/README.md +68 -0
- package/uview-plus/libs/function/color/color-convert/conversions.js +839 -0
- package/uview-plus/libs/function/color/color-convert/index.js +81 -0
- package/uview-plus/libs/function/color/color-convert/package.json +48 -0
- package/uview-plus/libs/function/color/color-convert/route.js +97 -0
- package/uview-plus/libs/function/color/color-name/LICENSE +8 -0
- package/uview-plus/libs/function/color/color-name/README.md +11 -0
- package/uview-plus/libs/function/color/color-name/index.js +152 -0
- package/uview-plus/libs/function/color/color-name/package.json +28 -0
- package/uview-plus/libs/function/color/color-string/LICENSE +21 -0
- package/uview-plus/libs/function/color/color-string/README.md +62 -0
- package/uview-plus/libs/function/color/color-string/index.js +244 -0
- package/uview-plus/libs/function/color/color-string/package.json +39 -0
- package/uview-plus/libs/function/color/color.js +496 -0
- package/uview-plus/libs/function/color/index.js +158 -0
- package/uview-plus/libs/function/color/is-arrayish/LICENSE +21 -0
- package/uview-plus/libs/function/color/is-arrayish/README.md +16 -0
- package/uview-plus/libs/function/color/is-arrayish/index.js +9 -0
- package/uview-plus/libs/function/color/is-arrayish/package.json +45 -0
- package/uview-plus/libs/function/color/is-arrayish/yarn-error.log +1443 -0
- package/uview-plus/libs/function/color/simple-swizzle/LICENSE +21 -0
- package/uview-plus/libs/function/color/simple-swizzle/README.md +39 -0
- package/uview-plus/libs/function/color/simple-swizzle/index.js +29 -0
- package/uview-plus/libs/function/color/simple-swizzle/package.json +36 -0
- package/uview-plus/libs/function/colorGradient.js +108 -106
- package/uview-plus/libs/function/debounce.js +17 -17
- package/uview-plus/libs/function/digit.js +1 -3
- package/uview-plus/libs/function/http.js +3 -3
- package/uview-plus/libs/function/index-wu.js +231 -0
- package/uview-plus/libs/function/index.js +579 -566
- package/uview-plus/libs/function/platform.js +18 -18
- package/uview-plus/libs/function/test.js +135 -137
- package/uview-plus/libs/function/throttle.js +17 -17
- package/uview-plus/libs/luch-request/core/Request.js +199 -199
- package/uview-plus/libs/mixin/mpMixin.js +1 -0
- package/uview-plus/libs/mixin/openType.js +33 -0
- package/uview-plus/libs/util/async-validator.js +1343 -1343
- package/uview-plus/libs/util/dayjs.js +404 -0
- package/uview-plus/libs/util/route.js +101 -105
- package/uview-plus/package-wu-tool.json +84 -0
- package/uview-plus/package-wu.json +112 -0
- package/uview-plus/package.json +106 -95
- package/uview-plus/readme-wu.md +148 -0
- package/uview-ui/index.js +51 -52
- package/plugins/uni-upgrade.js +0 -294
package/package.json
CHANGED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import buildURL from '../helpers/buildURL';
|
|
2
|
+
import buildFullPath from '../core/buildFullPath';
|
|
3
|
+
import settle from '../core/settle';
|
|
4
|
+
import { isUndefined } from '../utils';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 返回可选值存在的配置
|
|
8
|
+
* @param {Array} keys - 可选值数组
|
|
9
|
+
* @param {Object} config2 - 配置
|
|
10
|
+
* @return {{}} - 存在的配置项
|
|
11
|
+
*/
|
|
12
|
+
const mergeKeys = (keys, config2) => {
|
|
13
|
+
let config = {};
|
|
14
|
+
keys.forEach((prop) => {
|
|
15
|
+
if (!isUndefined(config2[prop])) {
|
|
16
|
+
config[prop] = config2[prop];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return config;
|
|
20
|
+
};
|
|
21
|
+
export default (config) => {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
let fullPath = buildURL(buildFullPath(config.baseURL, config.url), config.params, config.paramsSerializer);
|
|
24
|
+
const _config = {
|
|
25
|
+
url: fullPath,
|
|
26
|
+
header: config.header,
|
|
27
|
+
complete: (response) => {
|
|
28
|
+
config.fullPath = fullPath;
|
|
29
|
+
response.config = config;
|
|
30
|
+
response.rawData = response.data;
|
|
31
|
+
try {
|
|
32
|
+
let jsonParseHandle = false;
|
|
33
|
+
const forcedJSONParsingType = typeof config.forcedJSONParsing;
|
|
34
|
+
if (forcedJSONParsingType === 'boolean') {
|
|
35
|
+
jsonParseHandle = config.forcedJSONParsing;
|
|
36
|
+
} else if (forcedJSONParsingType === 'object') {
|
|
37
|
+
const includesMethod = config.forcedJSONParsing.include || [];
|
|
38
|
+
jsonParseHandle = includesMethod.includes(config.method);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 对可能字符串不是json 的情况容错
|
|
42
|
+
if (jsonParseHandle && typeof response.data === 'string') {
|
|
43
|
+
response.data = JSON.parse(response.data);
|
|
44
|
+
}
|
|
45
|
+
// eslint-disable-next-line no-empty
|
|
46
|
+
} catch (e) {}
|
|
47
|
+
settle(resolve, reject, response);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
let requestTask;
|
|
51
|
+
if (config.method === 'UPLOAD') {
|
|
52
|
+
delete _config.header['content-type'];
|
|
53
|
+
delete _config.header['Content-Type'];
|
|
54
|
+
let otherConfig = {
|
|
55
|
+
// #ifdef MP-ALIPAY
|
|
56
|
+
fileType: config.fileType,
|
|
57
|
+
// #endif
|
|
58
|
+
filePath: config.filePath,
|
|
59
|
+
name: config.name
|
|
60
|
+
};
|
|
61
|
+
const optionalKeys = [
|
|
62
|
+
// #ifdef APP-PLUS || H5
|
|
63
|
+
'files',
|
|
64
|
+
// #endif
|
|
65
|
+
// #ifdef H5
|
|
66
|
+
'file',
|
|
67
|
+
// #endif
|
|
68
|
+
// #ifdef H5 || APP-PLUS || MP-WEIXIN || MP-ALIPAY || MP-TOUTIAO || MP-KUAISHOU
|
|
69
|
+
'timeout',
|
|
70
|
+
// #endif
|
|
71
|
+
'formData'
|
|
72
|
+
];
|
|
73
|
+
requestTask = uni.uploadFile({ ..._config, ...otherConfig, ...mergeKeys(optionalKeys, config) });
|
|
74
|
+
} else if (config.method === 'DOWNLOAD') {
|
|
75
|
+
const optionalKeys = [
|
|
76
|
+
// #ifdef H5 || APP-PLUS || MP-WEIXIN || MP-ALIPAY || MP-TOUTIAO || MP-KUAISHOU
|
|
77
|
+
'timeout',
|
|
78
|
+
// #endif
|
|
79
|
+
// #ifdef MP
|
|
80
|
+
'filePath'
|
|
81
|
+
// #endif
|
|
82
|
+
];
|
|
83
|
+
requestTask = uni.downloadFile({ ..._config, ...mergeKeys(optionalKeys, config) });
|
|
84
|
+
} else {
|
|
85
|
+
const optionalKeys = [
|
|
86
|
+
'data',
|
|
87
|
+
'method',
|
|
88
|
+
// #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN
|
|
89
|
+
'timeout',
|
|
90
|
+
// #endif
|
|
91
|
+
'dataType',
|
|
92
|
+
// #ifndef MP-ALIPAY
|
|
93
|
+
'responseType',
|
|
94
|
+
// #endif
|
|
95
|
+
// #ifdef APP-PLUS
|
|
96
|
+
'sslVerify',
|
|
97
|
+
// #endif
|
|
98
|
+
// #ifdef H5
|
|
99
|
+
'withCredentials',
|
|
100
|
+
// #endif
|
|
101
|
+
// #ifdef APP-PLUS
|
|
102
|
+
'firstIpv4',
|
|
103
|
+
// #endif
|
|
104
|
+
// #ifdef MP-WEIXIN
|
|
105
|
+
'enableHttp2',
|
|
106
|
+
'enableQuic',
|
|
107
|
+
// #endif
|
|
108
|
+
// #ifdef MP-TOUTIAO || MP-WEIXIN
|
|
109
|
+
'enableCache',
|
|
110
|
+
// #endif
|
|
111
|
+
// #ifdef MP-WEIXIN
|
|
112
|
+
'enableHttpDNS',
|
|
113
|
+
'httpDNSServiceId',
|
|
114
|
+
'enableChunked',
|
|
115
|
+
'forceCellularNetwork',
|
|
116
|
+
// #endif
|
|
117
|
+
// #ifdef MP-ALIPAY
|
|
118
|
+
'enableCookie',
|
|
119
|
+
// #endif
|
|
120
|
+
// #ifdef MP-BAIDU
|
|
121
|
+
'cloudCache',
|
|
122
|
+
'defer'
|
|
123
|
+
// #endif
|
|
124
|
+
];
|
|
125
|
+
requestTask = uni.request({ ..._config, ...mergeKeys(optionalKeys, config) });
|
|
126
|
+
}
|
|
127
|
+
if (config.getTask) {
|
|
128
|
+
config.getTask(requestTask, config);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function InterceptorManager() {
|
|
4
|
+
this.handlers = [];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Add a new interceptor to the stack
|
|
9
|
+
*
|
|
10
|
+
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
|
11
|
+
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
|
12
|
+
*
|
|
13
|
+
* @return {Number} An ID used to remove interceptor later
|
|
14
|
+
*/
|
|
15
|
+
InterceptorManager.prototype.use = function use(fulfilled, rejected) {
|
|
16
|
+
this.handlers.push({
|
|
17
|
+
fulfilled: fulfilled,
|
|
18
|
+
rejected: rejected
|
|
19
|
+
});
|
|
20
|
+
return this.handlers.length - 1;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Remove an interceptor from the stack
|
|
25
|
+
*
|
|
26
|
+
* @param {Number} id The ID that was returned by `use`
|
|
27
|
+
*/
|
|
28
|
+
InterceptorManager.prototype.eject = function eject(id) {
|
|
29
|
+
if (this.handlers[id]) {
|
|
30
|
+
this.handlers[id] = null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Iterate over all the registered interceptors
|
|
36
|
+
*
|
|
37
|
+
* This method is particularly useful for skipping over any
|
|
38
|
+
* interceptors that may have become `null` calling `eject`.
|
|
39
|
+
*
|
|
40
|
+
* @param {Function} fn The function to call for each interceptor
|
|
41
|
+
*/
|
|
42
|
+
InterceptorManager.prototype.forEach = function forEach(fn) {
|
|
43
|
+
this.handlers.forEach((h) => {
|
|
44
|
+
if (h !== null) {
|
|
45
|
+
fn(h);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default InterceptorManager;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Class Request
|
|
3
|
+
* @description luch-request http请求插件
|
|
4
|
+
* @Author lu-ch
|
|
5
|
+
* @Email webwork.s@qq.com
|
|
6
|
+
* 文档: https://www.quanzhan.co/luch-request/
|
|
7
|
+
* github: https://github.com/lei-mu/luch-request
|
|
8
|
+
* DCloud: http://ext.dcloud.net.cn/plugin?id=392
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import dispatchRequest from './dispatchRequest';
|
|
12
|
+
import InterceptorManager from './InterceptorManager';
|
|
13
|
+
import mergeConfig from './mergeConfig';
|
|
14
|
+
import defaults from './defaults';
|
|
15
|
+
import { isPlainObject } from '../utils';
|
|
16
|
+
import clone from '../utils/clone';
|
|
17
|
+
|
|
18
|
+
export default class Request {
|
|
19
|
+
/**
|
|
20
|
+
* @param {Object} arg - 全局配置
|
|
21
|
+
* @param {String} arg.baseURL - 全局根路径
|
|
22
|
+
* @param {Object} arg.header - 全局header
|
|
23
|
+
* @param {String} arg.method = [GET|POST|PUT|DELETE|CONNECT|HEAD|OPTIONS|TRACE] - 全局默认请求方式
|
|
24
|
+
* @param {String} arg.dataType = [json] - 全局默认的dataType
|
|
25
|
+
* @param {String} arg.responseType = [text|arraybuffer] - 全局默认的responseType。支付宝小程序不支持
|
|
26
|
+
* @param {Object} arg.custom - 全局默认的自定义参数
|
|
27
|
+
* @param {Number} arg.timeout - 全局默认的超时时间,单位 ms。默认60000。H5(HBuilderX 2.9.9+)、APP(HBuilderX 2.9.9+)、微信小程序(2.10.0)、支付宝小程序
|
|
28
|
+
* @param {Boolean} arg.sslVerify - 全局默认的是否验证 ssl 证书。默认true.仅App安卓端支持(HBuilderX 2.3.3+)
|
|
29
|
+
* @param {Boolean} arg.withCredentials - 全局默认的跨域请求时是否携带凭证(cookies)。默认false。仅H5支持(HBuilderX 2.6.15+)
|
|
30
|
+
* @param {Boolean} arg.firstIpv4 - 全DNS解析时优先使用ipv4。默认false。仅 App-Android 支持 (HBuilderX 2.8.0+)
|
|
31
|
+
* @param {Function(statusCode):Boolean} arg.validateStatus - 全局默认的自定义验证器。默认statusCode >= 200 && statusCode < 300
|
|
32
|
+
*/
|
|
33
|
+
constructor(arg = {}) {
|
|
34
|
+
if (!isPlainObject(arg)) {
|
|
35
|
+
arg = {};
|
|
36
|
+
console.warn('设置全局参数必须接收一个Object');
|
|
37
|
+
}
|
|
38
|
+
this.config = clone({ ...defaults, ...arg });
|
|
39
|
+
this.interceptors = {
|
|
40
|
+
request: new InterceptorManager(),
|
|
41
|
+
response: new InterceptorManager()
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @Function
|
|
47
|
+
* @param {Request~setConfigCallback} f - 设置全局默认配置
|
|
48
|
+
*/
|
|
49
|
+
setConfig(f) {
|
|
50
|
+
this.config = f(this.config);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
middleware(config) {
|
|
54
|
+
config = mergeConfig(this.config, config);
|
|
55
|
+
let chain = [dispatchRequest, undefined];
|
|
56
|
+
let promise = Promise.resolve(config);
|
|
57
|
+
|
|
58
|
+
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
|
59
|
+
chain.unshift(interceptor.fulfilled, interceptor.rejected);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
|
63
|
+
chain.push(interceptor.fulfilled, interceptor.rejected);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
while (chain.length) {
|
|
67
|
+
promise = promise.then(chain.shift(), chain.shift());
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return promise;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @Function
|
|
75
|
+
* @param {Object} config - 请求配置项
|
|
76
|
+
* @prop {String} options.url - 请求路径
|
|
77
|
+
* @prop {Object} options.data - 请求参数
|
|
78
|
+
* @prop {Object} [options.responseType = config.responseType] [text|arraybuffer] - 响应的数据类型
|
|
79
|
+
* @prop {Object} [options.dataType = config.dataType] - 如果设为 json,会尝试对返回的数据做一次 JSON.parse
|
|
80
|
+
* @prop {Object} [options.header = config.header] - 请求header
|
|
81
|
+
* @prop {Object} [options.method = config.method] - 请求方法
|
|
82
|
+
* @returns {Promise<unknown>}
|
|
83
|
+
*/
|
|
84
|
+
request(config = {}) {
|
|
85
|
+
return this.middleware(config);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
get(url, options = {}) {
|
|
89
|
+
return this.middleware({
|
|
90
|
+
url,
|
|
91
|
+
method: 'GET',
|
|
92
|
+
...options
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
post(url, data, options = {}) {
|
|
97
|
+
return this.middleware({
|
|
98
|
+
url,
|
|
99
|
+
data,
|
|
100
|
+
method: 'POST',
|
|
101
|
+
...options
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// #ifndef MP-ALIPAY || MP-KUAISHOU || MP-JD
|
|
106
|
+
put(url, data, options = {}) {
|
|
107
|
+
return this.middleware({
|
|
108
|
+
url,
|
|
109
|
+
data,
|
|
110
|
+
method: 'PUT',
|
|
111
|
+
...options
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// #endif
|
|
116
|
+
|
|
117
|
+
// #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-BAIDU
|
|
118
|
+
delete(url, data, options = {}) {
|
|
119
|
+
return this.middleware({
|
|
120
|
+
url,
|
|
121
|
+
data,
|
|
122
|
+
method: 'DELETE',
|
|
123
|
+
...options
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// #endif
|
|
128
|
+
|
|
129
|
+
// #ifdef H5 || MP-WEIXIN
|
|
130
|
+
connect(url, data, options = {}) {
|
|
131
|
+
return this.middleware({
|
|
132
|
+
url,
|
|
133
|
+
data,
|
|
134
|
+
method: 'CONNECT',
|
|
135
|
+
...options
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// #endif
|
|
140
|
+
|
|
141
|
+
// #ifdef H5 || MP-WEIXIN || MP-BAIDU
|
|
142
|
+
head(url, data, options = {}) {
|
|
143
|
+
return this.middleware({
|
|
144
|
+
url,
|
|
145
|
+
data,
|
|
146
|
+
method: 'HEAD',
|
|
147
|
+
...options
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// #endif
|
|
152
|
+
|
|
153
|
+
// #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-BAIDU
|
|
154
|
+
options(url, data, options = {}) {
|
|
155
|
+
return this.middleware({
|
|
156
|
+
url,
|
|
157
|
+
data,
|
|
158
|
+
method: 'OPTIONS',
|
|
159
|
+
...options
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// #endif
|
|
164
|
+
|
|
165
|
+
// #ifdef H5 || MP-WEIXIN
|
|
166
|
+
trace(url, data, options = {}) {
|
|
167
|
+
return this.middleware({
|
|
168
|
+
url,
|
|
169
|
+
data,
|
|
170
|
+
method: 'TRACE',
|
|
171
|
+
...options
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// #endif
|
|
176
|
+
|
|
177
|
+
upload(url, config = {}) {
|
|
178
|
+
config.url = url;
|
|
179
|
+
config.method = 'UPLOAD';
|
|
180
|
+
return this.middleware(config);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
download(url, config = {}) {
|
|
184
|
+
config.url = url;
|
|
185
|
+
config.method = 'DOWNLOAD';
|
|
186
|
+
return this.middleware(config);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
get version() {
|
|
190
|
+
return '3.1.0';
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* setConfig回调
|
|
196
|
+
* @return {Object} - 返回操作后的config
|
|
197
|
+
* @callback Request~setConfigCallback
|
|
198
|
+
* @param {Object} config - 全局默认config
|
|
199
|
+
*/
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import isAbsoluteURL from '../helpers/isAbsoluteURL';
|
|
4
|
+
import combineURLs from '../helpers/combineURLs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new URL by combining the baseURL with the requestedURL,
|
|
8
|
+
* only when the requestedURL is not already an absolute URL.
|
|
9
|
+
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} baseURL The base URL
|
|
12
|
+
* @param {string} requestedURL Absolute or relative URL to combine
|
|
13
|
+
* @returns {string} The combined full path
|
|
14
|
+
*/
|
|
15
|
+
export default function buildFullPath(baseURL, requestedURL) {
|
|
16
|
+
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
|
17
|
+
return combineURLs(baseURL, requestedURL);
|
|
18
|
+
}
|
|
19
|
+
return requestedURL;
|
|
20
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 默认的全局配置
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
baseURL: '',
|
|
7
|
+
header: {},
|
|
8
|
+
method: 'GET',
|
|
9
|
+
dataType: 'json',
|
|
10
|
+
paramsSerializer: null,
|
|
11
|
+
// #ifndef MP-ALIPAY
|
|
12
|
+
responseType: 'text',
|
|
13
|
+
// #endif
|
|
14
|
+
custom: {},
|
|
15
|
+
// #ifdef H5 || APP-PLUS || MP-WEIXIN || MP-ALIPAY || MP-TOUTIAO || MP-KUAISHOU
|
|
16
|
+
timeout: 60000,
|
|
17
|
+
// #endif
|
|
18
|
+
// #ifdef APP-PLUS
|
|
19
|
+
sslVerify: true,
|
|
20
|
+
// #endif
|
|
21
|
+
// #ifdef H5
|
|
22
|
+
withCredentials: false,
|
|
23
|
+
// #endif
|
|
24
|
+
// #ifdef APP-PLUS
|
|
25
|
+
firstIpv4: false,
|
|
26
|
+
// #endif
|
|
27
|
+
validateStatus: function validateStatus(status) {
|
|
28
|
+
return status >= 200 && status < 300;
|
|
29
|
+
},
|
|
30
|
+
// 是否尝试将响应数据json化
|
|
31
|
+
forcedJSONParsing: true
|
|
32
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { deepMerge, isUndefined } from '../utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 合并局部配置优先的配置,如果局部有该配置项则用局部,如果全局有该配置项则用全局
|
|
5
|
+
* @param {Array} keys - 配置项
|
|
6
|
+
* @param {Object} globalsConfig - 当前的全局配置
|
|
7
|
+
* @param {Object} config2 - 局部配置
|
|
8
|
+
* @return {{}}
|
|
9
|
+
*/
|
|
10
|
+
const mergeKeys = (keys, globalsConfig, config2) => {
|
|
11
|
+
let config = {};
|
|
12
|
+
keys.forEach((prop) => {
|
|
13
|
+
if (!isUndefined(config2[prop])) {
|
|
14
|
+
config[prop] = config2[prop];
|
|
15
|
+
} else if (!isUndefined(globalsConfig[prop])) {
|
|
16
|
+
config[prop] = globalsConfig[prop];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return config;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param globalsConfig - 当前实例的全局配置
|
|
24
|
+
* @param config2 - 当前的局部配置
|
|
25
|
+
* @return - 合并后的配置
|
|
26
|
+
*/
|
|
27
|
+
export default (globalsConfig, config2 = {}) => {
|
|
28
|
+
const method = config2.method || globalsConfig.method || 'GET';
|
|
29
|
+
let config = {
|
|
30
|
+
baseURL: config2.baseURL || globalsConfig.baseURL || '',
|
|
31
|
+
method: method,
|
|
32
|
+
url: config2.url || '',
|
|
33
|
+
params: config2.params || {},
|
|
34
|
+
custom: { ...(globalsConfig.custom || {}), ...(config2.custom || {}) },
|
|
35
|
+
header: deepMerge(globalsConfig.header || {}, config2.header || {})
|
|
36
|
+
};
|
|
37
|
+
const defaultToConfig2Keys = ['getTask', 'validateStatus', 'paramsSerializer', 'forcedJSONParsing'];
|
|
38
|
+
config = { ...config, ...mergeKeys(defaultToConfig2Keys, globalsConfig, config2) };
|
|
39
|
+
|
|
40
|
+
// eslint-disable-next-line no-empty
|
|
41
|
+
if (method === 'DOWNLOAD') {
|
|
42
|
+
const downloadKeys = [
|
|
43
|
+
// #ifdef H5 || APP-PLUS || MP-WEIXIN || MP-ALIPAY || MP-TOUTIAO || MP-KUAISHOU
|
|
44
|
+
'timeout',
|
|
45
|
+
// #endif
|
|
46
|
+
// #ifdef MP
|
|
47
|
+
'filePath'
|
|
48
|
+
// #endif
|
|
49
|
+
];
|
|
50
|
+
config = { ...config, ...mergeKeys(downloadKeys, globalsConfig, config2) };
|
|
51
|
+
} else if (method === 'UPLOAD') {
|
|
52
|
+
delete config.header['content-type'];
|
|
53
|
+
delete config.header['Content-Type'];
|
|
54
|
+
const uploadKeys = [
|
|
55
|
+
// #ifdef APP-PLUS || H5
|
|
56
|
+
'files',
|
|
57
|
+
// #endif
|
|
58
|
+
// #ifdef MP-ALIPAY
|
|
59
|
+
'fileType',
|
|
60
|
+
// #endif
|
|
61
|
+
// #ifdef H5
|
|
62
|
+
'file',
|
|
63
|
+
// #endif
|
|
64
|
+
'filePath',
|
|
65
|
+
'name',
|
|
66
|
+
// #ifdef H5 || APP-PLUS || MP-WEIXIN || MP-ALIPAY || MP-TOUTIAO || MP-KUAISHOU
|
|
67
|
+
'timeout',
|
|
68
|
+
// #endif
|
|
69
|
+
'formData'
|
|
70
|
+
];
|
|
71
|
+
uploadKeys.forEach((prop) => {
|
|
72
|
+
if (!isUndefined(config2[prop])) {
|
|
73
|
+
config[prop] = config2[prop];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
// #ifdef H5 || APP-PLUS || MP-WEIXIN || MP-ALIPAY || MP-TOUTIAO || MP-KUAISHOU
|
|
77
|
+
if (isUndefined(config.timeout) && !isUndefined(globalsConfig.timeout)) {
|
|
78
|
+
config['timeout'] = globalsConfig['timeout'];
|
|
79
|
+
}
|
|
80
|
+
// #endif
|
|
81
|
+
} else {
|
|
82
|
+
const defaultsKeys = [
|
|
83
|
+
'data',
|
|
84
|
+
// #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN
|
|
85
|
+
'timeout',
|
|
86
|
+
// #endif
|
|
87
|
+
'dataType',
|
|
88
|
+
// #ifndef MP-ALIPAY
|
|
89
|
+
'responseType',
|
|
90
|
+
// #endif
|
|
91
|
+
// #ifdef APP-PLUS
|
|
92
|
+
'sslVerify',
|
|
93
|
+
// #endif
|
|
94
|
+
// #ifdef H5
|
|
95
|
+
'withCredentials',
|
|
96
|
+
// #endif
|
|
97
|
+
// #ifdef APP-PLUS
|
|
98
|
+
'firstIpv4',
|
|
99
|
+
// #endif
|
|
100
|
+
// #ifdef MP-WEIXIN
|
|
101
|
+
'enableHttp2',
|
|
102
|
+
'enableQuic',
|
|
103
|
+
// #endif
|
|
104
|
+
// #ifdef MP-TOUTIAO || MP-WEIXIN
|
|
105
|
+
'enableCache',
|
|
106
|
+
// #endif
|
|
107
|
+
// #ifdef MP-WEIXIN
|
|
108
|
+
'enableHttpDNS',
|
|
109
|
+
'httpDNSServiceId',
|
|
110
|
+
'enableChunked',
|
|
111
|
+
'forceCellularNetwork',
|
|
112
|
+
// #endif
|
|
113
|
+
// #ifdef MP-ALIPAY
|
|
114
|
+
'enableCookie',
|
|
115
|
+
// #endif
|
|
116
|
+
// #ifdef MP-BAIDU
|
|
117
|
+
'cloudCache',
|
|
118
|
+
'defer'
|
|
119
|
+
// #endif
|
|
120
|
+
];
|
|
121
|
+
config = { ...config, ...mergeKeys(defaultsKeys, globalsConfig, config2) };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return config;
|
|
125
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve or reject a Promise based on response status.
|
|
3
|
+
*
|
|
4
|
+
* @param {Function} resolve A function that resolves the promise.
|
|
5
|
+
* @param {Function} reject A function that rejects the promise.
|
|
6
|
+
* @param {object} response The response.
|
|
7
|
+
*/
|
|
8
|
+
export default function settle(resolve, reject, response) {
|
|
9
|
+
const validateStatus = response.config.validateStatus;
|
|
10
|
+
const status = response.statusCode;
|
|
11
|
+
if (status && (!validateStatus || validateStatus(status))) {
|
|
12
|
+
resolve(response);
|
|
13
|
+
} else {
|
|
14
|
+
reject(response);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import * as utils from './../utils';
|
|
4
|
+
|
|
5
|
+
function encode(val) {
|
|
6
|
+
return encodeURIComponent(val)
|
|
7
|
+
.replace(/%40/gi, '@')
|
|
8
|
+
.replace(/%3A/gi, ':')
|
|
9
|
+
.replace(/%24/g, '$')
|
|
10
|
+
.replace(/%2C/gi, ',')
|
|
11
|
+
.replace(/%20/g, '+')
|
|
12
|
+
.replace(/%5B/gi, '[')
|
|
13
|
+
.replace(/%5D/gi, ']');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Build a URL by appending params to the end
|
|
18
|
+
*
|
|
19
|
+
* @param {string} url The base of the url (e.g., http://www.google.com)
|
|
20
|
+
* @param {object} [params] The params to be appended
|
|
21
|
+
* @returns {string} The formatted url
|
|
22
|
+
*/
|
|
23
|
+
export default function buildURL(url, params, paramsSerializer) {
|
|
24
|
+
/*eslint no-param-reassign:0*/
|
|
25
|
+
if (!params) {
|
|
26
|
+
return url;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var serializedParams;
|
|
30
|
+
if (paramsSerializer) {
|
|
31
|
+
serializedParams = paramsSerializer(params);
|
|
32
|
+
} else if (utils.isURLSearchParams(params)) {
|
|
33
|
+
serializedParams = params.toString();
|
|
34
|
+
} else {
|
|
35
|
+
var parts = [];
|
|
36
|
+
|
|
37
|
+
utils.forEach(params, function serialize(val, key) {
|
|
38
|
+
if (val === null || typeof val === 'undefined') {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (utils.isArray(val)) {
|
|
43
|
+
key = key + '[]';
|
|
44
|
+
} else {
|
|
45
|
+
val = [val];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
utils.forEach(val, function parseValue(v) {
|
|
49
|
+
if (utils.isDate(v)) {
|
|
50
|
+
v = v.toISOString();
|
|
51
|
+
} else if (utils.isObject(v)) {
|
|
52
|
+
v = JSON.stringify(v);
|
|
53
|
+
}
|
|
54
|
+
parts.push(encode(key) + '=' + encode(v));
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
serializedParams = parts.join('&');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (serializedParams) {
|
|
62
|
+
var hashmarkIndex = url.indexOf('#');
|
|
63
|
+
if (hashmarkIndex !== -1) {
|
|
64
|
+
url = url.slice(0, hashmarkIndex);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return url;
|
|
71
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new URL by combining the specified URLs
|
|
5
|
+
*
|
|
6
|
+
* @param {string} baseURL The base URL
|
|
7
|
+
* @param {string} relativeURL The relative URL
|
|
8
|
+
* @returns {string} The combined URL
|
|
9
|
+
*/
|
|
10
|
+
export default function combineURLs(baseURL, relativeURL) {
|
|
11
|
+
return relativeURL ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '') : baseURL;
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Determines whether the specified URL is absolute
|
|
5
|
+
*
|
|
6
|
+
* @param {string} url The URL to test
|
|
7
|
+
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
|
8
|
+
*/
|
|
9
|
+
export default function isAbsoluteURL(url) {
|
|
10
|
+
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
|
11
|
+
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
|
12
|
+
// by any combination of letters, digits, plus, period, or hyphen.
|
|
13
|
+
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
|
14
|
+
}
|