@tarojs/taro-h5 3.5.0-alpha.10 → 3.5.0-alpha.13

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