@tarojs/plugin-platform-harmony-ets 4.0.0-beta.13 → 4.0.0-beta.131
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 +60 -25
- package/dist/apis/base/weapp/life-cycle.ts +1 -1
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/device/clipboard.ts +23 -8
- package/dist/apis/framework/index.ts +1 -1
- package/dist/apis/index.ts +24 -16
- package/dist/apis/media/image/index.ts +169 -17
- package/dist/apis/network/downloadFile.ts +3 -1
- package/dist/apis/network/uploadFile.ts +3 -1
- package/dist/apis/route/index.ts +1 -2
- package/dist/apis/storage/index.ts +135 -131
- package/dist/apis/ui/animation/animation.ts +71 -29
- package/dist/apis/ui/background.ts +3 -2
- package/dist/apis/ui/interaction/index.ts +58 -59
- package/dist/apis/ui/navigation-bar/index.ts +2 -2
- 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 +4 -5
- package/dist/apis/utils/handler.ts +2 -1
- package/dist/apis/utils/index.ts +20 -2
- package/dist/apis/utils/permissions.ts +6 -0
- package/dist/apis/wxml/IntersectionObserver.ts +18 -10
- package/dist/apis/wxml/selectorQuery.ts +26 -13
- package/dist/components-harmony-ets/button.ets +36 -9
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +69 -60
- package/dist/components-harmony-ets/form.ets +33 -15
- package/dist/components-harmony-ets/icon.ets +16 -8
- package/dist/components-harmony-ets/image.ets +22 -6
- package/dist/components-harmony-ets/index.ets +39 -0
- package/dist/components-harmony-ets/innerHtml.ets +6 -5
- package/dist/components-harmony-ets/input.ets +63 -37
- package/dist/components-harmony-ets/label.ets +43 -21
- package/dist/components-harmony-ets/listView.ets +32 -0
- package/dist/components-harmony-ets/movableArea.ets +110 -51
- package/dist/components-harmony-ets/movableView.ets +74 -47
- 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 +36 -33
- package/dist/components-harmony-ets/progress.ets +31 -24
- package/dist/components-harmony-ets/pseudo.ets +43 -35
- package/dist/components-harmony-ets/radio.ets +75 -66
- package/dist/components-harmony-ets/richText.ets +4 -25
- package/dist/components-harmony-ets/scrollList.ets +108 -0
- package/dist/components-harmony-ets/scrollView.ets +53 -44
- 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 +274 -38
- package/dist/components-harmony-ets/swiper.ets +42 -5
- 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 +102 -46
- package/dist/components-harmony-ets/textArea.ets +49 -34
- 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 +43 -13
- package/dist/components-harmony-ets/utils/helper.ets +20 -8
- 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 +165 -104
- package/dist/components-harmony-ets/video.ets +28 -20
- package/dist/components-harmony-ets/view.ets +44 -38
- package/dist/components-harmony-ets/webView.ets +6 -5
- package/dist/index.d.ts +152 -0
- package/dist/index.js +73 -44
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/URL.ts +2 -0
- package/dist/runtime-ets/bom/document.ts +5 -4
- package/dist/runtime-ets/bom/getComputedStyle.ts +2 -3
- package/dist/runtime-ets/bom/history.ts +1 -0
- package/dist/runtime-ets/bom/location.ts +1 -0
- package/dist/runtime-ets/bom/navigator.ts +1 -21
- package/dist/runtime-ets/bom/raf.ts +1 -37
- package/dist/runtime-ets/bom/window.ts +9 -5
- package/dist/runtime-ets/constant.ts +17 -10
- package/dist/runtime-ets/current.ts +26 -2
- 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 +9 -12
- package/dist/runtime-ets/dom/element/canvas.ts +137 -0
- package/dist/runtime-ets/dom/element/element.ts +355 -71
- package/dist/runtime-ets/dom/element/form.ts +26 -22
- package/dist/runtime-ets/dom/element/index.ts +22 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +0 -1
- package/dist/runtime-ets/dom/element/movableView.ts +238 -2
- package/dist/runtime-ets/dom/element/normal.ts +27 -6
- package/dist/runtime-ets/dom/element/progress.ts +0 -2
- package/dist/runtime-ets/dom/element/text.ts +0 -8
- package/dist/runtime-ets/dom/element/video.ts +4 -4
- package/dist/runtime-ets/dom/element/webView.ts +4 -5
- package/dist/runtime-ets/dom/event-source.ts +1 -0
- package/dist/runtime-ets/dom/event.ts +3 -5
- package/dist/runtime-ets/dom/eventTarget.ts +3 -4
- package/dist/runtime-ets/dom/node.ts +53 -22
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +401 -243
- package/dist/runtime-ets/dom/stylesheet/index.ts +27 -316
- package/dist/runtime-ets/dom/stylesheet/type.ts +52 -11
- package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
- package/dist/runtime-ets/emitter/emitter.ts +1 -0
- package/dist/runtime-ets/env.ts +1 -0
- package/dist/runtime-ets/index.ts +23 -7
- package/dist/runtime-ets/interface/event.ts +1 -1
- package/dist/runtime-ets/interface/index.ts +6 -0
- package/dist/runtime-ets/utils/index.ts +78 -19
- package/dist/runtime-ets/utils/info.ts +2 -2
- package/dist/runtime-ets/utils/router.ts +9 -0
- package/dist/runtime-framework/react/app.ts +10 -10
- package/dist/runtime-framework/react/hooks.ts +1 -2
- package/dist/runtime-framework/react/index.ts +0 -2
- package/dist/runtime-framework/react/native-page.ts +212 -80
- package/dist/runtime-framework/react/page.ts +3 -10
- package/dist/runtime-framework/react/utils/index.ts +3 -3
- package/dist/runtime-framework/solid/app.ts +29 -46
- 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 +84 -31
- package/dist/runtime-framework/solid/reconciler/props.ts +73 -29
- 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 +826 -0
- package/dist/runtime-utils.js +575 -284
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +575 -284
- 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 +5 -0
- package/types/index.d.ts +4 -0
- package/types/runtime.d.ts +8 -1
- /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
package/dist/apis/base/system.ts
CHANGED
|
@@ -5,39 +5,74 @@ import deviceInfo from '@ohos.deviceInfo'
|
|
|
5
5
|
import _display from '@ohos.display'
|
|
6
6
|
// 从 API Version 7 开始支持
|
|
7
7
|
import i18n from '@ohos.i18n'
|
|
8
|
+
import { Current, window } from '@tarojs/runtime'
|
|
8
9
|
|
|
9
10
|
import { callAsyncFail, callAsyncSuccess } from '../utils'
|
|
10
11
|
|
|
11
12
|
import type Taro from '@tarojs/taro/types'
|
|
12
13
|
|
|
13
14
|
let display
|
|
15
|
+
let navigationIndicatorRect
|
|
14
16
|
let safeArea: TaroGeneral.SafeAreaResult | null = null
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
let statusBarHeight
|
|
18
|
+
let windowRect
|
|
19
|
+
|
|
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
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
display = _display.getDefaultDisplaySync()
|
|
30
|
+
|
|
31
|
+
setSafeArea({
|
|
32
|
+
top: statusBarHeight,
|
|
33
|
+
left: 0,
|
|
34
|
+
right: display.width,
|
|
35
|
+
bottom: navigationIndicatorRect?.top
|
|
36
|
+
})
|
|
23
37
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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)
|
|
35
59
|
}
|
|
36
60
|
})
|
|
37
|
-
}
|
|
38
|
-
|
|
61
|
+
})
|
|
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
|
+
}
|
|
39
73
|
}
|
|
40
74
|
|
|
75
|
+
|
|
41
76
|
/* 同步版本 */
|
|
42
77
|
export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
|
|
43
78
|
const res: any = {}
|
|
@@ -60,17 +95,17 @@ export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
|
|
|
60
95
|
res.notificationSoundAuthorized = false // 通知带有声音的开关(仅 iOS 有效)boolean
|
|
61
96
|
res.phoneCalendarAuthorized = null // 使用日历的开关 boolean
|
|
62
97
|
res.wifiEnabled = false // Wi-Fi 的系统开关 boolean
|
|
63
|
-
res.pixelRatio = display &&
|
|
98
|
+
res.pixelRatio = display && display.densityPixels // 设备像素比,number
|
|
64
99
|
res.platform = 'harmony' // 客户端平台 string
|
|
65
100
|
res.safeArea = safeArea // 在竖屏正方向下的安全区域 General.SafeAreaResult
|
|
66
101
|
res.screenHeight = display?.height // 屏幕高度,单位px number
|
|
67
102
|
res.screenWidth = display?.width // 屏幕宽度,单位px number
|
|
68
|
-
res.statusBarHeight =
|
|
103
|
+
res.statusBarHeight = statusBarHeight // 状态栏的高度,单位px number
|
|
69
104
|
res.system = deviceInfo?.osFullName // 操作系统及版本 string
|
|
70
105
|
// Note: 更新配置时才能记录
|
|
71
106
|
res.theme = AppStorage.get('__TARO_APP_CONFIG')?.colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK ? 'dark' : 'light' // 系统当前主题,取值为light或dark 'light' | 'dark'
|
|
72
|
-
res.windowHeight =
|
|
73
|
-
res.windowWidth =
|
|
107
|
+
res.windowHeight = windowRect?.height // 可使用窗口高度,单位px number
|
|
108
|
+
res.windowWidth = windowRect?.width // 可使用窗口宽度,单位px number
|
|
74
109
|
res.version = deviceInfo?.displayVersion // 版本号 string
|
|
75
110
|
|
|
76
111
|
return res
|
|
@@ -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,7 +1,10 @@
|
|
|
1
1
|
// 从 API Version 6 开始支持
|
|
2
2
|
import pasteboard from '@ohos.pasteboard'
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import { Current } from '@tarojs/runtime'
|
|
3
5
|
import { isString } from '@tarojs/shared'
|
|
4
6
|
|
|
7
|
+
import {} from '../'
|
|
5
8
|
import { callAsyncFail, getParameterError, object2String } from '../utils'
|
|
6
9
|
import { MethodHandler } from '../utils/handler'
|
|
7
10
|
|
|
@@ -27,9 +30,25 @@ export const setClipboardData: typeof Taro.setClipboardData = function (options)
|
|
|
27
30
|
|
|
28
31
|
return new Promise((resolve, reject) => {
|
|
29
32
|
const systemPasteboard = pasteboard.getSystemPasteboard()
|
|
30
|
-
const pasteData = pasteboard.
|
|
33
|
+
const pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, data)
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
try {
|
|
36
|
+
systemPasteboard.setDataSync(pasteData)
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
const uiContext = Current?.page?.getUIContext?.()
|
|
39
|
+
|
|
40
|
+
if (!uiContext) return
|
|
41
|
+
|
|
42
|
+
uiContext.getPromptAction().showToast({
|
|
43
|
+
message: '内容已复制',
|
|
44
|
+
duration: 1500,
|
|
45
|
+
bottom: '50%',
|
|
46
|
+
showMode: 1 // 设置弹窗显示模式,显示在应用之上。
|
|
47
|
+
})
|
|
48
|
+
return handle.success({
|
|
49
|
+
data,
|
|
50
|
+
}, { resolve, reject })
|
|
51
|
+
} catch (error) {
|
|
33
52
|
if (error) {
|
|
34
53
|
console.error('Failed to set PasteData. Cause: ' + JSON.stringify(error))
|
|
35
54
|
res = {
|
|
@@ -37,12 +56,8 @@ export const setClipboardData: typeof Taro.setClipboardData = function (options)
|
|
|
37
56
|
error: error
|
|
38
57
|
}
|
|
39
58
|
callAsyncFail(reject, res, options)
|
|
40
|
-
} else {
|
|
41
|
-
return handle.success({
|
|
42
|
-
data,
|
|
43
|
-
}, { resolve, reject })
|
|
44
59
|
}
|
|
45
|
-
}
|
|
60
|
+
}
|
|
46
61
|
})
|
|
47
62
|
}
|
|
48
63
|
|
|
@@ -54,7 +69,7 @@ export const getClipboardData: typeof Taro.getClipboardData = function (options)
|
|
|
54
69
|
const handle = new MethodHandler({ name: 'getClipboardData', success, fail, complete })
|
|
55
70
|
return new Promise((resolve, reject) => {
|
|
56
71
|
const systemPasteboard = pasteboard.getSystemPasteboard()
|
|
57
|
-
systemPasteboard.
|
|
72
|
+
systemPasteboard.getData((error, pasteData) => { // callback 形式调用异步接口
|
|
58
73
|
if (error) {
|
|
59
74
|
console.error('Failed to obtain PasteData. Cause: ' + JSON.stringify(error))
|
|
60
75
|
return handle.fail({
|
|
@@ -24,4 +24,4 @@ export { Current, getCurrentInstance } from '@tarojs/runtime'
|
|
|
24
24
|
|
|
25
25
|
export const requirePlugin = temporarilyNotSupport('requirePlugin')
|
|
26
26
|
|
|
27
|
-
export { eventCenter, Events, History } from '@tarojs/runtime
|
|
27
|
+
export { eventCenter, Events, History } from '@tarojs/runtime'
|
package/dist/apis/index.ts
CHANGED
|
@@ -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 () {
|
|
@@ -9,10 +9,13 @@
|
|
|
9
9
|
// ❌ wx.saveImageToPhotosAlbum(Object object) api 9+ HarmonyOS不支持
|
|
10
10
|
// ❌ wx.previewImage(Object object) api 9+ HarmonyOS不支持
|
|
11
11
|
|
|
12
|
+
import fs from '@ohos.file.fs'
|
|
12
13
|
import picker from '@ohos.file.picker'
|
|
13
14
|
import image from '@ohos.multimedia.image'
|
|
15
|
+
import { Current } from '@tarojs/runtime'
|
|
14
16
|
import { isNull } from '@tarojs/shared'
|
|
15
17
|
|
|
18
|
+
import { getSystemInfoSync } from '../../base'
|
|
16
19
|
import { callAsyncFail, callAsyncSuccess, temporarilyNotSupport, validateParams } from '../../utils'
|
|
17
20
|
|
|
18
21
|
import type Taro from '@tarojs/taro/types'
|
|
@@ -22,12 +25,21 @@ interface IPackingOptionOHOS {
|
|
|
22
25
|
quality: number
|
|
23
26
|
}
|
|
24
27
|
|
|
28
|
+
interface IChooseImageData {
|
|
29
|
+
tempFilePaths?: string[]
|
|
30
|
+
|
|
31
|
+
tempFiles?: {
|
|
32
|
+
path: string
|
|
33
|
+
size: number
|
|
34
|
+
}[]
|
|
35
|
+
}
|
|
36
|
+
|
|
25
37
|
const getImageInfoSchema = {
|
|
26
|
-
|
|
38
|
+
src: 'String'
|
|
27
39
|
}
|
|
28
40
|
|
|
29
41
|
const compressImageSchema = {
|
|
30
|
-
|
|
42
|
+
src: 'String'
|
|
31
43
|
}
|
|
32
44
|
|
|
33
45
|
const chooseImageSchema = {
|
|
@@ -60,6 +72,44 @@ export const getImageInfo: typeof Taro.getImageInfo = function (options) {
|
|
|
60
72
|
})
|
|
61
73
|
}
|
|
62
74
|
|
|
75
|
+
|
|
76
|
+
class CompressedImageInfo {
|
|
77
|
+
imageUri = '' // 压缩后图片保存位置的uri
|
|
78
|
+
imageByteLength = 0 // 压缩后图片字节长度
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function saveImage(compressedImageData, compressedImageUri) {
|
|
82
|
+
const tempArr = compressedImageUri.split('/')
|
|
83
|
+
const name = tempArr[tempArr.length - 1]
|
|
84
|
+
const context = getContext(Current?.page)
|
|
85
|
+
const applicationContext = context.getApplicationContext()
|
|
86
|
+
const tempDir = applicationContext.tempDir
|
|
87
|
+
const filePath = `${tempDir}/${name}`
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const res = fs.accessSync(filePath)
|
|
91
|
+
if (res) {
|
|
92
|
+
// 如果图片afterCompressiona.jpeg已存在,则删除
|
|
93
|
+
fs.unlinkSync(filePath)
|
|
94
|
+
}
|
|
95
|
+
} catch (err) {
|
|
96
|
+
console.error(`[Taro] saveImage Error: AccessSync failed with error message: ${err.message}, error code: ${err.code}`)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 知识点:保存图片。获取最终图片压缩数据compressedImageData,保存图片。
|
|
100
|
+
// 压缩图片数据写入文件
|
|
101
|
+
const file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE)
|
|
102
|
+
fs.writeSync(file.fd, compressedImageData)
|
|
103
|
+
fs.closeSync(file)
|
|
104
|
+
|
|
105
|
+
// 获取压缩图片信息
|
|
106
|
+
const compressedImageInfo = new CompressedImageInfo()
|
|
107
|
+
compressedImageInfo.imageUri = filePath
|
|
108
|
+
compressedImageInfo.imageByteLength = compressedImageData.byteLength
|
|
109
|
+
|
|
110
|
+
return compressedImageInfo
|
|
111
|
+
}
|
|
112
|
+
|
|
63
113
|
export const compressImage: typeof Taro.compressImage = function (options) {
|
|
64
114
|
return new Promise((resolve, reject) => {
|
|
65
115
|
try {
|
|
@@ -68,30 +118,68 @@ export const compressImage: typeof Taro.compressImage = function (options) {
|
|
|
68
118
|
const res = { errMsg: error.message }
|
|
69
119
|
return callAsyncFail(reject, res, options)
|
|
70
120
|
}
|
|
71
|
-
const { src, quality = 80 } = options
|
|
121
|
+
const { src, quality = 80, compressedWidth, compressedHeight } = options
|
|
122
|
+
const srcAfterCompress = src.includes('_after_compress') ? src : src.split('.').join('_after_compress.')
|
|
123
|
+
const file = fs.openSync(src, fs.OpenMode.READ_ONLY)
|
|
72
124
|
|
|
73
|
-
const
|
|
125
|
+
// const stat = fs.statSync(file.fd)
|
|
126
|
+
// console.log('[Taro] 压缩前图片的大小为:', stat.size)
|
|
127
|
+
|
|
128
|
+
const source = image.createImageSource(file.fd)
|
|
74
129
|
if (isNull(source)) {
|
|
75
130
|
const createImageSourceError = { errMsg: 'compressImage fail: createImageSource has failed.' }
|
|
76
131
|
callAsyncFail(reject, createImageSourceError, options)
|
|
77
132
|
return
|
|
78
133
|
}
|
|
79
134
|
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
135
|
+
const width = source.getImageInfoSync().size.width
|
|
136
|
+
const height = source.getImageInfoSync().size.height
|
|
137
|
+
let wantWidth = compressedWidth || compressedHeight || 0
|
|
138
|
+
let wantHeight = compressedHeight || compressedWidth || 0
|
|
139
|
+
|
|
140
|
+
if (width > wantWidth || height > wantHeight) {
|
|
141
|
+
const heightRatio = height / wantHeight
|
|
142
|
+
const widthRatio = width / wantWidth
|
|
143
|
+
const finalRatio = heightRatio < widthRatio ? heightRatio : widthRatio
|
|
144
|
+
|
|
145
|
+
wantWidth = Math.round(width / finalRatio)
|
|
146
|
+
wantHeight = Math.round(height / finalRatio)
|
|
84
147
|
}
|
|
85
148
|
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
149
|
+
const decodingOptions = {
|
|
150
|
+
editable: true,
|
|
151
|
+
desiredPixelFormat: image.PixelMapFormat.RGBA_8888,
|
|
152
|
+
desiredSize: { width: wantWidth, height: wantHeight }
|
|
90
153
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
154
|
+
source.createPixelMap(decodingOptions, (error, pixelMap) => {
|
|
155
|
+
if (error !== undefined) {
|
|
156
|
+
fs.closeSync(file)
|
|
157
|
+
const res = { errMsg: error }
|
|
158
|
+
callAsyncFail(reject, res, options)
|
|
159
|
+
} else {
|
|
160
|
+
const packer = image.createImagePacker(file.fd)
|
|
161
|
+
if (isNull(packer)) {
|
|
162
|
+
fs.closeSync(file)
|
|
163
|
+
const createImagePackerError = { errMsg: 'compressImage fail: createImagePacker has failed.' }
|
|
164
|
+
callAsyncFail(reject, createImagePackerError, options)
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const isPNG = src.endsWith('.png')
|
|
169
|
+
const packingOptionsOHOS: IPackingOptionOHOS = {
|
|
170
|
+
format: isPNG ? 'image/png' : 'image/jpeg',
|
|
171
|
+
quality: quality
|
|
172
|
+
}
|
|
173
|
+
packer.packing(pixelMap, packingOptionsOHOS).then((value) => {
|
|
174
|
+
fs.closeSync(file)
|
|
175
|
+
saveImage(value, srcAfterCompress).then(result => {
|
|
176
|
+
callAsyncSuccess(resolve, { tempFilePath: result.imageUri }, options)
|
|
177
|
+
})
|
|
178
|
+
}).catch((error) => {
|
|
179
|
+
fs.closeSync(file)
|
|
180
|
+
callAsyncFail(reject, error, options)
|
|
181
|
+
})
|
|
182
|
+
}
|
|
95
183
|
})
|
|
96
184
|
})
|
|
97
185
|
}
|
|
@@ -107,12 +195,76 @@ export const chooseImage: typeof Taro.chooseImage = function (options) {
|
|
|
107
195
|
|
|
108
196
|
const { count = 9 } = options
|
|
109
197
|
const photoViewPicker = new picker.PhotoViewPicker()
|
|
198
|
+
let sizeType = options.sizeType
|
|
199
|
+
|
|
200
|
+
if (!sizeType || !sizeType.length) {
|
|
201
|
+
sizeType = ['compressed', 'original']
|
|
202
|
+
}
|
|
110
203
|
|
|
111
204
|
photoSelectOptions.maxSelectNumber = count // 选择媒体文件的最大数目
|
|
112
205
|
photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE // 过滤选择媒体文件类型为IMAGE
|
|
113
206
|
|
|
114
207
|
photoViewPicker.select(photoSelectOptions).then((photoSelectResult) => {
|
|
115
|
-
|
|
208
|
+
const result: IChooseImageData = {}
|
|
209
|
+
const isOrigin = photoSelectResult.isOriginalPhoto
|
|
210
|
+
|
|
211
|
+
if (isOrigin) {
|
|
212
|
+
const tempFilePaths: string[] = []
|
|
213
|
+
const tempFiles = photoSelectResult.photoUris.map(uri => {
|
|
214
|
+
const file = fs.openSync(uri, fs.OpenMode.READ_ONLY)
|
|
215
|
+
const stat = fs.statSync(file.fd)
|
|
216
|
+
const size = stat.size
|
|
217
|
+
|
|
218
|
+
fs.closeSync(file)
|
|
219
|
+
tempFilePaths.push(uri)
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
size,
|
|
223
|
+
path: uri,
|
|
224
|
+
}
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
result.tempFiles = tempFiles
|
|
228
|
+
result.tempFilePaths = tempFilePaths
|
|
229
|
+
|
|
230
|
+
callAsyncSuccess(resolve, result, options)
|
|
231
|
+
} else {
|
|
232
|
+
const actions: Promise<string>[] = photoSelectResult.photoUris.map(uri => {
|
|
233
|
+
return new Promise<string>(resolve => {
|
|
234
|
+
compressImage({
|
|
235
|
+
src: uri,
|
|
236
|
+
compressedWidth: getSystemInfoSync().screenWidth / 2,
|
|
237
|
+
compressedHeight: getSystemInfoSync().screenHeight / 2,
|
|
238
|
+
success: (compressResult) => {
|
|
239
|
+
resolve(compressResult.tempFilePath)
|
|
240
|
+
}
|
|
241
|
+
})
|
|
242
|
+
})
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
Promise.all(actions).then(tempFilePaths => {
|
|
246
|
+
const tempFiles = tempFilePaths.map(uri => {
|
|
247
|
+
const file = fs.openSync(uri, fs.OpenMode.READ_ONLY)
|
|
248
|
+
const stat = fs.statSync(file.fd)
|
|
249
|
+
const size: number = stat.size
|
|
250
|
+
|
|
251
|
+
fs.closeSync(file)
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
size,
|
|
255
|
+
path: uri,
|
|
256
|
+
}
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
result.tempFilePaths = tempFilePaths
|
|
260
|
+
result.tempFiles = tempFiles
|
|
261
|
+
|
|
262
|
+
callAsyncSuccess(resolve, result, options)
|
|
263
|
+
}).catch(error => {
|
|
264
|
+
const res = { errMsg: error }
|
|
265
|
+
return callAsyncFail(reject, res, options)
|
|
266
|
+
})
|
|
267
|
+
}
|
|
116
268
|
}).catch((error) => {
|
|
117
269
|
callAsyncFail(reject, error, options)
|
|
118
270
|
})
|
|
@@ -8,10 +8,12 @@
|
|
|
8
8
|
// ❌ DownloadTask.offHeadersReceived 此接口 ohos 不支持
|
|
9
9
|
|
|
10
10
|
import request from '@ohos.request'
|
|
11
|
-
import Taro, { DownloadTask } from '@tarojs/taro'
|
|
12
11
|
|
|
13
12
|
import { callAsyncFail, callAsyncSuccess, validateParams } from '../utils'
|
|
14
13
|
|
|
14
|
+
import type Taro from '@tarojs/taro/types'
|
|
15
|
+
import type { DownloadTask } from '@tarojs/taro/types'
|
|
16
|
+
|
|
15
17
|
interface IDownloadConfigOHOS {
|
|
16
18
|
url: string
|
|
17
19
|
header?: any
|
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
|
|
10
10
|
import request from '@ohos.request'
|
|
11
11
|
import { isUndefined } from '@tarojs/shared'
|
|
12
|
-
import Taro, { UploadTask } from '@tarojs/taro'
|
|
13
12
|
|
|
14
13
|
import { callAsyncFail, callAsyncSuccess, validateParams } from '../utils'
|
|
15
14
|
|
|
15
|
+
import type Taro from '@tarojs/taro/types'
|
|
16
|
+
import type { UploadTask } from '@tarojs/taro/types'
|
|
17
|
+
|
|
16
18
|
interface IOHOSFileType {
|
|
17
19
|
filename?: string
|
|
18
20
|
name?: string
|
package/dist/apis/route/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import router from '@ohos.router'
|
|
2
|
-
import { window } from '@tarojs/runtime'
|
|
3
|
-
import { eventCenter } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
|
|
2
|
+
import { eventCenter, window } from '@tarojs/runtime'
|
|
4
3
|
import { queryToJson } from '@tarojs/shared'
|
|
5
4
|
|
|
6
5
|
import { callAsyncFail, callAsyncSuccess } from '../utils'
|