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

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