├── index.js ├── dist ├── main.js.map └── main.js ├── .editorconfig ├── .gitignore ├── example └── defaultConfig │ └── request.js ├── src ├── InterceptorManager.js ├── defaults.js ├── request.js ├── dispatchRequest.js ├── util.js └── class.js ├── package.json ├── LICENSE ├── webpack.prod.js ├── .yo-rc.json └── README.md /index.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | import request from './src/request'; 4 | 5 | 6 | export default request; -------------------------------------------------------------------------------- /dist/main.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":[],"names":[],"mappings":"","file":"main.js","sourceRoot":""} -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 4 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | npm-debug.log* 4 | yarn-debug.log* 5 | yarn-error.log* 6 | 7 | # Editor directories and files 8 | .idea 9 | *.suo 10 | *.ntvs* 11 | *.njsproj 12 | *.sln 13 | -------------------------------------------------------------------------------- /example/defaultConfig/request.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | import wxRequest from 'wechat-request'; 4 | 5 | 6 | // 针对post请求增加token 7 | wxRequest.interceptors.request.use( 8 | config => { 9 | if (config.method === 'post') { 10 | config.headers.common['Authorization'] = AUTH_TOKEN; 11 | } 12 | return config; 13 | }, 14 | err => { 15 | return Promise.reject(err); 16 | }); 17 | 18 | 19 | 20 | export default wxRequest; 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/InterceptorManager.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | export default class InterceptorManager{ 7 | constructor(){ 8 | this.handlers = []; 9 | } 10 | 11 | use(fulfilled, rejected){ 12 | this.handlers.push({ 13 | fulfilled, 14 | rejected 15 | }); 16 | return this.handlers.length - 1; 17 | } 18 | 19 | eject(id){ 20 | if( this.handlers[id] ){ 21 | this.handlers[id] = null; 22 | } 23 | } 24 | 25 | forEach(fn){ 26 | this.handlers.forEach(e =>{ 27 | if(e !== null ){ 28 | fn(e) 29 | } 30 | }) 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/defaults.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | import * as util from './util'; 4 | 5 | let DEFAULT_CONTENT_TYPE = { 6 | 'Content-Type': 'application/x-www-form-urlencoded' 7 | }; 8 | 9 | var defaults = { 10 | method: 'get', // default 11 | // baseURL: '', 12 | dataType : 'json', 13 | responseType : 'text', 14 | // timeout: 0, 15 | headers: {}, 16 | }; 17 | 18 | defaults.headers = { 19 | common: { 20 | 'Accept': 'application/json, text/plain, */*' 21 | } 22 | }; 23 | 24 | ['delete','get', 'head','post', 'put', 'patch'].map(e => { 25 | defaults.headers[e] = util.merge(defaults.headers , DEFAULT_CONTENT_TYPE); 26 | }); 27 | 28 | 29 | export default defaults; -------------------------------------------------------------------------------- /src/request.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | import Request from './class'; 9 | import * as util from './util'; 10 | import defaults from './defaults'; 11 | 12 | 13 | function createInstance(config) { 14 | let context = new Request(config); 15 | let instance = util.bind( Request.prototype.request , context ); 16 | util.extend( instance , Request.prototype , context ); 17 | util.extend( instance , context ); 18 | return instance; 19 | } 20 | 21 | let request = createInstance(defaults); 22 | 23 | // 用于创建多个实例 24 | request.create = function (config) { 25 | return createInstance(utils.merge(defaults, config)); 26 | } 27 | 28 | export default request; 29 | 30 | 31 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wechat-request", 3 | "version": "1.5.0", 4 | "description": "基于Promise微信小程序http请求,轻便,小巧,api友好,功能丰富", 5 | "main": "dist/main.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "dev": "webpack --config=webpack.prod.js --mode development", 9 | "build": "webpack --config=webpack.prod.js --mode production" 10 | }, 11 | "keywords": [ 12 | "request", 13 | "wechat", 14 | "promise", 15 | "http", 16 | "微信小程序" 17 | ], 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/hatedMe/wechat-request.git" 21 | }, 22 | "bugs": { 23 | "url": "https://github.com/hatedMe/wechat-request/issues" 24 | }, 25 | "license": "ISC", 26 | "author": "Atom <7548764@qq.com>", 27 | "devDependencies": { 28 | "babel-core": "^6.26.0", 29 | "babel-loader": "^7.1.4", 30 | "babel-preset-env": "^1.6.1", 31 | "uglifyjs-webpack-plugin": "^1.2.4", 32 | "webpack": "^4.5.0", 33 | "webpack-cli": "^2.0.14" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /webpack.prod.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | const path = require('path'); 3 | 4 | /* 5 | * We've enabled UglifyJSPlugin for you! This minifies your app 6 | * in order to load faster and run less javascript. 7 | * 8 | * https://github.com/webpack-contrib/uglifyjs-webpack-plugin 9 | * 10 | */ 11 | 12 | // production 13 | 14 | const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); 15 | 16 | module.exports = { 17 | entry: './index.js', 18 | 19 | output: { 20 | // library: 'wxRequest', 21 | libraryTarget: 'umd', 22 | umdNamedDefine: true , 23 | filename: '[name].js', 24 | path: path.resolve(__dirname, 'dist') 25 | }, 26 | devtool : 'source-map', 27 | module: { 28 | rules: [ 29 | { 30 | test: /\.js$/, 31 | exclude: /node_modules/, 32 | loader: 'babel-loader', 33 | options: { 34 | presets: ['env'], 35 | plugins : 'transform-es2015-modules-commonjs' 36 | } 37 | } 38 | ] 39 | }, 40 | 41 | plugins: [ 42 | new UglifyJSPlugin(), 43 | new webpack.BannerPlugin( 44 | ` 45 | author : 7548764@qq.com 46 | github : https://github.com/hatedMe/wechat-request 47 | version : 1.4.2 48 | ` 49 | ) 50 | ] 51 | }; 52 | -------------------------------------------------------------------------------- /.yo-rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ajax": { 3 | "configuration": { 4 | "config": { 5 | "webpackOptions": { 6 | "module": { 7 | "rules": [ 8 | { 9 | "test": "/\\.js$/", 10 | "exclude": "/node_modules/", 11 | "loader": "'babel-loader'", 12 | "options": { 13 | "presets": [ 14 | "'env'" 15 | ] 16 | } 17 | } 18 | ] 19 | }, 20 | "plugins": [ 21 | "new UglifyJSPlugin()" 22 | ], 23 | "entry": "\"index\"", 24 | "output": { 25 | "filename": "'[name].bundle.js'", 26 | "path": "path.resolve(__dirname, 'dist')" 27 | } 28 | }, 29 | "topScope": [ 30 | "const webpack = require('webpack')", 31 | "const path = require('path')", 32 | "/*\n * We've enabled UglifyJSPlugin for you! This minifies your app\n * in order to load faster and run less javascript.\n *\n * https://github.com/webpack-contrib/uglifyjs-webpack-plugin\n *\n */", 33 | "const UglifyJSPlugin = require('uglifyjs-webpack-plugin');", 34 | "\n" 35 | ], 36 | "configName": "prod" 37 | } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /src/dispatchRequest.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | import * as util from './util'; 4 | 5 | 6 | export const dispatchRequest = function (config) { 7 | 8 | if (config.baseURL && !util.isAbsoluteURL(config.url)) { 9 | config.url = util.combineURLs(config.baseURL, config.url); 10 | } 11 | 12 | config.headers = util.merge( 13 | config.headers.common || {}, 14 | config.headers || {}, 15 | config.headers[config.method] || {}, 16 | ) 17 | 18 | let methods = ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'] 19 | methods.forEach(method => { 20 | delete config.headers[method]; 21 | }); 22 | 23 | let promise = Promise.resolve( config ); 24 | promise = promise.then( config => { 25 | return new Promise(function(resolve, reject) { 26 | let requestTask = wx.request({ 27 | url : config.url , 28 | data : config.data || {}, 29 | header : config.headers, 30 | method : config.method, 31 | dataType : config.dataType, 32 | success : function (res) { 33 | resolve({ 34 | data : res.data , 35 | headers : res.header, 36 | status : res.statusCode, 37 | statusText : 'ok' 38 | }) 39 | }, 40 | fail : function (err) { 41 | reject(err) 42 | }, 43 | complete : function () { 44 | config.complete && config.complete() 45 | } 46 | }) 47 | 48 | if( config.timeout && typeof config.timeout === 'number' && config.timeout > 1000 ){ 49 | setTimeout(() =>{ 50 | requestTask.abort(); 51 | resolve({ 52 | status : 'canceled' 53 | }); 54 | },config.timeout) 55 | } 56 | }); 57 | }) 58 | 59 | return promise; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /src/util.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | export const bind = function(fn,thisArg){ 8 | return function warp(){ 9 | return fn.apply(thisArg , Array.from(arguments) ) 10 | } 11 | } 12 | 13 | export const extend = function (a,b, thisArg) { 14 | let o = Object.getOwnPropertyNames( b ); 15 | o.forEach(attr => { 16 | if(thisArg && typeof b[attr] === "function" ){ 17 | a[attr] = bind( b[attr] , thisArg ) 18 | }else{ 19 | a[attr] = b[attr]; 20 | } 21 | }); 22 | return a; 23 | } 24 | 25 | export const copyobj = function( a, b ){ 26 | return Object.assign( {} , a ,b ); 27 | } 28 | 29 | export const merge = function(){ 30 | var result = {}; 31 | Array.from(arguments).forEach( e =>{ 32 | for(let key in e){ 33 | if( typeof e[key] === 'object' && !isEmptyObject(e[key]) ){ 34 | merge( result[key] , e[key] ) 35 | } 36 | result[key] = e[key] 37 | } 38 | }) 39 | 40 | return result; 41 | } 42 | 43 | 44 | 45 | export const isEmptyObject = function(obj){ 46 | return Object.getOwnPropertyNames(obj).length === 0 47 | } 48 | 49 | 50 | 51 | export const combineURLs = function (baseURL, relativeURL) { 52 | return relativeURL 53 | ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '') 54 | : baseURL; 55 | }; 56 | 57 | 58 | // /** 59 | // * Transform the data for a request or a response 60 | // * 61 | // * @param {Object|String} data The data to be transformed 62 | // * @param {Array} headers The headers for the request or response 63 | // * @param {Array|Function} fns A single function or Array of functions 64 | // * @returns {*} The resulting transformed data 65 | // */ 66 | // export const transformData = function(data, headers, fns) { 67 | // // utils.forEach(fns, function transform(fn) { 68 | // // data = fn(data, headers); 69 | // // }); 70 | 71 | // if( typeof data !== 'object' ) { 72 | // data = [data] 73 | // } 74 | 75 | // if( Array.isArray(data) ){ 76 | 77 | // } 78 | 79 | // return data; 80 | // }; 81 | 82 | 83 | /** 84 | * Determines whether the specified URL is absolute 85 | * 86 | * @param {string} url The URL to test 87 | * @returns {boolean} True if the specified URL is absolute, otherwise false 88 | */ 89 | 90 | export const isAbsoluteURL = function (url) { 91 | // A URL is considered absolute if it begins with "://" or "//" (protocol-relative URL). 92 | // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed 93 | // by any combination of letters, digits, plus, period, or hyphen. 94 | return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url); 95 | }; -------------------------------------------------------------------------------- /src/class.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | import * as util from './util'; 5 | import defaults from './defaults'; 6 | import InterceptorManager from './InterceptorManager'; 7 | import { dispatchRequest } from './dispatchRequest'; 8 | 9 | 10 | class Request { 11 | constructor( config ){ 12 | this.defaults = config; 13 | this.interceptors = { 14 | request: new InterceptorManager(), 15 | response: new InterceptorManager() 16 | }; 17 | } 18 | request( config ){ 19 | if( typeof config === 'string'){ 20 | config = util.merge({url: arguments[0]}, arguments[1]); 21 | } 22 | config = util.merge(defaults, this.defaults,{ method: 'GET' }, config ); 23 | config.method = config.method.toLowerCase(); 24 | 25 | let chain = [dispatchRequest, undefined]; 26 | let promise = Promise.resolve( config ); 27 | 28 | this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) { 29 | chain.unshift(interceptor.fulfilled, interceptor.rejected); 30 | }); 31 | 32 | this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) { 33 | chain.push(interceptor.fulfilled, interceptor.rejected); 34 | }); 35 | 36 | while (chain.length) { 37 | promise = promise.then(chain.shift(), chain.shift()); 38 | } 39 | 40 | return promise; 41 | } 42 | all (promises){ 43 | return Promise.all(promises); 44 | } 45 | 46 | uploadFile ( ){ // 上传图片 47 | let config = util.merge({url: arguments[0]}, arguments[1]); 48 | let formData; 49 | if( config.formData && typeof config.formData === 'object' ){ 50 | formData = new FormData(); 51 | for(let attr in config.formData){ 52 | formData.append( attr , config.formData[attr] ) 53 | } 54 | config.formData = formData 55 | } 56 | return new Promise((resolve, reject) => { 57 | wx.uploadFile({ 58 | url: config.url, 59 | filePath: config.filePath, 60 | name: config.name, 61 | formData: config.formData, 62 | success: function(res){ 63 | resolve({ 64 | data : res.data , 65 | headers : res.header, 66 | status : res.statusCode, 67 | statusText : 'ok' 68 | }) 69 | }, 70 | fail (err) { 71 | reject(err) 72 | }, 73 | complete() {} 74 | }) 75 | }); 76 | } 77 | 78 | } 79 | 80 | 81 | ['delete', 'get', 'head', 'options','post', 'put', 'patch'].forEach(e => { 82 | Request.prototype[e] = function ( url,config ) { 83 | return this.request( util.merge(config || {} ,{ 84 | method: e, 85 | url: url 86 | }) ) 87 | } 88 | }); 89 | 90 | 91 | 92 | export default Request; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | # wechat-request 6 | 7 |

8 | 9 | 10 | 11 |

12 | 13 | > 基于Promise微信小程序http请求,轻便,小巧,api友好,功能丰富 14 | 15 | 16 | ## 特别之处 17 | - 支持Promise API 18 | - 拦截请求和响应 19 | - 转换请求和响应数据 20 | - 取消请求 21 | - 自动转换为JSON数据 22 | - 超时请求 23 | - 告别callback 24 | - 支持默认请求前缀 25 | - 支持并发请求 26 | 27 | ## 使用方式 28 | 29 | ```mpvue```、```wepy```框架中 30 | ```npm install wechat-request --save ```
31 | ```import wxRequest from 'wechat-request';```
32 | 33 | 在原生中使用,只需要引入```dist/main.js```引入就好; 34 | 35 | 36 | ## 一步上手 37 | 38 | 首先来一个简单的```get```请求 39 | ```js 40 | // 向具有给定ID的用户发出请求 41 | wxRequest.get('/user?id=12345') 42 | .then(function (response) { 43 | console.log(response); 44 | }) 45 | .catch(function (error) { 46 | console.log(error); 47 | }); 48 | 49 | // 可选地,上面的请求也可以按照 50 | wxRequest.get('/user', { 51 | data: { 52 | id: 'number' 53 | } 54 | }).then(function (response) { 55 | console.log(response); 56 | }).catch(function (error) { 57 | console.log(error); 58 | }); 59 | 60 | // 想要使用 async/await? 将`async`关键字添加到外部函数/method 61 | async function getUser() { 62 | try { 63 | const response = await wxRequest.get('/user?ID=12345'); 64 | console.log(response); 65 | } catch (error) { 66 | console.error(error); 67 | } 68 | } 69 | ``` 70 | > 想要开启 async/waait 畅快之旅,需要 bable2阶段。吼吼 71 | 72 | 接着再来一个```post```请求 73 | 74 | ```js 75 | wxRequest.post('/user', { 76 | data :{ 77 | firstname : 'firstname', 78 | lastname : 'lastname' 79 | } 80 | }).then(function (response) { 81 | console.log(response); 82 | }).catch(function (error) { 83 | console.log(error); 84 | }); 85 | ``` 86 | 87 | 执行多并发请求例子 88 | 89 | ```js 90 | function getUserAccount() { 91 | return wxRequest.get('/user/12345'); 92 | } 93 | 94 | function getUserPermissions() { 95 | return wxRequest.get('/user/12345/permissions'); 96 | } 97 | 98 | wxRequest.all([getUserAccount(), getUserPermissions()]) 99 | .then(response =>{ 100 | // dosoming ... 101 | }); 102 | ``` 103 | 104 | ## 请求方法别名 105 | 当然除了常见的```get```,```post```其他的请求也统一封装 106 | 107 | - ```wxRequest.request(config)``` 108 | - ```wxRequest.get(url[, config])``` 109 | - ```wxRequest.delete(url[, config])``` 110 | - ```wxRequest.head(url[, config])``` 111 | - ```wxRequest.options(url[, config])``` 112 | - ```wxRequest.post(url[, data[, config]])``` 113 | - ```wxRequest.put(url[, data[, config]])``` 114 | - ```wxRequest.patch(url[, data[, config]])``` 115 | 116 | > note: 当使用别名方法`url`时,`method`和`data`属性不需要在config中指定。 117 | 118 | 119 | ### 全局配置 120 | 121 | 使用场景用户请求需要token,或者地址前缀,一次配置,省时省心。 122 | 123 | ```js 124 | wxRequest.defaults.baseURL = 'https://api.example.com'; 125 | wxRequest.defaults.headers.common['Authorization'] = AUTH_TOKEN; 126 | wxRequest.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; 127 | ``` 128 | 129 | ## 致谢 && 参考 130 | * [axios](https://github.com/axios/axios) 131 | 132 | 133 | ## License 134 | 135 | MIT -------------------------------------------------------------------------------- /dist/main.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * 3 | * author : 7548764@qq.com 4 | * github : https://github.com/hatedMe/wechat-request 5 | * version : 1.4.1 6 | * 7 | */ 8 | !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=6)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=t.bind=function(e,t){return function(){return e.apply(t,Array.from(arguments))}},u=(t.extend=function(e,t,n){return Object.getOwnPropertyNames(t).forEach(function(r){n&&"function"==typeof t[r]?e[r]=o(t[r],n):e[r]=t[r]}),e},t.copyobj=function(e,t){return Object.assign({},e,t)},t.merge=function e(){var t={};return Array.from(arguments).forEach(function(n){for(var o in n)"object"!==r(n[o])||u(n[o])||e(t[o],n[o]),t[o]=n[o]}),t},t.isEmptyObject=function(e){return 0===Object.getOwnPropertyNames(e).length});t.combineURLs=function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e},t.isAbsoluteURL=function(e){return/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(e)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}(n(0)),o={"Content-Type":"application/x-www-form-urlencoded"},u={method:"get",dataType:"json",responseType:"text",headers:{}};u.headers={common:{Accept:"application/json, text/plain, */*"}},["delete","get","head","post","put","patch"].map(function(e){u.headers[e]=r.merge(u.headers,o)}),t.default=u},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.dispatchRequest=void 0;var r=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}(n(0));t.dispatchRequest=function(e){e.baseURL&&!r.isAbsoluteURL(e.url)&&(e.url=r.combineURLs(e.baseURL,e.url)),e.headers=r.merge(e.headers.common||{},e.headers||{},e.headers[e.method]||{}),["delete","get","head","post","put","patch","common"].forEach(function(t){delete e.headers[t]});var t=Promise.resolve(e);return t.then(function(e){return new Promise(function(t,n){var r=wx.request({url:e.url,data:e.data||{},header:e.headers,method:e.method,dataType:e.dataType,success:function(e){t({data:e.data,headers:e.header,status:e.statusCode,statusText:"ok"})},fail:function(e){n(e)},complete:function(){e.complete&&e.complete()}});e.timeout&&"number"==typeof e.timeout&&e.timeout>1e3&&setTimeout(function(){r.abort(),t({status:"canceled"})},e.timeout)})})}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n