@tarojs/plugin-platform-harmony-ets 3.7.0-alpha.27 → 4.0.0-beta.0

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 (176) hide show
  1. package/dist/apis/apis.ts +6 -2
  2. package/dist/apis/base/crypto.ts +4 -0
  3. package/dist/apis/base/debug.ts +5 -0
  4. package/dist/apis/base/index.ts +9 -1
  5. package/dist/apis/base/performance.ts +8 -0
  6. package/dist/apis/base/system.ts +1 -1
  7. package/dist/apis/base/update.ts +5 -0
  8. package/dist/apis/base/weapp/app-event.ts +75 -0
  9. package/dist/apis/base/weapp/life-cycle.ts +21 -0
  10. package/dist/apis/canvas/index.ts +18 -0
  11. package/dist/apis/data-analysis/index.ts +6 -0
  12. package/dist/apis/device/accelerometer.ts +2 -1
  13. package/dist/apis/device/accessibility.ts +4 -0
  14. package/dist/apis/device/battery.ts +2 -2
  15. package/dist/apis/device/bluetooth-ble.ts +19 -0
  16. package/dist/apis/device/bluetooth-peripheral.ts +6 -0
  17. package/dist/apis/device/bluetooth.ts +16 -0
  18. package/dist/apis/device/calendar.ts +5 -0
  19. package/dist/apis/device/clipboard.ts +1 -1
  20. package/dist/apis/device/compass.ts +21 -0
  21. package/dist/apis/device/contact.ts +5 -0
  22. package/dist/apis/device/crypto.ts +4 -0
  23. package/dist/apis/device/gyroscope.ts +7 -0
  24. package/dist/apis/device/iBeacon.ts +10 -0
  25. package/dist/apis/device/index.ts +15 -0
  26. package/dist/apis/device/keyboard.ts +2 -1
  27. package/dist/apis/device/motion.ts +6 -0
  28. package/dist/apis/device/network.ts +26 -9
  29. package/dist/apis/device/nfc.ts +10 -0
  30. package/dist/apis/device/phone.ts +2 -1
  31. package/dist/apis/device/scan.ts +4 -0
  32. package/dist/apis/device/screen.ts +2 -1
  33. package/dist/apis/device/sms.ts +4 -0
  34. package/dist/apis/device/vibrate.ts +19 -11
  35. package/dist/apis/device/wifi.ts +15 -0
  36. package/dist/apis/ext/index.ts +5 -0
  37. package/dist/apis/files/index.ts +2 -1
  38. package/dist/apis/files/manager.ts +2 -1
  39. package/dist/apis/framework/index.ts +5 -6
  40. package/dist/apis/location/index.ts +61 -68
  41. package/dist/apis/media/EditorContext.ts +32 -0
  42. package/dist/apis/media/audio/index.ts +18 -0
  43. package/dist/apis/media/background-audio/index.ts +16 -0
  44. package/dist/apis/media/camera.ts +16 -0
  45. package/dist/apis/media/common.ts +2 -1
  46. package/dist/apis/media/{image.ts → image/index.ts} +3 -2
  47. package/dist/apis/media/index.ts +10 -0
  48. package/dist/apis/media/live.ts +5 -0
  49. package/dist/apis/media/map.ts +4 -0
  50. package/dist/apis/media/media-recorder.ts +4 -0
  51. package/dist/apis/media/recorder.ts +6 -0
  52. package/dist/apis/media/video/VideoContext.ts +19 -0
  53. package/dist/apis/media/{video.ts → video/index.ts} +12 -2
  54. package/dist/apis/media/video-decoder.ts +4 -0
  55. package/dist/apis/media/video-processing.ts +4 -0
  56. package/dist/apis/media/voip.ts +19 -0
  57. package/dist/apis/network/index.ts +3 -0
  58. package/dist/apis/network/mdns.ts +13 -0
  59. package/dist/apis/network/request.ts +2 -1
  60. package/dist/apis/network/tcp.ts +4 -0
  61. package/dist/apis/network/udp.ts +4 -0
  62. package/dist/apis/network/webSocket.ts +2 -6
  63. package/dist/apis/open-api/account.ts +4 -0
  64. package/dist/apis/open-api/address.ts +4 -0
  65. package/dist/apis/open-api/authorize.ts +5 -0
  66. package/dist/apis/open-api/card.ts +5 -0
  67. package/dist/apis/open-api/channels-live.ts +11 -0
  68. package/dist/apis/open-api/customer-service.ts +4 -0
  69. package/dist/apis/open-api/device-voip.ts +5 -0
  70. package/dist/apis/open-api/facial.ts +7 -0
  71. package/dist/apis/open-api/favorites.ts +5 -0
  72. package/dist/apis/open-api/group.ts +4 -0
  73. package/dist/apis/open-api/index.ts +20 -6
  74. package/dist/apis/open-api/invoice.ts +5 -0
  75. package/dist/apis/open-api/license-plate.ts +4 -0
  76. package/dist/apis/open-api/login.ts +6 -0
  77. package/dist/apis/open-api/my-miniprogram.ts +4 -0
  78. package/dist/apis/open-api/privacy.ts +7 -0
  79. package/dist/apis/open-api/red-package.ts +4 -0
  80. package/dist/apis/open-api/settings.ts +5 -0
  81. package/dist/apis/open-api/soter.ts +6 -0
  82. package/dist/apis/open-api/subscribe-message.ts +6 -0
  83. package/dist/apis/open-api/{user-info/index.ts → user-info.ts} +1 -16
  84. package/dist/apis/open-api/werun.ts +5 -0
  85. package/dist/apis/payment/index.ts +6 -0
  86. package/dist/apis/route/index.ts +4 -28
  87. package/dist/apis/share/index.ts +33 -0
  88. package/dist/apis/storage/background-fetch.ts +7 -0
  89. package/dist/apis/storage/cache-manager.ts +4 -0
  90. package/dist/apis/storage/index.ts +20 -18
  91. package/dist/apis/ui/{animation.ts → animation/animation.ts} +2 -2
  92. package/dist/apis/ui/animation/index.ts +7 -0
  93. package/dist/apis/ui/background.ts +2 -18
  94. package/dist/apis/ui/custom-component.ts +8 -0
  95. package/dist/apis/ui/fonts.ts +4 -0
  96. package/dist/apis/ui/index.ts +8 -10
  97. package/dist/apis/ui/interaction/index.ts +3 -0
  98. package/dist/apis/ui/menu.ts +4 -0
  99. package/dist/apis/ui/navigation-bar/index.ts +60 -21
  100. package/dist/apis/ui/pull-down-refresh.ts +1 -1
  101. package/dist/apis/{page → ui/scroll}/index.ts +27 -22
  102. package/dist/apis/ui/sticky.ts +4 -0
  103. package/dist/apis/{tabbar/index.ts → ui/tab-bar.ts} +3 -5
  104. package/dist/apis/ui/window.ts +20 -0
  105. package/dist/apis/utils/handler.ts +4 -4
  106. package/dist/apis/worker/index.ts +4 -0
  107. package/dist/apis/wxml/IntersectionObserver.ts +12 -21
  108. package/dist/apis/wxml/index.ts +5 -2
  109. package/dist/apis/wxml/nodesRef.ts +2 -2
  110. package/dist/apis/wxml/selectorQuery.ts +3 -4
  111. package/dist/components-harmony-ets/button.ets +90 -64
  112. package/dist/components-harmony-ets/checkbox.ets +53 -98
  113. package/dist/components-harmony-ets/form.ets +16 -112
  114. package/dist/components-harmony-ets/icon.ets +59 -46
  115. package/dist/components-harmony-ets/image.ets +15 -40
  116. package/dist/components-harmony-ets/innerHtml.ets +6 -74
  117. package/dist/components-harmony-ets/input.ets +58 -128
  118. package/dist/components-harmony-ets/label.ets +43 -69
  119. package/dist/components-harmony-ets/picker.ets +114 -137
  120. package/dist/components-harmony-ets/radio.ets +55 -103
  121. package/dist/components-harmony-ets/richText.ets +17 -41
  122. package/dist/components-harmony-ets/scrollView.ets +69 -101
  123. package/dist/components-harmony-ets/slider.ets +35 -58
  124. package/dist/components-harmony-ets/swiper.ets +24 -135
  125. package/dist/components-harmony-ets/switch.ets +25 -55
  126. package/dist/components-harmony-ets/text.ets +42 -46
  127. package/dist/components-harmony-ets/textArea.ets +39 -107
  128. package/dist/components-harmony-ets/utils/constant/style.ets +9 -6
  129. package/dist/components-harmony-ets/utils/flexManager.ets +3 -88
  130. package/dist/components-harmony-ets/utils/helper.ets +2 -62
  131. package/dist/components-harmony-ets/utils/index.ts +1 -1
  132. package/dist/components-harmony-ets/utils/styles.ets +6 -9
  133. package/dist/components-harmony-ets/video.ets +63 -92
  134. package/dist/components-harmony-ets/view.ets +65 -40
  135. package/dist/index.js +33 -4
  136. package/dist/index.js.map +1 -1
  137. package/dist/runtime-ets/bom/getComputedStyle.ts +1 -1
  138. package/dist/runtime-ets/dom/bind.ts +80 -0
  139. package/dist/runtime-ets/dom/class-list.ts +2 -4
  140. package/dist/runtime-ets/dom/comment.ts +1 -2
  141. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +1 -1
  142. package/dist/runtime-ets/dom/dataSource.ts +64 -0
  143. package/dist/runtime-ets/dom/document.ts +14 -43
  144. package/dist/runtime-ets/dom/element/element.ts +162 -0
  145. package/dist/runtime-ets/dom/element/form.ts +397 -0
  146. package/dist/runtime-ets/dom/element/index.ts +89 -0
  147. package/dist/runtime-ets/dom/element/normal.ts +75 -0
  148. package/dist/runtime-ets/dom/element/scrollView.ts +14 -0
  149. package/dist/runtime-ets/dom/element/text.ts +17 -0
  150. package/dist/runtime-ets/dom/element/video.ts +49 -0
  151. package/dist/runtime-ets/dom/event.ts +24 -1
  152. package/dist/runtime-ets/dom/eventTarget.ts +2 -1
  153. package/dist/runtime-ets/dom/node.ts +74 -44
  154. package/dist/runtime-ets/dom/stylesheet/index.ts +136 -23
  155. package/dist/runtime-ets/dom/stylesheet/type.ts +4 -3
  156. package/dist/runtime-ets/dom/stylesheet/util.ts +71 -1
  157. package/dist/runtime-ets/index.ts +0 -1
  158. package/dist/runtime-ets/utils/bind.ts +3 -14
  159. package/dist/runtime-ets/utils/index.ts +12 -7
  160. package/dist/runtime-ets/utils/info.ts +22 -50
  161. package/dist/runtime-framework/react/app.ts +3 -6
  162. package/dist/runtime-framework/react/page.ts +2 -9
  163. package/dist/runtime-framework/solid/page.ts +0 -6
  164. package/dist/runtime-utils.js +1150 -339
  165. package/dist/runtime-utils.js.map +1 -1
  166. package/dist/runtime.js +1150 -339
  167. package/dist/runtime.js.map +1 -1
  168. package/package.json +8 -8
  169. package/types/runtime.d.ts +4 -0
  170. package/LICENSE +0 -160
  171. package/dist/components-harmony-ets/base.ets +0 -63
  172. package/dist/components-harmony-ets/element.ets +0 -223
  173. package/dist/components-harmony-ets/utils/constant/icon.ts +0 -19
  174. package/dist/runtime-ets/dom/element.ts +0 -457
  175. package/dist/runtime-ets/dom/text.ts +0 -19
  176. package/types/api.d.ts +0 -4
