@tarojs/taro-h5 3.5.0-alpha.12 → 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.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
  */
@@ -3240,6 +3243,32 @@ const hideShareMenu = temporarilyNotSupport('hideShareMenu');
3240
3243
  const getShareInfo = temporarilyNotSupport('getShareInfo');
3241
3244
  const authPrivateMessage = temporarilyNotSupport('authPrivateMessage');
3242
3245
 
3246
+ const setPageInfo = temporarilyNotSupport('setPageInfo');
3247
+ // 百度小程序 AI 相关
3248
+ const ocrIdCard = temporarilyNotSupport('ocrIdCard');
3249
+ const ocrBankCard = temporarilyNotSupport('ocrBankCard');
3250
+ const ocrDrivingLicense = temporarilyNotSupport('ocrDrivingLicense');
3251
+ const ocrVehicleLicense = temporarilyNotSupport('ocrVehicleLicense');
3252
+ const textReview = temporarilyNotSupport('textReview');
3253
+ const textToAudio = temporarilyNotSupport('textToAudio');
3254
+ const imageAudit = temporarilyNotSupport('imageAudit');
3255
+ const advancedGeneralIdentify = temporarilyNotSupport('advancedGeneralIdentify');
3256
+ const objectDetectIdentify = temporarilyNotSupport('objectDetectIdentify');
3257
+ const carClassify = temporarilyNotSupport('carClassify');
3258
+ const dishClassify = temporarilyNotSupport('dishClassify');
3259
+ const logoClassify = temporarilyNotSupport('logoClassify');
3260
+ const animalClassify = temporarilyNotSupport('animalClassify');
3261
+ const plantClassify = temporarilyNotSupport('plantClassify');
3262
+ // 用户信息
3263
+ const getSwanId = temporarilyNotSupport('getSwanId');
3264
+ // 百度收银台支付
3265
+ const requestPolymerPayment = temporarilyNotSupport('requestPolymerPayment');
3266
+ // 打开小程序
3267
+ const navigateToSmartGameProgram = temporarilyNotSupport('navigateToSmartGameProgram');
3268
+ const navigateToSmartProgram = temporarilyNotSupport('navigateToSmartProgram');
3269
+ const navigateBackSmartProgram = temporarilyNotSupport('navigateBackSmartProgram');
3270
+ const preloadSubPackage = temporarilyNotSupport('preloadSubPackage');
3271
+
3243
3272
  /**
3244
3273
  * H5 下的 styleSheet 操作
3245
3274
  * @author leeenx
@@ -3587,468 +3616,370 @@ const loadFontFace = (options) => __awaiter(void 0, void 0, void 0, function* ()
3587
3616
  }
3588
3617
  });
3589
3618
 
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;
3619
+ const noop = function () { };
3620
+ class ActionSheet {
3621
+ constructor() {
3622
+ this.options = {
3623
+ itemList: [],
3624
+ itemColor: '#000000',
3625
+ success: noop,
3626
+ fail: noop,
3627
+ complete: noop
3628
+ };
3629
+ this.style = {
3630
+ maskStyle: {
3631
+ position: 'fixed',
3632
+ 'z-index': '1000',
3633
+ top: '0',
3634
+ right: '0',
3635
+ left: '0',
3636
+ bottom: '0',
3637
+ background: 'rgba(0,0,0,0.6)'
3638
+ },
3639
+ actionSheetStyle: {
3640
+ 'z-index': '4999',
3641
+ position: 'fixed',
3642
+ left: '0',
3643
+ bottom: '0',
3644
+ '-webkit-transform': 'translate(0, 100%)',
3645
+ transform: 'translate(0, 100%)',
3646
+ width: '100%',
3647
+ 'line-height': '1.6',
3648
+ background: '#EFEFF4',
3649
+ '-webkit-transition': '-webkit-transform .3s',
3650
+ transition: 'transform .3s'
3651
+ },
3652
+ menuStyle: {
3653
+ 'background-color': '#FCFCFD'
3654
+ },
3655
+ cellStyle: {
3656
+ position: 'relative',
3657
+ padding: '10px 0',
3658
+ 'text-align': 'center',
3659
+ 'font-size': '18px'
3660
+ },
3661
+ cancelStyle: {
3662
+ 'margin-top': '6px',
3663
+ padding: '10px 0',
3664
+ 'text-align': 'center',
3665
+ 'font-size': '18px',
3666
+ color: '#000000',
3667
+ 'background-color': '#FCFCFD'
3668
+ }
3669
+ };
3670
+ this.lastConfig = {};
3616
3671
  }
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)
3672
+ create(options = {}) {
3673
+ return new Promise((resolve) => {
3674
+ // style
3675
+ const { maskStyle, actionSheetStyle, menuStyle, cellStyle, cancelStyle } = this.style;
3676
+ // configuration
3677
+ const config = Object.assign(Object.assign({}, this.options), options);
3678
+ this.lastConfig = config;
3679
+ // wrapper
3680
+ this.el = document.createElement('div');
3681
+ this.el.className = 'taro__actionSheet';
3682
+ this.el.style.opacity = '0';
3683
+ this.el.style.transition = 'opacity 0.2s linear';
3684
+ // mask
3685
+ const mask = document.createElement('div');
3686
+ mask.setAttribute('style', inlineStyle(maskStyle));
3687
+ // actionSheet
3688
+ this.actionSheet = document.createElement('div');
3689
+ this.actionSheet.setAttribute('style', inlineStyle(actionSheetStyle));
3690
+ // menu
3691
+ this.menu = document.createElement('div');
3692
+ this.menu.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, menuStyle), { color: config.itemColor })));
3693
+ // cells
3694
+ this.cells = config.itemList.map((item, index) => {
3695
+ const cell = document.createElement('div');
3696
+ cell.className = 'taro-actionsheet__cell';
3697
+ cell.setAttribute('style', inlineStyle(cellStyle));
3698
+ cell.textContent = item;
3699
+ cell.dataset.tapIndex = `${index}`;
3700
+ cell.onclick = e => {
3701
+ this.hide();
3702
+ const target = e.currentTarget;
3703
+ const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
3704
+ resolve(index);
3705
+ };
3706
+ return cell;
3707
+ });
3708
+ // cancel
3709
+ this.cancel = document.createElement('div');
3710
+ this.cancel.setAttribute('style', inlineStyle(cancelStyle));
3711
+ this.cancel.textContent = '取消';
3712
+ // result
3713
+ this.cells.forEach(item => this.menu.appendChild(item));
3714
+ this.actionSheet.appendChild(this.menu);
3715
+ this.actionSheet.appendChild(this.cancel);
3716
+ this.el.appendChild(mask);
3717
+ this.el.appendChild(this.actionSheet);
3718
+ // callbacks
3719
+ const cb = () => {
3720
+ this.hide();
3721
+ resolve('cancel');
3722
+ };
3723
+ mask.onclick = cb;
3724
+ this.cancel.onclick = cb;
3725
+ // show immediately
3726
+ document.body.appendChild(this.el);
3727
+ setTimeout(() => {
3728
+ this.el.style.opacity = '1';
3729
+ setTransform(this.actionSheet, 'translate(0, 0)');
3730
+ }, 0);
3655
3731
  });
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
- };
3732
+ }
3733
+ show(options = {}) {
3734
+ return new Promise((resolve) => {
3735
+ const config = Object.assign(Object.assign({}, this.options), options);
3736
+ this.lastConfig = config;
3737
+ if (this.hideOpacityTimer)
3738
+ clearTimeout(this.hideOpacityTimer);
3739
+ if (this.hideDisplayTimer)
3740
+ clearTimeout(this.hideDisplayTimer);
3741
+ // itemColor
3742
+ if (config.itemColor)
3743
+ this.menu.style.color = config.itemColor;
3744
+ // cells
3745
+ const { cellStyle } = this.style;
3746
+ config.itemList.forEach((item, index) => {
3747
+ let cell;
3748
+ if (this.cells[index]) {
3749
+ // assign new content
3750
+ cell = this.cells[index];
3690
3751
  }
3691
3752
  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);
3753
+ // create new cell
3754
+ cell = document.createElement('div');
3755
+ cell.className = 'taro-actionsheet__cell';
3756
+ cell.setAttribute('style', inlineStyle(cellStyle));
3757
+ cell.dataset.tapIndex = `${index}`;
3758
+ this.cells.push(cell);
3759
+ this.menu.appendChild(cell);
3725
3760
  }
3726
- else {
3727
- return handle.success({}, resolve);
3761
+ cell.textContent = item;
3762
+ cell.onclick = e => {
3763
+ this.hide();
3764
+ const target = e.currentTarget;
3765
+ const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
3766
+ resolve(index);
3767
+ };
3768
+ });
3769
+ const cellsLen = this.cells.length;
3770
+ const itemListLen = config.itemList.length;
3771
+ if (cellsLen > itemListLen) {
3772
+ for (let i = itemListLen; i < cellsLen; i++) {
3773
+ this.menu.removeChild(this.cells[i]);
3728
3774
  }
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
- })
3775
+ this.cells.splice(itemListLen);
3776
+ }
3777
+ // show
3778
+ this.el.style.display = 'block';
3779
+ setTimeout(() => {
3780
+ this.el.style.opacity = '1';
3781
+ setTransform(this.actionSheet, 'translate(0, 0)');
3782
+ }, 0);
3767
3783
  });
3768
3784
  }
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);
3785
+ hide() {
3786
+ if (this.hideOpacityTimer)
3787
+ clearTimeout(this.hideOpacityTimer);
3788
+ if (this.hideDisplayTimer)
3789
+ clearTimeout(this.hideDisplayTimer);
3790
+ this.hideOpacityTimer = setTimeout(() => {
3791
+ this.el.style.opacity = '0';
3792
+ setTransform(this.actionSheet, 'translate(0, 100%)');
3793
+ this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
3794
+ }, 0);
3787
3795
  }
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);
3796
+ }
3797
+
3798
+ class Modal {
3799
+ constructor() {
3800
+ this.options = {
3801
+ title: '',
3802
+ content: '',
3803
+ showCancel: true,
3804
+ cancelText: '取消',
3805
+ cancelColor: '#000000',
3806
+ confirmText: '确定',
3807
+ confirmColor: '#3CC51F'
3808
+ };
3809
+ this.style = {
3810
+ maskStyle: {
3811
+ position: 'fixed',
3812
+ 'z-index': '1000',
3813
+ top: '0',
3814
+ right: '0',
3815
+ left: '0',
3816
+ bottom: '0',
3817
+ background: 'rgba(0,0,0,0.6)'
3818
+ },
3819
+ modalStyle: {
3820
+ 'z-index': '4999',
3821
+ position: 'fixed',
3822
+ top: '50%',
3823
+ left: '50%',
3824
+ transform: 'translate(-50%, -50%)',
3825
+ width: '80%',
3826
+ 'max-width': '300px',
3827
+ 'border-radius': '3px',
3828
+ 'text-align': 'center',
3829
+ 'line-height': '1.6',
3830
+ overflow: 'hidden',
3831
+ background: '#FFFFFF'
3832
+ },
3833
+ titleStyle: {
3834
+ padding: '20px 24px 9px',
3835
+ 'font-size': '18px'
3836
+ },
3837
+ textStyle: {
3838
+ padding: '0 24px 12px',
3839
+ 'min-height': '40px',
3840
+ 'font-size': '15px',
3841
+ 'line-height': '1.3',
3842
+ color: '#808080'
3843
+ },
3844
+ footStyle: {
3845
+ position: 'relative',
3846
+ 'line-height': '48px',
3847
+ 'font-size': '18px',
3848
+ display: 'flex'
3849
+ },
3850
+ btnStyle: {
3851
+ position: 'relative',
3852
+ '-webkit-box-flex': '1',
3853
+ '-webkit-flex': '1',
3854
+ flex: '1'
3855
+ }
3856
+ };
4002
3857
  }
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
- })
3858
+ create(options = {}) {
3859
+ return new Promise((resolve) => {
3860
+ // style
3861
+ const { maskStyle, modalStyle, titleStyle, textStyle, footStyle, btnStyle } = this.style;
3862
+ // configuration
3863
+ const config = Object.assign(Object.assign({}, this.options), options);
3864
+ // wrapper
3865
+ this.el = document.createElement('div');
3866
+ this.el.className = 'taro__modal';
3867
+ this.el.style.opacity = '0';
3868
+ this.el.style.transition = 'opacity 0.2s linear';
3869
+ // mask
3870
+ const mask = document.createElement('div');
3871
+ mask.className = 'taro-modal__mask';
3872
+ mask.setAttribute('style', inlineStyle(maskStyle));
3873
+ // modal
3874
+ const modal = document.createElement('div');
3875
+ modal.className = 'taro-modal__content';
3876
+ modal.setAttribute('style', inlineStyle(modalStyle));
3877
+ // title
3878
+ const titleCSS = config.title ? titleStyle : Object.assign(Object.assign({}, titleStyle), { display: 'none' });
3879
+ this.title = document.createElement('div');
3880
+ this.title.className = 'taro-modal__title';
3881
+ this.title.setAttribute('style', inlineStyle(titleCSS));
3882
+ this.title.textContent = config.title;
3883
+ // text
3884
+ const textCSS = config.title ? textStyle : Object.assign(Object.assign({}, textStyle), { padding: '40px 20px 26px', color: '#353535' });
3885
+ this.text = document.createElement('div');
3886
+ this.text.className = 'taro-modal__text';
3887
+ this.text.setAttribute('style', inlineStyle(textCSS));
3888
+ this.text.textContent = config.content;
3889
+ // foot
3890
+ const foot = document.createElement('div');
3891
+ foot.className = 'taro-modal__foot';
3892
+ foot.setAttribute('style', inlineStyle(footStyle));
3893
+ // cancel button
3894
+ const cancelCSS = Object.assign(Object.assign({}, btnStyle), { color: config.cancelColor, display: config.showCancel ? 'block' : 'none' });
3895
+ this.cancel = document.createElement('div');
3896
+ this.cancel.className = 'taro-model__btn taro-model__cancel';
3897
+ this.cancel.setAttribute('style', inlineStyle(cancelCSS));
3898
+ this.cancel.textContent = config.cancelText;
3899
+ this.cancel.onclick = () => {
3900
+ this.hide();
3901
+ resolve('cancel');
3902
+ };
3903
+ // confirm button
3904
+ this.confirm = document.createElement('div');
3905
+ this.confirm.className = 'taro-model__btn taro-model__confirm';
3906
+ this.confirm.setAttribute('style', inlineStyle(btnStyle));
3907
+ this.confirm.style.color = config.confirmColor;
3908
+ this.confirm.textContent = config.confirmText;
3909
+ this.confirm.onclick = () => {
3910
+ this.hide();
3911
+ resolve('confirm');
3912
+ };
3913
+ // result
3914
+ foot.appendChild(this.cancel);
3915
+ foot.appendChild(this.confirm);
3916
+ modal.appendChild(this.title);
3917
+ modal.appendChild(this.text);
3918
+ modal.appendChild(foot);
3919
+ this.el.appendChild(mask);
3920
+ this.el.appendChild(modal);
3921
+ // show immediately
3922
+ document.body.appendChild(this.el);
3923
+ setTimeout(() => { this.el.style.opacity = '1'; }, 0);
4012
3924
  });
4013
3925
  }
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)
3926
+ show(options = {}) {
3927
+ return new Promise((resolve) => {
3928
+ const config = Object.assign(Object.assign({}, this.options), options);
3929
+ if (this.hideOpacityTimer)
3930
+ clearTimeout(this.hideOpacityTimer);
3931
+ if (this.hideDisplayTimer)
3932
+ clearTimeout(this.hideDisplayTimer);
3933
+ // title & text
3934
+ const { textStyle } = this.style;
3935
+ if (config.title) {
3936
+ this.title.textContent = config.title;
3937
+ // none => block
3938
+ this.title.style.display = 'block';
3939
+ this.text.setAttribute('style', inlineStyle(textStyle));
3940
+ }
3941
+ else {
3942
+ // block => none
3943
+ this.title.style.display = 'none';
3944
+ const textCSS = Object.assign(Object.assign({}, textStyle), { padding: '40px 20px 26px', color: '#353535' });
3945
+ this.text.setAttribute('style', inlineStyle(textCSS));
3946
+ }
3947
+ this.text.textContent = config.content || '';
3948
+ // showCancel
3949
+ this.cancel.style.display = config.showCancel ? 'block' : 'none';
3950
+ // cancelText
3951
+ this.cancel.textContent = config.cancelText || '';
3952
+ // cancelColor
3953
+ this.cancel.style.color = config.cancelColor || '';
3954
+ // confirmText
3955
+ this.confirm.textContent = config.confirmText || '';
3956
+ // confirmColor
3957
+ this.confirm.style.color = config.confirmColor || '';
3958
+ // cbs
3959
+ this.cancel.onclick = () => {
3960
+ this.hide();
3961
+ resolve('cancel');
3962
+ };
3963
+ this.confirm.onclick = () => {
3964
+ this.hide();
3965
+ resolve('confirm');
3966
+ };
3967
+ // show
3968
+ this.el.style.display = 'block';
3969
+ setTimeout(() => { this.el.style.opacity = '1'; }, 0);
4019
3970
  });
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
3971
  }
4042
- };
4043
- /**
4044
- * 取消监听窗口尺寸变化事件
4045
- */
4046
- const offWindowResize = callback => {
4047
- callbackManager.remove(callback);
4048
- if (callbackManager.count() === 0) {
4049
- window.removeEventListener('resize', resizeListener);
3972
+ hide() {
3973
+ if (this.hideOpacityTimer)
3974
+ clearTimeout(this.hideOpacityTimer);
3975
+ if (this.hideDisplayTimer)
3976
+ clearTimeout(this.hideDisplayTimer);
3977
+ this.hideOpacityTimer = setTimeout(() => {
3978
+ this.el.style.opacity = '0';
3979
+ this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
3980
+ }, 0);
4050
3981
  }
4051
- };
3982
+ }
4052
3983
 
