@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,113 @@
1
+ // HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-request-0000001123753962#section455311474372
2
+ // WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/network/download/wx.downloadFile.html
3
+ // ✅ wx.downloadFile (BETA)7+,因为使用了 query 和 on('complete')
4
+ // ✅ DownloadTask.abort
5
+ // ✅ DownloadTask.offProgressUpdate
6
+ // ✅ DownloadTask.onProgressUpdate
7
+ // ❌ DownloadTask.onHeadersReceived 此接口 ohos 不支持
8
+ // ❌ DownloadTask.offHeadersReceived 此接口 ohos 不支持
9
+
10
+ import request from '@ohos.request'
11
+ import Taro, { DownloadTask } from '@tarojs/taro'
12
+
13
+ import { callAsyncFail, callAsyncSuccess, validateParams } from '../utils'
14
+
15
+ interface IDownloadConfigOHOS {
16
+ url: string
17
+ header?: any
18
+ filePath?: string
19
+ enableMetered?: boolean // ohos参数
20
+ enableRoaming?: boolean // ohos参数
21
+ description?: string // ohos参数
22
+ networkType?: number // ohos参数
23
+ title?: string // ohos参数
24
+ }
25
+
26
+ const downloadFileSchema = {
27
+ url: 'String'
28
+ }
29
+
30
+ export const downloadFile: typeof Taro.downloadFile = function (options) {
31
+ let downloadTask: any = {}
32
+
33
+ const downloadTaskWX: any = new Promise((resolve, reject) => {
34
+ const { url, header, filePath } = options
35
+
36
+ try {
37
+ validateParams('downloadFile', options, downloadFileSchema)
38
+ } catch (error) {
39
+ const res = { errMsg: error.message }
40
+ return callAsyncFail(reject, res, options)
41
+ }
42
+
43
+ const ohosParams: IDownloadConfigOHOS = {
44
+ url
45
+ }
46
+ if (header) ohosParams.header = header
47
+ if (filePath) ohosParams.filePath = filePath
48
+
49
+ request.download(ohosParams).then((dataDownload:any) => {
50
+ downloadTask = dataDownload
51
+
52
+ // TODO: 建议鸿蒙优化 complete 回调接口。
53
+ // ohos 的 complete 回调不返回任何下载信息,需要调用 query 查询后,在 complete 和 fail 中调用回调返回
54
+ downloadTask.query().then(dataQuery => {
55
+ downloadTask.on('complete', () => {
56
+ dataQuery.status = dataQuery.statusCode
57
+ callAsyncSuccess(resolve, dataQuery, options)
58
+ })
59
+ downloadTask.on('fail', (err) => {
60
+ const res = {
61
+ errMsg: err
62
+ }
63
+ callAsyncFail(reject, res, options)
64
+ })
65
+ }).catch((err) => {
66
+ callAsyncFail(reject, err, options)
67
+ })
68
+ }).catch((err) => {
69
+ callAsyncFail(reject, err, options)
70
+ })
71
+ })
72
+ downloadTaskWX.abort = function () {
73
+ downloadTask.remove((err: any, data: any) => {
74
+ if (err) {
75
+ return err
76
+ }
77
+ return data
78
+ })
79
+ }
80
+ downloadTaskWX.offProgressUpdate = function offProgressUpdate (callback: DownloadTask.OnProgressUpdateCallback) {
81
+ validateParams('offProgressUpdate', [callback], ['Function'])
82
+ downloadTask.off('progress', (receivedSize: number, totalSize: number) => {
83
+ const totalBytesWritten: number = receivedSize * 1024
84
+ const totalBytesExpectedToWrite: number = totalSize * 1024
85
+ // TODO: 进度应该保留几位小数?暂时保留6位
86
+ const progress: number = +(receivedSize / totalSize).toFixed(6)
87
+ const progressParams = {
88
+ totalBytesWritten,
89
+ totalBytesExpectedToWrite,
90
+ progress,
91
+ errMsg: 'Cancel progress listening is done.'
92
+ }
93
+ callback(progressParams)
94
+ })
95
+ }
96
+ // wx 单位是 Bytes,ohos 单位是 KBytes
97
+ downloadTaskWX.onProgressUpdate = function (callback: DownloadTask.OnProgressUpdateCallback) {
98
+ validateParams('onProgressUpdate', [callback], ['Function'])
99
+ downloadTask.on('progress', (receivedSize: number, totalSize: number) => {
100
+ const totalBytesWritten: number = receivedSize * 1024
101
+ const totalBytesExpectedToWrite: number = totalSize * 1024
102
+ // TODO: 进度应该保留几位小数?暂时保留6位
103
+ const progress: number = +(receivedSize / totalSize).toFixed(6)
104
+ const progressParams: DownloadTask.OnProgressUpdateCallbackResult = {
105
+ totalBytesWritten,
106
+ totalBytesExpectedToWrite,
107
+ progress
108
+ }
109
+ callback(progressParams)
110
+ })
111
+ }
112
+ return downloadTaskWX
113
+ }
@@ -0,0 +1,4 @@
1
+ export * from './downloadFile'
2
+ export * from './request'
3
+ export * from './uploadFile'
4
+ export * from './webSocket'
@@ -0,0 +1,113 @@
1
+ // HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-net-http-0000001168304341
2
+ // WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html
3
+ // ✅ wx.request
4
+ // ✅ RequestTask.abort
5
+ // ✅ RequestTask.offHeadersReceived
6
+ // ✅ RequestTask.onHeadersReceived
7
+
8
+ import http from '@ohos.net.http'
9
+ import { isString, isUndefined } from '@tarojs/shared'
10
+ import Taro from '@tarojs/taro'
11
+
12
+ import { callAsyncFail, callAsyncSuccess, validateParams } from '../utils'
13
+
14
+ const METHOD: string [] = ['OPTIONS', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'CONNECT']
15
+
16
+ interface IRequestResultOHOS {
17
+ result: string | any
18
+ responseCode: number
19
+ header
20
+ }
21
+
22
+ interface IRequestParamsOHOS {
23
+ method?: string
24
+ header?: any
25
+ extraData?: any | string
26
+ readTimeout?: number
27
+ connectTimeout?: number
28
+ }
29
+
30
+ const requestSchema = {
31
+ url: 'String'
32
+ }
33
+
34
+ export const request: typeof Taro.request = function (options) {
35
+ let httpRequestOhos: ReturnType<typeof http.createHttp>
36
+
37
+ const requestTask: any = new Promise((resolve, reject) => {
38
+ try {
39
+ httpRequestOhos = http.createHttp()
40
+ } catch (error) {
41
+ const res = { errMsg: error }
42
+ return callAsyncFail(reject, res, options)
43
+ }
44
+
45
+ const { url, method, header = {}, timeout, dataType, data } = options
46
+
47
+ try {
48
+ validateParams('send', options, requestSchema)
49
+ } catch (error) {
50
+ const res = { errMsg: error.message }
51
+ return callAsyncFail(reject, res, options)
52
+ }
53
+
54
+ const keyOfContentType = Object.keys(header).find(item => item.toLowerCase() === 'content-type')
55
+
56
+ if (!keyOfContentType) {
57
+ header['Content-Type'] = 'application/json'
58
+ }
59
+
60
+ // 检查 Header 是否有 Referer
61
+ if (isUndefined(header.Referer)) {
62
+ const error = { errMsg: 'request fail parameter error: the header doesn‘t support Referer property' }
63
+ callAsyncFail(reject, error, options)
64
+ }
65
+
66
+ // 检查 method 是否正确
67
+ if (method) {
68
+ if (!METHOD.includes(method)) {
69
+ const error = { errMsg: `request fail parameter error: the method value should be one of the ${METHOD.join(',')}` }
70
+ callAsyncFail(reject, error, options)
71
+ }
72
+ }
73
+
74
+ const requestParamsOHOS: IRequestParamsOHOS = {
75
+ method,
76
+ header,
77
+ extraData: data as IRequestParamsOHOS['extraData'],
78
+ readTimeout: timeout,
79
+ connectTimeout: timeout
80
+ }
81
+
82
+ httpRequestOhos.request(url, requestParamsOHOS).then((requestData: IRequestResultOHOS) => {
83
+ const reswx = {
84
+ data: dataType === 'json' && isString(requestData.result) ? JSON.parse(requestData.result) : requestData.result,
85
+ statusCode: requestData.responseCode,
86
+ header: requestData.header
87
+ }
88
+ callAsyncSuccess(resolve, reswx, options)
89
+ }).catch(error => {
90
+ callAsyncFail(reject, error, options)
91
+ })
92
+ })
93
+
94
+ requestTask.abort = function () {
95
+ httpRequestOhos.destroy()
96
+ }
97
+
98
+ requestTask.onHeadersReceived = function (callback) {
99
+ validateParams('onHeadersReceived', [callback], ['Function'])
100
+ httpRequestOhos.on('headerReceive', (err, res) => {
101
+ callback(!err ? res : err)
102
+ })
103
+ }
104
+
105
+ requestTask.offHeadersReceived = function (callback) {
106
+ validateParams('offHeadersReceived', [callback], ['Function'])
107
+ httpRequestOhos.off('headerReceive', (err, res) => {
108
+ callback(!err ? res : err)
109
+ })
110
+ }
111
+
112
+ return requestTask
113
+ }
@@ -0,0 +1,158 @@
1
+ // HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-request-0000001123753962#section455311474372
2
+ // WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/wx.uploadFile.html
3
+ // ✅ wx.uploadFile
4
+ // ✅ UploadTask.abort
5
+ // ✅ UploadTask.offHeadersReceived (BETA)7+
6
+ // ✅ UploadTask.offProgressUpdate
7
+ // ✅ UploadTask.onHeadersReceived(BETA)7+
8
+ // ✅ UploadTask.onProgressUpdate
9
+
10
+ import request from '@ohos.request'
11
+ import { isUndefined } from '@tarojs/shared'
12
+ import Taro, { UploadTask } from '@tarojs/taro'
13
+
14
+ import { callAsyncFail, callAsyncSuccess, validateParams } from '../utils'
15
+
16
+ interface IOHOSFileType {
17
+ filename?: string
18
+ name?: string
19
+ url: string // 支持“dataability”和“internal”两种协议类型,但“internal”仅支持临时目录。详见官方文档
20
+ type?: string
21
+ }
22
+
23
+ interface IRequestDataOHOS {
24
+ name?: string
25
+ value?: string
26
+ }
27
+
28
+ interface IUploadFileParamsOHOS {
29
+ url: string // 资源地址
30
+ header?: any
31
+ method?: string // POST、PUT。缺省为POST
32
+ files?: Array<IOHOSFileType> // 请使用 multipart/form-data提交。官方文档提供的demo未传此参数,应该是文档错了。
33
+ data?: Array<IRequestDataOHOS>
34
+ }
35
+
36
+ const uploadSchema = {
37
+ url: 'String'
38
+ // filePath: 'String',
39
+ // name: 'String'
40
+ }
41
+
42
+ // wx 只支持 HTTP POST 请求,OHOS 支持 POST 和 PUT 请求
43
+ // OHOS 不支持 wx 的 timeout,但是支持 file 文件列表上传,wx 是单文件上传
44
+ export const uploadFile: typeof Taro.uploadFile = function (options) {
45
+ let uploadTask: any = {}
46
+
47
+ const UploadTaskWX: any = new Promise((resolve, reject) => {
48
+ let timer
49
+ const { url, filePath, name, header, formData, timeout } = options
50
+
51
+ try {
52
+ validateParams('uploadFile', options, uploadSchema)
53
+ } catch (error) {
54
+ const res = { errMsg: error.message }
55
+ return callAsyncFail(reject, res, options)
56
+ }
57
+
58
+ const file: IOHOSFileType = {
59
+ url: filePath,
60
+ name
61
+ }
62
+ const files: Array<IOHOSFileType> = [file]
63
+ const ohosParams: IUploadFileParamsOHOS = {
64
+ url,
65
+ files,
66
+ method: 'POST',
67
+ header
68
+ }
69
+
70
+ if (formData) {
71
+ const rData: Array<IRequestDataOHOS> = []
72
+ Object.keys(formData).forEach((key: string) => {
73
+ const rDataEle: IRequestDataOHOS = {
74
+ name: key,
75
+ value: formData[key]
76
+ }
77
+ rData.push(rDataEle)
78
+ })
79
+ ohosParams.data = rData
80
+ }
81
+ if (!isUndefined(timeout)) {
82
+ timer = setTimeout(() => {
83
+ const err: {errMsg: string} = {
84
+ errMsg: 'uploadFile request timeout, please try again later.'
85
+ }
86
+ callAsyncFail(reject, err, options)
87
+ }, timeout)
88
+ }
89
+
90
+ request.upload(ohosParams).then((dataUpload) => {
91
+ if (timer) {
92
+ clearTimeout(timer)
93
+ }
94
+ uploadTask = dataUpload
95
+ callAsyncSuccess(resolve, UploadTaskWX, options)
96
+ }).catch((err) => {
97
+ if (timer) {
98
+ clearTimeout(timer)
99
+ }
100
+ callAsyncFail(reject, err, options)
101
+ })
102
+ })
103
+
104
+ UploadTaskWX.abort = function () {
105
+ uploadTask.remove((err: any, result: any) => {
106
+ if (err || result) {
107
+ return err || result
108
+ }
109
+ return result
110
+ })
111
+ }
112
+ UploadTaskWX.onHeadersReceived = function (callback: (params) => void) {
113
+ validateParams('onHeadersReceived', [callback], ['Function'])
114
+ uploadTask.on('headerReceive', (headers: any) => {
115
+ callback(headers)
116
+ })
117
+ }
118
+ UploadTaskWX.offHeadersReceived = function (callback: (params) => void) {
119
+ validateParams('offHeadersReceived', [callback], ['Function'])
120
+ uploadTask.off('headerReceive', (headers: any) => {
121
+ callback(headers)
122
+ })
123
+ }
124
+ // wx 单位是 Bytes,ohos 单位是 KBytes
125
+ UploadTaskWX.onProgressUpdate = function (callback: UploadTask.OnProgressUpdateCallback) {
126
+ validateParams('onProgressUpdate', [callback], ['Function'])
127
+ uploadTask.on('progress', (uploadSize: number, totalSize: number) => {
128
+ const totalBytesSent: number = uploadSize * 1024
129
+ const totalBytesExpectedToSend: number = totalSize * 1024
130
+ // TODO: 进度应该保留几位小数?暂时保留6位
131
+ const progress: number = +(uploadSize / totalSize).toFixed(6)
132
+ const progressParams: UploadTask.OnProgressUpdateCallbackResult = {
133
+ totalBytesSent,
134
+ totalBytesExpectedToSend,
135
+ progress
136
+ }
137
+ callback(progressParams)
138
+ })
139
+ }
140
+ UploadTaskWX.offProgressUpdate = function (callback: UploadTask.OnProgressUpdateCallback) {
141
+ validateParams('offProgressUpdate', [callback], ['Function'])
142
+ uploadTask.off('progress', (uploadSize: number, totalSize: number) => {
143
+ const totalBytesSent: number = uploadSize * 1024
144
+ const totalBytesExpectedToSend: number = totalSize * 1024
145
+ // TODO: 进度应该保留几位小数?暂时保留6位
146
+ const progress: number = +(uploadSize / totalSize).toFixed(6)
147
+ const progressParams = {
148
+ totalBytesSent,
149
+ totalBytesExpectedToSend,
150
+ progress,
151
+ errMsg: 'Cancel progress listening is done.'
152
+ }
153
+ callback(progressParams)
154
+ })
155
+ }
156
+
157
+ return UploadTaskWX
158
+ }
@@ -0,0 +1,130 @@
1
+ // OpenHarmony 不支持全局操作 WebSocket
2
+ // HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-net-websocket-0000001168304641
3
+ // WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.sendSocketMessage.html
4
+ // ✅ wx.connectSocket
5
+ // ✅ SocketTask
6
+ // ✅ SocketTask.close
7
+ // ✅ SocketTask.onClose
8
+ // ✅ SocketTask.onError
9
+ // ✅ SocketTask.onMessage
10
+ // ✅ SocketTask.onOpen
11
+ // ✅ SocketTask.send
12
+
13
+ // ❌ wx.sendSocketMessage
14
+ // ❌ wx.onSocketOpen
15
+ // ❌ wx.onSocketMessage
16
+ // ❌ wx.onSocketError
17
+ // ❌ wx.onSocketClose
18
+ // ❌ wx.closeSocket
19
+
20
+ import webSocket from '@ohos.net.webSocket'
21
+ import Taro from '@tarojs/taro'
22
+
23
+ import { callAsyncFail, callAsyncSuccess, validateParams } from '../utils'
24
+ import { IAsyncParams } from '../utils/types'
25
+
26
+ interface ISendSocketOptions extends IAsyncParams {
27
+ data: string
28
+ }
29
+
30
+ const connectSocketSchema = {
31
+ url: 'String'
32
+ }
33
+
34
+ // const closetSocketSchema = {
35
+ // code: 'Number',
36
+ // reason: 'String'
37
+ // }
38
+
39
+ const sendSocketSchema = {
40
+ data: 'String'
41
+ }
42
+
43
+ export const connectSocket: typeof Taro.connectSocket = function (options) {
44
+ let ws
45
+ const SocketTaskWX: any = new Promise((resolve, reject) => {
46
+ ws = webSocket.createWebSocket()
47
+
48
+ const { url, header } = options
49
+
50
+ try {
51
+ validateParams('uploadFile', options, connectSocketSchema)
52
+ } catch (error) {
53
+ const res = { errMsg: error.message }
54
+ return callAsyncFail(reject, res, options)
55
+ }
56
+
57
+ const result = {
58
+ errMsg: 'websocket connect success'
59
+ }
60
+ ws.connect(url, { header }).then((value) => {
61
+ callAsyncSuccess(resolve, value, options)
62
+ }).catch((err) => {
63
+ result.errMsg = 'websocket connect fail'
64
+ callAsyncFail(reject, err, options)
65
+ })
66
+ })
67
+
68
+ SocketTaskWX.close = function (closeOptions) {
69
+ return new Promise((resolve, reject) => {
70
+ // TODO: 检验非必须参数
71
+ // try {
72
+ // validateParams('close', options, closeSocketSchema)
73
+ // } catch (error) {
74
+ // const res = { errMsg: error.message }
75
+ // return callAsyncFail(reject, res, options)
76
+ // }
77
+
78
+ ws.close(closeOptions).then(value => {
79
+ callAsyncSuccess(resolve, value, closeOptions)
80
+ }, error => {
81
+ callAsyncFail(reject, error, closeOptions)
82
+ })
83
+ })
84
+ }
85
+ SocketTaskWX.onClose = function (onCloseCallback) {
86
+ validateParams('onClose', [onCloseCallback], ['Function'])
87
+ ws.on('close', (err, value) => {
88
+ onCloseCallback(!err ? value : err)
89
+ })
90
+ }
91
+ SocketTaskWX.onError = function (onErrorCallback) {
92
+ validateParams('onError', [onErrorCallback], ['Function'])
93
+ ws.on('error', (err) => {
94
+ onErrorCallback(err)
95
+ })
96
+ }
97
+ SocketTaskWX.onMessage = function (onMessageCallback?: any) {
98
+ validateParams('onMessage', [onMessageCallback], ['Function'])
99
+ ws.on('onMessage', (err, value) => {
100
+ onMessageCallback(!err ? value : err)
101
+ })
102
+ }
103
+ SocketTaskWX.onOpen = function (onOpenCallback) {
104
+ validateParams('onOpen', [onOpenCallback], ['Function'])
105
+ ws.on('open', (err, value) => {
106
+ // TODO:返回数据字段完全不一样,无法兼容,暂不处理
107
+ // wx:{header, profile}, ohos:{err, value:{status, message}}
108
+ onOpenCallback(!err ? value : err)
109
+ })
110
+ }
111
+ SocketTaskWX.send = function (sendOptions: ISendSocketOptions) {
112
+ return new Promise((resolve, reject) => {
113
+ const { data } = sendOptions
114
+ try {
115
+ validateParams('send', sendOptions, sendSocketSchema)
116
+ } catch (error) {
117
+ const res = { errMsg: error.message }
118
+ return callAsyncFail(reject, res, options)
119
+ }
120
+
121
+ ws.send(data).then(value => {
122
+ callAsyncSuccess(resolve, value, sendOptions)
123
+ }, error => {
124
+ callAsyncFail(reject, error, sendOptions)
125
+ })
126
+ })
127
+ }
128
+
129
+ return SocketTaskWX
130
+ }
@@ -0,0 +1,7 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ export const login = temporarilyNotSupport('login')
4
+ export const getAccountInfoSync = temporarilyNotSupport('getAccountInfoSync')
5
+ export const requestSubscribeMessage = temporarilyNotSupport('requestSubscribeMessage')
6
+
7
+ export * from './user-info'
@@ -0,0 +1,85 @@
1
+ /**
2
+ * 用户相关API, Harmony ACE API 6
3
+ *
4
+ * 1. 华为账号场景介绍文档 @see https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/harmonyos-js-login-0000001151310900
5
+ * 2. 华为账号API参考 @see https://developer.huawei.com/consumer/cn/doc/development/HMSCore-References/harmonyos-js-overview-0000001063532145
6
+ */
7
+
8
+ // import hmsJSAccount from '@hmscore/hms-jsb-account'
9
+ import { temporarilyNotSupport } from '../../utils'
10
+
11
+ /**
12
+ * 通过Scope数组获取已登录的对应帐号信息(依赖login行为)
13
+ * @param options
14
+ */
15
+ export const getUserInfo = temporarilyNotSupport('getUserInfo')
16
+ // export function getUserInfo (options) {
17
+ // const { success, fail, complete } = options
18
+ // const res: Record<string, any> = {}
19
+
20
+ // // const result = hmsJSAccount.HuaweiIdAuthManager.getAuthResultWithScopes([hmsJSAccount.PROFILE])
21
+ // const result = null
22
+
23
+ // if (result) {
24
+ // res.data = { userInfo: generateUserInfo(result) }
25
+ // isFunction(success) && success(res)
26
+ // } else {
27
+ // res.errorMsg = 'getUserInfo result data is null'
28
+ // isFunction(fail) && fail(res)
29
+ // }
30
+ // isFunction(complete) && complete(res)
31
+ // }
32
+
33
+ /**
34
+ * 获取用户信息
35
+ */
36
+ export const getUserProfile = temporarilyNotSupport('getUserProfile')
37
+ // export const getUserProfile = (_options) => {
38
+ // return new Promise((resolve, reject) => {
39
+ // const res: Record<string, any> = {}
40
+ // hmsJSAccount.HuaweiIdAuthManager.addAuthScopes([hmsJSAccount.PROFILE])
41
+ // .then(result => {
42
+ // if (result) {
43
+ // res.data = { userInfo: generateUserInfo(result) }
44
+ // callAsyncSuccess(resolve, res, options)
45
+ // } else {
46
+ // res.errorMsg = 'getUserProfile result data is null'
47
+ // callAsyncFail(reject, res, options)
48
+ // }
49
+ // })
50
+ // .catch(error => {
51
+ // callAsyncFail(reject, error, options)
52
+ // })
53
+ // })
54
+ // }
55
+
56
+ /**
57
+ * 提前向用户发起授权请求
58
+ */
59
+ export const authorize = temporarilyNotSupport('authorize')
60
+
61
+ /**
62
+ * 获取用户的当前设置
63
+ */
64
+ export const getSetting = temporarilyNotSupport('getSetting')
65
+
66
+ /**
67
+ * 调起客户端小程序设置界面
68
+ */
69
+ export const openSetting = temporarilyNotSupport('openSetting')
70
+
71
+ // function generateUserInfo (hmsAuthInfo) {
72
+ // const userInfo = {
73
+ // nickName: String,
74
+ // avatarUrl: String,
75
+ // gender: Number,
76
+ // country: String
77
+ // }
78
+ // if (hmsAuthInfo) {
79
+ // userInfo.nickName = hmsAuthInfo.displayName
80
+ // userInfo.avatarUrl = hmsAuthInfo.photoUriString
81
+ // userInfo.gender = hmsAuthInfo.gender
82
+ // userInfo.country = hmsAuthInfo.country
83
+ // }
84
+ // return userInfo
85
+ // }