@tarojs/taro-h5 3.5.0-alpha.9 → 3.5.0-beta.0

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 (74) hide show
  1. package/dist/api/base/index.js +4 -4
  2. package/dist/api/canvas/canvasGetImageData.js +1 -1
  3. package/dist/api/canvas/canvasPutImageData.js +1 -1
  4. package/dist/api/device/clipboard.js +1 -1
  5. package/dist/api/device/compass.js +1 -1
  6. package/dist/api/device/network.js +1 -1
  7. package/dist/api/device/phone.js +1 -1
  8. package/dist/api/index.js +2 -2
  9. package/dist/api/location/chooseLocation.js +1 -1
  10. package/dist/api/media/image/chooseImage.js +1 -1
  11. package/dist/api/media/image/index.js +1 -1
  12. package/dist/api/media/video/index.js +1 -1
  13. package/dist/api/network/download.js +1 -0
  14. package/dist/api/network/request/index.js +1 -1
  15. package/dist/api/network/upload.js +1 -0
  16. package/dist/api/network/utils.js +1 -0
  17. package/dist/api/network/websocket/index.js +2 -2
  18. package/dist/api/route/index.js +1 -1
  19. package/dist/api/storage/index.js +1 -1
  20. package/dist/api/taro.js +2 -2
  21. package/dist/api/ui/index.js +1 -1
  22. package/dist/api/ui/interaction/index.js +3 -3
  23. package/dist/api/ui/navigation-bar/index.js +1 -1
  24. package/dist/api/ui/scroll/index.js +1 -1
  25. package/dist/api/ui/tab-bar.js +1 -1
  26. package/dist/api/wxml/selectorQuery.js +1 -1
  27. package/dist/index.cjs.js +1092 -1089
  28. package/dist/index.cjs.js.map +1 -1
  29. package/dist/index.esm.js +1092 -1089
  30. package/dist/index.esm.js.map +1 -1
  31. package/dist/utils/index.js +1 -1
  32. package/package.json +5 -5
  33. package/src/api/base/index.ts +4 -4
  34. package/src/api/canvas/canvasGetImageData.ts +2 -1
  35. package/src/api/canvas/canvasPutImageData.ts +2 -1
  36. package/src/api/canvas/canvasToTempFilePath.ts +1 -0
  37. package/src/api/canvas/createCanvasContext.ts +1 -0
  38. package/src/api/cloud/index.ts +1 -0
  39. package/src/api/device/accelerometer.ts +1 -0
  40. package/src/api/device/battery.ts +1 -0
  41. package/src/api/device/clipboard.ts +2 -1
  42. package/src/api/device/compass.ts +1 -1
  43. package/src/api/device/network.ts +1 -1
  44. package/src/api/device/phone.ts +2 -1
  45. package/src/api/device/vibrate.ts +1 -0
  46. package/src/api/index.ts +2 -3
  47. package/src/api/location/chooseLocation.ts +2 -1
  48. package/src/api/location/getLocation.ts +1 -0
  49. package/src/api/media/EditorContext.ts +1 -0
  50. package/src/api/media/audio/InnerAudioContext.ts +1 -0
  51. package/src/api/media/audio/index.ts +1 -0
  52. package/src/api/media/background-audio/BackgroundAudioManager.ts +1 -0
  53. package/src/api/media/image/chooseImage.ts +1 -1
  54. package/src/api/media/image/index.ts +1 -1
  55. package/src/api/media/video/index.ts +1 -1
  56. package/src/api/network/download.ts +2 -0
  57. package/src/api/network/request/index.ts +2 -1
  58. package/src/api/network/upload.ts +2 -0
  59. package/src/api/network/utils.ts +1 -0
  60. package/src/api/network/websocket/index.ts +2 -2
  61. package/src/api/route/index.ts +4 -4
  62. package/src/api/storage/index.ts +2 -1
  63. package/src/api/taro.ts +10 -10
  64. package/src/api/ui/fonts.ts +1 -0
  65. package/src/api/ui/index.ts +1 -1
  66. package/src/api/ui/interaction/index.ts +4 -3
  67. package/src/api/ui/navigation-bar/index.ts +1 -1
  68. package/src/api/ui/pull-down-refresh.ts +1 -0
  69. package/src/api/ui/scroll/index.ts +1 -1
  70. package/src/api/ui/tab-bar.ts +2 -1
  71. package/src/api/ui/window.ts +1 -0
  72. package/src/api/wxml/index.ts +1 -0
  73. package/src/api/wxml/selectorQuery.ts +2 -1
  74. package/src/utils/index.ts +1 -1
package/dist/index.esm.js CHANGED
@@ -231,6 +231,20 @@ const isVKSupport = temporarilyNotSupport('isVKSupport');
231
231
  // 视觉算法
232
232
  const createVKSession = temporarilyNotSupport('createVKSession');
233
233
 
234
+ // AliPay
235
+ const getOpenUserInfo = temporarilyNotSupport('getOpenUserInfo');
236
+
237
+ // 加密
238
+ const getUserCryptoManager = temporarilyNotSupport('getUserCryptoManager');
239
+
240
+ const setEnableDebug = temporarilyNotSupport('setEnableDebug');
241
+ const getRealtimeLogManager = temporarilyNotSupport('getRealtimeLogManager');
242
+ const getLogManager = temporarilyNotSupport('getLogManager');
243
+
244
+ // 性能
245
+ const reportPerformance = temporarilyNotSupport('reportPerformance');
246
+ const getPerformance = temporarilyNotSupport('getPerformance');
247
+
234
248
  /*! *****************************************************************************
235
249
  Copyright (c) Microsoft Corporation.
236
250
 
@@ -736,10 +750,6 @@ const getSystemInfo = (options = {}) => __awaiter(void 0, void 0, void 0, functi
736
750
  const updateWeChatApp = temporarilyNotSupport('updateWeChatApp');
737
751
  const getUpdateManager = temporarilyNotSupport('getUpdateManager');
738
752
 
739
- // 生命周期
740
- const getLaunchOptionsSync = temporarilyNotSupport('getLaunchOptionsSync');
741
- const getEnterOptionsSync = temporarilyNotSupport('getEnterOptionsSync');
742
-
743
753
  // 应用级事件
744
754
  const onUnhandledRejection = temporarilyNotSupport('onUnhandledRejection');
745
755
  const onThemeChange = temporarilyNotSupport('onThemeChange');
@@ -758,16 +768,9 @@ const offAudioInterruptionBegin = temporarilyNotSupport('offAudioInterruptionBeg
758
768
  const offAppShow = temporarilyNotSupport('offAppShow');
759
769
  const offAppHide = temporarilyNotSupport('offAppHide');
760
770
 
761
- const setEnableDebug = temporarilyNotSupport('setEnableDebug');
762
- const getRealtimeLogManager = temporarilyNotSupport('getRealtimeLogManager');
763
- const getLogManager = temporarilyNotSupport('getLogManager');
764
-
765
- // 性能
766
- const reportPerformance = temporarilyNotSupport('reportPerformance');
767
- const getPerformance = temporarilyNotSupport('getPerformance');
768
-
769
- // 加密
770
- const getUserCryptoManager = temporarilyNotSupport('getUserCryptoManager');
771
+ // 生命周期
772
+ const getLaunchOptionsSync = temporarilyNotSupport('getLaunchOptionsSync');
773
+ const getEnterOptionsSync = temporarilyNotSupport('getEnterOptionsSync');
771
774
 
772
775
  // TODO env 环境变量
773
776
  const canIUse = temporarilyNotSupport('canIUse');
@@ -2221,6 +2224,51 @@ const getBackgroundAudioManager = () => new BackgroundAudioManager();
2221
2224
  // 相机
2222
2225
  const createCameraContext = temporarilyNotSupport('createCameraContext');
2223
2226
 
2227
+ /**
2228
+ * 获取图片信息。网络图片需先配置download域名才能生效。
2229
+ */
2230
+ const getImageInfo = (options) => {
2231
+ // options must be an Object
2232
+ const isObject = shouldBeObject(options);
2233
+ if (!isObject.flag) {
2234
+ const res = { errMsg: `getImageInfo:fail ${isObject.msg}` };
2235
+ console.error(res.errMsg);
2236
+ return Promise.reject(res);
2237
+ }
2238
+ const getBase64Image = (image) => {
2239
+ try {
2240
+ const canvas = document.createElement('canvas');
2241
+ canvas.width = image.width;
2242
+ canvas.height = image.height;
2243
+ const ctx = canvas.getContext('2d');
2244
+ ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(image, 0, 0, image.width, image.height);
2245
+ return canvas.toDataURL('image/png');
2246
+ }
2247
+ catch (e) {
2248
+ console.error('getImageInfo:get base64 fail', e);
2249
+ }
2250
+ };
2251
+ const { src, success, fail, complete } = options;
2252
+ const handle = new MethodHandler({ name: 'getImageInfo', success, fail, complete });
2253
+ return new Promise((resolve, reject) => {
2254
+ const image = new Image();
2255
+ image.crossOrigin = '';
2256
+ image.onload = () => {
2257
+ handle.success({
2258
+ width: image.naturalWidth,
2259
+ height: image.naturalHeight,
2260
+ path: getBase64Image(image) || src
2261
+ }, resolve);
2262
+ };
2263
+ image.onerror = (e) => {
2264
+ handle.fail({
2265
+ errMsg: e.message
2266
+ }, reject);
2267
+ };
2268
+ image.src = src;
2269
+ });
2270
+ };
2271
+
2224
2272
  /**
2225
2273
  * previewImage api基于开源的React组件[react-wx-images-viewer](https://github.com/react-ld/react-wx-images-viewer)开发,感谢!
2226
2274
  */
@@ -2287,51 +2335,6 @@ const previewImage = (options) => __awaiter(void 0, void 0, void 0, function* ()
2287
2335
  return handle.success();
2288
2336
  });
2289
2337
 
2290
- /**
2291
- * 获取图片信息。网络图片需先配置download域名才能生效。
2292
- */
2293
- const getImageInfo = (options) => {
2294
- // options must be an Object
2295
- const isObject = shouldBeObject(options);
2296
- if (!isObject.flag) {
2297
- const res = { errMsg: `getImageInfo:fail ${isObject.msg}` };
2298
- console.error(res.errMsg);
2299
- return Promise.reject(res);
2300
- }
2301
- const getBase64Image = (image) => {
2302
- try {
2303
- const canvas = document.createElement('canvas');
2304
- canvas.width = image.width;
2305
- canvas.height = image.height;
2306
- const ctx = canvas.getContext('2d');
2307
- ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(image, 0, 0, image.width, image.height);
2308
- return canvas.toDataURL('image/png');
2309
- }
2310
- catch (e) {
2311
- console.error('getImageInfo:get base64 fail', e);
2312
- }
2313
- };
2314
- const { src, success, fail, complete } = options;
2315
- const handle = new MethodHandler({ name: 'getImageInfo', success, fail, complete });
2316
- return new Promise((resolve, reject) => {
2317
- const image = new Image();
2318
- image.crossOrigin = '';
2319
- image.onload = () => {
2320
- handle.success({
2321
- width: image.naturalWidth,
2322
- height: image.naturalHeight,
2323
- path: getBase64Image(image) || src
2324
- }, resolve);
2325
- };
2326
- image.onerror = (e) => {
2327
- handle.fail({
2328
- errMsg: e.message
2329
- }, reject);
2330
- };
2331
- image.src = src;
2332
- });
2333
- };
2334
-
2335
2338
  /**
2336
2339
  * 从本地相册选择图片或使用相机拍照。
2337
2340
  */