@@ -1,14 +1,11 @@
1
- import { bindInstanceToNode, Current, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, getPageScrollerOrNode, AREA_CHANGE_EVENT_NAME,
2
- TaroAny } from '@tarojs/runtime'
1
+ import { Current, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, getPageScrollerOrNode, AREA_CHANGE_EVENT_NAME } from '@tarojs/runtime'
3
2
 
4
- import { createNode } from './render'
5
- import TaroComponentWrapper from './base'
3
+ import { createLazyChildren } from './render'
6
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
7
5
  import { FlexManager } from './utils/FlexManager'
8
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds, bindAnimation } from './utils/helper'
6
+ import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
9
7
 
10
- import type { TaroLabelElement, TaroElement } from './element'
11
- import type { TaroStyleType } from '@tarojs/runtime'
8
+ import type { TaroStyleType, TaroLabelElement, TaroElement, TaroAny, TaroRadioElement, TaroCheckboxElement } from '@tarojs/runtime'
12
9
 
13
10
  @Extend(Flex)
14
11
  function attrs (style: TaroStyleType) {
@@ -26,6 +23,7 @@ function attrs (style: TaroStyleType) {
26
23
  .backgroundColor(style.backgroundColor)
27
24
  .backgroundImage(style.backgroundImage, style.backgroundRepeat)
28
25
  .backgroundImageSize(style.backgroundImageSize)
26
+ .backgroundImagePosition(style.backgroundImagePosition)
29
27
  .rotate(style.rotate)
30
28
  .scale(style.scale)
31
29
  .translate(style.translate)
@@ -40,72 +38,48 @@ function attrs (style: TaroStyleType) {
40
38
  .clip(style.clip)
41
39
  }
42
40
 
43
- @Component
44
- export default struct TaroLabel {
45
- nodeInfoMap: TaroAny = {}
41
+ function handleTargetChange (id: string) {
42
+ const taro: TaroAny = Current.taro
43
+ const page: TaroAny = taro.getCurrentInstance().page
44
+ const currentPageNode: TaroElement = getPageScrollerOrNode(page.node, page)
45
+ const node: TaroElement | null = currentPageNode.getElementById(id)
46
46
 
47
- @Styles visibleChangeEvent () {
48
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
49
- }
50
-
51
- @ObjectLink node: TaroLabelElement
52
-
53
- aboutToAppear () {
54
- initComponentNodeInfo(this, this.node)
55
- bindInstanceToNode(this.node, this)
56
- // 绑定动画
57
- bindAnimation(this.node)
58
- }
59
-
60
- @Styles defaultEvent () {
61
- .onClick((e: ClickEvent) => {
62
- const firstChild = this.node.childNodes[0] as TaroElement | null
63
- const id: string = this.node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
64
- this.handleTargetChange(id)
65
- eventHandler(e, 'click', this.node)
66
- })
67
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
68
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
69
- const eventResult: TaroAny = res.eventResult
70
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
71
- }))
72
- }
47
+ if (!node) return
73
48
 
74
- handleTargetChange (id: string) {
75
- const taro: TaroAny = Current.taro
76
- const page: TaroAny = taro.getCurrentInstance().page
77
- const currentPageNode: TaroElement = getPageScrollerOrNode(page.node, page)
78
- const node: TaroElement | null = currentPageNode.getElementById(id)
79
-
80
- if (!node || !node._instance) return
81
-
82
- if (['BUTTON', 'CHECKBOX', 'RADIO', 'SWITCH', 'INPUT'].includes(node.tagName)) {
83
- const instance: TaroAny = node._instance
84
- switch (node.tagName) {
85
- case 'RADIO':
86
- if (!instance.checked) {
87
- instance.checked = !instance.checked
88
- }
89
- break
90
- case 'CHECKBOX':
91
- instance.checked = !instance.checked
92
- break
93
- default:
94
- focusControl.requestFocus(id)
95
- }
49
+ if (['BUTTON', 'CHECKBOX', 'RADIO', 'SWITCH', 'INPUT'].includes(node.tagName)) {
50
+ switch (node.tagName) {
51
+ case 'RADIO':
52
+ const radioNode: TaroRadioElement = node as TaroRadioElement
53
+ if (!radioNode.checked) {
54
+ radioNode.checked = !radioNode.checked
55
+ }
56
+ break
57
+ case 'CHECKBOX':
58
+ const checkBoxNode: TaroCheckboxElement = node as TaroCheckboxElement
59
+ checkBoxNode.checked = !checkBoxNode.checked
60
+ break
61
+ default:
62
+ focusControl.requestFocus(id)
96
63
  }
97
64
  }
65
+ }
98
66
 
99
- build() {
100
- TaroComponentWrapper({ node: this.node }) {
101
- Flex(FlexManager.flexOptions(this.node)) {
102
- ForEach(this.node.childNodes, (item: TaroElement) => {
103
- createNode(item)
104
- }, (item: TaroElement) => item._nid)
105
- }
106
- .attrs(getNormalAttributes(this.node))
107
- .defaultEvent()
108
- .visibleChangeEvent()
109
- }
67
+ @Builder
68
+ export default function TaroLabel (node: TaroLabelElement) {
69
+ Flex(FlexManager.flexOptions(node)) {
70
+ createLazyChildren(node)
110
71
  }
72
+ .attrs(getNormalAttributes(node))
73
+ .onClick((e: ClickEvent) => {
74
+ const firstChild: TaroElement | null = node.childNodes[0] as TaroElement | null
75
+ const id: string = node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
76
+
77
+ handleTargetChange(id)
78
+ eventHandler(e, 'click', node)
79
+ })
80
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
81
+ .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
82
+ node._nodeInfo.areaInfo = res[1]
83
+ }))
84
+ .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
111
85
  }
