@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.
Files changed (212) hide show
  1. package/LICENSE +160 -0
  2. package/dist/apis/apis.ts +15 -0
  3. package/dist/apis/base/index.ts +5 -0
  4. package/dist/apis/base/system.ts +77 -0
  5. package/dist/apis/device/accelerometer.ts +76 -0
  6. package/dist/apis/device/battery.ts +24 -0
  7. package/dist/apis/device/clipboard.ts +70 -0
  8. package/dist/apis/device/index.ts +9 -0
  9. package/dist/apis/device/keyboard.ts +62 -0
  10. package/dist/apis/device/memory.ts +4 -0
  11. package/dist/apis/device/network.ts +72 -0
  12. package/dist/apis/device/phone.ts +43 -0
  13. package/dist/apis/device/screen.ts +79 -0
  14. package/dist/apis/device/vibrate.ts +24 -0
  15. package/dist/apis/files/index.ts +135 -0
  16. package/dist/apis/files/manager.ts +941 -0
  17. package/dist/apis/framework/index.ts +32 -0
  18. package/dist/apis/index.ts +124 -0
  19. package/dist/apis/location/index.ts +133 -0
  20. package/dist/apis/media/common.ts +74 -0
  21. package/dist/apis/media/image.ts +122 -0
  22. package/dist/apis/media/index.ts +3 -0
  23. package/dist/apis/media/video.ts +86 -0
  24. package/dist/apis/navigate/index.ts +8 -0
  25. package/dist/apis/network/downloadFile.ts +113 -0
  26. package/dist/apis/network/index.ts +4 -0
  27. package/dist/apis/network/request.ts +113 -0
  28. package/dist/apis/network/uploadFile.ts +158 -0
  29. package/dist/apis/network/webSocket.ts +130 -0
  30. package/dist/apis/open-api/index.ts +7 -0
  31. package/dist/apis/open-api/user-info/index.ts +85 -0
  32. package/dist/apis/page/index.ts +92 -0
  33. package/dist/apis/route/index.ts +138 -0
  34. package/dist/apis/storage/index.ts +133 -0
  35. package/dist/apis/tabbar/index.ts +147 -0
  36. package/dist/apis/ui/animation.ts +222 -0
  37. package/dist/apis/ui/background.ts +35 -0
  38. package/dist/apis/ui/index.ts +14 -0
  39. package/dist/apis/ui/interaction/index.ts +195 -0
  40. package/dist/apis/ui/navigation-bar/index.ts +33 -0
  41. package/dist/apis/ui/pull-down-refresh.ts +41 -0
  42. package/dist/apis/utils/handler.ts +116 -0
  43. package/dist/apis/utils/index.ts +85 -0
  44. package/dist/apis/utils/types.ts +12 -0
  45. package/dist/apis/utils/validate.ts +87 -0
  46. package/dist/apis/wxml/IntersectionObserver.ts +119 -0
  47. package/dist/apis/wxml/index.ts +12 -0
  48. package/dist/apis/wxml/nodesRef.ts +56 -0
  49. package/dist/apis/wxml/selectorQuery.ts +287 -0
  50. package/dist/components/components-react.js +51 -0
  51. package/dist/components/components-react.js.map +1 -0
  52. package/dist/components-harmony/button/index.css +109 -0
  53. package/dist/components-harmony/button/index.hml +31 -0
  54. package/dist/components-harmony/button/index.js +105 -0
  55. package/dist/components-harmony/camera/index.hml +6 -0
  56. package/dist/components-harmony/camera/index.js +12 -0
  57. package/dist/components-harmony/checkbox/index.hml +11 -0
  58. package/dist/components-harmony/checkbox/index.js +60 -0
  59. package/dist/components-harmony/checkbox-group/index.hml +3 -0
  60. package/dist/components-harmony/checkbox-group/index.js +22 -0
  61. package/dist/components-harmony/cover-image/index.css +4 -0
  62. package/dist/components-harmony/cover-image/index.hml +9 -0
  63. package/dist/components-harmony/cover-image/index.js +15 -0
  64. package/dist/components-harmony/form/index.hml +10 -0
  65. package/dist/components-harmony/form/index.js +11 -0
  66. package/dist/components-harmony/icon/index.css +27 -0
  67. package/dist/components-harmony/icon/index.hml +54 -0
  68. package/dist/components-harmony/icon/index.js +17 -0
  69. package/dist/components-harmony/image/index.css +5 -0
  70. package/dist/components-harmony/image/index.hml +11 -0
  71. package/dist/components-harmony/image/index.js +28 -0
  72. package/dist/components-harmony/input/index.hml +21 -0
  73. package/dist/components-harmony/input/index.js +98 -0
  74. package/dist/components-harmony/label/index.hml +3 -0
  75. package/dist/components-harmony/label/index.js +6 -0
  76. package/dist/components-harmony/navbar/index.css +56 -0
  77. package/dist/components-harmony/navbar/index.hml +9 -0
  78. package/dist/components-harmony/navbar/index.js +30 -0
  79. package/dist/components-harmony/navigator/index.css +8 -0
  80. package/dist/components-harmony/navigator/index.hml +9 -0
  81. package/dist/components-harmony/navigator/index.js +104 -0
  82. package/dist/components-harmony/picker/index.hml +25 -0
  83. package/dist/components-harmony/picker/index.js +132 -0
  84. package/dist/components-harmony/picker-view/index.hml +23 -0
  85. package/dist/components-harmony/picker-view/index.js +161 -0
  86. package/dist/components-harmony/picker-view-column/index.hml +3 -0
  87. package/dist/components-harmony/picker-view-column/index.js +3 -0
  88. package/dist/components-harmony/progress/index.css +4 -0
  89. package/dist/components-harmony/progress/index.hml +28 -0
  90. package/dist/components-harmony/progress/index.js +23 -0
  91. package/dist/components-harmony/radio/index.hml +11 -0
  92. package/dist/components-harmony/radio/index.js +41 -0
  93. package/dist/components-harmony/radio-group/index.hml +3 -0
  94. package/dist/components-harmony/radio-group/index.js +11 -0
  95. package/dist/components-harmony/rich-text/index.hml +5 -0
  96. package/dist/components-harmony/rich-text/index.js +16 -0
  97. package/dist/components-harmony/scroll-view/index.css +5 -0
  98. package/dist/components-harmony/scroll-view/index.hml +12 -0
  99. package/dist/components-harmony/scroll-view/index.js +65 -0
  100. package/dist/components-harmony/slider/index.hml +16 -0
  101. package/dist/components-harmony/slider/index.js +53 -0
  102. package/dist/components-harmony/swiper/index.css +3 -0
  103. package/dist/components-harmony/swiper/index.hml +14 -0
  104. package/dist/components-harmony/swiper/index.js +19 -0
  105. package/dist/components-harmony/switch/index.hml +7 -0
  106. package/dist/components-harmony/switch/index.js +16 -0
  107. package/dist/components-harmony/tabbar/index.css +7 -0
  108. package/dist/components-harmony/tabbar/index.hml +26 -0
  109. package/dist/components-harmony/tabbar/index.js +42 -0
  110. package/dist/components-harmony/textarea/index.hml +24 -0
  111. package/dist/components-harmony/textarea/index.js +92 -0
  112. package/dist/components-harmony/utils/index.js +41 -0
  113. package/dist/components-harmony/video/index.hml +7 -0
  114. package/dist/components-harmony/video/index.js +73 -0
  115. package/dist/components-harmony/web-view/index.hml +8 -0
  116. package/dist/components-harmony/web-view/index.js +22 -0
  117. package/dist/components-harmony-ets/base.ets +63 -0
  118. package/dist/components-harmony-ets/button.ets +119 -0
  119. package/dist/components-harmony-ets/checkbox.ets +219 -0
  120. package/dist/components-harmony-ets/element.ets +223 -0
  121. package/dist/components-harmony-ets/form.ets +149 -0
  122. package/dist/components-harmony-ets/icon.ets +84 -0
  123. package/dist/components-harmony-ets/image.ets +85 -0
  124. package/dist/components-harmony-ets/index.ts +49 -0
  125. package/dist/components-harmony-ets/innerHtml.ets +79 -0
  126. package/dist/components-harmony-ets/input.ets +195 -0
  127. package/dist/components-harmony-ets/label.ets +111 -0
  128. package/dist/components-harmony-ets/picker.ets +370 -0
  129. package/dist/components-harmony-ets/radio.ets +225 -0
  130. package/dist/components-harmony-ets/richText.ets +97 -0
  131. package/dist/components-harmony-ets/scrollView.ets +199 -0
  132. package/dist/components-harmony-ets/slider.ets +159 -0
  133. package/dist/components-harmony-ets/swiper.ets +204 -0
  134. package/dist/components-harmony-ets/switch.ets +113 -0
  135. package/dist/components-harmony-ets/text.ets +97 -0
  136. package/dist/components-harmony-ets/textArea.ets +169 -0
  137. package/dist/components-harmony-ets/utils/AttributeManager.ets +250 -0
  138. package/dist/components-harmony-ets/utils/DynamicCenter.ts +48 -0
  139. package/dist/components-harmony-ets/utils/constant/event.ets +25 -0
  140. package/dist/components-harmony-ets/utils/constant/icon.ts +19 -0
  141. package/dist/components-harmony-ets/utils/constant/style.ets +88 -0
  142. package/dist/components-harmony-ets/utils/events.ts +24 -0
  143. package/dist/components-harmony-ets/utils/flexManager.ets +107 -0
  144. package/dist/components-harmony-ets/utils/helper.ets +99 -0
  145. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +103 -0
  146. package/dist/components-harmony-ets/utils/htmlParser/index.ts +56 -0
  147. package/dist/components-harmony-ets/utils/index.ts +83 -0
  148. package/dist/components-harmony-ets/utils/styles.ets +91 -0
  149. package/dist/components-harmony-ets/video.ets +161 -0
  150. package/dist/components-harmony-ets/view.ets +79 -0
  151. package/dist/index.js +1183 -0
  152. package/dist/index.js.map +1 -0
  153. package/dist/runtime-ets/bom/document.ts +38 -0
  154. package/dist/runtime-ets/bom/getComputedStyle.ts +5 -0
  155. package/dist/runtime-ets/bom/navigator.ts +21 -0
  156. package/dist/runtime-ets/bom/raf.ts +37 -0
  157. package/dist/runtime-ets/bom/window.ts +44 -0
  158. package/dist/runtime-ets/constant.ts +29 -0
  159. package/dist/runtime-ets/current.ts +16 -0
  160. package/dist/runtime-ets/dom/class-list.ts +117 -0
  161. package/dist/runtime-ets/dom/comment.ts +10 -0
  162. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +105 -0
  163. package/dist/runtime-ets/dom/document.ts +108 -0
  164. package/dist/runtime-ets/dom/element.ts +457 -0
  165. package/dist/runtime-ets/dom/event.ts +164 -0
  166. package/dist/runtime-ets/dom/eventTarget.ts +98 -0
  167. package/dist/runtime-ets/dom/node.ts +215 -0
  168. package/dist/runtime-ets/dom/stylesheet/index.ts +687 -0
  169. package/dist/runtime-ets/dom/stylesheet/type.ts +136 -0
  170. package/dist/runtime-ets/dom/stylesheet/util.ts +134 -0
  171. package/dist/runtime-ets/dom/text.ts +19 -0
  172. package/dist/runtime-ets/index.ts +19 -0
  173. package/dist/runtime-ets/interface/event.ts +9 -0
  174. package/dist/runtime-ets/interface/index.ts +1 -0
  175. package/dist/runtime-ets/utils/bind.ts +35 -0
  176. package/dist/runtime-ets/utils/index.ts +135 -0
  177. package/dist/runtime-ets/utils/info.ts +128 -0
  178. package/dist/runtime-framework/react/app.ts +256 -0
  179. package/dist/runtime-framework/react/connect.ts +24 -0
  180. package/dist/runtime-framework/react/constant.ts +5 -0
  181. package/dist/runtime-framework/react/hooks.ts +101 -0
  182. package/dist/runtime-framework/react/index.ts +16 -0
  183. package/dist/runtime-framework/react/page.ts +263 -0
  184. package/dist/runtime-framework/react/utils/index.ts +25 -0
  185. package/dist/runtime-framework/react/utils/is.ts +46 -0
  186. package/dist/runtime-framework/solid/README.md +99 -0
  187. package/dist/runtime-framework/solid/app.ts +200 -0
  188. package/dist/runtime-framework/solid/connect.ts +11 -0
  189. package/dist/runtime-framework/solid/contant.ts +5 -0
  190. package/dist/runtime-framework/solid/hooks.ts +88 -0
  191. package/dist/runtime-framework/solid/index.ts +10 -0
  192. package/dist/runtime-framework/solid/page.ts +202 -0
  193. package/dist/runtime-framework/solid/reconciler/h.ts +132 -0
  194. package/dist/runtime-framework/solid/reconciler/index.ts +3 -0
  195. package/dist/runtime-framework/solid/reconciler/props.ts +151 -0
  196. package/dist/runtime-framework/solid/reconciler/render.ts +61 -0
  197. package/dist/runtime-framework/solid/reconciler/use.ts +8 -0
  198. package/dist/runtime-framework/solid/utils/index.ts +49 -0
  199. package/dist/runtime-framework/solid/utils/is.ts +46 -0
  200. package/dist/runtime-utils.js +4149 -0
  201. package/dist/runtime-utils.js.map +1 -0
  202. package/dist/runtime.js +4150 -0
  203. package/dist/runtime.js.map +1 -0
  204. package/dist/template/container.js +7 -0
  205. package/index.js +4 -0
  206. package/package.json +54 -0
  207. package/types/api.d.ts +4 -0
  208. package/types/component.d.ts +4 -0
  209. package/types/harmony.d.ts +11 -0
  210. package/types/runtime.d.ts +15 -0
  211. package/types/taro.d.ts +7 -0
  212. package/types/webpack-sources.d.ts +108 -0
