@tarojs/taro-h5 3.7.0-alpha.7 → 3.7.0-alpha.8

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';
@@ -2396,7 +2396,6 @@ class InnerAudioContext {
2396
2396
  this.destroy = () => {
2397
2397
  this.stop();
2398
2398
  if (this.Instance) {
2399
- document.body.removeChild(this.Instance);
2400
2399
  this.Instance = undefined;
2401
2400
  }
2402
2401
  };
@@ -2423,6 +2422,7 @@ class InnerAudioContext {
2423
2422
  this.Instance = new Audio();
2424
2423
  this.errorStack = new CallbackManager();
2425
2424
  this.stopStack = new CallbackManager();
2425
+ this.Instance.onerror = this.errorStack.trigger;
2426
2426
  Taro.eventCenter.on('__taroRouterChange', () => { this.stop(); });
2427
2427
  this.onPlay(() => {
2428
2428
  if (this.__isFirstPlay) {
@@ -2515,6 +2515,7 @@ class BackgroundAudioManager {
2515
2515
  this.Instance = new Audio();
2516
2516
  this.errorStack = new CallbackManager();
2517
2517
  this.stopStack = new CallbackManager();
2518
+ this.Instance.onerror = this.errorStack.trigger;
2518
2519
  this.Instance.autoplay = true;
2519
2520
  this.onPlay(() => {
2520
2521
  if (this.currentTime !== this.startTime) {
@@ -2685,12 +2686,16 @@ const previewImage = (options) => __awaiter(void 0, void 0, void 0, function* ()
2685
2686
  const { urls = [], current = '', success, fail, complete } = options;
2686
2687
  const handle = new MethodHandler({ name: 'previewImage', success, fail, complete });
2687
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);
2688
2695
  container.classList.add('preview-image');
2689
2696
  container.style.cssText =
2690
2697
  'position:fixed;top:0;left:0;z-index:1050;width:100%;height:100%;overflow:hidden;outline:0;background-color:#111;';
2691
- container.addEventListener('click', () => {
2692
- container.remove();
2693
- });
2698
+ container.addEventListener('click', removeHandler);
2694
2699
  const swiper = document.createElement('taro-swiper-core');
2695
2700
  // @ts-ignore
2696
2701
  swiper.full = true;
@@ -5002,19 +5007,21 @@ function generateRequestUrlWithParams(url = '', params) {
5002
5007
  }
5003
5008
  function _request(options = {}) {
5004
5009
  const { success, complete, fail } = options;
5005
- let url = options.url || '';
5006
5010
  const params = {};
5007
5011
  const res = {};
5008
- if (options.jsonp) {
5009
- const { jsonp } = options, opts = __rest(options, ["jsonp"]);
5010
- 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) {
5011
5015
  // @ts-ignore
5012
- params.params = opts.data;
5016
+ params.params = data;
5013
5017
  params.cache = opts.jsonpCache;
5018
+ // @ts-ignore
5019
+ params.timeout = timeout;
5014
5020
  if (typeof jsonp === 'string') {
5015
5021
  // @ts-ignore
5016
5022
  params.name = jsonp;
5017
5023
  }
5024
+ // Note: https://github.com/luckyadam/jsonp-retry
5018
5025
  return jsonpRetry(url, params)
5019
5026
  .then(data => {
5020
5027
  res.statusCode = 200;
@@ -5029,50 +5036,49 @@ function _request(options = {}) {
5029
5036
  return Promise.reject(err);
5030
5037
  });
5031
5038
  }
5032
- params.method = options.method || 'GET';
5039
+ params.method = method;
5033
5040
  const methodUpper = params.method.toUpperCase();
5034
- params.cache = options.cache || 'default';
5041
+ params.cache = cache;
5035
5042
  if (methodUpper === 'GET' || methodUpper === 'HEAD') {
5036
- url = generateRequestUrlWithParams(url, options.data);
5043
+ url = generateRequestUrlWithParams(url, data);
5037
5044
  }
5038
- else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(options.data)) >= 0) {
5039
- options.header = options.header || {};
5040
- 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');
5041
5047
  if (!keyOfContentType) {
5042
- options.header['Content-Type'] = 'application/json';
5048
+ header['Content-Type'] = 'application/json';
5043
5049
  }
5044
- const contentType = options.header[keyOfContentType || 'Content-Type'];
5050
+ const contentType = header[keyOfContentType || 'Content-Type'];
5045
5051
  if (contentType.indexOf('application/json') >= 0) {
5046
- params.body = JSON.stringify(options.data);
5052
+ params.body = JSON.stringify(data);
5047
5053
  }
5048
5054
  else if (contentType.indexOf('application/x-www-form-urlencoded') >= 0) {
5049
- params.body = serializeParams(options.data);
5055
+ params.body = serializeParams(data);
5050
5056
  }
5051
5057
  else {
5052
- params.body = options.data;
5058
+ params.body = data;
5053
5059
  }
5054
5060
  }
5055
5061
  else {
5056
- params.body = options.data;
5062
+ params.body = data;
5057
5063
  }
5058
- if (options.header) {
5059
- params.headers = options.header;
5064
+ if (header) {
5065
+ params.headers = header;
5060
5066
  }
5061
- if (options.mode) {
5062
- params.mode = options.mode;
5067
+ if (mode) {
5068
+ params.mode = mode;
5063
5069
  }
5064
5070
  let timeoutTimer = null;
5065
- if (options.signal) {
5066
- params.signal = options.signal;
5071
+ if (signal) {
5072
+ params.signal = signal;
5067
5073
  }
5068
- else if (typeof options.timeout === 'number') {
5074
+ else if (typeof timeout === 'number') {
5069
5075
  const controller = new window.AbortController();
5070
5076
  params.signal = controller.signal;
5071
5077
  timeoutTimer = setTimeout(function () {
5072
5078
  controller.abort();
5073
- }, options.timeout);
5079
+ }, timeout);
5074
5080
  }
5075
- params.credentials = options.credentials;
5081
+ params.credentials = credentials;
5076
5082
  return fetch(url, params)
5077
5083
  .then(response => {
5078
5084
  if (timeoutTimer) {
@@ -5088,17 +5094,17 @@ function _request(options = {}) {
5088
5094
  for (const key of response.headers.keys()) {
5089
5095
  res.header[key] = response.headers.get(key);
5090
5096
  }
5091
- if (options.responseType === 'arraybuffer') {
5097
+ if (responseType === 'arraybuffer') {
5092
5098
  return response.arrayBuffer();
5093
5099
  }
5094
5100
  if (res.statusCode !== 204) {
5095
- if (options.dataType === 'json' || typeof options.dataType === 'undefined') {
5101
+ if (dataType === 'json' || typeof dataType === 'undefined') {
5096
5102
  return response.json().catch(() => {
5097
5103
  return null;
5098
5104
  });
5099
5105
  }
5100
5106
  }
5101
- if (options.responseType === 'text' || options.dataType === 'text') {
5107
+ if (responseType === 'text' || dataType === 'text') {
5102
5108
  return response.text();
5103
5109
  }
5104
5110
  return Promise.resolve(null);
@@ -5408,9 +5414,9 @@ function connectSocket(options) {
5408
5414
  // protocols must be array
5409
5415
  const _protocols = Array.isArray(protocols) ? protocols : null;
5410
5416
  // 2 connection at most
5411
- if (socketTasks.length > 1) {
5417
+ if (socketTasks.length >= 5) {
5412
5418
  return handle.fail({
5413
- errMsg: '同时最多发起 2 个 socket 请求,更多请参考文档。'
5419
+ errMsg: '同时最多发起 5 个 socket 请求,更多请参考文档。'
5414
5420
  }, { resolve, reject });
5415
5421
  }
5416
5422
  const task = new SocketTask(url, _protocols);