@gmcb/uv-ui 0.2.26

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.
Files changed (285) hide show
  1. package/CHANGELOG.md +295 -0
  2. package/LICENSE +21 -0
  3. package/README.md +164 -0
  4. package/components/uv-action-sheet/props.js +50 -0
  5. package/components/uv-action-sheet/uv-action-sheet.vue +280 -0
  6. package/components/uv-album/uv-album.vue +312 -0
  7. package/components/uv-alert/props.js +45 -0
  8. package/components/uv-alert/uv-alert.vue +246 -0
  9. package/components/uv-avatar/props.js +85 -0
  10. package/components/uv-avatar/uv-avatar.vue +182 -0
  11. package/components/uv-avatar-group/props.js +53 -0
  12. package/components/uv-avatar-group/uv-avatar-group.vue +106 -0
  13. package/components/uv-back-top/props.js +58 -0
  14. package/components/uv-back-top/uv-back-top.vue +116 -0
  15. package/components/uv-badge/props.js +73 -0
  16. package/components/uv-badge/uv-badge.vue +176 -0
  17. package/components/uv-button/nvue.scss +46 -0
  18. package/components/uv-button/props.js +163 -0
  19. package/components/uv-button/uv-button.vue +529 -0
  20. package/components/uv-button/vue.scss +93 -0
  21. package/components/uv-calendar/calendar.js +546 -0
  22. package/components/uv-calendar/header.vue +104 -0
  23. package/components/uv-calendar/month.vue +616 -0
  24. package/components/uv-calendar/props.js +145 -0
  25. package/components/uv-calendar/uv-calendar.vue +390 -0
  26. package/components/uv-calendars/calendar-body.vue +376 -0
  27. package/components/uv-calendars/calendar-item.vue +248 -0
  28. package/components/uv-calendars/calendar.js +546 -0
  29. package/components/uv-calendars/i18n/en.json +12 -0
  30. package/components/uv-calendars/i18n/index.js +8 -0
  31. package/components/uv-calendars/i18n/zh-Hans.json +12 -0
  32. package/components/uv-calendars/i18n/zh-Hant.json +12 -0
  33. package/components/uv-calendars/util.js +435 -0
  34. package/components/uv-calendars/uv-calendars.vue +452 -0
  35. package/components/uv-cell/props.js +116 -0
  36. package/components/uv-cell/uv-cell.vue +209 -0
  37. package/components/uv-cell-group/props.js +15 -0
  38. package/components/uv-cell-group/uv-cell-group.vue +63 -0
  39. package/components/uv-checkbox/props.js +70 -0
  40. package/components/uv-checkbox/uv-checkbox.vue +371 -0
  41. package/components/uv-checkbox-group/props.js +84 -0
  42. package/components/uv-checkbox-group/uv-checkbox-group.vue +119 -0
  43. package/components/uv-code/props.js +35 -0
  44. package/components/uv-code/uv-code.vue +136 -0
  45. package/components/uv-code-input/props.js +83 -0
  46. package/components/uv-code-input/uv-code-input.vue +272 -0
  47. package/components/uv-col/props.js +30 -0
  48. package/components/uv-col/uv-col.vue +165 -0
  49. package/components/uv-collapse/props.js +20 -0
  50. package/components/uv-collapse/uv-collapse.vue +86 -0
  51. package/components/uv-collapse-item/props.js +60 -0
  52. package/components/uv-collapse-item/uv-collapse-item.vue +228 -0
  53. package/components/uv-column-notice/props.js +61 -0
  54. package/components/uv-column-notice/uv-column-notice.vue +176 -0
  55. package/components/uv-count-down/props.js +25 -0
  56. package/components/uv-count-down/utils.js +62 -0
  57. package/components/uv-count-down/uv-count-down.vue +169 -0
  58. package/components/uv-count-to/props.js +60 -0
  59. package/components/uv-count-to/uv-count-to.vue +187 -0
  60. package/components/uv-datetime-picker/props.js +130 -0
  61. package/components/uv-datetime-picker/uv-datetime-picker.vue +355 -0
  62. package/components/uv-divider/props.js +45 -0
  63. package/components/uv-divider/uv-divider.vue +113 -0
  64. package/components/uv-drop-down/uv-drop-down.vue +135 -0
  65. package/components/uv-drop-down-item/uv-drop-down-item.vue +169 -0
  66. package/components/uv-drop-down-popup/uv-drop-down-popup.vue +242 -0
  67. package/components/uv-empty/props.js +60 -0
  68. package/components/uv-empty/uv-empty.vue +126 -0
  69. package/components/uv-form/props.js +46 -0
  70. package/components/uv-form/uv-form.vue +209 -0
  71. package/components/uv-form/valid.js +1343 -0
  72. package/components/uv-form-item/props.js +49 -0
  73. package/components/uv-form-item/uv-form-item.vue +226 -0
  74. package/components/uv-gap/props.js +25 -0
  75. package/components/uv-gap/uv-gap.vue +36 -0
  76. package/components/uv-grid/props.js +20 -0
  77. package/components/uv-grid/uv-grid.vue +100 -0
  78. package/components/uv-grid-item/props.js +15 -0
  79. package/components/uv-grid-item/uv-grid-item.vue +223 -0
  80. package/components/uv-icon/icons.js +160 -0
  81. package/components/uv-icon/props.js +90 -0
  82. package/components/uv-icon/uv-icon.vue +226 -0
  83. package/components/uv-icon/uvicons.ttf +0 -0
  84. package/components/uv-image/props.js +100 -0
  85. package/components/uv-image/uv-image.vue +296 -0
  86. package/components/uv-index-anchor/props.js +30 -0
  87. package/components/uv-index-anchor/uv-index-anchor.vue +98 -0
  88. package/components/uv-index-item/uv-index-item.vue +87 -0
  89. package/components/uv-index-list/props.js +30 -0
  90. package/components/uv-index-list/uv-index-list.vue +461 -0
  91. package/components/uv-input/props.js +175 -0
  92. package/components/uv-input/uv-input.vue +348 -0
  93. package/components/uv-keyboard/props.js +95 -0
  94. package/components/uv-keyboard/uv-keyboard.vue +180 -0
  95. package/components/uv-keyboard-car/props.js +24 -0
  96. package/components/uv-keyboard-car/uv-keyboard-car.vue +347 -0
  97. package/components/uv-keyboard-number/props.js +19 -0
  98. package/components/uv-keyboard-number/uv-keyboard-number.vue +201 -0
  99. package/components/uv-line/props.js +34 -0
  100. package/components/uv-line/uv-line.vue +60 -0
  101. package/components/uv-line-progress/props.js +29 -0
  102. package/components/uv-line-progress/uv-line-progress.vue +146 -0
  103. package/components/uv-link/props.js +40 -0
  104. package/components/uv-link/uv-link.vue +83 -0
  105. package/components/uv-list/uv-list.vue +147 -0
  106. package/components/uv-list-item/uv-list-item.vue +535 -0
  107. package/components/uv-load-more/props.js +95 -0
  108. package/components/uv-load-more/uv-load-more.vue +152 -0
  109. package/components/uv-loading-icon/props.js +67 -0
  110. package/components/uv-loading-icon/uv-loading-icon.vue +347 -0
  111. package/components/uv-loading-page/props.js +55 -0
  112. package/components/uv-loading-page/uv-loading-page.vue +96 -0
  113. package/components/uv-modal/props.js +90 -0
  114. package/components/uv-modal/uv-modal.vue +245 -0
  115. package/components/uv-navbar/props.js +89 -0
  116. package/components/uv-navbar/uv-navbar.vue +245 -0
  117. package/components/uv-no-network/props.js +20 -0
  118. package/components/uv-no-network/uv-no-network.vue +222 -0
  119. package/components/uv-notice-bar/props.js +76 -0
  120. package/components/uv-notice-bar/uv-notice-bar.vue +110 -0
  121. package/components/uv-notify/props.js +45 -0
  122. package/components/uv-notify/uv-notify.vue +220 -0
  123. package/components/uv-number-box/props.js +118 -0
  124. package/components/uv-number-box/uv-number-box.vue +397 -0
  125. package/components/uv-overlay/props.js +25 -0
  126. package/components/uv-overlay/uv-overlay.vue +85 -0
  127. package/components/uv-parse/node/node.vue +576 -0
  128. package/components/uv-parse/parser.js +1335 -0
  129. package/components/uv-parse/uv-parse.vue +498 -0
  130. package/components/uv-pick-color/colors.js +217 -0
  131. package/components/uv-pick-color/props.js +47 -0
  132. package/components/uv-pick-color/uv-pick-color.vue +551 -0
  133. package/components/uv-picker/props.js +95 -0
  134. package/components/uv-picker/uv-picker.vue +329 -0
  135. package/components/uv-popup/keypress.js +45 -0
  136. package/components/uv-popup/uv-popup.vue +537 -0
  137. package/components/uv-preview-video/uv-preview-video.vue +52 -0
  138. package/components/uv-qrcode/cache.js +1 -0
  139. package/components/uv-qrcode/gcanvas/bridge/bridge-weex.js +241 -0
  140. package/components/uv-qrcode/gcanvas/context-2d/FillStyleLinearGradient.js +18 -0
  141. package/components/uv-qrcode/gcanvas/context-2d/FillStylePattern.js +8 -0
  142. package/components/uv-qrcode/gcanvas/context-2d/FillStyleRadialGradient.js +17 -0
  143. package/components/uv-qrcode/gcanvas/context-2d/RenderingContext.js +666 -0
  144. package/components/uv-qrcode/gcanvas/context-webgl/ActiveInfo.js +11 -0
  145. package/components/uv-qrcode/gcanvas/context-webgl/Buffer.js +21 -0
  146. package/components/uv-qrcode/gcanvas/context-webgl/Framebuffer.js +21 -0
  147. package/components/uv-qrcode/gcanvas/context-webgl/GLenum.js +298 -0
  148. package/components/uv-qrcode/gcanvas/context-webgl/GLmethod.js +142 -0
  149. package/components/uv-qrcode/gcanvas/context-webgl/GLtype.js +23 -0
  150. package/components/uv-qrcode/gcanvas/context-webgl/Program.js +21 -0
  151. package/components/uv-qrcode/gcanvas/context-webgl/Renderbuffer.js +21 -0
  152. package/components/uv-qrcode/gcanvas/context-webgl/RenderingContext.js +1191 -0
  153. package/components/uv-qrcode/gcanvas/context-webgl/Shader.js +22 -0
  154. package/components/uv-qrcode/gcanvas/context-webgl/ShaderPrecisionFormat.js +11 -0
  155. package/components/uv-qrcode/gcanvas/context-webgl/Texture.js +22 -0
  156. package/components/uv-qrcode/gcanvas/context-webgl/UniformLocation.js +22 -0
  157. package/components/uv-qrcode/gcanvas/context-webgl/classUtils.js +3 -0
  158. package/components/uv-qrcode/gcanvas/env/canvas.js +74 -0
  159. package/components/uv-qrcode/gcanvas/env/image.js +96 -0
  160. package/components/uv-qrcode/gcanvas/env/tool.js +24 -0
  161. package/components/uv-qrcode/gcanvas/index.js +39 -0
  162. package/components/uv-qrcode/props.js +85 -0
  163. package/components/uv-qrcode/qrcode.js +34 -0
  164. package/components/uv-qrcode/queue.js +41 -0
  165. package/components/uv-qrcode/uv-qrcode.vue +1038 -0
  166. package/components/uv-radio/props.js +65 -0
  167. package/components/uv-radio/uv-radio.vue +349 -0
  168. package/components/uv-radio-group/props.js +89 -0
  169. package/components/uv-radio-group/uv-radio-group.vue +115 -0
  170. package/components/uv-rate/props.js +73 -0
  171. package/components/uv-rate/uv-rate.vue +274 -0
  172. package/components/uv-read-more/props.js +62 -0
  173. package/components/uv-read-more/uv-read-more.vue +162 -0
  174. package/components/uv-row/props.js +20 -0
  175. package/components/uv-row/uv-row.vue +95 -0
  176. package/components/uv-row-notice/props.js +40 -0
  177. package/components/uv-row-notice/uv-row-notice.vue +341 -0
  178. package/components/uv-safe-bottom/uv-safe-bottom.vue +67 -0
  179. package/components/uv-scroll-list/nvue.js +29 -0
  180. package/components/uv-scroll-list/props.js +35 -0
  181. package/components/uv-scroll-list/scrollWxs.wxs +51 -0
  182. package/components/uv-scroll-list/uv-scroll-list.vue +218 -0
  183. package/components/uv-search/props.js +127 -0
  184. package/components/uv-search/uv-search.vue +311 -0
  185. package/components/uv-skeleton/props.js +65 -0
  186. package/components/uv-skeleton/uv-skeleton.vue +250 -0
  187. package/components/uv-skeletons/uv-skeletons.vue +247 -0
  188. package/components/uv-slider/props.js +58 -0
  189. package/components/uv-slider/uv-slider.vue +58 -0
  190. package/components/uv-status-bar/props.js +8 -0
  191. package/components/uv-status-bar/uv-status-bar.vue +54 -0
  192. package/components/uv-steps/props.js +40 -0
  193. package/components/uv-steps/uv-steps.vue +83 -0
  194. package/components/uv-steps-item/props.js +25 -0
  195. package/components/uv-steps-item/uv-steps-item.vue +347 -0
  196. package/components/uv-sticky/props.js +41 -0
  197. package/components/uv-sticky/uv-sticky.vue +223 -0
  198. package/components/uv-subsection/props.js +54 -0
  199. package/components/uv-subsection/uv-subsection.vue +269 -0
  200. package/components/uv-swipe-action/props.js +10 -0
  201. package/components/uv-swipe-action/uv-swipe-action.vue +65 -0
  202. package/components/uv-swipe-action-item/index - backup.wxs +256 -0
  203. package/components/uv-swipe-action-item/index.wxs +225 -0
  204. package/components/uv-swipe-action-item/nvue - backup.js +264 -0
  205. package/components/uv-swipe-action-item/nvue.js +182 -0
  206. package/components/uv-swipe-action-item/props.js +40 -0
  207. package/components/uv-swipe-action-item/uv-swipe-action-item.vue +200 -0
  208. package/components/uv-swipe-action-item/wxs.js +15 -0
  209. package/components/uv-swiper/props.js +136 -0
  210. package/components/uv-swiper/uv-swiper.vue +263 -0
  211. package/components/uv-swiper-indicator/props.js +30 -0
  212. package/components/uv-swiper-indicator/uv-swiper-indicator.vue +112 -0
  213. package/components/uv-switch/props.js +58 -0
  214. package/components/uv-switch/uv-switch.vue +182 -0
  215. package/components/uv-tabbar/props.js +50 -0
  216. package/components/uv-tabbar/uv-tabbar.vue +146 -0
  217. package/components/uv-tabbar-item/props.js +40 -0
  218. package/components/uv-tabbar-item/uv-tabbar-item.vue +146 -0
  219. package/components/uv-tabs/props.js +71 -0
  220. package/components/uv-tabs/uv-tabs.vue +391 -0
  221. package/components/uv-tags/props.js +104 -0
  222. package/components/uv-tags/uv-tags.vue +379 -0
  223. package/components/uv-text/props.js +113 -0
  224. package/components/uv-text/uv-text.vue +218 -0
  225. package/components/uv-text/value.js +87 -0
  226. package/components/uv-textarea/props.js +138 -0
  227. package/components/uv-textarea/uv-textarea.vue +238 -0
  228. package/components/uv-toast/uv-toast.vue +292 -0
  229. package/components/uv-toolbar/props.js +40 -0
  230. package/components/uv-toolbar/uv-toolbar.vue +109 -0
  231. package/components/uv-tooltip/props.js +60 -0
  232. package/components/uv-tooltip/uv-tooltip.vue +372 -0
  233. package/components/uv-transition/createAnimation.js +131 -0
  234. package/components/uv-transition/props.js +31 -0
  235. package/components/uv-transition/uv-transition.vue +320 -0
  236. package/components/uv-upload/mixin.js +22 -0
  237. package/components/uv-upload/props.js +130 -0
  238. package/components/uv-upload/utils.js +151 -0
  239. package/components/uv-upload/uv-upload.vue +488 -0
  240. package/components/uv-vtabs/props.js +79 -0
  241. package/components/uv-vtabs/uv-vtabs.vue +438 -0
  242. package/components/uv-vtabs-item/uv-vtabs-item.vue +68 -0
  243. package/components/uv-waterfall/props.js +69 -0
  244. package/components/uv-waterfall/uv-waterfall.vue +265 -0
  245. package/index.js +82 -0
  246. package/index.scss +7 -0
  247. package/libs/config/config.js +34 -0
  248. package/libs/css/color.scss +32 -0
  249. package/libs/css/common.scss +100 -0
  250. package/libs/css/components.scss +23 -0
  251. package/libs/css/variable.scss +111 -0
  252. package/libs/css/vue.scss +40 -0
  253. package/libs/function/colorGradient.js +134 -0
  254. package/libs/function/compress.js +27 -0
  255. package/libs/function/debounce.js +29 -0
  256. package/libs/function/digit.js +167 -0
  257. package/libs/function/index.js +734 -0
  258. package/libs/function/platform.js +75 -0
  259. package/libs/function/test.js +287 -0
  260. package/libs/function/throttle.js +30 -0
  261. package/libs/luch-request/adapters/index.js +132 -0
  262. package/libs/luch-request/core/InterceptorManager.js +51 -0
  263. package/libs/luch-request/core/Request.js +201 -0
  264. package/libs/luch-request/core/buildFullPath.js +20 -0
  265. package/libs/luch-request/core/defaults.js +33 -0
  266. package/libs/luch-request/core/dispatchRequest.js +6 -0
  267. package/libs/luch-request/core/mergeConfig.js +126 -0
  268. package/libs/luch-request/core/settle.js +16 -0
  269. package/libs/luch-request/helpers/buildURL.js +64 -0
  270. package/libs/luch-request/helpers/combineURLs.js +14 -0
  271. package/libs/luch-request/helpers/isAbsoluteURL.js +14 -0
  272. package/libs/luch-request/index.d.ts +197 -0
  273. package/libs/luch-request/index.js +2 -0
  274. package/libs/luch-request/utils/clone.js +264 -0
  275. package/libs/luch-request/utils.js +135 -0
  276. package/libs/mixin/button.js +13 -0
  277. package/libs/mixin/mixin.js +172 -0
  278. package/libs/mixin/mpMixin.js +8 -0
  279. package/libs/mixin/mpShare.js +13 -0
  280. package/libs/mixin/openType.js +47 -0
  281. package/libs/mixin/touch.js +59 -0
  282. package/libs/util/dayjs.js +216 -0
  283. package/libs/util/route.js +126 -0
  284. package/package.json +28 -0
  285. package/theme.scss +43 -0