@@ -1,17 +1,11 @@
1
- import { bindInstanceToNode, AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, getPageScrollerOrNode,
2
- TaroAny,
3
- TaroEvent
4
- } from '@tarojs/runtime'
5
- import { createNode } from './render'
6
- import TaroComponentWrapper from './base'
1
+ import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, TaroPickerElement, createTaroEvent } from '@tarojs/runtime'
2
+ import { createLazyChildren } from './render'
7
3
  import { getSingleSelector, getMultiSelector } from './utils'
8
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
9
5
  import { FlexManager } from './utils/FlexManager'
10
- import { createTaroEvent } from './utils/events'
11
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds, bindAnimation } from './utils/helper'
6
+ import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
12
7
 
13
- import type { TaroPickerElement, TaroElement } from './element'
14
- import type { TaroStyleType } from '@tarojs/runtime'
8
+ import type { TaroAny, TaroStyleType, TaroEvent } from '@tarojs/runtime'
15
9
 
16
10
  import { PickerDateProps, PickerMultiSelectorProps, PickerSelectorProps, PickerTimeProps } from './types'
17
11
 
@@ -31,6 +25,7 @@ function textPickerAttrs (style: TaroStyleType) {
31
25
  .backgroundColor(style.backgroundColor || '#fff')
32
26
  .backgroundImage(style.backgroundImage, style.backgroundRepeat)
33
27
  .backgroundImageSize(style.backgroundImageSize)
28
+ .backgroundImagePosition(style.backgroundImagePosition)
34
29
  .rotate(style.rotate)
35
30
  .scale(style.scale)
36
31
  .translate(style.translate)
@@ -61,6 +56,7 @@ function datePickerAttrs (style: TaroStyleType) {
61
56
  .backgroundColor(style.backgroundColor || '#fff')
62
57
  .backgroundImage(style.backgroundImage, style.backgroundRepeat)
63
58
  .backgroundImageSize(style.backgroundImageSize)
59
+ .backgroundImagePosition(style.backgroundImagePosition)
64
60
  .rotate(style.rotate)
65
61
  .scale(style.scale)
66
62
  .translate(style.translate)
@@ -84,10 +80,7 @@ interface TimeRange {
84
80
 
85
81
  @CustomDialog
86
82
  export struct PickerView {
87
-
88
- @ObjectLink node: TaroPickerElement
89
-
90
- @Link select: string | number
83
+ node: TaroPickerElement | null = null
91
84
 
92
85
  controller?: CustomDialogController
93
86
 
@@ -96,7 +89,7 @@ export struct PickerView {
96
89
  showSelector: number[] = []
97
90
 
98
91
  getDateOptions (): DatePickerOptions {
99
- const _attrs = this.node._attrs as PickerDateProps
92
+ const _attrs = this.node?._attrs as PickerDateProps
100
93
  return {
101
94
  start: new Date(_attrs.start || ''),
102
95
  end: new Date(_attrs.end || ''),
@@ -105,9 +98,9 @@ export struct PickerView {
105
98
  }
106
99
 
107
100
  getTextOptions (): TextPickerOptions {
108
- let mode: string = this.node._attrs.mode || 'selector'
101
+ let mode: string = this.node?._attrs.mode || 'selector'
109
102
  if (!mode) {
110
- const _attrs = this.node._attrs as PickerSelectorProps
103
+ const _attrs = this.node?._attrs as PickerSelectorProps
111
104
  const range = _attrs.range
112
105
  if (range && range.length && range[0] instanceof Array) {
113
106
  mode = 'multiSelector'
@@ -116,7 +109,7 @@ export struct PickerView {
116
109
  }
117
110
  switch (mode) {
118
111
  case 'time': {
119
- const _attrs = this.node._attrs as PickerTimeProps
112
+ const _attrs = this.node?._attrs as PickerTimeProps
120
113
  let timeRange: TimeRange = {
121
114
  startHH: 0,
122
115
  startMM: 0,
@@ -143,30 +136,27 @@ export struct PickerView {
143
136
  }
144
137
  }
145
138
  case 'multiSelector': {
146
- const _attrs = this.node._attrs as PickerMultiSelectorProps
147
- const value = _attrs.value as number[]
139
+ const _attrs = this.node?._attrs as PickerMultiSelectorProps
148
140
  let showRange = _attrs.range as string[][]
149
- this.showSelector = value
150
- showRange = getMultiSelector(this, _attrs.range, _attrs.rangeKey, value)
151
- let selects: string | number | string[] | number[] = this.select
152
- if (typeof selects === 'string') {
153
- selects = selects.split(',').map(i => Number(i))
154
- }
141
+ const selected: number[] = this.node?.value
142
+ this.showSelector = selected
143
+ showRange = getMultiSelector(this, _attrs.range, _attrs.rangeKey, selected)
144
+
155
145
  return {
146
+ selected,
156
147
  range: showRange,
157
- selected: selects || value
158
148
  }
159
149
  }
160
150
  default: {
161
- const _attrs = this.node._attrs as PickerSelectorProps
151
+ const _attrs = this.node?._attrs as PickerSelectorProps
162
152
  const range = _attrs.range
163
153
  let showRange = _attrs.range as string[]
164
154
  if (_attrs.rangeKey && typeof range[0] === 'object') {
165
- showRange = getSingleSelector(this, range, _attrs.rangeKey)
155
+ showRange = getSingleSelector(range, _attrs.rangeKey)
166
156
  }
167
157
  return {
168
158
  range: showRange,
169
- selected: (this.select as number) || _attrs.value
159
+ selected: this.node?.value
170
160
  }
171
161
  }
172
162
  }
@@ -179,7 +169,7 @@ export struct PickerView {
179
169
  }
180
170
 
181
171
  getText = () => {
182
- if (this.node._attrs.mode === 'selector') {
172
+ if (this.node?._attrs.mode === 'selector') {
183
173
  const _attrs = this.node._attrs as PickerSelectorProps
184
174
  return [_attrs.textProps?.okText || '确认', _attrs.textProps?.cancelText || '取消']
185
175
  } else {
@@ -190,83 +180,89 @@ export struct PickerView {
190
180
  @Builder
191
181
  showDialog() {
192
182
  Column() {
193
- Flex({
194
- direction: FlexDirection.Row,
195
- justifyContent: FlexAlign.SpaceBetween,
196
- alignItems: ItemAlign.Center
197
- }) {
198
- Text(this.getText()[1]).fontSize(15).padding({top: 20, bottom: 40}).fontColor('#888').onClick(() => {
199
- this.emitEvent('cancel')
200
- this.controller?.close()
201
- })
202
- Text(this.getText()[0]).fontSize(15).padding({top: 20, bottom: 40}).fontColor('#1aad19').onClick(() => {
203
- this.emitEvent('change', { value: this.select})
204
- this.controller?.close()
205
- })
206
- }
207
- .width('100%')
208
- .backgroundColor('#fff')
209
- .padding({
210
- left: 20,
211
- right: 20
212
- })
213
- if (this.node._attrs.mode === 'selector') {
214
- TextPicker(this.getTextOptions())
215
- .selectedTextStyle({
216
- color: '#000'
183
+ if (this.node) {
184
+ Flex({
185
+ direction: FlexDirection.Row,
186
+ justifyContent: FlexAlign.SpaceBetween,
187
+ alignItems: ItemAlign.Center
188
+ }) {
189
+ Text(this.getText()[1]).fontSize(15).padding({top: 20, bottom: 40}).fontColor('#888').onClick(() => {
190
+ this.emitEvent('cancel')
191
+ this.controller?.close()
217
192
  })
218
- .canLoop(false)
219
- .textPickerAttrs(getNormalAttributes(this.node))
220
- .onChange((value, index) => {
221
- this.select = index as number
193
+ Text(this.getText()[0]).fontSize(15).padding({top: 20, bottom: 40}).fontColor('#1aad19').onClick(() => {
194
+ this.emitEvent('change', { value: this.node?.value})
195
+ this.controller?.close()
222
196
  })
223
- } else if (this.node._attrs.mode === 'multiSelector') {
224
- TextPicker(this.getTextOptions())
225
- .selectedTextStyle({
226
- color: '#000'
227
- })
228
- .canLoop(false)
229
- .textPickerAttrs(getNormalAttributes(this.node))
230
- .onChange((value, index) => {
231
- if (index instanceof Array) {
232
- this.select = index.join(',')
233
- // 计算几列发生了变化
234
- const originIndexs: number[] = this.multiColumnIndex || this.showSelector
235
- this.multiColumnIndex = index
236
- let changeValue: number | undefined
237
- const changeIndex = index.findIndex((item, i) => {
238
- const originIndex = originIndexs[i]
239
- if (originIndex != item) {
240
- changeValue = item
241
- return true
197
+ }
198
+ .width('100%')
199
+ .backgroundColor('#fff')
200
+ .padding({
201
+ left: 20,
202
+ right: 20
203
+ })
204
+ if (this.node._attrs.mode === 'selector') {
205
+ TextPicker(this.getTextOptions())
206
+ .selectedTextStyle({
207
+ color: '#000'
208
+ })
209
+ .canLoop(false)
210
+ .textPickerAttrs(getNormalAttributes(this.node))
211
+ .onChange((_, index) => {
212
+ this.node?.updateFormWidgetValue(index)
213
+ })
214
+ } else if (this.node?._attrs.mode === 'multiSelector') {
215
+ TextPicker(this.getTextOptions())
216
+ .selectedTextStyle({
217
+ color: '#000'
218
+ })
219
+ .canLoop(false)
220
+ .textPickerAttrs(getNormalAttributes(this.node))
221
+ .onChange((_, index) => {
222
+ if (index instanceof Array) {
223
+ this.node?.updateFormWidgetValue(index)
224
+ // 计算几列发生了变化
225
+ const originIndexs: number[] = this.multiColumnIndex || this.showSelector
226
+ this.multiColumnIndex = index
227
+ let changeValue: number | undefined
228
+ const changeIndex = index.findIndex((item, i) => {
229
+ const originIndex = originIndexs[i]
230
+ if (originIndex != item) {
231
+ changeValue = item
232
+ return true
233
+ }
234
+ return false
235
+ })
236
+ if (changeIndex < 0) {
237
+ return
242
238
  }
243
- return false
244
- })
245
- if (changeIndex < 0) {
246
- return
239
+ this.emitEvent('columnChange', { column: changeIndex, value: changeValue })
247
240
  }
248
- this.emitEvent('columnChange', { column: changeIndex, value: changeValue })
249
- }
250
- })
251
- } else if (this.node._attrs.mode === 'date') {
252
- DatePicker(this.getDateOptions())
253
- .selectedTextStyle({
254
- color: '#000'
255
- })
256
- .datePickerAttrs(getNormalAttributes(this.node))
257
- .onChange(value => {
258
- this.select = `${value.year}-${value.month}-${value.day}`
259
- })
260
- } else if (this.node._attrs.mode === 'time') {
261
- TextPicker(this.getTextOptions())
262
- .selectedTextStyle({
263
- color: '#000'
264
- })
265
- .canLoop(false)
266
- .textPickerAttrs(getNormalAttributes(this.node))
267
- .onChange((value) => {
268
- this.select = `${('00'+value[0]).slice(-2)}:${('00'+value[1]).slice(-2)}}`
269
- })
241
+ })
242
+ } else if (this.node._attrs.mode === 'date') {
243
+ DatePicker(this.getDateOptions())
244
+ .selectedTextStyle({
245
+ color: '#000'
246
+ })
247
+ .datePickerAttrs(getNormalAttributes(this.node))
248
+ .onDateChange(value => {
249
+ const data = value.toLocaleDateString().split('/')
250
+ const day = data[1]
251
+ const month = data[0]
252
+ const year = data[2]
253
+ this.node?.updateFormWidgetValue(`${year}-${month}-${day}`)
254
+ })
255
+ } else if (this.node._attrs.mode === 'time') {
256
+ TextPicker(this.getTextOptions())
257
+ .selectedTextStyle({
258
+ color: '#000'
259
+ })
260
+ .canLoop(false)
261
+ .textPickerAttrs(getNormalAttributes(this.node))
262
+ .onChange((value) => {
263
+ this.node?.updateFormWidgetValue(`${('00'+value[0]).slice(-2)}:${('00'+value[1]).slice(-2)}`)
264
+ })
265
+ }
270
266
  }
271
267
  }
272
268
  }
@@ -276,41 +272,25 @@ export struct PickerView {
276
272
  }
277
273
  }
278
274
 
279
-
280
-
281
275
  @Component
282
276
  export default struct TaroPicker {
283
- nodeInfoMap: TaroAny = {}
284
-
285
- @State select: string = ''
286
-
287
- @ObjectLink node: TaroPickerElement
277
+ node: TaroPickerElement | null = null
288
278
 
289
279
  aboutToAppear () {
290
- initComponentNodeInfo(this, this.node)
291
- bindInstanceToNode(this.node, this)
292
- // 绑定动画
293
- bindAnimation(this.node)
294
-
295
- this.select = this.node._attrs.value as TaroAny
296
-
297
- this.node.addEventListener('click', this.handleClick)
280
+ this.node?.addEventListener('click', this.handleClick)
298
281
  }
299
282
 
300
283
  dialogController: CustomDialogController | null = null
301
284
 
302
285
  aboutToDisappear() {
303
286
  this.dialogController = null // 将dialogController置空
287
+ this.node?.removeEventListener('click', this.handleClick)
304
288
  }
305
289
 
306
-
307
290
  handleClick = () => {
308
- if (!this.dialogController) {
291
+ if (!this.dialogController && this.node) {
309
292
  this.dialogController = new CustomDialogController({
310
- builder: PickerView({
311
- node: this.node,
312
- select: this.select
313
- }),
293
+ builder: PickerView({ node: this.node }),
314
294
  customStyle: true,
315
295
  cornerRadius: '0vp',
316
296
  autoCancel: true,
@@ -324,7 +304,7 @@ export default struct TaroPicker {
324
304
  }
325
305
  })
326
306
  }
327
- this.dialogController.open()
307
+ this.dialogController?.open()
328
308
  }
329
309
 
330
310
  @Styles defaultEvent () {
@@ -332,9 +312,10 @@ export default struct TaroPicker {
332
312
  eventHandler(e, 'click', this.node)
333
313
  })
334
314
  .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
335
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
336
- const eventResult: TaroAny = res.eventResult
337
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
315
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
316
+ if (this.node) {
317
+ this.node._nodeInfo.areaInfo = res[1]
318
+ }
338
319
  }))
339
320
  }
340
321
 
@@ -343,20 +324,16 @@ export default struct TaroPicker {
343
324
  }
344
325
 
345
326
  build() {
346
- TaroComponentWrapper({ node: this.node }) {
327
+ if (this.node) {
347
328
  Flex(FlexManager.flexOptions(this.node)) {
348
- ForEach(this.node.childNodes, (item: TaroElement) => {
349
- createNode(item)
350
- }, (item: TaroElement) => item._nid)
329
+ createLazyChildren(this.node)
351
330
  }
352
- .defaultEvent()
353
- .visibleChangeEvent()
331
+ .defaultEvent()
332
+ .visibleChangeEvent()
354
333
  }
355
334
  }
356
335
  }
357
336
 
358
-
359
-
360
337
  function generateNumberArray(x: number, y: number) {
361
338
  // 创建一个空数组来存储结果
362
339
  let result: string[] = []