4053
3984
  class Toast {
4054
3985
  constructor() {
@@ -4219,632 +4150,730 @@ class Toast {
4219
4150
  }
4220
4151
  }
4221
4152
 
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
- };
4153
+ // 交互
4154
+ let status = 'default';
4155
+ // inject necessary style
4156
+ function init(doc) {
4157
+ if (status === 'ready')
4158
+ return;
4159
+ const taroStyle = doc.createElement('style');
4160
+ 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);}';
4161
+ doc.querySelector('head').appendChild(taroStyle);
4162
+ status = 'ready';
4163
+ }
4164
+ const toast = new Toast();
4165
+ const modal = new Modal();
4166
+ const actionSheet = new ActionSheet();
4167
+ const showToast = (options = { title: '' }) => {
4168
+ init(document);
4169
+ options = Object.assign({
4170
+ title: '',
4171
+ icon: 'success',
4172
+ image: '',
4173
+ duration: 1500,
4174
+ mask: false
4175
+ }, options);
4176
+ const { success, fail, complete } = options;
4177
+ const handle = new MethodHandler({ name: 'showToast', success, fail, complete });
4178
+ if (typeof options.title !== 'string') {
4179
+ return handle.fail({
4180
+ errMsg: getParameterError({
4181
+ para: 'title',
4182
+ correct: 'String',
4183
+ wrong: options.title
4184
+ })
4185
+ });
4281
4186
  }
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);
4187
+ if (typeof options.duration !== 'number') {
4188
+ return handle.fail({
4189
+ errMsg: getParameterError({
4190
+ para: 'duration',
4191
+ correct: 'Number',
4192
+ wrong: options.duration
4193
+ })
4194
+ });
4195
+ }
4196
+ if (options.image && typeof options.image !== 'string')
4197
+ options.image = '';
4198
+ options.mask = !!options.mask;
4199
+ let errMsg = '';
4200
+ if (!toast.el) {
4201
+ errMsg = toast.create(options, 'toast');
4202
+ }
4203
+ else {
4204
+ errMsg = toast.show(options, 'toast');
4205
+ }
4206
+ return handle.success({ errMsg });
4207
+ };
4208
+ const hideToast = ({ success, fail, complete } = {}) => {
4209
+ const handle = new MethodHandler({ name: 'hideToast', success, fail, complete });
4210
+ if (!toast.el)
4211
+ return handle.success();
4212
+ toast.hide(0, 'toast');
4213
+ return handle.success();
4214
+ };
4215
+ const showLoading = (options = { title: '' }) => {
4216
+ init(document);
4217
+ options = Object.assign({
4218
+ title: '',
4219
+ mask: false
4220
+ }, options);
4221
+ const { success, fail, complete } = options;
4222
+ const handle = new MethodHandler({ name: 'showLoading', success, fail, complete });
4223
+ const config = {
4224
+ icon: 'loading',
4225
+ image: '',
4226
+ duration: -1
4227
+ };
4228
+ options = Object.assign({}, options, config);
4229
+ if (typeof options.title !== 'string') {
4230
+ return handle.fail({
4231
+ errMsg: getParameterError({
4232
+ para: 'title',
4233
+ correct: 'String',
4234
+ wrong: options.title
4235
+ })
4236
+ });
4237
+ }
4238
+ options.mask = !!options.mask;
4239
+ let errMsg = '';
4240
+ if (!toast.el) {
4241
+ errMsg = toast.create(options, 'loading');
4242
+ }
4243
+ else {
4244
+ errMsg = toast.show(options, 'loading');
4245
+ }
4246
+ return handle.success({ errMsg });
4247
+ };
4248
+ const hideLoading = ({ success, fail, complete } = {}) => {
4249
+ const handle = new MethodHandler({ name: 'hideLoading', success, fail, complete });
4250
+ if (!toast.el)
4251
+ return handle.success();
4252
+ toast.hide(0, 'loading');
4253
+ return handle.success();
4254
+ };
4255
+ const showModal = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
4256
+ init(document);
4257
+ options = Object.assign({
4258
+ title: '',
4259
+ content: '',
4260
+ showCancel: true,
4261
+ cancelText: '取消',
4262
+ cancelColor: '#000000',
4263
+ confirmText: '确定',
4264
+ confirmColor: '#3CC51F'
4265
+ }, options);
4266
+ const { success, fail, complete } = options;
4267
+ const handle = new MethodHandler({ name: 'showModal', success, fail, complete });
4268
+ if (typeof options.title !== 'string') {
4269
+ return handle.fail({
4270
+ errMsg: getParameterError({
4271
+ para: 'title',
4272
+ correct: 'String',
4273
+ wrong: options.title
4274
+ })
4348
4275
  });
4349
4276
  }
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);
4277
+ if (typeof options.content !== 'string') {
4278
+ return handle.fail({
4279
+ errMsg: getParameterError({
4280
+ para: 'content',
4281
+ correct: 'String',
4282
+ wrong: options.content
4283
+ })
4394
4284
  });
4395
4285
  }
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);
4286
+ if (typeof options.cancelText !== 'string') {
4287
+ return handle.fail({
4288
+ errMsg: getParameterError({
4289
+ para: 'cancelText',
4290
+ correct: 'String',
4291
+ wrong: options.cancelText
4292
+ })
4293
+ });
4405
4294
  }
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 = {};
4295
+ if (options.cancelText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
4296
+ return handle.fail({
4297
+ errMsg: 'cancelText length should not larger then 4 Chinese characters'
4298
+ });
4460
4299
  }
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);
4300
+ if (typeof options.confirmText !== 'string') {
4301
+ return handle.fail({
4302
+ errMsg: getParameterError({
4303
+ para: 'confirmText',
4304
+ correct: 'String',
4305
+ wrong: options.confirmText
4306
+ })
4307
+ });
4308
+ }
4309
+ if (options.confirmText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
4310
+ return handle.fail({
4311
+ errMsg: 'confirmText length should not larger then 4 Chinese characters'
4312
+ });
4313
+ }
4314
+ if (typeof options.cancelColor !== 'string') {
4315
+ return handle.fail({
4316
+ errMsg: getParameterError({
4317
+ para: 'cancelColor',
4318
+ correct: 'String',
4319
+ wrong: options.cancelColor
4320
+ })
4321
+ });
4322
+ }
4323
+ if (typeof options.confirmColor !== 'string') {
4324
+ return handle.fail({
4325
+ errMsg: getParameterError({
4326
+ para: 'confirmColor',
4327
+ correct: 'String',
4328
+ wrong: options.confirmColor
4329
+ })
4330
+ });
4331
+ }
4332
+ options.showCancel = !!options.showCancel;
4333
+ let result = '';
4334
+ if (!modal.el) {
4335
+ result = yield modal.create(options);
4336
+ }
4337
+ else {
4338
+ result = yield modal.show(options);
4339
+ }
4340
+ const res = { cancel: !1, confirm: !1 };
4341
+ res[result] = !0;
4342
+ return handle.success(res);
4343
+ });
4344
+ function hideModal() {
4345
+ if (!modal.el)
4346
+ return;
4347
+ modal.hide();
4348
+ }
4349
+ const showActionSheet = (options = { itemList: [] }) => __awaiter(void 0, void 0, void 0, function* () {
4350
+ init(document);
4351
+ options = Object.assign({
4352
+ itemColor: '#000000',
4353
+ itemList: []
4354
+ }, options);
4355
+ const { success, fail, complete } = options;
4356
+ const handle = new MethodHandler({ name: 'showActionSheet', success, fail, complete });
4357
+ // list item String
4358
+ if (!Array.isArray(options.itemList)) {
4359
+ return handle.fail({
4360
+ errMsg: getParameterError({
4361
+ para: 'itemList',
4362
+ correct: 'Array',
4363
+ wrong: options.itemList
4364
+ })
4520
4365
  });
4521
4366
  }
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
- };
4367
+ if (options.itemList.length < 1) {
4368
+ return handle.fail({ errMsg: 'parameter error: parameter.itemList should have at least 1 item' });
4369
+ }
4370
+ if (options.itemList.length > 6) {
4371
+ return handle.fail({ errMsg: 'parameter error: parameter.itemList should not be large than 6' });
4372
+ }
4373
+ for (let i = 0; i < options.itemList.length; i++) {
4374
+ if (typeof options.itemList[i] !== 'string') {
4375
+ return handle.fail({
4376
+ errMsg: getParameterError({
4377
+ para: `itemList[${i}]`,
4378
+ correct: 'String',
4379
+ wrong: options.itemList[i]
4380
+ })
4557
4381
  });
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);
4382
+ }
4383
+ }
4384
+ if (typeof options.itemColor !== 'string') {
4385
+ return handle.fail({
4386
+ errMsg: getParameterError({
4387
+ para: 'itemColor',
4388
+ correct: 'String',
4389
+ wrong: options.itemColor
4390
+ })
4572
4391
  });
4573
4392
  }
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);
4393
+ let result = '';
4394
+ if (!actionSheet.el) {
4395
+ result = yield actionSheet.create(options);
4396
+ }
4397
+ else {
4398
+ result = yield actionSheet.show(options);
4399
+ }
4400
+ if (typeof result === 'string') {
4401
+ return handle.fail(({ errMsg: result }));
4402
+ }
4403
+ else {
4404
+ return handle.success(({ tapIndex: result }));
4405
+ }
4406
+ });
4407
+ Taro.eventCenter.on('__taroRouterChange', () => {
4408
+ hideToast();
4409
+ hideLoading();
4410
+ hideModal();
4411
+ });
4412
+ const enableAlertBeforeUnload = temporarilyNotSupport('enableAlertBeforeUnload');
4413
+ const disableAlertBeforeUnload = temporarilyNotSupport('disableAlertBeforeUnload');
4414
+
4415
+ // 菜单
4416
+ const getMenuButtonBoundingClientRect = temporarilyNotSupport('getMenuButtonBoundingClientRect');
4417
+
4418
+ // 导航栏
4419
+ const showNavigationBarLoading = temporarilyNotSupport('showNavigationBarLoading');
4420
+ function setNavigationBarTitle(options) {
4421
+ // options must be an Object
4422
+ const isObject = shouldBeObject(options);
4423
+ if (!isObject.flag) {
4424
+ const res = { errMsg: `setNavigationBarTitle:fail ${isObject.msg}` };
4425
+ console.error(res.errMsg);
4426
+ return Promise.reject(res);
4427
+ }
4428
+ const { title, success, fail, complete } = options;
4429
+ const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete });
4430
+ if (!title || typeof title !== 'string') {
4431
+ return handle.fail({
4432
+ errMsg: getParameterError({
4433
+ para: 'title',
4434
+ correct: 'String',
4435
+ wrong: title
4436
+ })
4437
+ });
4584
4438
  }