@@ -0,0 +1,201 @@
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
+
12
+ import dispatchRequest from './dispatchRequest'
13
+ import InterceptorManager from './InterceptorManager'
14
+ import mergeConfig from './mergeConfig'
15
+ import defaults from './defaults'
16
+ import { isPlainObject } from '../utils'
17
+ import clone from '../utils/clone'
18
+
19
+ export default class Request {
20
+ /**
21
+ * @param {Object} arg - 全局配置
22
+ * @param {String} arg.baseURL - 全局根路径
23
+ * @param {Object} arg.header - 全局header
24
+ * @param {String} arg.method = [GET|POST|PUT|DELETE|CONNECT|HEAD|OPTIONS|TRACE] - 全局默认请求方式
25
+ * @param {String} arg.dataType = [json] - 全局默认的dataType
26
+ * @param {String} arg.responseType = [text|arraybuffer] - 全局默认的responseType。支付宝小程序不支持
27
+ * @param {Object} arg.custom - 全局默认的自定义参数
28
+ * @param {Number} arg.timeout - 全局默认的超时时间,单位 ms。默认60000。H5(HBuilderX 2.9.9+)、APP(HBuilderX 2.9.9+)、微信小程序(2.10.0)、支付宝小程序
29
+ * @param {Boolean} arg.sslVerify - 全局默认的是否验证 ssl 证书。默认true.仅App安卓端支持(HBuilderX 2.3.3+)
30
+ * @param {Boolean} arg.withCredentials - 全局默认的跨域请求时是否携带凭证(cookies)。默认false。仅H5支持(HBuilderX 2.6.15+)
31
+ * @param {Boolean} arg.firstIpv4 - 全DNS解析时优先使用ipv4。默认false。仅 App-Android 支持 (HBuilderX 2.8.0+)
32
+ * @param {Function(statusCode):Boolean} arg.validateStatus - 全局默认的自定义验证器。默认statusCode >= 200 && statusCode < 300
33
+ */
34
+ constructor(arg = {}) {
35
+ if (!isPlainObject(arg)) {
36
+ arg = {}
37
+ console.warn('设置全局参数必须接收一个Object')
38
+ }
39
+ this.config = clone({...defaults, ...arg})
40
+ this.interceptors = {
41
+ request: new InterceptorManager(),
42
+ response: new InterceptorManager()
43
+ }
44
+ }
45
+
46
+ /**
47
+ * @Function
48
+ * @param {Request~setConfigCallback} f - 设置全局默认配置
49
+ */
50
+ setConfig(f) {
51
+ this.config = f(this.config)
52
+ }
53
+
54
+ middleware(config) {
55
+ config = mergeConfig(this.config, config)
56
+ let chain = [dispatchRequest, undefined]
57
+ let promise = Promise.resolve(config)
58
+
59
+ this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
60
+ chain.unshift(interceptor.fulfilled, interceptor.rejected)
61
+ })
62
+
63
+ this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
64
+ chain.push(interceptor.fulfilled, interceptor.rejected)
65
+ })
66
+
67
+ while (chain.length) {
68
+ promise = promise.then(chain.shift(), chain.shift())
69
+ }
70
+
71
+ return promise
72
+ }
73
+
74
+ /**
75
+ * @Function
76
+ * @param {Object} config - 请求配置项
77
+ * @prop {String} options.url - 请求路径
78
+ * @prop {Object} options.data - 请求参数
79
+ * @prop {Object} [options.responseType = config.responseType] [text|arraybuffer] - 响应的数据类型
80
+ * @prop {Object} [options.dataType = config.dataType] - 如果设为 json,会尝试对返回的数据做一次 JSON.parse
81
+ * @prop {Object} [options.header = config.header] - 请求header
82
+ * @prop {Object} [options.method = config.method] - 请求方法
83
+ * @returns {Promise<unknown>}
84
+ */
85
+ request(config = {}) {
86
+ return this.middleware(config)
87
+ }
88
+
89
+ get(url, options = {}) {
90
+ return this.middleware({
91
+ url,
92
+ method: 'GET',
93
+ ...options
94
+ })
95
+ }
96
+
97
+ post(url, data, options = {}) {
98
+ return this.middleware({
99
+ url,
100
+ data,
101
+ method: 'POST',
102
+ ...options
103
+ })
104
+ }
105
+
106
+ // #ifndef MP-ALIPAY || MP-KUAISHOU || MP-JD
107
+ put(url, data, options = {}) {
108
+ return this.middleware({
109
+ url,
110
+ data,
111
+ method: 'PUT',
112
+ ...options
113
+ })
114
+ }
115
+
116
+ // #endif
117
+
118
+ // #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-BAIDU
119
+ delete(url, data, options = {}) {
120
+ return this.middleware({
121
+ url,
122
+ data,
123
+ method: 'DELETE',
124
+ ...options
125
+ })
126
+ }
127
+
128
+ // #endif
129
+
130
+ // #ifdef H5 || MP-WEIXIN
131
+ connect(url, data, options = {}) {
132
+ return this.middleware({
133
+ url,
134
+ data,
135
+ method: 'CONNECT',
136
+ ...options
137
+ })
138
+ }
139
+
140
+ // #endif
141
+
142
+ // #ifdef H5 || MP-WEIXIN || MP-BAIDU
143
+ head(url, data, options = {}) {
144
+ return this.middleware({
145
+ url,
146
+ data,
147
+ method: 'HEAD',
148
+ ...options
149
+ })
150
+ }
151
+
152
+ // #endif
153
+
154
+ // #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-BAIDU
155
+ options(url, data, options = {}) {
156
+ return this.middleware({
157
+ url,
158
+ data,
159
+ method: 'OPTIONS',
160
+ ...options
161
+ })
162
+ }
163
+
164
+ // #endif
165
+
166
+ // #ifdef H5 || MP-WEIXIN
167
+ trace(url, data, options = {}) {
168
+ return this.middleware({
169
+ url,
170
+ data,
171
+ method: 'TRACE',
172
+ ...options
173
+ })
174
+ }
175
+
176
+ // #endif
177
+
178
+ upload(url, config = {}) {
179
+ config.url = url
180
+ config.method = 'UPLOAD'
181
+ return this.middleware(config)
182
+ }
183
+
184
+ download(url, config = {}) {
185
+ config.url = url
186
+ config.method = 'DOWNLOAD'
187
+ return this.middleware(config)
188
+ }
189
+
190
+ get version () {
191
+ return '3.1.0'
192
+ }
193
+ }
194
+
195
+
196
+ /**
197
+ * setConfig回调
198
+ * @return {Object} - 返回操作后的config
199
+ * @callback Request~setConfigCallback
200
+ * @param {Object} config - 全局默认config
201
+ */
@@ -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,33 @@
1
+ /**
2
+ * 默认的全局配置
3
+ */
4
+
5
+
6
+ export default {
7
+ baseURL: '',
8
+ header: {},
9
+ method: 'GET',
10
+ dataType: 'json',
11
+ paramsSerializer: null,
12
+ // #ifndef MP-ALIPAY
13
+ responseType: 'text',
14
+ // #endif
15
+ custom: {},
16
+ // #ifdef H5 || APP-PLUS || MP-WEIXIN || MP-ALIPAY || MP-TOUTIAO || MP-KUAISHOU
17
+ timeout: 60000,
18
+ // #endif
19
+ // #ifdef APP-PLUS
20
+ sslVerify: true,
21
+ // #endif
22
+ // #ifdef H5
23
+ withCredentials: false,
24
+ // #endif
25
+ // #ifdef APP-PLUS
26
+ firstIpv4: false,
27
+ // #endif
28
+ validateStatus: function validateStatus(status) {
29
+ return status >= 200 && status < 300
30
+ },
31
+ // 是否尝试将响应数据json化
32
+ forcedJSONParsing: true
33
+ }
@@ -0,0 +1,6 @@
1
+ import adapter from '../adapters/index'
2
+
3
+
4
+ export default (config) => {
5
+ return adapter(config)
6
+ }
@@ -0,0 +1,126 @@
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
+ ]
122
+ config = {...config, ...mergeKeys(defaultsKeys, globalsConfig, config2)}
123
+ }
124
+
125
+ return config
126
+ }
@@ -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,64 @@
1
+ 'use strict'
2
+
3
+ import * as utils from './../utils'
4
+
5
+ function encode(val) {
6
+ return encodeURIComponent(val).replace(/%40/gi, '@').replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%20/g, '+').replace(/%5B/gi, '[').replace(/%5D/gi, ']')
7
+ }
8
+
9
+ /**
10
+ * Build a URL by appending params to the end
11
+ *
12
+ * @param {string} url The base of the url (e.g., http://www.google.com)
13
+ * @param {object} [params] The params to be appended
14
+ * @returns {string} The formatted url
15
+ */
16
+ export default function buildURL(url, params, paramsSerializer) {
17
+ /*eslint no-param-reassign:0*/
18
+ if (!params) {
19
+ return url
20
+ }
21
+
22
+ var serializedParams
23
+ if (paramsSerializer) {
24
+ serializedParams = paramsSerializer(params)
25
+ } else if (utils.isURLSearchParams(params)) {
26
+ serializedParams = params.toString()
27
+ } else {
28
+ var parts = []
29
+
30
+ utils.forEach(params, function serialize(val, key) {
31
+ if (val === null || typeof val === 'undefined') {
32
+ return
33
+ }
34
+
35
+ if (utils.isArray(val)) {
36
+ key = key + '[]'
37
+ } else {
38
+ val = [val]
39
+ }
40
+
41
+ utils.forEach(val, function parseValue(v) {
42
+ if (utils.isDate(v)) {
43
+ v = v.toISOString()
44
+ } else if (utils.isObject(v)) {
45
+ v = JSON.stringify(v)
46
+ }
47
+ parts.push(encode(key) + '=' + encode(v))
48
+ })
49
+ })
50
+
51
+ serializedParams = parts.join('&')
52
+ }
53
+
54
+ if (serializedParams) {
55
+ var hashmarkIndex = url.indexOf('#')
56
+ if (hashmarkIndex !== -1) {
57
+ url = url.slice(0, hashmarkIndex)
58
+ }
59
+
60
+ url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams
61
+ }
62
+
63
+ return url
64
+ }
@@ -0,0 +1,14 @@
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
12
+ ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
13
+ : baseURL
14
+ }
@@ -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
+ }
@@ -0,0 +1,197 @@
1
+ export type HttpTask = UniApp.RequestTask | UniApp.UploadTask | UniApp.DownloadTask;
2
+
3
+ export type HttpRequestTask = UniApp.RequestTask;
4
+
5
+ export type HttpUploadTask = UniApp.UploadTask;
6
+
7
+ export type HttpDownloadTask = UniApp.DownloadTask;
8
+
9
+ export type HttpMethod =
10
+ "GET"
11
+ | "POST"
12
+ | "PUT"
13
+ | "DELETE"
14
+ | "CONNECT"
15
+ | "HEAD"
16
+ | "OPTIONS"
17
+ | "TRACE"
18
+ | "UPLOAD"
19
+ | "DOWNLOAD";
20
+
21
+ export type HttpRequestHeader = Record<string, string>;
22
+
23
+ export type HttpParams = Record<string, any>;
24
+
25
+ export type HttpData = Record<string, any>;
26
+
27
+ export type HttpResponseType = 'arraybuffer' | 'text';
28
+
29
+ export type HttpCustom = Record<string, any>;
30
+
31
+ export type HttpFileType = 'image' | 'video' | 'audio';
32
+
33
+ export type HttpFormData = Record<string, any>;
34
+
35
+ export type HttpResponseHeader = Record<string, string> & {
36
+ "set-cookie"?: string[]
37
+ };
38
+
39
+ export interface HttpRequestConfig<T = HttpTask> {
40
+ /** @desc 请求服务器接口地址 */
41
+ url?: string;
42
+ /** @desc 请求方式,默认为 GET */
43
+ method?: HttpMethod;
44
+ /** @desc 请求基地址 */
45
+ baseURL?: string;
46
+ /** @desc 请求头信息,不能设置 Referer,App、H5 端会自动带上 cookie,且 H5 端不可手动修改 */
47
+ header?: HttpRequestHeader;
48
+ /** @desc 请求查询参数,自动拼接为查询字符串 */
49
+ params?: HttpParams;
50
+ /** @desc 请求体参数 */
51
+ data?: HttpData;
52
+ /** @desc 超时时间,单位 ms,默认为 60000,仅 H5 (HBuilderX 2.9.9+)、APP (HBuilderX 2.9.9+)、微信小程序 (2.10.0)、支付宝小程序支持 */
53
+ timeout?: number;
54
+ /** @desc 跨域请求时是否携带凭证 (cookies),默认为 false,仅 H5 (HBuilderX 2.6.15+) 支持 */
55
+ withCredentials?: boolean;
56
+ /** @desc 设置响应的数据类型,支付宝小程序不支持 */
57
+ responseType?: HttpResponseType;
58
+ /** @desc 全局自定义验证器 */
59
+ validateStatus?: ((statusCode: number) => boolean) | null;
60
+
61
+
62
+ /** params 参数自定义处理 */
63
+ paramsSerializer?: (params: AnyObject) => string | void;
64
+
65
+ /** @desc 默认为 json,如果设为 json,会尝试对返回的数据做一次 JSON.parse */
66
+ dataType?: string;
67
+ /** @desc DNS 解析时是否优先使用 ipv4,默认为 false,仅 App-Android (HBuilderX 2.8.0+) 支持 */
68
+ firstIpv4?: boolean;
69
+ /** @desc 是否验证 SSL 证书,默认为 true,仅 App-Android (HBuilderX 2.3.3+) 支持 */
70
+ sslVerify?: boolean;
71
+
72
+ /** @desc 开启 http2;微信小程序 */
73
+ enableHttp2?: boolean;
74
+
75
+ /** @desc 开启 quic;微信小程序 */
76
+ enableQuic?: boolean;
77
+ /** @desc 开启 cache;微信小程序、字节跳动小程序 2.31.0+ */
78
+ enableCache?: boolean;
79
+ /** @desc 开启 httpDNS;微信小程序 */
80
+ enableHttpDNS?: boolean;
81
+ /** @desc httpDNS 服务商;微信小程序 */
82
+ httpDNSServiceId?: string;
83
+ /** @desc 开启 transfer-encoding chunked;微信小程序 */
84
+ enableChunked?: boolean;
85
+ /** @desc wifi下使用移动网络发送请求;微信小程序 */
86
+ forceCellularNetwork?: boolean;
87
+ /** @desc 开启后可在headers中编辑cookie;支付宝小程序 10.2.33+ */
88
+ enableCookie?: boolean;
89
+ /** @desc 是否开启云加速;百度小程序 3.310.11+ */
90
+ cloudCache?: boolean | object;
91
+ /** @desc 控制当前请求是否延时至首屏内容渲染后发送;百度小程序 3.310.11+ */
92
+ defer?: boolean;
93
+
94
+ /** @desc 自定义参数 */
95
+ custom?: HttpCustom;
96
+
97
+ /** @desc 返回当前请求的 task 和 options,不要在这里修改 options */
98
+ getTask?: (task: T, options: HttpRequestConfig<T>) => void;
99
+
100
+ /** @desc 需要上传的文件列表,使用 files 时,filePath 和 name 不生效,仅支持 App、H5 (2.6.15+) */
101
+ files?: { name?: string; file?: File; uri: string; }[];
102
+ /** @desc 文件类型,仅支付宝小程序支持且为必填项 */
103
+ fileType?: HttpFileType;
104
+ /** @desc 要上传的文件对象,仅 H5 (2.6.15+) 支持 */
105
+ file?: File;
106
+ /** @desc 要上传文件资源的路径,使用 files 时,filePath 和 name 不生效 */
107
+ filePath?: string;
108
+ /** @desc 文件对应的 key,开发者在服务器端通过这个 key 可以获取到文件二进制内容,使用 files 时,filePath 和 name 不生效 */
109
+ name?: string;
110
+ /** @desc 请求中其他额外的 form data */
111
+ formData?: HttpFormData;
112
+ }
113
+
114
+ export interface HttpResponse<T = any, D = HttpTask> {
115
+ data: T;
116
+ statusCode: number;
117
+ header: HttpResponseHeader;
118
+ config: HttpRequestConfig<D>;
119
+ cookies: string[];
120
+ errMsg: string;
121
+ rawData: any;
122
+ }
123
+
124
+ export interface HttpUploadResponse<T = any, D = HttpTask> {
125
+ data: T;
126
+ statusCode: number;
127
+ config: HttpRequestConfig<D>;
128
+ errMsg: string;
129
+ rawData: any;
130
+ }
131
+
132
+ export interface HttpDownloadResponse extends HttpResponse {
133
+ tempFilePath: string;
134
+ apFilePath?: string;
135
+ filePath?: string;
136
+ fileContent?: string;
137
+ }
138
+
139
+ export interface HttpError<T = any, D = HttpTask> {
140
+ data?: T;
141
+ statusCode?: number;
142
+ header?: HttpResponseHeader;
143
+ config: HttpRequestConfig<D>;
144
+ cookies?: string[];
145
+ errMsg: string;
146
+ }
147
+
148
+ export interface HttpPromise<T = any> extends Promise<HttpResponse<T>> {
149
+ }
150
+
151
+ export interface HttpInterceptorManager<V, E = V> {
152
+ use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: E) => T | Promise<E>): void;
153
+
154
+ eject(id: number): void;
155
+ }
156
+
157
+ export abstract class HttpRequestAbstract {
158
+ constructor(config?: HttpRequestConfig);
159
+
160
+ interceptors: {
161
+ request: HttpInterceptorManager<HttpRequestConfig>;
162
+ response: HttpInterceptorManager<HttpResponse, HttpError>;
163
+ }
164
+
165
+ request<T = any, R = HttpResponse<T>, D = HttpRequestTask>(config: HttpRequestConfig<D>): Promise<R>;
166
+
167
+ get<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, config?: HttpRequestConfig<D>): Promise<R>;
168
+
169
+ delete<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, data?: HttpData, config?: HttpRequestConfig<D>): Promise<R>;
170
+
171
+ head<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, data?: HttpData, config?: HttpRequestConfig<D>): Promise<R>;
172
+
173
+ options<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, data?: HttpData, config?: HttpRequestConfig<D>): Promise<R>;
174
+
175
+ post<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, data?: HttpData, config?: HttpRequestConfig<D>): Promise<R>;
176
+
177
+ put<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, data?: HttpData, config?: HttpRequestConfig<D>): Promise<R>;
178
+
179
+ config: HttpRequestConfig;
180
+
181
+ setConfig<D = HttpTask>(onSend: (config: HttpRequestConfig<D>) => HttpRequestConfig<D>): void;
182
+
183
+ connect<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, data?: HttpData, config?: HttpRequestConfig<D>): Promise<R>;
184
+
185
+ trace<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, data?: HttpData, config?: HttpRequestConfig<D>): Promise<R>;
186
+
187
+ upload<T = any, R = HttpUploadResponse<T>, D = HttpUploadTask>(url: string, config?: HttpRequestConfig<D>): Promise<R>;
188
+
189
+ download<T = any, R = HttpDownloadResponse<T>, D = HttpDownloadTask>(url: string, config?: HttpRequestConfig<D>): Promise<R>;
190
+
191
+ middleware<T = any, R = HttpResponse<T>, D = HttpTask>(config: HttpRequestConfig<D>): Promise<R>;
192
+ }
193
+
194
+ declare class HttpRequest extends HttpRequestAbstract {
195
+ }
196
+
197
+ export default HttpRequest;