@tarojs/taro-h5 3.6.12-alpha.0 → 3.6.12
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/dist/api/media/image/previewImage.js +8 -3
- package/dist/api/media/image/previewImage.js.map +1 -1
- package/dist/api/network/request/index.js +30 -29
- package/dist/api/network/request/index.js.map +1 -1
- package/dist/api/network/websocket/index.js +2 -2
- package/dist/api/network/websocket/index.js.map +1 -1
- package/dist/index.cjs.js +39 -34
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +40 -35
- package/dist/index.esm.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __awaiter } from '../../../node_modules/.pnpm/registry.npmjs.org_tslib@2.5.0/node_modules/tslib/tslib.es6.js';
|
|
2
2
|
import { defineCustomElementTaroSwiperCore, defineCustomElementTaroSwiperItemCore } from '@tarojs/components/dist/components';
|
|
3
|
+
import { eventCenter } from '@tarojs/runtime';
|
|
3
4
|
import { isFunction } from '@tarojs/shared';
|
|
4
5
|
import { shouldBeObject } from '../../../utils/index.js';
|
|
5
6
|
import { MethodHandler } from '../../../utils/handler.js';
|
|
@@ -45,12 +46,16 @@ const previewImage = (options) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
45
46
|
const { urls = [], current = '', success, fail, complete } = options;
|
|
46
47
|
const handle = new MethodHandler({ name: 'previewImage', success, fail, complete });
|
|
47
48
|
const container = document.createElement('div');
|
|
49
|
+
const removeHandler = () => {
|
|
50
|
+
eventCenter.off('__taroRouterChange', removeHandler);
|
|
51
|
+
container.remove();
|
|
52
|
+
};
|
|
53
|
+
// 路由改变后应该关闭预览框
|
|
54
|
+
eventCenter.on('__taroRouterChange', removeHandler);
|
|
48
55
|
container.classList.add('preview-image');
|
|
49
56
|
container.style.cssText =
|
|
50
57
|
'position:fixed;top:0;left:0;z-index:1050;width:100%;height:100%;overflow:hidden;outline:0;background-color:#111;';
|
|
51
|
-
container.addEventListener('click',
|
|
52
|
-
container.remove();
|
|
53
|
-
});
|
|
58
|
+
container.addEventListener('click', removeHandler);
|
|
54
59
|
const swiper = document.createElement('taro-swiper-core');
|
|
55
60
|
// @ts-ignore
|
|
56
61
|
swiper.full = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"previewImage.js","sources":["../../../../src/api/media/image/previewImage.ts"],"sourcesContent":["import Taro from '@tarojs/api'\nimport { SwiperProps } from '@tarojs/components'\nimport {\n defineCustomElementTaroSwiperCore,\n defineCustomElementTaroSwiperItemCore,\n} from '@tarojs/components/dist/components'\nimport { isFunction } from '@tarojs/shared'\n\nimport { shouldBeObject } from '../../../utils'\nimport { MethodHandler } from '../../../utils/handler'\n\n/**\n * previewImage api基于开源的React组件[react-wx-images-viewer](https://github.com/react-ld/react-wx-images-viewer)开发,感谢!\n */\n\n/**\n * 在新页面中全屏预览图片。预览的过程中用户可以进行保存图片、发送给朋友等操作。\n */\nexport const previewImage: typeof Taro.previewImage = async (options) => {\n // TODO 改为通过 window.__taroAppConfig 获取配置的 Swiper 插件创建节点\n defineCustomElementTaroSwiperCore()\n defineCustomElementTaroSwiperItemCore()\n\n function loadImage (url: string, loadFail: typeof fail): Promise<Node> {\n return new Promise((resolve) => {\n const item = document.createElement('taro-swiper-item-core')\n item.style.cssText = 'display:flex;align-items:start;justify-content:center;overflow-y:scroll;'\n const image = new Image()\n image.style.maxWidth = '100%'\n image.src = url\n const div = document.createElement('div')\n div.classList.add('swiper-zoom-container')\n div.style.cssText = 'display:flex;align-items:center;justify-content:center;max-width:100%;min-height:100%;'\n div.appendChild(image)\n item.appendChild(div)\n // Note: 等待图片加载完后返回,会导致轮播被卡住\n resolve(item)\n if (isFunction(loadFail)) {\n image.addEventListener('error', (err) => {\n loadFail({ errMsg: err.message })\n })\n }\n })\n }\n\n // options must be an Object\n const isObject = shouldBeObject(options)\n if (!isObject.flag) {\n const res = { errMsg: `previewImage:fail ${isObject.msg}` }\n console.error(res.errMsg)\n return Promise.reject(res)\n }\n\n const { urls = [], current = '', success, fail, complete } = options\n const handle = new MethodHandler({ name: 'previewImage', success, fail, complete })\n const container = document.createElement('div')\n container.classList.add('preview-image')\n container.style.cssText =\n 'position:fixed;top:0;left:0;z-index:1050;width:100%;height:100%;overflow:hidden;outline:0;background-color:#111;'\n container.addEventListener('click',
|
|
1
|
+
{"version":3,"file":"previewImage.js","sources":["../../../../src/api/media/image/previewImage.ts"],"sourcesContent":["import Taro from '@tarojs/api'\nimport { SwiperProps } from '@tarojs/components'\nimport {\n defineCustomElementTaroSwiperCore,\n defineCustomElementTaroSwiperItemCore,\n} from '@tarojs/components/dist/components'\nimport { eventCenter } from '@tarojs/runtime'\nimport { isFunction } from '@tarojs/shared'\n\nimport { shouldBeObject } from '../../../utils'\nimport { MethodHandler } from '../../../utils/handler'\n\n/**\n * previewImage api基于开源的React组件[react-wx-images-viewer](https://github.com/react-ld/react-wx-images-viewer)开发,感谢!\n */\n\n/**\n * 在新页面中全屏预览图片。预览的过程中用户可以进行保存图片、发送给朋友等操作。\n */\nexport const previewImage: typeof Taro.previewImage = async (options) => {\n // TODO 改为通过 window.__taroAppConfig 获取配置的 Swiper 插件创建节点\n defineCustomElementTaroSwiperCore()\n defineCustomElementTaroSwiperItemCore()\n\n function loadImage (url: string, loadFail: typeof fail): Promise<Node> {\n return new Promise((resolve) => {\n const item = document.createElement('taro-swiper-item-core')\n item.style.cssText = 'display:flex;align-items:start;justify-content:center;overflow-y:scroll;'\n const image = new Image()\n image.style.maxWidth = '100%'\n image.src = url\n const div = document.createElement('div')\n div.classList.add('swiper-zoom-container')\n div.style.cssText = 'display:flex;align-items:center;justify-content:center;max-width:100%;min-height:100%;'\n div.appendChild(image)\n item.appendChild(div)\n // Note: 等待图片加载完后返回,会导致轮播被卡住\n resolve(item)\n if (isFunction(loadFail)) {\n image.addEventListener('error', (err) => {\n loadFail({ errMsg: err.message })\n })\n }\n })\n }\n\n // options must be an Object\n const isObject = shouldBeObject(options)\n if (!isObject.flag) {\n const res = { errMsg: `previewImage:fail ${isObject.msg}` }\n console.error(res.errMsg)\n return Promise.reject(res)\n }\n\n const { urls = [], current = '', success, fail, complete } = options\n const handle = new MethodHandler({ name: 'previewImage', success, fail, complete })\n const container = document.createElement('div')\n const removeHandler = () => {\n eventCenter.off('__taroRouterChange', removeHandler)\n container.remove()\n }\n // 路由改变后应该关闭预览框\n eventCenter.on('__taroRouterChange', removeHandler)\n\n container.classList.add('preview-image')\n container.style.cssText =\n 'position:fixed;top:0;left:0;z-index:1050;width:100%;height:100%;overflow:hidden;outline:0;background-color:#111;'\n container.addEventListener('click', removeHandler)\n\n const swiper: HTMLElement & Omit<SwiperProps, 'style' | 'children'> = document.createElement('taro-swiper-core')\n // @ts-ignore\n swiper.full = true\n // @ts-ignore\n swiper.zoom = true\n\n let children: Node[] = []\n try {\n children = await Promise.all(urls.map((e) => loadImage(e, fail)))\n } catch (error) {\n return handle.fail({\n errMsg: error,\n })\n }\n\n for (let i = 0; i < children.length; i++) {\n const child = children[i]\n swiper.appendChild(child)\n }\n\n const currentIndex = typeof current === 'number' ? current : urls.indexOf(current)\n\n swiper.current = currentIndex\n\n container.appendChild(swiper)\n document.body.appendChild(container)\n\n return handle.success()\n}\n"],"names":[],"mappings":";;;;;;;AAYA;;AAEG;AAEH;;AAEG;AACU,MAAA,YAAY,GAA6B,CAAO,OAAO,KAAI,SAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;;AAEtE,IAAA,iCAAiC,EAAE,CAAA;AACnC,IAAA,qCAAqC,EAAE,CAAA;AAEvC,IAAA,SAAS,SAAS,CAAE,GAAW,EAAE,QAAqB,EAAA;AACpD,QAAA,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,KAAI;YAC7B,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,uBAAuB,CAAC,CAAA;AAC5D,YAAA,IAAI,CAAC,KAAK,CAAC,OA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MAAM,EAAE,CAAC,EAAE,EAAE;AACxC,QAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;AACzB,QAAA,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;AAC1B,KAAA;AAED,IAAA,MAAM,YAAY,GAAG,OAAO,OAAO,KAAK,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAElF,IAAA,MAAM,CAAC,OAAO,GAAG,YAAY,CAAA;AAE7B,IAAA,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;AAC7B,IAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAA;AAEpC,IAAA,OAAO,MAAM,CAAC,OAAO,EAAE,CAAA;AACzB,CAAC;;;;"}
|
|
@@ -18,19 +18,21 @@ function generateRequestUrlWithParams(url = '', params) {
|
|
|
18
18
|
}
|
|
19
19
|
function _request(options = {}) {
|
|
20
20
|
const { success, complete, fail } = options;
|
|
21
|
-
let url = options.url || '';
|
|
22
21
|
const params = {};
|
|
23
22
|
const res = {};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
let { cache = 'default', credentials, data, dataType, header = {}, jsonp, method = 'GET', mode, responseType, signal, timeout = 2000, url = '' } = options, opts = __rest(options, ["cache", "credentials", "data", "dataType", "header", "jsonp", "method", "mode", "responseType", "signal", "timeout", "url"]);
|
|
24
|
+
Object.assign(params, opts);
|
|
25
|
+
if (jsonp) {
|
|
27
26
|
// @ts-ignore
|
|
28
|
-
params.params =
|
|
27
|
+
params.params = data;
|
|
29
28
|
params.cache = opts.jsonpCache;
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
params.timeout = timeout;
|
|
30
31
|
if (typeof jsonp === 'string') {
|
|
31
32
|
// @ts-ignore
|
|
32
33
|
params.name = jsonp;
|
|
33
34
|
}
|
|
35
|
+
// Note: https://github.com/luckyadam/jsonp-retry
|
|
34
36
|
return jsonpRetry(url, params)
|
|
35
37
|
.then(data => {
|
|
36
38
|
res.statusCode = 200;
|
|
@@ -45,50 +47,49 @@ function _request(options = {}) {
|
|
|
45
47
|
return Promise.reject(err);
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
|
-
params.method =
|
|
50
|
+
params.method = method;
|
|
49
51
|
const methodUpper = params.method.toUpperCase();
|
|
50
|
-
params.cache =
|
|
52
|
+
params.cache = cache;
|
|
51
53
|
if (methodUpper === 'GET' || methodUpper === 'HEAD') {
|
|
52
|
-
url = generateRequestUrlWithParams(url,
|
|
54
|
+
url = generateRequestUrlWithParams(url, data);
|
|
53
55
|
}
|
|
54
|
-
else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(
|
|
55
|
-
|
|
56
|
-
const keyOfContentType = Object.keys(options.header).find(item => item.toLowerCase() === 'content-type');
|
|
56
|
+
else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(data)) >= 0) {
|
|
57
|
+
const keyOfContentType = Object.keys(header).find(item => item.toLowerCase() === 'content-type');
|
|
57
58
|
if (!keyOfContentType) {
|
|
58
|
-
|
|
59
|
+
header['Content-Type'] = 'application/json';
|
|
59
60
|
}
|
|
60
|
-
const contentType =
|
|
61
|
+
const contentType = header[keyOfContentType || 'Content-Type'];
|
|
61
62
|
if (contentType.indexOf('application/json') >= 0) {
|
|
62
|
-
params.body = JSON.stringify(
|
|
63
|
+
params.body = JSON.stringify(data);
|
|
63
64
|
}
|
|
64
65
|
else if (contentType.indexOf('application/x-www-form-urlencoded') >= 0) {
|
|
65
|
-
params.body = serializeParams(
|
|
66
|
+
params.body = serializeParams(data);
|
|
66
67
|
}
|
|
67
68
|
else {
|
|
68
|
-
params.body =
|
|
69
|
+
params.body = data;
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
else {
|
|
72
|
-
params.body =
|
|
73
|
+
params.body = data;
|
|
73
74
|
}
|
|
74
|
-
if (
|
|
75
|
-
params.headers =
|
|
75
|
+
if (header) {
|
|
76
|
+
params.headers = header;
|
|
76
77
|
}
|
|
77
|
-
if (
|
|
78
|
-
params.mode =
|
|
78
|
+
if (mode) {
|
|
79
|
+
params.mode = mode;
|
|
79
80
|
}
|
|
80
81
|
let timeoutTimer = null;
|
|
81
|
-
if (
|
|
82
|
-
params.signal =
|
|
82
|
+
if (signal) {
|
|
83
|
+
params.signal = signal;
|
|
83
84
|
}
|
|
84
|
-
else if (typeof
|
|
85
|
+
else if (typeof timeout === 'number') {
|
|
85
86
|
const controller = new window.AbortController();
|
|
86
87
|
params.signal = controller.signal;
|
|
87
88
|
timeoutTimer = setTimeout(function () {
|
|
88
89
|
controller.abort();
|
|
89
|
-
},
|
|
90
|
+
}, timeout);
|
|
90
91
|
}
|
|
91
|
-
params.credentials =
|
|
92
|
+
params.credentials = credentials;
|
|
92
93
|
return fetch(url, params)
|
|
93
94
|
.then(response => {
|
|
94
95
|
if (timeoutTimer) {
|
|
@@ -104,17 +105,17 @@ function _request(options = {}) {
|
|
|
104
105
|
for (const key of response.headers.keys()) {
|
|
105
106
|
res.header[key] = response.headers.get(key);
|
|
106
107
|
}
|
|
107
|
-
if (
|
|
108
|
+
if (responseType === 'arraybuffer') {
|
|
108
109
|
return response.arrayBuffer();
|
|
109
110
|
}
|
|
110
111
|
if (res.statusCode !== 204) {
|
|
111
|
-
if (
|
|
112
|
+
if (dataType === 'json' || typeof dataType === 'undefined') {
|
|
112
113
|
return response.json().catch(() => {
|
|
113
114
|
return null;
|
|
114
115
|
});
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
|
-
if (
|
|
118
|
+
if (responseType === 'text' || dataType === 'text') {
|
|
118
119
|
return response.text();
|
|
119
120
|
}
|
|
120
121
|
return Promise.resolve(null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/api/network/request/index.ts"],"sourcesContent":["import 'whatwg-fetch'\nimport 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'\n\nimport Taro from '@tarojs/api'\nimport { isFunction } from '@tarojs/shared'\nimport jsonpRetry from 'jsonp-retry'\n\nimport { serializeParams } from '../../../utils'\n\n// @ts-ignore\nconst { Link } = Taro\n\nfunction generateRequestUrlWithParams (url = '', params?: unknown) {\n params = typeof params === 'string' ? params : serializeParams(params)\n if (params) {\n url += (~url.indexOf('?') ? '&' : '?') + params\n }\n url = url.replace('?&', '?')\n return url\n}\n\nfunction _request (options: Partial<Taro.request.Option> = {}) {\n const { success, complete, fail } = options\n let url = options.url || ''\n const params: RequestInit = {}\n const res: any = {}\n if (options.jsonp) {\n const { jsonp, ...opts } = options\n Object.assign(params, opts)\n // @ts-ignore\n params.params = opts.data\n params.cache = opts.jsonpCache\n if (typeof jsonp === 'string') {\n // @ts-ignore\n params.name = jsonp\n }\n return jsonpRetry(url, params)\n .then(data => {\n res.statusCode = 200\n res.data = data\n isFunction(success) && success(res)\n isFunction(complete) && complete(res)\n return res\n })\n .catch(err => {\n isFunction(fail) && fail(err)\n isFunction(complete) && complete(res)\n return Promise.reject(err)\n })\n }\n params.method = options.method || 'GET'\n const methodUpper = params.method.toUpperCase()\n params.cache = options.cache || 'default'\n if (methodUpper === 'GET' || methodUpper === 'HEAD') {\n url = generateRequestUrlWithParams(url, options.data)\n } else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(options.data)) >= 0) {\n options.header = options.header || {}\n\n const keyOfContentType = Object.keys(options.header).find(item => item.toLowerCase() === 'content-type')\n if (!keyOfContentType) {\n options.header['Content-Type'] = 'application/json'\n }\n const contentType = options.header[keyOfContentType || 'Content-Type']\n\n if (contentType.indexOf('application/json') >= 0) {\n params.body = JSON.stringify(options.data)\n } else if (contentType.indexOf('application/x-www-form-urlencoded') >= 0) {\n params.body = serializeParams(options.data)\n } else {\n params.body = options.data\n }\n } else {\n params.body = options.data\n }\n if (options.header) {\n params.headers = options.header\n }\n if (options.mode) {\n params.mode = options.mode\n }\n let timeoutTimer: ReturnType<typeof setTimeout> | null = null\n if (options.signal) {\n params.signal = options.signal\n } else if (typeof options.timeout === 'number') {\n const controller = new window.AbortController()\n params.signal = controller.signal\n timeoutTimer = setTimeout(function () {\n controller.abort()\n }, options.timeout)\n }\n params.credentials = options.credentials\n return fetch(url, params)\n .then(response => {\n if (timeoutTimer) {\n clearTimeout(timeoutTimer)\n timeoutTimer = null\n }\n if (!response) {\n const errorResponse = { ok: false }\n throw errorResponse\n }\n res.statusCode = response.status\n res.header = {}\n for (const key of response.headers.keys()) {\n res.header[key] = response.headers.get(key)\n }\n if (options.responseType === 'arraybuffer') {\n return response.arrayBuffer()\n }\n if (res.statusCode !== 204) {\n if (options.dataType === 'json' || typeof options.dataType === 'undefined') {\n return response.json().catch(() => {\n return null\n })\n }\n }\n if (options.responseType === 'text' || options.dataType === 'text') {\n return response.text()\n }\n return Promise.resolve(null)\n })\n .then(data => {\n res.data = data\n isFunction(success) && success(res)\n isFunction(complete) && complete(res)\n return res\n })\n .catch(err => {\n if (timeoutTimer) {\n clearTimeout(timeoutTimer)\n timeoutTimer = null\n }\n isFunction(fail) && fail(err)\n isFunction(complete) && complete(res)\n err.statusCode = res.statusCode\n err.errMsg = err.message\n return Promise.reject(err)\n })\n}\n\nfunction taroInterceptor (chain) {\n return _request(chain.requestParams)\n}\n\nconst link = new Link(taroInterceptor)\n\nexport const request = (<T extends Partial<Taro.request.Option> = TaroGeneral.IAnyObject>(...args: [string | T, T]) => {\n const [url = '', options = {} as T] = args\n if (typeof url === 'string') {\n options.url = url\n } else {\n Object.assign(options, url)\n }\n return link.request(options)\n}) as typeof Taro.request\nexport const addInterceptor = link.addInterceptor.bind(link)\nexport const cleanInterceptors = link.cleanInterceptors.bind(link)\n"],"names":[],"mappings":";;;;;;;;AASA;AACA,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;AAErB,SAAS,4BAA4B,CAAE,GAAG,GAAG,EAAE,EAAE,MAAgB,EAAA;AAC/D,IAAA,MAAM,GAAG,OAAO,MAAM,KAAK,QAAQ,G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AAO,GAAG,KAAK,QAAQ,EAAE;AAC3B,QAAA,OAAO,CAAC,GAAG,GAAG,GAAG,CAAA;AAClB,KAAA;AAAM,SAAA;AACL,QAAA,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;AAC5B,KAAA;AACD,IAAA,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAC9B,CAAC,EAAwB;AAClB,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAC;AACrD,MAAM,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/api/network/request/index.ts"],"sourcesContent":["import 'whatwg-fetch'\nimport 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'\n\nimport Taro from '@tarojs/api'\nimport { isFunction } from '@tarojs/shared'\nimport jsonpRetry from 'jsonp-retry'\n\nimport { serializeParams } from '../../../utils'\n\n// @ts-ignore\nconst { Link } = Taro\n\nfunction generateRequestUrlWithParams (url = '', params?: unknown) {\n params = typeof params === 'string' ? params : serializeParams(params)\n if (params) {\n url += (~url.indexOf('?') ? '&' : '?') + params\n }\n url = url.replace('?&', '?')\n return url\n}\n\nfunction _request (options: Partial<Taro.request.Option> = {}) {\n const { success, complete, fail } = options\n const params: RequestInit = {}\n const res: any = {}\n let {\n cache = 'default',\n credentials,\n data, dataType,\n header = {},\n jsonp,\n method = 'GET',\n mode,\n responseType,\n signal,\n timeout = 2000,\n url = '',\n ...opts\n } = options\n Object.assign(params, opts)\n if (jsonp) {\n // @ts-ignore\n params.params = data\n params.cache = opts.jsonpCache\n // @ts-ignore\n params.timeout = timeout\n if (typeof jsonp === 'string') {\n // @ts-ignore\n params.name = jsonp\n }\n // Note: https://github.com/luckyadam/jsonp-retry\n return jsonpRetry(url, params)\n .then(data => {\n res.statusCode = 200\n res.data = data\n isFunction(success) && success(res)\n isFunction(complete) && complete(res)\n return res\n })\n .catch(err => {\n isFunction(fail) && fail(err)\n isFunction(complete) && complete(res)\n return Promise.reject(err)\n })\n }\n params.method = method\n const methodUpper = params.method.toUpperCase()\n params.cache = cache\n if (methodUpper === 'GET' || methodUpper === 'HEAD') {\n url = generateRequestUrlWithParams(url, data)\n } else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(data)) >= 0) {\n const keyOfContentType = Object.keys(header).find(item => item.toLowerCase() === 'content-type')\n if (!keyOfContentType) {\n header['Content-Type'] = 'application/json'\n }\n const contentType = header[keyOfContentType || 'Content-Type']\n\n if (contentType.indexOf('application/json') >= 0) {\n params.body = JSON.stringify(data)\n } else if (contentType.indexOf('application/x-www-form-urlencoded') >= 0) {\n params.body = serializeParams(data)\n } else {\n params.body = data\n }\n } else {\n params.body = data\n }\n if (header) {\n params.headers = header\n }\n if (mode) {\n params.mode = mode\n }\n let timeoutTimer: ReturnType<typeof setTimeout> | null = null\n if (signal) {\n params.signal = signal\n } else if (typeof timeout === 'number') {\n const controller = new window.AbortController()\n params.signal = controller.signal\n timeoutTimer = setTimeout(function () {\n controller.abort()\n }, timeout)\n }\n params.credentials = credentials\n return fetch(url, params)\n .then(response => {\n if (timeoutTimer) {\n clearTimeout(timeoutTimer)\n timeoutTimer = null\n }\n if (!response) {\n const errorResponse = { ok: false }\n throw errorResponse\n }\n res.statusCode = response.status\n res.header = {}\n for (const key of response.headers.keys()) {\n res.header[key] = response.headers.get(key)\n }\n if (responseType === 'arraybuffer') {\n return response.arrayBuffer()\n }\n if (res.statusCode !== 204) {\n if (dataType === 'json' || typeof dataType === 'undefined') {\n return response.json().catch(() => {\n return null\n })\n }\n }\n if (responseType === 'text' || dataType === 'text') {\n return response.text()\n }\n return Promise.resolve(null)\n })\n .then(data => {\n res.data = data\n isFunction(success) && success(res)\n isFunction(complete) && complete(res)\n return res\n })\n .catch(err => {\n if (timeoutTimer) {\n clearTimeout(timeoutTimer)\n timeoutTimer = null\n }\n isFunction(fail) && fail(err)\n isFunction(complete) && complete(res)\n err.statusCode = res.statusCode\n err.errMsg = err.message\n return Promise.reject(err)\n })\n}\n\nfunction taroInterceptor (chain) {\n return _request(chain.requestParams)\n}\n\nconst link = new Link(taroInterceptor)\n\nexport const request = (<T extends Partial<Taro.request.Option> = TaroGeneral.IAnyObject>(...args: [string | T, T]) => {\n const [url = '', options = {} as T] = args\n if (typeof url === 'string') {\n options.url = url\n } else {\n Object.assign(options, url)\n }\n return link.request(options)\n}) as typeof Taro.request\nexport const addInterceptor = link.addInterceptor.bind(link)\nexport const cleanInterceptors = link.cleanInterceptors.bind(link)\n"],"names":[],"mappings":";;;;;;;;AASA;AACA,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;AAErB,SAAS,4BAA4B,CAAE,GAAG,GAAG,EAAE,EAAE,MAAgB,EAAA;AAC/D,IAAA,MAAM,GAAG,OAAO,MAAM,KAAK,QAAQ,GAAG,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAA;AACtE,IAAA,IAAI,MAAM,EAAE;QACV,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,IAAI,MAAM,CAAA;AAChD,KAAA;IACD,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;AAC5B,IAAA,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,SAAS,QAAQ,CAAE,OAAA,GAAwC,EAAE,EAAA;IAC3D,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,OAAO,CAAA;IAC3C,MAAM,MAAM,GAAgB,EAAE,CAAA;IAC9B,MAAM,GAAG,GAAQ,EAAE,CAAA;AACnB,IAAA,IAAI,EACF,KAAK,GAAG,SAAS,EACjB,WAAW,EACX,IAAI,EAAE,QAAQ,EACd,MAAM,GAAG,EAAE,EACX,KAAK,EACL,MAAM,GAAG,KAAK,EACd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,UAAU,CAAA;AAC/B,QAAA,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,OAAO,CAAA;AACxB,QAAA,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AAC5B,KAAC,CAAC,CAAA;AACN,CAAC;AAED,SAAS,eAAe,CAAE,KAAK,EAAA;AAC7B,IAAA,OAAO,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;AACtC,CAAC;AAED,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,eAAe,CAAC,CAAA;MAEzB,OAAO,IAAI,CAAkE,GAAG,IAAqB,KAAI;IACpH,MAAM,CAAC,GAAG,GAAG,EAAE,EAAE,OAAO,GAAG,EAAO,CAAC,GAAG,IAAI,CAAA;AAC1C,IAAA,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;AAC3B,QAAA,OAAO,CAAC,GAAG,GAAG,GAAG,CAAA;AAClB,KAAA;AAAM,SAAA;AACL,QAAA,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;AAC5B,KAAA;AACD,IAAA,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAC9B,CAAC,EAAwB;AAClB,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAC;AACrD,MAAM,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI;;;;"}
|
|
@@ -50,9 +50,9 @@ function connectSocket(options) {
|
|
|
50
50
|
// protocols must be array
|
|
51
51
|
const _protocols = Array.isArray(protocols) ? protocols : null;
|
|
52
52
|
// 2 connection at most
|
|
53
|
-
if (socketTasks.length
|
|
53
|
+
if (socketTasks.length >= 5) {
|
|
54
54
|
return handle.fail({
|
|
55
|
-
errMsg: '同时最多发起
|
|
55
|
+
errMsg: '同时最多发起 5 个 socket 请求,更多请参考文档。'
|
|
56
56
|
}, { resolve, reject });
|
|
57
57
|
}
|
|
58
58
|
const task = new SocketTask(url, _protocols);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/api/network/websocket/index.ts"],"sourcesContent":["import { getParameterError, shouldBeObject } from '../../../utils'\nimport { MethodHandler } from '../../../utils/handler'\nimport { SocketTask } from './socketTask'\n\nlet socketTasks: SocketTask[] = []\nlet socketsCounter = 1\n\nexport function sendSocketMessage () {\n console.warn('Deprecated.Please use socketTask.send instead.')\n}\n\nexport function onSocketOpen () {\n console.warn('Deprecated.Please use socketTask.onOpen instead.')\n}\n\nexport function onSocketMessage () {\n console.warn('Deprecated.Please use socketTask.onMessage instead.')\n}\n\nexport function onSocketError () {\n console.warn('Deprecated.Please use socketTask.onError instead.')\n}\n\nexport function onSocketClose () {\n console.warn('Deprecated.Please use socketTask.onClose instead.')\n}\n\nexport function connectSocket (options?: Taro.connectSocket.Option) {\n const name = 'connectSocket'\n\n return new Promise((resolve, reject) => {\n // options must be an Object\n const isObject = shouldBeObject(options)\n if (!isObject.flag) {\n const res = { errMsg: `${name}:fail ${isObject.msg}` }\n console.error(res.errMsg)\n return reject(res)\n }\n const { url, protocols, success, fail, complete } = options as Exclude<typeof options, undefined>\n const handle = new MethodHandler<{\n socketTaskId?: number\n }>({ name, success, fail, complete })\n\n // options.url must be String\n if (typeof url !== 'string') {\n return handle.fail({\n errMsg: getParameterError({\n para: 'url',\n correct: 'String',\n wrong: url\n })\n }, { resolve, reject })\n }\n\n // options.url must be invalid\n if (!url.startsWith('ws://') && !url.startsWith('wss://')) {\n return handle.fail({\n errMsg: `request:fail invalid url \"${url}\"`\n }, { resolve, reject })\n }\n\n // protocols must be array\n const _protocols = Array.isArray(protocols) ? protocols : null\n\n // 2 connection at most\n if (socketTasks.length
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/api/network/websocket/index.ts"],"sourcesContent":["import { getParameterError, shouldBeObject } from '../../../utils'\nimport { MethodHandler } from '../../../utils/handler'\nimport { SocketTask } from './socketTask'\n\nlet socketTasks: SocketTask[] = []\nlet socketsCounter = 1\n\nexport function sendSocketMessage () {\n console.warn('Deprecated.Please use socketTask.send instead.')\n}\n\nexport function onSocketOpen () {\n console.warn('Deprecated.Please use socketTask.onOpen instead.')\n}\n\nexport function onSocketMessage () {\n console.warn('Deprecated.Please use socketTask.onMessage instead.')\n}\n\nexport function onSocketError () {\n console.warn('Deprecated.Please use socketTask.onError instead.')\n}\n\nexport function onSocketClose () {\n console.warn('Deprecated.Please use socketTask.onClose instead.')\n}\n\nexport function connectSocket (options?: Taro.connectSocket.Option) {\n const name = 'connectSocket'\n\n return new Promise((resolve, reject) => {\n // options must be an Object\n const isObject = shouldBeObject(options)\n if (!isObject.flag) {\n const res = { errMsg: `${name}:fail ${isObject.msg}` }\n console.error(res.errMsg)\n return reject(res)\n }\n const { url, protocols, success, fail, complete } = options as Exclude<typeof options, undefined>\n const handle = new MethodHandler<{\n socketTaskId?: number\n }>({ name, success, fail, complete })\n\n // options.url must be String\n if (typeof url !== 'string') {\n return handle.fail({\n errMsg: getParameterError({\n para: 'url',\n correct: 'String',\n wrong: url\n })\n }, { resolve, reject })\n }\n\n // options.url must be invalid\n if (!url.startsWith('ws://') && !url.startsWith('wss://')) {\n return handle.fail({\n errMsg: `request:fail invalid url \"${url}\"`\n }, { resolve, reject })\n }\n\n // protocols must be array\n const _protocols = Array.isArray(protocols) ? protocols : null\n\n // 2 connection at most\n if (socketTasks.length >= 5) {\n return handle.fail({\n errMsg: '同时最多发起 5 个 socket 请求,更多请参考文档。'\n }, { resolve, reject })\n }\n\n const task = new SocketTask(url, _protocols)\n task._destroyWhenClose = function () {\n socketTasks = socketTasks.filter(socketTask => socketTask !== this)\n }\n socketTasks.push(task)\n\n handle.success({\n socketTaskId: socketsCounter++\n })\n\n return resolve(task)\n })\n}\n\nexport function closeSocket () {\n console.warn('Deprecated.Please use socketTask.close instead.')\n}\n"],"names":[],"mappings":";;;;AAIA,IAAI,WAAW,GAAiB,EAAE,CAAA;AA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CAAC,IAAI,CAAC,CAAA;AACtB,KAAC,CAAC,CAAA;AACJ,CAAC;SAEe,WAAW,GAAA;AACzB,IAAA,OAAO,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAA;AACjE;;;;"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -2708,12 +2708,16 @@ const previewImage = (options) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
2708
2708
|
const { urls = [], current = '', success, fail, complete } = options;
|
|
2709
2709
|
const handle = new MethodHandler({ name: 'previewImage', success, fail, complete });
|
|
2710
2710
|
const container = document.createElement('div');
|
|
2711
|
+
const removeHandler = () => {
|
|
2712
|
+
runtime.eventCenter.off('__taroRouterChange', removeHandler);
|
|
2713
|
+
container.remove();
|
|
2714
|
+
};
|
|
2715
|
+
// 路由改变后应该关闭预览框
|
|
2716
|
+
runtime.eventCenter.on('__taroRouterChange', removeHandler);
|
|
2711
2717
|
container.classList.add('preview-image');
|
|
2712
2718
|
container.style.cssText =
|
|
2713
2719
|
'position:fixed;top:0;left:0;z-index:1050;width:100%;height:100%;overflow:hidden;outline:0;background-color:#111;';
|
|
2714
|
-
container.addEventListener('click',
|
|
2715
|
-
container.remove();
|
|
2716
|
-
});
|
|
2720
|
+
container.addEventListener('click', removeHandler);
|
|
2717
2721
|
const swiper = document.createElement('taro-swiper-core');
|
|
2718
2722
|
// @ts-ignore
|
|
2719
2723
|
swiper.full = true;
|
|
@@ -5025,19 +5029,21 @@ function generateRequestUrlWithParams(url = '', params) {
|
|
|
5025
5029
|
}
|
|
5026
5030
|
function _request(options = {}) {
|
|
5027
5031
|
const { success, complete, fail } = options;
|
|
5028
|
-
let url = options.url || '';
|
|
5029
5032
|
const params = {};
|
|
5030
5033
|
const res = {};
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
+
let { cache = 'default', credentials, data, dataType, header = {}, jsonp, method = 'GET', mode, responseType, signal, timeout = 2000, url = '' } = options, opts = __rest(options, ["cache", "credentials", "data", "dataType", "header", "jsonp", "method", "mode", "responseType", "signal", "timeout", "url"]);
|
|
5035
|
+
Object.assign(params, opts);
|
|
5036
|
+
if (jsonp) {
|
|
5034
5037
|
// @ts-ignore
|
|
5035
|
-
params.params =
|
|
5038
|
+
params.params = data;
|
|
5036
5039
|
params.cache = opts.jsonpCache;
|
|
5040
|
+
// @ts-ignore
|
|
5041
|
+
params.timeout = timeout;
|
|
5037
5042
|
if (typeof jsonp === 'string') {
|
|
5038
5043
|
// @ts-ignore
|
|
5039
5044
|
params.name = jsonp;
|
|
5040
5045
|
}
|
|
5046
|
+
// Note: https://github.com/luckyadam/jsonp-retry
|
|
5041
5047
|
return jsonpRetry(url, params)
|
|
5042
5048
|
.then(data => {
|
|
5043
5049
|
res.statusCode = 200;
|
|
@@ -5052,50 +5058,49 @@ function _request(options = {}) {
|
|
|
5052
5058
|
return Promise.reject(err);
|
|
5053
5059
|
});
|
|
5054
5060
|
}
|
|
5055
|
-
params.method =
|
|
5061
|
+
params.method = method;
|
|
5056
5062
|
const methodUpper = params.method.toUpperCase();
|
|
5057
|
-
params.cache =
|
|
5063
|
+
params.cache = cache;
|
|
5058
5064
|
if (methodUpper === 'GET' || methodUpper === 'HEAD') {
|
|
5059
|
-
url = generateRequestUrlWithParams(url,
|
|
5065
|
+
url = generateRequestUrlWithParams(url, data);
|
|
5060
5066
|
}
|
|
5061
|
-
else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(
|
|
5062
|
-
|
|
5063
|
-
const keyOfContentType = Object.keys(options.header).find(item => item.toLowerCase() === 'content-type');
|
|
5067
|
+
else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(data)) >= 0) {
|
|
5068
|
+
const keyOfContentType = Object.keys(header).find(item => item.toLowerCase() === 'content-type');
|
|
5064
5069
|
if (!keyOfContentType) {
|
|
5065
|
-
|
|
5070
|
+
header['Content-Type'] = 'application/json';
|
|
5066
5071
|
}
|
|
5067
|
-
const contentType =
|
|
5072
|
+
const contentType = header[keyOfContentType || 'Content-Type'];
|
|
5068
5073
|
if (contentType.indexOf('application/json') >= 0) {
|
|
5069
|
-
params.body = JSON.stringify(
|
|
5074
|
+
params.body = JSON.stringify(data);
|
|
5070
5075
|
}
|
|
5071
5076
|
else if (contentType.indexOf('application/x-www-form-urlencoded') >= 0) {
|
|
5072
|
-
params.body = serializeParams(
|
|
5077
|
+
params.body = serializeParams(data);
|
|
5073
5078
|
}
|
|
5074
5079
|
else {
|
|
5075
|
-
params.body =
|
|
5080
|
+
params.body = data;
|
|
5076
5081
|
}
|
|
5077
5082
|
}
|
|
5078
5083
|
else {
|
|
5079
|
-
params.body =
|
|
5084
|
+
params.body = data;
|
|
5080
5085
|
}
|
|
5081
|
-
if (
|
|
5082
|
-
params.headers =
|
|
5086
|
+
if (header) {
|
|
5087
|
+
params.headers = header;
|
|
5083
5088
|
}
|
|
5084
|
-
if (
|
|
5085
|
-
params.mode =
|
|
5089
|
+
if (mode) {
|
|
5090
|
+
params.mode = mode;
|
|
5086
5091
|
}
|
|
5087
5092
|
let timeoutTimer = null;
|
|
5088
|
-
if (
|
|
5089
|
-
params.signal =
|
|
5093
|
+
if (signal) {
|
|
5094
|
+
params.signal = signal;
|
|
5090
5095
|
}
|
|
5091
|
-
else if (typeof
|
|
5096
|
+
else if (typeof timeout === 'number') {
|
|
5092
5097
|
const controller = new window.AbortController();
|
|
5093
5098
|
params.signal = controller.signal;
|
|
5094
5099
|
timeoutTimer = setTimeout(function () {
|
|
5095
5100
|
controller.abort();
|
|
5096
|
-
},
|
|
5101
|
+
}, timeout);
|
|
5097
5102
|
}
|
|
5098
|
-
params.credentials =
|
|
5103
|
+
params.credentials = credentials;
|
|
5099
5104
|
return fetch(url, params)
|
|
5100
5105
|
.then(response => {
|
|
5101
5106
|
if (timeoutTimer) {
|
|
@@ -5111,17 +5116,17 @@ function _request(options = {}) {
|
|
|
5111
5116
|
for (const key of response.headers.keys()) {
|
|
5112
5117
|
res.header[key] = response.headers.get(key);
|
|
5113
5118
|
}
|
|
5114
|
-
if (
|
|
5119
|
+
if (responseType === 'arraybuffer') {
|
|
5115
5120
|
return response.arrayBuffer();
|
|
5116
5121
|
}
|
|
5117
5122
|
if (res.statusCode !== 204) {
|
|
5118
|
-
if (
|
|
5123
|
+
if (dataType === 'json' || typeof dataType === 'undefined') {
|
|
5119
5124
|
return response.json().catch(() => {
|
|
5120
5125
|
return null;
|
|
5121
5126
|
});
|
|
5122
5127
|
}
|
|
5123
5128
|
}
|
|
5124
|
-
if (
|
|
5129
|
+
if (responseType === 'text' || dataType === 'text') {
|
|
5125
5130
|
return response.text();
|
|
5126
5131
|
}
|
|
5127
5132
|
return Promise.resolve(null);
|
|
@@ -5431,9 +5436,9 @@ function connectSocket(options) {
|
|
|
5431
5436
|
// protocols must be array
|
|
5432
5437
|
const _protocols = Array.isArray(protocols) ? protocols : null;
|
|
5433
5438
|
// 2 connection at most
|
|
5434
|
-
if (socketTasks.length
|
|
5439
|
+
if (socketTasks.length >= 5) {
|
|
5435
5440
|
return handle.fail({
|
|
5436
|
-
errMsg: '同时最多发起
|
|
5441
|
+
errMsg: '同时最多发起 5 个 socket 请求,更多请参考文档。'
|
|
5437
5442
|
}, { resolve, reject });
|
|
5438
5443
|
}
|
|
5439
5444
|
const task = new SocketTask(url, _protocols);
|