@@ -2591,6 +2594,7 @@ const convertObjectUrlToBlob = url => {
2591
2594
  const xhr = new XMLHttpRequest();
2592
2595
  xhr.open('GET', url, true);
2593
2596
  xhr.responseType = 'blob';
2597
+ xhr.withCredentials = true;
2594
2598
  xhr.onload = function () {
2595
2599
  if (this.status === 200) {
2596
2600
  resolve(this.response);
@@ -2613,6 +2617,7 @@ const createDownloadTask = ({ url, header, success, error }) => {
2613
2617
  progressUpdate: new CallbackManager()
2614
2618
  };
2615
2619
  xhr.open('GET', url, true);
2620
+ xhr.withCredentials = true;
2616
2621
  xhr.responseType = 'blob';
2617
2622
  setHeader(xhr, header);
2618
2623
  xhr.onprogress = e => {
@@ -2882,6 +2887,7 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
2882
2887
  progressUpdate: new CallbackManager()
2883
2888
  };
2884
2889
  xhr.open('POST', url);
2890
+ xhr.withCredentials = true;
2885
2891
  setHeader(xhr, header);
2886
2892
  for (formKey in formData) {
2887
2893
  form.append(formKey, formData[formKey]);
@@ -3240,6 +3246,32 @@ const hideShareMenu = temporarilyNotSupport('hideShareMenu');
3240
3246
  const getShareInfo = temporarilyNotSupport('getShareInfo');
3241
3247
  const authPrivateMessage = temporarilyNotSupport('authPrivateMessage');
3242
3248
 
3249
+ const setPageInfo = temporarilyNotSupport('setPageInfo');
3250
+ // 百度小程序 AI 相关
3251
+ const ocrIdCard = temporarilyNotSupport('ocrIdCard');
3252
+ const ocrBankCard = temporarilyNotSupport('ocrBankCard');
3253
+ const ocrDrivingLicense = temporarilyNotSupport('ocrDrivingLicense');
3254
+ const ocrVehicleLicense = temporarilyNotSupport('ocrVehicleLicense');
3255
+ const textReview = temporarilyNotSupport('textReview');
3256
+ const textToAudio = temporarilyNotSupport('textToAudio');
3257
+ const imageAudit = temporarilyNotSupport('imageAudit');
3258
+ const advancedGeneralIdentify = temporarilyNotSupport('advancedGeneralIdentify');
3259
+ const objectDetectIdentify = temporarilyNotSupport('objectDetectIdentify');
3260
+ const carClassify = temporarilyNotSupport('carClassify');
3261
+ const dishClassify = temporarilyNotSupport('dishClassify');
3262
+ const logoClassify = temporarilyNotSupport('logoClassify');
3263
+ const animalClassify = temporarilyNotSupport('animalClassify');
3264
+ const plantClassify = temporarilyNotSupport('plantClassify');
3265
+ // 用户信息
3266
+ const getSwanId = temporarilyNotSupport('getSwanId');
3267
+ // 百度收银台支付
3268
+ const requestPolymerPayment = temporarilyNotSupport('requestPolymerPayment');
3269
+ // 打开小程序
3270
+ const navigateToSmartGameProgram = temporarilyNotSupport('navigateToSmartGameProgram');
3271
+ const navigateToSmartProgram = temporarilyNotSupport('navigateToSmartProgram');
3272
+ const navigateBackSmartProgram = temporarilyNotSupport('navigateBackSmartProgram');
3273
+ const preloadSubPackage = temporarilyNotSupport('preloadSubPackage');
3274
+
3243
3275
  /**
3244
3276
  * H5 下的 styleSheet 操作
3245
3277
  * @author leeenx
@@ -3587,468 +3619,370 @@ const loadFontFace = (options) => __awaiter(void 0, void 0, void 0, function* ()
3587
3619
  }
3588
3620
  });
3589
3621
 
3590
- // 菜单
3591
- const getMenuButtonBoundingClientRect = temporarilyNotSupport('getMenuButtonBoundingClientRect');
3592
-
3593
- // 导航栏
3594
- const showNavigationBarLoading = temporarilyNotSupport('showNavigationBarLoading');
3595
- function setNavigationBarTitle(options) {
3596
- // options must be an Object
3597
- const isObject = shouldBeObject(options);
3598
- if (!isObject.flag) {
3599
- const res = { errMsg: `setNavigationBarTitle:fail ${isObject.msg}` };
3600
- console.error(res.errMsg);
3601
- return Promise.reject(res);
3602
- }
3603
- const { title, success, fail, complete } = options;
3604
- const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete });
3605
- if (!title || typeof title !== 'string') {
3606
- return handle.fail({
3607
- errMsg: getParameterError({
3608
- para: 'title',
3609
- correct: 'String',
3610
- wrong: title
3611
- })
3612
- });
3613
- }
3614
- if (document.title !== title) {
3615
- document.title = title;
3622
+ const noop = function () { };
3623
+ class ActionSheet {
3624
+ constructor() {
3625
+ this.options = {
3626
+ itemList: [],
3627
+ itemColor: '#000000',
3628
+ success: noop,
3629
+ fail: noop,
3630
+ complete: noop
3631
+ };
3632
+ this.style = {
3633
+ maskStyle: {
3634
+ position: 'fixed',
3635
+ 'z-index': '1000',
3636
+ top: '0',
3637
+ right: '0',
3638
+ left: '0',
3639
+ bottom: '0',
3640
+ background: 'rgba(0,0,0,0.6)'
3641
+ },
3642
+ actionSheetStyle: {
3643
+ 'z-index': '4999',
3644
+ position: 'fixed',
3645
+ left: '0',
3646
+ bottom: '0',
3647
+ '-webkit-transform': 'translate(0, 100%)',
3648
+ transform: 'translate(0, 100%)',
3649
+ width: '100%',
3650
+ 'line-height': '1.6',
3651
+ background: '#EFEFF4',
3652
+ '-webkit-transition': '-webkit-transform .3s',
3653
+ transition: 'transform .3s'
3654
+ },
3655
+ menuStyle: {
3656
+ 'background-color': '#FCFCFD'
3657
+ },
3658
+ cellStyle: {
3659
+ position: 'relative',
3660
+ padding: '10px 0',
3661
+ 'text-align': 'center',
3662
+ 'font-size': '18px'
3663
+ },
3664
+ cancelStyle: {
3665
+ 'margin-top': '6px',
3666
+ padding: '10px 0',
3667
+ 'text-align': 'center',
3668
+ 'font-size': '18px',
3669
+ color: '#000000',
3670
+ 'background-color': '#FCFCFD'
3671
+ }
3672
+ };
3673
+ this.lastConfig = {};
3616
3674
  }
3617
- return handle.success();
3618
- }
3619
- /**
3620
- * 设置页面导航条颜色
3621
- */
3622
- const setNavigationBarColor = (options) => {
3623
- const { backgroundColor, success, fail, complete } = options;
3624
- const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete });
3625
- const meta = document.createElement('meta');
3626
- meta.setAttribute('name', 'theme-color');
3627
- meta.setAttribute('content', backgroundColor);
3628
- document.head.appendChild(meta);
3629
- return handle.success();
3630
- };
3631
- const hideNavigationBarLoading = temporarilyNotSupport('hideNavigationBarLoading');
3632
- const hideHomeButton = temporarilyNotSupport('hideHomeButton');
3633
-
3634
- /**
3635
- * 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
3636
- */
3637
- const startPullDownRefresh = function ({ success, fail, complete } = {}) {
3638
- const handle = new MethodHandler({ name: 'startPullDownRefresh', success, fail, complete });
3639
- return new Promise((resolve, reject) => {
3640
- Taro.eventCenter.trigger('__taroStartPullDownRefresh', {
3641
- successHandler: (res = {}) => handle.success(res, resolve),
3642
- errorHandler: (res = {}) => handle.fail(res, reject)
3643
- });
3644
- });
3645
- };
3646
- /**
3647
- * 停止当前页面下拉刷新。
3648
- */
3649
- const stopPullDownRefresh = function ({ success, fail, complete } = {}) {
3650
- const handle = new MethodHandler({ name: 'stopPullDownRefresh', success, fail, complete });
3651
- return new Promise((resolve, reject) => {
3652
- Taro.eventCenter.trigger('__taroStopPullDownRefresh', {
3653
- successHandler: (res = {}) => handle.success(res, resolve),
3654
- errorHandler: (res = {}) => handle.fail(res, reject)
3675
+ create(options = {}) {
3676
+ return new Promise((resolve) => {
3677
+ // style
3678
+ const { maskStyle, actionSheetStyle, menuStyle, cellStyle, cancelStyle } = this.style;
3679
+ // configuration
3680
+ const config = Object.assign(Object.assign({}, this.options), options);
3681
+ this.lastConfig = config;
3682
+ // wrapper
3683
+ this.el = document.createElement('div');
3684
+ this.el.className = 'taro__actionSheet';
3685
+ this.el.style.opacity = '0';
3686
+ this.el.style.transition = 'opacity 0.2s linear';
3687
+ // mask
3688
+ const mask = document.createElement('div');
3689
+ mask.setAttribute('style', inlineStyle(maskStyle));
3690
+ // actionSheet
3691
+ this.actionSheet = document.createElement('div');
3692
+ this.actionSheet.setAttribute('style', inlineStyle(actionSheetStyle));
3693
+ // menu
3694
+ this.menu = document.createElement('div');
3695
+ this.menu.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, menuStyle), { color: config.itemColor })));
3696
+ // cells
3697
+ this.cells = config.itemList.map((item, index) => {
3698
+ const cell = document.createElement('div');
3699
+ cell.className = 'taro-actionsheet__cell';
3700
+ cell.setAttribute('style', inlineStyle(cellStyle));
3701
+ cell.textContent = item;
3702
+ cell.dataset.tapIndex = `${index}`;
3703
+ cell.onclick = e => {
3704
+ this.hide();
3705
+ const target = e.currentTarget;
3706
+ const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
3707
+ resolve(index);
3708
+ };
3709
+ return cell;
3710
+ });
3711
+ // cancel
3712
+ this.cancel = document.createElement('div');
3713
+ this.cancel.setAttribute('style', inlineStyle(cancelStyle));
3714
+ this.cancel.textContent = '取消';
3715
+ // result
3716
+ this.cells.forEach(item => this.menu.appendChild(item));
3717
+ this.actionSheet.appendChild(this.menu);
3718
+ this.actionSheet.appendChild(this.cancel);
3719
+ this.el.appendChild(mask);
3720
+ this.el.appendChild(this.actionSheet);
3721
+ // callbacks
3722
+ const cb = () => {
3723
+ this.hide();
3724
+ resolve('cancel');
3725
+ };
3726
+ mask.onclick = cb;
3727
+ this.cancel.onclick = cb;
3728
+ // show immediately
3729
+ document.body.appendChild(this.el);
3730
+ setTimeout(() => {
3731
+ this.el.style.opacity = '1';
3732
+ setTransform(this.actionSheet, 'translate(0, 0)');
3733
+ }, 0);
3655
3734
  });
3656
- });
3657
- };
3658
-
3659
- let timer;
3660
- const FRAME_DURATION = 17;
3661
- /**
3662
- * 将页面滚动到目标位置
3663
- */
3664
- const pageScrollTo = ({ scrollTop, selector = '', duration = 300, success, fail, complete }) => {
3665
- let scrollFunc;
3666
- const handle = new MethodHandler({ name: 'pageScrollTo', success, fail, complete });
3667
- return new Promise((resolve, reject) => {
3668
- var _a, _b;
3669
- try {
3670
- if (scrollTop === undefined && !selector) {
3671
- return handle.fail({
3672
- errMsg: 'scrollTop" 或 "selector" 需要其之一'
3673
- }, reject);
3674
- }
3675
- const id = (_b = (_a = Current$1.page) === null || _a === void 0 ? void 0 : _a.path) === null || _b === void 0 ? void 0 : _b.replace(/([^a-z0-9\u00a0-\uffff_-])/ig, '\\$1');
3676
- const el = (id
3677
- ? document.querySelector(`.taro_page#${id}`)
3678
- : document.querySelector('.taro_page') ||
3679
- document.querySelector('.taro_router'));
3680
- if (!scrollFunc) {
3681
- if (!el) {
3682
- scrollFunc = pos => {
3683
- if (pos === undefined) {
3684
- return window.pageYOffset;
3685
- }
3686
- else {
3687
- window.scrollTo(0, pos);
3688
- }
3689
- };
3735
+ }
3736
+ show(options = {}) {
3737
+ return new Promise((resolve) => {
3738
+ const config = Object.assign(Object.assign({}, this.options), options);
3739
+ this.lastConfig = config;
3740
+ if (this.hideOpacityTimer)
3741
+ clearTimeout(this.hideOpacityTimer);
3742
+ if (this.hideDisplayTimer)
3743
+ clearTimeout(this.hideDisplayTimer);
3744
+ // itemColor
3745
+ if (config.itemColor)
3746
+ this.menu.style.color = config.itemColor;
3747
+ // cells
3748
+ const { cellStyle } = this.style;
3749
+ config.itemList.forEach((item, index) => {
3750
+ let cell;
3751
+ if (this.cells[index]) {
3752
+ // assign new content
3753
+ cell = this.cells[index];
3690
3754
  }
3691
3755
  else {
3692
- scrollFunc = pos => {
3693
- if (pos === undefined) {
3694
- return el.scrollTop;
3695
- }
3696
- else {
3697
- el.scrollTop = pos;
3698
- }
3699
- };
3700
- }
3701
- }
3702
- if (scrollTop && selector) {
3703
- console.warn('"scrollTop" 或 "selector" 建议只设一个值,全部设置会忽略selector');
3704
- }
3705
- const from = scrollFunc();
3706
- let to;
3707
- if (typeof scrollTop === 'number') {
3708
- to = scrollTop;
3709
- }
3710
- else {
3711
- const el = document.querySelector(selector);
3712
- to = (el === null || el === void 0 ? void 0 : el.offsetTop) || 0;
3713
- }
3714
- const delta = to - from;
3715
- const frameCnt = duration / FRAME_DURATION;
3716
- const easeFunc = getTimingFunc(easeInOut, frameCnt);
3717
- const scroll = (frame = 0) => {
3718
- const dest = from + delta * easeFunc(frame);
3719
- scrollFunc(dest);
3720
- if (frame < frameCnt) {
3721
- timer && clearTimeout(timer);
3722
- timer = setTimeout(() => {
3723
- scroll(frame + 1);
3724
- }, FRAME_DURATION);
3756
+ // create new cell
3757
+ cell = document.createElement('div');
3758
+ cell.className = 'taro-actionsheet__cell';
3759
+ cell.setAttribute('style', inlineStyle(cellStyle));
3760
+ cell.dataset.tapIndex = `${index}`;
3761
+ this.cells.push(cell);
3762
+ this.menu.appendChild(cell);
3725
3763
  }
3726
- else {
3727
- return handle.success({}, resolve);
3764
+ cell.textContent = item;
3765
+ cell.onclick = e => {
3766
+ this.hide();
3767
+ const target = e.currentTarget;
3768
+ const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
3769
+ resolve(index);
3770
+ };
3771
+ });
3772
+ const cellsLen = this.cells.length;
3773
+ const itemListLen = config.itemList.length;
3774
+ if (cellsLen > itemListLen) {
3775
+ for (let i = itemListLen; i < cellsLen; i++) {
3776
+ this.menu.removeChild(this.cells[i]);
3728
3777
  }
3729
- };
3730
- scroll();
3731
- }
3732
- catch (e) {
3733
- return handle.fail({
3734
- errMsg: e.message
3735
- }, reject);
3736
- }
3737
- });
3738
- };
3739
-
3740
- // 置顶
3741
- const setTopBarText = temporarilyNotSupport('setTopBarText');
3742
-
3743
- let tabConf;
3744
- function initTabBarApis(config = {}) {
3745
- tabConf = config.tabBar;
3746
- }
3747
- /**
3748
- * 显示 tabBar 某一项的右上角的红点
3749
- */
3750
- const showTabBarRedDot = (options) => {
3751
- // options must be an Object
3752
- const isObject = shouldBeObject(options);
3753
- if (!isObject.flag) {
3754
- const res = { errMsg: `showTabBarRedDot:fail ${isObject.msg}` };
3755
- console.error(res.errMsg);
3756
- return Promise.reject(res);
3757
- }
3758
- const { index, success, fail, complete } = options;
3759
- const handle = new MethodHandler({ name: 'showTabBarRedDot', success, fail, complete });
3760
- if (typeof index !== 'number') {
3761
- return handle.fail({
3762
- errMsg: getParameterError({
3763
- para: 'index',
3764
- correct: 'Number',
3765
- wrong: index
3766
- })
3778
+ this.cells.splice(itemListLen);
3779
+ }
3780
+ // show
3781
+ this.el.style.display = 'block';
3782
+ setTimeout(() => {
3783
+ this.el.style.opacity = '1';
3784
+ setTransform(this.actionSheet, 'translate(0, 0)');
3785
+ }, 0);
3767
3786
  });
3768
3787
  }
3769
- return new Promise((resolve, reject) => {
3770
- Taro.eventCenter.trigger('__taroShowTabBarRedDotHandler', {
3771
- index,
3772
- successHandler: (res = {}) => handle.success(res, resolve),
3773
- errorHandler: (res = {}) => handle.fail(res, reject)
3774
- });
3775
- });
3776
- };
3777
- /**
3778
- * 显示 tabBar
3779
- */
3780
- const showTabBar = (options = {}) => {
3781
- // options must be an Object
3782
- const isObject = shouldBeObject(options);
3783
- if (!isObject.flag) {
3784
- const res = { errMsg: `showTabBar:fail ${isObject.msg}` };
3785
- console.error(res.errMsg);
3786
- return Promise.reject(res);
3788
+ hide() {
3789
+ if (this.hideOpacityTimer)
3790
+ clearTimeout(this.hideOpacityTimer);
3791
+ if (this.hideDisplayTimer)
3792
+ clearTimeout(this.hideDisplayTimer);
3793
+ this.hideOpacityTimer = setTimeout(() => {
3794
+ this.el.style.opacity = '0';
3795
+ setTransform(this.actionSheet, 'translate(0, 100%)');
3796
+ this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
3797
+ }, 0);
3787
3798
  }
3788
- const { animation, success, fail, complete } = options;
3789
- const handle = new MethodHandler({ name: 'showTabBar', success, fail, complete });
3790
- if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
3791
- return handle.fail({
3792
- errMsg: getParameterError({
3793
- para: 'animation',
3794
- correct: 'Boolean',
3795
- wrong: animation
3796
- })
3797
- });
3798
- }
3799
- return new Promise((resolve, reject) => {
3800
- Taro.eventCenter.trigger('__taroShowTabBar', {
3801
- animation,
3802
- successHandler: (res = {}) => handle.success(res, resolve),
3803
- errorHandler: (res = {}) => handle.fail(res, reject)
3804
- });
3805
- });
3806
- };
3807
- /**
3808
- * 动态设置 tabBar 的整体样式
3809
- */
3810
- const setTabBarStyle = (options = {}) => {
3811
- // options must be an Object
3812
- const isObject = shouldBeObject(options);
3813
- if (!isObject.flag) {
3814
- const res = { errMsg: `setTabBarStyle:fail ${isObject.msg}` };
3815
- console.error(res.errMsg);
3816
- return Promise.reject(res);
3817
- }
3818
- const { color, selectedColor, backgroundColor, borderStyle, success, fail, complete } = options;
3819
- const handle = new MethodHandler({ name: 'setTabBarStyle', success, fail, complete });
3820
- let errMsg;
3821
- if (color && !isValidColor(color)) {
3822
- errMsg = 'color';
3823
- }
3824
- else if (selectedColor && !isValidColor(selectedColor)) {
3825
- errMsg = 'selectedColor';
3826
- }
3827
- else if (backgroundColor && !isValidColor(backgroundColor)) {
3828
- errMsg = 'backgroundColor';
3829
- }
3830
- else if (borderStyle && !/^(black|white)$/.test(borderStyle)) {
3831
- errMsg = 'borderStyle';
3832
- }
3833
- if (errMsg) {
3834
- return handle.fail({ errMsg: `invalid ${errMsg}` });
3835
- }
3836
- if (!tabConf) {
3837
- return handle.fail();
3838
- }
3839
- const obj = {};
3840
- if (color)
3841
- obj.color = color;
3842
- if (selectedColor)
3843
- obj.selectedColor = selectedColor;
3844
- if (backgroundColor)
3845
- obj.backgroundColor = backgroundColor;
3846
- if (borderStyle)
3847
- obj.borderStyle = borderStyle;
3848
- return new Promise((resolve, reject) => {
3849
- Taro.eventCenter.trigger('__taroSetTabBarStyle', {
3850
- color,
3851
- selectedColor,
3852
- backgroundColor,
3853
- borderStyle,
3854
- successHandler: (res = {}) => handle.success(res, resolve),
3855
- errorHandler: (res = {}) => handle.fail(res, reject)
3856
- });
3857
- });
3858
- };
3859
- /**
3860
- * 动态设置 tabBar 某一项的内容
3861
- */
3862
- const setTabBarItem = (options) => {
3863
- // options must be an Object
3864
- const isObject = shouldBeObject(options);
3865
- if (!isObject.flag) {
3866
- const res = { errMsg: `setTabBarItem:fail ${isObject.msg}` };
3867
- console.error(res.errMsg);
3868
- return Promise.reject(res);
3869
- }
3870
- const { index, text, iconPath, selectedIconPath, success, fail, complete } = options;
3871
- const handle = new MethodHandler({ name: 'setTabBarItem', success, fail, complete });
3872
- if (typeof index !== 'number') {
3873
- return handle.fail({
3874
- errMsg: getParameterError({
3875
- para: 'index',
3876
- correct: 'Number',
3877
- wrong: index
3878
- })
3879
- });
3880
- }
3881
- return new Promise((resolve, reject) => {
3882
- Taro.eventCenter.trigger('__taroSetTabBarItem', {
3883
- index,
3884
- text,
3885
- iconPath,
3886
- selectedIconPath,
3887
- successHandler: (res = {}) => handle.success(res, resolve),
3888
- errorHandler: (res = {}) => handle.fail(res, reject)
3889
- });
3890
- });
3891
- };
3892
- /**
3893
- * 为 tabBar 某一项的右上角添加文本
3894
- */
3895
- const setTabBarBadge = (options) => {
3896
- // options must be an Object
3897
- const isObject = shouldBeObject(options);
3898
- if (!isObject.flag) {
3899
- const res = { errMsg: `setTabBarBadge:fail ${isObject.msg}` };
3900
- console.error(res.errMsg);
3901
- return Promise.reject(res);
3902
- }
3903
- const { index, text, success, fail, complete } = options;
3904
- const handle = new MethodHandler({ name: 'setTabBarBadge', success, fail, complete });
3905
- if (typeof index !== 'number') {
3906
- return handle.fail({
3907
- errMsg: getParameterError({
3908
- para: 'index',
3909
- correct: 'Number',
3910
- wrong: index
3911
- })
3912
- });
3913
- }
3914
- if (typeof text !== 'string') {
3915
- return handle.fail({
3916
- errMsg: getParameterError({
3917
- para: 'text',
3918
- correct: 'String',
3919
- wrong: text
3920
- })
3921
- });
3922
- }
3923
- return new Promise((resolve, reject) => {
3924
- Taro.eventCenter.trigger('__taroSetTabBarBadge', {
3925
- index,
3926
- text,
3927
- successHandler: (res = {}) => handle.success(res, resolve),
3928
- errorHandler: (res = {}) => handle.fail(res, reject)
3929
- });
3930
- });
3931
- };
3932
- /**
3933
- * 移除 tabBar 某一项右上角的文本
3934
- */
3935
- const removeTabBarBadge = (options) => {
3936
- // options must be an Object
3937
- const isObject = shouldBeObject(options);
3938
- if (!isObject.flag) {
3939
- const res = { errMsg: `removeTabBarBadge:fail ${isObject.msg}` };
3940
- console.error(res.errMsg);
3941
- return Promise.reject(res);
3942
- }
3943
- const { index, success, fail, complete } = options;
3944
- const handle = new MethodHandler({ name: 'removeTabBarBadge', success, fail, complete });
3945
- if (typeof index !== 'number') {
3946
- return handle.fail({
3947
- errMsg: getParameterError({
3948
- para: 'index',
3949
- correct: 'Number',
3950
- wrong: index
3951
- })
3952
- });
3953
- }
3954
- return new Promise((resolve, reject) => {
3955
- Taro.eventCenter.trigger('__taroRemoveTabBarBadge', {
3956
- index,
3957
- successHandler: (res = {}) => handle.success(res, resolve),
3958
- errorHandler: (res = {}) => handle.fail(res, reject)
3959
- });
3960
- });
3961
- };
3962
- /**
3963
- * 隐藏 tabBar 某一项的右上角的红点
3964
- */
3965
- const hideTabBarRedDot = (options) => {
3966
- // options must be an Object
3967
- const isObject = shouldBeObject(options);
3968
- if (!isObject.flag) {
3969
- const res = { errMsg: `hideTabBarRedDot:fail ${isObject.msg}` };
3970
- console.error(res.errMsg);
3971
- return Promise.reject(res);
3972
- }
3973
- const { index, success, fail, complete } = options;
3974
- const handle = new MethodHandler({ name: 'hideTabBarRedDot', success, fail, complete });
3975
- if (typeof index !== 'number') {
3976
- return handle.fail({
3977
- errMsg: getParameterError({
3978
- para: 'index',
3979
- correct: 'Number',
3980
- wrong: index
3981
- })
3982
- });
3983
- }
3984
- return new Promise((resolve, reject) => {
3985
- Taro.eventCenter.trigger('__taroHideTabBarRedDotHandler', {
3986
- index,
3987
- successHandler: (res = {}) => handle.success(res, resolve),
3988
- errorHandler: (res = {}) => handle.fail(res, reject)
3989
- });
3990
- });
3991
- };
3992
- /**
3993
- * 隐藏 tabBar
3994
- */
3995
- const hideTabBar = (options = {}) => {
3996
- // options must be an Object
3997
- const isObject = shouldBeObject(options);
3998
- if (!isObject.flag) {
3999
- const res = { errMsg: `hideTabBar:fail ${isObject.msg}` };
4000
- console.error(res.errMsg);
4001
- return Promise.reject(res);
3799
+ }
3800
+
3801
+ class Modal {
3802
+ constructor() {
3803
+ this.options = {
3804
+ title: '',
3805
+ content: '',
3806
+ showCancel: true,
3807
+ cancelText: '取消',
3808
+ cancelColor: '#000000',
3809
+ confirmText: '确定',
3810
+ confirmColor: '#3CC51F'
3811
+ };
3812
+ this.style = {
3813
+ maskStyle: {
3814
+ position: 'fixed',
3815
+ 'z-index': '1000',
3816
+ top: '0',
3817
+ right: '0',
3818
+ left: '0',
3819
+ bottom: '0',
3820
+ background: 'rgba(0,0,0,0.6)'
3821
+ },
3822
+ modalStyle: {
3823
+ 'z-index': '4999',
3824
+ position: 'fixed',
3825
+ top: '50%',
3826
+ left: '50%',
3827
+ transform: 'translate(-50%, -50%)',
3828
+ width: '80%',
3829
+ 'max-width': '300px',
3830
+ 'border-radius': '3px',
3831
+ 'text-align': 'center',
3832
+ 'line-height': '1.6',
3833
+ overflow: 'hidden',
3834
+ background: '#FFFFFF'
3835
+ },
3836
+ titleStyle: {
3837
+ padding: '20px 24px 9px',
3838
+ 'font-size': '18px'
3839
+ },
3840
+ textStyle: {
3841
+ padding: '0 24px 12px',
3842
+ 'min-height': '40px',
3843
+ 'font-size': '15px',
3844
+ 'line-height': '1.3',
3845
+ color: '#808080'
3846
+ },
3847
+ footStyle: {
3848
+ position: 'relative',
3849
+ 'line-height': '48px',
3850
+ 'font-size': '18px',
3851
+ display: 'flex'
3852
+ },
3853
+ btnStyle: {
3854
+ position: 'relative',
3855
+ '-webkit-box-flex': '1',
3856
+ '-webkit-flex': '1',
3857
+ flex: '1'
3858
+ }
3859
+ };
4002
3860
  }
4003
- const { animation, success, fail, complete } = options;
4004
- const handle = new MethodHandler({ name: 'hideTabBar', success, fail, complete });
4005
- if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
4006
- return handle.fail({
4007
- errMsg: getParameterError({
4008
- para: 'animation',
4009
- correct: 'Boolean',
4010
- wrong: animation
4011
- })
3861
+ create(options = {}) {
3862
+ return new Promise((resolve) => {
3863
+ // style
3864
+ const { maskStyle, modalStyle, titleStyle, textStyle, footStyle, btnStyle } = this.style;
3865
+ // configuration
3866
+ const config = Object.assign(Object.assign({}, this.options), options);
3867
+ // wrapper
3868
+ this.el = document.createElement('div');
3869
+ this.el.className = 'taro__modal';
3870
+ this.el.style.opacity = '0';
3871
+ this.el.style.transition = 'opacity 0.2s linear';
3872
+ // mask
3873
+ const mask = document.createElement('div');
3874
+ mask.className = 'taro-modal__mask';
3875
+ mask.setAttribute('style', inlineStyle(maskStyle));
3876
+ // modal
3877
+ const modal = document.createElement('div');
3878
+ modal.className = 'taro-modal__content';
3879
+ modal.setAttribute('style', inlineStyle(modalStyle));
3880
+ // title
3881
+ const titleCSS = config.title ? titleStyle : Object.assign(Object.assign({}, titleStyle), { display: 'none' });
3882
+ this.title = document.createElement('div');
3883
+ this.title.className = 'taro-modal__title';
3884
+ this.title.setAttribute('style', inlineStyle(titleCSS));
3885
+ this.title.textContent = config.title;
3886
+ // text
3887
+ const textCSS = config.title ? textStyle : Object.assign(Object.assign({}, textStyle), { padding: '40px 20px 26px', color: '#353535' });
3888
+ this.text = document.createElement('div');
3889
+ this.text.className = 'taro-modal__text';
3890
+ this.text.setAttribute('style', inlineStyle(textCSS));
3891
+ this.text.textContent = config.content;
3892
+ // foot
3893
+ const foot = document.createElement('div');
3894
+ foot.className = 'taro-modal__foot';
3895
+ foot.setAttribute('style', inlineStyle(footStyle));
3896
+ // cancel button
3897
+ const cancelCSS = Object.assign(Object.assign({}, btnStyle), { color: config.cancelColor, display: config.showCancel ? 'block' : 'none' });
3898
+ this.cancel = document.createElement('div');
3899
+ this.cancel.className = 'taro-model__btn taro-model__cancel';
3900
+ this.cancel.setAttribute('style', inlineStyle(cancelCSS));
3901
+ this.cancel.textContent = config.cancelText;
3902
+ this.cancel.onclick = () => {
3903
+ this.hide();
3904
+ resolve('cancel');
3905
+ };
3906
+ // confirm button
3907
+ this.confirm = document.createElement('div');
3908
+ this.confirm.className = 'taro-model__btn taro-model__confirm';
3909
+ this.confirm.setAttribute('style', inlineStyle(btnStyle));
3910
+ this.confirm.style.color = config.confirmColor;
3911
+ this.confirm.textContent = config.confirmText;
3912
+ this.confirm.onclick = () => {
3913
+ this.hide();
3914
+ resolve('confirm');
3915
+ };
3916
+ // result
3917
+ foot.appendChild(this.cancel);
3918
+ foot.appendChild(this.confirm);
3919
+ modal.appendChild(this.title);
3920
+ modal.appendChild(this.text);
3921
+ modal.appendChild(foot);
3922
+ this.el.appendChild(mask);
3923
+ this.el.appendChild(modal);
3924
+ // show immediately
3925
+ document.body.appendChild(this.el);
3926
+ setTimeout(() => { this.el.style.opacity = '1'; }, 0);
4012
3927
  });
4013
3928
  }
4014
- return new Promise((resolve, reject) => {
4015
- Taro.eventCenter.trigger('__taroHideTabBar', {
4016
- animation,
4017
- successHandler: (res = {}) => handle.success(res, resolve),
4018
- errorHandler: (res = {}) => handle.fail(res, reject)
3929
+ show(options = {}) {
3930
+ return new Promise((resolve) => {
3931
+ const config = Object.assign(Object.assign({}, this.options), options);
3932
+ if (this.hideOpacityTimer)
3933
+ clearTimeout(this.hideOpacityTimer);
3934
+ if (this.hideDisplayTimer)
3935
+ clearTimeout(this.hideDisplayTimer);
3936
+ // title & text
3937
+ const { textStyle } = this.style;
3938
+ if (config.title) {
3939
+ this.title.textContent = config.title;
3940
+ // none => block
3941
+ this.title.style.display = 'block';
3942
+ this.text.setAttribute('style', inlineStyle(textStyle));
3943
+ }
3944
+ else {
3945
+ // block => none
3946
+ this.title.style.display = 'none';
3947
+ const textCSS = Object.assign(Object.assign({}, textStyle), { padding: '40px 20px 26px', color: '#353535' });
3948
+ this.text.setAttribute('style', inlineStyle(textCSS));
3949
+ }
3950
+ this.text.textContent = config.content || '';
3951
+ // showCancel
3952
+ this.cancel.style.display = config.showCancel ? 'block' : 'none';
3953
+ // cancelText
3954
+ this.cancel.textContent = config.cancelText || '';
3955
+ // cancelColor
3956
+ this.cancel.style.color = config.cancelColor || '';
3957
+ // confirmText
3958
+ this.confirm.textContent = config.confirmText || '';
3959
+ // confirmColor
3960
+ this.confirm.style.color = config.confirmColor || '';
3961
+ // cbs
3962
+ this.cancel.onclick = () => {
3963
+ this.hide();
3964
+ resolve('cancel');
3965
+ };
3966
+ this.confirm.onclick = () => {
3967
+ this.hide();
3968
+ resolve('confirm');
3969
+ };
3970
+ // show
3971
+ this.el.style.display = 'block';
3972
+ setTimeout(() => { this.el.style.opacity = '1'; }, 0);
4019
3973
  });
4020
- });
4021
- };
4022
-
4023
- const callbackManager = new CallbackManager();
4024
- const resizeListener = () => {
4025
- callbackManager.trigger({
4026
- windowWidth: window.screen.width,
4027
- windowHeight: window.screen.height
4028
- });
4029
- };
4030
- /**
4031
- * 设置窗口大小,该接口仅适用于 PC 平台,使用细则请参见指南
4032
- */
4033
- const setWindowSize = temporarilyNotSupport('setWindowSize');
4034
- /**
4035
- * 监听窗口尺寸变化事件
4036
- */
4037
- const onWindowResize = callback => {
4038
- callbackManager.add(callback);
4039
- if (callbackManager.count() === 1) {
4040
- window.addEventListener('resize', resizeListener);
4041
3974
  }
4042
- };
4043
- /**
4044
- * 取消监听窗口尺寸变化事件
4045
- */
4046
- const offWindowResize = callback => {
4047
- callbackManager.remove(callback);
4048
- if (callbackManager.count() === 0) {
4049
- window.removeEventListener('resize', resizeListener);
3975
+ hide() {
3976
+ if (this.hideOpacityTimer)
3977
+ clearTimeout(this.hideOpacityTimer);
3978
+ if (this.hideDisplayTimer)
3979
+ clearTimeout(this.hideDisplayTimer);
3980
+ this.hideOpacityTimer = setTimeout(() => {
3981
+ this.el.style.opacity = '0';
3982
+ this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
3983
+ }, 0);
4050
3984
  }
4051
- };
3985
+ }
4052
3986
 
4053
3987
  class Toast {
4054
3988
  constructor() {
@@ -4219,632 +4153,730 @@ class Toast {
4219
4153
  }
4220
4154
  }
4221
4155
 
4222
- class Modal {
4223
- constructor() {
4224
- this.options = {
4225
- title: '',
4226
- content: '',
4227
- showCancel: true,
4228
- cancelText: '取消',
4229
- cancelColor: '#000000',
4230
- confirmText: '确定',
4231
- confirmColor: '#3CC51F'
4232
- };
4233
- this.style = {
4234
- maskStyle: {
4235
- position: 'fixed',
4236
- 'z-index': '1000',
4237
- top: '0',
4238
- right: '0',
4239
- left: '0',
4240
- bottom: '0',
4241
- background: 'rgba(0,0,0,0.6)'
4242
- },
4243
- modalStyle: {
4244
- 'z-index': '4999',
4245
- position: 'fixed',
4246
- top: '50%',
4247
- left: '50%',
4248
- transform: 'translate(-50%, -50%)',
4249
- width: '80%',
4250
- 'max-width': '300px',
4251
- 'border-radius': '3px',
4252
- 'text-align': 'center',
4253
- 'line-height': '1.6',
4254
- overflow: 'hidden',
4255
- background: '#FFFFFF'
4256
- },
4257
- titleStyle: {
4258
- padding: '20px 24px 9px',
4259
- 'font-size': '18px'
4260
- },
4261
- textStyle: {
4262
- padding: '0 24px 12px',
4263
- 'min-height': '40px',
4264
- 'font-size': '15px',
4265
- 'line-height': '1.3',
4266
- color: '#808080'
4267
- },
4268
- footStyle: {
4269
- position: 'relative',
4270
- 'line-height': '48px',
4271
- 'font-size': '18px',
4272
- display: 'flex'
4273
- },
4274
- btnStyle: {
4275
- position: 'relative',
4276
- '-webkit-box-flex': '1',
4277
- '-webkit-flex': '1',
4278
- flex: '1'
4279
- }
4280
- };
4156
+ // 交互
4157
+ let status = 'default';
4158
+ // inject necessary style
4159
+ function init(doc) {
4160
+ if (status === 'ready')
4161
+ return;
4162
+ const taroStyle = doc.createElement('style');
4163
+ taroStyle.textContent = '@font-face{font-weight:normal;font-style:normal;font-family:"taro";src:url("data:application/x-font-ttf;charset=utf-8;base64, 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") format("truetype");}@-webkit-keyframes taroLoading{0%{-webkit-transform:rotate3d(0, 0, 1, 0deg);}100%{-webkit-transform:rotate3d(0, 0, 1, 360deg);transform:rotate3d(0, 0, 1, 360deg);}}@keyframes taroLoading{0%{-webkit-transform:rotate3d(0, 0, 1, 0deg);}100%{-webkit-transform:rotate3d(0, 0, 1, 360deg);transform:rotate3d(0, 0, 1, 360deg);}}.taro-modal__foot:after {content: "";position: absolute;left: 0;top: 0;right: 0;height: 1px;border-top: 1px solid #D5D5D6;color: #D5D5D6;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleY(0.5);transform: scaleY(0.5);} .taro-model__btn:active {background-color: #EEEEEE}.taro-model__btn:not(:first-child):after {content: "";position: absolute;left: 0;top: 0;width: 1px;bottom: 0;border-left: 1px solid #D5D5D6;color: #D5D5D6;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleX(0.5);transform: scaleX(0.5);}.taro-actionsheet__cell:not(:first-child):after {content: "";position: absolute;left: 0;top: 0;right: 0;height: 1px;border-top: 1px solid #e5e5e5;color: #e5e5e5;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleY(0.5);transform: scaleY(0.5);}';
4164
+ doc.querySelector('head').appendChild(taroStyle);
4165
+ status = 'ready';
4166
+ }
4167
+ const toast = new Toast();
4168
+ const modal = new Modal();
4169
+ const actionSheet = new ActionSheet();
4170
+ const showToast = (options = { title: '' }) => {
4171
+ init(document);
4172
+ options = Object.assign({
4173
+ title: '',
4174
+ icon: 'success',
4175
+ image: '',
4176
+ duration: 1500,
4177
+ mask: false
4178
+ }, options);
4179
+ const { success, fail, complete } = options;
4180
+ const handle = new MethodHandler({ name: 'showToast', success, fail, complete });
4181
+ if (typeof options.title !== 'string') {
4182
+ return handle.fail({
4183
+ errMsg: getParameterError({
4184
+ para: 'title',
4185
+ correct: 'String',
4186
+ wrong: options.title
4187
+ })
4188
+ });
4281
4189
  }
4282
- create(options = {}) {
4283
- return new Promise((resolve) => {
4284
- // style
4285
- const { maskStyle, modalStyle, titleStyle, textStyle, footStyle, btnStyle } = this.style;
4286
- // configuration
4287
- const config = Object.assign(Object.assign({}, this.options), options);
4288
- // wrapper
4289
- this.el = document.createElement('div');
4290
- this.el.className = 'taro__modal';
4291
- this.el.style.opacity = '0';
4292
- this.el.style.transition = 'opacity 0.2s linear';
4293
- // mask
4294
- const mask = document.createElement('div');
4295
- mask.className = 'taro-modal__mask';
4296
- mask.setAttribute('style', inlineStyle(maskStyle));
4297
- // modal
4298
- const modal = document.createElement('div');
4299
- modal.className = 'taro-modal__content';
4300
- modal.setAttribute('style', inlineStyle(modalStyle));
4301
- // title
4302
- const titleCSS = config.title ? titleStyle : Object.assign(Object.assign({}, titleStyle), { display: 'none' });
4303
- this.title = document.createElement('div');
4304
- this.title.className = 'taro-modal__title';
4305
- this.title.setAttribute('style', inlineStyle(titleCSS));
4306
- this.title.textContent = config.title;
4307
- // text
4308
- const textCSS = config.title ? textStyle : Object.assign(Object.assign({}, textStyle), { padding: '40px 20px 26px', color: '#353535' });
4309
- this.text = document.createElement('div');
4310
- this.text.className = 'taro-modal__text';
4311
- this.text.setAttribute('style', inlineStyle(textCSS));
4312
- this.text.textContent = config.content;
4313
- // foot
4314
- const foot = document.createElement('div');
4315
- foot.className = 'taro-modal__foot';
4316
- foot.setAttribute('style', inlineStyle(footStyle));
4317
- // cancel button
4318
- const cancelCSS = Object.assign(Object.assign({}, btnStyle), { color: config.cancelColor, display: config.showCancel ? 'block' : 'none' });
4319
- this.cancel = document.createElement('div');
4320
- this.cancel.className = 'taro-model__btn taro-model__cancel';
4321
- this.cancel.setAttribute('style', inlineStyle(cancelCSS));
4322
- this.cancel.textContent = config.cancelText;
4323
- this.cancel.onclick = () => {
4324
- this.hide();
4325
- resolve('cancel');
4326
- };
4327
- // confirm button
4328
- this.confirm = document.createElement('div');
4329
- this.confirm.className = 'taro-model__btn taro-model__confirm';
4330
- this.confirm.setAttribute('style', inlineStyle(btnStyle));
4331
- this.confirm.style.color = config.confirmColor;
4332
- this.confirm.textContent = config.confirmText;
4333
- this.confirm.onclick = () => {
4334
- this.hide();
4335
- resolve('confirm');
4336
- };
4337
- // result
4338
- foot.appendChild(this.cancel);
4339
- foot.appendChild(this.confirm);
4340
- modal.appendChild(this.title);
4341
- modal.appendChild(this.text);
4342
- modal.appendChild(foot);
4343
- this.el.appendChild(mask);
4344
- this.el.appendChild(modal);
4345
- // show immediately
4346
- document.body.appendChild(this.el);
4347
- setTimeout(() => { this.el.style.opacity = '1'; }, 0);
4190
+ if (typeof options.duration !== 'number') {
4191
+ return handle.fail({
4192
+ errMsg: getParameterError({
4193
+ para: 'duration',
4194
+ correct: 'Number',
4195
+ wrong: options.duration
4196
+ })
4197
+ });
4198
+ }
4199
+ if (options.image && typeof options.image !== 'string')
4200
+ options.image = '';
4201
+ options.mask = !!options.mask;
4202
+ let errMsg = '';
4203
+ if (!toast.el) {
4204
+ errMsg = toast.create(options, 'toast');
4205
+ }
4206
+ else {
4207
+ errMsg = toast.show(options, 'toast');
4208
+ }
4209
+ return handle.success({ errMsg });
4210
+ };
4211
+ const hideToast = ({ success, fail, complete } = {}) => {
4212
+ const handle = new MethodHandler({ name: 'hideToast', success, fail, complete });
4213
+ if (!toast.el)
4214
+ return handle.success();
4215
+ toast.hide(0, 'toast');
4216
+ return handle.success();
4217
+ };
4218
+ const showLoading = (options = { title: '' }) => {
4219
+ init(document);
4220
+ options = Object.assign({
4221
+ title: '',
4222
+ mask: false
4223
+ }, options);
4224
+ const { success, fail, complete } = options;
4225
+ const handle = new MethodHandler({ name: 'showLoading', success, fail, complete });
4226
+ const config = {
4227
+ icon: 'loading',
4228
+ image: '',
4229
+ duration: -1
4230
+ };
4231
+ options = Object.assign({}, options, config);
4232
+ if (typeof options.title !== 'string') {
4233
+ return handle.fail({
4234
+ errMsg: getParameterError({
4235
+ para: 'title',
4236
+ correct: 'String',
4237
+ wrong: options.title
4238
+ })
4239
+ });
4240
+ }
4241
+ options.mask = !!options.mask;
4242
+ let errMsg = '';
4243
+ if (!toast.el) {
4244
+ errMsg = toast.create(options, 'loading');
4245
+ }
4246
+ else {
4247
+ errMsg = toast.show(options, 'loading');
4248
+ }
4249
+ return handle.success({ errMsg });
4250
+ };
4251
+ const hideLoading = ({ success, fail, complete } = {}) => {
4252
+ const handle = new MethodHandler({ name: 'hideLoading', success, fail, complete });
4253
+ if (!toast.el)
4254
+ return handle.success();
4255
+ toast.hide(0, 'loading');
4256
+ return handle.success();
4257
+ };
4258
+ const showModal = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
4259
+ init(document);
4260
+ options = Object.assign({
4261
+ title: '',
4262
+ content: '',
4263
+ showCancel: true,
4264
+ cancelText: '取消',
4265
+ cancelColor: '#000000',
4266
+ confirmText: '确定',
4267
+ confirmColor: '#3CC51F'
4268
+ }, options);
4269
+ const { success, fail, complete } = options;
4270
+ const handle = new MethodHandler({ name: 'showModal', success, fail, complete });
4271
+ if (typeof options.title !== 'string') {
4272
+ return handle.fail({
4273
+ errMsg: getParameterError({
4274
+ para: 'title',
4275
+ correct: 'String',
4276
+ wrong: options.title
4277
+ })
4348
4278
  });
4349
4279
  }
4350
- show(options = {}) {
4351
- return new Promise((resolve) => {
4352
- const config = Object.assign(Object.assign({}, this.options), options);
4353
- if (this.hideOpacityTimer)
4354
- clearTimeout(this.hideOpacityTimer);
4355
- if (this.hideDisplayTimer)
4356
- clearTimeout(this.hideDisplayTimer);
4357
- // title & text
4358
- const { textStyle } = this.style;
4359
- if (config.title) {
4360
- this.title.textContent = config.title;
4361
- // none => block
4362
- this.title.style.display = 'block';
4363
- this.text.setAttribute('style', inlineStyle(textStyle));
4364
- }
4365
- else {
4366
- // block => none
4367
- this.title.style.display = 'none';
4368
- const textCSS = Object.assign(Object.assign({}, textStyle), { padding: '40px 20px 26px', color: '#353535' });
4369
- this.text.setAttribute('style', inlineStyle(textCSS));
4370
- }
4371
- this.text.textContent = config.content || '';
4372
- // showCancel
4373
- this.cancel.style.display = config.showCancel ? 'block' : 'none';
4374
- // cancelText
4375
- this.cancel.textContent = config.cancelText || '';
4376
- // cancelColor
4377
- this.cancel.style.color = config.cancelColor || '';
4378
- // confirmText
4379
- this.confirm.textContent = config.confirmText || '';
4380
- // confirmColor
4381
- this.confirm.style.color = config.confirmColor || '';
4382
- // cbs
4383
- this.cancel.onclick = () => {
4384
- this.hide();
4385
- resolve('cancel');
4386
- };
4387
- this.confirm.onclick = () => {
4388
- this.hide();
4389
- resolve('confirm');
4390
- };
4391
- // show
4392
- this.el.style.display = 'block';
4393
- setTimeout(() => { this.el.style.opacity = '1'; }, 0);
4280
+ if (typeof options.content !== 'string') {
4281
+ return handle.fail({
4282
+ errMsg: getParameterError({
4283
+ para: 'content',
4284
+ correct: 'String',
4285
+ wrong: options.content
4286
+ })
4394
4287
  });
4395
4288
  }
4396
- hide() {
4397
- if (this.hideOpacityTimer)
4398
- clearTimeout(this.hideOpacityTimer);
4399
- if (this.hideDisplayTimer)
4400
- clearTimeout(this.hideDisplayTimer);
4401
- this.hideOpacityTimer = setTimeout(() => {
4402
- this.el.style.opacity = '0';
4403
- this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
4404
- }, 0);
4289
+ if (typeof options.cancelText !== 'string') {
4290
+ return handle.fail({
4291
+ errMsg: getParameterError({
4292
+ para: 'cancelText',
4293
+ correct: 'String',
4294
+ wrong: options.cancelText
4295
+ })
4296
+ });
4405
4297
  }
4406
- }
4407
-
4408
- const noop = function () { };
4409
- class ActionSheet {
4410
- constructor() {
4411
- this.options = {
4412
- itemList: [],
4413
- itemColor: '#000000',
4414
- success: noop,
4415
- fail: noop,
4416
- complete: noop
4417
- };
4418
- this.style = {
4419
- maskStyle: {
4420
- position: 'fixed',
4421
- 'z-index': '1000',
4422
- top: '0',
4423
- right: '0',
4424
- left: '0',
4425
- bottom: '0',
4426
- background: 'rgba(0,0,0,0.6)'
4427
- },
4428
- actionSheetStyle: {
4429
- 'z-index': '4999',
4430
- position: 'fixed',
4431
- left: '0',
4432
- bottom: '0',
4433
- '-webkit-transform': 'translate(0, 100%)',
4434
- transform: 'translate(0, 100%)',
4435
- width: '100%',
4436
- 'line-height': '1.6',
4437
- background: '#EFEFF4',
4438
- '-webkit-transition': '-webkit-transform .3s',
4439
- transition: 'transform .3s'
4440
- },
4441
- menuStyle: {
4442
- 'background-color': '#FCFCFD'
4443
- },
4444
- cellStyle: {
4445
- position: 'relative',
4446
- padding: '10px 0',
4447
- 'text-align': 'center',
4448
- 'font-size': '18px'
4449
- },
4450
- cancelStyle: {
4451
- 'margin-top': '6px',
4452
- padding: '10px 0',
4453
- 'text-align': 'center',
4454
- 'font-size': '18px',
4455
- color: '#000000',
4456
- 'background-color': '#FCFCFD'
4457
- }
4458
- };
4459
- this.lastConfig = {};
4298
+ if (options.cancelText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
4299
+ return handle.fail({
4300
+ errMsg: 'cancelText length should not larger then 4 Chinese characters'
4301
+ });
4460
4302
  }
4461
- create(options = {}) {
4462
- return new Promise((resolve) => {
4463
- // style
4464
- const { maskStyle, actionSheetStyle, menuStyle, cellStyle, cancelStyle } = this.style;
4465
- // configuration
4466
- const config = Object.assign(Object.assign({}, this.options), options);
4467
- this.lastConfig = config;
4468
- // wrapper
4469
- this.el = document.createElement('div');
4470
- this.el.className = 'taro__actionSheet';
4471
- this.el.style.opacity = '0';
4472
- this.el.style.transition = 'opacity 0.2s linear';
4473
- // mask
4474
- const mask = document.createElement('div');
4475
- mask.setAttribute('style', inlineStyle(maskStyle));
4476
- // actionSheet
4477
- this.actionSheet = document.createElement('div');
4478
- this.actionSheet.setAttribute('style', inlineStyle(actionSheetStyle));
4479
- // menu
4480
- this.menu = document.createElement('div');
4481
- this.menu.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, menuStyle), { color: config.itemColor })));
4482
- // cells
4483
- this.cells = config.itemList.map((item, index) => {
4484
- const cell = document.createElement('div');
4485
- cell.className = 'taro-actionsheet__cell';
4486
- cell.setAttribute('style', inlineStyle(cellStyle));
4487
- cell.textContent = item;
4488
- cell.dataset.tapIndex = `${index}`;
4489
- cell.onclick = e => {
4490
- this.hide();
4491
- const target = e.currentTarget;
4492
- const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
4493
- resolve(index);
4494
- };
4495
- return cell;
4496
- });
4497
- // cancel
4498
- this.cancel = document.createElement('div');
4499
- this.cancel.setAttribute('style', inlineStyle(cancelStyle));
4500
- this.cancel.textContent = '取消';
4501
- // result
4502
- this.cells.forEach(item => this.menu.appendChild(item));
4503
- this.actionSheet.appendChild(this.menu);
4504
- this.actionSheet.appendChild(this.cancel);
4505
- this.el.appendChild(mask);
4506
- this.el.appendChild(this.actionSheet);
4507
- // callbacks
4508
- const cb = () => {
4509
- this.hide();
4510
- resolve('cancel');
4511
- };
4512
- mask.onclick = cb;
4513
- this.cancel.onclick = cb;
4514
- // show immediately
4515
- document.body.appendChild(this.el);
4516
- setTimeout(() => {
4517
- this.el.style.opacity = '1';
4518
- setTransform(this.actionSheet, 'translate(0, 0)');
4519
- }, 0);
4303
+ if (typeof options.confirmText !== 'string') {
4304
+ return handle.fail({
4305
+ errMsg: getParameterError({
4306
+ para: 'confirmText',
4307
+ correct: 'String',
4308
+ wrong: options.confirmText
4309
+ })
4310
+ });
4311
+ }
4312
+ if (options.confirmText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
4313
+ return handle.fail({
4314
+ errMsg: 'confirmText length should not larger then 4 Chinese characters'
4315
+ });
4316
+ }
4317
+ if (typeof options.cancelColor !== 'string') {
4318
+ return handle.fail({
4319
+ errMsg: getParameterError({
4320
+ para: 'cancelColor',
4321
+ correct: 'String',
4322
+ wrong: options.cancelColor
4323
+ })
4324
+ });
4325
+ }
4326
+ if (typeof options.confirmColor !== 'string') {
4327
+ return handle.fail({
4328
+ errMsg: getParameterError({
4329
+ para: 'confirmColor',
4330
+ correct: 'String',
4331
+ wrong: options.confirmColor
4332
+ })
4333
+ });
4334
+ }
4335
+ options.showCancel = !!options.showCancel;
4336
+ let result = '';
4337
+ if (!modal.el) {
4338
+ result = yield modal.create(options);
4339
+ }
4340
+ else {
4341
+ result = yield modal.show(options);
4342
+ }
4343
+ const res = { cancel: !1, confirm: !1 };
4344
+ res[result] = !0;
4345
+ return handle.success(res);
4346
+ });
4347
+ function hideModal() {
4348
+ if (!modal.el)
4349
+ return;
4350
+ modal.hide();
4351
+ }
4352
+ const showActionSheet = (options = { itemList: [] }) => __awaiter(void 0, void 0, void 0, function* () {
4353
+ init(document);
4354
+ options = Object.assign({
4355
+ itemColor: '#000000',
4356
+ itemList: []
4357
+ }, options);
4358
+ const { success, fail, complete } = options;
4359
+ const handle = new MethodHandler({ name: 'showActionSheet', success, fail, complete });
4360
+ // list item String
4361
+ if (!Array.isArray(options.itemList)) {
4362
+ return handle.fail({
4363
+ errMsg: getParameterError({
4364
+ para: 'itemList',
4365
+ correct: 'Array',
4366
+ wrong: options.itemList
4367
+ })
4520
4368
  });
4521
4369
  }
4522
- show(options = {}) {
4523
- return new Promise((resolve) => {
4524
- const config = Object.assign(Object.assign({}, this.options), options);
4525
- this.lastConfig = config;
4526
- if (this.hideOpacityTimer)
4527
- clearTimeout(this.hideOpacityTimer);
4528
- if (this.hideDisplayTimer)
4529
- clearTimeout(this.hideDisplayTimer);
4530
- // itemColor
4531
- if (config.itemColor)
4532
- this.menu.style.color = config.itemColor;
4533
- // cells
4534
- const { cellStyle } = this.style;
4535
- config.itemList.forEach((item, index) => {
4536
- let cell;
4537
- if (this.cells[index]) {
4538
- // assign new content
4539
- cell = this.cells[index];
4540
- }
4541
- else {
4542
- // create new cell
4543
- cell = document.createElement('div');
4544
- cell.className = 'taro-actionsheet__cell';
4545
- cell.setAttribute('style', inlineStyle(cellStyle));
4546
- cell.dataset.tapIndex = `${index}`;
4547
- this.cells.push(cell);
4548
- this.menu.appendChild(cell);
4549
- }
4550
- cell.textContent = item;
4551
- cell.onclick = e => {
4552
- this.hide();
4553
- const target = e.currentTarget;
4554
- const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
4555
- resolve(index);
4556
- };
4370
+ if (options.itemList.length < 1) {
4371
+ return handle.fail({ errMsg: 'parameter error: parameter.itemList should have at least 1 item' });
4372
+ }
4373
+ if (options.itemList.length > 6) {
4374
+ return handle.fail({ errMsg: 'parameter error: parameter.itemList should not be large than 6' });
4375
+ }
4376
+ for (let i = 0; i < options.itemList.length; i++) {
4377
+ if (typeof options.itemList[i] !== 'string') {
4378
+ return handle.fail({
4379
+ errMsg: getParameterError({
4380
+ para: `itemList[${i}]`,
4381
+ correct: 'String',
4382
+ wrong: options.itemList[i]
4383
+ })
4557
4384
  });
4558
- const cellsLen = this.cells.length;
4559
- const itemListLen = config.itemList.length;
4560
- if (cellsLen > itemListLen) {
4561
- for (let i = itemListLen; i < cellsLen; i++) {
4562
- this.menu.removeChild(this.cells[i]);
4563
- }
4564
- this.cells.splice(itemListLen);
4565
- }
4566
- // show
4567
- this.el.style.display = 'block';
4568
- setTimeout(() => {
4569
- this.el.style.opacity = '1';
4570
- setTransform(this.actionSheet, 'translate(0, 0)');
4571
- }, 0);
4385
+ }
4386
+ }
4387
+ if (typeof options.itemColor !== 'string') {
4388
+ return handle.fail({
4389
+ errMsg: getParameterError({
4390
+ para: 'itemColor',
4391
+ correct: 'String',
4392
+ wrong: options.itemColor
4393
+ })
4572
4394
  });
4573
4395
  }
4574
- hide() {
4575
- if (this.hideOpacityTimer)
4576
- clearTimeout(this.hideOpacityTimer);
4577
- if (this.hideDisplayTimer)
4578
- clearTimeout(this.hideDisplayTimer);
4579
- this.hideOpacityTimer = setTimeout(() => {
4580
- this.el.style.opacity = '0';
4581
- setTransform(this.actionSheet, 'translate(0, 100%)');
4582
- this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
4583
- }, 0);
4396
+ let result = '';
4397
+ if (!actionSheet.el) {
4398
+ result = yield actionSheet.create(options);
4399
+ }
4400
+ else {
4401
+ result = yield actionSheet.show(options);
4402
+ }
4403
+ if (typeof result === 'string') {
4404
+ return handle.fail(({ errMsg: result }));
4405
+ }
4406
+ else {
4407
+ return handle.success(({ tapIndex: result }));
4408
+ }
4409
+ });
4410
+ Taro.eventCenter.on('__taroRouterChange', () => {
4411
+ hideToast();
4412
+ hideLoading();
4413
+ hideModal();
4414
+ });
4415
+ const enableAlertBeforeUnload = temporarilyNotSupport('enableAlertBeforeUnload');
4416
+ const disableAlertBeforeUnload = temporarilyNotSupport('disableAlertBeforeUnload');
4417
+
4418
+ // 菜单
4419
+ const getMenuButtonBoundingClientRect = temporarilyNotSupport('getMenuButtonBoundingClientRect');
4420
+
4421
+ // 导航栏
4422
+ const showNavigationBarLoading = temporarilyNotSupport('showNavigationBarLoading');
4423
+ function setNavigationBarTitle(options) {
4424
+ // options must be an Object
4425
+ const isObject = shouldBeObject(options);
4426
+ if (!isObject.flag) {
4427
+ const res = { errMsg: `setNavigationBarTitle:fail ${isObject.msg}` };
4428
+ console.error(res.errMsg);
4429
+ return Promise.reject(res);
4430
+ }
4431
+ const { title, success, fail, complete } = options;
4432
+ const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete });
4433
+ if (!title || typeof title !== 'string') {
4434
+ return handle.fail({
4435
+ errMsg: getParameterError({
4436
+ para: 'title',
4437
+ correct: 'String',
4438
+ wrong: title
4439
+ })
4440
+ });
4584
4441
  }
4442
+ if (document.title !== title) {
4443
+ document.title = title;
4444
+ }
4445
+ return handle.success();
4585
4446
  }
4447
+ /**
4448
+ * 设置页面导航条颜色
4449
+ */
4450
+ const setNavigationBarColor = (options) => {
4451
+ const { backgroundColor, success, fail, complete } = options;
4452
+ const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete });
4453
+ const meta = document.createElement('meta');
4454
+ meta.setAttribute('name', 'theme-color');
4455
+ meta.setAttribute('content', backgroundColor);
4456
+ document.head.appendChild(meta);
4457
+ return handle.success();
4458
+ };
4459
+ const hideNavigationBarLoading = temporarilyNotSupport('hideNavigationBarLoading');
4460
+ const hideHomeButton = temporarilyNotSupport('hideHomeButton');
4461
+
4462
+ /**
4463
+ * 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
4464
+ */
4465
+ const startPullDownRefresh = function ({ success, fail, complete } = {}) {
4466
+ const handle = new MethodHandler({ name: 'startPullDownRefresh', success, fail, complete });
4467
+ return new Promise((resolve, reject) => {
4468
+ Taro.eventCenter.trigger('__taroStartPullDownRefresh', {
4469
+ successHandler: (res = {}) => handle.success(res, resolve),
4470
+ errorHandler: (res = {}) => handle.fail(res, reject)
4471
+ });
4472
+ });
4473
+ };
4474
+ /**
4475
+ * 停止当前页面下拉刷新。
4476
+ */
4477
+ const stopPullDownRefresh = function ({ success, fail, complete } = {}) {
4478
+ const handle = new MethodHandler({ name: 'stopPullDownRefresh', success, fail, complete });
4479
+ return new Promise((resolve, reject) => {
4480
+ Taro.eventCenter.trigger('__taroStopPullDownRefresh', {
4481
+ successHandler: (res = {}) => handle.success(res, resolve),
4482
+ errorHandler: (res = {}) => handle.fail(res, reject)
4483
+ });
4484
+ });
4485
+ };
4486
+
4487
+ let timer;
4488
+ const FRAME_DURATION = 17;
4489
+ /**
4490
+ * 将页面滚动到目标位置
4491
+ */
4492
+ const pageScrollTo = ({ scrollTop, selector = '', duration = 300, success, fail, complete }) => {
4493
+ let scrollFunc;
4494
+ const handle = new MethodHandler({ name: 'pageScrollTo', success, fail, complete });
4495
+ return new Promise((resolve, reject) => {
4496
+ var _a, _b;
4497
+ try {
4498
+ if (scrollTop === undefined && !selector) {
4499
+ return handle.fail({
4500
+ errMsg: 'scrollTop" 或 "selector" 需要其之一'
4501
+ }, reject);
4502
+ }
4503
+ const id = (_b = (_a = Current$1.page) === null || _a === void 0 ? void 0 : _a.path) === null || _b === void 0 ? void 0 : _b.replace(/([^a-z0-9\u00a0-\uffff_-])/ig, '\\$1');
4504
+ const el = (id
4505
+ ? document.querySelector(`.taro_page#${id}`)
4506
+ : document.querySelector('.taro_page') ||
4507
+ document.querySelector('.taro_router'));
4508
+ if (!scrollFunc) {
4509
+ if (!el) {
4510
+ scrollFunc = pos => {
4511
+ if (pos === undefined) {
4512
+ return window.pageYOffset;
4513
+ }
4514
+ else {
4515
+ window.scrollTo(0, pos);
4516
+ }
4517
+ };
4518
+ }
4519
+ else {
4520
+ scrollFunc = pos => {
4521
+ if (pos === undefined) {
4522
+ return el.scrollTop;
4523
+ }
4524
+ else {
4525
+ el.scrollTop = pos;
4526
+ }
4527
+ };
4528
+ }
4529
+ }
4530
+ if (scrollTop && selector) {
4531
+ console.warn('"scrollTop" 或 "selector" 建议只设一个值,全部设置会忽略selector');
4532
+ }
4533
+ const from = scrollFunc();
4534
+ let to;
4535
+ if (typeof scrollTop === 'number') {
4536
+ to = scrollTop;
4537
+ }
4538
+ else {
4539
+ const el = document.querySelector(selector);
4540
+ to = (el === null || el === void 0 ? void 0 : el.offsetTop) || 0;
4541
+ }
4542
+ const delta = to - from;
4543
+ const frameCnt = duration / FRAME_DURATION;
4544
+ const easeFunc = getTimingFunc(easeInOut, frameCnt);
4545
+ const scroll = (frame = 0) => {
4546
+ const dest = from + delta * easeFunc(frame);
4547
+ scrollFunc(dest);
4548
+ if (frame < frameCnt) {
4549
+ timer && clearTimeout(timer);
4550
+ timer = setTimeout(() => {
4551
+ scroll(frame + 1);
4552
+ }, FRAME_DURATION);
4553
+ }
4554
+ else {
4555
+ return handle.success({}, resolve);
4556
+ }
4557
+ };
4558
+ scroll();
4559
+ }
4560
+ catch (e) {
4561
+ return handle.fail({
4562
+ errMsg: e.message
4563
+ }, reject);
4564
+ }
4565
+ });
4566
+ };
4586
4567
 
4587
- // 交互
4588
- let status = 'default';
4589
- // inject necessary style
4590
- function init(doc) {
4591
- if (status === 'ready')
4592
- return;
4593
- const taroStyle = doc.createElement('style');
4594
- taroStyle.textContent = '@font-face{font-weight:normal;font-style:normal;font-family:"taro";src:url("data:application/x-font-ttf;charset=utf-8;base64, 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") format("truetype");}@-webkit-keyframes taroLoading{0%{-webkit-transform:rotate3d(0, 0, 1, 0deg);}100%{-webkit-transform:rotate3d(0, 0, 1, 360deg);transform:rotate3d(0, 0, 1, 360deg);}}@keyframes taroLoading{0%{-webkit-transform:rotate3d(0, 0, 1, 0deg);}100%{-webkit-transform:rotate3d(0, 0, 1, 360deg);transform:rotate3d(0, 0, 1, 360deg);}}.taro-modal__foot:after {content: "";position: absolute;left: 0;top: 0;right: 0;height: 1px;border-top: 1px solid #D5D5D6;color: #D5D5D6;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleY(0.5);transform: scaleY(0.5);} .taro-model__btn:active {background-color: #EEEEEE}.taro-model__btn:not(:first-child):after {content: "";position: absolute;left: 0;top: 0;width: 1px;bottom: 0;border-left: 1px solid #D5D5D6;color: #D5D5D6;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleX(0.5);transform: scaleX(0.5);}.taro-actionsheet__cell:not(:first-child):after {content: "";position: absolute;left: 0;top: 0;right: 0;height: 1px;border-top: 1px solid #e5e5e5;color: #e5e5e5;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleY(0.5);transform: scaleY(0.5);}';
4595
- doc.querySelector('head').appendChild(taroStyle);
4596
- status = 'ready';
4568
+ // 置顶
4569
+ const setTopBarText = temporarilyNotSupport('setTopBarText');
4570
+
4571
+ let tabConf;
4572
+ function initTabBarApis(config = {}) {
4573
+ tabConf = config.tabBar;
4597
4574
  }
4598
- const toast = new Toast();
4599
- const modal = new Modal();
4600
- const actionSheet = new ActionSheet();
4601
- const showToast = (options = { title: '' }) => {
4602
- init(document);
4603
- options = Object.assign({
4604
- title: '',
4605
- icon: 'success',
4606
- image: '',
4607
- duration: 1500,
4608
- mask: false
4609
- }, options);
4610
- const { success, fail, complete } = options;
4611
- const handle = new MethodHandler({ name: 'showToast', success, fail, complete });
4612
- if (typeof options.title !== 'string') {
4613
- return handle.fail({
4614
- errMsg: getParameterError({
4615
- para: 'title',
4616
- correct: 'String',
4617
- wrong: options.title
4618
- })
4619
- });
4575
+ /**
4576
+ * 显示 tabBar 某一项的右上角的红点
4577
+ */
4578
+ const showTabBarRedDot = (options) => {
4579
+ // options must be an Object
4580
+ const isObject = shouldBeObject(options);
4581
+ if (!isObject.flag) {
4582
+ const res = { errMsg: `showTabBarRedDot:fail ${isObject.msg}` };
4583
+ console.error(res.errMsg);
4584
+ return Promise.reject(res);
4620
4585
  }
4621
- if (typeof options.duration !== 'number') {
4586
+ const { index, success, fail, complete } = options;
4587
+ const handle = new MethodHandler({ name: 'showTabBarRedDot', success, fail, complete });
4588
+ if (typeof index !== 'number') {
4622
4589
  return handle.fail({
4623
4590
  errMsg: getParameterError({
4624
- para: 'duration',
4591
+ para: 'index',
4625
4592
  correct: 'Number',
4626
- wrong: options.duration
4593
+ wrong: index
4627
4594
  })
4628
4595
  });
4629
4596
  }
4630
- if (options.image && typeof options.image !== 'string')
4631
- options.image = '';
4632
- options.mask = !!options.mask;
4633
- let errMsg = '';
4634
- if (!toast.el) {
4635
- errMsg = toast.create(options, 'toast');
4636
- }
4637
- else {
4638
- errMsg = toast.show(options, 'toast');
4639
- }
4640
- return handle.success({ errMsg });
4641
- };
4642
- const hideToast = ({ success, fail, complete } = {}) => {
4643
- const handle = new MethodHandler({ name: 'hideToast', success, fail, complete });
4644
- if (!toast.el)
4645
- return handle.success();
4646
- toast.hide(0, 'toast');
4647
- return handle.success();
4597
+ return new Promise((resolve, reject) => {
4598
+ Taro.eventCenter.trigger('__taroShowTabBarRedDotHandler', {
4599
+ index,
4600
+ successHandler: (res = {}) => handle.success(res, resolve),
4601
+ errorHandler: (res = {}) => handle.fail(res, reject)
4602
+ });
4603
+ });
4648
4604
  };
4649
- const showLoading = (options = { title: '' }) => {
4650
- init(document);
4651
- options = Object.assign({
4652
- title: '',
4653
- mask: false
4654
- }, options);
4655
- const { success, fail, complete } = options;
4656
- const handle = new MethodHandler({ name: 'showLoading', success, fail, complete });
4657
- const config = {
4658
- icon: 'loading',
4659
- image: '',
4660
- duration: -1
4661
- };
4662
- options = Object.assign({}, options, config);
4663
- if (typeof options.title !== 'string') {
4605
+ /**
4606
+ * 显示 tabBar
4607
+ */
4608
+ const showTabBar = (options = {}) => {
4609
+ // options must be an Object
4610
+ const isObject = shouldBeObject(options);
4611
+ if (!isObject.flag) {
4612
+ const res = { errMsg: `showTabBar:fail ${isObject.msg}` };
4613
+ console.error(res.errMsg);
4614
+ return Promise.reject(res);
4615
+ }
4616
+ const { animation, success, fail, complete } = options;
4617
+ const handle = new MethodHandler({ name: 'showTabBar', success, fail, complete });
4618
+ if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
4664
4619
  return handle.fail({
4665
4620
  errMsg: getParameterError({
4666
- para: 'title',
4667
- correct: 'String',
4668
- wrong: options.title
4621
+ para: 'animation',
4622
+ correct: 'Boolean',
4623
+ wrong: animation
4669
4624
  })
4670
4625
  });
4671
4626
  }
4672
- options.mask = !!options.mask;
4673
- let errMsg = '';
4674
- if (!toast.el) {
4675
- errMsg = toast.create(options, 'loading');
4627
+ return new Promise((resolve, reject) => {
4628
+ Taro.eventCenter.trigger('__taroShowTabBar', {
4629
+ animation,
4630
+ successHandler: (res = {}) => handle.success(res, resolve),
4631
+ errorHandler: (res = {}) => handle.fail(res, reject)
4632
+ });
4633
+ });
4634
+ };
4635
+ /**
4636
+ * 动态设置 tabBar 的整体样式
4637
+ */
4638
+ const setTabBarStyle = (options = {}) => {
4639
+ // options must be an Object
4640
+ const isObject = shouldBeObject(options);
4641
+ if (!isObject.flag) {
4642
+ const res = { errMsg: `setTabBarStyle:fail ${isObject.msg}` };
4643
+ console.error(res.errMsg);
4644
+ return Promise.reject(res);
4676
4645
  }
4677
- else {
4678
- errMsg = toast.show(options, 'loading');
4646
+ const { color, selectedColor, backgroundColor, borderStyle, success, fail, complete } = options;
4647
+ const handle = new MethodHandler({ name: 'setTabBarStyle', success, fail, complete });
4648
+ let errMsg;
4649
+ if (color && !isValidColor(color)) {
4650
+ errMsg = 'color';
4679
4651
  }
4680
- return handle.success({ errMsg });
4681
- };
4682
- const hideLoading = ({ success, fail, complete } = {}) => {
4683
- const handle = new MethodHandler({ name: 'hideLoading', success, fail, complete });
4684
- if (!toast.el)
4685
- return handle.success();
4686
- toast.hide(0, 'loading');
4687
- return handle.success();
4652
+ else if (selectedColor && !isValidColor(selectedColor)) {
4653
+ errMsg = 'selectedColor';
4654
+ }
4655
+ else if (backgroundColor && !isValidColor(backgroundColor)) {
4656
+ errMsg = 'backgroundColor';
4657
+ }
4658
+ else if (borderStyle && !/^(black|white)$/.test(borderStyle)) {
4659
+ errMsg = 'borderStyle';
4660
+ }
4661
+ if (errMsg) {
4662
+ return handle.fail({ errMsg: `invalid ${errMsg}` });
4663
+ }
4664
+ if (!tabConf) {
4665
+ return handle.fail();
4666
+ }
4667
+ const obj = {};
4668
+ if (color)
4669
+ obj.color = color;
4670
+ if (selectedColor)
4671
+ obj.selectedColor = selectedColor;
4672
+ if (backgroundColor)
4673
+ obj.backgroundColor = backgroundColor;
4674
+ if (borderStyle)
4675
+ obj.borderStyle = borderStyle;
4676
+ return new Promise((resolve, reject) => {
4677
+ Taro.eventCenter.trigger('__taroSetTabBarStyle', {
4678
+ color,
4679
+ selectedColor,
4680
+ backgroundColor,
4681
+ borderStyle,
4682
+ successHandler: (res = {}) => handle.success(res, resolve),
4683
+ errorHandler: (res = {}) => handle.fail(res, reject)
4684
+ });
4685
+ });
4688
4686
  };
4689
- const showModal = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
4690
- init(document);
4691
- options = Object.assign({
4692
- title: '',
4693
- content: '',
4694
- showCancel: true,
4695
- cancelText: '取消',
4696
- cancelColor: '#000000',
4697
- confirmText: '确定',
4698
- confirmColor: '#3CC51F'
4699
- }, options);
4700
- const { success, fail, complete } = options;
4701
- const handle = new MethodHandler({ name: 'showModal', success, fail, complete });
4702
- if (typeof options.title !== 'string') {
4687
+ /**
4688
+ * 动态设置 tabBar 某一项的内容
4689
+ */
4690
+ const setTabBarItem = (options) => {
4691
+ // options must be an Object
4692
+ const isObject = shouldBeObject(options);
4693
+ if (!isObject.flag) {
4694
+ const res = { errMsg: `setTabBarItem:fail ${isObject.msg}` };
4695
+ console.error(res.errMsg);
4696
+ return Promise.reject(res);
4697
+ }
4698
+ const { index, text, iconPath, selectedIconPath, success, fail, complete } = options;
4699
+ const handle = new MethodHandler({ name: 'setTabBarItem', success, fail, complete });
4700
+ if (typeof index !== 'number') {
4703
4701
  return handle.fail({
4704
4702
  errMsg: getParameterError({
4705
- para: 'title',
4706
- correct: 'String',
4707
- wrong: options.title
4703
+ para: 'index',
4704
+ correct: 'Number',
4705
+ wrong: index
4708
4706
  })
4709
4707
  });
4710
4708
  }
4711
- if (typeof options.content !== 'string') {
4709
+ return new Promise((resolve, reject) => {
4710
+ Taro.eventCenter.trigger('__taroSetTabBarItem', {
4711
+ index,
4712
+ text,
4713
+ iconPath,
4714
+ selectedIconPath,
4715
+ successHandler: (res = {}) => handle.success(res, resolve),
4716
+ errorHandler: (res = {}) => handle.fail(res, reject)
4717
+ });
4718
+ });
4719
+ };
4720
+ /**
4721
+ * 为 tabBar 某一项的右上角添加文本
4722
+ */
4723
+ const setTabBarBadge = (options) => {
4724
+ // options must be an Object
4725
+ const isObject = shouldBeObject(options);
4726
+ if (!isObject.flag) {
4727
+ const res = { errMsg: `setTabBarBadge:fail ${isObject.msg}` };
4728
+ console.error(res.errMsg);
4729
+ return Promise.reject(res);
4730
+ }
4731
+ const { index, text, success, fail, complete } = options;
4732
+ const handle = new MethodHandler({ name: 'setTabBarBadge', success, fail, complete });
4733
+ if (typeof index !== 'number') {
4712
4734
  return handle.fail({
4713
4735
  errMsg: getParameterError({
4714
- para: 'content',
4715
- correct: 'String',
4716
- wrong: options.content
4736
+ para: 'index',
4737
+ correct: 'Number',
4738
+ wrong: index
4717
4739
  })
4718
4740
  });
4719
4741
  }
4720
- if (typeof options.cancelText !== 'string') {
4742
+ if (typeof text !== 'string') {
4721
4743
  return handle.fail({
4722
4744
  errMsg: getParameterError({
4723
- para: 'cancelText',
4745
+ para: 'text',
4724
4746
  correct: 'String',
4725
- wrong: options.cancelText
4747
+ wrong: text
4726
4748
  })
4727
4749
  });
4728
4750
  }
4729
- if (options.cancelText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
4730
- return handle.fail({
4731
- errMsg: 'cancelText length should not larger then 4 Chinese characters'
4751
+ return new Promise((resolve, reject) => {
4752
+ Taro.eventCenter.trigger('__taroSetTabBarBadge', {
4753
+ index,
4754
+ text,
4755
+ successHandler: (res = {}) => handle.success(res, resolve),
4756
+ errorHandler: (res = {}) => handle.fail(res, reject)
4732
4757
  });
4758
+ });
4759
+ };
4760
+ /**
4761
+ * 移除 tabBar 某一项右上角的文本
4762
+ */
4763
+ const removeTabBarBadge = (options) => {
4764
+ // options must be an Object
4765
+ const isObject = shouldBeObject(options);
4766
+ if (!isObject.flag) {
4767
+ const res = { errMsg: `removeTabBarBadge:fail ${isObject.msg}` };
4768
+ console.error(res.errMsg);
4769
+ return Promise.reject(res);
4733
4770
  }
4734
- if (typeof options.confirmText !== 'string') {
4771
+ const { index, success, fail, complete } = options;
4772
+ const handle = new MethodHandler({ name: 'removeTabBarBadge', success, fail, complete });
4773
+ if (typeof index !== 'number') {
4735
4774
  return handle.fail({
4736
4775
  errMsg: getParameterError({
4737
- para: 'confirmText',
4738
- correct: 'String',
4739
- wrong: options.confirmText
4776
+ para: 'index',
4777
+ correct: 'Number',
4778
+ wrong: index
4740
4779
  })
4741
4780
  });
4742
4781
  }
4743
- if (options.confirmText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
4744
- return handle.fail({
4745
- errMsg: 'confirmText length should not larger then 4 Chinese characters'
4782
+ return new Promise((resolve, reject) => {
4783
+ Taro.eventCenter.trigger('__taroRemoveTabBarBadge', {
4784
+ index,
4785
+ successHandler: (res = {}) => handle.success(res, resolve),
4786
+ errorHandler: (res = {}) => handle.fail(res, reject)
4746
4787
  });
4788
+ });
4789
+ };
4790
+ /**
4791
+ * 隐藏 tabBar 某一项的右上角的红点
4792
+ */
4793
+ const hideTabBarRedDot = (options) => {
4794
+ // options must be an Object
4795
+ const isObject = shouldBeObject(options);
4796
+ if (!isObject.flag) {
4797
+ const res = { errMsg: `hideTabBarRedDot:fail ${isObject.msg}` };
4798
+ console.error(res.errMsg);
4799
+ return Promise.reject(res);
4747
4800
  }
4748
- if (typeof options.cancelColor !== 'string') {
4801
+ const { index, success, fail, complete } = options;
4802
+ const handle = new MethodHandler({ name: 'hideTabBarRedDot', success, fail, complete });
4803
+ if (typeof index !== 'number') {
4749
4804
  return handle.fail({
4750
4805
  errMsg: getParameterError({
4751
- para: 'cancelColor',
4752
- correct: 'String',
4753
- wrong: options.cancelColor
4806
+ para: 'index',
4807
+ correct: 'Number',
4808
+ wrong: index
4754
4809
  })
4755
4810
  });
4756
4811
  }
4757
- if (typeof options.confirmColor !== 'string') {
4758
- return handle.fail({
4759
- errMsg: getParameterError({
4760
- para: 'confirmColor',
4761
- correct: 'String',
4762
- wrong: options.confirmColor
4763
- })
4812
+ return new Promise((resolve, reject) => {
4813
+ Taro.eventCenter.trigger('__taroHideTabBarRedDotHandler', {
4814
+ index,
4815
+ successHandler: (res = {}) => handle.success(res, resolve),
4816
+ errorHandler: (res = {}) => handle.fail(res, reject)
4764
4817
  });
4818
+ });
4819
+ };
4820
+ /**
4821
+ * 隐藏 tabBar
4822
+ */
4823
+ const hideTabBar = (options = {}) => {
4824
+ // options must be an Object
4825
+ const isObject = shouldBeObject(options);
4826
+ if (!isObject.flag) {
4827
+ const res = { errMsg: `hideTabBar:fail ${isObject.msg}` };
4828
+ console.error(res.errMsg);
4829
+ return Promise.reject(res);
4765
4830
  }
4766
- options.showCancel = !!options.showCancel;
4767
- let result = '';
4768
- if (!modal.el) {
4769
- result = yield modal.create(options);
4770
- }
4771
- else {
4772
- result = yield modal.show(options);
4773
- }
4774
- const res = { cancel: !1, confirm: !1 };
4775
- res[result] = !0;
4776
- return handle.success(res);
4777
- });
4778
- function hideModal() {
4779
- if (!modal.el)
4780
- return;
4781
- modal.hide();
4782
- }
4783
- const showActionSheet = (options = { itemList: [] }) => __awaiter(void 0, void 0, void 0, function* () {
4784
- init(document);
4785
- options = Object.assign({
4786
- itemColor: '#000000',
4787
- itemList: []
4788
- }, options);
4789
- const { success, fail, complete } = options;
4790
- const handle = new MethodHandler({ name: 'showActionSheet', success, fail, complete });
4791
- // list item String
4792
- if (!Array.isArray(options.itemList)) {
4831
+ const { animation, success, fail, complete } = options;
4832
+ const handle = new MethodHandler({ name: 'hideTabBar', success, fail, complete });
4833
+ if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
4793
4834
  return handle.fail({
4794
4835
  errMsg: getParameterError({
4795
- para: 'itemList',
4796
- correct: 'Array',
4797
- wrong: options.itemList
4836
+ para: 'animation',
4837
+ correct: 'Boolean',
4838
+ wrong: animation
4798
4839
  })
4799
4840
  });
4800
4841
  }
4801
- if (options.itemList.length < 1) {
4802
- return handle.fail({ errMsg: 'parameter error: parameter.itemList should have at least 1 item' });
4803
- }
4804
- if (options.itemList.length > 6) {
4805
- return handle.fail({ errMsg: 'parameter error: parameter.itemList should not be large than 6' });
4806
- }
4807
- for (let i = 0; i < options.itemList.length; i++) {
4808
- if (typeof options.itemList[i] !== 'string') {
4809
- return handle.fail({
4810
- errMsg: getParameterError({
4811
- para: `itemList[${i}]`,
4812
- correct: 'String',
4813
- wrong: options.itemList[i]
4814
- })
4815
- });
4816
- }
4817
- }
4818
- if (typeof options.itemColor !== 'string') {
4819
- return handle.fail({
4820
- errMsg: getParameterError({
4821
- para: 'itemColor',
4822
- correct: 'String',
4823
- wrong: options.itemColor
4824
- })
4842
+ return new Promise((resolve, reject) => {
4843
+ Taro.eventCenter.trigger('__taroHideTabBar', {
4844
+ animation,
4845
+ successHandler: (res = {}) => handle.success(res, resolve),
4846
+ errorHandler: (res = {}) => handle.fail(res, reject)
4825
4847
  });
4848
+ });
4849
+ };
4850
+
4851
+ const callbackManager = new CallbackManager();
4852
+ const resizeListener = () => {
4853
+ callbackManager.trigger({
4854
+ windowWidth: window.screen.width,
4855
+ windowHeight: window.screen.height
4856
+ });
4857
+ };
4858
+ /**
4859
+ * 设置窗口大小,该接口仅适用于 PC 平台,使用细则请参见指南
4860
+ */
4861
+ const setWindowSize = temporarilyNotSupport('setWindowSize');
4862
+ /**
4863
+ * 监听窗口尺寸变化事件
4864
+ */
4865
+ const onWindowResize = callback => {
4866
+ callbackManager.add(callback);
4867
+ if (callbackManager.count() === 1) {
4868
+ window.addEventListener('resize', resizeListener);
4826
4869
  }
4827
- let result = '';
4828
- if (!actionSheet.el) {
4829
- result = yield actionSheet.create(options);
4830
- }
4831
- else {
4832
- result = yield actionSheet.show(options);
4833
- }
4834
- if (typeof result === 'string') {
4835
- return handle.fail(({ errMsg: result }));
4836
- }
4837
- else {
4838
- return handle.success(({ tapIndex: result }));
4870
+ };
4871
+ /**
4872
+ * 取消监听窗口尺寸变化事件
4873
+ */
4874
+ const offWindowResize = callback => {
4875
+ callbackManager.remove(callback);
4876
+ if (callbackManager.count() === 0) {
4877
+ window.removeEventListener('resize', resizeListener);
4839
4878
  }
4840
- });
4841
- Taro.eventCenter.on('__taroRouterChange', () => {
4842
- hideToast();
4843
- hideLoading();
4844
- hideModal();
4845
- });
4846
- const enableAlertBeforeUnload = temporarilyNotSupport('enableAlertBeforeUnload');
4847
- const disableAlertBeforeUnload = temporarilyNotSupport('disableAlertBeforeUnload');
4879
+ };
4848
4880
 
4849
4881
  // Worker
4850
4882
  const createWorker = temporarilyNotSupport('createWorker');
@@ -5096,35 +5128,6 @@ const createSelectorQuery = () => {
5096
5128
  };
5097
5129
  const createIntersectionObserver = temporarilyNotSupport('createIntersectionObserver');
5098
5130
 
5099
- // AliPay
5100
- const getOpenUserInfo = temporarilyNotSupport('getOpenUserInfo');
5101
-
5102
- const setPageInfo = temporarilyNotSupport('setPageInfo');
5103
- // 百度小程序 AI 相关
5104
- const ocrIdCard = temporarilyNotSupport('ocrIdCard');
5105
- const ocrBankCard = temporarilyNotSupport('ocrBankCard');
5106
- const ocrDrivingLicense = temporarilyNotSupport('ocrDrivingLicense');
5107
- const ocrVehicleLicense = temporarilyNotSupport('ocrVehicleLicense');
5108
- const textReview = temporarilyNotSupport('textReview');
5109
- const textToAudio = temporarilyNotSupport('textToAudio');
5110
- const imageAudit = temporarilyNotSupport('imageAudit');
5111
- const advancedGeneralIdentify = temporarilyNotSupport('advancedGeneralIdentify');
5112
- const objectDetectIdentify = temporarilyNotSupport('objectDetectIdentify');
5113
- const carClassify = temporarilyNotSupport('carClassify');
5114
- const dishClassify = temporarilyNotSupport('dishClassify');
5115
- const logoClassify = temporarilyNotSupport('logoClassify');
5116
- const animalClassify = temporarilyNotSupport('animalClassify');
5117
- const plantClassify = temporarilyNotSupport('plantClassify');
5118
- // 用户信息
5119
- const getSwanId = temporarilyNotSupport('getSwanId');
5120
- // 百度收银台支付
5121
- const requestPolymerPayment = temporarilyNotSupport('requestPolymerPayment');
5122
- // 打开小程序
5123
- const navigateToSmartGameProgram = temporarilyNotSupport('navigateToSmartGameProgram');
5124
- const navigateToSmartProgram = temporarilyNotSupport('navigateToSmartProgram');
5125
- const navigateBackSmartProgram = temporarilyNotSupport('navigateBackSmartProgram');
5126
- const preloadSubPackage = temporarilyNotSupport('preloadSubPackage');
5127
-
5128
5131
  const { Behavior, getEnv, ENV_TYPE, Link, interceptors, getInitPxTransform, Current, options, eventCenter, Events, preload } = Taro;
5129
5132
  const taro = {
5130
5133
  // @ts-ignore