@tarojs/plugin-platform-harmony-ets 3.7.0-alpha.27
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/LICENSE +160 -0
- package/dist/apis/apis.ts +15 -0
- package/dist/apis/base/index.ts +5 -0
- package/dist/apis/base/system.ts +77 -0
- package/dist/apis/device/accelerometer.ts +76 -0
- package/dist/apis/device/battery.ts +24 -0
- package/dist/apis/device/clipboard.ts +70 -0
- package/dist/apis/device/index.ts +9 -0
- package/dist/apis/device/keyboard.ts +62 -0
- package/dist/apis/device/memory.ts +4 -0
- package/dist/apis/device/network.ts +72 -0
- package/dist/apis/device/phone.ts +43 -0
- package/dist/apis/device/screen.ts +79 -0
- package/dist/apis/device/vibrate.ts +24 -0
- package/dist/apis/files/index.ts +135 -0
- package/dist/apis/files/manager.ts +941 -0
- package/dist/apis/framework/index.ts +32 -0
- package/dist/apis/index.ts +124 -0
- package/dist/apis/location/index.ts +133 -0
- package/dist/apis/media/common.ts +74 -0
- package/dist/apis/media/image.ts +122 -0
- package/dist/apis/media/index.ts +3 -0
- package/dist/apis/media/video.ts +86 -0
- package/dist/apis/navigate/index.ts +8 -0
- package/dist/apis/network/downloadFile.ts +113 -0
- package/dist/apis/network/index.ts +4 -0
- package/dist/apis/network/request.ts +113 -0
- package/dist/apis/network/uploadFile.ts +158 -0
- package/dist/apis/network/webSocket.ts +130 -0
- package/dist/apis/open-api/index.ts +7 -0
- package/dist/apis/open-api/user-info/index.ts +85 -0
- package/dist/apis/page/index.ts +92 -0
- package/dist/apis/route/index.ts +138 -0
- package/dist/apis/storage/index.ts +133 -0
- package/dist/apis/tabbar/index.ts +147 -0
- package/dist/apis/ui/animation.ts +222 -0
- package/dist/apis/ui/background.ts +35 -0
- package/dist/apis/ui/index.ts +14 -0
- package/dist/apis/ui/interaction/index.ts +195 -0
- package/dist/apis/ui/navigation-bar/index.ts +33 -0
- package/dist/apis/ui/pull-down-refresh.ts +41 -0
- package/dist/apis/utils/handler.ts +116 -0
- package/dist/apis/utils/index.ts +85 -0
- package/dist/apis/utils/types.ts +12 -0
- package/dist/apis/utils/validate.ts +87 -0
- package/dist/apis/wxml/IntersectionObserver.ts +119 -0
- package/dist/apis/wxml/index.ts +12 -0
- package/dist/apis/wxml/nodesRef.ts +56 -0
- package/dist/apis/wxml/selectorQuery.ts +287 -0
- package/dist/components/components-react.js +51 -0
- package/dist/components/components-react.js.map +1 -0
- package/dist/components-harmony/button/index.css +109 -0
- package/dist/components-harmony/button/index.hml +31 -0
- package/dist/components-harmony/button/index.js +105 -0
- package/dist/components-harmony/camera/index.hml +6 -0
- package/dist/components-harmony/camera/index.js +12 -0
- package/dist/components-harmony/checkbox/index.hml +11 -0
- package/dist/components-harmony/checkbox/index.js +60 -0
- package/dist/components-harmony/checkbox-group/index.hml +3 -0
- package/dist/components-harmony/checkbox-group/index.js +22 -0
- package/dist/components-harmony/cover-image/index.css +4 -0
- package/dist/components-harmony/cover-image/index.hml +9 -0
- package/dist/components-harmony/cover-image/index.js +15 -0
- package/dist/components-harmony/form/index.hml +10 -0
- package/dist/components-harmony/form/index.js +11 -0
- package/dist/components-harmony/icon/index.css +27 -0
- package/dist/components-harmony/icon/index.hml +54 -0
- package/dist/components-harmony/icon/index.js +17 -0
- package/dist/components-harmony/image/index.css +5 -0
- package/dist/components-harmony/image/index.hml +11 -0
- package/dist/components-harmony/image/index.js +28 -0
- package/dist/components-harmony/input/index.hml +21 -0
- package/dist/components-harmony/input/index.js +98 -0
- package/dist/components-harmony/label/index.hml +3 -0
- package/dist/components-harmony/label/index.js +6 -0
- package/dist/components-harmony/navbar/index.css +56 -0
- package/dist/components-harmony/navbar/index.hml +9 -0
- package/dist/components-harmony/navbar/index.js +30 -0
- package/dist/components-harmony/navigator/index.css +8 -0
- package/dist/components-harmony/navigator/index.hml +9 -0
- package/dist/components-harmony/navigator/index.js +104 -0
- package/dist/components-harmony/picker/index.hml +25 -0
- package/dist/components-harmony/picker/index.js +132 -0
- package/dist/components-harmony/picker-view/index.hml +23 -0
- package/dist/components-harmony/picker-view/index.js +161 -0
- package/dist/components-harmony/picker-view-column/index.hml +3 -0
- package/dist/components-harmony/picker-view-column/index.js +3 -0
- package/dist/components-harmony/progress/index.css +4 -0
- package/dist/components-harmony/progress/index.hml +28 -0
- package/dist/components-harmony/progress/index.js +23 -0
- package/dist/components-harmony/radio/index.hml +11 -0
- package/dist/components-harmony/radio/index.js +41 -0
- package/dist/components-harmony/radio-group/index.hml +3 -0
- package/dist/components-harmony/radio-group/index.js +11 -0
- package/dist/components-harmony/rich-text/index.hml +5 -0
- package/dist/components-harmony/rich-text/index.js +16 -0
- package/dist/components-harmony/scroll-view/index.css +5 -0
- package/dist/components-harmony/scroll-view/index.hml +12 -0
- package/dist/components-harmony/scroll-view/index.js +65 -0
- package/dist/components-harmony/slider/index.hml +16 -0
- package/dist/components-harmony/slider/index.js +53 -0
- package/dist/components-harmony/swiper/index.css +3 -0
- package/dist/components-harmony/swiper/index.hml +14 -0
- package/dist/components-harmony/swiper/index.js +19 -0
- package/dist/components-harmony/switch/index.hml +7 -0
- package/dist/components-harmony/switch/index.js +16 -0
- package/dist/components-harmony/tabbar/index.css +7 -0
- package/dist/components-harmony/tabbar/index.hml +26 -0
- package/dist/components-harmony/tabbar/index.js +42 -0
- package/dist/components-harmony/textarea/index.hml +24 -0
- package/dist/components-harmony/textarea/index.js +92 -0
- package/dist/components-harmony/utils/index.js +41 -0
- package/dist/components-harmony/video/index.hml +7 -0
- package/dist/components-harmony/video/index.js +73 -0
- package/dist/components-harmony/web-view/index.hml +8 -0
- package/dist/components-harmony/web-view/index.js +22 -0
- package/dist/components-harmony-ets/base.ets +63 -0
- package/dist/components-harmony-ets/button.ets +119 -0
- package/dist/components-harmony-ets/checkbox.ets +219 -0
- package/dist/components-harmony-ets/element.ets +223 -0
- package/dist/components-harmony-ets/form.ets +149 -0
- package/dist/components-harmony-ets/icon.ets +84 -0
- package/dist/components-harmony-ets/image.ets +85 -0
- package/dist/components-harmony-ets/index.ts +49 -0
- package/dist/components-harmony-ets/innerHtml.ets +79 -0
- package/dist/components-harmony-ets/input.ets +195 -0
- package/dist/components-harmony-ets/label.ets +111 -0
- package/dist/components-harmony-ets/picker.ets +370 -0
- package/dist/components-harmony-ets/radio.ets +225 -0
- package/dist/components-harmony-ets/richText.ets +97 -0
- package/dist/components-harmony-ets/scrollView.ets +199 -0
- package/dist/components-harmony-ets/slider.ets +159 -0
- package/dist/components-harmony-ets/swiper.ets +204 -0
- package/dist/components-harmony-ets/switch.ets +113 -0
- package/dist/components-harmony-ets/text.ets +97 -0
- package/dist/components-harmony-ets/textArea.ets +169 -0
- package/dist/components-harmony-ets/utils/AttributeManager.ets +250 -0
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +48 -0
- package/dist/components-harmony-ets/utils/constant/event.ets +25 -0
- package/dist/components-harmony-ets/utils/constant/icon.ts +19 -0
- package/dist/components-harmony-ets/utils/constant/style.ets +88 -0
- package/dist/components-harmony-ets/utils/events.ts +24 -0
- package/dist/components-harmony-ets/utils/flexManager.ets +107 -0
- package/dist/components-harmony-ets/utils/helper.ets +99 -0
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +103 -0
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +56 -0
- package/dist/components-harmony-ets/utils/index.ts +83 -0
- package/dist/components-harmony-ets/utils/styles.ets +91 -0
- package/dist/components-harmony-ets/video.ets +161 -0
- package/dist/components-harmony-ets/view.ets +79 -0
- package/dist/index.js +1183 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime-ets/bom/document.ts +38 -0
- package/dist/runtime-ets/bom/getComputedStyle.ts +5 -0
- package/dist/runtime-ets/bom/navigator.ts +21 -0
- package/dist/runtime-ets/bom/raf.ts +37 -0
- package/dist/runtime-ets/bom/window.ts +44 -0
- package/dist/runtime-ets/constant.ts +29 -0
- package/dist/runtime-ets/current.ts +16 -0
- package/dist/runtime-ets/dom/class-list.ts +117 -0
- package/dist/runtime-ets/dom/comment.ts +10 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +105 -0
- package/dist/runtime-ets/dom/document.ts +108 -0
- package/dist/runtime-ets/dom/element.ts +457 -0
- package/dist/runtime-ets/dom/event.ts +164 -0
- package/dist/runtime-ets/dom/eventTarget.ts +98 -0
- package/dist/runtime-ets/dom/node.ts +215 -0
- package/dist/runtime-ets/dom/stylesheet/index.ts +687 -0
- package/dist/runtime-ets/dom/stylesheet/type.ts +136 -0
- package/dist/runtime-ets/dom/stylesheet/util.ts +134 -0
- package/dist/runtime-ets/dom/text.ts +19 -0
- package/dist/runtime-ets/index.ts +19 -0
- package/dist/runtime-ets/interface/event.ts +9 -0
- package/dist/runtime-ets/interface/index.ts +1 -0
- package/dist/runtime-ets/utils/bind.ts +35 -0
- package/dist/runtime-ets/utils/index.ts +135 -0
- package/dist/runtime-ets/utils/info.ts +128 -0
- package/dist/runtime-framework/react/app.ts +256 -0
- package/dist/runtime-framework/react/connect.ts +24 -0
- package/dist/runtime-framework/react/constant.ts +5 -0
- package/dist/runtime-framework/react/hooks.ts +101 -0
- package/dist/runtime-framework/react/index.ts +16 -0
- package/dist/runtime-framework/react/page.ts +263 -0
- package/dist/runtime-framework/react/utils/index.ts +25 -0
- package/dist/runtime-framework/react/utils/is.ts +46 -0
- package/dist/runtime-framework/solid/README.md +99 -0
- package/dist/runtime-framework/solid/app.ts +200 -0
- package/dist/runtime-framework/solid/connect.ts +11 -0
- package/dist/runtime-framework/solid/contant.ts +5 -0
- package/dist/runtime-framework/solid/hooks.ts +88 -0
- package/dist/runtime-framework/solid/index.ts +10 -0
- package/dist/runtime-framework/solid/page.ts +202 -0
- package/dist/runtime-framework/solid/reconciler/h.ts +132 -0
- package/dist/runtime-framework/solid/reconciler/index.ts +3 -0
- package/dist/runtime-framework/solid/reconciler/props.ts +151 -0
- package/dist/runtime-framework/solid/reconciler/render.ts +61 -0
- package/dist/runtime-framework/solid/reconciler/use.ts +8 -0
- package/dist/runtime-framework/solid/utils/index.ts +49 -0
- package/dist/runtime-framework/solid/utils/is.ts +46 -0
- package/dist/runtime-utils.js +4149 -0
- package/dist/runtime-utils.js.map +1 -0
- package/dist/runtime.js +4150 -0
- package/dist/runtime.js.map +1 -0
- package/dist/template/container.js +7 -0
- package/index.js +4 -0
- package/package.json +54 -0
- package/types/api.d.ts +4 -0
- package/types/component.d.ts +4 -0
- package/types/harmony.d.ts +11 -0
- package/types/runtime.d.ts +15 -0
- package/types/taro.d.ts +7 -0
- package/types/webpack-sources.d.ts +108 -0
|
@@ -0,0 +1,4149 @@
|
|
|
1
|
+
import { isFunction, isString, isArray, isObject, isNull, isNumber, isUndefined, queryToJson, PLATFORM_TYPE, singleQuote, internalComponents } from '@tarojs/shared';
|
|
2
|
+
import _display from '@ohos.display';
|
|
3
|
+
import { Current, window, getPageScrollerOrNode, findChildNodeWithDFS, setNodeEventCallbackAndTriggerComponentUpdate, AREA_CHANGE_EVENT_NAME, disconnectEvent, VISIBLE_CHANGE_EVENT_NAME, hooks } from '@tarojs/runtime';
|
|
4
|
+
import { eventCenter, Events, History } from '@tarojs/runtime/dist/runtime.esm';
|
|
5
|
+
import deviceInfo from '@ohos.deviceInfo';
|
|
6
|
+
import i18n from '@ohos.i18n';
|
|
7
|
+
import deviceMethod from '@system.device';
|
|
8
|
+
import sensor from '@ohos.sensor';
|
|
9
|
+
import batteryInfo, { BatteryChargeState } from '@ohos.batteryInfo';
|
|
10
|
+
import pasteboard from '@ohos.pasteboard';
|
|
11
|
+
import inputMethodEngine from '@ohos.inputMethodEngine';
|
|
12
|
+
import network from '@system.network';
|
|
13
|
+
import call from '@ohos.telephony.call';
|
|
14
|
+
import brightness from '@system.brightness';
|
|
15
|
+
import vibrator from '@ohos.vibrator';
|
|
16
|
+
import document from '@ohos.document';
|
|
17
|
+
import fileio from '@ohos.fileio';
|
|
18
|
+
import zlib from '@ohos.zlib';
|
|
19
|
+
import app from '@system.app';
|
|
20
|
+
import file from '@system.file';
|
|
21
|
+
import geoLocationManager from '@ohos.geoLocationManager';
|
|
22
|
+
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
|
|
23
|
+
import picker from '@ohos.file.picker';
|
|
24
|
+
import image from '@ohos.multimedia.image';
|
|
25
|
+
import request$1 from '@ohos.request';
|
|
26
|
+
import http from '@ohos.net.http';
|
|
27
|
+
import webSocket from '@ohos.net.webSocket';
|
|
28
|
+
import { pxTransformHelper } from '@tarojs/taro';
|
|
29
|
+
import router from '@ohos.router';
|
|
30
|
+
import bundleManager from '@ohos.bundle.bundleManager';
|
|
31
|
+
import dataPreferences from '@ohos.data.preferences';
|
|
32
|
+
import hilog from '@ohos.hilog';
|
|
33
|
+
import matrix4 from '@ohos.matrix4';
|
|
34
|
+
import prompt from '@ohos.prompt';
|
|
35
|
+
|
|
36
|
+
class MethodHandler {
|
|
37
|
+
constructor({ name, success, fail, complete }) {
|
|
38
|
+
this.isHandlerError = false;
|
|
39
|
+
this.methodName = name;
|
|
40
|
+
this.__success = success;
|
|
41
|
+
this.__fail = fail;
|
|
42
|
+
this.__complete = complete;
|
|
43
|
+
this.isHandlerError = isFunction(this.__complete) || isFunction(this.__fail);
|
|
44
|
+
}
|
|
45
|
+
success(res = {}, promise = {}) {
|
|
46
|
+
if (!res.errMsg) {
|
|
47
|
+
res.errMsg = `${this.methodName}:ok`;
|
|
48
|
+
}
|
|
49
|
+
isFunction(this.__success) && this.__success(res);
|
|
50
|
+
isFunction(this.__complete) && this.__complete(res);
|
|
51
|
+
const { resolve = Promise.resolve.bind(Promise) } = promise;
|
|
52
|
+
return resolve(res);
|
|
53
|
+
}
|
|
54
|
+
fail(res = {}, promise = {}) {
|
|
55
|
+
if (!res.errMsg) {
|
|
56
|
+
res.errMsg = `${this.methodName}:fail`;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
res.errMsg = `${this.methodName}:fail ${res.errMsg}`;
|
|
60
|
+
}
|
|
61
|
+
isFunction(this.__fail) && this.__fail(res);
|
|
62
|
+
isFunction(this.__complete) && this.__complete(res);
|
|
63
|
+
const { resolve = Promise.resolve.bind(Promise), reject = Promise.reject.bind(Promise) } = promise;
|
|
64
|
+
return this.isHandlerError
|
|
65
|
+
? resolve(res)
|
|
66
|
+
: reject(res);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
class CallbackManager {
|
|
70
|
+
constructor() {
|
|
71
|
+
this.callbacks = [];
|
|
72
|
+
/** 添加回调 */
|
|
73
|
+
this.add = (opt) => {
|
|
74
|
+
if (opt)
|
|
75
|
+
this.callbacks.push(opt);
|
|
76
|
+
};
|
|
77
|
+
/** 移除回调 */
|
|
78
|
+
this.remove = (opt) => {
|
|
79
|
+
if (opt) {
|
|
80
|
+
let pos = -1;
|
|
81
|
+
this.callbacks.forEach((callback, k) => {
|
|
82
|
+
if (callback === opt) {
|
|
83
|
+
pos = k;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
if (pos > -1) {
|
|
87
|
+
this.callbacks.splice(pos, 1);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
/** 获取回调函数数量 */
|
|
92
|
+
this.count = () => {
|
|
93
|
+
return this.callbacks.length;
|
|
94
|
+
};
|
|
95
|
+
/** 触发回调 */
|
|
96
|
+
this.trigger = (...args) => {
|
|
97
|
+
this.callbacks.forEach(opt => {
|
|
98
|
+
if (isFunction(opt)) {
|
|
99
|
+
opt(...args);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const { callback, ctx } = opt;
|
|
103
|
+
isFunction(callback) && callback.call(ctx, ...args);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function shouldBeObject(target) {
|
|
111
|
+
if (target && typeof target === 'object')
|
|
112
|
+
return { flag: true };
|
|
113
|
+
return {
|
|
114
|
+
flag: false,
|
|
115
|
+
msg: getParameterError({
|
|
116
|
+
correct: 'Object',
|
|
117
|
+
wrong: target
|
|
118
|
+
})
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function getParameterError({ name = '', para, correct, wrong, level = 'error' }) {
|
|
122
|
+
const parameter = para ? `parameter.${para}` : 'parameter';
|
|
123
|
+
const errorType = upperCaseFirstLetter(wrong === null ? 'Null' : typeof wrong);
|
|
124
|
+
return `${name ? `${name}:fail ` : ''}parameter ${level}: ${parameter} should be ${correct} instead of ${errorType}`;
|
|
125
|
+
}
|
|
126
|
+
function upperCaseFirstLetter(string) {
|
|
127
|
+
if (!isString(string))
|
|
128
|
+
return string;
|
|
129
|
+
string = string.replace(/^./, match => match.toUpperCase());
|
|
130
|
+
return string;
|
|
131
|
+
}
|
|
132
|
+
function getType(param) {
|
|
133
|
+
if (isNull(param)) {
|
|
134
|
+
return 'null';
|
|
135
|
+
}
|
|
136
|
+
else if (isArray(param)) {
|
|
137
|
+
return 'array';
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
return typeof param;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function assertType(target, type, methodName, paramName) {
|
|
144
|
+
const correct = upperCaseFirstLetter(type);
|
|
145
|
+
if (correct !== upperCaseFirstLetter(getType(target))) {
|
|
146
|
+
const err = getParameterError({ name: methodName, para: paramName, correct, wrong: target });
|
|
147
|
+
throw new Error(err);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 用于校验方法的参数类型
|
|
152
|
+
* @param name 方法名称
|
|
153
|
+
* @param params [array|object] 当前参数
|
|
154
|
+
* @param schema [array|object] 参数类型规范
|
|
155
|
+
* @example
|
|
156
|
+
* ```js
|
|
157
|
+
* // 例子一:
|
|
158
|
+
* validateParams(methodA, [key], [string])
|
|
159
|
+
* // 例子二:
|
|
160
|
+
* validateParams(methodB, { key: 123 }, { key: number })
|
|
161
|
+
* ```
|
|
162
|
+
* @todo 校验可选参数
|
|
163
|
+
*/
|
|
164
|
+
const validateParams = function (name, params, schema) {
|
|
165
|
+
if (isArray(schema) && isString(schema[0])) {
|
|
166
|
+
schema.forEach((correctType, index) => assertType(params[index], correctType, name, `[${index}]`));
|
|
167
|
+
}
|
|
168
|
+
else if (isObject(schema)) {
|
|
169
|
+
const optionsSchema = schema;
|
|
170
|
+
assertType(params, 'object', name);
|
|
171
|
+
for (const key in optionsSchema) {
|
|
172
|
+
assertType(params[key], optionsSchema[key], name, key);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
function object2String(obj) {
|
|
178
|
+
let str = '';
|
|
179
|
+
for (const item in obj) {
|
|
180
|
+
str = str + item + ':' + obj[item] + ' \n';
|
|
181
|
+
}
|
|
182
|
+
return str;
|
|
183
|
+
}
|
|
184
|
+
function temporarilyNotSupport(name, recommended) {
|
|
185
|
+
return (option = {}, ...args) => {
|
|
186
|
+
const { success, fail, complete } = option;
|
|
187
|
+
const handle = new MethodHandler({ name, success, fail, complete });
|
|
188
|
+
let errMsg = '暂时不支持 API';
|
|
189
|
+
if (recommended) {
|
|
190
|
+
errMsg += `, 请使用 ${recommended}`;
|
|
191
|
+
}
|
|
192
|
+
eventCenter.trigger('__taroNotSupport', {
|
|
193
|
+
name,
|
|
194
|
+
args: [option, ...args],
|
|
195
|
+
type: 'method',
|
|
196
|
+
category: 'temporarily',
|
|
197
|
+
});
|
|
198
|
+
if (process.env.NODE_ENV === 'production') {
|
|
199
|
+
console.warn(errMsg);
|
|
200
|
+
return handle.success({ errMsg });
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
return handle.fail({ errMsg });
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function permanentlyNotSupport(name = '') {
|
|
208
|
+
return (option = {}, ...args) => {
|
|
209
|
+
const { success, fail, complete } = option;
|
|
210
|
+
const handle = new MethodHandler({ name, success, fail, complete });
|
|
211
|
+
const errMsg = '不支持 API';
|
|
212
|
+
eventCenter.trigger('__taroNotSupport', {
|
|
213
|
+
name,
|
|
214
|
+
args: [option, ...args],
|
|
215
|
+
type: 'method',
|
|
216
|
+
category: 'permanently',
|
|
217
|
+
});
|
|
218
|
+
if (process.env.NODE_ENV === 'production') {
|
|
219
|
+
console.warn(errMsg);
|
|
220
|
+
return handle.success({ errMsg });
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
return handle.fail({ errMsg });
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/** @deprecated */
|
|
228
|
+
function callCallbackSuccess(res, options) {
|
|
229
|
+
var _a, _b;
|
|
230
|
+
(_a = options === null || options === void 0 ? void 0 : options.success) === null || _a === void 0 ? void 0 : _a.call(options, res);
|
|
231
|
+
(_b = options === null || options === void 0 ? void 0 : options.complete) === null || _b === void 0 ? void 0 : _b.call(options, res);
|
|
232
|
+
}
|
|
233
|
+
/** @deprecated */
|
|
234
|
+
function callCallbackFail(res, options) {
|
|
235
|
+
var _a, _b;
|
|
236
|
+
(_a = options === null || options === void 0 ? void 0 : options.fail) === null || _a === void 0 ? void 0 : _a.call(options, res);
|
|
237
|
+
(_b = options === null || options === void 0 ? void 0 : options.complete) === null || _b === void 0 ? void 0 : _b.call(options, res);
|
|
238
|
+
}
|
|
239
|
+
/** @deprecated */
|
|
240
|
+
function callAsyncSuccess(resolve, res, options) {
|
|
241
|
+
var _a, _b;
|
|
242
|
+
(_a = options === null || options === void 0 ? void 0 : options.success) === null || _a === void 0 ? void 0 : _a.call(options, res);
|
|
243
|
+
(_b = options === null || options === void 0 ? void 0 : options.complete) === null || _b === void 0 ? void 0 : _b.call(options, res);
|
|
244
|
+
resolve(res);
|
|
245
|
+
}
|
|
246
|
+
/** @deprecated */
|
|
247
|
+
function callAsyncFail(reject, res, options) {
|
|
248
|
+
var _a, _b;
|
|
249
|
+
(_a = options === null || options === void 0 ? void 0 : options.fail) === null || _a === void 0 ? void 0 : _a.call(options, res);
|
|
250
|
+
(_b = options === null || options === void 0 ? void 0 : options.complete) === null || _b === void 0 ? void 0 : _b.call(options, res);
|
|
251
|
+
reject(res);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// 设备信息,从 API Version 6 开始支持
|
|
255
|
+
const display = _display.getDefaultDisplaySync();
|
|
256
|
+
let device;
|
|
257
|
+
deviceMethod.getInfo({
|
|
258
|
+
success: data => {
|
|
259
|
+
device = data;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
/* 同步版本 */
|
|
263
|
+
const getSystemInfoSync = function () {
|
|
264
|
+
const res = {};
|
|
265
|
+
res.SDKVersion = deviceInfo && deviceInfo.sdkApiVersion; // 客户端基础库版本 string
|
|
266
|
+
res.albumAuthorized = false; // 允许使用相册的开关(仅 iOS 有效) boolean
|
|
267
|
+
res.benchmarkLevel = null; // 设备性能等级 number
|
|
268
|
+
res.bluetoothEnabled = null; // 蓝牙的系统开关 boolean
|
|
269
|
+
res.brand = deviceInfo && deviceInfo.brand; // 设备品牌 string
|
|
270
|
+
res.cameraAuthorized = null; // 允许使用摄像头的开关 boolean
|
|
271
|
+
res.enableDebug = null; // 是否已打开调试 boolean
|
|
272
|
+
res.fontSizeSetting = null; // 用户字体大小(单位px) number
|
|
273
|
+
res.language = i18n && i18n.getSystemLanguage && i18n.getSystemLanguage(); // string
|
|
274
|
+
res.locationAuthorized = null; // 定位的开关 boolean
|
|
275
|
+
res.locationEnabled = null; // 地理位置的系统开关 boolean
|
|
276
|
+
res.microphoneAuthorized = null; // 麦克风的开关 boolean
|
|
277
|
+
res.model = deviceInfo && deviceInfo.deviceType; // 设备型号 string
|
|
278
|
+
res.notificationAuthorized = null; // 通知的开关 boolean
|
|
279
|
+
res.notificationAlertAuthorized = false; // 通知带有提醒的开关(仅 iOS 有效) boolean
|
|
280
|
+
res.notificationBadgeAuthorized = false; // 通知带有标记的开关(仅 iOS 有效) boolean
|
|
281
|
+
res.notificationSoundAuthorized = false; // 通知带有声音的开关(仅 iOS 有效)boolean
|
|
282
|
+
res.phoneCalendarAuthorized = null; // 使用日历的开关 boolean
|
|
283
|
+
res.wifiEnabled = false; // Wi-Fi 的系统开关 boolean
|
|
284
|
+
res.pixelRatio = null; // 设备像素比,number
|
|
285
|
+
res.platform = 'android'; // 客户端平台 string
|
|
286
|
+
res.safeArea = null; // 在竖屏正方向下的安全区域 General.SafeAreaResult
|
|
287
|
+
res.screenHeight = display && display.height; // 屏幕高度,单位px number
|
|
288
|
+
res.screenWidth = display && display.width; // 屏幕宽度,单位px number
|
|
289
|
+
res.statusBarHeight = null; // 状态栏的高度,单位px number
|
|
290
|
+
res.system = deviceInfo && deviceInfo.osFullName; // 操作系统及版本 string
|
|
291
|
+
res.theme = null; // 系统当前主题,取值为light或dark 'light' | 'dark'
|
|
292
|
+
res.windowWidth = device && device.windowWidth; // 可使用窗口宽度,单位px number
|
|
293
|
+
res.windowHeight = device && device.windowHeight; // 可使用窗口高度,单位px number
|
|
294
|
+
res.version = deviceInfo && deviceInfo.displayVersion; // 版本号 string
|
|
295
|
+
return res;
|
|
296
|
+
};
|
|
297
|
+
/* 异步版本 */
|
|
298
|
+
const getSystemInfo = function (options) {
|
|
299
|
+
let res = {};
|
|
300
|
+
return new Promise((resolve, reject) => {
|
|
301
|
+
try {
|
|
302
|
+
res = getSystemInfoSync();
|
|
303
|
+
callAsyncSuccess(resolve, res, options);
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
res = {
|
|
307
|
+
errMsg: `getSystemInfo:fail ${error && error.toString && error.toString()}`,
|
|
308
|
+
error: error
|
|
309
|
+
};
|
|
310
|
+
callAsyncFail(reject, res, options);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
globalThis.getSystemInfoSync = getSystemInfoSync;
|
|
315
|
+
|
|
316
|
+
const getUpdateManager = temporarilyNotSupport('getUpdateManager');
|
|
317
|
+
|
|
318
|
+
const callbackManager$1 = new CallbackManager();
|
|
319
|
+
let devicemotionListener;
|
|
320
|
+
/**
|
|
321
|
+
* 停止监听加速度数据。
|
|
322
|
+
*/
|
|
323
|
+
const stopAccelerometer = ({ success, fail, complete } = {}) => {
|
|
324
|
+
const res = {};
|
|
325
|
+
const handle = new MethodHandler({ name: 'stopAccelerometer', success, fail, complete });
|
|
326
|
+
try {
|
|
327
|
+
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, devicemotionListener);
|
|
328
|
+
return handle.success(res);
|
|
329
|
+
}
|
|
330
|
+
catch (e) {
|
|
331
|
+
res.errMsg = e.message;
|
|
332
|
+
return handle.fail(res);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
const INTERVAL_MAP = {
|
|
336
|
+
game: {
|
|
337
|
+
interval: 20 * 1000 * 1000,
|
|
338
|
+
frequency: 50
|
|
339
|
+
},
|
|
340
|
+
ui: {
|
|
341
|
+
interval: 60 * 1000 * 1000,
|
|
342
|
+
frequency: 16.67
|
|
343
|
+
},
|
|
344
|
+
normal: {
|
|
345
|
+
interval: 200 * 1000 * 1000,
|
|
346
|
+
frequency: 5
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* 开始监听加速度数据。
|
|
351
|
+
*/
|
|
352
|
+
const startAccelerometer = ({ interval = 'normal', success, fail, complete } = {}) => {
|
|
353
|
+
const handle = new MethodHandler({ name: 'startAccelerometer', success, fail, complete });
|
|
354
|
+
try {
|
|
355
|
+
const intervalObj = INTERVAL_MAP[interval];
|
|
356
|
+
if (devicemotionListener) ;
|
|
357
|
+
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data) => {
|
|
358
|
+
callbackManager$1.trigger({
|
|
359
|
+
x: (data === null || data === void 0 ? void 0 : data.x) || 0,
|
|
360
|
+
y: (data === null || data === void 0 ? void 0 : data.y) || 0,
|
|
361
|
+
z: (data === null || data === void 0 ? void 0 : data.z) || 0
|
|
362
|
+
});
|
|
363
|
+
}, {
|
|
364
|
+
interval: intervalObj.interval,
|
|
365
|
+
});
|
|
366
|
+
return handle.success();
|
|
367
|
+
}
|
|
368
|
+
catch (e) {
|
|
369
|
+
return handle.fail({ errMsg: e.message });
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
/**
|
|
373
|
+
* 监听加速度数据事件。频率根据 Taro.startAccelerometer() 的 interval 参数。可使用 Taro.stopAccelerometer() 停止监听。
|
|
374
|
+
*/
|
|
375
|
+
const onAccelerometerChange = callback => {
|
|
376
|
+
callbackManager$1.add(callback);
|
|
377
|
+
};
|
|
378
|
+
/**
|
|
379
|
+
* 取消监听加速度数据事件,参数为空,则取消所有的事件监听
|
|
380
|
+
*/
|
|
381
|
+
const offAccelerometerChange = callback => {
|
|
382
|
+
callbackManager$1.remove(callback);
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
/******************************************************************************
|
|
386
|
+
Copyright (c) Microsoft Corporation.
|
|
387
|
+
|
|
388
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
389
|
+
purpose with or without fee is hereby granted.
|
|
390
|
+
|
|
391
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
392
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
393
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
394
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
395
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
396
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
397
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
398
|
+
***************************************************************************** */
|
|
399
|
+
/* global Reflect, Promise */
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
403
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
404
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
405
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
406
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
407
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
408
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// 电量
|
|
413
|
+
const getBatteryInfoSync = () => ({
|
|
414
|
+
// @ts-ignore
|
|
415
|
+
isCharging: [BatteryChargeState.ENABLE, BatteryChargeState.FULL].includes(batteryInfo.chargingStatus),
|
|
416
|
+
level: batteryInfo.batterySOC
|
|
417
|
+
});
|
|
418
|
+
const getBatteryInfo = ({ success, fail, complete } = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
419
|
+
const handle = new MethodHandler({ name: 'getBatteryInfo', success, fail, complete });
|
|
420
|
+
try {
|
|
421
|
+
return handle.success(getBatteryInfoSync());
|
|
422
|
+
}
|
|
423
|
+
catch (error) {
|
|
424
|
+
return handle.fail({
|
|
425
|
+
errMsg: (error === null || error === void 0 ? void 0 : error.message) || error
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// 从 API Version 6 开始支持
|
|
431
|
+
/**
|
|
432
|
+
* 设置系统剪贴板的内容
|
|
433
|
+
*/
|
|
434
|
+
const setClipboardData = function (options) {
|
|
435
|
+
const { data, success, fail, complete } = options;
|
|
436
|
+
const handle = new MethodHandler({ name: 'setClipboardData', success, fail, complete });
|
|
437
|
+
let res = {};
|
|
438
|
+
if (!isString(data)) {
|
|
439
|
+
return handle.fail({
|
|
440
|
+
errMsg: getParameterError({
|
|
441
|
+
para: 'data',
|
|
442
|
+
correct: 'String',
|
|
443
|
+
wrong: data
|
|
444
|
+
})
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
return new Promise((resolve, reject) => {
|
|
448
|
+
const systemPasteboard = pasteboard.getSystemPasteboard();
|
|
449
|
+
const pasteData = pasteboard.createPlainTextData(data);
|
|
450
|
+
systemPasteboard.setPasteData(pasteData, (error, data) => {
|
|
451
|
+
if (error) {
|
|
452
|
+
console.error('Failed to set PasteData. Cause: ' + JSON.stringify(error));
|
|
453
|
+
res = {
|
|
454
|
+
errMsg: 'setClipboardData:fail,error: ' + object2String(error),
|
|
455
|
+
error: error
|
|
456
|
+
};
|
|
457
|
+
callAsyncFail(reject, res, options);
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
return handle.success({
|
|
461
|
+
data,
|
|
462
|
+
}, { resolve, reject });
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
};
|
|
467
|
+
/**
|
|
468
|
+
* 获取系统剪贴板的内容
|
|
469
|
+
*/
|
|
470
|
+
const getClipboardData = function (options) {
|
|
471
|
+
const { success, fail, complete } = options || {};
|
|
472
|
+
const handle = new MethodHandler({ name: 'getClipboardData', success, fail, complete });
|
|
473
|
+
return new Promise((resolve, reject) => {
|
|
474
|
+
const systemPasteboard = pasteboard.getSystemPasteboard();
|
|
475
|
+
systemPasteboard.getPasteData((error, pasteData) => {
|
|
476
|
+
if (error) {
|
|
477
|
+
console.error('Failed to obtain PasteData. Cause: ' + JSON.stringify(error));
|
|
478
|
+
return handle.fail({
|
|
479
|
+
errMsg: object2String(error),
|
|
480
|
+
}, { resolve, reject });
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
return handle.success({
|
|
484
|
+
data: pasteData.getPrimaryText(),
|
|
485
|
+
}, { resolve, reject });
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
const callbackManager = new CallbackManager();
|
|
492
|
+
const resizeListener = (height) => {
|
|
493
|
+
callbackManager.trigger({
|
|
494
|
+
height,
|
|
495
|
+
});
|
|
496
|
+
};
|
|
497
|
+
let topWindow;
|
|
498
|
+
const onKeyboardHeightChange = callback => {
|
|
499
|
+
callbackManager.add(callback);
|
|
500
|
+
if (callbackManager.count() === 1) {
|
|
501
|
+
Current.contextPromise
|
|
502
|
+
.then(context => {
|
|
503
|
+
const win = window.__ohos.getLastWindow(context);
|
|
504
|
+
win.then(mainWindow => {
|
|
505
|
+
topWindow = mainWindow;
|
|
506
|
+
topWindow.on('keyboardHeightChange', resizeListener);
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
const offKeyboardHeightChange = callback => {
|
|
512
|
+
callbackManager.remove(callback);
|
|
513
|
+
if (callbackManager.count() === 0) {
|
|
514
|
+
topWindow === null || topWindow === void 0 ? void 0 : topWindow.off('keyboardHeightChange', resizeListener);
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
// @ts-ignore
|
|
518
|
+
let keyboardController;
|
|
519
|
+
inputMethodEngine.getInputMethodAbility()
|
|
520
|
+
// FIXME 当前事件无效,等待鸿蒙方面沟通
|
|
521
|
+
.on('inputStart', (kbController) => {
|
|
522
|
+
keyboardController = kbController;
|
|
523
|
+
});
|
|
524
|
+
const hideKeyboard = function (options) {
|
|
525
|
+
const { success, fail, complete } = options || {};
|
|
526
|
+
const handle = new MethodHandler({ name: 'hideKeyboard', success, fail, complete });
|
|
527
|
+
return new Promise((resolve, reject) => {
|
|
528
|
+
keyboardController === null || keyboardController === void 0 ? void 0 : keyboardController.hide((err) => {
|
|
529
|
+
if (err) {
|
|
530
|
+
return handle.fail({
|
|
531
|
+
errMsg: err,
|
|
532
|
+
}, { resolve, reject });
|
|
533
|
+
}
|
|
534
|
+
return handle.success({}, { resolve, reject });
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
};
|
|
538
|
+
const getSelectedTextRange = /* @__PURE__ */ temporarilyNotSupport('getSelectedTextRange');
|
|
539
|
+
|
|
540
|
+
const onMemoryWarning = temporarilyNotSupport('onMemoryWarning');
|
|
541
|
+
const offMemoryWarning = temporarilyNotSupport('offMemoryWarning');
|
|
542
|
+
|
|
543
|
+
const getNetworkType = (options = {}) => {
|
|
544
|
+
const { success, fail, complete } = options;
|
|
545
|
+
const handle = new MethodHandler({ name: 'getNetworkType', success, fail, complete });
|
|
546
|
+
return new Promise((resolve, reject) => {
|
|
547
|
+
network.getType({
|
|
548
|
+
success: function (data) {
|
|
549
|
+
return handle.success({
|
|
550
|
+
networkType: data.type || 'unknown',
|
|
551
|
+
metered: data.metered
|
|
552
|
+
}, { resolve, reject });
|
|
553
|
+
},
|
|
554
|
+
fail: function (data, code) {
|
|
555
|
+
return handle.fail({
|
|
556
|
+
errMsg: data || '',
|
|
557
|
+
code
|
|
558
|
+
}, { resolve, reject });
|
|
559
|
+
},
|
|
560
|
+
});
|
|
561
|
+
});
|
|
562
|
+
};
|
|
563
|
+
const networkStatusManager = new CallbackManager();
|
|
564
|
+
const networkStatusListener = (data, code = 0) => __awaiter(void 0, void 0, void 0, function* () {
|
|
565
|
+
if (code > 0) {
|
|
566
|
+
return networkStatusManager.trigger({ isConnected: false, networkType: 'none' });
|
|
567
|
+
}
|
|
568
|
+
const networkType = data.type || 'unknown';
|
|
569
|
+
const isConnected = networkType !== 'none';
|
|
570
|
+
const metered = !!data.metered;
|
|
571
|
+
const obj = { isConnected, networkType, metered };
|
|
572
|
+
networkStatusManager.trigger(obj);
|
|
573
|
+
});
|
|
574
|
+
/**
|
|
575
|
+
* 在最近的八次网络请求中, 出现下列三个现象之一则判定弱网。
|
|
576
|
+
* - 出现三次以上连接超时
|
|
577
|
+
* - 出现三次 rtt 超过 400
|
|
578
|
+
* - 出现三次以上的丢包
|
|
579
|
+
* > 弱网事件通知规则是: 弱网状态变化时立即通知, 状态不变时 30s 内最多通知一次。
|
|
580
|
+
*/
|
|
581
|
+
const onNetworkWeakChange = /* @__PURE__ */ temporarilyNotSupport('onNetworkWeakChange');
|
|
582
|
+
const onNetworkStatusChange = callback => {
|
|
583
|
+
networkStatusManager.add(callback);
|
|
584
|
+
if (networkStatusManager.count() === 1) {
|
|
585
|
+
network.subscribe({
|
|
586
|
+
success: networkStatusListener,
|
|
587
|
+
fail: networkStatusListener,
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
const offNetworkWeakChange = /* @__PURE__ */ temporarilyNotSupport('offNetworkWeakChange');
|
|
592
|
+
const offNetworkStatusChange = callback => {
|
|
593
|
+
networkStatusManager.remove(callback);
|
|
594
|
+
if (networkStatusManager.count() === 0) {
|
|
595
|
+
network.unsubscribe();
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
const getLocalIPAddress = /* @__PURE__ */ temporarilyNotSupport('getLocalIPAddress');
|
|
599
|
+
|
|
600
|
+
// 从 API Version 7 开始支持。
|
|
601
|
+
const makePhoneCall = (options) => {
|
|
602
|
+
// options must be an Object
|
|
603
|
+
const isObject = shouldBeObject(options);
|
|
604
|
+
if (!isObject.flag) {
|
|
605
|
+
const res = { errMsg: `makePhoneCall:fail ${isObject.msg}` };
|
|
606
|
+
console.error(res.errMsg);
|
|
607
|
+
return Promise.reject(res);
|
|
608
|
+
}
|
|
609
|
+
const { phoneNumber, success, fail, complete } = options;
|
|
610
|
+
const handle = new MethodHandler({ name: 'makePhoneCall', success, fail, complete });
|
|
611
|
+
if (!isString(phoneNumber)) {
|
|
612
|
+
return handle.fail({
|
|
613
|
+
errMsg: getParameterError({
|
|
614
|
+
para: 'phoneNumber',
|
|
615
|
+
correct: 'String',
|
|
616
|
+
wrong: phoneNumber
|
|
617
|
+
})
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
return new Promise((resolve, reject) => {
|
|
621
|
+
call.makeCall(phoneNumber, err => {
|
|
622
|
+
if (err) {
|
|
623
|
+
console.error('Failed to makePhoneCall. Cause: ' + JSON.stringify(err));
|
|
624
|
+
return handle.fail({
|
|
625
|
+
errMsg: object2String(err)
|
|
626
|
+
}, { resolve, reject });
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
return handle.success({}, { resolve, reject });
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
});
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
// 从API Version 7 开始,该接口不再维护,推荐使用新接口'@ohos.brightness'
|
|
636
|
+
// 但是 新接口 @ohos.brightness 没有 getValue
|
|
637
|
+
// 屏幕
|
|
638
|
+
const setVisualEffectOnCapture = /* @__PURE__ */ temporarilyNotSupport('setVisualEffectOnCapture');
|
|
639
|
+
const setScreenBrightness = function (options) {
|
|
640
|
+
// options must be an Object
|
|
641
|
+
const isObject = shouldBeObject(options);
|
|
642
|
+
if (!isObject.flag) {
|
|
643
|
+
const res = { errMsg: `setScreenBrightness:fail ${isObject.msg}` };
|
|
644
|
+
console.error(res.errMsg);
|
|
645
|
+
return Promise.reject(res);
|
|
646
|
+
}
|
|
647
|
+
const { value, success, fail, complete } = options;
|
|
648
|
+
const handle = new MethodHandler({ name: 'setScreenBrightness', success, fail, complete });
|
|
649
|
+
if (!isNumber(value)) {
|
|
650
|
+
return handle.fail({
|
|
651
|
+
errMsg: getParameterError({
|
|
652
|
+
para: 'value',
|
|
653
|
+
correct: 'Number',
|
|
654
|
+
wrong: value
|
|
655
|
+
})
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
return new Promise((resolve, reject) => {
|
|
659
|
+
brightness.setValue({
|
|
660
|
+
// FIXME 不生效
|
|
661
|
+
value: value >= 0 && value <= 1 ? value * 255 : value,
|
|
662
|
+
success: function () {
|
|
663
|
+
return handle.success({}, { resolve, reject });
|
|
664
|
+
},
|
|
665
|
+
fail: function (data, code) {
|
|
666
|
+
return handle.fail({
|
|
667
|
+
errMsg: data || '',
|
|
668
|
+
code
|
|
669
|
+
}, { resolve, reject });
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
});
|
|
673
|
+
};
|
|
674
|
+
const setKeepScreenOn = /* @__PURE__ */ temporarilyNotSupport('setKeepScreenOn');
|
|
675
|
+
const onUserCaptureScreen = /* @__PURE__ */ temporarilyNotSupport('onUserCaptureScreen');
|
|
676
|
+
const offUserCaptureScreen = /* @__PURE__ */ temporarilyNotSupport('offUserCaptureScreen');
|
|
677
|
+
const getScreenBrightness = function (options) {
|
|
678
|
+
const { success, fail, complete } = options || {};
|
|
679
|
+
const handle = new MethodHandler({ name: 'getScreenBrightness', success, fail, complete });
|
|
680
|
+
return new Promise((resolve, reject) => {
|
|
681
|
+
brightness.getValue({
|
|
682
|
+
success: function (data) {
|
|
683
|
+
return handle.success({
|
|
684
|
+
value: data.value
|
|
685
|
+
}, { resolve, reject });
|
|
686
|
+
},
|
|
687
|
+
fail: function (data, code) {
|
|
688
|
+
return handle.fail({
|
|
689
|
+
errMsg: data || '',
|
|
690
|
+
code
|
|
691
|
+
}, { resolve, reject });
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
});
|
|
695
|
+
};
|
|
696
|
+
const onScreenRecordingStateChanged = /* @__PURE__ */ temporarilyNotSupport('onScreenRecordingStateChanged');
|
|
697
|
+
const offScreenRecordingStateChanged = /* @__PURE__ */ temporarilyNotSupport('offScreenRecordingStateChanged');
|
|
698
|
+
const getScreenRecordingState = /* @__PURE__ */ temporarilyNotSupport('getScreenRecordingState');
|
|
699
|
+
|
|
700
|
+
const VIBRATOR_LONG_TIME = 400;
|
|
701
|
+
const VIBRATOR_SHORT_TIME = 15;
|
|
702
|
+
function vibrateBaseGenerator(time) {
|
|
703
|
+
return (options) => {
|
|
704
|
+
return new Promise((resolve, reject) => {
|
|
705
|
+
vibrator.vibrate(time).then(() => {
|
|
706
|
+
const res = { errMsg: 'vibrateShort:ok' };
|
|
707
|
+
callAsyncSuccess(resolve, res, options);
|
|
708
|
+
}, (error) => {
|
|
709
|
+
const res = { errMsg: 'vibrateShort:fail' + error };
|
|
710
|
+
callAsyncFail(reject, res, options);
|
|
711
|
+
});
|
|
712
|
+
});
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
const vibrateLong = vibrateBaseGenerator(VIBRATOR_LONG_TIME);
|
|
716
|
+
const vibrateShort = vibrateBaseGenerator(VIBRATOR_SHORT_TIME);
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* HarmonyOS 文档:
|
|
720
|
+
* https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-fileio-0000001168366687
|
|
721
|
+
*
|
|
722
|
+
* WX 文档:
|
|
723
|
+
* https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.html
|
|
724
|
+
*
|
|
725
|
+
* Taro.js 文档
|
|
726
|
+
* https://taro-docs.jd.com/taro/docs/apis/files/FileSystemManager
|
|
727
|
+
*
|
|
728
|
+
* HarmonyOS 不支持接口:
|
|
729
|
+
* readCompressedFile
|
|
730
|
+
* readCompressedFileSync
|
|
731
|
+
* readdirSync
|
|
732
|
+
* readZipEntry
|
|
733
|
+
*
|
|
734
|
+
* HarmonyOS 差异性接口:
|
|
735
|
+
* readFile:encoding 仅支持 utf-8
|
|
736
|
+
* readFileSync:encoding 仅支持 utf-8
|
|
737
|
+
* write:encoding 仅支持 utf-8
|
|
738
|
+
* writeSync:encoding 仅支持 utf-8
|
|
739
|
+
* rmdirSync:recursive 参数无效(即不支持递归删除)
|
|
740
|
+
* statSync:recursive 参数无效(即不支持递归获取目录下的每个文件的 Stats 信息)
|
|
741
|
+
* getSavedFileList:返回值 fileList 中的每一项不包含 createTime 属性
|
|
742
|
+
*/
|
|
743
|
+
var _a;
|
|
744
|
+
const rootDataPath = `/data/data/${((_a = app.getInfo()) === null || _a === void 0 ? void 0 : _a.appID) || 'app'}`;
|
|
745
|
+
const rootSavedFilePath = `${rootDataPath}/files`;
|
|
746
|
+
const pathSchema = {
|
|
747
|
+
path: 'String'
|
|
748
|
+
};
|
|
749
|
+
const copyFileSchema = {
|
|
750
|
+
srcPath: 'String',
|
|
751
|
+
destPath: 'String'
|
|
752
|
+
};
|
|
753
|
+
const filePathSchema$1 = {
|
|
754
|
+
filePath: 'String'
|
|
755
|
+
};
|
|
756
|
+
const dirPathSchema = {
|
|
757
|
+
dirPath: 'String'
|
|
758
|
+
};
|
|
759
|
+
const readSchema = {
|
|
760
|
+
fd: 'String',
|
|
761
|
+
arrayBuffer: 'Object'
|
|
762
|
+
};
|
|
763
|
+
const writeSchema = {
|
|
764
|
+
fd: 'String',
|
|
765
|
+
data: 'String'
|
|
766
|
+
};
|
|
767
|
+
const renameSchema = {
|
|
768
|
+
newPath: 'String',
|
|
769
|
+
oldPath: 'String'
|
|
770
|
+
};
|
|
771
|
+
const fdSchema = {
|
|
772
|
+
fd: 'String'
|
|
773
|
+
};
|
|
774
|
+
const saveFileSchema = {
|
|
775
|
+
tempFilePath: 'String'
|
|
776
|
+
};
|
|
777
|
+
const unzipSchema = {
|
|
778
|
+
targetPath: 'String',
|
|
779
|
+
zipFilePath: 'String'
|
|
780
|
+
};
|
|
781
|
+
function convertFilePathToUri(filePath) {
|
|
782
|
+
let uri = filePath.replace(/\/+/g, '/').replace(rootDataPath, 'internal:').replace('internal:/files', 'internal:/app');
|
|
783
|
+
uri = /\/$/.test(uri) ? uri : `${uri}/`;
|
|
784
|
+
return uri.replace(/\//g, '//');
|
|
785
|
+
}
|
|
786
|
+
function convertUriToFilePath(uri) {
|
|
787
|
+
return uri.replace(/\/+/g, '/').replace('internal:/app', 'internal:/files').replace('internal:', rootDataPath);
|
|
788
|
+
}
|
|
789
|
+
function convertDataToString(data) {
|
|
790
|
+
if (isString(data)) {
|
|
791
|
+
return data;
|
|
792
|
+
}
|
|
793
|
+
return String.fromCharCode.apply(null, new Uint8Array(data));
|
|
794
|
+
}
|
|
795
|
+
function convertReadOption(option) {
|
|
796
|
+
const result = {};
|
|
797
|
+
const { offset, length, position } = option;
|
|
798
|
+
if (isNumber(offset)) {
|
|
799
|
+
result.offset = offset;
|
|
800
|
+
}
|
|
801
|
+
if (isNumber(length)) {
|
|
802
|
+
result.length = length;
|
|
803
|
+
}
|
|
804
|
+
if (isNumber(position)) {
|
|
805
|
+
result.position = position;
|
|
806
|
+
}
|
|
807
|
+
return result;
|
|
808
|
+
}
|
|
809
|
+
function convertWriteOption(option) {
|
|
810
|
+
const result = {
|
|
811
|
+
encoding: 'utf-8'
|
|
812
|
+
};
|
|
813
|
+
const { offset, length, position } = option;
|
|
814
|
+
if (isNumber(offset)) {
|
|
815
|
+
result.offset = offset;
|
|
816
|
+
}
|
|
817
|
+
if (isNumber(length)) {
|
|
818
|
+
result.length = length;
|
|
819
|
+
}
|
|
820
|
+
if (isNumber(position)) {
|
|
821
|
+
result.position = position;
|
|
822
|
+
}
|
|
823
|
+
return result;
|
|
824
|
+
}
|
|
825
|
+
function convertReadFileOption(option) {
|
|
826
|
+
const result = {
|
|
827
|
+
encoding: 'utf-8'
|
|
828
|
+
};
|
|
829
|
+
const { position, length } = option;
|
|
830
|
+
if (isNumber(position)) {
|
|
831
|
+
result.position = position;
|
|
832
|
+
}
|
|
833
|
+
if (isNumber(length)) {
|
|
834
|
+
result.length = length;
|
|
835
|
+
}
|
|
836
|
+
return result;
|
|
837
|
+
}
|
|
838
|
+
function convertFd(fd) {
|
|
839
|
+
return parseInt(fd, 10);
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* HarmonyOS flag 详情参见:
|
|
843
|
+
* https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-fileio-0000001168366687#section1153565865716
|
|
844
|
+
*/
|
|
845
|
+
function convertOpenFlag(flag) {
|
|
846
|
+
if (typeof flag === 'string') {
|
|
847
|
+
switch (flag) {
|
|
848
|
+
case 'a':
|
|
849
|
+
return 0o1 | 0o100 | 0o2000;
|
|
850
|
+
case 'ax':
|
|
851
|
+
return 0o1 | 0o100 | 0o2000 | 0o200;
|
|
852
|
+
case 'a+':
|
|
853
|
+
return 0o2 | 0o100 | 0o2000;
|
|
854
|
+
case 'ax+':
|
|
855
|
+
return 0o2 | 0o100 | 0o2000 | 0o200;
|
|
856
|
+
case 'as':
|
|
857
|
+
return 0o1 | 0o100 | 0o2000 | 0o4010000;
|
|
858
|
+
case 'as+':
|
|
859
|
+
return 0o2 | 0o100 | 0o2000 | 0o4010000;
|
|
860
|
+
case 'r':
|
|
861
|
+
return 0o0;
|
|
862
|
+
case 'r+':
|
|
863
|
+
return 0o2;
|
|
864
|
+
case 'w':
|
|
865
|
+
return 0o1 | 0o100 | 0o1000;
|
|
866
|
+
case 'wx':
|
|
867
|
+
return 0o1 | 0o100 | 0o200;
|
|
868
|
+
case 'w+':
|
|
869
|
+
return 0o2 | 0o100 | 0o1000;
|
|
870
|
+
case 'wx+':
|
|
871
|
+
return 0o2 | 0o100 | 0o200;
|
|
872
|
+
default:
|
|
873
|
+
return 0o0;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
else {
|
|
877
|
+
return 0o0;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
function validateSavedFilePath(savedFilePath) {
|
|
881
|
+
if (savedFilePath.indexOf(rootSavedFilePath) !== 0) {
|
|
882
|
+
throw new Error(`The filePath should in ${rootSavedFilePath}`);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
function parseSavedFilePath(srcPath, savedFilePath) {
|
|
886
|
+
if (isString(savedFilePath) && savedFilePath.length > 0) {
|
|
887
|
+
validateSavedFilePath(savedFilePath);
|
|
888
|
+
return savedFilePath;
|
|
889
|
+
}
|
|
890
|
+
return `${rootSavedFilePath}/${srcPath.split('/').pop()}`;
|
|
891
|
+
}
|
|
892
|
+
function isFileExist(filePath) {
|
|
893
|
+
try {
|
|
894
|
+
accessSync(filePath);
|
|
895
|
+
return true;
|
|
896
|
+
}
|
|
897
|
+
catch (_) {
|
|
898
|
+
return false;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
function getDirFiles(dirPath) {
|
|
902
|
+
return new Promise((resolve, reject) => {
|
|
903
|
+
file.list({
|
|
904
|
+
uri: convertFilePathToUri(dirPath),
|
|
905
|
+
success: ({ fileList }) => {
|
|
906
|
+
resolve({
|
|
907
|
+
files: fileList.filter(({ type }) => type.toLowerCase() === 'file').map(({ uri }) => convertUriToFilePath(uri)),
|
|
908
|
+
dirs: fileList.filter(({ type }) => type.toLowerCase() === 'dir').map(({ uri }) => convertUriToFilePath(uri))
|
|
909
|
+
});
|
|
910
|
+
},
|
|
911
|
+
fail: (error) => {
|
|
912
|
+
reject(new Error(error));
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
const readCompressedFile = temporarilyNotSupport('readCompressedFile');
|
|
918
|
+
function readCompressedFileSync(_) {
|
|
919
|
+
temporarilyNotSupport('readCompressedFileSync')(_);
|
|
920
|
+
return new ArrayBuffer(0);
|
|
921
|
+
}
|
|
922
|
+
function readdirSync(_) {
|
|
923
|
+
temporarilyNotSupport('readdirSync')(_);
|
|
924
|
+
return [];
|
|
925
|
+
}
|
|
926
|
+
const readZipEntry = temporarilyNotSupport('readZipEntry');
|
|
927
|
+
function access(option) {
|
|
928
|
+
try {
|
|
929
|
+
validateParams('access', option, pathSchema);
|
|
930
|
+
}
|
|
931
|
+
catch (error) {
|
|
932
|
+
const res = { errMsg: error.message };
|
|
933
|
+
return callCallbackFail(res, option);
|
|
934
|
+
}
|
|
935
|
+
fileio.access(option.path, (error) => {
|
|
936
|
+
if (error) {
|
|
937
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
938
|
+
callCallbackFail(res, option);
|
|
939
|
+
}
|
|
940
|
+
else {
|
|
941
|
+
callCallbackSuccess(undefined, option);
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
function accessSync(path) {
|
|
946
|
+
fileio.accessSync(path);
|
|
947
|
+
}
|
|
948
|
+
function mkdir(option) {
|
|
949
|
+
try {
|
|
950
|
+
validateParams('mkdir', option, dirPathSchema);
|
|
951
|
+
}
|
|
952
|
+
catch (error) {
|
|
953
|
+
const res = { errMsg: error.message };
|
|
954
|
+
return callCallbackFail(res, option);
|
|
955
|
+
}
|
|
956
|
+
file.mkdir({
|
|
957
|
+
uri: convertFilePathToUri(option.dirPath),
|
|
958
|
+
recursive: option.recursive,
|
|
959
|
+
success: () => callCallbackSuccess(undefined, option),
|
|
960
|
+
fail: (error, code) => {
|
|
961
|
+
const res = { errMsg: `mkdir invoke failed, code: ${code}, error: ${error}` };
|
|
962
|
+
callCallbackFail(res, option);
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
function mkdirSync(dirPath, recursive) {
|
|
967
|
+
if (recursive === true) {
|
|
968
|
+
const pathParts = dirPath.split('/');
|
|
969
|
+
for (let index = 0; index < pathParts.length; index++) {
|
|
970
|
+
const filePath = pathParts.slice(0, index + 1).join('/');
|
|
971
|
+
if (filePath.length === 0 || isFileExist(filePath)) {
|
|
972
|
+
continue;
|
|
973
|
+
}
|
|
974
|
+
fileio.mkdirSync(filePath);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
else {
|
|
978
|
+
fileio.mkdirSync(dirPath);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
function rmdir(option) {
|
|
982
|
+
try {
|
|
983
|
+
validateParams('rmdir', option, dirPathSchema);
|
|
984
|
+
}
|
|
985
|
+
catch (error) {
|
|
986
|
+
const res = { errMsg: error.message };
|
|
987
|
+
return callCallbackFail(res, option);
|
|
988
|
+
}
|
|
989
|
+
file.rmdir({
|
|
990
|
+
uri: convertFilePathToUri(option.dirPath),
|
|
991
|
+
recursive: option.recursive,
|
|
992
|
+
success: () => callCallbackSuccess(undefined, option),
|
|
993
|
+
fail: (error, code) => {
|
|
994
|
+
const res = { errMsg: `rmdir invoke failed, code: ${code}, error: ${error}` };
|
|
995
|
+
callCallbackFail(res, option);
|
|
996
|
+
}
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
function rmdirSync(dirPath, recursive) {
|
|
1000
|
+
if (recursive === true) {
|
|
1001
|
+
temporarilyNotSupport('rmdirSync recursive')(dirPath);
|
|
1002
|
+
}
|
|
1003
|
+
else {
|
|
1004
|
+
fileio.rmdirSync(dirPath);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
function readdir(option) {
|
|
1008
|
+
try {
|
|
1009
|
+
validateParams('readdir', option, dirPathSchema);
|
|
1010
|
+
}
|
|
1011
|
+
catch (error) {
|
|
1012
|
+
const res = { errMsg: error.message };
|
|
1013
|
+
return callCallbackFail(res, option);
|
|
1014
|
+
}
|
|
1015
|
+
getDirFiles(option.dirPath).then(({ files, dirs }) => {
|
|
1016
|
+
callCallbackSuccess({ files: [...files, ...dirs] }, option);
|
|
1017
|
+
}).catch((error) => {
|
|
1018
|
+
const res = { errMsg: error.message };
|
|
1019
|
+
callCallbackFail(res, option);
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
function copyFile(option) {
|
|
1023
|
+
try {
|
|
1024
|
+
validateParams('copyFile', option, copyFileSchema);
|
|
1025
|
+
}
|
|
1026
|
+
catch (error) {
|
|
1027
|
+
const res = { errMsg: error.message };
|
|
1028
|
+
return callCallbackFail(res, option);
|
|
1029
|
+
}
|
|
1030
|
+
fileio.copyFile(option.srcPath, option.destPath, 0, (error) => {
|
|
1031
|
+
if (error) {
|
|
1032
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1033
|
+
callCallbackFail(res, option);
|
|
1034
|
+
}
|
|
1035
|
+
else {
|
|
1036
|
+
callCallbackSuccess(undefined, option);
|
|
1037
|
+
}
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
function copyFileSync(srcPath, destPath) {
|
|
1041
|
+
fileio.copyFileSync(srcPath, destPath, 0);
|
|
1042
|
+
}
|
|
1043
|
+
function open(option) {
|
|
1044
|
+
try {
|
|
1045
|
+
validateParams('open', option, filePathSchema$1);
|
|
1046
|
+
}
|
|
1047
|
+
catch (error) {
|
|
1048
|
+
const res = { errMsg: error.message };
|
|
1049
|
+
return callCallbackFail(res, option);
|
|
1050
|
+
}
|
|
1051
|
+
// 由于 HarmonyOS 异步方法 fileio.open 在【文件不存在则创建】模式下依旧抛出 No such file or directory 异常,
|
|
1052
|
+
// 为保证接口的可用性,此处降级使用 fileio.openSync 方法。
|
|
1053
|
+
const openPromise = new Promise((resolve, reject) => {
|
|
1054
|
+
try {
|
|
1055
|
+
const fd = fileio.openSync(option.filePath, convertOpenFlag(option.flag), 0o666);
|
|
1056
|
+
resolve({ fd: fd.toString() });
|
|
1057
|
+
}
|
|
1058
|
+
catch (error) {
|
|
1059
|
+
reject(new Error(error.message ? error.message : error));
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
openPromise.then((res) => callCallbackSuccess(res, option))
|
|
1063
|
+
.catch((error) => callCallbackFail({ errMsg: error.message }, option));
|
|
1064
|
+
}
|
|
1065
|
+
function openSync(option) {
|
|
1066
|
+
validateParams('openSync', option, filePathSchema$1);
|
|
1067
|
+
return fileio.openSync(option.filePath, convertOpenFlag(option.flag), 0o666).toString();
|
|
1068
|
+
}
|
|
1069
|
+
function read(option) {
|
|
1070
|
+
try {
|
|
1071
|
+
validateParams('read', option, readSchema);
|
|
1072
|
+
}
|
|
1073
|
+
catch (error) {
|
|
1074
|
+
const res = { errMsg: error.message };
|
|
1075
|
+
return callCallbackFail(res, option);
|
|
1076
|
+
}
|
|
1077
|
+
fileio.read(convertFd(option.fd), option.arrayBuffer, convertReadOption(option), (error, readOut) => {
|
|
1078
|
+
if (error) {
|
|
1079
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1080
|
+
callCallbackFail(res, option);
|
|
1081
|
+
}
|
|
1082
|
+
else {
|
|
1083
|
+
callCallbackSuccess({ bytesRead: readOut.bytesRead, arrayBuffer: readOut.buffer }, option);
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
function readSync(option) {
|
|
1088
|
+
validateParams('readSync', option, readSchema);
|
|
1089
|
+
return {
|
|
1090
|
+
bytesRead: fileio.readSync(convertFd(option.fd), option.arrayBuffer, convertReadOption(option)),
|
|
1091
|
+
arrayBuffer: option.arrayBuffer
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
/**
|
|
1095
|
+
* HarmonyOS encoding 目前仅支持 utf-8,详情参见:
|
|
1096
|
+
* https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-fileio-0000001168366687#section17477155374810
|
|
1097
|
+
*/
|
|
1098
|
+
function readFile(option) {
|
|
1099
|
+
try {
|
|
1100
|
+
validateParams('readFile', option, filePathSchema$1);
|
|
1101
|
+
}
|
|
1102
|
+
catch (error) {
|
|
1103
|
+
const res = { errMsg: error.message };
|
|
1104
|
+
return callCallbackFail(res, option);
|
|
1105
|
+
}
|
|
1106
|
+
fileio.readText(option.filePath, convertReadFileOption(option), (error, data) => {
|
|
1107
|
+
if (error) {
|
|
1108
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1109
|
+
callCallbackFail(res, option);
|
|
1110
|
+
}
|
|
1111
|
+
else {
|
|
1112
|
+
callCallbackSuccess({ data }, option);
|
|
1113
|
+
}
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* HarmonyOS encoding 目前仅支持 utf-8,详情参见:
|
|
1118
|
+
* https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-fileio-0000001168366687#section4147155065718
|
|
1119
|
+
*/
|
|
1120
|
+
function readFileSync(filePath, encoding, position, length) {
|
|
1121
|
+
return fileio.readTextSync(filePath, convertReadFileOption({ filePath, encoding, length, position }));
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* HarmonyOS encoding 目前仅支持 utf-8,详情参见:
|
|
1125
|
+
* https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-fileio-0000001168366687#section140547195118
|
|
1126
|
+
*/
|
|
1127
|
+
function write(option) {
|
|
1128
|
+
const data = convertDataToString(option.data);
|
|
1129
|
+
try {
|
|
1130
|
+
validateParams('write', Object.assign(Object.assign({}, option), { data }), writeSchema);
|
|
1131
|
+
}
|
|
1132
|
+
catch (error) {
|
|
1133
|
+
const res = { errMsg: error.message };
|
|
1134
|
+
return callCallbackFail(res, option);
|
|
1135
|
+
}
|
|
1136
|
+
fileio.write(convertFd(option.fd), data, convertWriteOption(option), (error, bytesWritten) => {
|
|
1137
|
+
if (error) {
|
|
1138
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1139
|
+
callCallbackFail(res, option);
|
|
1140
|
+
}
|
|
1141
|
+
else {
|
|
1142
|
+
callCallbackSuccess({ bytesWritten }, option);
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* HarmonyOS encoding 目前仅支持 utf-8,详情参见:
|
|
1148
|
+
* https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-fileio-0000001168366687#section144923345218
|
|
1149
|
+
*/
|
|
1150
|
+
function writeSync(option) {
|
|
1151
|
+
const data = convertDataToString(option.data);
|
|
1152
|
+
validateParams('writeSync', Object.assign(Object.assign({}, option), { data }), writeSchema);
|
|
1153
|
+
return {
|
|
1154
|
+
bytesWritten: fileio.writeSync(convertFd(option.fd), data, convertWriteOption(option))
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
function writeFileWithFlag(option, flag) {
|
|
1158
|
+
open({
|
|
1159
|
+
flag,
|
|
1160
|
+
filePath: option.filePath,
|
|
1161
|
+
success: ({ fd }) => {
|
|
1162
|
+
const writePromise = new Promise((resolve) => {
|
|
1163
|
+
write({
|
|
1164
|
+
fd,
|
|
1165
|
+
data: option.data,
|
|
1166
|
+
success: (res) => resolve({
|
|
1167
|
+
error: null,
|
|
1168
|
+
res
|
|
1169
|
+
}),
|
|
1170
|
+
fail: (res) => resolve({
|
|
1171
|
+
error: res,
|
|
1172
|
+
res: null
|
|
1173
|
+
})
|
|
1174
|
+
});
|
|
1175
|
+
});
|
|
1176
|
+
writePromise.then(({ error, res }) => {
|
|
1177
|
+
close({
|
|
1178
|
+
fd,
|
|
1179
|
+
success: () => {
|
|
1180
|
+
if (error === null) {
|
|
1181
|
+
callCallbackSuccess(res, option);
|
|
1182
|
+
}
|
|
1183
|
+
else {
|
|
1184
|
+
callCallbackFail(error, option);
|
|
1185
|
+
}
|
|
1186
|
+
},
|
|
1187
|
+
fail: (res) => callCallbackFail(res, option)
|
|
1188
|
+
});
|
|
1189
|
+
});
|
|
1190
|
+
},
|
|
1191
|
+
fail: (res) => callCallbackFail(res, option)
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
function writeFile(option) {
|
|
1195
|
+
writeFileWithFlag(option, 'w');
|
|
1196
|
+
}
|
|
1197
|
+
function writeFileSyncWithFlag(filePath, data, flag) {
|
|
1198
|
+
const fd = openSync({ filePath, flag });
|
|
1199
|
+
writeSync({ fd, data });
|
|
1200
|
+
closeSync({ fd });
|
|
1201
|
+
}
|
|
1202
|
+
function writeFileSync(filePath, data) {
|
|
1203
|
+
writeFileSyncWithFlag(filePath, data, 'w');
|
|
1204
|
+
}
|
|
1205
|
+
function appendFile(option) {
|
|
1206
|
+
writeFileWithFlag(option, 'a');
|
|
1207
|
+
}
|
|
1208
|
+
function appendFileSync(filePath, data) {
|
|
1209
|
+
writeFileSyncWithFlag(filePath, data, 'a');
|
|
1210
|
+
}
|
|
1211
|
+
function rename(option) {
|
|
1212
|
+
try {
|
|
1213
|
+
validateParams('rename', option, renameSchema);
|
|
1214
|
+
}
|
|
1215
|
+
catch (error) {
|
|
1216
|
+
const res = { errMsg: error.message };
|
|
1217
|
+
return callCallbackFail(res, option);
|
|
1218
|
+
}
|
|
1219
|
+
fileio.rename(option.oldPath, option.newPath, (error) => {
|
|
1220
|
+
if (error) {
|
|
1221
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1222
|
+
callCallbackFail(res, option);
|
|
1223
|
+
}
|
|
1224
|
+
else {
|
|
1225
|
+
callCallbackSuccess(undefined, option);
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1229
|
+
function renameSync(oldPath, newPath) {
|
|
1230
|
+
fileio.renameSync(oldPath, newPath);
|
|
1231
|
+
}
|
|
1232
|
+
function unlink(option) {
|
|
1233
|
+
try {
|
|
1234
|
+
validateParams('unlink', option, filePathSchema$1);
|
|
1235
|
+
}
|
|
1236
|
+
catch (error) {
|
|
1237
|
+
const res = { errMsg: error.message };
|
|
1238
|
+
return callCallbackFail(res, option);
|
|
1239
|
+
}
|
|
1240
|
+
fileio.unlink(option.filePath, (error) => {
|
|
1241
|
+
if (error) {
|
|
1242
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1243
|
+
callCallbackFail(res, option);
|
|
1244
|
+
}
|
|
1245
|
+
else {
|
|
1246
|
+
callCallbackSuccess(undefined, option);
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
function unlinkSync(filePath) {
|
|
1251
|
+
fileio.unlinkSync(filePath);
|
|
1252
|
+
}
|
|
1253
|
+
function fstat(option) {
|
|
1254
|
+
try {
|
|
1255
|
+
validateParams('fstat', option, fdSchema);
|
|
1256
|
+
}
|
|
1257
|
+
catch (error) {
|
|
1258
|
+
const res = { errMsg: error.message };
|
|
1259
|
+
return callCallbackFail(res, option);
|
|
1260
|
+
}
|
|
1261
|
+
fileio.fstat(convertFd(option.fd), (error, stats) => {
|
|
1262
|
+
if (error) {
|
|
1263
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1264
|
+
callCallbackFail(res, option);
|
|
1265
|
+
}
|
|
1266
|
+
else {
|
|
1267
|
+
const res = {
|
|
1268
|
+
mode: stats.mode.toString(),
|
|
1269
|
+
size: stats.size,
|
|
1270
|
+
lastAccessedTime: stats.atime,
|
|
1271
|
+
lastModifiedTime: stats.mtime,
|
|
1272
|
+
isDirectory: () => stats.isDirectory(),
|
|
1273
|
+
isFile: () => stats.isFile()
|
|
1274
|
+
};
|
|
1275
|
+
callCallbackSuccess({ stats: res }, option);
|
|
1276
|
+
}
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
function fstatSync(option) {
|
|
1280
|
+
validateParams('fstatSync', option, fdSchema);
|
|
1281
|
+
const stats = fileio.fstatSync(convertFd(option.fd));
|
|
1282
|
+
return {
|
|
1283
|
+
mode: stats.mode.toString(),
|
|
1284
|
+
size: stats.size,
|
|
1285
|
+
lastAccessedTime: stats.atime,
|
|
1286
|
+
lastModifiedTime: stats.mtime,
|
|
1287
|
+
isDirectory: () => stats.isDirectory(),
|
|
1288
|
+
isFile: () => stats.isFile()
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
function statWithFd(fd) {
|
|
1292
|
+
return new Promise((resolve) => {
|
|
1293
|
+
fstat({
|
|
1294
|
+
fd,
|
|
1295
|
+
success: ({ stats }) => resolve({
|
|
1296
|
+
stats,
|
|
1297
|
+
error: null
|
|
1298
|
+
}),
|
|
1299
|
+
fail: (error) => resolve({
|
|
1300
|
+
error,
|
|
1301
|
+
stats: null
|
|
1302
|
+
})
|
|
1303
|
+
});
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
function statWithPath(path) {
|
|
1307
|
+
return new Promise((resolve, reject) => {
|
|
1308
|
+
open({
|
|
1309
|
+
filePath: path,
|
|
1310
|
+
flag: 'r',
|
|
1311
|
+
success: ({ fd }) => {
|
|
1312
|
+
statWithFd(fd).then(({ error, stats }) => {
|
|
1313
|
+
close({
|
|
1314
|
+
fd,
|
|
1315
|
+
success: () => {
|
|
1316
|
+
if (error === null) {
|
|
1317
|
+
resolve(stats);
|
|
1318
|
+
}
|
|
1319
|
+
else {
|
|
1320
|
+
reject(error);
|
|
1321
|
+
}
|
|
1322
|
+
},
|
|
1323
|
+
fail: (error) => reject(error)
|
|
1324
|
+
});
|
|
1325
|
+
});
|
|
1326
|
+
},
|
|
1327
|
+
fail: (error) => reject(error)
|
|
1328
|
+
});
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
function statWithRecursive(rootPath) {
|
|
1332
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1333
|
+
let result = {};
|
|
1334
|
+
const { files, dirs } = yield getDirFiles(rootPath);
|
|
1335
|
+
for (const dir of dirs) {
|
|
1336
|
+
result[dir] = yield statWithPath(dir);
|
|
1337
|
+
result = Object.assign(Object.assign({}, result), (yield statWithRecursive(dir)));
|
|
1338
|
+
}
|
|
1339
|
+
for (const file of files) {
|
|
1340
|
+
result[file] = yield statWithPath(file);
|
|
1341
|
+
}
|
|
1342
|
+
return result;
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
function stat(option) {
|
|
1346
|
+
try {
|
|
1347
|
+
validateParams('fstat', option, pathSchema);
|
|
1348
|
+
}
|
|
1349
|
+
catch (error) {
|
|
1350
|
+
const res = { errMsg: error.message };
|
|
1351
|
+
return callCallbackFail(res, option);
|
|
1352
|
+
}
|
|
1353
|
+
const statPromise = option.recursive === true ? statWithRecursive(option.path) : statWithPath(option.path);
|
|
1354
|
+
statPromise.then((stats) => {
|
|
1355
|
+
callCallbackSuccess({ stats }, option);
|
|
1356
|
+
}).catch((error) => {
|
|
1357
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1358
|
+
callCallbackFail(res, option);
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1361
|
+
function statSync(path, recursive) {
|
|
1362
|
+
if (recursive === true) {
|
|
1363
|
+
return temporarilyNotSupport('statSync recursive')(path);
|
|
1364
|
+
}
|
|
1365
|
+
const fd = openSync({ filePath: path, flag: 'r' });
|
|
1366
|
+
const stats = fstatSync({ fd });
|
|
1367
|
+
closeSync({ fd });
|
|
1368
|
+
return stats;
|
|
1369
|
+
}
|
|
1370
|
+
function getFileInfo$1(option) {
|
|
1371
|
+
statWithPath(option.filePath).then((stats) => {
|
|
1372
|
+
callCallbackSuccess({ size: stats.size }, option);
|
|
1373
|
+
}).catch((error) => {
|
|
1374
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1375
|
+
callCallbackFail(res, option);
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
function getSavedFileList$1(option) {
|
|
1379
|
+
statWithRecursive(rootSavedFilePath).then((stats) => {
|
|
1380
|
+
const fileList = Object.keys(stats).map((filePath) => {
|
|
1381
|
+
const file = stats[filePath];
|
|
1382
|
+
if (file.isFile()) {
|
|
1383
|
+
return {
|
|
1384
|
+
filePath,
|
|
1385
|
+
size: file.size
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
return null;
|
|
1389
|
+
}).filter((file) => file !== null);
|
|
1390
|
+
callCallbackSuccess({ fileList }, option);
|
|
1391
|
+
}).catch((error) => {
|
|
1392
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1393
|
+
callCallbackFail(res, option);
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
function ftruncate(option) {
|
|
1397
|
+
var _a;
|
|
1398
|
+
try {
|
|
1399
|
+
validateParams('ftruncate', option, fdSchema);
|
|
1400
|
+
}
|
|
1401
|
+
catch (error) {
|
|
1402
|
+
const res = { errMsg: error.message };
|
|
1403
|
+
return callCallbackFail(res, option);
|
|
1404
|
+
}
|
|
1405
|
+
fileio.ftruncate(convertFd(option.fd), (_a = option.length) !== null && _a !== void 0 ? _a : 0, (error) => {
|
|
1406
|
+
if (error) {
|
|
1407
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1408
|
+
callCallbackFail(res, option);
|
|
1409
|
+
}
|
|
1410
|
+
else {
|
|
1411
|
+
callCallbackSuccess(undefined, option);
|
|
1412
|
+
}
|
|
1413
|
+
});
|
|
1414
|
+
}
|
|
1415
|
+
function ftruncateSync(option) {
|
|
1416
|
+
var _a;
|
|
1417
|
+
validateParams('ftruncateSync', option, fdSchema);
|
|
1418
|
+
fileio.ftruncateSync(convertFd(option.fd), (_a = option.length) !== null && _a !== void 0 ? _a : 0);
|
|
1419
|
+
}
|
|
1420
|
+
function truncate(option) {
|
|
1421
|
+
var _a;
|
|
1422
|
+
try {
|
|
1423
|
+
validateParams('truncate', option, filePathSchema$1);
|
|
1424
|
+
}
|
|
1425
|
+
catch (error) {
|
|
1426
|
+
const res = { errMsg: error.message };
|
|
1427
|
+
return callCallbackFail(res, option);
|
|
1428
|
+
}
|
|
1429
|
+
fileio.truncate(option.filePath, (_a = option.length) !== null && _a !== void 0 ? _a : 0, (error) => {
|
|
1430
|
+
if (error) {
|
|
1431
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1432
|
+
callCallbackFail(res, option);
|
|
1433
|
+
}
|
|
1434
|
+
else {
|
|
1435
|
+
callCallbackSuccess(undefined, option);
|
|
1436
|
+
}
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
function truncateSync(option) {
|
|
1440
|
+
var _a;
|
|
1441
|
+
validateParams('truncateSync', option, filePathSchema$1);
|
|
1442
|
+
fileio.truncateSync(option.filePath, (_a = option.length) !== null && _a !== void 0 ? _a : 0);
|
|
1443
|
+
}
|
|
1444
|
+
function close(option) {
|
|
1445
|
+
try {
|
|
1446
|
+
validateParams('close', option, fdSchema);
|
|
1447
|
+
}
|
|
1448
|
+
catch (error) {
|
|
1449
|
+
const res = { errMsg: error.message };
|
|
1450
|
+
return callCallbackFail(res, option);
|
|
1451
|
+
}
|
|
1452
|
+
fileio.close(convertFd(option.fd), (error) => {
|
|
1453
|
+
if (error) {
|
|
1454
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1455
|
+
callCallbackFail(res, option);
|
|
1456
|
+
}
|
|
1457
|
+
else {
|
|
1458
|
+
callCallbackSuccess(undefined, option);
|
|
1459
|
+
}
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
function closeSync(option) {
|
|
1463
|
+
validateParams('closeSync', option, fdSchema);
|
|
1464
|
+
fileio.closeSync(convertFd(option.fd));
|
|
1465
|
+
}
|
|
1466
|
+
function saveFile$1(option) {
|
|
1467
|
+
try {
|
|
1468
|
+
validateParams('saveFile', option, saveFileSchema);
|
|
1469
|
+
}
|
|
1470
|
+
catch (error) {
|
|
1471
|
+
const res = { errMsg: error.message };
|
|
1472
|
+
return callCallbackFail(res, option);
|
|
1473
|
+
}
|
|
1474
|
+
try {
|
|
1475
|
+
const savedFilePath = parseSavedFilePath(option.tempFilePath, option.filePath);
|
|
1476
|
+
rename({
|
|
1477
|
+
oldPath: option.tempFilePath,
|
|
1478
|
+
newPath: savedFilePath,
|
|
1479
|
+
success: () => {
|
|
1480
|
+
callCallbackSuccess({ savedFilePath }, option);
|
|
1481
|
+
},
|
|
1482
|
+
fail: (res) => {
|
|
1483
|
+
callCallbackFail(res, option);
|
|
1484
|
+
}
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
catch (error) {
|
|
1488
|
+
const res = { errMsg: error.message };
|
|
1489
|
+
return callCallbackFail(res, option);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
function saveFileSync(tempFilePath, filePath) {
|
|
1493
|
+
const savedFilePath = parseSavedFilePath(tempFilePath, filePath);
|
|
1494
|
+
renameSync(tempFilePath, savedFilePath);
|
|
1495
|
+
return savedFilePath;
|
|
1496
|
+
}
|
|
1497
|
+
function removeSavedFile$1(option) {
|
|
1498
|
+
try {
|
|
1499
|
+
validateParams('removeSavedFile', option, filePathSchema$1);
|
|
1500
|
+
}
|
|
1501
|
+
catch (error) {
|
|
1502
|
+
const res = { errMsg: error.message };
|
|
1503
|
+
return callCallbackFail(res, option);
|
|
1504
|
+
}
|
|
1505
|
+
try {
|
|
1506
|
+
validateSavedFilePath(option.filePath);
|
|
1507
|
+
}
|
|
1508
|
+
catch (error) {
|
|
1509
|
+
const res = { errMsg: error.message };
|
|
1510
|
+
return callCallbackFail(res, option);
|
|
1511
|
+
}
|
|
1512
|
+
unlink(option);
|
|
1513
|
+
}
|
|
1514
|
+
function unzip(option) {
|
|
1515
|
+
try {
|
|
1516
|
+
validateParams('unzip', option, unzipSchema);
|
|
1517
|
+
}
|
|
1518
|
+
catch (error) {
|
|
1519
|
+
const res = { errMsg: error.message };
|
|
1520
|
+
return callCallbackFail(res, option);
|
|
1521
|
+
}
|
|
1522
|
+
zlib.unzipFile(option.zipFilePath, option.targetPath).then(() => {
|
|
1523
|
+
callCallbackSuccess(undefined, option);
|
|
1524
|
+
}).catch(error => {
|
|
1525
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1526
|
+
callCallbackFail(res, option);
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
function getFileSystemManager() {
|
|
1530
|
+
return {
|
|
1531
|
+
access,
|
|
1532
|
+
accessSync,
|
|
1533
|
+
appendFile,
|
|
1534
|
+
appendFileSync,
|
|
1535
|
+
close,
|
|
1536
|
+
closeSync,
|
|
1537
|
+
copyFile,
|
|
1538
|
+
copyFileSync,
|
|
1539
|
+
fstat,
|
|
1540
|
+
fstatSync,
|
|
1541
|
+
ftruncate,
|
|
1542
|
+
ftruncateSync,
|
|
1543
|
+
getFileInfo: getFileInfo$1,
|
|
1544
|
+
getSavedFileList: getSavedFileList$1,
|
|
1545
|
+
mkdir,
|
|
1546
|
+
mkdirSync,
|
|
1547
|
+
open,
|
|
1548
|
+
openSync,
|
|
1549
|
+
read,
|
|
1550
|
+
readCompressedFile,
|
|
1551
|
+
readCompressedFileSync,
|
|
1552
|
+
readdir,
|
|
1553
|
+
readdirSync,
|
|
1554
|
+
readFile,
|
|
1555
|
+
readFileSync,
|
|
1556
|
+
readSync,
|
|
1557
|
+
readZipEntry,
|
|
1558
|
+
removeSavedFile: removeSavedFile$1,
|
|
1559
|
+
rename,
|
|
1560
|
+
renameSync,
|
|
1561
|
+
rmdir,
|
|
1562
|
+
rmdirSync,
|
|
1563
|
+
saveFile: saveFile$1,
|
|
1564
|
+
saveFileSync,
|
|
1565
|
+
stat,
|
|
1566
|
+
statSync,
|
|
1567
|
+
truncate,
|
|
1568
|
+
truncateSync,
|
|
1569
|
+
unlink,
|
|
1570
|
+
unlinkSync,
|
|
1571
|
+
unzip,
|
|
1572
|
+
write,
|
|
1573
|
+
writeFile,
|
|
1574
|
+
writeFileSync,
|
|
1575
|
+
writeSync
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
/**
|
|
1580
|
+
* HarmonyOS 文档:
|
|
1581
|
+
* https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-fileio-0000001168366687
|
|
1582
|
+
*
|
|
1583
|
+
* WX 文档:
|
|
1584
|
+
* https://developers.weixin.qq.com/miniprogram/dev/api/file/wx.saveFileToDisk.html
|
|
1585
|
+
*
|
|
1586
|
+
* Taro.js 文档
|
|
1587
|
+
* https://taro-docs.jd.com/taro/docs/apis/files/saveFileToDisk
|
|
1588
|
+
*
|
|
1589
|
+
* HarmonyOS 不支持接口:
|
|
1590
|
+
* saveFileToDisk
|
|
1591
|
+
*
|
|
1592
|
+
* HarmonyOS 差异性接口:
|
|
1593
|
+
* openDocument:showMenu、type 选项无效
|
|
1594
|
+
* getSavedFileList:返回值 fileList 中的每一项不包含 createTime 属性
|
|
1595
|
+
* getSavedFileInfo:返回值不包含 createTime 属性
|
|
1596
|
+
*/
|
|
1597
|
+
const filePathSchema = {
|
|
1598
|
+
filePath: 'String'
|
|
1599
|
+
};
|
|
1600
|
+
const saveFileToDisk = temporarilyNotSupport('saveFileToDisk');
|
|
1601
|
+
/**
|
|
1602
|
+
* HarmonyOS 不支持 showMenu 选项,并且 type 目前仅支持 *,详情参见:
|
|
1603
|
+
* https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-document-0000001168936589#section9616125953711
|
|
1604
|
+
*/
|
|
1605
|
+
function openDocument(option) {
|
|
1606
|
+
return new Promise((resolve, reject) => {
|
|
1607
|
+
try {
|
|
1608
|
+
validateParams('access', option, filePathSchema);
|
|
1609
|
+
}
|
|
1610
|
+
catch (error) {
|
|
1611
|
+
const res = { errMsg: error.message };
|
|
1612
|
+
return callAsyncFail(reject, res, option);
|
|
1613
|
+
}
|
|
1614
|
+
document.show(option.filePath, '*', (error) => {
|
|
1615
|
+
if (error) {
|
|
1616
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1617
|
+
return callAsyncFail(reject, res, option);
|
|
1618
|
+
}
|
|
1619
|
+
else {
|
|
1620
|
+
callAsyncSuccess(resolve, undefined, option);
|
|
1621
|
+
}
|
|
1622
|
+
});
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
function saveFile(option) {
|
|
1626
|
+
return new Promise((resolve, reject) => {
|
|
1627
|
+
const fileSystemManager = getFileSystemManager();
|
|
1628
|
+
fileSystemManager.saveFile({
|
|
1629
|
+
tempFilePath: option.tempFilePath,
|
|
1630
|
+
filePath: option.filePath,
|
|
1631
|
+
success: (res) => {
|
|
1632
|
+
callAsyncSuccess(resolve, res, option);
|
|
1633
|
+
},
|
|
1634
|
+
fail: (res) => {
|
|
1635
|
+
callAsyncFail(reject, res, option);
|
|
1636
|
+
}
|
|
1637
|
+
});
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
function removeSavedFile(option) {
|
|
1641
|
+
return new Promise((resolve, reject) => {
|
|
1642
|
+
const fileSystemManager = getFileSystemManager();
|
|
1643
|
+
fileSystemManager.removeSavedFile({
|
|
1644
|
+
filePath: option.filePath,
|
|
1645
|
+
success: (res) => {
|
|
1646
|
+
callAsyncSuccess(resolve, res, option);
|
|
1647
|
+
},
|
|
1648
|
+
fail: (res) => {
|
|
1649
|
+
callAsyncFail(reject, res, option);
|
|
1650
|
+
}
|
|
1651
|
+
});
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
function getFileInfo(option) {
|
|
1655
|
+
return new Promise((resolve, reject) => {
|
|
1656
|
+
const fileSystemManager = getFileSystemManager();
|
|
1657
|
+
fileSystemManager.getFileInfo({
|
|
1658
|
+
filePath: option.filePath,
|
|
1659
|
+
success: ({ size }) => {
|
|
1660
|
+
var _a;
|
|
1661
|
+
fileio.hash(option.filePath, (_a = option.digestAlgorithm) !== null && _a !== void 0 ? _a : 'md5').then((digest) => {
|
|
1662
|
+
callAsyncSuccess(resolve, { size, digest }, option);
|
|
1663
|
+
}).catch((error) => {
|
|
1664
|
+
const res = { errMsg: error.message ? error.message : error };
|
|
1665
|
+
callAsyncFail(reject, res, option);
|
|
1666
|
+
});
|
|
1667
|
+
},
|
|
1668
|
+
fail: (res) => {
|
|
1669
|
+
callAsyncFail(reject, res, option);
|
|
1670
|
+
}
|
|
1671
|
+
});
|
|
1672
|
+
});
|
|
1673
|
+
}
|
|
1674
|
+
function getSavedFileList(option) {
|
|
1675
|
+
return new Promise((resolve, reject) => {
|
|
1676
|
+
const fileSystemManager = getFileSystemManager();
|
|
1677
|
+
fileSystemManager.getSavedFileList({
|
|
1678
|
+
success: (res) => callAsyncSuccess(resolve, res, option),
|
|
1679
|
+
fail: (res) => callAsyncFail(reject, res, option)
|
|
1680
|
+
});
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
function getSavedFileInfo(option) {
|
|
1684
|
+
return new Promise((resolve, reject) => {
|
|
1685
|
+
try {
|
|
1686
|
+
validateParams('getSavedFileInfo', option, filePathSchema);
|
|
1687
|
+
validateSavedFilePath(option.filePath);
|
|
1688
|
+
}
|
|
1689
|
+
catch (error) {
|
|
1690
|
+
const res = { errMsg: error.message };
|
|
1691
|
+
return callAsyncFail(reject, res, option);
|
|
1692
|
+
}
|
|
1693
|
+
const fileSystemManager = getFileSystemManager();
|
|
1694
|
+
fileSystemManager.getFileInfo({
|
|
1695
|
+
filePath: option.filePath,
|
|
1696
|
+
success: ({ size }) => callAsyncSuccess(resolve, { size }, option),
|
|
1697
|
+
fail: (res) => callAsyncFail(reject, res, option)
|
|
1698
|
+
});
|
|
1699
|
+
});
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
const ENV_TYPE = {
|
|
1703
|
+
WEAPP: 'WEAPP',
|
|
1704
|
+
SWAN: 'SWAN',
|
|
1705
|
+
ALIPAY: 'ALIPAY',
|
|
1706
|
+
TT: 'TT',
|
|
1707
|
+
QQ: 'QQ',
|
|
1708
|
+
JD: 'JD',
|
|
1709
|
+
WEB: 'WEB',
|
|
1710
|
+
RN: 'RN',
|
|
1711
|
+
HARMONY: 'HARMONY',
|
|
1712
|
+
QUICKAPP: 'QUICKAPP'
|
|
1713
|
+
};
|
|
1714
|
+
function getEnv() {
|
|
1715
|
+
return ENV_TYPE.HARMONY;
|
|
1716
|
+
}
|
|
1717
|
+
const getCurrentInstance = () => Current;
|
|
1718
|
+
const nextTick = (cb, ctx) => {
|
|
1719
|
+
setTimeout(function () {
|
|
1720
|
+
ctx ? cb.call(ctx) : cb();
|
|
1721
|
+
}, 1);
|
|
1722
|
+
};
|
|
1723
|
+
const requirePlugin$1 = temporarilyNotSupport('requirePlugin');
|
|
1724
|
+
|
|
1725
|
+
// HarmonyOS 文档: https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-geolocation-0000001199568865#section13752433138
|
|
1726
|
+
// WX 文档: https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.onLocationChange.html
|
|
1727
|
+
// ✅ wx.offLocationChange
|
|
1728
|
+
// ✅ wx.getLocation
|
|
1729
|
+
// ✅ wx.onLocationChange
|
|
1730
|
+
// 不支持实现
|
|
1731
|
+
// ❌ wx.startLocationUpdateBackground
|
|
1732
|
+
// ❌ wx.onLocationChangeError
|
|
1733
|
+
// ❌ wx.offLocationChangeError
|
|
1734
|
+
// ❌ wx.openLocation 地图相关
|
|
1735
|
+
// ❌ wx.choosePoi 地图相关
|
|
1736
|
+
// ❌ wx.chooseLocation 地图相关
|
|
1737
|
+
// ❌ wx.stopLocationUpdate
|
|
1738
|
+
// ❌ wx.startLocationUpdate
|
|
1739
|
+
function formatLocation(location) {
|
|
1740
|
+
const locationWX = {
|
|
1741
|
+
latitude: location.latitude,
|
|
1742
|
+
longitude: location.longitude,
|
|
1743
|
+
altitude: location.altitude,
|
|
1744
|
+
accuracy: location.accuracy,
|
|
1745
|
+
speed: location.speed,
|
|
1746
|
+
verticalAccuracy: 0,
|
|
1747
|
+
horizontalAccuracy: 0 // OHOS 不支持返回此参数,直接设置为默认值
|
|
1748
|
+
};
|
|
1749
|
+
return locationWX;
|
|
1750
|
+
}
|
|
1751
|
+
// TODO:增加参数校验
|
|
1752
|
+
// const getLocationSchema = {
|
|
1753
|
+
// type: 'String',
|
|
1754
|
+
// altitude: 'Boolean',
|
|
1755
|
+
// ishighAccuracy: 'Boolean',
|
|
1756
|
+
// highAccuracyExpireTime: 'number'
|
|
1757
|
+
// }
|
|
1758
|
+
const getLocation = function (options = {}) {
|
|
1759
|
+
return new Promise((resolve, reject) => {
|
|
1760
|
+
/**
|
|
1761
|
+
* ohos 有 priority, scenario, maxAccuracy, timeoutMs
|
|
1762
|
+
* wx 有 type, altitude, isHighAccuracy, highAccuracyExpireTime
|
|
1763
|
+
* 二者参数不一致
|
|
1764
|
+
*/
|
|
1765
|
+
const { type, altitude, isHighAccuracy, highAccuracyExpireTime } = options;
|
|
1766
|
+
const params = {
|
|
1767
|
+
type,
|
|
1768
|
+
altitude,
|
|
1769
|
+
isHighAccuracy,
|
|
1770
|
+
highAccuracyExpireTime
|
|
1771
|
+
};
|
|
1772
|
+
try {
|
|
1773
|
+
return geoLocationManager.getCurrentLocation(params).then((location) => {
|
|
1774
|
+
if (location.code !== 0) {
|
|
1775
|
+
callAsyncFail(reject, location, options);
|
|
1776
|
+
}
|
|
1777
|
+
else {
|
|
1778
|
+
const locationWX = formatLocation(location.data);
|
|
1779
|
+
callAsyncSuccess(resolve, locationWX, options);
|
|
1780
|
+
}
|
|
1781
|
+
}).catch(error => {
|
|
1782
|
+
callAsyncFail(reject, error, options);
|
|
1783
|
+
});
|
|
1784
|
+
}
|
|
1785
|
+
catch (error) {
|
|
1786
|
+
callAsyncFail(reject, error, options);
|
|
1787
|
+
}
|
|
1788
|
+
});
|
|
1789
|
+
};
|
|
1790
|
+
const onLocationChange = function (callback) {
|
|
1791
|
+
validateParams('onLocationChange', [callback], ['Function']);
|
|
1792
|
+
const requestInfo = {};
|
|
1793
|
+
geoLocationManager.on('locationChange', requestInfo, (location) => {
|
|
1794
|
+
if (location) {
|
|
1795
|
+
const locationWX = formatLocation(location);
|
|
1796
|
+
callback(locationWX);
|
|
1797
|
+
}
|
|
1798
|
+
});
|
|
1799
|
+
};
|
|
1800
|
+
const offLocationChange = function (callback) {
|
|
1801
|
+
validateParams('offLocationChange', [callback], ['Function']);
|
|
1802
|
+
geoLocationManager.off('locationChange', (location) => {
|
|
1803
|
+
const status = {
|
|
1804
|
+
errCode: 200,
|
|
1805
|
+
errMsg: location ? 'offLocationChange is off' : 'offLocationChange err'
|
|
1806
|
+
};
|
|
1807
|
+
if (callback) {
|
|
1808
|
+
callback(status);
|
|
1809
|
+
}
|
|
1810
|
+
});
|
|
1811
|
+
};
|
|
1812
|
+
|
|
1813
|
+
// HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-media-0000001103383404
|
|
1814
|
+
// WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.previewMedia.html
|
|
1815
|
+
// ✅ wx.previewMedia(Object object)
|
|
1816
|
+
// ✅ wx.chooseMedia
|
|
1817
|
+
const previewMediaSchema = {
|
|
1818
|
+
sources: 'Array'
|
|
1819
|
+
};
|
|
1820
|
+
// TODO: 扩展支持预览video
|
|
1821
|
+
const previewMedia = function (options) {
|
|
1822
|
+
return new Promise((resolve, reject) => {
|
|
1823
|
+
try {
|
|
1824
|
+
validateParams('previewMedia', options, previewMediaSchema);
|
|
1825
|
+
}
|
|
1826
|
+
catch (error) {
|
|
1827
|
+
const res = { errMsg: error.message };
|
|
1828
|
+
return callAsyncFail(reject, res, options);
|
|
1829
|
+
}
|
|
1830
|
+
const { sources, current } = options;
|
|
1831
|
+
const urls = [];
|
|
1832
|
+
for (const s of sources) {
|
|
1833
|
+
if (s.type === 'image') {
|
|
1834
|
+
urls.push(s.url);
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
const previewImageOptions = {
|
|
1838
|
+
images: urls,
|
|
1839
|
+
index: current || 0
|
|
1840
|
+
};
|
|
1841
|
+
mediaLibrary.getMediaLibrary().startImagePreview(previewImageOptions.images, previewImageOptions.index).then((value) => {
|
|
1842
|
+
callAsyncSuccess(resolve, value, options);
|
|
1843
|
+
}).catch((error) => {
|
|
1844
|
+
callAsyncFail(reject, error, options);
|
|
1845
|
+
});
|
|
1846
|
+
});
|
|
1847
|
+
};
|
|
1848
|
+
const chooseMedia = function (options) {
|
|
1849
|
+
return new Promise((resolve, reject) => {
|
|
1850
|
+
try {
|
|
1851
|
+
validateParams('chooseMedia', [options], ['Object']);
|
|
1852
|
+
}
|
|
1853
|
+
catch (error) {
|
|
1854
|
+
const res = { errMsg: error.message };
|
|
1855
|
+
return callAsyncFail(reject, res, options);
|
|
1856
|
+
}
|
|
1857
|
+
const { count = 9, mediaType = ['image'] } = options;
|
|
1858
|
+
// HarmonyOS不支持image和video同时选择
|
|
1859
|
+
// TODO: 不支持视频拍摄,无现成组件,后续需要封装
|
|
1860
|
+
const mediaSelectOptions = {
|
|
1861
|
+
count,
|
|
1862
|
+
type: mediaType[0]
|
|
1863
|
+
};
|
|
1864
|
+
mediaLibrary.getMediaLibrary().startMediaSelect(mediaSelectOptions).then((value) => {
|
|
1865
|
+
callAsyncSuccess(resolve, value, options);
|
|
1866
|
+
}).catch((error) => {
|
|
1867
|
+
callAsyncFail(reject, error, options);
|
|
1868
|
+
});
|
|
1869
|
+
});
|
|
1870
|
+
};
|
|
1871
|
+
|
|
1872
|
+
// HarmonyOS 图片模块首批接口从API version 7开始支持。
|
|
1873
|
+
// HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-image-0000001122977382
|
|
1874
|
+
// WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.saveImageToPhotosAlbum.html
|
|
1875
|
+
// ✅ wx.getImageInfo(Object object) API7以上支持
|
|
1876
|
+
// ✅ wx.compressImage(Object object) API7以上支持
|
|
1877
|
+
// ✅ wx.chooseImage(Object object)
|
|
1878
|
+
// ❌ wx.chooseMessageFile(Object object) HarmonyOS不支持
|
|
1879
|
+
// ❌ wx.saveImageToPhotosAlbum(Object object) api 9+ HarmonyOS不支持
|
|
1880
|
+
// ❌ wx.previewImage(Object object) api 9+ HarmonyOS不支持
|
|
1881
|
+
const getImageInfoSchema = {
|
|
1882
|
+
url: 'String'
|
|
1883
|
+
};
|
|
1884
|
+
const compressImageSchema = {
|
|
1885
|
+
url: 'String'
|
|
1886
|
+
};
|
|
1887
|
+
const chooseImageSchema = {
|
|
1888
|
+
count: 'Number'
|
|
1889
|
+
};
|
|
1890
|
+
const photoSelectOptions = new picker.PhotoSelectOptions();
|
|
1891
|
+
const getImageInfo = function (options) {
|
|
1892
|
+
return new Promise((resolve, reject) => {
|
|
1893
|
+
try {
|
|
1894
|
+
validateParams('getImageInfo', options, getImageInfoSchema);
|
|
1895
|
+
}
|
|
1896
|
+
catch (error) {
|
|
1897
|
+
const res = { errMsg: error.message };
|
|
1898
|
+
return callAsyncFail(reject, res, options);
|
|
1899
|
+
}
|
|
1900
|
+
const { src } = options;
|
|
1901
|
+
// FIX: 调试发现在版本api7中 source 为 undefined, 需鸿蒙侧确认
|
|
1902
|
+
const source = image.createImageSource(src);
|
|
1903
|
+
if (isNull(source)) {
|
|
1904
|
+
const createImageSourceError = { errMsg: 'getImageInfo fail: createImageSource has failed.' };
|
|
1905
|
+
callAsyncFail(reject, createImageSourceError, options);
|
|
1906
|
+
return;
|
|
1907
|
+
}
|
|
1908
|
+
source.getImageInfo().then((value) => {
|
|
1909
|
+
callAsyncSuccess(resolve, value, options);
|
|
1910
|
+
}).catch((error) => {
|
|
1911
|
+
callAsyncFail(reject, error, options);
|
|
1912
|
+
});
|
|
1913
|
+
});
|
|
1914
|
+
};
|
|
1915
|
+
const compressImage = function (options) {
|
|
1916
|
+
return new Promise((resolve, reject) => {
|
|
1917
|
+
try {
|
|
1918
|
+
validateParams('compressImage', options, compressImageSchema);
|
|
1919
|
+
}
|
|
1920
|
+
catch (error) {
|
|
1921
|
+
const res = { errMsg: error.message };
|
|
1922
|
+
return callAsyncFail(reject, res, options);
|
|
1923
|
+
}
|
|
1924
|
+
const { src, quality = 80 } = options;
|
|
1925
|
+
const source = image.createImageSource(src);
|
|
1926
|
+
if (isNull(source)) {
|
|
1927
|
+
const createImageSourceError = { errMsg: 'compressImage fail: createImageSource has failed.' };
|
|
1928
|
+
callAsyncFail(reject, createImageSourceError, options);
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
const packer = image.createImagePacker(src);
|
|
1932
|
+
if (isNull(packer)) {
|
|
1933
|
+
const createImagePackerError = { errMsg: 'compressImage fail: createImagePacker has failed.' };
|
|
1934
|
+
callAsyncFail(reject, createImagePackerError, options);
|
|
1935
|
+
}
|
|
1936
|
+
const packingOptionsOHOS = {
|
|
1937
|
+
// TODO:需要获取文件名后缀
|
|
1938
|
+
format: 'image/jpeg',
|
|
1939
|
+
quality: quality
|
|
1940
|
+
};
|
|
1941
|
+
packer.packing(source, packingOptionsOHOS).then((value) => {
|
|
1942
|
+
callAsyncSuccess(resolve, value, options);
|
|
1943
|
+
}).catch((error) => {
|
|
1944
|
+
callAsyncFail(reject, error, options);
|
|
1945
|
+
});
|
|
1946
|
+
});
|
|
1947
|
+
};
|
|
1948
|
+
const chooseImage = function (options) {
|
|
1949
|
+
return new Promise((resolve, reject) => {
|
|
1950
|
+
try {
|
|
1951
|
+
validateParams('chooseImage', options, chooseImageSchema);
|
|
1952
|
+
}
|
|
1953
|
+
catch (error) {
|
|
1954
|
+
const res = { errMsg: error.message };
|
|
1955
|
+
return callAsyncFail(reject, res, options);
|
|
1956
|
+
}
|
|
1957
|
+
const { count = 9 } = options;
|
|
1958
|
+
const photoViewPicker = new picker.PhotoViewPicker();
|
|
1959
|
+
photoSelectOptions.maxSelectNumber = count; // 选择媒体文件的最大数目
|
|
1960
|
+
photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE
|
|
1961
|
+
photoViewPicker.select(photoSelectOptions).then((photoSelectResult) => {
|
|
1962
|
+
callAsyncSuccess(resolve, { tempFilePaths: photoSelectResult.photoUris });
|
|
1963
|
+
}).catch((error) => {
|
|
1964
|
+
callAsyncFail(reject, error, options);
|
|
1965
|
+
});
|
|
1966
|
+
});
|
|
1967
|
+
};
|
|
1968
|
+
const previewImage = temporarilyNotSupport('previewImage');
|
|
1969
|
+
const saveImageToPhotosAlbum = temporarilyNotSupport('saveImageToPhotosAlbum');
|
|
1970
|
+
|
|
1971
|
+
// HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-media-0000001103383404
|
|
1972
|
+
// WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/media/video/wx.chooseVideo.html
|
|
1973
|
+
// ✅ wx.saveVideoToPhotosAlbum
|
|
1974
|
+
// ❌ wx.openVideoEditor
|
|
1975
|
+
// ❌ wx.getVideoInfo
|
|
1976
|
+
// ❌ wx.createVideoContext
|
|
1977
|
+
// ❌ wx.compressVideo
|
|
1978
|
+
// ✅ wx.chooseVideo
|
|
1979
|
+
// VideoContext
|
|
1980
|
+
// ❌ VideoContext.exitBackgroundPlayback
|
|
1981
|
+
// ❌ VideoContext.exitFullScreen
|
|
1982
|
+
// ❌ VideoContext.exitPictureInPicture
|
|
1983
|
+
// ❌ VideoContext.hideStatusBar
|
|
1984
|
+
// ❌ VideoContext.pause
|
|
1985
|
+
// ❌ VideoContext.play
|
|
1986
|
+
// ❌ VideoContext.playbackRate
|
|
1987
|
+
// ❌ VideoContext.requestBackgroundPlayback
|
|
1988
|
+
// ❌ VideoContext.requestFullScreen
|
|
1989
|
+
// ❌ VideoContext.seek
|
|
1990
|
+
// ❌ VideoContext.sendDanmu
|
|
1991
|
+
// ❌ VideoContext.showStatusBar
|
|
1992
|
+
// ❌ VideoContext.stop
|
|
1993
|
+
const saveVideoToPhotosAlbumSchema = {
|
|
1994
|
+
filePath: 'String'
|
|
1995
|
+
};
|
|
1996
|
+
// TODO: 1.返回属性补全
|
|
1997
|
+
// TODO: 2.只支持从相册选择,补充摄像头拍摄功能,需要HarmonyOS提供选择组件
|
|
1998
|
+
const chooseVideo = function (options = {}) {
|
|
1999
|
+
return new Promise((resolve, reject) => {
|
|
2000
|
+
try {
|
|
2001
|
+
validateParams('chooseVideo', [options], ['Object']);
|
|
2002
|
+
}
|
|
2003
|
+
catch (error) {
|
|
2004
|
+
const res = { errMsg: error.message };
|
|
2005
|
+
return callAsyncFail(reject, res, options);
|
|
2006
|
+
}
|
|
2007
|
+
const chooseVideoOptionsOHOS = {
|
|
2008
|
+
type: 'video',
|
|
2009
|
+
count: 1
|
|
2010
|
+
};
|
|
2011
|
+
mediaLibrary.getMediaLibrary().startMediaSelect(chooseVideoOptionsOHOS).then((value) => {
|
|
2012
|
+
callAsyncSuccess(resolve, { tempFilePaths: value });
|
|
2013
|
+
}).catch((error) => {
|
|
2014
|
+
callAsyncFail(reject, error, options);
|
|
2015
|
+
});
|
|
2016
|
+
});
|
|
2017
|
+
};
|
|
2018
|
+
const saveVideoToPhotosAlbum = function (options) {
|
|
2019
|
+
return new Promise((resolve, reject) => {
|
|
2020
|
+
try {
|
|
2021
|
+
validateParams('saveVideoToPhotosAlbum', options, saveVideoToPhotosAlbumSchema);
|
|
2022
|
+
}
|
|
2023
|
+
catch (error) {
|
|
2024
|
+
const res = { errMsg: error.message };
|
|
2025
|
+
return callAsyncFail(reject, res, options);
|
|
2026
|
+
}
|
|
2027
|
+
const { filePath } = options;
|
|
2028
|
+
const saveVideoToPhotosAlbumOptions = {
|
|
2029
|
+
src: filePath,
|
|
2030
|
+
// TODO:需要获取文件名后缀,'video/mp4'、'video/3gpp'等
|
|
2031
|
+
mimeType: 'video/mp4'
|
|
2032
|
+
};
|
|
2033
|
+
mediaLibrary.getMediaLibrary().storeMediaAsset(saveVideoToPhotosAlbumOptions).then((value) => {
|
|
2034
|
+
callAsyncSuccess(resolve, value, options);
|
|
2035
|
+
}).catch((error) => {
|
|
2036
|
+
callAsyncFail(reject, error, options);
|
|
2037
|
+
});
|
|
2038
|
+
});
|
|
2039
|
+
};
|
|
2040
|
+
|
|
2041
|
+
// 跳转
|
|
2042
|
+
const openEmbeddedMiniProgram = /* @__PURE__ */ temporarilyNotSupport('openEmbeddedMiniProgram');
|
|
2043
|
+
const navigateToMiniProgram = /* @__PURE__ */ temporarilyNotSupport('navigateToMiniProgram');
|
|
2044
|
+
const navigateBackMiniProgram = /* @__PURE__ */ temporarilyNotSupport('navigateBackMiniProgram');
|
|
2045
|
+
const exitMiniProgram = /* @__PURE__ */ temporarilyNotSupport('exitMiniProgram');
|
|
2046
|
+
const openBusinessView = /* @__PURE__ */ temporarilyNotSupport('openBusinessView');
|
|
2047
|
+
|
|
2048
|
+
// HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-request-0000001123753962#section455311474372
|
|
2049
|
+
// WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/network/download/wx.downloadFile.html
|
|
2050
|
+
// ✅ wx.downloadFile (BETA)7+,因为使用了 query 和 on('complete')
|
|
2051
|
+
// ✅ DownloadTask.abort
|
|
2052
|
+
// ✅ DownloadTask.offProgressUpdate
|
|
2053
|
+
// ✅ DownloadTask.onProgressUpdate
|
|
2054
|
+
// ❌ DownloadTask.onHeadersReceived 此接口 ohos 不支持
|
|
2055
|
+
// ❌ DownloadTask.offHeadersReceived 此接口 ohos 不支持
|
|
2056
|
+
const downloadFileSchema = {
|
|
2057
|
+
url: 'String'
|
|
2058
|
+
};
|
|
2059
|
+
const downloadFile = function (options) {
|
|
2060
|
+
let downloadTask = {};
|
|
2061
|
+
const downloadTaskWX = new Promise((resolve, reject) => {
|
|
2062
|
+
const { url, header, filePath } = options;
|
|
2063
|
+
try {
|
|
2064
|
+
validateParams('downloadFile', options, downloadFileSchema);
|
|
2065
|
+
}
|
|
2066
|
+
catch (error) {
|
|
2067
|
+
const res = { errMsg: error.message };
|
|
2068
|
+
return callAsyncFail(reject, res, options);
|
|
2069
|
+
}
|
|
2070
|
+
const ohosParams = {
|
|
2071
|
+
url
|
|
2072
|
+
};
|
|
2073
|
+
if (header)
|
|
2074
|
+
ohosParams.header = header;
|
|
2075
|
+
if (filePath)
|
|
2076
|
+
ohosParams.filePath = filePath;
|
|
2077
|
+
request$1.download(ohosParams).then((dataDownload) => {
|
|
2078
|
+
downloadTask = dataDownload;
|
|
2079
|
+
// TODO: 建议鸿蒙优化 complete 回调接口。
|
|
2080
|
+
// ohos 的 complete 回调不返回任何下载信息,需要调用 query 查询后,在 complete 和 fail 中调用回调返回
|
|
2081
|
+
downloadTask.query().then(dataQuery => {
|
|
2082
|
+
downloadTask.on('complete', () => {
|
|
2083
|
+
dataQuery.status = dataQuery.statusCode;
|
|
2084
|
+
callAsyncSuccess(resolve, dataQuery, options);
|
|
2085
|
+
});
|
|
2086
|
+
downloadTask.on('fail', (err) => {
|
|
2087
|
+
const res = {
|
|
2088
|
+
errMsg: err
|
|
2089
|
+
};
|
|
2090
|
+
callAsyncFail(reject, res, options);
|
|
2091
|
+
});
|
|
2092
|
+
}).catch((err) => {
|
|
2093
|
+
callAsyncFail(reject, err, options);
|
|
2094
|
+
});
|
|
2095
|
+
}).catch((err) => {
|
|
2096
|
+
callAsyncFail(reject, err, options);
|
|
2097
|
+
});
|
|
2098
|
+
});
|
|
2099
|
+
downloadTaskWX.abort = function () {
|
|
2100
|
+
downloadTask.remove((err, data) => {
|
|
2101
|
+
if (err) {
|
|
2102
|
+
return err;
|
|
2103
|
+
}
|
|
2104
|
+
return data;
|
|
2105
|
+
});
|
|
2106
|
+
};
|
|
2107
|
+
downloadTaskWX.offProgressUpdate = function offProgressUpdate(callback) {
|
|
2108
|
+
validateParams('offProgressUpdate', [callback], ['Function']);
|
|
2109
|
+
downloadTask.off('progress', (receivedSize, totalSize) => {
|
|
2110
|
+
const totalBytesWritten = receivedSize * 1024;
|
|
2111
|
+
const totalBytesExpectedToWrite = totalSize * 1024;
|
|
2112
|
+
// TODO: 进度应该保留几位小数?暂时保留6位
|
|
2113
|
+
const progress = +(receivedSize / totalSize).toFixed(6);
|
|
2114
|
+
const progressParams = {
|
|
2115
|
+
totalBytesWritten,
|
|
2116
|
+
totalBytesExpectedToWrite,
|
|
2117
|
+
progress,
|
|
2118
|
+
errMsg: 'Cancel progress listening is done.'
|
|
2119
|
+
};
|
|
2120
|
+
callback(progressParams);
|
|
2121
|
+
});
|
|
2122
|
+
};
|
|
2123
|
+
// wx 单位是 Bytes,ohos 单位是 KBytes
|
|
2124
|
+
downloadTaskWX.onProgressUpdate = function (callback) {
|
|
2125
|
+
validateParams('onProgressUpdate', [callback], ['Function']);
|
|
2126
|
+
downloadTask.on('progress', (receivedSize, totalSize) => {
|
|
2127
|
+
const totalBytesWritten = receivedSize * 1024;
|
|
2128
|
+
const totalBytesExpectedToWrite = totalSize * 1024;
|
|
2129
|
+
// TODO: 进度应该保留几位小数?暂时保留6位
|
|
2130
|
+
const progress = +(receivedSize / totalSize).toFixed(6);
|
|
2131
|
+
const progressParams = {
|
|
2132
|
+
totalBytesWritten,
|
|
2133
|
+
totalBytesExpectedToWrite,
|
|
2134
|
+
progress
|
|
2135
|
+
};
|
|
2136
|
+
callback(progressParams);
|
|
2137
|
+
});
|
|
2138
|
+
};
|
|
2139
|
+
return downloadTaskWX;
|
|
2140
|
+
};
|
|
2141
|
+
|
|
2142
|
+
// HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-net-http-0000001168304341
|
|
2143
|
+
// WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html
|
|
2144
|
+
// ✅ wx.request
|
|
2145
|
+
// ✅ RequestTask.abort
|
|
2146
|
+
// ✅ RequestTask.offHeadersReceived
|
|
2147
|
+
// ✅ RequestTask.onHeadersReceived
|
|
2148
|
+
const METHOD = ['OPTIONS', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'CONNECT'];
|
|
2149
|
+
const requestSchema = {
|
|
2150
|
+
url: 'String'
|
|
2151
|
+
};
|
|
2152
|
+
const request = function (options) {
|
|
2153
|
+
let httpRequestOhos;
|
|
2154
|
+
const requestTask = new Promise((resolve, reject) => {
|
|
2155
|
+
try {
|
|
2156
|
+
httpRequestOhos = http.createHttp();
|
|
2157
|
+
}
|
|
2158
|
+
catch (error) {
|
|
2159
|
+
const res = { errMsg: error };
|
|
2160
|
+
return callAsyncFail(reject, res, options);
|
|
2161
|
+
}
|
|
2162
|
+
const { url, method, header = {}, timeout, dataType, data } = options;
|
|
2163
|
+
try {
|
|
2164
|
+
validateParams('send', options, requestSchema);
|
|
2165
|
+
}
|
|
2166
|
+
catch (error) {
|
|
2167
|
+
const res = { errMsg: error.message };
|
|
2168
|
+
return callAsyncFail(reject, res, options);
|
|
2169
|
+
}
|
|
2170
|
+
const keyOfContentType = Object.keys(header).find(item => item.toLowerCase() === 'content-type');
|
|
2171
|
+
if (!keyOfContentType) {
|
|
2172
|
+
header['Content-Type'] = 'application/json';
|
|
2173
|
+
}
|
|
2174
|
+
// 检查 Header 是否有 Referer
|
|
2175
|
+
if (isUndefined(header.Referer)) {
|
|
2176
|
+
const error = { errMsg: 'request fail parameter error: the header doesn‘t support Referer property' };
|
|
2177
|
+
callAsyncFail(reject, error, options);
|
|
2178
|
+
}
|
|
2179
|
+
// 检查 method 是否正确
|
|
2180
|
+
if (method) {
|
|
2181
|
+
if (!METHOD.includes(method)) {
|
|
2182
|
+
const error = { errMsg: `request fail parameter error: the method value should be one of the ${METHOD.join(',')}` };
|
|
2183
|
+
callAsyncFail(reject, error, options);
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
const requestParamsOHOS = {
|
|
2187
|
+
method,
|
|
2188
|
+
header,
|
|
2189
|
+
extraData: data,
|
|
2190
|
+
readTimeout: timeout,
|
|
2191
|
+
connectTimeout: timeout
|
|
2192
|
+
};
|
|
2193
|
+
httpRequestOhos.request(url, requestParamsOHOS).then((requestData) => {
|
|
2194
|
+
const reswx = {
|
|
2195
|
+
data: dataType === 'json' && isString(requestData.result) ? JSON.parse(requestData.result) : requestData.result,
|
|
2196
|
+
statusCode: requestData.responseCode,
|
|
2197
|
+
header: requestData.header
|
|
2198
|
+
};
|
|
2199
|
+
callAsyncSuccess(resolve, reswx, options);
|
|
2200
|
+
}).catch(error => {
|
|
2201
|
+
callAsyncFail(reject, error, options);
|
|
2202
|
+
});
|
|
2203
|
+
});
|
|
2204
|
+
requestTask.abort = function () {
|
|
2205
|
+
httpRequestOhos.destroy();
|
|
2206
|
+
};
|
|
2207
|
+
requestTask.onHeadersReceived = function (callback) {
|
|
2208
|
+
validateParams('onHeadersReceived', [callback], ['Function']);
|
|
2209
|
+
httpRequestOhos.on('headerReceive', (err, res) => {
|
|
2210
|
+
callback(!err ? res : err);
|
|
2211
|
+
});
|
|
2212
|
+
};
|
|
2213
|
+
requestTask.offHeadersReceived = function (callback) {
|
|
2214
|
+
validateParams('offHeadersReceived', [callback], ['Function']);
|
|
2215
|
+
httpRequestOhos.off('headerReceive', (err, res) => {
|
|
2216
|
+
callback(!err ? res : err);
|
|
2217
|
+
});
|
|
2218
|
+
};
|
|
2219
|
+
return requestTask;
|
|
2220
|
+
};
|
|
2221
|
+
|
|
2222
|
+
// HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-request-0000001123753962#section455311474372
|
|
2223
|
+
// WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/wx.uploadFile.html
|
|
2224
|
+
// ✅ wx.uploadFile
|
|
2225
|
+
// ✅ UploadTask.abort
|
|
2226
|
+
// ✅ UploadTask.offHeadersReceived (BETA)7+
|
|
2227
|
+
// ✅ UploadTask.offProgressUpdate
|
|
2228
|
+
// ✅ UploadTask.onHeadersReceived(BETA)7+
|
|
2229
|
+
// ✅ UploadTask.onProgressUpdate
|
|
2230
|
+
const uploadSchema = {
|
|
2231
|
+
url: 'String'
|
|
2232
|
+
// filePath: 'String',
|
|
2233
|
+
// name: 'String'
|
|
2234
|
+
};
|
|
2235
|
+
// wx 只支持 HTTP POST 请求,OHOS 支持 POST 和 PUT 请求
|
|
2236
|
+
// OHOS 不支持 wx 的 timeout,但是支持 file 文件列表上传,wx 是单文件上传
|
|
2237
|
+
const uploadFile = function (options) {
|
|
2238
|
+
let uploadTask = {};
|
|
2239
|
+
const UploadTaskWX = new Promise((resolve, reject) => {
|
|
2240
|
+
let timer;
|
|
2241
|
+
const { url, filePath, name, header, formData, timeout } = options;
|
|
2242
|
+
try {
|
|
2243
|
+
validateParams('uploadFile', options, uploadSchema);
|
|
2244
|
+
}
|
|
2245
|
+
catch (error) {
|
|
2246
|
+
const res = { errMsg: error.message };
|
|
2247
|
+
return callAsyncFail(reject, res, options);
|
|
2248
|
+
}
|
|
2249
|
+
const file = {
|
|
2250
|
+
url: filePath,
|
|
2251
|
+
name
|
|
2252
|
+
};
|
|
2253
|
+
const files = [file];
|
|
2254
|
+
const ohosParams = {
|
|
2255
|
+
url,
|
|
2256
|
+
files,
|
|
2257
|
+
method: 'POST',
|
|
2258
|
+
header
|
|
2259
|
+
};
|
|
2260
|
+
if (formData) {
|
|
2261
|
+
const rData = [];
|
|
2262
|
+
Object.keys(formData).forEach((key) => {
|
|
2263
|
+
const rDataEle = {
|
|
2264
|
+
name: key,
|
|
2265
|
+
value: formData[key]
|
|
2266
|
+
};
|
|
2267
|
+
rData.push(rDataEle);
|
|
2268
|
+
});
|
|
2269
|
+
ohosParams.data = rData;
|
|
2270
|
+
}
|
|
2271
|
+
if (!isUndefined(timeout)) {
|
|
2272
|
+
timer = setTimeout(() => {
|
|
2273
|
+
const err = {
|
|
2274
|
+
errMsg: 'uploadFile request timeout, please try again later.'
|
|
2275
|
+
};
|
|
2276
|
+
callAsyncFail(reject, err, options);
|
|
2277
|
+
}, timeout);
|
|
2278
|
+
}
|
|
2279
|
+
request$1.upload(ohosParams).then((dataUpload) => {
|
|
2280
|
+
if (timer) {
|
|
2281
|
+
clearTimeout(timer);
|
|
2282
|
+
}
|
|
2283
|
+
uploadTask = dataUpload;
|
|
2284
|
+
callAsyncSuccess(resolve, UploadTaskWX, options);
|
|
2285
|
+
}).catch((err) => {
|
|
2286
|
+
if (timer) {
|
|
2287
|
+
clearTimeout(timer);
|
|
2288
|
+
}
|
|
2289
|
+
callAsyncFail(reject, err, options);
|
|
2290
|
+
});
|
|
2291
|
+
});
|
|
2292
|
+
UploadTaskWX.abort = function () {
|
|
2293
|
+
uploadTask.remove((err, result) => {
|
|
2294
|
+
if (err || result) {
|
|
2295
|
+
return err || result;
|
|
2296
|
+
}
|
|
2297
|
+
return result;
|
|
2298
|
+
});
|
|
2299
|
+
};
|
|
2300
|
+
UploadTaskWX.onHeadersReceived = function (callback) {
|
|
2301
|
+
validateParams('onHeadersReceived', [callback], ['Function']);
|
|
2302
|
+
uploadTask.on('headerReceive', (headers) => {
|
|
2303
|
+
callback(headers);
|
|
2304
|
+
});
|
|
2305
|
+
};
|
|
2306
|
+
UploadTaskWX.offHeadersReceived = function (callback) {
|
|
2307
|
+
validateParams('offHeadersReceived', [callback], ['Function']);
|
|
2308
|
+
uploadTask.off('headerReceive', (headers) => {
|
|
2309
|
+
callback(headers);
|
|
2310
|
+
});
|
|
2311
|
+
};
|
|
2312
|
+
// wx 单位是 Bytes,ohos 单位是 KBytes
|
|
2313
|
+
UploadTaskWX.onProgressUpdate = function (callback) {
|
|
2314
|
+
validateParams('onProgressUpdate', [callback], ['Function']);
|
|
2315
|
+
uploadTask.on('progress', (uploadSize, totalSize) => {
|
|
2316
|
+
const totalBytesSent = uploadSize * 1024;
|
|
2317
|
+
const totalBytesExpectedToSend = totalSize * 1024;
|
|
2318
|
+
// TODO: 进度应该保留几位小数?暂时保留6位
|
|
2319
|
+
const progress = +(uploadSize / totalSize).toFixed(6);
|
|
2320
|
+
const progressParams = {
|
|
2321
|
+
totalBytesSent,
|
|
2322
|
+
totalBytesExpectedToSend,
|
|
2323
|
+
progress
|
|
2324
|
+
};
|
|
2325
|
+
callback(progressParams);
|
|
2326
|
+
});
|
|
2327
|
+
};
|
|
2328
|
+
UploadTaskWX.offProgressUpdate = function (callback) {
|
|
2329
|
+
validateParams('offProgressUpdate', [callback], ['Function']);
|
|
2330
|
+
uploadTask.off('progress', (uploadSize, totalSize) => {
|
|
2331
|
+
const totalBytesSent = uploadSize * 1024;
|
|
2332
|
+
const totalBytesExpectedToSend = totalSize * 1024;
|
|
2333
|
+
// TODO: 进度应该保留几位小数?暂时保留6位
|
|
2334
|
+
const progress = +(uploadSize / totalSize).toFixed(6);
|
|
2335
|
+
const progressParams = {
|
|
2336
|
+
totalBytesSent,
|
|
2337
|
+
totalBytesExpectedToSend,
|
|
2338
|
+
progress,
|
|
2339
|
+
errMsg: 'Cancel progress listening is done.'
|
|
2340
|
+
};
|
|
2341
|
+
callback(progressParams);
|
|
2342
|
+
});
|
|
2343
|
+
};
|
|
2344
|
+
return UploadTaskWX;
|
|
2345
|
+
};
|
|
2346
|
+
|
|
2347
|
+
// OpenHarmony 不支持全局操作 WebSocket
|
|
2348
|
+
// HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-net-websocket-0000001168304641
|
|
2349
|
+
// WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.sendSocketMessage.html
|
|
2350
|
+
// ✅ wx.connectSocket
|
|
2351
|
+
// ✅ SocketTask
|
|
2352
|
+
// ✅ SocketTask.close
|
|
2353
|
+
// ✅ SocketTask.onClose
|
|
2354
|
+
// ✅ SocketTask.onError
|
|
2355
|
+
// ✅ SocketTask.onMessage
|
|
2356
|
+
// ✅ SocketTask.onOpen
|
|
2357
|
+
// ✅ SocketTask.send
|
|
2358
|
+
// ❌ wx.sendSocketMessage
|
|
2359
|
+
// ❌ wx.onSocketOpen
|
|
2360
|
+
// ❌ wx.onSocketMessage
|
|
2361
|
+
// ❌ wx.onSocketError
|
|
2362
|
+
// ❌ wx.onSocketClose
|
|
2363
|
+
// ❌ wx.closeSocket
|
|
2364
|
+
const connectSocketSchema = {
|
|
2365
|
+
url: 'String'
|
|
2366
|
+
};
|
|
2367
|
+
// const closetSocketSchema = {
|
|
2368
|
+
// code: 'Number',
|
|
2369
|
+
// reason: 'String'
|
|
2370
|
+
// }
|
|
2371
|
+
const sendSocketSchema = {
|
|
2372
|
+
data: 'String'
|
|
2373
|
+
};
|
|
2374
|
+
const connectSocket = function (options) {
|
|
2375
|
+
let ws;
|
|
2376
|
+
const SocketTaskWX = new Promise((resolve, reject) => {
|
|
2377
|
+
ws = webSocket.createWebSocket();
|
|
2378
|
+
const { url, header } = options;
|
|
2379
|
+
try {
|
|
2380
|
+
validateParams('uploadFile', options, connectSocketSchema);
|
|
2381
|
+
}
|
|
2382
|
+
catch (error) {
|
|
2383
|
+
const res = { errMsg: error.message };
|
|
2384
|
+
return callAsyncFail(reject, res, options);
|
|
2385
|
+
}
|
|
2386
|
+
ws.connect(url, { header }).then((value) => {
|
|
2387
|
+
callAsyncSuccess(resolve, value, options);
|
|
2388
|
+
}).catch((err) => {
|
|
2389
|
+
callAsyncFail(reject, err, options);
|
|
2390
|
+
});
|
|
2391
|
+
});
|
|
2392
|
+
SocketTaskWX.close = function (closeOptions) {
|
|
2393
|
+
return new Promise((resolve, reject) => {
|
|
2394
|
+
// TODO: 检验非必须参数
|
|
2395
|
+
// try {
|
|
2396
|
+
// validateParams('close', options, closeSocketSchema)
|
|
2397
|
+
// } catch (error) {
|
|
2398
|
+
// const res = { errMsg: error.message }
|
|
2399
|
+
// return callAsyncFail(reject, res, options)
|
|
2400
|
+
// }
|
|
2401
|
+
ws.close(closeOptions).then(value => {
|
|
2402
|
+
callAsyncSuccess(resolve, value, closeOptions);
|
|
2403
|
+
}, error => {
|
|
2404
|
+
callAsyncFail(reject, error, closeOptions);
|
|
2405
|
+
});
|
|
2406
|
+
});
|
|
2407
|
+
};
|
|
2408
|
+
SocketTaskWX.onClose = function (onCloseCallback) {
|
|
2409
|
+
validateParams('onClose', [onCloseCallback], ['Function']);
|
|
2410
|
+
ws.on('close', (err, value) => {
|
|
2411
|
+
onCloseCallback(!err ? value : err);
|
|
2412
|
+
});
|
|
2413
|
+
};
|
|
2414
|
+
SocketTaskWX.onError = function (onErrorCallback) {
|
|
2415
|
+
validateParams('onError', [onErrorCallback], ['Function']);
|
|
2416
|
+
ws.on('error', (err) => {
|
|
2417
|
+
onErrorCallback(err);
|
|
2418
|
+
});
|
|
2419
|
+
};
|
|
2420
|
+
SocketTaskWX.onMessage = function (onMessageCallback) {
|
|
2421
|
+
validateParams('onMessage', [onMessageCallback], ['Function']);
|
|
2422
|
+
ws.on('onMessage', (err, value) => {
|
|
2423
|
+
onMessageCallback(!err ? value : err);
|
|
2424
|
+
});
|
|
2425
|
+
};
|
|
2426
|
+
SocketTaskWX.onOpen = function (onOpenCallback) {
|
|
2427
|
+
validateParams('onOpen', [onOpenCallback], ['Function']);
|
|
2428
|
+
ws.on('open', (err, value) => {
|
|
2429
|
+
// TODO:返回数据字段完全不一样,无法兼容,暂不处理
|
|
2430
|
+
// wx:{header, profile}, ohos:{err, value:{status, message}}
|
|
2431
|
+
onOpenCallback(!err ? value : err);
|
|
2432
|
+
});
|
|
2433
|
+
};
|
|
2434
|
+
SocketTaskWX.send = function (sendOptions) {
|
|
2435
|
+
return new Promise((resolve, reject) => {
|
|
2436
|
+
const { data } = sendOptions;
|
|
2437
|
+
try {
|
|
2438
|
+
validateParams('send', sendOptions, sendSocketSchema);
|
|
2439
|
+
}
|
|
2440
|
+
catch (error) {
|
|
2441
|
+
const res = { errMsg: error.message };
|
|
2442
|
+
return callAsyncFail(reject, res, options);
|
|
2443
|
+
}
|
|
2444
|
+
ws.send(data).then(value => {
|
|
2445
|
+
callAsyncSuccess(resolve, value, sendOptions);
|
|
2446
|
+
}, error => {
|
|
2447
|
+
callAsyncFail(reject, error, sendOptions);
|
|
2448
|
+
});
|
|
2449
|
+
});
|
|
2450
|
+
};
|
|
2451
|
+
return SocketTaskWX;
|
|
2452
|
+
};
|
|
2453
|
+
|
|
2454
|
+
/**
|
|
2455
|
+
* 用户相关API, Harmony ACE API 6
|
|
2456
|
+
*
|
|
2457
|
+
* 1. 华为账号场景介绍文档 @see https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/harmonyos-js-login-0000001151310900
|
|
2458
|
+
* 2. 华为账号API参考 @see https://developer.huawei.com/consumer/cn/doc/development/HMSCore-References/harmonyos-js-overview-0000001063532145
|
|
2459
|
+
*/
|
|
2460
|
+
// import hmsJSAccount from '@hmscore/hms-jsb-account'
|
|
2461
|
+
/**
|
|
2462
|
+
* 通过Scope数组获取已登录的对应帐号信息(依赖login行为)
|
|
2463
|
+
* @param options
|
|
2464
|
+
*/
|
|
2465
|
+
const getUserInfo = temporarilyNotSupport('getUserInfo');
|
|
2466
|
+
// export function getUserInfo (options) {
|
|
2467
|
+
// const { success, fail, complete } = options
|
|
2468
|
+
// const res: Record<string, any> = {}
|
|
2469
|
+
// // const result = hmsJSAccount.HuaweiIdAuthManager.getAuthResultWithScopes([hmsJSAccount.PROFILE])
|
|
2470
|
+
// const result = null
|
|
2471
|
+
// if (result) {
|
|
2472
|
+
// res.data = { userInfo: generateUserInfo(result) }
|
|
2473
|
+
// isFunction(success) && success(res)
|
|
2474
|
+
// } else {
|
|
2475
|
+
// res.errorMsg = 'getUserInfo result data is null'
|
|
2476
|
+
// isFunction(fail) && fail(res)
|
|
2477
|
+
// }
|
|
2478
|
+
// isFunction(complete) && complete(res)
|
|
2479
|
+
// }
|
|
2480
|
+
/**
|
|
2481
|
+
* 获取用户信息
|
|
2482
|
+
*/
|
|
2483
|
+
const getUserProfile = temporarilyNotSupport('getUserProfile');
|
|
2484
|
+
// export const getUserProfile = (_options) => {
|
|
2485
|
+
// return new Promise((resolve, reject) => {
|
|
2486
|
+
// const res: Record<string, any> = {}
|
|
2487
|
+
// hmsJSAccount.HuaweiIdAuthManager.addAuthScopes([hmsJSAccount.PROFILE])
|
|
2488
|
+
// .then(result => {
|
|
2489
|
+
// if (result) {
|
|
2490
|
+
// res.data = { userInfo: generateUserInfo(result) }
|
|
2491
|
+
// callAsyncSuccess(resolve, res, options)
|
|
2492
|
+
// } else {
|
|
2493
|
+
// res.errorMsg = 'getUserProfile result data is null'
|
|
2494
|
+
// callAsyncFail(reject, res, options)
|
|
2495
|
+
// }
|
|
2496
|
+
// })
|
|
2497
|
+
// .catch(error => {
|
|
2498
|
+
// callAsyncFail(reject, error, options)
|
|
2499
|
+
// })
|
|
2500
|
+
// })
|
|
2501
|
+
// }
|
|
2502
|
+
/**
|
|
2503
|
+
* 提前向用户发起授权请求
|
|
2504
|
+
*/
|
|
2505
|
+
const authorize = temporarilyNotSupport('authorize');
|
|
2506
|
+
/**
|
|
2507
|
+
* 获取用户的当前设置
|
|
2508
|
+
*/
|
|
2509
|
+
const getSetting = temporarilyNotSupport('getSetting');
|
|
2510
|
+
/**
|
|
2511
|
+
* 调起客户端小程序设置界面
|
|
2512
|
+
*/
|
|
2513
|
+
const openSetting = temporarilyNotSupport('openSetting');
|
|
2514
|
+
// function generateUserInfo (hmsAuthInfo) {
|
|
2515
|
+
// const userInfo = {
|
|
2516
|
+
// nickName: String,
|
|
2517
|
+
// avatarUrl: String,
|
|
2518
|
+
// gender: Number,
|
|
2519
|
+
// country: String
|
|
2520
|
+
// }
|
|
2521
|
+
// if (hmsAuthInfo) {
|
|
2522
|
+
// userInfo.nickName = hmsAuthInfo.displayName
|
|
2523
|
+
// userInfo.avatarUrl = hmsAuthInfo.photoUriString
|
|
2524
|
+
// userInfo.gender = hmsAuthInfo.gender
|
|
2525
|
+
// userInfo.country = hmsAuthInfo.country
|
|
2526
|
+
// }
|
|
2527
|
+
// return userInfo
|
|
2528
|
+
// }
|
|
2529
|
+
|
|
2530
|
+
const login = temporarilyNotSupport('login');
|
|
2531
|
+
const getAccountInfoSync = temporarilyNotSupport('getAccountInfoSync');
|
|
2532
|
+
const requestSubscribeMessage = temporarilyNotSupport('requestSubscribeMessage');
|
|
2533
|
+
|
|
2534
|
+
// TODO
|
|
2535
|
+
const getCurrentPages = () => [];
|
|
2536
|
+
const pageScrollTo = (options) => {
|
|
2537
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
2538
|
+
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
2539
|
+
var _a, _b;
|
|
2540
|
+
const taro = Current.taro;
|
|
2541
|
+
const page = taro.getCurrentInstance().page;
|
|
2542
|
+
const res = { errMsg: 'pageScrollTo:ok' };
|
|
2543
|
+
const error = { errMsg: 'pageScrollTo:fail' };
|
|
2544
|
+
const { scrollTop, selector = '', duration = 300, offsetTop = 0 } = options;
|
|
2545
|
+
if (scrollTop && selector) {
|
|
2546
|
+
console.warn('"scrollTop" 或 "selector" 建议只设一个值,全部设置会忽略selector');
|
|
2547
|
+
}
|
|
2548
|
+
let scrollValue = -1;
|
|
2549
|
+
let scroller = page.scroller;
|
|
2550
|
+
const currentPageNode = getPageScrollerOrNode(page.node, page);
|
|
2551
|
+
if (scrollTop || typeof scrollTop === 'number') {
|
|
2552
|
+
scrollValue = scrollTop;
|
|
2553
|
+
}
|
|
2554
|
+
else if (selector) {
|
|
2555
|
+
const node = findChildNodeWithDFS(currentPageNode, selector);
|
|
2556
|
+
if (!node || !node._instance)
|
|
2557
|
+
return;
|
|
2558
|
+
const instance = node._instance;
|
|
2559
|
+
const id = node === null || node === void 0 ? void 0 : node._nid;
|
|
2560
|
+
// 获取 areaInfo,需要先调用 setNodeEventCallbackAndTriggerComponentUpdate 更新一次组件并获取组件信息
|
|
2561
|
+
yield setNodeEventCallbackAndTriggerComponentUpdate(node, AREA_CHANGE_EVENT_NAME, null, true);
|
|
2562
|
+
const { areaInfo } = ((_a = instance === null || instance === void 0 ? void 0 : instance.nodeInfoMap) === null || _a === void 0 ? void 0 : _a[id]) || {};
|
|
2563
|
+
let parent = node === null || node === void 0 ? void 0 : node.parentNode;
|
|
2564
|
+
while (!!parent && parent !== currentPageNode) {
|
|
2565
|
+
if ((_b = parent === null || parent === void 0 ? void 0 : parent._instance) === null || _b === void 0 ? void 0 : _b.scroller) {
|
|
2566
|
+
scroller = parent._instance.scroller;
|
|
2567
|
+
break;
|
|
2568
|
+
}
|
|
2569
|
+
parent = parent === null || parent === void 0 ? void 0 : parent.parentNode;
|
|
2570
|
+
}
|
|
2571
|
+
scroller = getPageScrollerOrNode(scroller, page);
|
|
2572
|
+
const { yOffset } = scroller.currentOffset();
|
|
2573
|
+
if (areaInfo) {
|
|
2574
|
+
scrollValue = areaInfo.globalPosition.y + yOffset + pxTransformHelper(offsetTop, 'px', true);
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
const { xOffset } = scroller.currentOffset();
|
|
2578
|
+
if (scrollValue === -1) {
|
|
2579
|
+
return callAsyncFail(reject, { errMsg: 'pageScrollTo:fail, 请检查传入的 scrollTop 或 selector 是否合法' }, options);
|
|
2580
|
+
}
|
|
2581
|
+
try {
|
|
2582
|
+
scroller.scrollTo({
|
|
2583
|
+
xOffset,
|
|
2584
|
+
yOffset: scrollValue,
|
|
2585
|
+
animation: {
|
|
2586
|
+
duration: duration,
|
|
2587
|
+
// @ts-ignore
|
|
2588
|
+
curve: Curve.Linear
|
|
2589
|
+
}
|
|
2590
|
+
});
|
|
2591
|
+
setTimeout(() => {
|
|
2592
|
+
callAsyncSuccess(resolve, res, options);
|
|
2593
|
+
}, duration);
|
|
2594
|
+
}
|
|
2595
|
+
catch (_) {
|
|
2596
|
+
callAsyncFail(reject, error, options);
|
|
2597
|
+
}
|
|
2598
|
+
}));
|
|
2599
|
+
};
|
|
2600
|
+
|
|
2601
|
+
const launchOptions = {
|
|
2602
|
+
path: '',
|
|
2603
|
+
query: {},
|
|
2604
|
+
scene: 0,
|
|
2605
|
+
shareTicket: '',
|
|
2606
|
+
referrerInfo: {}
|
|
2607
|
+
};
|
|
2608
|
+
function initLaunchOptions(options = {}) {
|
|
2609
|
+
Object.assign(launchOptions, options);
|
|
2610
|
+
}
|
|
2611
|
+
eventCenter.once('__taroRouterLaunch', initLaunchOptions);
|
|
2612
|
+
const TARO_TABBAR_PAGE_PATH = 'taro_tabbar';
|
|
2613
|
+
function isTabPage(url) {
|
|
2614
|
+
var _a, _b;
|
|
2615
|
+
return (_b = (_a = window.__taroAppConfig.tabBar) === null || _a === void 0 ? void 0 : _a.list) === null || _b === void 0 ? void 0 : _b.some(item => item.pagePath === url);
|
|
2616
|
+
}
|
|
2617
|
+
function parseURL(raw = '') {
|
|
2618
|
+
const [urlStr, queryStr = ''] = raw.split('?');
|
|
2619
|
+
const query = queryToJson(queryStr);
|
|
2620
|
+
let url = urlStr.replace(/^\//, '');
|
|
2621
|
+
if (isTabPage(url)) {
|
|
2622
|
+
query.$page = url;
|
|
2623
|
+
url = TARO_TABBAR_PAGE_PATH;
|
|
2624
|
+
}
|
|
2625
|
+
return [url, query];
|
|
2626
|
+
}
|
|
2627
|
+
// 生命周期
|
|
2628
|
+
const getLaunchOptionsSync = () => launchOptions;
|
|
2629
|
+
const getEnterOptionsSync = () => launchOptions;
|
|
2630
|
+
const getRouterFunc = (method) => {
|
|
2631
|
+
const methodName = method === 'navigateTo' ? 'pushUrl' : 'replaceUrl';
|
|
2632
|
+
return function (options) {
|
|
2633
|
+
const [url, params = {}] = parseURL(options.url);
|
|
2634
|
+
return new Promise((resolve, reject) => {
|
|
2635
|
+
router[methodName]({
|
|
2636
|
+
url,
|
|
2637
|
+
params
|
|
2638
|
+
}, (error) => {
|
|
2639
|
+
const res = { errMsg: `${method}:ok` };
|
|
2640
|
+
if (error) {
|
|
2641
|
+
const { code, message } = error;
|
|
2642
|
+
res.code = code;
|
|
2643
|
+
res.errMsg = `${method}:failed, ${message}`;
|
|
2644
|
+
callAsyncFail(reject, res, options);
|
|
2645
|
+
return;
|
|
2646
|
+
}
|
|
2647
|
+
callAsyncSuccess(resolve, res, options);
|
|
2648
|
+
});
|
|
2649
|
+
});
|
|
2650
|
+
};
|
|
2651
|
+
};
|
|
2652
|
+
const navigateTo = getRouterFunc('navigateTo');
|
|
2653
|
+
const redirectTo = getRouterFunc('redirectTo');
|
|
2654
|
+
function navigateBack(options) {
|
|
2655
|
+
return new Promise(resolve => {
|
|
2656
|
+
if (!(options === null || options === void 0 ? void 0 : options.url)) {
|
|
2657
|
+
router.back();
|
|
2658
|
+
}
|
|
2659
|
+
else {
|
|
2660
|
+
const [url] = parseURL(options.url);
|
|
2661
|
+
router.back({ url });
|
|
2662
|
+
}
|
|
2663
|
+
const res = { errMsg: 'navigateBack:ok' };
|
|
2664
|
+
callAsyncSuccess(resolve, res, options);
|
|
2665
|
+
});
|
|
2666
|
+
}
|
|
2667
|
+
const reLaunch = (options) => {
|
|
2668
|
+
return new Promise(resolve => {
|
|
2669
|
+
redirectTo({ url: options.url });
|
|
2670
|
+
router.clear();
|
|
2671
|
+
const res = { errMsg: 'reLaunch:ok' };
|
|
2672
|
+
callAsyncSuccess(resolve, res, options);
|
|
2673
|
+
});
|
|
2674
|
+
};
|
|
2675
|
+
const switchTab = (options) => {
|
|
2676
|
+
return new Promise((resolve, reject) => {
|
|
2677
|
+
var _a;
|
|
2678
|
+
const stack = AppStorage.prop('__TARO_PAGE_STACK').get();
|
|
2679
|
+
const [url, params] = parseURL(options.url);
|
|
2680
|
+
if (url !== TARO_TABBAR_PAGE_PATH) {
|
|
2681
|
+
const res = { errMsg: 'switchTab:failed' };
|
|
2682
|
+
callAsyncFail(reject, res, options);
|
|
2683
|
+
return;
|
|
2684
|
+
}
|
|
2685
|
+
if (((_a = stack[stack.length - 1]) === null || _a === void 0 ? void 0 : _a.path) === url) {
|
|
2686
|
+
// Note: 当前为 Tab 页时,触发 switch 事件
|
|
2687
|
+
eventCenter.trigger('__taroSwitchTab', { url, params });
|
|
2688
|
+
router.getLength() > 1 && router.clear();
|
|
2689
|
+
}
|
|
2690
|
+
else if (stack.some(item => item.path === url)) {
|
|
2691
|
+
// Note: 寻找路由栈中的 Tab 页,如果找到,则使用 navigateBack
|
|
2692
|
+
router.back({ url, params });
|
|
2693
|
+
router.getLength() > 1 && router.clear();
|
|
2694
|
+
}
|
|
2695
|
+
else {
|
|
2696
|
+
// Note: 未找到页面时,使用 reLaunch
|
|
2697
|
+
reLaunch({ url: options.url });
|
|
2698
|
+
}
|
|
2699
|
+
const res = { errMsg: 'switchTab:ok' };
|
|
2700
|
+
callAsyncSuccess(resolve, res, options);
|
|
2701
|
+
});
|
|
2702
|
+
};
|
|
2703
|
+
const getLength = () => {
|
|
2704
|
+
return router.getLength();
|
|
2705
|
+
};
|
|
2706
|
+
const getState = () => {
|
|
2707
|
+
return router.getState();
|
|
2708
|
+
};
|
|
2709
|
+
|
|
2710
|
+
const preferencesPromise = Current.contextPromise
|
|
2711
|
+
.then((context) => {
|
|
2712
|
+
return bundleManager
|
|
2713
|
+
.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION)
|
|
2714
|
+
.then(data => {
|
|
2715
|
+
return dataPreferences
|
|
2716
|
+
.getPreferences(context, `${data.appInfo.uid}Store`);
|
|
2717
|
+
});
|
|
2718
|
+
})
|
|
2719
|
+
.catch((error) => {
|
|
2720
|
+
hilog.error(0x0000, 'TaroFailedTag', 'Failed to load the storage. Cause: %{public}s', error.code ? JSON.stringify(error) : error.message || error);
|
|
2721
|
+
});
|
|
2722
|
+
function getItem(key) {
|
|
2723
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2724
|
+
try {
|
|
2725
|
+
const preferences = yield preferencesPromise;
|
|
2726
|
+
const item = yield preferences.get(key, null);
|
|
2727
|
+
return { result: true, data: item };
|
|
2728
|
+
}
|
|
2729
|
+
catch (error) {
|
|
2730
|
+
return { result: false };
|
|
2731
|
+
}
|
|
2732
|
+
});
|
|
2733
|
+
}
|
|
2734
|
+
const storageSchema = {
|
|
2735
|
+
key: 'String'
|
|
2736
|
+
};
|
|
2737
|
+
function getStorage(options) {
|
|
2738
|
+
return new Promise((resolve, reject) => {
|
|
2739
|
+
try {
|
|
2740
|
+
validateParams('getStorage', options, storageSchema);
|
|
2741
|
+
}
|
|
2742
|
+
catch (error) {
|
|
2743
|
+
const res = { errMsg: error.message };
|
|
2744
|
+
return callAsyncFail(reject, res, options);
|
|
2745
|
+
}
|
|
2746
|
+
getItem(options.key).then(({ result, data }) => {
|
|
2747
|
+
const res = { errMsg: 'getStorage:ok' };
|
|
2748
|
+
if (result) {
|
|
2749
|
+
res.data = data;
|
|
2750
|
+
callAsyncSuccess(resolve, res, options);
|
|
2751
|
+
}
|
|
2752
|
+
else {
|
|
2753
|
+
res.errMsg = 'getStorage:fail data not found';
|
|
2754
|
+
callAsyncFail(reject, res, options);
|
|
2755
|
+
}
|
|
2756
|
+
});
|
|
2757
|
+
});
|
|
2758
|
+
}
|
|
2759
|
+
function setStorage(options) {
|
|
2760
|
+
return new Promise((resolve, reject) => {
|
|
2761
|
+
try {
|
|
2762
|
+
validateParams('setStorage', options, storageSchema);
|
|
2763
|
+
}
|
|
2764
|
+
catch (error) {
|
|
2765
|
+
const res = { errMsg: error.message };
|
|
2766
|
+
return callAsyncFail(reject, res, options);
|
|
2767
|
+
}
|
|
2768
|
+
const { key, data } = options;
|
|
2769
|
+
const res = { errMsg: 'setStorage:ok' };
|
|
2770
|
+
preferencesPromise.then((preferences) => __awaiter(this, void 0, void 0, function* () {
|
|
2771
|
+
yield preferences.put(key, data);
|
|
2772
|
+
yield preferences.flush();
|
|
2773
|
+
callAsyncSuccess(resolve, res, options);
|
|
2774
|
+
}));
|
|
2775
|
+
});
|
|
2776
|
+
}
|
|
2777
|
+
function removeStorage(options) {
|
|
2778
|
+
return new Promise((resolve, reject) => {
|
|
2779
|
+
try {
|
|
2780
|
+
validateParams('removeStorage', options, storageSchema);
|
|
2781
|
+
}
|
|
2782
|
+
catch (error) {
|
|
2783
|
+
const res = { errMsg: error.message };
|
|
2784
|
+
return callAsyncFail(reject, res, options);
|
|
2785
|
+
}
|
|
2786
|
+
const { key } = options;
|
|
2787
|
+
preferencesPromise.then((preferences) => __awaiter(this, void 0, void 0, function* () {
|
|
2788
|
+
yield preferences.delete(key);
|
|
2789
|
+
yield preferences.flush();
|
|
2790
|
+
const res = { errMsg: 'removeStorage:ok' };
|
|
2791
|
+
callAsyncSuccess(resolve, res, options);
|
|
2792
|
+
}));
|
|
2793
|
+
});
|
|
2794
|
+
}
|
|
2795
|
+
function clearStorage(options) {
|
|
2796
|
+
return new Promise(resolve => {
|
|
2797
|
+
preferencesPromise.then((preferences) => __awaiter(this, void 0, void 0, function* () {
|
|
2798
|
+
yield preferences.clear();
|
|
2799
|
+
yield preferences.flush();
|
|
2800
|
+
const res = { errMsg: 'clearStorage:ok' };
|
|
2801
|
+
callAsyncSuccess(resolve, res, options);
|
|
2802
|
+
}));
|
|
2803
|
+
});
|
|
2804
|
+
}
|
|
2805
|
+
const getStorageSync = temporarilyNotSupport('getStorageSync', 'getStorage');
|
|
2806
|
+
const setStorageSync = temporarilyNotSupport('setStorageSync', 'setStorage');
|
|
2807
|
+
const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clearStorage');
|
|
2808
|
+
const removeStorageSync = temporarilyNotSupport('removeStorageSync', 'removeStorage');
|
|
2809
|
+
|
|
2810
|
+
// eslint-disable-next-line import/no-duplicates
|
|
2811
|
+
const toggleTabBar = function (type) {
|
|
2812
|
+
return function (options) {
|
|
2813
|
+
return new Promise((resolve, reject) => {
|
|
2814
|
+
var _a, _b;
|
|
2815
|
+
const taro = Current.taro;
|
|
2816
|
+
const page = taro.getCurrentInstance().page;
|
|
2817
|
+
const currentData = ((_a = page._data) === null || _a === void 0 ? void 0 : _a.taroTabBar) || page.tabBar;
|
|
2818
|
+
const res = { errMsg: `${type}TabBar:ok` };
|
|
2819
|
+
const error = { errMsg: `${type}TabBar:fail not TabBar page` };
|
|
2820
|
+
if (!currentData) {
|
|
2821
|
+
callAsyncFail(reject, error, options);
|
|
2822
|
+
}
|
|
2823
|
+
else {
|
|
2824
|
+
const isShow = type === 'show';
|
|
2825
|
+
const event = isShow ? '__taroShowTabBar' : '__taroHideTabBar';
|
|
2826
|
+
eventCenter.trigger(event, {
|
|
2827
|
+
animation: options === null || options === void 0 ? void 0 : options.animation,
|
|
2828
|
+
});
|
|
2829
|
+
(_b = page.$set) === null || _b === void 0 ? void 0 : _b.call(page, 'isShowTaroTabBar', isShow);
|
|
2830
|
+
callAsyncSuccess(resolve, res, options);
|
|
2831
|
+
}
|
|
2832
|
+
});
|
|
2833
|
+
};
|
|
2834
|
+
};
|
|
2835
|
+
const showTabBar = toggleTabBar('show');
|
|
2836
|
+
const hideTabBar = toggleTabBar('hide');
|
|
2837
|
+
const setTabBarStyle = function (options = {}) {
|
|
2838
|
+
return new Promise((resolve, reject) => {
|
|
2839
|
+
var _a, _b;
|
|
2840
|
+
const taro = Current.taro;
|
|
2841
|
+
const page = taro.getCurrentInstance().page;
|
|
2842
|
+
const currentData = ((_a = page._data) === null || _a === void 0 ? void 0 : _a.taroTabBar) || page.tabBar;
|
|
2843
|
+
const res = { errMsg: 'setTabBarStyle:ok' };
|
|
2844
|
+
const error = { errMsg: 'setTabBarStyle:fail not TabBar page' };
|
|
2845
|
+
if (!currentData) {
|
|
2846
|
+
callAsyncFail(reject, error, options);
|
|
2847
|
+
}
|
|
2848
|
+
else {
|
|
2849
|
+
const data = Object.assign({}, currentData);
|
|
2850
|
+
if (options.color)
|
|
2851
|
+
data.color = options.color;
|
|
2852
|
+
if (options.selectedColor)
|
|
2853
|
+
data.selectedColor = options.selectedColor;
|
|
2854
|
+
if (options.backgroundColor)
|
|
2855
|
+
data.backgroundColor = options.backgroundColor;
|
|
2856
|
+
if (options.borderStyle)
|
|
2857
|
+
data.borderStyle = options.borderStyle;
|
|
2858
|
+
eventCenter.trigger('__taroSetTabBarStyle', options);
|
|
2859
|
+
(_b = page.$set) === null || _b === void 0 ? void 0 : _b.call(page, 'taroTabBar', data);
|
|
2860
|
+
callAsyncSuccess(resolve, res, options);
|
|
2861
|
+
}
|
|
2862
|
+
});
|
|
2863
|
+
};
|
|
2864
|
+
const setTabBarItem = function (options) {
|
|
2865
|
+
return new Promise((resolve, reject) => {
|
|
2866
|
+
var _a, _b;
|
|
2867
|
+
const taro = Current.taro;
|
|
2868
|
+
const page = taro.getCurrentInstance().page;
|
|
2869
|
+
const currentData = ((_a = page._data) === null || _a === void 0 ? void 0 : _a.taroTabBar) || page.tabBar;
|
|
2870
|
+
const res = { errMsg: 'setTabBarItem:ok' };
|
|
2871
|
+
const error = { errMsg: 'setTabBarItem:fail not TabBar page' };
|
|
2872
|
+
if (!currentData) {
|
|
2873
|
+
callAsyncFail(reject, error, options);
|
|
2874
|
+
}
|
|
2875
|
+
else {
|
|
2876
|
+
const index = options.index;
|
|
2877
|
+
const item = Object.assign({}, currentData.list[index]);
|
|
2878
|
+
if (options.text)
|
|
2879
|
+
item.text = options.text;
|
|
2880
|
+
if (options.iconPath)
|
|
2881
|
+
item.iconPath = options.iconPath;
|
|
2882
|
+
if (options.selectedIconPath)
|
|
2883
|
+
item.selectedIconPath = options.selectedIconPath;
|
|
2884
|
+
const list = [
|
|
2885
|
+
...currentData.list.slice(0, index),
|
|
2886
|
+
item,
|
|
2887
|
+
...currentData.list.slice(index + 1)
|
|
2888
|
+
];
|
|
2889
|
+
const data = Object.assign({}, currentData, { list });
|
|
2890
|
+
eventCenter.trigger('__taroSetTabBarItem', options);
|
|
2891
|
+
(_b = page.$set) === null || _b === void 0 ? void 0 : _b.call(page, 'taroTabBar', data);
|
|
2892
|
+
callAsyncSuccess(resolve, res, options);
|
|
2893
|
+
}
|
|
2894
|
+
});
|
|
2895
|
+
};
|
|
2896
|
+
function showTabBarRedDot(options) {
|
|
2897
|
+
const res = { errMsg: 'showTabBarRedDot:ok' };
|
|
2898
|
+
return new Promise((resolve) => {
|
|
2899
|
+
eventCenter.trigger('__taroShowTabBarRedDotHandler', {
|
|
2900
|
+
index: (options === null || options === void 0 ? void 0 : options.index) || 0,
|
|
2901
|
+
});
|
|
2902
|
+
callAsyncSuccess(resolve, res, options);
|
|
2903
|
+
});
|
|
2904
|
+
}
|
|
2905
|
+
function hideTabBarRedDot(options) {
|
|
2906
|
+
const res = { errMsg: 'hideTabBarRedDot:ok' };
|
|
2907
|
+
return new Promise((resolve) => {
|
|
2908
|
+
eventCenter.trigger('__taroHideTabBarRedDotHandler', {
|
|
2909
|
+
index: (options === null || options === void 0 ? void 0 : options.index) || 0,
|
|
2910
|
+
});
|
|
2911
|
+
callAsyncSuccess(resolve, res, options);
|
|
2912
|
+
});
|
|
2913
|
+
}
|
|
2914
|
+
function setTabBarBadge(options) {
|
|
2915
|
+
const res = { errMsg: 'setTabBarBadge:ok' };
|
|
2916
|
+
return new Promise((resolve) => {
|
|
2917
|
+
const text = (options === null || options === void 0 ? void 0 : options.text) || '';
|
|
2918
|
+
eventCenter.trigger('__taroSetTabBarBadge', {
|
|
2919
|
+
index: (options === null || options === void 0 ? void 0 : options.index) || 0,
|
|
2920
|
+
text: text.replace(/[\u0391-\uFFE5]/g, 'aa').length > 4 ? '...' : text,
|
|
2921
|
+
});
|
|
2922
|
+
callAsyncSuccess(resolve, res, options);
|
|
2923
|
+
});
|
|
2924
|
+
}
|
|
2925
|
+
function removeTabBarBadge(options) {
|
|
2926
|
+
const res = { errMsg: 'removeTabBarBadge:ok' };
|
|
2927
|
+
return new Promise((resolve) => {
|
|
2928
|
+
eventCenter.trigger('__taroRemoveTabBarBadge', {
|
|
2929
|
+
index: (options === null || options === void 0 ? void 0 : options.index) || 0,
|
|
2930
|
+
});
|
|
2931
|
+
callAsyncSuccess(resolve, res, options);
|
|
2932
|
+
});
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2935
|
+
class Animation {
|
|
2936
|
+
constructor({ duration = 400, delay = 0, timingFunction = 'linear', transformOrigin = '50% 50% 0', unit = 'px' } = {}) {
|
|
2937
|
+
// 组合动画
|
|
2938
|
+
this.steps = [];
|
|
2939
|
+
// 属性组合
|
|
2940
|
+
this.rule = {};
|
|
2941
|
+
this.unit = unit;
|
|
2942
|
+
this.setDefault(duration, delay, timingFunction, transformOrigin);
|
|
2943
|
+
}
|
|
2944
|
+
// 设置默认值
|
|
2945
|
+
setDefault(duration, delay, timingFunction, transformOrigin) {
|
|
2946
|
+
this.DEFAULT = { duration, delay, timingFunction, transformOrigin };
|
|
2947
|
+
}
|
|
2948
|
+
export() {
|
|
2949
|
+
const actions = this.steps.slice();
|
|
2950
|
+
this.steps = [];
|
|
2951
|
+
this.rule = {};
|
|
2952
|
+
return {
|
|
2953
|
+
actions
|
|
2954
|
+
};
|
|
2955
|
+
}
|
|
2956
|
+
step(arg = {}) {
|
|
2957
|
+
const { DEFAULT } = this;
|
|
2958
|
+
const { duration = DEFAULT.duration, delay = DEFAULT.delay, timingFunction = DEFAULT.timingFunction, transformOrigin = DEFAULT.transformOrigin } = arg;
|
|
2959
|
+
this.steps.push({
|
|
2960
|
+
duration,
|
|
2961
|
+
delay,
|
|
2962
|
+
timingFunction,
|
|
2963
|
+
transformOrigin,
|
|
2964
|
+
rule: Object.assign({}, this.rule)
|
|
2965
|
+
});
|
|
2966
|
+
return this;
|
|
2967
|
+
}
|
|
2968
|
+
matrix(a, b, c, d, tx, ty) {
|
|
2969
|
+
this.rule.transform = matrix4.init([a, b, c, d, tx, ty]);
|
|
2970
|
+
return this;
|
|
2971
|
+
}
|
|
2972
|
+
matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
|
|
2973
|
+
this.rule.transform = matrix4.init([a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4]);
|
|
2974
|
+
return this;
|
|
2975
|
+
}
|
|
2976
|
+
rotate(angle) {
|
|
2977
|
+
this.rule.rotate = { x: 0, y: 0, z: 1, angle };
|
|
2978
|
+
return this;
|
|
2979
|
+
}
|
|
2980
|
+
rotate3d(x, y, z, angle) {
|
|
2981
|
+
this.rule.rotate = { x, y, z, angle };
|
|
2982
|
+
return this;
|
|
2983
|
+
}
|
|
2984
|
+
rotateX(angle) {
|
|
2985
|
+
this.rule.rotate = { x: 1, y: 0, z: 0, angle };
|
|
2986
|
+
return this;
|
|
2987
|
+
}
|
|
2988
|
+
rotateY(angle) {
|
|
2989
|
+
this.rule.rotate = { x: 0, y: 1, z: 0, angle };
|
|
2990
|
+
return this;
|
|
2991
|
+
}
|
|
2992
|
+
rotateZ(angle) {
|
|
2993
|
+
this.rule.rotate = { x: 0, y: 0, z: 1, angle };
|
|
2994
|
+
return this;
|
|
2995
|
+
}
|
|
2996
|
+
scale(sx, sy) {
|
|
2997
|
+
this.rule.scale = { x: sx, y: sy };
|
|
2998
|
+
return this;
|
|
2999
|
+
}
|
|
3000
|
+
scale3d(sx, sy, sz) {
|
|
3001
|
+
this.rule.scale = { x: sx, y: sy, z: sz };
|
|
3002
|
+
return this;
|
|
3003
|
+
}
|
|
3004
|
+
scaleX(scale) {
|
|
3005
|
+
this.rule.scale = { x: scale };
|
|
3006
|
+
return this;
|
|
3007
|
+
}
|
|
3008
|
+
scaleY(scale) {
|
|
3009
|
+
this.rule.scale = { y: scale };
|
|
3010
|
+
return this;
|
|
3011
|
+
}
|
|
3012
|
+
scaleZ(scale) {
|
|
3013
|
+
this.rule.scale = { z: scale };
|
|
3014
|
+
return this;
|
|
3015
|
+
}
|
|
3016
|
+
skew(ax, ay) {
|
|
3017
|
+
this.rule.skew = { x: ax, y: ay };
|
|
3018
|
+
return this;
|
|
3019
|
+
}
|
|
3020
|
+
skewX(angle) {
|
|
3021
|
+
this.rule.skew = { x: angle };
|
|
3022
|
+
return this;
|
|
3023
|
+
}
|
|
3024
|
+
skewY(angle) {
|
|
3025
|
+
this.rule.skew = { y: angle };
|
|
3026
|
+
return this;
|
|
3027
|
+
}
|
|
3028
|
+
translate(tx, ty) {
|
|
3029
|
+
this.rule.translate = { x: tx, y: ty };
|
|
3030
|
+
return this;
|
|
3031
|
+
}
|
|
3032
|
+
translate3d(tx, ty, tz) {
|
|
3033
|
+
this.rule.translate = { x: tx, y: ty, z: tz };
|
|
3034
|
+
return this;
|
|
3035
|
+
}
|
|
3036
|
+
translateX(translation) {
|
|
3037
|
+
this.rule.translate = { x: translation };
|
|
3038
|
+
return this;
|
|
3039
|
+
}
|
|
3040
|
+
translateY(translation) {
|
|
3041
|
+
this.rule.translate = { y: translation };
|
|
3042
|
+
return this;
|
|
3043
|
+
}
|
|
3044
|
+
translateZ(translation) {
|
|
3045
|
+
this.rule.translate = { z: translation };
|
|
3046
|
+
return this;
|
|
3047
|
+
}
|
|
3048
|
+
opacity(value) {
|
|
3049
|
+
this.rule.opacity = value;
|
|
3050
|
+
return this;
|
|
3051
|
+
}
|
|
3052
|
+
backgroundColor(value) {
|
|
3053
|
+
this.rule.backgroundColor = value;
|
|
3054
|
+
return this;
|
|
3055
|
+
}
|
|
3056
|
+
width(value) {
|
|
3057
|
+
this.rule.size = Object.assign(Object.assign({}, this.rule.size), { width: value });
|
|
3058
|
+
return this;
|
|
3059
|
+
}
|
|
3060
|
+
height(value) {
|
|
3061
|
+
this.rule.size = Object.assign(Object.assign({}, this.rule.size), { height: value });
|
|
3062
|
+
return this;
|
|
3063
|
+
}
|
|
3064
|
+
left(value) {
|
|
3065
|
+
temporarilyNotSupport('animation.left:' + value)(value);
|
|
3066
|
+
return this;
|
|
3067
|
+
}
|
|
3068
|
+
right(value) {
|
|
3069
|
+
temporarilyNotSupport('animation.right:' + value)(value);
|
|
3070
|
+
return this;
|
|
3071
|
+
}
|
|
3072
|
+
top(value) {
|
|
3073
|
+
temporarilyNotSupport('animation.top:' + value)(value);
|
|
3074
|
+
return this;
|
|
3075
|
+
}
|
|
3076
|
+
bottom(value) {
|
|
3077
|
+
temporarilyNotSupport('animation.bottom:' + value)(value);
|
|
3078
|
+
return this;
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
|
|
3082
|
+
// import window from '@ohos.window'
|
|
3083
|
+
// import { Current } from '@tarojs/runtime'
|
|
3084
|
+
// import { callAsyncFail, callAsyncSuccess } from '../utils'
|
|
3085
|
+
// const windowClassPromise = (Current as any).contextPromise
|
|
3086
|
+
// .then(context => {
|
|
3087
|
+
// return window.getTopWindow(context)
|
|
3088
|
+
// })
|
|
3089
|
+
function setBackgroundColor(options) {
|
|
3090
|
+
const { success, fail, complete } = options || {};
|
|
3091
|
+
const handle = new MethodHandler({ name: 'setBackgroundColor', success, fail, complete });
|
|
3092
|
+
return new Promise((resolve, reject) => {
|
|
3093
|
+
eventCenter.trigger('__taroPageStyle', {
|
|
3094
|
+
backgroundColor: options.backgroundColor || options.backgroundColorTop || options.backgroundColorBottom,
|
|
3095
|
+
});
|
|
3096
|
+
return handle.success({}, { resolve, reject });
|
|
3097
|
+
// windowClassPromise.then(windowClass => {
|
|
3098
|
+
// windowClass.setBackgroundColor(color).then(() => {
|
|
3099
|
+
// const res = { errMsg: 'setBackgroundColor:ok' }
|
|
3100
|
+
// callAsyncSuccess(resolve, res, options)
|
|
3101
|
+
// }, (error) => {
|
|
3102
|
+
// const res = { errMsg: 'setBackgroundColor:fail' + error }
|
|
3103
|
+
// callAsyncFail(reject, res, options)
|
|
3104
|
+
// })
|
|
3105
|
+
// })
|
|
3106
|
+
});
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
const resCallback = (res) => {
|
|
3110
|
+
return { errMsg: `${res}:ok` };
|
|
3111
|
+
};
|
|
3112
|
+
const showToastSchema = {
|
|
3113
|
+
title: 'String',
|
|
3114
|
+
duration: 'Number',
|
|
3115
|
+
bottom: 'String'
|
|
3116
|
+
};
|
|
3117
|
+
function showToast(options) {
|
|
3118
|
+
return new Promise((resolve, reject) => {
|
|
3119
|
+
const _default = {
|
|
3120
|
+
title: '',
|
|
3121
|
+
duration: 1500,
|
|
3122
|
+
bottom: '50%'
|
|
3123
|
+
};
|
|
3124
|
+
options = Object.assign(Object.assign({}, _default), options);
|
|
3125
|
+
try {
|
|
3126
|
+
validateParams('showToast', options, showToastSchema);
|
|
3127
|
+
}
|
|
3128
|
+
catch (error) {
|
|
3129
|
+
const res = { errMsg: error.message };
|
|
3130
|
+
return callAsyncFail(reject, res, options);
|
|
3131
|
+
}
|
|
3132
|
+
prompt.showToast({
|
|
3133
|
+
message: options.title,
|
|
3134
|
+
duration: options.duration,
|
|
3135
|
+
bottom: options.bottom
|
|
3136
|
+
});
|
|
3137
|
+
callAsyncSuccess(resolve, resCallback('showToast'), options);
|
|
3138
|
+
});
|
|
3139
|
+
}
|
|
3140
|
+
function showModal(options) {
|
|
3141
|
+
const _default = {
|
|
3142
|
+
title: '',
|
|
3143
|
+
content: '',
|
|
3144
|
+
showCancel: true,
|
|
3145
|
+
cancelText: '取消',
|
|
3146
|
+
cancelColor: '#000000',
|
|
3147
|
+
confirmText: '确定',
|
|
3148
|
+
confirmColor: '#3CC51F'
|
|
3149
|
+
};
|
|
3150
|
+
options = Object.assign(Object.assign({}, _default), options);
|
|
3151
|
+
const { title, content, cancelText, confirmText, cancelColor, confirmColor, showCancel } = options;
|
|
3152
|
+
const buttons = [];
|
|
3153
|
+
if (cancelText !== '' && showCancel) {
|
|
3154
|
+
buttons.push({
|
|
3155
|
+
text: cancelText,
|
|
3156
|
+
color: cancelColor
|
|
3157
|
+
});
|
|
3158
|
+
}
|
|
3159
|
+
if (confirmText !== '') {
|
|
3160
|
+
buttons.push({
|
|
3161
|
+
text: confirmText,
|
|
3162
|
+
color: confirmColor
|
|
3163
|
+
});
|
|
3164
|
+
}
|
|
3165
|
+
return new Promise(resolve => {
|
|
3166
|
+
const modalOptions = {
|
|
3167
|
+
title,
|
|
3168
|
+
message: content,
|
|
3169
|
+
buttons: buttons,
|
|
3170
|
+
success: (data) => {
|
|
3171
|
+
if (data.index === 1 || !showCancel) {
|
|
3172
|
+
callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: true, cancel: false, content: null }), options);
|
|
3173
|
+
}
|
|
3174
|
+
else {
|
|
3175
|
+
callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: false, cancel: true }), options);
|
|
3176
|
+
}
|
|
3177
|
+
},
|
|
3178
|
+
// 鸿蒙没有失败方法,只有取消
|
|
3179
|
+
cancel: (_) => {
|
|
3180
|
+
callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: false, cancel: true }), options);
|
|
3181
|
+
}
|
|
3182
|
+
};
|
|
3183
|
+
prompt.showDialog(modalOptions);
|
|
3184
|
+
});
|
|
3185
|
+
}
|
|
3186
|
+
const showActionSheetSchema = {
|
|
3187
|
+
title: 'String',
|
|
3188
|
+
itemList: 'Array'
|
|
3189
|
+
};
|
|
3190
|
+
function showActionSheet(options) {
|
|
3191
|
+
return new Promise((resolve, reject) => {
|
|
3192
|
+
const _default = {
|
|
3193
|
+
title: '',
|
|
3194
|
+
itemList: [],
|
|
3195
|
+
itemColor: '#000000'
|
|
3196
|
+
};
|
|
3197
|
+
options = Object.assign(Object.assign({}, _default), options);
|
|
3198
|
+
try {
|
|
3199
|
+
validateParams('showActionSheet', options, showActionSheetSchema);
|
|
3200
|
+
}
|
|
3201
|
+
catch (error) {
|
|
3202
|
+
const res = { errMsg: error.message };
|
|
3203
|
+
return callAsyncFail(reject, res, options);
|
|
3204
|
+
}
|
|
3205
|
+
const { title, itemList, itemColor } = options;
|
|
3206
|
+
const buttons = itemList.map(res => {
|
|
3207
|
+
return {
|
|
3208
|
+
text: res,
|
|
3209
|
+
color: itemColor
|
|
3210
|
+
};
|
|
3211
|
+
});
|
|
3212
|
+
const actionSheetOptions = {
|
|
3213
|
+
title,
|
|
3214
|
+
buttons,
|
|
3215
|
+
success: (data) => {
|
|
3216
|
+
callAsyncSuccess(resolve, Object.assign(Object.assign({}, data), resCallback('showActionSheet')), options);
|
|
3217
|
+
},
|
|
3218
|
+
// 取消方法,并非失败
|
|
3219
|
+
fail: (data) => {
|
|
3220
|
+
callAsyncFail(reject, Object.assign(Object.assign({}, data), { errMsg: data.errMsg.replace('showActionMenu', 'showActionSheet') }), options);
|
|
3221
|
+
}
|
|
3222
|
+
};
|
|
3223
|
+
prompt.showActionMenu(actionSheetOptions);
|
|
3224
|
+
});
|
|
3225
|
+
}
|
|
3226
|
+
function hideToast(options) {
|
|
3227
|
+
return new Promise(resolve => {
|
|
3228
|
+
prompt.showToast({
|
|
3229
|
+
message: '关闭中',
|
|
3230
|
+
duration: 10,
|
|
3231
|
+
bottom: '9999px'
|
|
3232
|
+
});
|
|
3233
|
+
callAsyncSuccess(resolve, resCallback('hideToast'), options);
|
|
3234
|
+
});
|
|
3235
|
+
}
|
|
3236
|
+
const showLoading = temporarilyNotSupport('showLoading');
|
|
3237
|
+
const hideLoading = temporarilyNotSupport('hideLoading');
|
|
3238
|
+
|
|
3239
|
+
const setNavigationBarTitle = function (options) {
|
|
3240
|
+
return new Promise(resolve => {
|
|
3241
|
+
var _a;
|
|
3242
|
+
const taro = Current.taro;
|
|
3243
|
+
const page = taro.getCurrentInstance().page;
|
|
3244
|
+
const res = { errMsg: 'setNavigationBarTitle:ok' };
|
|
3245
|
+
(_a = page.$set) === null || _a === void 0 ? void 0 : _a.call(page, 'taroNavBar.title', options.title);
|
|
3246
|
+
callAsyncSuccess(resolve, res, options);
|
|
3247
|
+
});
|
|
3248
|
+
};
|
|
3249
|
+
const setNavigationBarColor = function (options) {
|
|
3250
|
+
return new Promise(resolve => {
|
|
3251
|
+
var _a, _b;
|
|
3252
|
+
const taro = Current.taro;
|
|
3253
|
+
const page = taro.getCurrentInstance().page;
|
|
3254
|
+
const { frontColor, backgroundColor } = options;
|
|
3255
|
+
const res = { errMsg: 'setNavigationBarColor:ok' };
|
|
3256
|
+
(_a = page.$set) === null || _a === void 0 ? void 0 : _a.call(page, 'taroNavBar.textStyle', frontColor);
|
|
3257
|
+
(_b = page.$set) === null || _b === void 0 ? void 0 : _b.call(page, 'taroNavBar.background', backgroundColor);
|
|
3258
|
+
callAsyncSuccess(resolve, res, options);
|
|
3259
|
+
});
|
|
3260
|
+
};
|
|
3261
|
+
const showNavigationBarLoading = temporarilyNotSupport('showNavigationBarLoading');
|
|
3262
|
+
const hideNavigationBarLoading = temporarilyNotSupport('hideNavigationBarLoading');
|
|
3263
|
+
const hideHomeButton = temporarilyNotSupport('hideHomeButton');
|
|
3264
|
+
|
|
3265
|
+
const startPullDownRefresh = function (options) {
|
|
3266
|
+
return new Promise(resolve => {
|
|
3267
|
+
var _a;
|
|
3268
|
+
const taro = Current.taro;
|
|
3269
|
+
const page = taro.getCurrentInstance().page;
|
|
3270
|
+
if (page.isRefreshing instanceof Array) {
|
|
3271
|
+
const index = page.tabBarCurrentIndex || 0;
|
|
3272
|
+
page.isRefreshing[index] = true;
|
|
3273
|
+
}
|
|
3274
|
+
else {
|
|
3275
|
+
page.isRefreshing = true;
|
|
3276
|
+
}
|
|
3277
|
+
const res = { errMsg: 'startPullDownRefresh:ok' };
|
|
3278
|
+
(_a = page.$set) === null || _a === void 0 ? void 0 : _a.call(page, 'isRefreshing', true);
|
|
3279
|
+
callAsyncSuccess(resolve, res, options);
|
|
3280
|
+
});
|
|
3281
|
+
};
|
|
3282
|
+
const stopPullDownRefresh = function (options) {
|
|
3283
|
+
return new Promise(resolve => {
|
|
3284
|
+
var _a;
|
|
3285
|
+
const taro = Current.taro;
|
|
3286
|
+
const page = taro.getCurrentInstance().page;
|
|
3287
|
+
if (page.isRefreshing instanceof Array) {
|
|
3288
|
+
const index = page.tabBarCurrentIndex || 0;
|
|
3289
|
+
page.isRefreshing[index] = false;
|
|
3290
|
+
}
|
|
3291
|
+
else {
|
|
3292
|
+
page.isRefreshing = false;
|
|
3293
|
+
}
|
|
3294
|
+
const res = { errMsg: 'stopPullDownRefresh:ok' };
|
|
3295
|
+
(_a = page.$set) === null || _a === void 0 ? void 0 : _a.call(page, 'isRefreshing', false);
|
|
3296
|
+
callAsyncSuccess(resolve, res, options);
|
|
3297
|
+
});
|
|
3298
|
+
};
|
|
3299
|
+
|
|
3300
|
+
const createAnimation = (option) => {
|
|
3301
|
+
return new Animation(option);
|
|
3302
|
+
};
|
|
3303
|
+
const getMenuButtonBoundingClientRect = temporarilyNotSupport('getMenuButtonBoundingClientRect');
|
|
3304
|
+
|
|
3305
|
+
// @ts-ignore
|
|
3306
|
+
class IntersectionObserver {
|
|
3307
|
+
constructor(component, options = {}) {
|
|
3308
|
+
// 选项
|
|
3309
|
+
this._options = {
|
|
3310
|
+
thresholds: [0],
|
|
3311
|
+
initialRatio: 0,
|
|
3312
|
+
observeAll: false
|
|
3313
|
+
};
|
|
3314
|
+
const taro = Current.taro;
|
|
3315
|
+
const page = taro.getCurrentInstance().page;
|
|
3316
|
+
const currentPage = getPageScrollerOrNode(page.node, page);
|
|
3317
|
+
this._component = component || currentPage;
|
|
3318
|
+
Object.assign(this._options, options);
|
|
3319
|
+
}
|
|
3320
|
+
disconnect() {
|
|
3321
|
+
var _a, _b, _c;
|
|
3322
|
+
if (this._observerNodes) {
|
|
3323
|
+
if (this._observerNodes instanceof Array) {
|
|
3324
|
+
this._observerNodes.forEach((n) => {
|
|
3325
|
+
var _a, _b, _c;
|
|
3326
|
+
disconnectEvent(n, VISIBLE_CHANGE_EVENT_NAME);
|
|
3327
|
+
if (n._instance) {
|
|
3328
|
+
// @ts-ignore
|
|
3329
|
+
(_c = (_b = (_a = n._instance) === null || _a === void 0 ? void 0 : _a.nodeInfoMap) === null || _b === void 0 ? void 0 : _b[n._nid]) === null || _c === void 0 ? void 0 : _c.thresholds = null;
|
|
3330
|
+
}
|
|
3331
|
+
});
|
|
3332
|
+
}
|
|
3333
|
+
else {
|
|
3334
|
+
disconnectEvent(this._observerNodes, VISIBLE_CHANGE_EVENT_NAME);
|
|
3335
|
+
// @ts-ignore
|
|
3336
|
+
if (this._observerNodes._instance) {
|
|
3337
|
+
// @ts-ignore
|
|
3338
|
+
(_c = (_b = (_a = this._observerNodes._instance) === null || _a === void 0 ? void 0 : _a.nodeInfoMap) === null || _b === void 0 ? void 0 : _b[this._observerNodes._nid]) === null || _c === void 0 ? void 0 : _c.thresholds = null;
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3343
|
+
observe(targetSelector, callback) {
|
|
3344
|
+
const { observeAll, thresholds } = this._options;
|
|
3345
|
+
const node = findChildNodeWithDFS(this._component, targetSelector, observeAll);
|
|
3346
|
+
this._observerNodes = node;
|
|
3347
|
+
if (node) {
|
|
3348
|
+
if (node instanceof Array) {
|
|
3349
|
+
node.forEach(n => {
|
|
3350
|
+
// @ts-ignore
|
|
3351
|
+
n.awaitAppear.then(() => {
|
|
3352
|
+
var _a, _b, _c;
|
|
3353
|
+
// @ts-ignore
|
|
3354
|
+
(_c = (_b = (_a = n._instance) === null || _a === void 0 ? void 0 : _a.nodeInfoMap) === null || _b === void 0 ? void 0 : _b[n._nid]) === null || _c === void 0 ? void 0 : _c.thresholds = thresholds;
|
|
3355
|
+
setNodeEventCallbackAndTriggerComponentUpdate(n, VISIBLE_CHANGE_EVENT_NAME, (isVisible, currentRatio) => {
|
|
3356
|
+
callback(this.handleResult(isVisible, currentRatio));
|
|
3357
|
+
});
|
|
3358
|
+
});
|
|
3359
|
+
});
|
|
3360
|
+
}
|
|
3361
|
+
else {
|
|
3362
|
+
// @ts-ignore
|
|
3363
|
+
node.awaitAppear.then(() => {
|
|
3364
|
+
var _a, _b, _c;
|
|
3365
|
+
// @ts-ignore
|
|
3366
|
+
(_c = (_b = (_a = node._instance) === null || _a === void 0 ? void 0 : _a.nodeInfoMap) === null || _b === void 0 ? void 0 : _b[node._nid]) === null || _c === void 0 ? void 0 : _c.thresholds = thresholds;
|
|
3367
|
+
setNodeEventCallbackAndTriggerComponentUpdate(node, VISIBLE_CHANGE_EVENT_NAME, (isVisible, currentRatio) => {
|
|
3368
|
+
callback(this.handleResult(isVisible, currentRatio));
|
|
3369
|
+
});
|
|
3370
|
+
});
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3373
|
+
}
|
|
3374
|
+
relativeTo() {
|
|
3375
|
+
temporarilyNotSupport('relativeTo')();
|
|
3376
|
+
return this;
|
|
3377
|
+
}
|
|
3378
|
+
relativeToViewport() {
|
|
3379
|
+
temporarilyNotSupport('relativeToViewport')();
|
|
3380
|
+
return this;
|
|
3381
|
+
}
|
|
3382
|
+
// @ts-ignore
|
|
3383
|
+
handleResult(isVisible, currentRatio) {
|
|
3384
|
+
const result = {
|
|
3385
|
+
intersectionRatio: currentRatio,
|
|
3386
|
+
// TODO 未做,等待能拿到element的info信息
|
|
3387
|
+
boundingClientRect: {
|
|
3388
|
+
left: 0,
|
|
3389
|
+
right: 0,
|
|
3390
|
+
top: 0,
|
|
3391
|
+
bottom: 0,
|
|
3392
|
+
height: 0,
|
|
3393
|
+
width: 0
|
|
3394
|
+
},
|
|
3395
|
+
// TODO 未做,等待能拿到element和监听_component的info信息做运算
|
|
3396
|
+
intersectionRect: {
|
|
3397
|
+
left: 0,
|
|
3398
|
+
right: 0,
|
|
3399
|
+
top: 0,
|
|
3400
|
+
bottom: 0,
|
|
3401
|
+
height: 0,
|
|
3402
|
+
width: 0
|
|
3403
|
+
},
|
|
3404
|
+
// TODO 未做,等待能拿到element和监听_component的info信息做运算
|
|
3405
|
+
relativeRect: { left: 0, right: 0, top: 0, bottom: 0 },
|
|
3406
|
+
time: new Date().getTime()
|
|
3407
|
+
};
|
|
3408
|
+
return result;
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
|
|
3412
|
+
class NodesRef {
|
|
3413
|
+
constructor(selector, querySelectorQuery, single) {
|
|
3414
|
+
this._component = querySelectorQuery._component;
|
|
3415
|
+
this._selector = selector;
|
|
3416
|
+
this._selectorQuery = querySelectorQuery;
|
|
3417
|
+
this._single = single;
|
|
3418
|
+
}
|
|
3419
|
+
context(cb) {
|
|
3420
|
+
const { _selector, _component, _single, _selectorQuery } = this;
|
|
3421
|
+
_selectorQuery._push(_selector, _component, _single, { context: !0 }, cb);
|
|
3422
|
+
return _selectorQuery;
|
|
3423
|
+
}
|
|
3424
|
+
node(cb) {
|
|
3425
|
+
const { _selector, _component, _single, _selectorQuery } = this;
|
|
3426
|
+
_selectorQuery._push(_selector, _component, _single, { nodeCanvasType: !0, node: !0 }, cb);
|
|
3427
|
+
return _selectorQuery;
|
|
3428
|
+
}
|
|
3429
|
+
boundingClientRect(cb) {
|
|
3430
|
+
const { _selector, _component, _single, _selectorQuery } = this;
|
|
3431
|
+
_selectorQuery._push(_selector, _component, _single, { id: !0, dataset: !0, rect: !0, size: !0 }, cb);
|
|
3432
|
+
return _selectorQuery;
|
|
3433
|
+
}
|
|
3434
|
+
scrollOffset(cb) {
|
|
3435
|
+
const { _selector, _component, _single, _selectorQuery } = this;
|
|
3436
|
+
_selectorQuery._push(_selector, _component, _single, { id: !0, dataset: !0, scrollOffset: !0 }, cb);
|
|
3437
|
+
return _selectorQuery;
|
|
3438
|
+
}
|
|
3439
|
+
fields(fields, cb) {
|
|
3440
|
+
const { _selector, _component, _single, _selectorQuery } = this;
|
|
3441
|
+
const { id, dataset, rect, size, scrollOffset, properties = [], computedStyle = [] } = fields;
|
|
3442
|
+
_selectorQuery._push(_selector, _component, _single, {
|
|
3443
|
+
id,
|
|
3444
|
+
dataset,
|
|
3445
|
+
rect,
|
|
3446
|
+
size,
|
|
3447
|
+
scrollOffset,
|
|
3448
|
+
properties,
|
|
3449
|
+
computedStyle
|
|
3450
|
+
}, cb);
|
|
3451
|
+
return _selectorQuery;
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
|
|
3455
|
+
let arr = [];
|
|
3456
|
+
// 深度搜索 rootDom 下的所有节点,存放在 arr 中
|
|
3457
|
+
function traversalDFSDom(rootDom) {
|
|
3458
|
+
if (!rootDom)
|
|
3459
|
+
return;
|
|
3460
|
+
arr.push(rootDom);
|
|
3461
|
+
if (rootDom.childNodes.length === 0)
|
|
3462
|
+
return;
|
|
3463
|
+
for (let i = 0; i < rootDom.childNodes.length; i++) {
|
|
3464
|
+
traversalDFSDom(rootDom.childNodes[i]);
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3467
|
+
// 从 arr 中寻找所有符合 selector 的节点
|
|
3468
|
+
function parseHandler(selector, selectAll) {
|
|
3469
|
+
var _a;
|
|
3470
|
+
const domList = [];
|
|
3471
|
+
if (arr.length === 0)
|
|
3472
|
+
return null;
|
|
3473
|
+
let selectedId, clsList;
|
|
3474
|
+
switch (selector.charAt(0)) {
|
|
3475
|
+
case '#': // id selector
|
|
3476
|
+
selectedId = selector.substring(1);
|
|
3477
|
+
for (let i = 0; i < arr.length; i++) {
|
|
3478
|
+
if (arr[i].id === selectedId) {
|
|
3479
|
+
domList.push(arr[i]);
|
|
3480
|
+
if (!selectAll) {
|
|
3481
|
+
break;
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
}
|
|
3485
|
+
break;
|
|
3486
|
+
case '.':
|
|
3487
|
+
clsList = selector.split('.').filter((item) => item !== '');
|
|
3488
|
+
if (clsList.length === 0)
|
|
3489
|
+
break;
|
|
3490
|
+
for (let i = 0; i < arr.length; i++) {
|
|
3491
|
+
for (let j = 0; j < clsList.length; j++) {
|
|
3492
|
+
if ((_a = arr[i].className) === null || _a === void 0 ? void 0 : _a.includes(clsList[j])) {
|
|
3493
|
+
domList.push(arr[i]);
|
|
3494
|
+
if (!selectAll) {
|
|
3495
|
+
break;
|
|
3496
|
+
}
|
|
3497
|
+
}
|
|
3498
|
+
}
|
|
3499
|
+
}
|
|
3500
|
+
break;
|
|
3501
|
+
default:
|
|
3502
|
+
console.warn('unSupport selector');
|
|
3503
|
+
break;
|
|
3504
|
+
}
|
|
3505
|
+
if (selectAll) {
|
|
3506
|
+
return domList;
|
|
3507
|
+
}
|
|
3508
|
+
else if (domList.length > 0) {
|
|
3509
|
+
return [domList[0]];
|
|
3510
|
+
}
|
|
3511
|
+
return [];
|
|
3512
|
+
}
|
|
3513
|
+
// 从 TaroNode 里找到对应的 fields 内容
|
|
3514
|
+
function filter(fields, dom) {
|
|
3515
|
+
var _a, _b;
|
|
3516
|
+
if (!dom)
|
|
3517
|
+
return null;
|
|
3518
|
+
const { id,
|
|
3519
|
+
// dataset,
|
|
3520
|
+
rect, size, scrollOffset, properties = [], computedStyle = [], nodeCanvasType, node, context } = fields;
|
|
3521
|
+
const res = {};
|
|
3522
|
+
if (nodeCanvasType && node) { // Node节点获取处理
|
|
3523
|
+
const typeName = dom.nodeName;
|
|
3524
|
+
res.node = {
|
|
3525
|
+
id: dom.id,
|
|
3526
|
+
$taroElement: dom
|
|
3527
|
+
};
|
|
3528
|
+
if (/^canvas/i.test(typeName)) {
|
|
3529
|
+
// harmony todo canvas attr type
|
|
3530
|
+
const canvasType = dom._attrs.type || '';
|
|
3531
|
+
res.nodeCanvasType = canvasType;
|
|
3532
|
+
if (/^(2d|webgl)/i.test(canvasType) && dom) {
|
|
3533
|
+
res.node = dom;
|
|
3534
|
+
}
|
|
3535
|
+
else {
|
|
3536
|
+
res.node = null;
|
|
3537
|
+
}
|
|
3538
|
+
}
|
|
3539
|
+
else {
|
|
3540
|
+
// TODO https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html
|
|
3541
|
+
// if (/^taro-scroll-view-core/i.test(tagName))
|
|
3542
|
+
res.nodeCanvasType = '';
|
|
3543
|
+
res.node = dom;
|
|
3544
|
+
}
|
|
3545
|
+
return res;
|
|
3546
|
+
}
|
|
3547
|
+
if (id)
|
|
3548
|
+
res.id = dom.id;
|
|
3549
|
+
// TODO harmony dataset
|
|
3550
|
+
// if (dataset) res.dataset = Object.assign({}, dom.dataset)
|
|
3551
|
+
if (rect || size) {
|
|
3552
|
+
const id = dom === null || dom === void 0 ? void 0 : dom._nid;
|
|
3553
|
+
const { areaInfo } = ((_b = (_a = dom === null || dom === void 0 ? void 0 : dom._instance) === null || _a === void 0 ? void 0 : _a.nodeInfoMap) === null || _b === void 0 ? void 0 : _b[id]) || {};
|
|
3554
|
+
if (areaInfo) {
|
|
3555
|
+
if (rect) {
|
|
3556
|
+
res.top = vp2px(areaInfo.globalPosition.y);
|
|
3557
|
+
res.left = vp2px(areaInfo.globalPosition.x);
|
|
3558
|
+
res.right = vp2px(areaInfo.globalPosition.x + areaInfo.width);
|
|
3559
|
+
res.bottom = vp2px(areaInfo.globalPosition.y + areaInfo.height);
|
|
3560
|
+
}
|
|
3561
|
+
if (size) {
|
|
3562
|
+
res.width = vp2px(areaInfo.width);
|
|
3563
|
+
res.height = vp2px(areaInfo.height);
|
|
3564
|
+
}
|
|
3565
|
+
}
|
|
3566
|
+
}
|
|
3567
|
+
if (scrollOffset) {
|
|
3568
|
+
const scroller = dom._instance.scroller;
|
|
3569
|
+
if (scroller) {
|
|
3570
|
+
const { xOffset, yOffset } = scroller.currentOffset();
|
|
3571
|
+
res.scrollLeft = vp2px(xOffset);
|
|
3572
|
+
res.scrollTop = vp2px(yOffset);
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
if (properties.length) {
|
|
3576
|
+
properties.forEach(prop => {
|
|
3577
|
+
const attrs = dom._attrs;
|
|
3578
|
+
if (attrs[prop])
|
|
3579
|
+
res[prop] = attrs[prop];
|
|
3580
|
+
});
|
|
3581
|
+
}
|
|
3582
|
+
if (computedStyle.length) {
|
|
3583
|
+
const styles = dom._st;
|
|
3584
|
+
computedStyle.forEach(key => {
|
|
3585
|
+
const value = styles[key];
|
|
3586
|
+
if (value)
|
|
3587
|
+
res[key] = value;
|
|
3588
|
+
});
|
|
3589
|
+
}
|
|
3590
|
+
return res;
|
|
3591
|
+
}
|
|
3592
|
+
function querySelector(selector, selectAll) {
|
|
3593
|
+
if (typeof selector === 'string') {
|
|
3594
|
+
return parseHandler(selector, selectAll);
|
|
3595
|
+
}
|
|
3596
|
+
return null;
|
|
3597
|
+
}
|
|
3598
|
+
function queryBat(queue, cb) {
|
|
3599
|
+
const result = [];
|
|
3600
|
+
const taro = Current.taro;
|
|
3601
|
+
const page = taro.getCurrentInstance().page;
|
|
3602
|
+
const element = getPageScrollerOrNode(page.node, page);
|
|
3603
|
+
if (element == null)
|
|
3604
|
+
return null;
|
|
3605
|
+
arr = [];
|
|
3606
|
+
traversalDFSDom(element);
|
|
3607
|
+
queue.forEach(item => {
|
|
3608
|
+
const { selector, single, fields } = item;
|
|
3609
|
+
const nodeList = querySelector(selector, !single);
|
|
3610
|
+
result.push(nodeList.map(dom => {
|
|
3611
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
3612
|
+
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
3613
|
+
yield setNodeEventCallbackAndTriggerComponentUpdate(dom, AREA_CHANGE_EVENT_NAME, null, true);
|
|
3614
|
+
resolve(filter(fields, dom));
|
|
3615
|
+
}));
|
|
3616
|
+
}));
|
|
3617
|
+
});
|
|
3618
|
+
Promise.all(result.map(item => {
|
|
3619
|
+
return Promise.all(item);
|
|
3620
|
+
})).then(data => {
|
|
3621
|
+
cb(data);
|
|
3622
|
+
});
|
|
3623
|
+
}
|
|
3624
|
+
class SelectorQuery {
|
|
3625
|
+
constructor() {
|
|
3626
|
+
/**
|
|
3627
|
+
* 设置选择器的选取范围
|
|
3628
|
+
* @param component 指定组件
|
|
3629
|
+
* @return selectQuery 返回查询对象
|
|
3630
|
+
*/
|
|
3631
|
+
this.in = (_) => {
|
|
3632
|
+
this._component = null;
|
|
3633
|
+
console.warn('暂不支持 in 操作');
|
|
3634
|
+
// this._component = component
|
|
3635
|
+
return this;
|
|
3636
|
+
};
|
|
3637
|
+
this._queue = [];
|
|
3638
|
+
this._queueCb = [];
|
|
3639
|
+
// this._component
|
|
3640
|
+
}
|
|
3641
|
+
/**
|
|
3642
|
+
* 在当前页面下选择第一个匹配选择器selector的节点
|
|
3643
|
+
* @param selector
|
|
3644
|
+
* @return nodesRef 返回一个NodesRef 对象实例,可以用于获取节点信息
|
|
3645
|
+
*/
|
|
3646
|
+
select(selector) {
|
|
3647
|
+
return new NodesRef(selector, this, true);
|
|
3648
|
+
}
|
|
3649
|
+
/**
|
|
3650
|
+
* 在当前页面下选择匹配选择器selector的所有节点
|
|
3651
|
+
* @param selector
|
|
3652
|
+
*/
|
|
3653
|
+
selectAll(selector) {
|
|
3654
|
+
return new NodesRef(selector, this, false);
|
|
3655
|
+
}
|
|
3656
|
+
/**
|
|
3657
|
+
* 选择显示区域。可用于获取显示区域的尺寸、滚动位置等信息
|
|
3658
|
+
*/
|
|
3659
|
+
selectViewport() {
|
|
3660
|
+
return new NodesRef('.taro_page', this, true);
|
|
3661
|
+
}
|
|
3662
|
+
exec(cb) {
|
|
3663
|
+
queryBat(this._queue, res => {
|
|
3664
|
+
const _queueCb = this._queueCb;
|
|
3665
|
+
res.forEach((item, index) => {
|
|
3666
|
+
const cb = _queueCb[index];
|
|
3667
|
+
typeof cb === 'function' && cb.call(this, item);
|
|
3668
|
+
});
|
|
3669
|
+
typeof cb === 'function' && cb.call(this, res);
|
|
3670
|
+
});
|
|
3671
|
+
return this;
|
|
3672
|
+
}
|
|
3673
|
+
_push(selector, component, single, fields, callback = null) {
|
|
3674
|
+
this._queue.push({
|
|
3675
|
+
component,
|
|
3676
|
+
selector,
|
|
3677
|
+
single,
|
|
3678
|
+
fields
|
|
3679
|
+
});
|
|
3680
|
+
this._queueCb.push(callback);
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
|
|
3684
|
+
const createSelectorQuery = () => {
|
|
3685
|
+
return new SelectorQuery();
|
|
3686
|
+
};
|
|
3687
|
+
const createIntersectionObserver = (component, options) => {
|
|
3688
|
+
return new IntersectionObserver(component, options);
|
|
3689
|
+
};
|
|
3690
|
+
|
|
3691
|
+
var apis = /*#__PURE__*/Object.freeze({
|
|
3692
|
+
__proto__: null,
|
|
3693
|
+
ENV_TYPE: ENV_TYPE,
|
|
3694
|
+
Events: Events,
|
|
3695
|
+
History: History,
|
|
3696
|
+
authorize: authorize,
|
|
3697
|
+
chooseImage: chooseImage,
|
|
3698
|
+
chooseMedia: chooseMedia,
|
|
3699
|
+
chooseVideo: chooseVideo,
|
|
3700
|
+
clearStorage: clearStorage,
|
|
3701
|
+
clearStorageSync: clearStorageSync,
|
|
3702
|
+
compressImage: compressImage,
|
|
3703
|
+
connectSocket: connectSocket,
|
|
3704
|
+
createAnimation: createAnimation,
|
|
3705
|
+
createIntersectionObserver: createIntersectionObserver,
|
|
3706
|
+
createSelectorQuery: createSelectorQuery,
|
|
3707
|
+
downloadFile: downloadFile,
|
|
3708
|
+
eventCenter: eventCenter,
|
|
3709
|
+
exitMiniProgram: exitMiniProgram,
|
|
3710
|
+
getAccountInfoSync: getAccountInfoSync,
|
|
3711
|
+
getBatteryInfo: getBatteryInfo,
|
|
3712
|
+
getBatteryInfoSync: getBatteryInfoSync,
|
|
3713
|
+
getClipboardData: getClipboardData,
|
|
3714
|
+
getCurrentInstance: getCurrentInstance,
|
|
3715
|
+
getCurrentPages: getCurrentPages,
|
|
3716
|
+
getEnterOptionsSync: getEnterOptionsSync,
|
|
3717
|
+
getEnv: getEnv,
|
|
3718
|
+
getFileInfo: getFileInfo,
|
|
3719
|
+
getFileSystemManager: getFileSystemManager,
|
|
3720
|
+
getImageInfo: getImageInfo,
|
|
3721
|
+
getLaunchOptionsSync: getLaunchOptionsSync,
|
|
3722
|
+
getLength: getLength,
|
|
3723
|
+
getLocalIPAddress: getLocalIPAddress,
|
|
3724
|
+
getLocation: getLocation,
|
|
3725
|
+
getMenuButtonBoundingClientRect: getMenuButtonBoundingClientRect,
|
|
3726
|
+
getNetworkType: getNetworkType,
|
|
3727
|
+
getSavedFileInfo: getSavedFileInfo,
|
|
3728
|
+
getSavedFileList: getSavedFileList,
|
|
3729
|
+
getScreenBrightness: getScreenBrightness,
|
|
3730
|
+
getScreenRecordingState: getScreenRecordingState,
|
|
3731
|
+
getSelectedTextRange: getSelectedTextRange,
|
|
3732
|
+
getSetting: getSetting,
|
|
3733
|
+
getState: getState,
|
|
3734
|
+
getStorage: getStorage,
|
|
3735
|
+
getStorageSync: getStorageSync,
|
|
3736
|
+
getSystemInfo: getSystemInfo,
|
|
3737
|
+
getSystemInfoSync: getSystemInfoSync,
|
|
3738
|
+
getUpdateManager: getUpdateManager,
|
|
3739
|
+
getUserInfo: getUserInfo,
|
|
3740
|
+
getUserProfile: getUserProfile,
|
|
3741
|
+
hideHomeButton: hideHomeButton,
|
|
3742
|
+
hideKeyboard: hideKeyboard,
|
|
3743
|
+
hideLoading: hideLoading,
|
|
3744
|
+
hideNavigationBarLoading: hideNavigationBarLoading,
|
|
3745
|
+
hideTabBar: hideTabBar,
|
|
3746
|
+
hideTabBarRedDot: hideTabBarRedDot,
|
|
3747
|
+
hideToast: hideToast,
|
|
3748
|
+
login: login,
|
|
3749
|
+
makePhoneCall: makePhoneCall,
|
|
3750
|
+
navigateBack: navigateBack,
|
|
3751
|
+
navigateBackMiniProgram: navigateBackMiniProgram,
|
|
3752
|
+
navigateTo: navigateTo,
|
|
3753
|
+
navigateToMiniProgram: navigateToMiniProgram,
|
|
3754
|
+
nextTick: nextTick,
|
|
3755
|
+
offAccelerometerChange: offAccelerometerChange,
|
|
3756
|
+
offKeyboardHeightChange: offKeyboardHeightChange,
|
|
3757
|
+
offLocationChange: offLocationChange,
|
|
3758
|
+
offMemoryWarning: offMemoryWarning,
|
|
3759
|
+
offNetworkStatusChange: offNetworkStatusChange,
|
|
3760
|
+
offNetworkWeakChange: offNetworkWeakChange,
|
|
3761
|
+
offScreenRecordingStateChanged: offScreenRecordingStateChanged,
|
|
3762
|
+
offUserCaptureScreen: offUserCaptureScreen,
|
|
3763
|
+
onAccelerometerChange: onAccelerometerChange,
|
|
3764
|
+
onKeyboardHeightChange: onKeyboardHeightChange,
|
|
3765
|
+
onLocationChange: onLocationChange,
|
|
3766
|
+
onMemoryWarning: onMemoryWarning,
|
|
3767
|
+
onNetworkStatusChange: onNetworkStatusChange,
|
|
3768
|
+
onNetworkWeakChange: onNetworkWeakChange,
|
|
3769
|
+
onScreenRecordingStateChanged: onScreenRecordingStateChanged,
|
|
3770
|
+
onUserCaptureScreen: onUserCaptureScreen,
|
|
3771
|
+
openBusinessView: openBusinessView,
|
|
3772
|
+
openDocument: openDocument,
|
|
3773
|
+
openEmbeddedMiniProgram: openEmbeddedMiniProgram,
|
|
3774
|
+
openSetting: openSetting,
|
|
3775
|
+
pageScrollTo: pageScrollTo,
|
|
3776
|
+
previewImage: previewImage,
|
|
3777
|
+
previewMedia: previewMedia,
|
|
3778
|
+
reLaunch: reLaunch,
|
|
3779
|
+
redirectTo: redirectTo,
|
|
3780
|
+
removeSavedFile: removeSavedFile,
|
|
3781
|
+
removeStorage: removeStorage,
|
|
3782
|
+
removeStorageSync: removeStorageSync,
|
|
3783
|
+
removeTabBarBadge: removeTabBarBadge,
|
|
3784
|
+
request: request,
|
|
3785
|
+
requestSubscribeMessage: requestSubscribeMessage,
|
|
3786
|
+
requirePlugin: requirePlugin$1,
|
|
3787
|
+
saveFile: saveFile,
|
|
3788
|
+
saveFileToDisk: saveFileToDisk,
|
|
3789
|
+
saveImageToPhotosAlbum: saveImageToPhotosAlbum,
|
|
3790
|
+
saveVideoToPhotosAlbum: saveVideoToPhotosAlbum,
|
|
3791
|
+
setBackgroundColor: setBackgroundColor,
|
|
3792
|
+
setClipboardData: setClipboardData,
|
|
3793
|
+
setKeepScreenOn: setKeepScreenOn,
|
|
3794
|
+
setNavigationBarColor: setNavigationBarColor,
|
|
3795
|
+
setNavigationBarTitle: setNavigationBarTitle,
|
|
3796
|
+
setScreenBrightness: setScreenBrightness,
|
|
3797
|
+
setStorage: setStorage,
|
|
3798
|
+
setStorageSync: setStorageSync,
|
|
3799
|
+
setTabBarBadge: setTabBarBadge,
|
|
3800
|
+
setTabBarItem: setTabBarItem,
|
|
3801
|
+
setTabBarStyle: setTabBarStyle,
|
|
3802
|
+
setVisualEffectOnCapture: setVisualEffectOnCapture,
|
|
3803
|
+
showActionSheet: showActionSheet,
|
|
3804
|
+
showLoading: showLoading,
|
|
3805
|
+
showModal: showModal,
|
|
3806
|
+
showNavigationBarLoading: showNavigationBarLoading,
|
|
3807
|
+
showTabBar: showTabBar,
|
|
3808
|
+
showTabBarRedDot: showTabBarRedDot,
|
|
3809
|
+
showToast: showToast,
|
|
3810
|
+
startAccelerometer: startAccelerometer,
|
|
3811
|
+
startPullDownRefresh: startPullDownRefresh,
|
|
3812
|
+
stopAccelerometer: stopAccelerometer,
|
|
3813
|
+
stopPullDownRefresh: stopPullDownRefresh,
|
|
3814
|
+
switchTab: switchTab,
|
|
3815
|
+
uploadFile: uploadFile,
|
|
3816
|
+
vibrateLong: vibrateLong,
|
|
3817
|
+
vibrateShort: vibrateShort
|
|
3818
|
+
});
|
|
3819
|
+
|
|
3820
|
+
Object.assign({}, apis);
|
|
3821
|
+
const requirePlugin = /* @__PURE__ */ permanentlyNotSupport('requirePlugin');
|
|
3822
|
+
function initNativeApi(taro) {
|
|
3823
|
+
Current.taro = taro;
|
|
3824
|
+
taro.requirePlugin = requirePlugin;
|
|
3825
|
+
taro.getApp = getApp$1;
|
|
3826
|
+
taro.pxTransform = pxTransform;
|
|
3827
|
+
taro.initPxTransform = initPxTransform;
|
|
3828
|
+
taro.canIUseWebp = canIUseWebp;
|
|
3829
|
+
taro.getAppInfo = getAppInfo;
|
|
3830
|
+
if (hooks.isExist('initNativeApi')) {
|
|
3831
|
+
hooks.call('initNativeApi', taro);
|
|
3832
|
+
}
|
|
3833
|
+
}
|
|
3834
|
+
const defaultDesignWidth = 750;
|
|
3835
|
+
const defaultDesignRatio = {
|
|
3836
|
+
640: 2.34 / 2,
|
|
3837
|
+
750: 1,
|
|
3838
|
+
828: 1.81 / 2
|
|
3839
|
+
};
|
|
3840
|
+
const defaultBaseFontSize = 20;
|
|
3841
|
+
const defaultUnitPrecision = 5;
|
|
3842
|
+
const defaultTargetUnit = 'vp';
|
|
3843
|
+
function getApp$1() {
|
|
3844
|
+
return Current.app;
|
|
3845
|
+
}
|
|
3846
|
+
function initPxTransform({ designWidth = defaultDesignWidth, deviceRatio = defaultDesignRatio, baseFontSize = defaultBaseFontSize, unitPrecision = defaultUnitPrecision, targetUnit = defaultTargetUnit }) {
|
|
3847
|
+
const taro = Current.taro;
|
|
3848
|
+
if (taro) {
|
|
3849
|
+
taro.config || (taro.config = {});
|
|
3850
|
+
const config = taro.config;
|
|
3851
|
+
config.designWidth = designWidth;
|
|
3852
|
+
config.deviceRatio = deviceRatio;
|
|
3853
|
+
config.baseFontSize = baseFontSize;
|
|
3854
|
+
config.targetUnit = targetUnit;
|
|
3855
|
+
config.unitPrecision = unitPrecision;
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
_display.getDefaultDisplaySync();
|
|
3859
|
+
function pxTransform(size) {
|
|
3860
|
+
var _a;
|
|
3861
|
+
const config = ((_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config) || {};
|
|
3862
|
+
const targetUnit = config.targetUnit || defaultTargetUnit;
|
|
3863
|
+
let val = size;
|
|
3864
|
+
switch (targetUnit) {
|
|
3865
|
+
case 'vp':
|
|
3866
|
+
val = px2vp(size);
|
|
3867
|
+
break;
|
|
3868
|
+
// NOTE: 鸿蒙环境下 style 会自动完成设计稿转换,无需在方法内二次调整
|
|
3869
|
+
}
|
|
3870
|
+
return val + config.targetUnit;
|
|
3871
|
+
}
|
|
3872
|
+
function canIUseWebp() {
|
|
3873
|
+
return true;
|
|
3874
|
+
}
|
|
3875
|
+
function getAppInfo() {
|
|
3876
|
+
var _a;
|
|
3877
|
+
const config = (_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config;
|
|
3878
|
+
return {
|
|
3879
|
+
platform: process.env.TARO_PLATFORM || PLATFORM_TYPE.HARMONY,
|
|
3880
|
+
taroVersion: process.env.TARO_VERSION || 'unknown',
|
|
3881
|
+
designWidth: config === null || config === void 0 ? void 0 : config.designWidth,
|
|
3882
|
+
};
|
|
3883
|
+
}
|
|
3884
|
+
|
|
3885
|
+
const components = {
|
|
3886
|
+
Checkbox: {
|
|
3887
|
+
'group-id': '',
|
|
3888
|
+
cn: ''
|
|
3889
|
+
},
|
|
3890
|
+
Span: {},
|
|
3891
|
+
Tabs: {
|
|
3892
|
+
index: '0',
|
|
3893
|
+
vertical: 'false',
|
|
3894
|
+
bindchange: ''
|
|
3895
|
+
},
|
|
3896
|
+
TabBar: {
|
|
3897
|
+
mode: singleQuote('scrollable')
|
|
3898
|
+
},
|
|
3899
|
+
TabContent: {
|
|
3900
|
+
scrollable: 'true'
|
|
3901
|
+
},
|
|
3902
|
+
List: {
|
|
3903
|
+
scrollpage: 'false',
|
|
3904
|
+
cachedcount: '0',
|
|
3905
|
+
scrollbar: 'off',
|
|
3906
|
+
scrolleffect: singleQuote('spring'),
|
|
3907
|
+
indexer: 'false',
|
|
3908
|
+
indexercircle: '',
|
|
3909
|
+
indexermulti: 'false',
|
|
3910
|
+
indexerbubble: 'true',
|
|
3911
|
+
divider: 'false',
|
|
3912
|
+
shapemode: singleQuote('default'),
|
|
3913
|
+
itemscale: 'true',
|
|
3914
|
+
itemcenter: 'false',
|
|
3915
|
+
updateeffect: 'false',
|
|
3916
|
+
chainanimation: 'false',
|
|
3917
|
+
scrollvibrate: 'true',
|
|
3918
|
+
initialindex: '0',
|
|
3919
|
+
initialoffset: '0',
|
|
3920
|
+
selected: '',
|
|
3921
|
+
bindindexerchange: '',
|
|
3922
|
+
bindscroll: '',
|
|
3923
|
+
bindscrollbottom: '',
|
|
3924
|
+
bindscrolltop: '',
|
|
3925
|
+
bindscrollend: '',
|
|
3926
|
+
bindscrolltouchup: '',
|
|
3927
|
+
bindrequestitem: ''
|
|
3928
|
+
},
|
|
3929
|
+
ListItem: {
|
|
3930
|
+
type: singleQuote('default'),
|
|
3931
|
+
primary: 'false',
|
|
3932
|
+
section: '',
|
|
3933
|
+
sticky: singleQuote('none'),
|
|
3934
|
+
stickyradius: singleQuote('1000px'),
|
|
3935
|
+
clickeffect: 'true',
|
|
3936
|
+
bindsticky: ''
|
|
3937
|
+
},
|
|
3938
|
+
Switch: {
|
|
3939
|
+
showtext: 'false',
|
|
3940
|
+
texton: singleQuote('On'),
|
|
3941
|
+
textoff: singleQuote('Off')
|
|
3942
|
+
},
|
|
3943
|
+
Textarea: {
|
|
3944
|
+
headericon: '',
|
|
3945
|
+
showcounter: 'false',
|
|
3946
|
+
menuoptions: '[]',
|
|
3947
|
+
softkeyboardenabled: 'true',
|
|
3948
|
+
bindtranslate: '',
|
|
3949
|
+
bindshare: '',
|
|
3950
|
+
bindsearch: '',
|
|
3951
|
+
bindoptionselect: '',
|
|
3952
|
+
bindselectchange: ''
|
|
3953
|
+
},
|
|
3954
|
+
Progress: {
|
|
3955
|
+
'active-color': singleQuote('#09BB07'),
|
|
3956
|
+
'background-color': singleQuote('#EBEBEB'),
|
|
3957
|
+
type: singleQuote('horizontal'),
|
|
3958
|
+
'font-size': singleQuote('25px'),
|
|
3959
|
+
secondarypercent: '0',
|
|
3960
|
+
clockwise: 'true'
|
|
3961
|
+
},
|
|
3962
|
+
Slider: {
|
|
3963
|
+
showsteps: 'false',
|
|
3964
|
+
showtips: 'false'
|
|
3965
|
+
},
|
|
3966
|
+
Input: {
|
|
3967
|
+
'placeholder-color': singleQuote('#99000000')
|
|
3968
|
+
},
|
|
3969
|
+
Video: {
|
|
3970
|
+
speed: '1',
|
|
3971
|
+
bindloadedmetadata: '',
|
|
3972
|
+
bindprogress: '',
|
|
3973
|
+
bindtap: ''
|
|
3974
|
+
},
|
|
3975
|
+
Image: {
|
|
3976
|
+
alt: ''
|
|
3977
|
+
},
|
|
3978
|
+
Radio: {
|
|
3979
|
+
'group-id': ''
|
|
3980
|
+
},
|
|
3981
|
+
Picker: {
|
|
3982
|
+
selected: '',
|
|
3983
|
+
hours: '',
|
|
3984
|
+
containsecond: 'false',
|
|
3985
|
+
vibrate: 'true',
|
|
3986
|
+
lunar: 'false',
|
|
3987
|
+
lunarswitch: 'false'
|
|
3988
|
+
},
|
|
3989
|
+
PickerView: {
|
|
3990
|
+
mode: '',
|
|
3991
|
+
range: '',
|
|
3992
|
+
selected: '',
|
|
3993
|
+
hours: '',
|
|
3994
|
+
indicatorprefix: '',
|
|
3995
|
+
indicatorsuffix: '',
|
|
3996
|
+
containsecond: 'false',
|
|
3997
|
+
vibrate: 'true',
|
|
3998
|
+
lunar: 'false',
|
|
3999
|
+
lunarswitch: 'false',
|
|
4000
|
+
bindcolumnchange: '',
|
|
4001
|
+
cn: ''
|
|
4002
|
+
}
|
|
4003
|
+
};
|
|
4004
|
+
|
|
4005
|
+
const BUBBLE_EVENTS = new Set([
|
|
4006
|
+
'touchStart',
|
|
4007
|
+
'touchMove',
|
|
4008
|
+
'touchEnd',
|
|
4009
|
+
'touchCancel',
|
|
4010
|
+
'click',
|
|
4011
|
+
'longTap'
|
|
4012
|
+
]);
|
|
4013
|
+
const hostConfig = {
|
|
4014
|
+
initNativeApi,
|
|
4015
|
+
modifyTaroEvent(event, node) {
|
|
4016
|
+
const comps = Object.keys(internalComponents).map(c => c.toLowerCase());
|
|
4017
|
+
const tagName = node.tagName.toLowerCase();
|
|
4018
|
+
if (event.type === 'click' && comps.includes(tagName)) {
|
|
4019
|
+
event.type = 'tap';
|
|
4020
|
+
}
|
|
4021
|
+
// getters & setters
|
|
4022
|
+
const { mpEvent } = event;
|
|
4023
|
+
// Note: Harmony ACE API 8 开发板该方法不存在
|
|
4024
|
+
const getOwnPropertyDescriptors = typeof Object.getOwnPropertyDescriptors === 'function' ? Object.getOwnPropertyDescriptors : (arg = {}) => (Object.assign({}, arg));
|
|
4025
|
+
// eslint-disable-next-line no-proto
|
|
4026
|
+
const mpEventDescs = Object.assign(Object.assign({}, (getOwnPropertyDescriptors(mpEvent) || {})), (getOwnPropertyDescriptors(mpEvent.__proto__) || {}));
|
|
4027
|
+
const descs = {};
|
|
4028
|
+
for (const key in mpEventDescs) {
|
|
4029
|
+
const item = mpEventDescs[key];
|
|
4030
|
+
if ((item.get || item.set) && key !== 'type') {
|
|
4031
|
+
descs[key] = item;
|
|
4032
|
+
}
|
|
4033
|
+
}
|
|
4034
|
+
Object.defineProperties(event, descs);
|
|
4035
|
+
},
|
|
4036
|
+
getPathIndex(indexOfNode) {
|
|
4037
|
+
return indexOfNode;
|
|
4038
|
+
},
|
|
4039
|
+
getSpecialNodes() {
|
|
4040
|
+
return [];
|
|
4041
|
+
},
|
|
4042
|
+
getMiniLifecycle(config) {
|
|
4043
|
+
config.app[0] = 'onCreate';
|
|
4044
|
+
config.page[0] = 'onInit';
|
|
4045
|
+
config.page[1] = 'onDestroy';
|
|
4046
|
+
config.page[5] = [
|
|
4047
|
+
'onActive',
|
|
4048
|
+
'onInactive',
|
|
4049
|
+
'onBackPress',
|
|
4050
|
+
'onNewRequest',
|
|
4051
|
+
'onStartContinuation',
|
|
4052
|
+
'onSaveData',
|
|
4053
|
+
'onRestoreData',
|
|
4054
|
+
'onCompleteContinuation',
|
|
4055
|
+
'onPullDownRefresh'
|
|
4056
|
+
];
|
|
4057
|
+
return config;
|
|
4058
|
+
},
|
|
4059
|
+
modifyPageObject(config) {
|
|
4060
|
+
const originOnInit = config.onInit;
|
|
4061
|
+
config.onInit = function () {
|
|
4062
|
+
// 对接小程序规范的 setData 到 harmony 规范的 $set
|
|
4063
|
+
this.setData = function (normalUpdate, cb) {
|
|
4064
|
+
Object.keys(normalUpdate).forEach(path => {
|
|
4065
|
+
this.$set(path, normalUpdate[path]);
|
|
4066
|
+
});
|
|
4067
|
+
cb();
|
|
4068
|
+
};
|
|
4069
|
+
// 处理路由参数
|
|
4070
|
+
const options = {};
|
|
4071
|
+
Object.keys(this._data).forEach(key => {
|
|
4072
|
+
if (!/^root\b/.test(key) && !/^\$i18n\b/.test(key)) {
|
|
4073
|
+
options[key] = this._data[key];
|
|
4074
|
+
}
|
|
4075
|
+
});
|
|
4076
|
+
// 调用 onInit
|
|
4077
|
+
originOnInit.call(this, options);
|
|
4078
|
+
// 手动记录路由堆栈
|
|
4079
|
+
const app = getApp();
|
|
4080
|
+
const pagePath = this.$taroPath.split('?')[0];
|
|
4081
|
+
if (!app.pageStack) {
|
|
4082
|
+
app.pageStack = [];
|
|
4083
|
+
}
|
|
4084
|
+
app.pageStack.push(pagePath);
|
|
4085
|
+
// 根据 page.config 初始化 navbar
|
|
4086
|
+
const appConfig = app.config;
|
|
4087
|
+
const pageConfig = this.config;
|
|
4088
|
+
const window = Object.assign({}, appConfig.window, pageConfig);
|
|
4089
|
+
this.$set('taroNavBar', {
|
|
4090
|
+
background: window.navigationBarBackgroundColor || '#000000',
|
|
4091
|
+
textStyle: window.navigationBarTextStyle || 'white',
|
|
4092
|
+
title: window.navigationBarTitleText || '',
|
|
4093
|
+
style: window.navigationStyle || 'default'
|
|
4094
|
+
});
|
|
4095
|
+
// 初始化下拉刷新组件
|
|
4096
|
+
this.$set('enablePullDownRefresh', Boolean(window.enablePullDownRefresh));
|
|
4097
|
+
this.$set('isRefreshing', false);
|
|
4098
|
+
// 根据 app.config 初始化 tabbar
|
|
4099
|
+
if (appConfig.tabBar) {
|
|
4100
|
+
const list = appConfig.tabBar.list;
|
|
4101
|
+
for (const idx in list) {
|
|
4102
|
+
const item = list[idx];
|
|
4103
|
+
if (item.pagePath === pagePath) {
|
|
4104
|
+
this.$set('selected', idx);
|
|
4105
|
+
this.$set('isShowTaroTabBar', true);
|
|
4106
|
+
this.$set('taroTabBar', appConfig.tabBar);
|
|
4107
|
+
break;
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
}
|
|
4111
|
+
};
|
|
4112
|
+
const originOnPullDownRefresh = config.onPullDownRefresh;
|
|
4113
|
+
config.onPullDownRefresh = function (e) {
|
|
4114
|
+
this.$set('isRefreshing', e.refreshing);
|
|
4115
|
+
// 调用 onPullDownRefresh
|
|
4116
|
+
originOnPullDownRefresh.call(this);
|
|
4117
|
+
};
|
|
4118
|
+
const originOnDestroy = config.onDestroy;
|
|
4119
|
+
config.onDestroy = function () {
|
|
4120
|
+
// 页面销毁时 执行路由堆栈 出栈
|
|
4121
|
+
const app = getApp();
|
|
4122
|
+
if (isArray(app.pageStack)) {
|
|
4123
|
+
// 不能用 pop,因为 onInit 会比 onDestroy 先触发,考虑一种情况:
|
|
4124
|
+
// current stack: [A, B], action: redirectTo C
|
|
4125
|
+
// [C onInit], push C, stack: [A, B, C]
|
|
4126
|
+
// [B onDestroy], pop C, stack: [A, B]
|
|
4127
|
+
// 可见 pop 会导致路由栈错误,上述例子中正确的路由栈应该是 [A, C],而不是 [A, B]
|
|
4128
|
+
const pagePath = this.$taroPath.split('?')[0];
|
|
4129
|
+
const stack = app.pageStack;
|
|
4130
|
+
const len = stack.length;
|
|
4131
|
+
let targetIdx = -1;
|
|
4132
|
+
for (let i = 0; i < len; i++) {
|
|
4133
|
+
if (stack[i] === pagePath)
|
|
4134
|
+
targetIdx = i;
|
|
4135
|
+
}
|
|
4136
|
+
targetIdx >= 0 && stack.splice(targetIdx, 1);
|
|
4137
|
+
}
|
|
4138
|
+
// 调用 OnDestroy
|
|
4139
|
+
originOnDestroy.call(this);
|
|
4140
|
+
};
|
|
4141
|
+
config.data = { root: { cn: [] } };
|
|
4142
|
+
},
|
|
4143
|
+
isBubbleEvents(eventName) {
|
|
4144
|
+
return BUBBLE_EVENTS.has(eventName);
|
|
4145
|
+
}
|
|
4146
|
+
};
|
|
4147
|
+
|
|
4148
|
+
export { components, hostConfig, initNativeApi };
|
|
4149
|
+
//# sourceMappingURL=runtime-utils.js.map
|