@tarojs/plugin-platform-harmony-ets 4.0.0-beta.10 → 4.0.0-beta.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apis/base/system.ts +73 -20
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/device/clipboard.ts +16 -8
- package/dist/apis/framework/index.ts +1 -5
- package/dist/apis/index.ts +25 -17
- package/dist/apis/media/image/index.ts +1 -1
- package/dist/apis/storage/index.ts +135 -131
- package/dist/apis/ui/animation/animation.ts +71 -29
- package/dist/apis/ui/background.ts +2 -1
- package/dist/apis/ui/interaction/index.ts +42 -59
- package/dist/apis/ui/navigation-bar/index.ts +1 -1
- package/dist/apis/ui/pull-down-refresh.ts +9 -3
- package/dist/apis/ui/scroll/index.ts +5 -5
- package/dist/apis/ui/tab-bar.ts +3 -3
- package/dist/apis/utils/index.ts +2 -1
- package/dist/apis/wxml/IntersectionObserver.ts +18 -10
- package/dist/apis/wxml/selectorQuery.ts +26 -13
- package/dist/components-harmony-ets/button.ets +64 -34
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +73 -62
- package/dist/components-harmony-ets/form.ets +51 -29
- package/dist/components-harmony-ets/icon.ets +31 -19
- package/dist/components-harmony-ets/image.ets +34 -14
- package/dist/components-harmony-ets/index.ets +92 -0
- package/dist/components-harmony-ets/innerHtml.ets +11 -6
- package/dist/components-harmony-ets/input.ets +64 -41
- package/dist/components-harmony-ets/label.ets +71 -44
- package/dist/components-harmony-ets/listView.ets +31 -0
- package/dist/components-harmony-ets/movableArea.ets +126 -0
- package/dist/components-harmony-ets/movableView.ets +93 -0
- package/dist/components-harmony-ets/navigationBar.ets +65 -0
- package/dist/components-harmony-ets/pageMeta.ets +94 -0
- package/dist/components-harmony-ets/picker.ets +43 -39
- package/dist/components-harmony-ets/progress.ets +52 -0
- package/dist/components-harmony-ets/pseudo.ets +80 -0
- package/dist/components-harmony-ets/radio.ets +78 -68
- package/dist/components-harmony-ets/richText.ets +14 -30
- package/dist/components-harmony-ets/scrollList.ets +103 -0
- package/dist/components-harmony-ets/scrollView.ets +61 -57
- package/dist/components-harmony-ets/slider.ets +19 -15
- package/dist/components-harmony-ets/stickySection.ets +42 -0
- package/dist/components-harmony-ets/style.ets +381 -130
- package/dist/components-harmony-ets/swiper.ets +61 -20
- package/dist/components-harmony-ets/switch.ets +36 -32
- package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
- package/dist/components-harmony-ets/text.ets +112 -50
- package/dist/components-harmony-ets/textArea.ets +50 -35
- package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
- package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
- package/dist/components-harmony-ets/utils/helper.ets +19 -7
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
- package/dist/components-harmony-ets/utils/index.ts +54 -50
- package/dist/components-harmony-ets/utils/styles.ets +170 -93
- package/dist/components-harmony-ets/video.ets +34 -21
- package/dist/components-harmony-ets/view.ets +63 -52
- package/dist/components-harmony-ets/webView.ets +40 -34
- package/dist/index.d.ts +152 -0
- package/dist/index.js +99 -55
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/document.ts +6 -4
- package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
- package/dist/runtime-ets/bom/window.ts +7 -0
- package/dist/runtime-ets/current.ts +5 -1
- package/dist/runtime-ets/dom/bind.ts +28 -12
- package/dist/runtime-ets/dom/class-list.ts +2 -2
- package/dist/runtime-ets/dom/cssNesting.ts +419 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
- package/dist/runtime-ets/dom/document.ts +8 -11
- package/dist/runtime-ets/dom/element/canvas.ts +136 -0
- package/dist/runtime-ets/dom/element/element.ts +348 -57
- package/dist/runtime-ets/dom/element/form.ts +31 -26
- package/dist/runtime-ets/dom/element/index.ts +30 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
- package/dist/runtime-ets/dom/element/movableView.ts +244 -0
- package/dist/runtime-ets/dom/element/normal.ts +35 -8
- package/dist/runtime-ets/dom/element/progress.ts +11 -0
- package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
- package/dist/runtime-ets/dom/element/text.ts +1 -8
- package/dist/runtime-ets/dom/element/video.ts +5 -4
- package/dist/runtime-ets/dom/element/webView.ts +12 -5
- package/dist/runtime-ets/dom/event.ts +2 -4
- package/dist/runtime-ets/dom/eventTarget.ts +2 -3
- package/dist/runtime-ets/dom/node.ts +64 -32
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +416 -235
- package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
- package/dist/runtime-ets/dom/stylesheet/type.ts +51 -9
- package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
- package/dist/runtime-ets/index.ts +2 -1
- package/dist/runtime-ets/interface/event.ts +1 -1
- package/dist/runtime-ets/utils/index.ts +74 -13
- package/dist/runtime-ets/utils/info.ts +2 -2
- package/dist/runtime-framework/react/app.ts +13 -8
- package/dist/runtime-framework/react/hooks.ts +0 -1
- package/dist/runtime-framework/react/index.ts +0 -2
- package/dist/runtime-framework/react/native-page.ts +155 -78
- package/dist/runtime-framework/react/page.ts +4 -9
- package/dist/runtime-framework/react/utils/index.ts +3 -3
- package/dist/runtime-framework/solid/app.ts +25 -45
- package/dist/runtime-framework/solid/connect.ts +21 -3
- package/dist/runtime-framework/solid/hooks.ts +16 -11
- package/dist/runtime-framework/solid/index.ts +6 -2
- package/dist/runtime-framework/solid/page.ts +85 -31
- package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
- package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
- package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
- package/dist/runtime-framework/solid/utils/index.ts +3 -5
- package/dist/runtime-utils.d.ts +827 -0
- package/dist/runtime-utils.js +425 -253
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +425 -253
- package/dist/runtime.js.map +1 -1
- package/index.js +3 -1
- package/package.json +14 -15
- package/static/media/cancel.svg +1 -1
- package/static/media/circle.svg +1 -1
- package/static/media/clear.svg +1 -1
- package/static/media/download.svg +1 -1
- package/static/media/info.svg +1 -1
- package/static/media/info_circle.svg +1 -1
- package/static/media/search.svg +1 -1
- package/static/media/success.svg +1 -1
- package/static/media/success_no_circle.svg +1 -1
- package/static/media/warn.svg +1 -1
- package/types/harmony.d.ts +4 -0
- package/types/index.d.ts +4 -0
- package/types/runtime.d.ts +1 -1
- /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
package/dist/apis/base/system.ts
CHANGED
|
@@ -1,26 +1,78 @@
|
|
|
1
|
+
import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant'
|
|
1
2
|
// 设备信息,从 API Version 6 开始支持
|
|
2
3
|
import deviceInfo from '@ohos.deviceInfo'
|
|
3
4
|
// 显示设备属性,从 API Version 7 开始支持
|
|
4
5
|
import _display from '@ohos.display'
|
|
5
6
|
// 从 API Version 7 开始支持
|
|
6
7
|
import i18n from '@ohos.i18n'
|
|
7
|
-
|
|
8
|
-
import deviceMethod from '@system.device'
|
|
8
|
+
import { Current, window } from '@tarojs/runtime'
|
|
9
9
|
|
|
10
10
|
import { callAsyncFail, callAsyncSuccess } from '../utils'
|
|
11
11
|
|
|
12
12
|
import type Taro from '@tarojs/taro/types'
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
let display
|
|
15
|
+
let navigationIndicatorRect
|
|
16
|
+
let safeArea: TaroGeneral.SafeAreaResult | null = null
|
|
17
|
+
let statusBarHeight
|
|
18
|
+
let windowRect
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
(Current as any).contextPromise.then((context) => {
|
|
21
|
+
const win = window.__ohos.getLastWindow(context)
|
|
22
|
+
win.then(mainWindow => {
|
|
23
|
+
const topRect = mainWindow.getWindowAvoidArea(window.__ohos.AvoidAreaType.TYPE_SYSTEM).topRect
|
|
24
|
+
navigationIndicatorRect = mainWindow.getWindowAvoidArea(window.__ohos.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect
|
|
25
|
+
statusBarHeight = topRect.top + topRect.height
|
|
26
|
+
windowRect = mainWindow.getWindowProperties().windowRect
|
|
17
27
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
try {
|
|
29
|
+
display = _display.getDefaultDisplaySync()
|
|
30
|
+
|
|
31
|
+
setSafeArea({
|
|
32
|
+
top: statusBarHeight,
|
|
33
|
+
left: 0,
|
|
34
|
+
right: display.width,
|
|
35
|
+
bottom: navigationIndicatorRect?.top
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
display.getCutoutInfo((err, { boundingRects = [], waterfallDisplayAreaRects = {} }: _display.CutoutInfo = {}) => {
|
|
40
|
+
if (err?.code) {
|
|
41
|
+
console.error('Failed to get cutout info', JSON.stringify(err))
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const top = Math.max(...boundingRects.map(rect => rect.top + rect.height), waterfallDisplayAreaRects.top?.top + waterfallDisplayAreaRects.top?.height, statusBarHeight)
|
|
46
|
+
const bottom = Math.min(display.height - waterfallDisplayAreaRects.bottom?.top, navigationIndicatorRect?.top)
|
|
47
|
+
const left = waterfallDisplayAreaRects.left?.left + waterfallDisplayAreaRects.left?.width
|
|
48
|
+
const right = display.width - waterfallDisplayAreaRects.right?.left
|
|
49
|
+
|
|
50
|
+
setSafeArea({
|
|
51
|
+
top,
|
|
52
|
+
left,
|
|
53
|
+
right,
|
|
54
|
+
bottom
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
} catch (e) {
|
|
58
|
+
console.error('Failed to get display', e)
|
|
59
|
+
}
|
|
60
|
+
})
|
|
22
61
|
})
|
|
23
62
|
|
|
63
|
+
|
|
64
|
+
function setSafeArea({ top, left, right, bottom }) {
|
|
65
|
+
safeArea = {
|
|
66
|
+
top,
|
|
67
|
+
bottom,
|
|
68
|
+
left,
|
|
69
|
+
right,
|
|
70
|
+
height: bottom - top,
|
|
71
|
+
width: right - left,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
24
76
|
/* 同步版本 */
|
|
25
77
|
export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
|
|
26
78
|
const res: any = {}
|
|
@@ -32,7 +84,7 @@ export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
|
|
|
32
84
|
res.cameraAuthorized = null // 允许使用摄像头的开关 boolean
|
|
33
85
|
res.enableDebug = null // 是否已打开调试 boolean
|
|
34
86
|
res.fontSizeSetting = null // 用户字体大小(单位px) number
|
|
35
|
-
res.language = i18n
|
|
87
|
+
res.language = i18n?.getSystemLanguage?.() // string
|
|
36
88
|
res.locationAuthorized = null // 定位的开关 boolean
|
|
37
89
|
res.locationEnabled = null // 地理位置的系统开关 boolean
|
|
38
90
|
res.microphoneAuthorized = null // 麦克风的开关 boolean
|
|
@@ -43,17 +95,18 @@ export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
|
|
|
43
95
|
res.notificationSoundAuthorized = false // 通知带有声音的开关(仅 iOS 有效)boolean
|
|
44
96
|
res.phoneCalendarAuthorized = null // 使用日历的开关 boolean
|
|
45
97
|
res.wifiEnabled = false // Wi-Fi 的系统开关 boolean
|
|
46
|
-
res.pixelRatio =
|
|
47
|
-
res.platform = '
|
|
48
|
-
res.safeArea =
|
|
49
|
-
res.screenHeight = display
|
|
50
|
-
res.screenWidth = display
|
|
51
|
-
res.statusBarHeight =
|
|
52
|
-
res.system = deviceInfo
|
|
53
|
-
|
|
54
|
-
res.
|
|
55
|
-
res.windowHeight =
|
|
56
|
-
res.
|
|
98
|
+
res.pixelRatio = display && display.densityPixels // 设备像素比,number
|
|
99
|
+
res.platform = 'harmony' // 客户端平台 string
|
|
100
|
+
res.safeArea = safeArea // 在竖屏正方向下的安全区域 General.SafeAreaResult
|
|
101
|
+
res.screenHeight = display?.height // 屏幕高度,单位px number
|
|
102
|
+
res.screenWidth = display?.width // 屏幕宽度,单位px number
|
|
103
|
+
res.statusBarHeight = statusBarHeight // 状态栏的高度,单位px number
|
|
104
|
+
res.system = deviceInfo?.osFullName // 操作系统及版本 string
|
|
105
|
+
// Note: 更新配置时才能记录
|
|
106
|
+
res.theme = AppStorage.get('__TARO_APP_CONFIG')?.colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK ? 'dark' : 'light' // 系统当前主题,取值为light或dark 'light' | 'dark'
|
|
107
|
+
res.windowHeight = windowRect?.height // 可使用窗口高度,单位px number
|
|
108
|
+
res.windowWidth = windowRect?.width // 可使用窗口宽度,单位px number
|
|
109
|
+
res.version = deviceInfo?.displayVersion // 版本号 string
|
|
57
110
|
|
|
58
111
|
return res
|
|
59
112
|
}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
+
import { eventSource } from '@tarojs/runtime'
|
|
2
|
+
|
|
1
3
|
import { temporarilyNotSupport } from '../utils'
|
|
2
4
|
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import type { TaroCanvasElement } from '@tarojs/runtime'
|
|
3
7
|
// 画布
|
|
4
8
|
|
|
5
9
|
/** 创建离屏 canvas 实例 */
|
|
6
10
|
export const createOffscreenCanvas = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas')
|
|
7
11
|
|
|
8
12
|
/** 创建 canvas 的绘图上下文 CanvasContext 对象 */
|
|
9
|
-
export const createCanvasContext = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas')
|
|
13
|
+
// export const createCanvasContext = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas')
|
|
14
|
+
export const createCanvasContext = (canvasId: string) => {
|
|
15
|
+
const dom = eventSource.get(`canvasId-${canvasId}`)
|
|
16
|
+
// return dom as TaroCanvasElement
|
|
17
|
+
if (dom) return (dom as unknown as TaroCanvasElement).context
|
|
18
|
+
}
|
|
10
19
|
|
|
11
20
|
/** 把当前画布指定区域的内容导出生成指定大小的图片 */
|
|
12
21
|
export const canvasToTempFilePath = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas')
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// 从 API Version 6 开始支持
|
|
2
2
|
import pasteboard from '@ohos.pasteboard'
|
|
3
|
+
import promptAction from '@ohos.promptAction'
|
|
3
4
|
import { isString } from '@tarojs/shared'
|
|
4
5
|
|
|
5
6
|
import { callAsyncFail, getParameterError, object2String } from '../utils'
|
|
@@ -27,9 +28,20 @@ export const setClipboardData: typeof Taro.setClipboardData = function (options)
|
|
|
27
28
|
|
|
28
29
|
return new Promise((resolve, reject) => {
|
|
29
30
|
const systemPasteboard = pasteboard.getSystemPasteboard()
|
|
30
|
-
const pasteData = pasteboard.
|
|
31
|
+
const pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, data)
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
try {
|
|
34
|
+
systemPasteboard.setDataSync(pasteData)
|
|
35
|
+
promptAction.showToast({
|
|
36
|
+
message: '内容已复制',
|
|
37
|
+
duration: 1500,
|
|
38
|
+
bottom: '50%',
|
|
39
|
+
showMode: 1 // 设置弹窗显示模式,显示在应用之上。
|
|
40
|
+
})
|
|
41
|
+
return handle.success({
|
|
42
|
+
data,
|
|
43
|
+
}, { resolve, reject })
|
|
44
|
+
} catch (error) {
|
|
33
45
|
if (error) {
|
|
34
46
|
console.error('Failed to set PasteData. Cause: ' + JSON.stringify(error))
|
|
35
47
|
res = {
|
|
@@ -37,12 +49,8 @@ export const setClipboardData: typeof Taro.setClipboardData = function (options)
|
|
|
37
49
|
error: error
|
|
38
50
|
}
|
|
39
51
|
callAsyncFail(reject, res, options)
|
|
40
|
-
} else {
|
|
41
|
-
return handle.success({
|
|
42
|
-
data,
|
|
43
|
-
}, { resolve, reject })
|
|
44
52
|
}
|
|
45
|
-
}
|
|
53
|
+
}
|
|
46
54
|
})
|
|
47
55
|
}
|
|
48
56
|
|
|
@@ -54,7 +62,7 @@ export const getClipboardData: typeof Taro.getClipboardData = function (options)
|
|
|
54
62
|
const handle = new MethodHandler({ name: 'getClipboardData', success, fail, complete })
|
|
55
63
|
return new Promise((resolve, reject) => {
|
|
56
64
|
const systemPasteboard = pasteboard.getSystemPasteboard()
|
|
57
|
-
systemPasteboard.
|
|
65
|
+
systemPasteboard.getData((error, pasteData) => { // callback 形式调用异步接口
|
|
58
66
|
if (error) {
|
|
59
67
|
console.error('Failed to obtain PasteData. Cause: ' + JSON.stringify(error))
|
|
60
68
|
return handle.fail({
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Current } from '@tarojs/runtime'
|
|
2
|
-
|
|
3
1
|
import { temporarilyNotSupport } from '../utils'
|
|
4
2
|
|
|
5
3
|
export const ENV_TYPE = {
|
|
@@ -19,12 +17,10 @@ export function getEnv () {
|
|
|
19
17
|
return ENV_TYPE.HARMONY
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
export { Current }
|
|
23
|
-
|
|
24
20
|
// TODO
|
|
25
21
|
export const getCurrentPages = () => []
|
|
26
22
|
|
|
27
|
-
export
|
|
23
|
+
export { Current, getCurrentInstance } from '@tarojs/runtime'
|
|
28
24
|
|
|
29
25
|
export const requirePlugin = temporarilyNotSupport('requirePlugin')
|
|
30
26
|
|
package/dist/apis/index.ts
CHANGED
|
@@ -33,7 +33,7 @@ const defaultUnitPrecision = 5
|
|
|
33
33
|
const defaultTargetUnit = 'vp'
|
|
34
34
|
|
|
35
35
|
export function getApp () {
|
|
36
|
-
return Current.app
|
|
36
|
+
return Current.app || {}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export function initPxTransform ({
|
|
@@ -58,20 +58,25 @@ export function initPxTransform ({
|
|
|
58
58
|
|
|
59
59
|
const display = _display.getDefaultDisplaySync()
|
|
60
60
|
|
|
61
|
+
let displayWidth = display.width
|
|
62
|
+
let ratioCache: number | false = false
|
|
61
63
|
let designWidthFunc: (input: number) => number
|
|
64
|
+
let designWidth = defaultDesignWidth
|
|
62
65
|
function getRatio (value: number) {
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
// Note: 提前调用 display 可能无法获取正确值
|
|
67
|
+
if (ratioCache === false || displayWidth !== display.width) {
|
|
68
|
+
const config = (Current as any).taro?.config || {}
|
|
69
|
+
if (!isFunction(designWidthFunc)) {
|
|
70
|
+
designWidthFunc = isFunction(config.designWidth)
|
|
71
|
+
? config.designWidth
|
|
72
|
+
: () => config.designWidth
|
|
73
|
+
designWidth = designWidthFunc(value) || defaultDesignWidth
|
|
74
|
+
}
|
|
75
|
+
displayWidth = display.width
|
|
76
|
+
ratioCache = Math.min(display.width, display.height) / designWidth
|
|
73
77
|
}
|
|
74
|
-
|
|
78
|
+
|
|
79
|
+
return ratioCache
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
// Note: 设置为 style 单位时会自动完成设计稿转换,设计开发者调用 API 时也许抹平差异,例如 pageScrollTo[option.offsetTop]
|
|
@@ -79,6 +84,9 @@ export function pxTransformHelper (size: number, unit?: string, isNumber = false
|
|
|
79
84
|
const config = (Current as any).taro?.config || {}
|
|
80
85
|
const targetUnit = unit || config.targetUnit || defaultTargetUnit
|
|
81
86
|
|
|
87
|
+
if (targetUnit === 'PX') {
|
|
88
|
+
return px2vp(size * display.scaledDensity) + 'vp'
|
|
89
|
+
}
|
|
82
90
|
const ratio = getRatio(size)
|
|
83
91
|
let val = size * ratio
|
|
84
92
|
|
|
@@ -92,19 +100,19 @@ export function pxTransformHelper (size: number, unit?: string, isNumber = false
|
|
|
92
100
|
return isNumber ? val : val + targetUnit
|
|
93
101
|
}
|
|
94
102
|
|
|
95
|
-
export function pxTransform (size: number): number {
|
|
103
|
+
export function pxTransform (size: number): number | string {
|
|
96
104
|
const config = (Current as any).taro?.config || {}
|
|
97
105
|
const targetUnit = config.targetUnit || defaultTargetUnit
|
|
98
106
|
|
|
99
|
-
|
|
107
|
+
const val = size
|
|
100
108
|
switch (targetUnit) {
|
|
101
109
|
case 'vp':
|
|
102
|
-
|
|
103
|
-
|
|
110
|
+
return pxTransformHelper(size, 'px')
|
|
111
|
+
// return `${size}lpx`
|
|
104
112
|
default:
|
|
105
113
|
// NOTE: 鸿蒙环境下 style 会自动完成设计稿转换,无需在方法内二次调整
|
|
106
114
|
}
|
|
107
|
-
return val +
|
|
115
|
+
return val + targetUnit
|
|
108
116
|
}
|
|
109
117
|
|
|
110
118
|
export function canIUseWebp () {
|
|
@@ -112,7 +112,7 @@ export const chooseImage: typeof Taro.chooseImage = function (options) {
|
|
|
112
112
|
photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE // 过滤选择媒体文件类型为IMAGE
|
|
113
113
|
|
|
114
114
|
photoViewPicker.select(photoSelectOptions).then((photoSelectResult) => {
|
|
115
|
-
callAsyncSuccess(resolve, { tempFilePaths: photoSelectResult.photoUris })
|
|
115
|
+
callAsyncSuccess(resolve, { tempFilePaths: photoSelectResult.photoUris }, options)
|
|
116
116
|
}).catch((error) => {
|
|
117
117
|
callAsyncFail(reject, error, options)
|
|
118
118
|
})
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
* https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-data-preferences-0000001427745052-V3
|
|
4
4
|
*/
|
|
5
5
|
import bundleManager from '@ohos.bundle.bundleManager'
|
|
6
|
-
import
|
|
7
|
-
import hilog from '@ohos.hilog'
|
|
6
|
+
import distributedKVStore from '@ohos.data.distributedKVStore'
|
|
8
7
|
import { Current } from '@tarojs/runtime'
|
|
9
8
|
|
|
10
9
|
import { temporarilyNotSupport, validateParams } from '../utils'
|
|
@@ -13,177 +12,176 @@ import { MethodHandler } from '../utils/handler'
|
|
|
13
12
|
import type Taro from '@tarojs/taro/types'
|
|
14
13
|
|
|
15
14
|
let context
|
|
16
|
-
let
|
|
15
|
+
let kvManager: distributedKVStore.KVManager
|
|
16
|
+
let kvStore: distributedKVStore.SingleKVStore
|
|
17
|
+
let kvStorePromise: Promise<void>
|
|
17
18
|
|
|
18
19
|
(Current as any).contextPromise.then((ctx) => {
|
|
19
20
|
context = ctx
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
const kvManagerConfig: distributedKVStore.KVManagerConfig = {
|
|
22
|
+
context: context,
|
|
23
|
+
bundleName: 'com.example.taro'
|
|
24
|
+
}
|
|
22
25
|
|
|
23
|
-
function getPreferences () {
|
|
24
26
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
// 创建KVManager实例
|
|
28
|
+
kvManager = distributedKVStore.createKVManager(kvManagerConfig)
|
|
29
|
+
// 继续创建获取数据库
|
|
30
|
+
const options: distributedKVStore.Options = {
|
|
31
|
+
createIfMissing: true,
|
|
32
|
+
encrypt: false,
|
|
33
|
+
backup: false,
|
|
34
|
+
autoSync: false,
|
|
35
|
+
// kvStoreType不填时,默认创建多设备协同数据库
|
|
36
|
+
kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION,
|
|
37
|
+
// 多设备协同数据库:kvStoreType: distributedKVStore.KVStoreType.DEVICE_COLLABORATION,
|
|
38
|
+
securityLevel: distributedKVStore.SecurityLevel.S1
|
|
28
39
|
}
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
|
|
41
|
+
const data = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION)
|
|
42
|
+
kvStorePromise = new Promise(resolve => {
|
|
43
|
+
kvManager.getKVStore<distributedKVStore.SingleKVStore>(`${data.appInfo.uid}Store`, options, (err, store: distributedKVStore.SingleKVStore) => {
|
|
44
|
+
if (err) {
|
|
45
|
+
console.error(`Failed to get KVStore: Code:${err.code},message:${err.message}`)
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
kvStore = store
|
|
49
|
+
// 请确保获取到键值数据库实例后,再进行相关数据操作
|
|
50
|
+
resolve()
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.error(`Failed to create KVManager. Code:${e.code},message:${e.message}`)
|
|
31
55
|
}
|
|
32
56
|
|
|
33
|
-
return
|
|
34
|
-
}
|
|
57
|
+
return context
|
|
58
|
+
})
|
|
35
59
|
|
|
36
60
|
const storageSchema = {
|
|
37
61
|
key: 'String'
|
|
38
62
|
}
|
|
39
63
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const res = { errMsg: error.message }
|
|
49
|
-
return handle.fail(res, { resolve, reject })
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const preferences = getPreferences()
|
|
53
|
-
|
|
54
|
-
if (!preferences) return handle.fail({}, { resolve, reject })
|
|
55
|
-
|
|
56
|
-
const data = preferences.getSync(key, null)
|
|
57
|
-
if (data) {
|
|
58
|
-
return handle.success({ data }, { resolve, reject })
|
|
64
|
+
function checkContextExist (api: string, isAsync = false) {
|
|
65
|
+
if (!context) {
|
|
66
|
+
const message = `${api} 调用失败,Taro 不支持过早地调用 ${api},请确保页面已经渲染完成再调用此 API`
|
|
67
|
+
if (isAsync) {
|
|
68
|
+
return {
|
|
69
|
+
isExist: false,
|
|
70
|
+
error: Promise.reject(new Error(message))
|
|
71
|
+
}
|
|
59
72
|
} else {
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
}
|
|
73
|
+
console.warn(message)
|
|
64
74
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const preferences = getPreferences()
|
|
71
|
-
|
|
72
|
-
if (!preferences) {
|
|
73
|
-
throw new Error('getStorageSync:fail:preferences is null')
|
|
75
|
+
return {
|
|
76
|
+
isExist: false,
|
|
77
|
+
}
|
|
78
|
+
}
|
|
74
79
|
}
|
|
75
80
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return data
|
|
79
|
-
} else {
|
|
80
|
-
throw new Error('data not found')
|
|
81
|
+
return {
|
|
82
|
+
isExist: true,
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
|
|
84
|
-
export function
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
return new Promise((resolve, reject) => {
|
|
89
|
-
try {
|
|
90
|
-
validateParams('setStorage', options, storageSchema)
|
|
91
|
-
} catch (error) {
|
|
92
|
-
const res = { errMsg: error.message }
|
|
93
|
-
return handle.fail(res, { resolve, reject })
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const preferences = getPreferences()
|
|
86
|
+
export function getStorage<T = any> (options: Taro.getStorage.Option<T>) {
|
|
87
|
+
const name = 'getStorage'
|
|
88
|
+
const { isExist, error } = checkContextExist(name, true)
|
|
97
89
|
|
|
98
|
-
|
|
90
|
+
if (!isExist) {
|
|
91
|
+
return error
|
|
92
|
+
}
|
|
99
93
|
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
const { key, success, fail, complete } = options || {}
|
|
95
|
+
const handle = new MethodHandler<{data: any}>({ name, success, fail, complete })
|
|
102
96
|
|
|
103
|
-
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
kvStorePromise.then(() => {
|
|
99
|
+
try {
|
|
100
|
+
validateParams(name, options, storageSchema)
|
|
101
|
+
} catch (error) {
|
|
102
|
+
const res = { errMsg: error.message }
|
|
103
|
+
return handle.fail(res, { resolve, reject })
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
kvStore = kvStore as distributedKVStore.SingleKVStore
|
|
107
|
+
kvStore.get(key, (err, data) => {
|
|
108
|
+
if (err) {
|
|
109
|
+
handle.fail({ errMsg: `Failed to get data. Code:${err.code},message:${err.message}` }, { resolve, reject })
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
handle.success({ data }, { resolve, reject })
|
|
114
|
+
})
|
|
115
|
+
})
|
|
104
116
|
})
|
|
105
117
|
}
|
|
106
118
|
|
|
107
|
-
export function
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
119
|
+
export function setStorage (options: Taro.setStorage.Option) {
|
|
120
|
+
const name = 'setStorage'
|
|
121
|
+
const { isExist, error } = checkContextExist(name, true)
|
|
111
122
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (!preferences) {
|
|
115
|
-
throw new Error('setStorageSync:fail:preferences is null')
|
|
123
|
+
if (!isExist) {
|
|
124
|
+
return error
|
|
116
125
|
}
|
|
117
126
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function removeStorage (options: Taro.removeStorage.Option) {
|
|
123
|
-
const { key, success, fail, complete } = options || {}
|
|
124
|
-
const handle = new MethodHandler({ name: 'removeStorage', success, fail, complete })
|
|
127
|
+
const { key, data, success, fail, complete } = options || {}
|
|
128
|
+
const handle = new MethodHandler({ name, success, fail, complete })
|
|
125
129
|
|
|
126
130
|
return new Promise((resolve, reject) => {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
131
|
+
kvStorePromise.then(() => {
|
|
132
|
+
try {
|
|
133
|
+
validateParams(name, options, storageSchema)
|
|
134
|
+
} catch (error) {
|
|
135
|
+
const res = { errMsg: error.message }
|
|
136
|
+
return handle.fail(res, { resolve, reject })
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
kvStore = kvStore as distributedKVStore.SingleKVStore
|
|
140
|
+
kvStore.put(key, data, (err) => {
|
|
141
|
+
if (err) {
|
|
142
|
+
handle.fail({ errMsg: `Failed to put data. Code:${err.code},message:${err.message}` }, { resolve, reject })
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
handle.success({}, { resolve, reject })
|
|
147
|
+
})
|
|
148
|
+
})
|
|
142
149
|
})
|
|
143
150
|
}
|
|
144
151
|
|
|
145
|
-
export function
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
152
|
+
export function removeStorage (options: Taro.removeStorage.Option) {
|
|
153
|
+
const name = 'removeStorage'
|
|
154
|
+
const { isExist, error } = checkContextExist(name, true)
|
|
149
155
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (!preferences) {
|
|
153
|
-
throw new Error('removeStorageSync:fail:preferences is null')
|
|
156
|
+
if (!isExist) {
|
|
157
|
+
return error
|
|
154
158
|
}
|
|
155
159
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function clearStorage (options: Taro.clearStorage.Option) {
|
|
161
|
-
const { success, fail, complete } = options || {}
|
|
162
|
-
const handle = new MethodHandler({ name: 'clearStorage', success, fail, complete })
|
|
160
|
+
const { key, success, fail, complete } = options || {}
|
|
161
|
+
const handle = new MethodHandler({ name, success, fail, complete })
|
|
163
162
|
|
|
164
163
|
return new Promise((resolve, reject) => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
164
|
+
kvStorePromise.then(() => {
|
|
165
|
+
try {
|
|
166
|
+
validateParams(name, options, storageSchema)
|
|
167
|
+
} catch (error) {
|
|
168
|
+
const res = { errMsg: error.message }
|
|
169
|
+
return handle.fail(res, { resolve, reject })
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
kvStore = kvStore as distributedKVStore.SingleKVStore
|
|
173
|
+
kvStore.delete(key, (err) => {
|
|
174
|
+
if (err) {
|
|
175
|
+
handle.fail({ errMsg: `Failed to delete data. Code:${err.code},message:${err.message}` }, { resolve, reject })
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
handle.success({}, { resolve, reject })
|
|
180
|
+
})
|
|
181
|
+
})
|
|
173
182
|
})
|
|
174
183
|
}
|
|
175
184
|
|
|
176
|
-
export function clearStorageSync () {
|
|
177
|
-
const preferences = getPreferences()
|
|
178
|
-
|
|
179
|
-
if (!preferences) {
|
|
180
|
-
throw new Error('clearStorageSync:fail:preferences is null')
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
preferences.clearSync()
|
|
184
|
-
preferences.flush()
|
|
185
|
-
}
|
|
186
|
-
|
|
187
185
|
export const getStorageInfoSync = temporarilyNotSupport('getStorageInfoSync')
|
|
188
186
|
export const getStorageInfo = temporarilyNotSupport('getStorageInfo')
|
|
189
187
|
|
|
@@ -195,5 +193,11 @@ export const batchSetStorage = /* @__PURE__ */ temporarilyNotSupport('batchSetSt
|
|
|
195
193
|
export const batchGetStorageSync = /* @__PURE__ */ temporarilyNotSupport('batchGetStorageSync')
|
|
196
194
|
export const batchGetStorage = /* @__PURE__ */ temporarilyNotSupport('batchGetStorage')
|
|
197
195
|
|
|
196
|
+
export const clearStorage = temporarilyNotSupport('clearStorage')
|
|
197
|
+
export const getStorageSync = temporarilyNotSupport('getStorageSync', 'getStorage')
|
|
198
|
+
export const setStorageSync = temporarilyNotSupport('setStorageSync', 'setStorage')
|
|
199
|
+
export const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clearStorage')
|
|
200
|
+
export const removeStorageSync = temporarilyNotSupport('removeStorageSync', 'removeStorage')
|
|
201
|
+
|
|
198
202
|
export * from './background-fetch'
|
|
199
203
|
export * from './cache-manager'
|