@tdesign/uniapp 0.7.2 → 0.8.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 (199) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +32 -2
  3. package/dist/action-sheet/README.md +1 -1
  4. package/dist/action-sheet/action-sheet.vue +158 -150
  5. package/dist/action-sheet/props.ts +2 -2
  6. package/dist/action-sheet/type.ts +1 -1
  7. package/dist/avatar/avatar.vue +89 -87
  8. package/dist/avatar-group/avatar-group.vue +69 -67
  9. package/dist/back-top/back-top.vue +60 -58
  10. package/dist/badge/badge.vue +69 -59
  11. package/dist/button/button.vue +121 -116
  12. package/dist/button/props.ts +2 -2
  13. package/dist/button/type.ts +1 -1
  14. package/dist/calendar/calendar-header.vue +4 -4
  15. package/dist/calendar/calendar.vue +308 -297
  16. package/dist/calendar/template.vue +1 -1
  17. package/dist/cascader/README.en-US.md +2 -1
  18. package/dist/cascader/README.md +2 -1
  19. package/dist/cascader/cascader.vue +340 -328
  20. package/dist/cascader/props.ts +6 -1
  21. package/dist/cascader/type.ts +6 -0
  22. package/dist/cell/cell.vue +127 -121
  23. package/dist/cell-group/cell-group.vue +32 -30
  24. package/dist/check-tag/check-tag.vue +73 -71
  25. package/dist/checkbox/README.en-US.md +6 -6
  26. package/dist/checkbox/README.md +5 -5
  27. package/dist/checkbox/checkbox.vue +127 -127
  28. package/dist/checkbox/props.ts +6 -6
  29. package/dist/checkbox/type.ts +6 -4
  30. package/dist/checkbox-group/checkbox-group.vue +175 -173
  31. package/dist/checkbox-group/props.ts +6 -6
  32. package/dist/checkbox-group/type.ts +6 -4
  33. package/dist/col/col.vue +26 -24
  34. package/dist/collapse/collapse.vue +83 -81
  35. package/dist/collapse-panel/collapse-panel.vue +121 -119
  36. package/dist/collapse-panel/props.ts +4 -4
  37. package/dist/collapse-panel/type.ts +2 -2
  38. package/dist/color-picker/README.md +1 -1
  39. package/dist/color-picker/color-picker.vue +324 -322
  40. package/dist/color-picker/props.ts +2 -2
  41. package/dist/color-picker/template.vue +14 -10
  42. package/dist/common/common.ts +1 -0
  43. package/dist/common/style/theme/index.css +57 -61
  44. package/dist/common/utils.js +7 -2
  45. package/dist/common/validator.js +172 -0
  46. package/dist/config-provider/README.en-US.md +184 -0
  47. package/dist/config-provider/README.md +234 -0
  48. package/dist/config-provider/config-provider.vue +105 -0
  49. package/dist/config-provider/config-store.js +70 -0
  50. package/dist/config-provider/props.ts +16 -0
  51. package/dist/config-provider/reactive-state.js +39 -0
  52. package/dist/config-provider/type.ts +401 -0
  53. package/dist/config-provider/use-config.js +29 -0
  54. package/dist/config-provider/utils.js +29 -0
  55. package/dist/count-down/count-down.vue +98 -97
  56. package/dist/date-time-picker/date-time-picker.vue +410 -395
  57. package/dist/demo/demo.vue +1 -0
  58. package/dist/dialog/dialog.vue +176 -173
  59. package/dist/divider/divider.vue +38 -36
  60. package/dist/draggable/draggable.vue +60 -58
  61. package/dist/drawer/README.md +1 -1
  62. package/dist/drawer/drawer.vue +48 -46
  63. package/dist/dropdown-item/dropdown-item.vue +209 -207
  64. package/dist/dropdown-item/props.ts +4 -4
  65. package/dist/dropdown-item/type.ts +3 -3
  66. package/dist/dropdown-menu/dropdown-menu.vue +93 -99
  67. package/dist/empty/empty.vue +43 -42
  68. package/dist/fab/fab.vue +88 -86
  69. package/dist/footer/footer.vue +36 -34
  70. package/dist/form/README.en-US.md +17 -24
  71. package/dist/form/README.md +18 -25
  72. package/dist/form/form.css +1 -166
  73. package/dist/form/form.vue +251 -236
  74. package/dist/form/props.ts +2 -21
  75. package/dist/form/type.ts +7 -70
  76. package/dist/form-item/README.en-US.md +4 -5
  77. package/dist/form-item/README.md +4 -5
  78. package/dist/form-item/form-item.css +69 -96
  79. package/dist/form-item/form-item.vue +315 -336
  80. package/dist/form-item/form-model.ts +125 -173
  81. package/dist/form-item/props.ts +4 -17
  82. package/dist/form-item/type.ts +43 -1
  83. package/dist/grid/grid.vue +53 -51
  84. package/dist/grid-item/grid-item.vue +121 -119
  85. package/dist/guide/README.md +1 -1
  86. package/dist/guide/guide.vue +281 -277
  87. package/dist/icon/README.md +2 -4
  88. package/dist/icon/icon.vue +78 -76
  89. package/dist/image/README.md +1 -1
  90. package/dist/image/image.vue +103 -101
  91. package/dist/image-viewer/image-viewer.vue +160 -158
  92. package/dist/image-viewer/props.ts +2 -2
  93. package/dist/image-viewer/type.ts +1 -1
  94. package/dist/index.js +3 -0
  95. package/dist/indexes/indexes.vue +264 -267
  96. package/dist/indexes-anchor/indexes-anchor.vue +41 -41
  97. package/dist/input/input.vue +192 -192
  98. package/dist/input/props.ts +6 -6
  99. package/dist/input/type.ts +3 -3
  100. package/dist/link/link.vue +73 -71
  101. package/dist/loading/loading.vue +59 -59
  102. package/dist/locale/ar_KW.ts +157 -0
  103. package/dist/locale/en_US.ts +146 -0
  104. package/dist/locale/it_IT.ts +145 -0
  105. package/dist/locale/ja_JP.ts +132 -0
  106. package/dist/locale/ko_KR.ts +132 -0
  107. package/dist/locale/ru_RU.ts +157 -0
  108. package/dist/locale/zh_CN.ts +133 -0
  109. package/dist/locale/zh_TW.ts +132 -0
  110. package/dist/message/message.vue +181 -173
  111. package/dist/message/props.ts +2 -2
  112. package/dist/message/type.ts +1 -1
  113. package/dist/message-item/message-item.vue +192 -184
  114. package/dist/mixins/using-config.js +39 -0
  115. package/dist/navbar/navbar.vue +201 -199
  116. package/dist/notice-bar/notice-bar.vue +175 -171
  117. package/dist/notice-bar/props.ts +2 -2
  118. package/dist/notice-bar/type.ts +1 -1
  119. package/dist/npm/dayjs/esm/locale/ar.js +81 -0
  120. package/dist/npm/dayjs/esm/locale/it.js +39 -0
  121. package/dist/overlay/overlay.vue +50 -48
  122. package/dist/picker/picker.vue +168 -161
  123. package/dist/picker-item/picker-item.vue +269 -269
  124. package/dist/popover/README.md +1 -1
  125. package/dist/popover/popover.vue +262 -261
  126. package/dist/popover/props.ts +4 -4
  127. package/dist/popover/type.ts +2 -2
  128. package/dist/popup/popup.vue +46 -45
  129. package/dist/progress/README.md +1 -1
  130. package/dist/progress/progress.vue +76 -76
  131. package/dist/pull-down-refresh/props.ts +2 -2
  132. package/dist/pull-down-refresh/pull-down-refresh.vue +240 -234
  133. package/dist/pull-down-refresh/type.ts +1 -1
  134. package/dist/qrcode/README.md +1 -1
  135. package/dist/qrcode/components/qrcode-canvas/qrcode-canvas.vue +340 -338
  136. package/dist/qrcode/components/qrcode-status/qrcode-status.vue +6 -6
  137. package/dist/qrcode/qrcode.vue +93 -87
  138. package/dist/radio/props.ts +6 -6
  139. package/dist/radio/radio.vue +118 -120
  140. package/dist/radio/type.ts +3 -3
  141. package/dist/radio-group/props.ts +4 -4
  142. package/dist/radio-group/radio-group.vue +136 -134
  143. package/dist/radio-group/type.ts +4 -4
  144. package/dist/rate/computed.js +2 -2
  145. package/dist/rate/props.ts +4 -4
  146. package/dist/rate/rate.vue +155 -154
  147. package/dist/rate/type.ts +2 -2
  148. package/dist/result/result.vue +41 -39
  149. package/dist/row/row.vue +38 -36
  150. package/dist/scroll-view/scroll-view.vue +24 -22
  151. package/dist/search/props.ts +2 -2
  152. package/dist/search/search.vue +127 -125
  153. package/dist/search/type.ts +1 -1
  154. package/dist/side-bar/side-bar.vue +57 -55
  155. package/dist/side-bar-item/side-bar-item.vue +86 -86
  156. package/dist/skeleton/skeleton.vue +126 -124
  157. package/dist/slider/README.md +1 -1
  158. package/dist/slider/props.ts +2 -2
  159. package/dist/slider/slider.vue +457 -457
  160. package/dist/slider/type.ts +1 -1
  161. package/dist/step-item/step-item.vue +77 -75
  162. package/dist/stepper/props.ts +2 -2
  163. package/dist/stepper/stepper.vue +168 -149
  164. package/dist/stepper/type.ts +1 -1
  165. package/dist/steps/props.ts +2 -2
  166. package/dist/steps/steps.vue +83 -81
  167. package/dist/steps/type.ts +1 -1
  168. package/dist/sticky/sticky.vue +104 -102
  169. package/dist/swipe-cell/swipe-cell.vue +91 -89
  170. package/dist/swiper/README.md +1 -1
  171. package/dist/swiper/swiper.vue +91 -89
  172. package/dist/swiper-nav/swiper-nav.vue +38 -36
  173. package/dist/switch/props.ts +2 -2
  174. package/dist/switch/switch.vue +62 -62
  175. package/dist/switch/type.ts +1 -1
  176. package/dist/tab-bar/tab-bar.vue +88 -86
  177. package/dist/tab-bar-item/tab-bar-item.vue +85 -82
  178. package/dist/tab-panel/tab-panel.vue +66 -64
  179. package/dist/tabs/tabs.vue +294 -287
  180. package/dist/tag/tag.vue +79 -77
  181. package/dist/textarea/props.ts +6 -6
  182. package/dist/textarea/textarea.vue +127 -126
  183. package/dist/textarea/type.ts +3 -3
  184. package/dist/toast/toast.vue +107 -106
  185. package/dist/transition/transition.vue +30 -28
  186. package/dist/tree-select/tree-select.vue +151 -151
  187. package/dist/types/config-provider.d.ts +7 -0
  188. package/dist/types/index.d.ts +2 -0
  189. package/dist/types/popover.d.ts +7 -0
  190. package/dist/upload/README.en-US.md +13 -14
  191. package/dist/upload/README.md +11 -12
  192. package/dist/upload/props.ts +2 -4
  193. package/dist/upload/type.ts +12 -11
  194. package/dist/upload/upload.css +1 -1
  195. package/dist/upload/upload.vue +672 -512
  196. package/dist/watermark/watermark.vue +151 -149
  197. package/global.d.ts +2 -0
  198. package/package.json +16 -2
  199. package/dist/form/form-item-props.ts +0 -56
