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