4439
+ if (document.title !== title) {
4440
+ document.title = title;
4441
+ }
4442
+ return handle.success();
4585
4443
  }
4444
+ /**
4445
+ * 设置页面导航条颜色
4446
+ */
4447
+ const setNavigationBarColor = (options) => {
4448
+ const { backgroundColor, success, fail, complete } = options;
4449
+ const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete });
4450
+ const meta = document.createElement('meta');
4451
+ meta.setAttribute('name', 'theme-color');
4452
+ meta.setAttribute('content', backgroundColor);
4453
+ document.head.appendChild(meta);
4454
+ return handle.success();
4455
+ };
4456
+ const hideNavigationBarLoading = temporarilyNotSupport('hideNavigationBarLoading');
4457
+ const hideHomeButton = temporarilyNotSupport('hideHomeButton');
4458
+
4459
+ /**
4460
+ * 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
4461
+ */
4462
+ const startPullDownRefresh = function ({ success, fail, complete } = {}) {
4463
+ const handle = new MethodHandler({ name: 'startPullDownRefresh', success, fail, complete });
4464
+ return new Promise((resolve, reject) => {
4465
+ Taro.eventCenter.trigger('__taroStartPullDownRefresh', {
4466
+ successHandler: (res = {}) => handle.success(res, resolve),
4467
+ errorHandler: (res = {}) => handle.fail(res, reject)
4468
+ });
4469
+ });
4470
+ };
4471
+ /**
4472
+ * 停止当前页面下拉刷新。
4473
+ */
4474
+ const stopPullDownRefresh = function ({ success, fail, complete } = {}) {
4475
+ const handle = new MethodHandler({ name: 'stopPullDownRefresh', success, fail, complete });
4476
+ return new Promise((resolve, reject) => {
4477
+ Taro.eventCenter.trigger('__taroStopPullDownRefresh', {
4478
+ successHandler: (res = {}) => handle.success(res, resolve),
4479
+ errorHandler: (res = {}) => handle.fail(res, reject)
4480
+ });
4481
+ });
4482
+ };
4483
+
4484
+ let timer;
4485
+ const FRAME_DURATION = 17;
4486
+ /**
4487
+ * 将页面滚动到目标位置
4488
+ */
4489
+ const pageScrollTo = ({ scrollTop, selector = '', duration = 300, success, fail, complete }) => {
4490
+ let scrollFunc;
4491
+ const handle = new MethodHandler({ name: 'pageScrollTo', success, fail, complete });
4492
+ return new Promise((resolve, reject) => {
4493
+ var _a, _b;
4494
+ try {
4495
+ if (scrollTop === undefined && !selector) {
4496
+ return handle.fail({
4497
+ errMsg: 'scrollTop" 或 "selector" 需要其之一'
4498
+ }, reject);
4499
+ }
4500
+ 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');
4501
+ const el = (id
4502
+ ? document.querySelector(`.taro_page#${id}`)
4503
+ : document.querySelector('.taro_page') ||
4504
+ document.querySelector('.taro_router'));
4505
+ if (!scrollFunc) {
4506
+ if (!el) {
4507
+ scrollFunc = pos => {
4508
+ if (pos === undefined) {
4509
+ return window.pageYOffset;
4510
+ }
4511
+ else {
4512
+ window.scrollTo(0, pos);
4513
+ }
4514
+ };
4515
+ }
4516
+ else {
4517
+ scrollFunc = pos => {
4518
+ if (pos === undefined) {
4519
+ return el.scrollTop;
4520
+ }
4521
+ else {
4522
+ el.scrollTop = pos;
4523
+ }
4524
+ };
4525
+ }
4526
+ }
4527
+ if (scrollTop && selector) {
4528
+ console.warn('"scrollTop" 或 "selector" 建议只设一个值,全部设置会忽略selector');
4529
+ }
4530
+ const from = scrollFunc();
4531
+ let to;
4532
+ if (typeof scrollTop === 'number') {
4533
+ to = scrollTop;
4534
+ }
4535
+ else {
4536
+ const el = document.querySelector(selector);
4537
+ to = (el === null || el === void 0 ? void 0 : el.offsetTop) || 0;
4538
+ }
4539
+ const delta = to - from;
4540
+ const frameCnt = duration / FRAME_DURATION;
4541
+ const easeFunc = getTimingFunc(easeInOut, frameCnt);
4542
+ const scroll = (frame = 0) => {
4543
+ const dest = from + delta * easeFunc(frame);
4544
+ scrollFunc(dest);
4545
+ if (frame < frameCnt) {
4546
+ timer && clearTimeout(timer);
4547
+ timer = setTimeout(() => {
4548
+ scroll(frame + 1);
4549
+ }, FRAME_DURATION);
4550
+ }
4551
+ else {
4552
+ return handle.success({}, resolve);
4553
+ }
4554
+ };
4555
+ scroll();
4556
+ }
4557
+ catch (e) {
4558
+ return handle.fail({
4559
+ errMsg: e.message
4560
+ }, reject);
4561
+ }
4562
+ });
4563
+ };
4586
4564
 
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';
4565
+ // 置顶
4566
+ const setTopBarText = temporarilyNotSupport('setTopBarText');
4567
+
4568
+ let tabConf;
4569
+ function initTabBarApis(config = {}) {
4570
+ tabConf = config.tabBar;
4597
4571
  }
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
- });
4572
+ /**
4573
+ * 显示 tabBar 某一项的右上角的红点
4574
+ */
4575
+ const showTabBarRedDot = (options) => {
4576
+ // options must be an Object
4577
+ const isObject = shouldBeObject(options);
4578
+ if (!isObject.flag) {
4579
+ const res = { errMsg: `showTabBarRedDot:fail ${isObject.msg}` };
4580
+ console.error(res.errMsg);
4581
+ return Promise.reject(res);
4620
4582
  }
4621
- if (typeof options.duration !== 'number') {
4583
+ const { index, success, fail, complete } = options;
4584
+ const handle = new MethodHandler({ name: 'showTabBarRedDot', success, fail, complete });
4585
+ if (typeof index !== 'number') {
4622
4586
  return handle.fail({
4623
4587
  errMsg: getParameterError({
4624
- para: 'duration',
4588
+ para: 'index',
4625
4589
  correct: 'Number',
4626
- wrong: options.duration
4590
+ wrong: index
4627
4591
  })
4628
4592
  });
4629
4593
  }
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();
4594
+ return new Promise((resolve, reject) => {
4595
+ Taro.eventCenter.trigger('__taroShowTabBarRedDotHandler', {
4596
+ index,
4597
+ successHandler: (res = {}) => handle.success(res, resolve),
4598
+ errorHandler: (res = {}) => handle.fail(res, reject)
4599
+ });
4600
+ });
4648
4601
  };
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') {
4602
+ /**
4603
+ * 显示 tabBar
4604
+ */
4605
+ const showTabBar = (options = {}) => {
4606
+ // options must be an Object
4607
+ const isObject = shouldBeObject(options);
4608
+ if (!isObject.flag) {
4609
+ const res = { errMsg: `showTabBar:fail ${isObject.msg}` };
4610
+ console.error(res.errMsg);
4611
+ return Promise.reject(res);
4612
+ }
4613
+ const { animation, success, fail, complete } = options;
4614
+ const handle = new MethodHandler({ name: 'showTabBar', success, fail, complete });
4615
+ if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
4664
4616
  return handle.fail({
4665
4617
  errMsg: getParameterError({
4666
- para: 'title',
4667
- correct: 'String',
4668
- wrong: options.title
4618
+ para: 'animation',
4619
+ correct: 'Boolean',
4620
+ wrong: animation
4669
4621
  })
4670
4622
  });
4671
4623
  }
4672
- options.mask = !!options.mask;
4673
- let errMsg = '';
4674
- if (!toast.el) {
4675
- errMsg = toast.create(options, 'loading');
4624
+ return new Promise((resolve, reject) => {
4625
+ Taro.eventCenter.trigger('__taroShowTabBar', {
4626
+ animation,
4627
+ successHandler: (res = {}) => handle.success(res, resolve),
4628
+ errorHandler: (res = {}) => handle.fail(res, reject)
4629
+ });
4630
+ });
4631
+ };
4632
+ /**
4633
+ * 动态设置 tabBar 的整体样式
4634
+ */
4635
+ const setTabBarStyle = (options = {}) => {
4636
+ // options must be an Object
4637
+ const isObject = shouldBeObject(options);
4638
+ if (!isObject.flag) {
4639
+ const res = { errMsg: `setTabBarStyle:fail ${isObject.msg}` };
4640
+ console.error(res.errMsg);
4641
+ return Promise.reject(res);
4676
4642
  }
4677
- else {
4678
- errMsg = toast.show(options, 'loading');
4643
+ const { color, selectedColor, backgroundColor, borderStyle, success, fail, complete } = options;
4644
+ const handle = new MethodHandler({ name: 'setTabBarStyle', success, fail, complete });
4645
+ let errMsg;
4646
+ if (color && !isValidColor(color)) {
4647
+ errMsg = 'color';
4679
4648
  }
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();
4649
+ else if (selectedColor && !isValidColor(selectedColor)) {
4650
+ errMsg = 'selectedColor';
4651
+ }
4652
+ else if (backgroundColor && !isValidColor(backgroundColor)) {
4653
+ errMsg = 'backgroundColor';
4654
+ }
4655
+ else if (borderStyle && !/^(black|white)$/.test(borderStyle)) {
4656
+ errMsg = 'borderStyle';
4657
+ }
4658
+ if (errMsg) {
4659
+ return handle.fail({ errMsg: `invalid ${errMsg}` });
4660
+ }
4661
+ if (!tabConf) {
4662
+ return handle.fail();
4663
+ }
4664
+ const obj = {};
4665
+ if (color)
4666
+ obj.color = color;
4667
+ if (selectedColor)
4668
+ obj.selectedColor = selectedColor;
4669
+ if (backgroundColor)
4670
+ obj.backgroundColor = backgroundColor;
4671
+ if (borderStyle)
4672
+ obj.borderStyle = borderStyle;
4673
+ return new Promise((resolve, reject) => {
4674
+ Taro.eventCenter.trigger('__taroSetTabBarStyle', {
4675
+ color,
4676
+ selectedColor,
4677
+ backgroundColor,
4678
+ borderStyle,
4679
+ successHandler: (res = {}) => handle.success(res, resolve),
4680
+ errorHandler: (res = {}) => handle.fail(res, reject)
4681
+ });
4682
+ });
4688
4683
  };
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') {
4684
+ /**
4685
+ * 动态设置 tabBar 某一项的内容
4686
+ */
4687
+ const setTabBarItem = (options) => {
4688
+ // options must be an Object
4689
+ const isObject = shouldBeObject(options);
4690
+ if (!isObject.flag) {
4691
+ const res = { errMsg: `setTabBarItem:fail ${isObject.msg}` };
4692
+ console.error(res.errMsg);
4693
+ return Promise.reject(res);
4694
+ }
4695
+ const { index, text, iconPath, selectedIconPath, success, fail, complete } = options;
4696
+ const handle = new MethodHandler({ name: 'setTabBarItem', success, fail, complete });
4697
+ if (typeof index !== 'number') {
4703
4698
  return handle.fail({
4704
4699
  errMsg: getParameterError({
4705
- para: 'title',
4706
- correct: 'String',
4707
- wrong: options.title
4700
+ para: 'index',
4701
+ correct: 'Number',
4702
+ wrong: index
4708
4703
  })
4709
4704
  });
4710
4705
  }
4711
- if (typeof options.content !== 'string') {
4706
+ return new Promise((resolve, reject) => {
4707
+ Taro.eventCenter.trigger('__taroSetTabBarItem', {
4708
+ index,
4709
+ text,
4710
+ iconPath,
4711
+ selectedIconPath,
4712
+ successHandler: (res = {}) => handle.success(res, resolve),
4713
+ errorHandler: (res = {}) => handle.fail(res, reject)
4714
+ });
4715
+ });
4716
+ };
4717
+ /**
4718
+ * 为 tabBar 某一项的右上角添加文本
4719
+ */
4720
+ const setTabBarBadge = (options) => {
4721
+ // options must be an Object
4722
+ const isObject = shouldBeObject(options);
4723
+ if (!isObject.flag) {
4724
+ const res = { errMsg: `setTabBarBadge:fail ${isObject.msg}` };
4725
+ console.error(res.errMsg);
4726
+ return Promise.reject(res);
4727
+ }
4728
+ const { index, text, success, fail, complete } = options;
4729
+ const handle = new MethodHandler({ name: 'setTabBarBadge', success, fail, complete });
4730
+ if (typeof index !== 'number') {
4712
4731
  return handle.fail({
4713
4732
  errMsg: getParameterError({
4714
- para: 'content',
4715
- correct: 'String',
4716
- wrong: options.content
4733
+ para: 'index',
4734
+ correct: 'Number',
4735
+ wrong: index
4717
4736
  })
4718
4737
  });
4719
4738
  }
4720
- if (typeof options.cancelText !== 'string') {
4739
+ if (typeof text !== 'string') {
4721
4740
  return handle.fail({
4722
4741
  errMsg: getParameterError({
4723
- para: 'cancelText',
4742
+ para: 'text',
4724
4743
  correct: 'String',
4725
- wrong: options.cancelText
4744
+ wrong: text
4726
4745
  })
4727
4746
  });
4728
4747
  }
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'
4748
+ return new Promise((resolve, reject) => {
4749
+ Taro.eventCenter.trigger('__taroSetTabBarBadge', {
4750
+ index,
4751
+ text,
4752
+ successHandler: (res = {}) => handle.success(res, resolve),
4753
+ errorHandler: (res = {}) => handle.fail(res, reject)
4732
4754
  });
4755
+ });
4756
+ };
4757
+ /**
4758
+ * 移除 tabBar 某一项右上角的文本
4759
+ */
4760
+ const removeTabBarBadge = (options) => {
4761
+ // options must be an Object
4762
+ const isObject = shouldBeObject(options);
4763
+ if (!isObject.flag) {
4764
+ const res = { errMsg: `removeTabBarBadge:fail ${isObject.msg}` };
4765
+ console.error(res.errMsg);
4766
+ return Promise.reject(res);
4733
4767
  }
4734
- if (typeof options.confirmText !== 'string') {
4768
+ const { index, success, fail, complete } = options;
4769
+ const handle = new MethodHandler({ name: 'removeTabBarBadge', success, fail, complete });
4770
+ if (typeof index !== 'number') {
4735
4771
  return handle.fail({
4736
4772
  errMsg: getParameterError({
4737
- para: 'confirmText',
4738
- correct: 'String',
4739
- wrong: options.confirmText
4773
+ para: 'index',
4774
+ correct: 'Number',
4775
+ wrong: index
4740
4776
  })
4741
4777
  });
4742
4778
  }
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'
4779
+ return new Promise((resolve, reject) => {
4780
+ Taro.eventCenter.trigger('__taroRemoveTabBarBadge', {
4781
+ index,
4782
+ successHandler: (res = {}) => handle.success(res, resolve),
4783
+ errorHandler: (res = {}) => handle.fail(res, reject)
4746
4784
  });
4785
+ });
4786
+ };
4787
+ /**
4788
+ * 隐藏 tabBar 某一项的右上角的红点
4789
+ */
4790
+ const hideTabBarRedDot = (options) => {
4791
+ // options must be an Object
4792
+ const isObject = shouldBeObject(options);
4793
+ if (!isObject.flag) {
4794
+ const res = { errMsg: `hideTabBarRedDot:fail ${isObject.msg}` };
4795
+ console.error(res.errMsg);
4796
+ return Promise.reject(res);
4747
4797
  }
4748
- if (typeof options.cancelColor !== 'string') {
4798
+ const { index, success, fail, complete } = options;
4799
+ const handle = new MethodHandler({ name: 'hideTabBarRedDot', success, fail, complete });
4800
+ if (typeof index !== 'number') {
4749
4801
  return handle.fail({
4750
4802
  errMsg: getParameterError({
4751
- para: 'cancelColor',
4752
- correct: 'String',
4753
- wrong: options.cancelColor
4803
+ para: 'index',
4804
+ correct: 'Number',
4805
+ wrong: index
4754
4806
  })
4755
4807
  });
4756
4808
  }
4757
- if (typeof options.confirmColor !== 'string') {
4758
- return handle.fail({
4759
- errMsg: getParameterError({
4760
- para: 'confirmColor',
4761
- correct: 'String',
4762
- wrong: options.confirmColor
4763
- })
4809
+ return new Promise((resolve, reject) => {
4810
+ Taro.eventCenter.trigger('__taroHideTabBarRedDotHandler', {
4811
+ index,
4812
+ successHandler: (res = {}) => handle.success(res, resolve),
4813
+ errorHandler: (res = {}) => handle.fail(res, reject)
4764
4814
  });
4815
+ });
4816
+ };
4817
+ /**
4818
+ * 隐藏 tabBar
4819
+ */
4820
+ const hideTabBar = (options = {}) => {
4821
+ // options must be an Object
4822
+ const isObject = shouldBeObject(options);
4823
+ if (!isObject.flag) {
4824
+ const res = { errMsg: `hideTabBar:fail ${isObject.msg}` };
4825
+ console.error(res.errMsg);
4826
+ return Promise.reject(res);
4765
4827
  }
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)) {
4828
+ const { animation, success, fail, complete } = options;
4829
+ const handle = new MethodHandler({ name: 'hideTabBar', success, fail, complete });
4830
+ if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
4793
4831
  return handle.fail({
4794
4832
  errMsg: getParameterError({
4795
- para: 'itemList',
4796
- correct: 'Array',
4797
- wrong: options.itemList
4833
+ para: 'animation',
4834
+ correct: 'Boolean',
4835
+ wrong: animation
4798
4836
  })
4799
4837
  });
4800
4838
  }
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
- })
4839
+ return new Promise((resolve, reject) => {
4840
+ Taro.eventCenter.trigger('__taroHideTabBar', {
4841
+ animation,
4842
+ successHandler: (res = {}) => handle.success(res, resolve),
4843
+ errorHandler: (res = {}) => handle.fail(res, reject)
4825
4844
  });
4845
+ });
4846
+ };
4847
+
4848
+ const callbackManager = new CallbackManager();
4849
+ const resizeListener = () => {
4850
+ callbackManager.trigger({
4851
+ windowWidth: window.screen.width,
4852
+ windowHeight: window.screen.height
4853
+ });
4854
+ };
4855
+ /**
4856
+ * 设置窗口大小,该接口仅适用于 PC 平台,使用细则请参见指南
4857
+ */
4858
+ const setWindowSize = temporarilyNotSupport('setWindowSize');
4859
+ /**
4860
+ * 监听窗口尺寸变化事件
4861
+ */
4862
+ const onWindowResize = callback => {
4863
+ callbackManager.add(callback);
4864
+ if (callbackManager.count() === 1) {
4865
+ window.addEventListener('resize', resizeListener);
4826
4866
  }
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 }));
4867
+ };
4868
+ /**
4869
+ * 取消监听窗口尺寸变化事件
4870
+ */
4871
+ const offWindowResize = callback => {
4872
+ callbackManager.remove(callback);
4873
+ if (callbackManager.count() === 0) {
4874
+ window.removeEventListener('resize', resizeListener);
4839
4875
  }
4840
- });
4841
- Taro.eventCenter.on('__taroRouterChange', () => {
4842
- hideToast();
4843
- hideLoading();
4844
- hideModal();
4845
- });
4846
- const enableAlertBeforeUnload = temporarilyNotSupport('enableAlertBeforeUnload');
4847
- const disableAlertBeforeUnload = temporarilyNotSupport('disableAlertBeforeUnload');
4876
+ };
4848
4877
 
4849
4878
  // Worker
4850
4879
  const createWorker = temporarilyNotSupport('createWorker');
@@ -5096,35 +5125,6 @@ const createSelectorQuery = () => {
5096
5125
  };
5097
5126
  const createIntersectionObserver = temporarilyNotSupport('createIntersectionObserver');
5098
5127
 
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
5128
  const { Behavior, getEnv, ENV_TYPE, Link, interceptors, getInitPxTransform, Current, options, eventCenter, Events, preload } = Taro;
5129
5129
  const taro = {
5130
5130
  // @ts-ignore