@@ -13,7 +13,7 @@
13
13
  :z-index="11000"
14
14
  :duration="0"
15
15
  background-color="rgba(0,0,0,0)"
16
- @click="onOverlayTap($event, { tagId: 'popover-overlay' })"
16
+ @click="(e) => onOverlayTap(e, { tagId: 'popover-overlay' })"
17
17
  />
18
18
  <view
19
19
  v-if="realVisible"
@@ -51,299 +51,300 @@ delete props.visible;
51
51
  const name = `${prefix}-popover`;
52
52
 
53
53
 
54
- export default uniComponent({
55
- name,
56
- options: {
57
- styleIsolation: 'shared',
58
- },
59
-
60
- controlledProps: [
61
- {
62
- key: 'visible',
63
- event: 'visible-change',
64
- },
65
- ],
66
-
67
- externalClasses: [
68
- `${prefix}-class`,
69
- `${prefix}-class-content`,
70
- `${prefix}-class-trigger`,
71
- ],
72
-
73
- mixins: [
74
- transitionMixins,
75
- pageScrollMixin(),
76
- ],
77
-
54
+ export default {
78
55
  components: {
79
56
  TOverlay,
80
57
  },
58
+ ...uniComponent({
59
+ name,
60
+ options: {
61
+ styleIsolation: 'shared',
62
+ },
81
63
 
82
- props: {
83
- ...props,
84
- },
64
+ controlledProps: [
65
+ {
66
+ key: 'visible',
67
+ event: 'visible-change',
68
+ },
69
+ ],
70
+
71
+ externalClasses: [
72
+ `${prefix}-class`,
73
+ `${prefix}-class-content`,
74
+ `${prefix}-class-trigger`,
75
+ ],
76
+
77
+ mixins: [
78
+ transitionMixins,
79
+ pageScrollMixin(),
80
+ ],
81
+
82
+ props: {
83
+ ...props,
84
+ },
85
85
 
86
- emits: [
87
- 'visible-change',
88
- 'leaved',
89
- 'update:visible',
90
- ],
86
+ emits: [
87
+ 'visible-change',
88
+ 'leaved',
89
+ 'update:visible',
90
+ ],
91
91
 
92
- data() {
93
- return {
94
- prefix,
95
- classPrefix: name,
92
+ data() {
93
+ return {
94
+ prefix,
95
+ classPrefix: name,
96
96
 
97
- dataVisible: coalesce(this.visible, this.defaultVisible),
97
+ dataVisible: coalesce(this.visible, this.defaultVisible),
98
98
 
99
- innerPlacement: 'top',
100
- contentStyle: '',
101
- arrowStyle: '',
102
- };
103
- },
104
- watch: {
105
- visible(val) {
106
- if (val === undefined || val === null) return;
107
- this.updateVisible(val);
108
- },
109
- 'placement'(v) {
110
- if (v) {
111
- nextTick().then(() => {
112
- this.computePosition();
113
- });
114
- }
99
+ innerPlacement: 'top',
100
+ contentStyle: '',
101
+ arrowStyle: '',
102
+ };
115
103
  },
116
- realVisible(v) {
117
- if (v) {
118
- nextTick().then(() => {
119
- this.computePosition();
104
+ watch: {
105
+ visible(val) {
106
+ if (val === undefined || val === null) return;
107
+ this.updateVisible(val);
108
+ },
109
+ 'placement'(v) {
110
+ if (v) {
120
111
  nextTick().then(() => {
121
112
  this.computePosition();
122
113
  });
123
- });
124
- }
125
- },
126
- },
127
- mounted() {
128
-
129
- },
130
- methods: {
131
- onScroll() {
132
- if (this.realVisible) {
133
- debounce(() => this.computePosition(), 100);
134
- }
135
- },
136
-
137
- updateVisible(visible) {
138
- if (visible === this.dataVisible) return;
139
- this.dataVisible = visible;
140
- nextTick().then(() => {
141
- this._trigger('visible-change', { visible });
142
- this.$emit('update:visible', visible);
143
- });
144
- },
145
-
146
- onOverlayTap() {
147
- if (this.closeOnClickOutside) {
148
- this.updateVisible(false);
149
- }
114
+ }
115
+ },
116
+ realVisible(v) {
117
+ if (v) {
118
+ nextTick().then(() => {
119
+ this.computePosition();
120
+ nextTick().then(() => {
121
+ this.computePosition();
122
+ });
123
+ });
124
+ }
125
+ },
150
126
  },
127
+ mounted() {
151
128
 
152
- getToward(placement) {
153
- const horizontal = ['top', 'bottom'];
154
- const vertical = ['left', 'right'];
155
- const isHorizontal = horizontal.find(item => placement.includes(item));
156
- const isVertical = vertical.find(item => placement.includes(item));
157
- const isBase = [...horizontal, ...vertical].find(item => item === placement);
158
- const isEnd = placement.includes('end');
159
- return {
160
- isHorizontal,
161
- isVertical,
162
- isBase,
163
- isEnd,
164
- };
165
129
  },
130
+ methods: {
131
+ onScroll() {
132
+ if (this.realVisible) {
133
+ debounce(() => this.computePosition(), 100);
134
+ }
135
+ },
166
136
 
167
- calcArrowStyle(placement, contentDom, popoverDom) {
168
- const { isHorizontal, isVertical, isBase, isEnd } = this.getToward(placement);
137
+ updateVisible(visible) {
138
+ if (visible === this.dataVisible) return;
139
+ this.dataVisible = visible;
140
+ nextTick().then(() => {
141
+ this._trigger('visible-change', { visible });
142
+ this.$emit('update:visible', visible);
143
+ });
144
+ },
169
145
 
170
- if (isBase) {
171
- return '';
172
- }
146
+ onOverlayTap() {
147
+ if (this.closeOnClickOutside) {
148
+ this.updateVisible(false);
149
+ }
150
+ },
151
+
152
+ getToward(placement) {
153
+ const horizontal = ['top', 'bottom'];
154
+ const vertical = ['left', 'right'];
155
+ const isHorizontal = horizontal.find(item => placement.includes(item));
156
+ const isVertical = vertical.find(item => placement.includes(item));
157
+ const isBase = [...horizontal, ...vertical].find(item => item === placement);
158
+ const isEnd = placement.includes('end');
159
+ return {
160
+ isHorizontal,
161
+ isVertical,
162
+ isBase,
163
+ isEnd,
164
+ };
165
+ },
166
+
167
+ calcArrowStyle(placement, contentDom, popoverDom) {
168
+ const { isHorizontal, isVertical, isBase, isEnd } = this.getToward(placement);
169
+
170
+ if (isBase) {
171
+ return '';
172
+ }
173
173
 
174
- const { width, left } = contentDom;
175
- const { width: popperWidth, height: popperHeight } = popoverDom;
176
- const { windowWidth } = getWindowInfo();
174
+ const { width, left } = contentDom;
175
+ const { width: popperWidth, height: popperHeight } = popoverDom;
176
+ const { windowWidth } = getWindowInfo();
177
177
 
178
- if (isHorizontal) {
179
- const padding = isEnd ? Math.min(width + left, popperWidth) : Math.min(windowWidth - left, popperWidth);
180
- if (isEnd) {
181
- return `left:${padding - 28}px;`;
178
+ if (isHorizontal) {
179
+ const padding = isEnd ? Math.min(width + left, popperWidth) : Math.min(windowWidth - left, popperWidth);
180
+ if (isEnd) {
181
+ return `left:${padding - 28}px;`;
182
+ }
183
+ return `right:${padding - 28}px;`;
184
+ }
185
+ if (isVertical) {
186
+ const offset = popperHeight - 28;
187
+ if (isEnd) {
188
+ return `top:${offset}px;`;
189
+ }
190
+ return `bottom:${offset}px;top:unset;`;
182
191
  }
183
- return `right:${padding - 28}px;`;
184
- }
185
- if (isVertical) {
186
- const offset = popperHeight - 28;
187
- if (isEnd) {
188
- return `top:${offset}px;`;
192
+ return '';
193
+ },
194
+
195
+ calcContentPosition(placement, triggerRect, contentRect) {
196
+ let top = 0;
197
+ let left = 0;
198
+
199
+ const isTopBase = placement.startsWith('top');
200
+ const isBottomBase = placement.startsWith('bottom');
201
+ const isLeftBase = placement.startsWith('left');
202
+ const isRightBase = placement.startsWith('right');
203
+
204
+ if (isTopBase) {
205
+ top = triggerRect.top - contentRect.height;
206
+ } else if (isBottomBase) {
207
+ top = triggerRect.top + triggerRect.height;
208
+ } else if (isLeftBase) {
209
+ left = triggerRect.left - contentRect.width;
210
+ } else if (isRightBase) {
211
+ left = triggerRect.left + triggerRect.width;
212
+ } else {
213
+ top = triggerRect.top - contentRect.height;
189
214
  }
190
- return `bottom:${offset}px;top:unset;`;
191
- }
192
- return '';
193
- },
194
215
 
195
- calcContentPosition(placement, triggerRect, contentRect) {
196
- let top = 0;
197
- let left = 0;
198
-
199
- const isTopBase = placement.startsWith('top');
200
- const isBottomBase = placement.startsWith('bottom');
201
- const isLeftBase = placement.startsWith('left');
202
- const isRightBase = placement.startsWith('right');
203
-
204
- if (isTopBase) {
205
- top = triggerRect.top - contentRect.height;
206
- } else if (isBottomBase) {
207
- top = triggerRect.top + triggerRect.height;
208
- } else if (isLeftBase) {
209
- left = triggerRect.left - contentRect.width;
210
- } else if (isRightBase) {
211
- left = triggerRect.left + triggerRect.width;
212
- } else {
213
- top = triggerRect.top - contentRect.height;
214
- }
215
-
216
- const isStart = placement.includes('start');
217
- const isEnd = placement.includes('end');
218
-
219
- let align;
220
- if (isStart) align = 'start';
221
- else if (isEnd) align = 'end';
222
- else align = 'center';
223
-
224
- if (isTopBase || isBottomBase) {
225
- left = this.alignCrossAxis(triggerRect.left, triggerRect.width, contentRect.width, align);
226
- }
227
-
228
- if (isLeftBase || isRightBase) {
229
- top = this.alignCrossAxis(triggerRect.top, triggerRect.height, contentRect.height, align);
230
- }
231
-
232
- return { top, left };
233
- },
216
+ const isStart = placement.includes('start');
217
+ const isEnd = placement.includes('end');
234
218
 
235
- alignCrossAxis(start, triggerSize, contentSize, align) {
236
- if (align === 'start') return start;
237
- if (align === 'end') return start + triggerSize - contentSize;
238
- return start + triggerSize / 2 - contentSize / 2;
239
- },
219
+ let align;
220
+ if (isStart) align = 'start';
221
+ else if (isEnd) align = 'end';
222
+ else align = 'center';
240
223
 
241
- calcPlacement(isFixed, placement, triggerRect, contentRect) {
242
- return new Promise((resolve) => {
243
- const owner = uni.createSelectorQuery().in(this);
244
- owner.select(`.${name}-wrapper--fixed`).boundingClientRect();
245
- owner.exec((b) => {
246
- const [triggerChildRect] = b;
247
- if (triggerChildRect && isFixed) {
248
- triggerRect = triggerChildRect;
249
- }
224
+ if (isTopBase || isBottomBase) {
225
+ left = this.alignCrossAxis(triggerRect.left, triggerRect.width, contentRect.width, align);
226
+ }
250
227
 
251
- const {
252
- isHorizontal,
253
- isVertical,
254
- } = this.getToward(placement);
255
- const {
256
- width: contentWidth,
257
- height: contentHeight,
258
- } = contentRect;
259
- const {
260
- left: triggerLeft,
261
- top: triggerTop,
262
- right: triggerRight,
263
- bottom: triggerBottom,
264
- } = triggerRect;
265
- let canPlace = true;
266
- const {
267
- windowWidth,
268
- windowHeight,
269
- } = getWindowInfo();
270
- let finalPlacement = placement;
271
- if (isHorizontal) {
272
- if (placement.startsWith('top')) {
273
- canPlace = triggerTop - contentHeight >= 0;
274
- } else if (placement.startsWith('bottom')) {
275
- canPlace = triggerBottom + contentHeight <= windowHeight;
276
- }
277
- } else if (isVertical) {
278
- if (placement.startsWith('left')) {
279
- canPlace = triggerLeft - contentWidth >= 0;
280
- } else if (placement.startsWith('right')) {
281
- canPlace = triggerRight + contentWidth <= windowWidth;
228
+ if (isLeftBase || isRightBase) {
229
+ top = this.alignCrossAxis(triggerRect.top, triggerRect.height, contentRect.height, align);
230
+ }
231
+
232
+ return { top, left };
233
+ },
234
+
235
+ alignCrossAxis(start, triggerSize, contentSize, align) {
236
+ if (align === 'start') return start;
237
+ if (align === 'end') return start + triggerSize - contentSize;
238
+ return start + triggerSize / 2 - contentSize / 2;
239
+ },
240
+
241
+ calcPlacement(isFixed, placement, triggerRect, contentRect) {
242
+ return new Promise((resolve) => {
243
+ const owner = uni.createSelectorQuery().in(this);
244
+ owner.select(`.${name}-wrapper--fixed`).boundingClientRect();
245
+ owner.exec((b) => {
246
+ const [triggerChildRect] = b;
247
+ if (triggerChildRect && isFixed) {
248
+ triggerRect = triggerChildRect;
282
249
  }
283
- }
284
- if (!canPlace) {
285
- // 反向
250
+
251
+ const {
252
+ isHorizontal,
253
+ isVertical,
254
+ } = this.getToward(placement);
255
+ const {
256
+ width: contentWidth,
257
+ height: contentHeight,
258
+ } = contentRect;
259
+ const {
260
+ left: triggerLeft,
261
+ top: triggerTop,
262
+ right: triggerRight,
263
+ bottom: triggerBottom,
264
+ } = triggerRect;
265
+ let canPlace = true;
266
+ const {
267
+ windowWidth,
268
+ windowHeight,
269
+ } = getWindowInfo();
270
+ let finalPlacement = placement;
286
271
  if (isHorizontal) {
287
- finalPlacement = placement.startsWith('top')
288
- ? placement.replace('top', 'bottom')
289
- : placement.replace('bottom', 'top');
272
+ if (placement.startsWith('top')) {
273
+ canPlace = triggerTop - contentHeight >= 0;
274
+ } else if (placement.startsWith('bottom')) {
275
+ canPlace = triggerBottom + contentHeight <= windowHeight;
276
+ }
290
277
  } else if (isVertical) {
291
- finalPlacement = placement.startsWith('left')
292
- ? placement.replace('left', 'right')
293
- : placement.replace('right', 'left');
278
+ if (placement.startsWith('left')) {
279
+ canPlace = triggerLeft - contentWidth >= 0;
280
+ } else if (placement.startsWith('right')) {
281
+ canPlace = triggerRight + contentWidth <= windowWidth;
282
+ }
294
283
  }
295
- }
296
- const basePos = this.calcContentPosition(finalPlacement, triggerRect, contentRect);
284
+ if (!canPlace) {
285
+ // 反向
286
+ if (isHorizontal) {
287
+ finalPlacement = placement.startsWith('top')
288
+ ? placement.replace('top', 'bottom')
289
+ : placement.replace('bottom', 'top');
290
+ } else if (isVertical) {
291
+ finalPlacement = placement.startsWith('left')
292
+ ? placement.replace('left', 'right')
293
+ : placement.replace('right', 'left');
294
+ }
295
+ }
296
+ const basePos = this.calcContentPosition(finalPlacement, triggerRect, contentRect);
297
297
 
298
- resolve({
299
- placement: finalPlacement,
300
- ...basePos,
298
+ resolve({
299
+ placement: finalPlacement,
300
+ ...basePos,
301
+ });
301
302
  });
302
303
  });
303
- });
304
- },
305
- async computePosition() {
306
- const { placement } = this;
307
- const innerPlacement = placement
308
- .replace(/-(left|top)$/, '-start')
309
- .replace(/-(right|bottom)$/, '-end');
310
- // 此处必须要设置,否则计算的位置会出错
311
- this.innerPlacement = innerPlacement;
312
-
313
- const query = uni.createSelectorQuery().in(this);
314
-
315
- query.select(`#${name}-wrapper`).boundingClientRect();
316
- query.select(`#${name}-content`).boundingClientRect();
317
- query.selectViewport().scrollOffset();
318
- query.exec(async (res) => {
319
- const [triggerRect, contentRect, viewportOffset] = res;
320
- if (!triggerRect || !contentRect) return;
321
- const isFixed = this.fixed;
322
- // 最终放置位置
323
- const { placement: finalPlacement, ...basePos } = await this.calcPlacement(
324
- isFixed,
325
- innerPlacement,
326
- triggerRect,
327
- contentRect,
328
- );
329
- // TODO 优化:滚动时可能导致箭头闪烁
330
- this.innerPlacement = finalPlacement;
331
-
332
- const {
333
- scrollTop = 0,
334
- scrollLeft = 0,
335
- } = viewportOffset || {};
336
- const top = isFixed ? basePos.top : basePos.top + scrollTop;
337
- const left = isFixed ? basePos.left : basePos.left + scrollLeft;
338
- const style = `top:${Math.max(top, 0)}px;left:${Math.max(left, 0)}px;`;
339
- const arrowStyle = this.calcArrowStyle(innerPlacement, triggerRect, contentRect);
340
-
341
- this.contentStyle = style;
342
- this.arrowStyle = arrowStyle;
343
- });
304
+ },
305
+ async computePosition() {
306
+ const { placement } = this;
307
+ const innerPlacement = placement
308
+ .replace(/-(left|top)$/, '-start')
309
+ .replace(/-(right|bottom)$/, '-end');
310
+ // 此处必须要设置,否则计算的位置会出错
311
+ this.innerPlacement = innerPlacement;
312
+
313
+ const query = uni.createSelectorQuery().in(this);
314
+
315
+ query.select(`#${name}-wrapper`).boundingClientRect();
316
+ query.select(`#${name}-content`).boundingClientRect();
317
+ query.selectViewport().scrollOffset();
318
+ query.exec(async (res) => {
319
+ const [triggerRect, contentRect, viewportOffset] = res;
320
+ if (!triggerRect || !contentRect) return;
321
+ const isFixed = this.fixed;
322
+ // 最终放置位置
323
+ const { placement: finalPlacement, ...basePos } = await this.calcPlacement(
324
+ isFixed,
325
+ innerPlacement,
326
+ triggerRect,
327
+ contentRect,
328
+ );
329
+ // TODO 优化:滚动时可能导致箭头闪烁
330
+ this.innerPlacement = finalPlacement;
331
+
332
+ const {
333
+ scrollTop = 0,
334
+ scrollLeft = 0,
335
+ } = viewportOffset || {};
336
+ const top = isFixed ? basePos.top : basePos.top + scrollTop;
337
+ const left = isFixed ? basePos.left : basePos.left + scrollLeft;
338
+ const style = `top:${Math.max(top, 0)}px;left:${Math.max(left, 0)}px;`;
339
+ const arrowStyle = this.calcArrowStyle(innerPlacement, triggerRect, contentRect);
340
+
341
+ this.contentStyle = style;
342
+ this.arrowStyle = arrowStyle;
343
+ });
344
+ },
344
345
  },
345
- },
346
- });
346
+ }),
347
+ };
347
348
 
348
349
 
349
350
  </script>
@@ -42,13 +42,13 @@ export default {
42
42
  },
43
43
  /** 是否显示气泡确认框 */
44
44
  visible: {
45
- type: Boolean,
46
- default: undefined,
45
+ type: [Boolean, null],
46
+ default: null as TdPopoverProps['visible'],
47
47
  },
48
48
  /** 是否显示气泡确认框,非受控属性 */
49
49
  defaultVisible: {
50
- type: Boolean,
51
- default: undefined,
50
+ type: [Boolean, null],
51
+ default: null as TdPopoverProps['defaultVisible'],
52
52
  },
53
53
  /** 确认框显示或隐藏时触发 */
54
54
  onVisibleChange: {
@@ -49,11 +49,11 @@ export interface TdPopoverProps {
49
49
  /**
50
50
  * 是否显示气泡确认框
51
51
  */
52
- visible?: boolean;
52
+ visible?: boolean | null;
53
53
  /**
54
54
  * 是否显示气泡确认框,非受控属性
55
55
  */
56
- defaultVisible?: boolean;
56
+ defaultVisible?: boolean | null;
57
57
  /**
58
58
  * 确认框显示或隐藏时触发
59
59
  */