@@ -0,0 +1,32 @@
1
+ import { Current } from '@tarojs/runtime'
2
+
3
+ import { temporarilyNotSupport } from '../utils'
4
+
5
+ export const ENV_TYPE = {
6
+ WEAPP: 'WEAPP',
7
+ SWAN: 'SWAN',
8
+ ALIPAY: 'ALIPAY',
9
+ TT: 'TT',
10
+ QQ: 'QQ',
11
+ JD: 'JD',
12
+ WEB: 'WEB',
13
+ RN: 'RN',
14
+ HARMONY: 'HARMONY',
15
+ QUICKAPP: 'QUICKAPP'
16
+ }
17
+
18
+ export function getEnv () {
19
+ return ENV_TYPE.HARMONY
20
+ }
21
+
22
+ export const getCurrentInstance = () => Current
23
+
24
+ export const nextTick = (cb: (...args: any[]) => any, ctx?: Record<string, any>) => {
25
+ setTimeout(function () {
26
+ ctx ? cb.call(ctx) : cb()
27
+ }, 1)
28
+ }
29
+
30
+ export const requirePlugin = temporarilyNotSupport('requirePlugin')
31
+
32
+ export { eventCenter, Events, History } from '@tarojs/runtime/dist/runtime.esm'
@@ -0,0 +1,124 @@
1
+ import _display from '@ohos.display'
2
+ import { Current, hooks } from '@tarojs/runtime'
3
+ import { isFunction, PLATFORM_TYPE } from '@tarojs/shared'
4
+
5
+ import * as apis from './apis'
6
+ import { permanentlyNotSupport } from './utils'
7
+
8
+ const taro = Object.assign({}, apis)
9
+
10
+ const requirePlugin = /* @__PURE__ */ permanentlyNotSupport('requirePlugin')
11
+ export function initNativeApi (taro) {
12
+ (Current as any).taro = taro
13
+ taro.requirePlugin = requirePlugin
14
+ taro.getApp = getApp
15
+ taro.pxTransform = pxTransform
16
+ taro.initPxTransform = initPxTransform
17
+ taro.canIUseWebp = canIUseWebp
18
+ taro.getAppInfo = getAppInfo
19
+
20
+ if (hooks.isExist('initNativeApi')) {
21
+ hooks.call('initNativeApi', taro)
22
+ }
23
+ }
24
+
25
+ const defaultDesignWidth = 750
26
+ const defaultDesignRatio: Record<string | number, number> = {
27
+ 640: 2.34 / 2,
28
+ 750: 1,
29
+ 828: 1.81 / 2
30
+ }
31
+ const defaultBaseFontSize = 20
32
+ const defaultUnitPrecision = 5
33
+ const defaultTargetUnit = 'vp'
34
+
35
+ export function getApp () {
36
+ return Current.app
37
+ }
38
+
39
+ export function initPxTransform ({
40
+ designWidth = defaultDesignWidth,
41
+ deviceRatio = defaultDesignRatio,
42
+ baseFontSize = defaultBaseFontSize,
43
+ unitPrecision = defaultUnitPrecision,
44
+ targetUnit = defaultTargetUnit
45
+ }) {
46
+ const taro = (Current as any).taro
47
+
48
+ if (taro) {
49
+ taro.config ||= {}
50
+ const config = taro.config
51
+ config.designWidth = designWidth
52
+ config.deviceRatio = deviceRatio
53
+ config.baseFontSize = baseFontSize
54
+ config.targetUnit = targetUnit
55
+ config.unitPrecision = unitPrecision
56
+ }
57
+ }
58
+
59
+ const display = _display.getDefaultDisplaySync()
60
+
61
+ let designWidthFunc: (input: number) => number
62
+ function getRatio (value: number) {
63
+ const config = (Current as any).taro?.config || {}
64
+ if (!isFunction(designWidthFunc)) {
65
+ designWidthFunc = isFunction(config.designWidth)
66
+ ? config.designWidth
67
+ : () => config.designWidth
68
+ }
69
+ const designWidth = designWidthFunc(value) || defaultDesignWidth
70
+ const deviceRatio = config.deviceRatio || defaultDesignRatio
71
+ if (!(designWidth in deviceRatio)) {
72
+ throw new Error(`deviceRatio 配置中不存在 ${designWidth} 的设置!`)
73
+ }
74
+ return Math.min(display.width, display.height) / designWidth / deviceRatio[designWidth]
75
+ }
76
+
77
+ // Note: 设置为 style 单位时会自动完成设计稿转换,设计开发者调用 API 时也许抹平差异,例如 pageScrollTo[option.offsetTop]
78
+ export function pxTransformHelper (size: number, unit?: string, isNumber = false): number | string {
79
+ const config = (Current as any).taro?.config || {}
80
+ const targetUnit = unit || config.targetUnit || defaultTargetUnit
81
+
82
+ const ratio = getRatio(size)
83
+ let val = size * ratio
84
+
85
+ switch (targetUnit) {
86
+ case 'vp':
87
+ // Note: 在应用创建前调用无效
88
+ val = px2vp(val)
89
+ break
90
+ default:
91
+ }
92
+ return isNumber ? val : val + targetUnit
93
+ }
94
+
95
+ export function pxTransform (size: number): number {
96
+ const config = (Current as any).taro?.config || {}
97
+ const targetUnit = config.targetUnit || defaultTargetUnit
98
+
99
+ let val = size
100
+ switch (targetUnit) {
101
+ case 'vp':
102
+ val = px2vp(size)
103
+ break
104
+ default:
105
+ // NOTE: 鸿蒙环境下 style 会自动完成设计稿转换,无需在方法内二次调整
106
+ }
107
+ return val + config.targetUnit
108
+ }
109
+
110
+ export function canIUseWebp () {
111
+ return true
112
+ }
113
+
114
+ export function getAppInfo () {
115
+ const config = (Current as any).taro?.config
116
+ return {
117
+ platform: process.env.TARO_PLATFORM || PLATFORM_TYPE.HARMONY,
118
+ taroVersion: process.env.TARO_VERSION || 'unknown',
119
+ designWidth: config?.designWidth,
120
+ }
121
+ }
122
+
123
+ export * from './apis'
124
+ export default taro
@@ -0,0 +1,133 @@
1
+ // HarmonyOS 文档: https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-geolocation-0000001199568865#section13752433138
2
+ // WX 文档: https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.onLocationChange.html
3
+ // ✅ wx.offLocationChange
4
+ // ✅ wx.getLocation
5
+ // ✅ wx.onLocationChange
6
+
7
+ // 不支持实现
8
+ // ❌ wx.startLocationUpdateBackground
9
+ // ❌ wx.onLocationChangeError
10
+ // ❌ wx.offLocationChangeError
11
+ // ❌ wx.openLocation 地图相关
12
+ // ❌ wx.choosePoi 地图相关
13
+ // ❌ wx.chooseLocation 地图相关
14
+ // ❌ wx.stopLocationUpdate
15
+ // ❌ wx.startLocationUpdate
16
+
17
+ import geoLocationManager from '@ohos.geoLocationManager'
18
+ import Taro from '@tarojs/taro'
19
+
20
+ import { callAsyncFail, callAsyncSuccess, validateParams } from '../utils'
21
+
22
+ interface IGetOHOSGeolocationParams {
23
+ type?: string
24
+ altitude?: boolean
25
+ isHighAccuracy?: boolean
26
+ highAccuracyExpireTime?: number
27
+ priority?: number // 数值为固定几种
28
+ scenario?: number // 数值为固定几种
29
+ maxAccuracy?: number // 表示精度信息,单位是米。
30
+ timeoutMs?: number
31
+ }
32
+
33
+ interface ILocationRequest {
34
+ priority?: number
35
+ scenario?: number // 勘误:注意 Harmony OS 这个参数是必填
36
+ timeInterval?: number
37
+ distanceInterval?: number
38
+ maxAccuracy?: number
39
+ }
40
+
41
+ interface ILocationSuccessDataOHOS {
42
+ latitude: number
43
+ longitude: number
44
+ altitude: number
45
+ accuracy: number
46
+ speed: number
47
+ timeStamp: number
48
+ direction: number
49
+ timeSinceBoot: number
50
+ additions: Array<string>
51
+ additionSize: number
52
+ }
53
+
54
+ interface ILocationSuccessOHOS {
55
+ code: number
56
+ data: ILocationSuccessDataOHOS
57
+ }
58
+
59
+ function formatLocation (location: ILocationSuccessDataOHOS) {
60
+ const locationWX = {
61
+ latitude: location.latitude,
62
+ longitude: location.longitude,
63
+ altitude: location.altitude,
64
+ accuracy: location.accuracy,
65
+ speed: location.speed,
66
+ verticalAccuracy: 0, // OHOS 不支持返回此参数,直接设置为默认值
67
+ horizontalAccuracy: 0 // OHOS 不支持返回此参数,直接设置为默认值
68
+ }
69
+ return locationWX
70
+ }
71
+ // TODO:增加参数校验
72
+ // const getLocationSchema = {
73
+ // type: 'String',
74
+ // altitude: 'Boolean',
75
+ // ishighAccuracy: 'Boolean',
76
+ // highAccuracyExpireTime: 'number'
77
+ // }
78
+
79
+ export const getLocation: typeof Taro.getLocation = function (options = {}) {
80
+ return new Promise((resolve, reject) => {
81
+ /**
82
+ * ohos 有 priority, scenario, maxAccuracy, timeoutMs
83
+ * wx 有 type, altitude, isHighAccuracy, highAccuracyExpireTime
84
+ * 二者参数不一致
85
+ */
86
+ const { type, altitude, isHighAccuracy, highAccuracyExpireTime } = options
87
+ const params: IGetOHOSGeolocationParams = {
88
+ type,
89
+ altitude,
90
+ isHighAccuracy,
91
+ highAccuracyExpireTime
92
+ }
93
+ try {
94
+ return geoLocationManager.getCurrentLocation(params).then((location: ILocationSuccessOHOS) => {
95
+ if (location.code !== 0) {
96
+ callAsyncFail(reject, location, options)
97
+ } else {
98
+ const locationWX = formatLocation(location.data)
99
+ callAsyncSuccess(resolve, locationWX, options)
100
+ }
101
+ }).catch(error => {
102
+ callAsyncFail(reject, error, options)
103
+ })
104
+ } catch (error) {
105
+ callAsyncFail(reject, error, options)
106
+ }
107
+ })
108
+ }
109
+
110
+ export const onLocationChange: typeof Taro.onLocationChange = function (callback) {
111
+ validateParams('onLocationChange', [callback], ['Function'])
112
+ const requestInfo: ILocationRequest = {}
113
+ geoLocationManager.on('locationChange', requestInfo, (location: ILocationSuccessDataOHOS) => {
114
+ if (location) {
115
+ const locationWX = formatLocation(location)
116
+ callback(locationWX)
117
+ }
118
+ })
119
+ }
120
+
121
+ export const offLocationChange: typeof Taro.offLocationChangeError = function (callback) {
122
+ validateParams('offLocationChange', [callback], ['Function'])
123
+ geoLocationManager.off('locationChange', (location: ILocationSuccessOHOS) => {
124
+ const status = {
125
+ errCode: 200,
126
+ errMsg: location ? 'offLocationChange is off' : 'offLocationChange err'
127
+ }
128
+
129
+ if (callback) {
130
+ callback(status)
131
+ }
132
+ })
133
+ }
@@ -0,0 +1,74 @@
1
+ // HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-media-0000001103383404
2
+ // WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.previewMedia.html
3
+ // ✅ wx.previewMedia(Object object)
4
+ // ✅ wx.chooseMedia
5
+
6
+ import mediaLibrary from '@ohos.multimedia.mediaLibrary'
7
+ import Taro from '@tarojs/taro'
8
+
9
+ import { callAsyncFail, callAsyncSuccess, validateParams } from '../utils'
10
+
11
+ interface IPreviewImagesOptionsOHOS {
12
+ images: Array<string>
13
+ index: number
14
+ }
15
+
16
+ interface IChooseMediaOptionsOHOS {
17
+ type: string
18
+ count: number
19
+ }
20
+
21
+ const previewMediaSchema = {
22
+ sources: 'Array'
23
+ }
24
+
25
+ // TODO: 扩展支持预览video
26
+ export const previewMedia: typeof Taro.previewMedia = function (options) {
27
+ return new Promise((resolve, reject) => {
28
+ try {
29
+ validateParams('previewMedia', options, previewMediaSchema)
30
+ } catch (error) {
31
+ const res = { errMsg: error.message }
32
+ return callAsyncFail(reject, res, options)
33
+ }
34
+ const { sources, current } = options
35
+ const urls: Array<string> = []
36
+ for (const s of sources) {
37
+ if (s.type === 'image') {
38
+ urls.push(s.url)
39
+ }
40
+ }
41
+ const previewImageOptions: IPreviewImagesOptionsOHOS = {
42
+ images: urls,
43
+ index: current || 0
44
+ }
45
+ mediaLibrary.getMediaLibrary().startImagePreview(previewImageOptions.images, previewImageOptions.index).then((value) => {
46
+ callAsyncSuccess(resolve, value, options)
47
+ }).catch((error) => {
48
+ callAsyncFail(reject, error, options)
49
+ })
50
+ })
51
+ }
52
+
53
+ export const chooseMedia: typeof Taro.chooseMedia = function (options) {
54
+ return new Promise((resolve, reject) => {
55
+ try {
56
+ validateParams('chooseMedia', [options], ['Object'])
57
+ } catch (error) {
58
+ const res = { errMsg: error.message }
59
+ return callAsyncFail(reject, res, options)
60
+ }
61
+ const { count = 9, mediaType = ['image'] } = options
62
+ // HarmonyOS不支持image和video同时选择
63
+ // TODO: 不支持视频拍摄,无现成组件,后续需要封装
64
+ const mediaSelectOptions: IChooseMediaOptionsOHOS = {
65
+ count,
66
+ type: mediaType[0]
67
+ }
68
+ mediaLibrary.getMediaLibrary().startMediaSelect(mediaSelectOptions).then((value) => {
69
+ callAsyncSuccess(resolve, value, options)
70
+ }).catch((error) => {
71
+ callAsyncFail(reject, error, options)
72
+ })
73
+ })
74
+ }
@@ -0,0 +1,122 @@
1
+ // HarmonyOS 图片模块首批接口从API version 7开始支持。
2
+ // HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-image-0000001122977382
3
+ // WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.saveImageToPhotosAlbum.html
4
+
5
+ // ✅ wx.getImageInfo(Object object) API7以上支持
6
+ // ✅ wx.compressImage(Object object) API7以上支持
7
+ // ✅ wx.chooseImage(Object object)
8
+ // ❌ wx.chooseMessageFile(Object object) HarmonyOS不支持
9
+ // ❌ wx.saveImageToPhotosAlbum(Object object) api 9+ HarmonyOS不支持
10
+ // ❌ wx.previewImage(Object object) api 9+ HarmonyOS不支持
11
+
12
+ import picker from '@ohos.file.picker'
13
+ import image from '@ohos.multimedia.image'
14
+ import { isNull } from '@tarojs/shared'
15
+ import Taro from '@tarojs/taro'
16
+
17
+ import { callAsyncFail, callAsyncSuccess, temporarilyNotSupport, validateParams } from '../utils'
18
+
19
+ interface IPackingOptionOHOS {
20
+ format: string
21
+ quality: number
22
+ }
23
+
24
+ const getImageInfoSchema = {
25
+ url: 'String'
26
+ }
27
+
28
+ const compressImageSchema = {
29
+ url: 'String'
30
+ }
31
+
32
+ const chooseImageSchema = {
33
+ count: 'Number'
34
+ }
35
+
36
+ const photoSelectOptions = new picker.PhotoSelectOptions()
37
+
38
+ export const getImageInfo: typeof Taro.getImageInfo = function (options) {
39
+ return new Promise((resolve, reject) => {
40
+ try {
41
+ validateParams('getImageInfo', options, getImageInfoSchema)
42
+ } catch (error) {
43
+ const res = { errMsg: error.message }
44
+ return callAsyncFail(reject, res, options)
45
+ }
46
+ const { src } = options
47
+ // FIX: 调试发现在版本api7中 source 为 undefined, 需鸿蒙侧确认
48
+ const source = image.createImageSource(src)
49
+ if (isNull(source)) {
50
+ const createImageSourceError = { errMsg: 'getImageInfo fail: createImageSource has failed.' }
51
+ callAsyncFail(reject, createImageSourceError, options)
52
+ return
53
+ }
54
+ source.getImageInfo().then((value) => {
55
+ callAsyncSuccess(resolve, value, options)
56
+ }).catch((error) => {
57
+ callAsyncFail(reject, error, options)
58
+ })
59
+ })
60
+ }
61
+
62
+ export const compressImage: typeof Taro.compressImage = function (options) {
63
+ return new Promise((resolve, reject) => {
64
+ try {
65
+ validateParams('compressImage', options, compressImageSchema)
66
+ } catch (error) {
67
+ const res = { errMsg: error.message }
68
+ return callAsyncFail(reject, res, options)
69
+ }
70
+ const { src, quality = 80 } = options
71
+
72
+ const source = image.createImageSource(src)
73
+ if (isNull(source)) {
74
+ const createImageSourceError = { errMsg: 'compressImage fail: createImageSource has failed.' }
75
+ callAsyncFail(reject, createImageSourceError, options)
76
+ return
77
+ }
78
+
79
+ const packer = image.createImagePacker(src)
80
+ if (isNull(packer)) {
81
+ const createImagePackerError = { errMsg: 'compressImage fail: createImagePacker has failed.' }
82
+ callAsyncFail(reject, createImagePackerError, options)
83
+ }
84
+
85
+ const packingOptionsOHOS: IPackingOptionOHOS = {
86
+ // TODO:需要获取文件名后缀
87
+ format: 'image/jpeg',
88
+ quality: quality
89
+ }
90
+ packer.packing(source, packingOptionsOHOS).then((value) => {
91
+ callAsyncSuccess(resolve, value, options)
92
+ }).catch((error) => {
93
+ callAsyncFail(reject, error, options)
94
+ })
95
+ })
96
+ }
97
+
98
+ export const chooseImage: typeof Taro.chooseImage = function (options) {
99
+ return new Promise((resolve, reject) => {
100
+ try {
101
+ validateParams('chooseImage', options, chooseImageSchema)
102
+ } catch (error) {
103
+ const res = { errMsg: error.message }
104
+ return callAsyncFail(reject, res, options)
105
+ }
106
+
107
+ const { count = 9 } = options
108
+ const photoViewPicker = new picker.PhotoViewPicker()
109
+
110
+ photoSelectOptions.maxSelectNumber = count // 选择媒体文件的最大数目
111
+ photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE // 过滤选择媒体文件类型为IMAGE
112
+
113
+ photoViewPicker.select(photoSelectOptions).then((photoSelectResult) => {
114
+ callAsyncSuccess(resolve, { tempFilePaths: photoSelectResult.photoUris })
115
+ }).catch((error) => {
116
+ callAsyncFail(reject, error, options)
117
+ })
118
+ })
119
+ }
120
+
121
+ export const previewImage = temporarilyNotSupport('previewImage')
122
+ export const saveImageToPhotosAlbum = temporarilyNotSupport('saveImageToPhotosAlbum')
@@ -0,0 +1,3 @@
1
+ export * from './common'
2
+ export * from './image'
3
+ export * from './video'
@@ -0,0 +1,86 @@
1
+ // HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-media-0000001103383404
2
+ // WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/media/video/wx.chooseVideo.html
3
+ // ✅ wx.saveVideoToPhotosAlbum
4
+ // ❌ wx.openVideoEditor
5
+ // ❌ wx.getVideoInfo
6
+ // ❌ wx.createVideoContext
7
+ // ❌ wx.compressVideo
8
+ // ✅ wx.chooseVideo
9
+ // VideoContext
10
+ // ❌ VideoContext.exitBackgroundPlayback
11
+ // ❌ VideoContext.exitFullScreen
12
+ // ❌ VideoContext.exitPictureInPicture
13
+ // ❌ VideoContext.hideStatusBar
14
+ // ❌ VideoContext.pause
15
+ // ❌ VideoContext.play
16
+ // ❌ VideoContext.playbackRate
17
+ // ❌ VideoContext.requestBackgroundPlayback
18
+ // ❌ VideoContext.requestFullScreen
19
+ // ❌ VideoContext.seek
20
+ // ❌ VideoContext.sendDanmu
21
+ // ❌ VideoContext.showStatusBar
22
+ // ❌ VideoContext.stop
23
+
24
+ import mediaLibrary from '@ohos.multimedia.mediaLibrary'
25
+ import Taro from '@tarojs/taro'
26
+
27
+ import { callAsyncFail, callAsyncSuccess, validateParams } from '../utils'
28
+
29
+ interface IChooseVideoOptionOHOS {
30
+ type: string
31
+ count: number
32
+ }
33
+
34
+ interface ISaveVideoToPhotosAlbumOptionsOHOS {
35
+ src: string
36
+ mimeType: string
37
+ relativePath?: string
38
+ }
39
+
40
+ const saveVideoToPhotosAlbumSchema = {
41
+ filePath: 'String'
42
+ }
43
+
44
+ // TODO: 1.返回属性补全
45
+ // TODO: 2.只支持从相册选择,补充摄像头拍摄功能,需要HarmonyOS提供选择组件
46
+ export const chooseVideo: typeof Taro.chooseVideo = function (options = {}) {
47
+ return new Promise((resolve, reject) => {
48
+ try {
49
+ validateParams('chooseVideo', [options], ['Object'])
50
+ } catch (error) {
51
+ const res = { errMsg: error.message }
52
+ return callAsyncFail(reject, res, options)
53
+ }
54
+ const chooseVideoOptionsOHOS: IChooseVideoOptionOHOS = {
55
+ type: 'video',
56
+ count: 1
57
+ }
58
+ mediaLibrary.getMediaLibrary().startMediaSelect(chooseVideoOptionsOHOS).then((value) => {
59
+ callAsyncSuccess(resolve, { tempFilePaths: value })
60
+ }).catch((error) => {
61
+ callAsyncFail(reject, error, options)
62
+ })
63
+ })
64
+ }
65
+
66
+ export const saveVideoToPhotosAlbum: typeof Taro.saveVideoToPhotosAlbum = function (options) {
67
+ return new Promise((resolve, reject) => {
68
+ try {
69
+ validateParams('saveVideoToPhotosAlbum', options, saveVideoToPhotosAlbumSchema)
70
+ } catch (error) {
71
+ const res = { errMsg: error.message }
72
+ return callAsyncFail(reject, res, options)
73
+ }
74
+ const { filePath } = options
75
+ const saveVideoToPhotosAlbumOptions: ISaveVideoToPhotosAlbumOptionsOHOS = {
76
+ src: filePath,
77
+ // TODO:需要获取文件名后缀,'video/mp4'、'video/3gpp'等
78
+ mimeType: 'video/mp4'
79
+ }
80
+ mediaLibrary.getMediaLibrary().storeMediaAsset(saveVideoToPhotosAlbumOptions).then((value) => {
81
+ callAsyncSuccess(resolve, value, options)
82
+ }).catch((error) => {
83
+ callAsyncFail(reject, error, options)
84
+ })
85
+ })
86
+ }
@@ -0,0 +1,8 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 跳转
4
+ export const openEmbeddedMiniProgram = /* @__PURE__ */ temporarilyNotSupport('openEmbeddedMiniProgram')
5
+ export const navigateToMiniProgram = /* @__PURE__ */ temporarilyNotSupport('navigateToMiniProgram')
6
+ export const navigateBackMiniProgram = /* @__PURE__ */ temporarilyNotSupport('navigateBackMiniProgram')
7
+ export const exitMiniProgram = /* @__PURE__ */ temporarilyNotSupport('exitMiniProgram')
8
+ export const openBusinessView = /* @__PURE__ */ temporarilyNotSupport('openBusinessView')