@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/index.esm.js CHANGED
@@ -3,7 +3,7 @@ import { history, navigateBack, navigateTo, reLaunch, redirectTo, getCurrentPage
3
3
  export { getCurrentPages, history, navigateBack, navigateTo, reLaunch, redirectTo, switchTab } from '@tarojs/router';
4
4
  import { isFunction, toKebabCase, PLATFORM_TYPE } from '@tarojs/shared';
5
5
  import { getCurrentPage, getHomePage } from '@tarojs/router/dist/utils';
6
- import { hooks, Current as Current$1 } from '@tarojs/runtime';
6
+ import { hooks, Current as Current$1, eventCenter as eventCenter$1 } from '@tarojs/runtime';
7
7
  import { fromByteArray, toByteArray } from 'base64-js';
8
8
  import { getMobileDetect, setTitle } from '@tarojs/router/dist/utils/navigate';
9
9
  import isNil from 'lodash-es/isNil';
@@ -2686,12 +2686,16 @@ const previewImage = (options) => __awaiter(void 0, void 0, void 0, function* ()
2686
2686
  const { urls = [], current = '', success, fail, complete } = options;
2687
2687
  const handle = new MethodHandler({ name: 'previewImage', success, fail, complete });
2688
2688
  const container = document.createElement('div');
2689
+ const removeHandler = () => {
2690
+ eventCenter$1.off('__taroRouterChange', removeHandler);
2691
+ container.remove();
2692
+ };
2693
+ // 路由改变后应该关闭预览框
2694
+ eventCenter$1.on('__taroRouterChange', removeHandler);
2689
2695
  container.classList.add('preview-image');
2690
2696
  container.style.cssText =
2691
2697
  'position:fixed;top:0;left:0;z-index:1050;width:100%;height:100%;overflow:hidden;outline:0;background-color:#111;';
2692
- container.addEventListener('click', () => {
2693
- container.remove();
2694
- });
2698
+ container.addEventListener('click', removeHandler);
2695
2699
  const swiper = document.createElement('taro-swiper-core');
2696
2700
  // @ts-ignore
2697
2701
  swiper.full = true;
@@ -5003,19 +5007,21 @@ function generateRequestUrlWithParams(url = '', params) {
5003
5007
  }
5004
5008
  function _request(options = {}) {
5005
5009
  const { success, complete, fail } = options;
5006
- let url = options.url || '';
5007
5010
  const params = {};
5008
5011
  const res = {};
5009
- if (options.jsonp) {
5010
- const { jsonp } = options, opts = __rest(options, ["jsonp"]);
5011
- Object.assign(params, opts);
5012
+ 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"]);
5013
+ Object.assign(params, opts);
5014
+ if (jsonp) {
5012
5015
  // @ts-ignore
5013
- params.params = opts.data;
5016
+ params.params = data;
5014
5017
  params.cache = opts.jsonpCache;
5018
+ // @ts-ignore
5019
+ params.timeout = timeout;
5015
5020
  if (typeof jsonp === 'string') {
5016
5021
  // @ts-ignore
5017
5022
  params.name = jsonp;
5018
5023
  }
5024
+ // Note: https://github.com/luckyadam/jsonp-retry
5019
5025
  return jsonpRetry(url, params)
5020
5026
  .then(data => {
5021
5027
  res.statusCode = 200;
@@ -5030,50 +5036,49 @@ function _request(options = {}) {
5030
5036
  return Promise.reject(err);
5031
5037
  });
5032
5038
  }
5033
- params.method = options.method || 'GET';
5039
+ params.method = method;
5034
5040
  const methodUpper = params.method.toUpperCase();
5035
- params.cache = options.cache || 'default';
5041
+ params.cache = cache;
5036
5042
  if (methodUpper === 'GET' || methodUpper === 'HEAD') {
5037
- url = generateRequestUrlWithParams(url, options.data);
5043
+ url = generateRequestUrlWithParams(url, data);
5038
5044
  }
5039
- else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(options.data)) >= 0) {
5040
- options.header = options.header || {};
5041
- const keyOfContentType = Object.keys(options.header).find(item => item.toLowerCase() === 'content-type');
5045
+ else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(data)) >= 0) {
5046
+ const keyOfContentType = Object.keys(header).find(item => item.toLowerCase() === 'content-type');
5042
5047
  if (!keyOfContentType) {
5043
- options.header['Content-Type'] = 'application/json';
5048
+ header['Content-Type'] = 'application/json';
5044
5049
  }
5045
- const contentType = options.header[keyOfContentType || 'Content-Type'];
5050
+ const contentType = header[keyOfContentType || 'Content-Type'];
5046
5051
  if (contentType.indexOf('application/json') >= 0) {
5047
- params.body = JSON.stringify(options.data);
5052
+ params.body = JSON.stringify(data);
5048
5053
  }
5049
5054
  else if (contentType.indexOf('application/x-www-form-urlencoded') >= 0) {
5050
- params.body = serializeParams(options.data);
5055
+ params.body = serializeParams(data);
5051
5056
  }
5052
5057
  else {
5053
- params.body = options.data;
5058
+ params.body = data;
5054
5059
  }
5055
5060
  }
5056
5061
  else {
5057
- params.body = options.data;
5062
+ params.body = data;
5058
5063
  }
5059
- if (options.header) {
5060
- params.headers = options.header;
5064
+ if (header) {
5065
+ params.headers = header;
5061
5066
  }
5062
- if (options.mode) {
5063
- params.mode = options.mode;
5067
+ if (mode) {
5068
+ params.mode = mode;
5064
5069
  }
5065
5070
  let timeoutTimer = null;
5066
- if (options.signal) {
5067
- params.signal = options.signal;
5071
+ if (signal) {
5072
+ params.signal = signal;
5068
5073
  }
5069
- else if (typeof options.timeout === 'number') {
5074
+ else if (typeof timeout === 'number') {
5070
5075
  const controller = new window.AbortController();
5071
5076
  params.signal = controller.signal;
5072
5077
  timeoutTimer = setTimeout(function () {
5073
5078
  controller.abort();
5074
- }, options.timeout);
5079
+ }, timeout);
5075
5080
  }
5076
- params.credentials = options.credentials;
5081
+ params.credentials = credentials;
5077
5082
  return fetch(url, params)
5078
5083
  .then(response => {
5079
5084
  if (timeoutTimer) {
@@ -5089,17 +5094,17 @@ function _request(options = {}) {
5089
5094
  for (const key of response.headers.keys()) {
5090
5095
  res.header[key] = response.headers.get(key);
5091
5096
  }
5092
- if (options.responseType === 'arraybuffer') {
5097
+ if (responseType === 'arraybuffer') {
5093
5098
  return response.arrayBuffer();
5094
5099
  }
5095
5100
  if (res.statusCode !== 204) {
5096
- if (options.dataType === 'json' || typeof options.dataType === 'undefined') {
5101
+ if (dataType === 'json' || typeof dataType === 'undefined') {
5097
5102
  return response.json().catch(() => {
5098
5103
  return null;
5099
5104
  });
5100
5105
  }
5101
5106
  }
5102
- if (options.responseType === 'text' || options.dataType === 'text') {
5107
+ if (responseType === 'text' || dataType === 'text') {
5103
5108
  return response.text();
5104
5109
  }
5105
5110
  return Promise.resolve(null);
@@ -5409,9 +5414,9 @@ function connectSocket(options) {
5409
5414
  // protocols must be array
5410
5415
  const _protocols = Array.isArray(protocols) ? protocols : null;
5411
5416
  // 2 connection at most
5412
- if (socketTasks.length > 1) {
5417
+ if (socketTasks.length >= 5) {
5413
5418
  return handle.fail({
5414
- errMsg: '同时最多发起 2 个 socket 请求,更多请参考文档。'
5419
+ errMsg: '同时最多发起 5 个 socket 请求,更多请参考文档。'
5415
5420
  }, { resolve, reject });
5416
5421
  }
5417
5422
  const task = new SocketTask(url, _protocols);