@tdesign/uniapp 0.7.3 → 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 (197) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +1 -1
  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/checkbox.vue +127 -127
  26. package/dist/checkbox/props.ts +6 -6
  27. package/dist/checkbox/type.ts +3 -3
  28. package/dist/checkbox-group/checkbox-group.vue +175 -173
  29. package/dist/checkbox-group/props.ts +6 -6
  30. package/dist/checkbox-group/type.ts +4 -4
  31. package/dist/col/col.vue +26 -24
  32. package/dist/collapse/collapse.vue +83 -81
  33. package/dist/collapse-panel/collapse-panel.vue +121 -119
  34. package/dist/collapse-panel/props.ts +4 -4
  35. package/dist/collapse-panel/type.ts +2 -2
  36. package/dist/color-picker/README.md +1 -1
  37. package/dist/color-picker/color-picker.vue +324 -322
  38. package/dist/color-picker/props.ts +2 -2
  39. package/dist/color-picker/template.vue +14 -10
  40. package/dist/common/common.ts +1 -0
  41. package/dist/common/style/theme/index.css +5 -5
  42. package/dist/common/utils.js +7 -2
  43. package/dist/common/validator.js +172 -0
  44. package/dist/config-provider/README.en-US.md +184 -0
  45. package/dist/config-provider/README.md +234 -0
  46. package/dist/config-provider/config-provider.vue +105 -0
  47. package/dist/config-provider/config-store.js +70 -0
  48. package/dist/config-provider/props.ts +16 -0
  49. package/dist/config-provider/reactive-state.js +39 -0
  50. package/dist/config-provider/type.ts +401 -0
  51. package/dist/config-provider/use-config.js +29 -0
  52. package/dist/config-provider/utils.js +29 -0
  53. package/dist/count-down/count-down.vue +98 -97
  54. package/dist/date-time-picker/date-time-picker.vue +410 -395
  55. package/dist/demo/demo.vue +1 -0
  56. package/dist/dialog/dialog.vue +175 -173
  57. package/dist/divider/divider.vue +38 -36
  58. package/dist/draggable/draggable.vue +60 -58
  59. package/dist/drawer/README.md +1 -1
  60. package/dist/drawer/drawer.vue +48 -46
  61. package/dist/dropdown-item/dropdown-item.vue +209 -207
  62. package/dist/dropdown-item/props.ts +4 -4
  63. package/dist/dropdown-item/type.ts +3 -3
  64. package/dist/dropdown-menu/dropdown-menu.vue +93 -99
  65. package/dist/empty/empty.vue +43 -42
  66. package/dist/fab/fab.vue +88 -86
  67. package/dist/footer/footer.vue +36 -34
  68. package/dist/form/README.en-US.md +17 -24
  69. package/dist/form/README.md +18 -25
  70. package/dist/form/form.css +1 -166
  71. package/dist/form/form.vue +251 -236
  72. package/dist/form/props.ts +2 -21
  73. package/dist/form/type.ts +7 -70
  74. package/dist/form-item/README.en-US.md +4 -5
  75. package/dist/form-item/README.md +4 -5
  76. package/dist/form-item/form-item.css +69 -96
  77. package/dist/form-item/form-item.vue +315 -336
  78. package/dist/form-item/form-model.ts +125 -173
  79. package/dist/form-item/props.ts +4 -17
  80. package/dist/form-item/type.ts +43 -1
  81. package/dist/grid/grid.vue +53 -51
  82. package/dist/grid-item/grid-item.vue +121 -119
  83. package/dist/guide/README.md +1 -1
  84. package/dist/guide/guide.vue +281 -277
  85. package/dist/icon/README.md +2 -4
  86. package/dist/icon/icon.vue +78 -76
  87. package/dist/image/README.md +1 -1
  88. package/dist/image/image.vue +103 -101
  89. package/dist/image-viewer/image-viewer.vue +160 -158
  90. package/dist/image-viewer/props.ts +2 -2
  91. package/dist/image-viewer/type.ts +1 -1
  92. package/dist/index.js +3 -0
  93. package/dist/indexes/indexes.vue +264 -267
  94. package/dist/indexes-anchor/indexes-anchor.vue +41 -41
  95. package/dist/input/input.vue +192 -192
  96. package/dist/input/props.ts +6 -6
  97. package/dist/input/type.ts +3 -3
  98. package/dist/link/link.vue +73 -71
  99. package/dist/loading/loading.vue +59 -59
  100. package/dist/locale/ar_KW.ts +157 -0
  101. package/dist/locale/en_US.ts +146 -0
  102. package/dist/locale/it_IT.ts +145 -0
  103. package/dist/locale/ja_JP.ts +132 -0
  104. package/dist/locale/ko_KR.ts +132 -0
  105. package/dist/locale/ru_RU.ts +157 -0
  106. package/dist/locale/zh_CN.ts +133 -0
  107. package/dist/locale/zh_TW.ts +132 -0
  108. package/dist/message/message.vue +181 -173
  109. package/dist/message/props.ts +2 -2
  110. package/dist/message/type.ts +1 -1
  111. package/dist/message-item/message-item.vue +192 -184
  112. package/dist/mixins/using-config.js +39 -0
  113. package/dist/navbar/navbar.vue +201 -199
  114. package/dist/notice-bar/notice-bar.vue +175 -171
  115. package/dist/notice-bar/props.ts +2 -2
  116. package/dist/notice-bar/type.ts +1 -1
  117. package/dist/npm/dayjs/esm/locale/ar.js +81 -0
  118. package/dist/npm/dayjs/esm/locale/it.js +39 -0
  119. package/dist/overlay/overlay.vue +50 -48
  120. package/dist/picker/picker.vue +168 -161
  121. package/dist/picker-item/picker-item.vue +269 -269
  122. package/dist/popover/README.md +1 -1
  123. package/dist/popover/popover.vue +262 -261
  124. package/dist/popover/props.ts +4 -4
  125. package/dist/popover/type.ts +2 -2
  126. package/dist/popup/popup.vue +46 -45
  127. package/dist/progress/README.md +1 -1
  128. package/dist/progress/progress.vue +76 -76
  129. package/dist/pull-down-refresh/props.ts +2 -2
  130. package/dist/pull-down-refresh/pull-down-refresh.vue +240 -234
  131. package/dist/pull-down-refresh/type.ts +1 -1
  132. package/dist/qrcode/README.md +1 -1
  133. package/dist/qrcode/components/qrcode-canvas/qrcode-canvas.vue +340 -338
  134. package/dist/qrcode/components/qrcode-status/qrcode-status.vue +6 -6
  135. package/dist/qrcode/qrcode.vue +93 -87
  136. package/dist/radio/props.ts +6 -6
  137. package/dist/radio/radio.vue +118 -120
  138. package/dist/radio/type.ts +3 -3
  139. package/dist/radio-group/props.ts +4 -4
  140. package/dist/radio-group/radio-group.vue +136 -134
  141. package/dist/radio-group/type.ts +4 -4
  142. package/dist/rate/computed.js +2 -2
  143. package/dist/rate/props.ts +4 -4
  144. package/dist/rate/rate.vue +155 -154
  145. package/dist/rate/type.ts +2 -2
  146. package/dist/result/result.vue +41 -39
  147. package/dist/row/row.vue +38 -36
  148. package/dist/scroll-view/scroll-view.vue +24 -22
  149. package/dist/search/props.ts +2 -2
  150. package/dist/search/search.vue +127 -125
  151. package/dist/search/type.ts +1 -1
  152. package/dist/side-bar/side-bar.vue +57 -55
  153. package/dist/side-bar-item/side-bar-item.vue +86 -86
  154. package/dist/skeleton/skeleton.vue +126 -124
  155. package/dist/slider/README.md +1 -1
  156. package/dist/slider/props.ts +2 -2
  157. package/dist/slider/slider.vue +457 -457
  158. package/dist/slider/type.ts +1 -1
  159. package/dist/step-item/step-item.vue +77 -75
  160. package/dist/stepper/props.ts +2 -2
  161. package/dist/stepper/stepper.vue +168 -149
  162. package/dist/stepper/type.ts +1 -1
  163. package/dist/steps/props.ts +2 -2
  164. package/dist/steps/steps.vue +83 -81
  165. package/dist/steps/type.ts +1 -1
  166. package/dist/sticky/sticky.vue +104 -102
  167. package/dist/swipe-cell/swipe-cell.vue +91 -89
  168. package/dist/swiper/README.md +1 -1
  169. package/dist/swiper/swiper.vue +91 -89
  170. package/dist/swiper-nav/swiper-nav.vue +38 -36
  171. package/dist/switch/props.ts +2 -2
  172. package/dist/switch/switch.vue +62 -62
  173. package/dist/switch/type.ts +1 -1
  174. package/dist/tab-bar/tab-bar.vue +88 -86
  175. package/dist/tab-bar-item/tab-bar-item.vue +85 -82
  176. package/dist/tab-panel/tab-panel.vue +66 -64
  177. package/dist/tabs/tabs.vue +294 -287
  178. package/dist/tag/tag.vue +79 -77
  179. package/dist/textarea/props.ts +6 -6
  180. package/dist/textarea/textarea.vue +127 -126
  181. package/dist/textarea/type.ts +3 -3
  182. package/dist/toast/toast.vue +107 -106
  183. package/dist/transition/transition.vue +30 -28
  184. package/dist/tree-select/tree-select.vue +151 -151
  185. package/dist/types/config-provider.d.ts +7 -0
  186. package/dist/types/index.d.ts +2 -0
  187. package/dist/types/popover.d.ts +7 -0
  188. package/dist/upload/README.en-US.md +13 -14
  189. package/dist/upload/README.md +11 -12
  190. package/dist/upload/props.ts +2 -4
  191. package/dist/upload/type.ts +12 -11
  192. package/dist/upload/upload.css +1 -1
  193. package/dist/upload/upload.vue +672 -512
  194. package/dist/watermark/watermark.vue +151 -149
  195. package/global.d.ts +2 -0
  196. package/package.json +15 -3
  197. package/dist/form/form-item-props.ts +0 -56
@@ -1,25 +1,29 @@
1
1
  <template>
2
2
  <view>
3
- <TPopup
3
+ <t-popup
4
4
  :class="tClass"
5
5
  :visible="dataVisible"
6
6
  placement="bottom"
7
+ :show-overlay="isShowOverlay(popupProps && popupProps.showOverlay, true)"
8
+ :using-custom-navbar="popupProps && popupProps.usingCustomNavbar"
9
+ :z-index="popupProps && popupProps.zIndex"
10
+ :overlay-props="popupProps && popupProps.overlayProps"
7
11
  @visible-change="onVisibleChange"
8
12
  >
9
13
  <view
10
- :style="tools._style([customStyle])"
11
- :class="name"
14
+ :style="'' + tools._style([customStyle])"
15
+ :class="classPrefix"
12
16
  >
13
- <view :class="name + '__title'">
17
+ <view :class="classPrefix + '__title'">
14
18
  <slot name="title" />
15
- {{ title }}
19
+ {{ title || globalConfig.title || '' }}
16
20
  </view>
17
21
  <view
18
- :class="name + '__close-btn'"
22
+ :class="classPrefix + '__close-btn'"
19
23
  @click="onClose"
20
24
  >
21
25
  <slot name="close-btn" />
22
- <TIcon
26
+ <t-icon
23
27
  v-if="closeBtn"
24
28
  size="48rpx"
25
29
  name="close"
@@ -28,88 +32,88 @@
28
32
 
29
33
  <slot name="header" />
30
34
 
31
- <view :class="name + '__content'">
35
+ <view :class="classPrefix + '__content'">
32
36
  <block v-if="steps && steps.length">
33
37
  <view
34
38
  v-if="theme == 'step'"
35
- :class="name + '__steps'"
39
+ :class="classPrefix + '__steps'"
36
40
  >
37
41
  <view
38
42
  v-for="(item, index) in steps"
39
43
  :key="index"
40
- :class="name + '__step'"
44
+ :class="classPrefix + '__step'"
41
45
  :data-index="index"
42
46
  @click="() => onStepClick(index)"
43
47
  >
44
48
  <view
45
49
  :class="
46
- name +
50
+ classPrefix +
47
51
  '__step-dot ' +
48
- name +
52
+ classPrefix +
49
53
  '__step-dot--' +
50
54
  (item !== placeholder ? 'active' : '') +
51
55
  ' ' +
52
- name +
56
+ classPrefix +
53
57
  '__step-dot--' +
54
58
  (index === steps.length - 1 ? 'last' : '')
55
59
  "
56
60
  />
57
61
 
58
- <view :class="name + '__step-label ' + name + '__step-label--' + (index === stepIndex ? 'active' : '')">
62
+ <view :class="classPrefix + '__step-label ' + classPrefix + '__step-label--' + (index === stepIndex ? 'active' : '')">
59
63
  {{ item }}
60
64
  </view>
61
65
 
62
- <TIcon
66
+ <t-icon
63
67
  name="chevron-right"
64
68
  size="44rpx"
65
- :t-class="name + '__step-arrow'"
69
+ :t-class="classPrefix + '__step-arrow'"
66
70
  :custom-style="stepArrowCustomStyle"
67
71
  style="margin-left: auto"
68
72
  />
69
73
  </view>
70
74
  </view>
71
75
 
72
- <TTabs
76
+ <t-tabs
73
77
  v-if="theme == 'tab'"
74
78
  ref="tabs"
75
79
  :value="stepIndex"
76
80
  :space-evenly="false"
77
81
  @change="({value}) => onTabChange(value)"
78
82
  >
79
- <TTabPanel
83
+ <t-tab-panel
80
84
  v-for="(item, index) in steps"
81
85
  :key="index"
82
86
  :ref="`tab-${index}`"
83
87
  :value="index"
84
88
  :label="item"
85
89
  />
86
- </TTabs>
90
+ </t-tabs>
87
91
  </block>
88
92
 
89
93
  <slot name="middle-content" />
90
94
 
91
95
  <view
92
96
  v-if="subTitles && subTitles[stepIndex]"
93
- :class="name + '__options-title'"
97
+ :class="classPrefix + '__options-title'"
94
98
  >
95
99
  {{ subTitles[stepIndex] }}
96
100
  </view>
97
101
 
98
102
  <view
99
- :class="name + '__options-container'"
100
- :style="'width: ' + (items.length + 1) + '00vw; transform: translateX(-' + stepIndex + '00vw)'"
103
+ :class="classPrefix + '__options-container'"
104
+ :style="'' + `width: ${items.length + 1 }00vw; transform: translateX(-${stepIndex}00vw)`"
101
105
  >
102
106
  <scroll-view
103
107
  v-for="(options, index) in items"
104
108
  :key="index"
105
- :class="name + '__options'"
109
+ :class="classPrefix + '__options'"
106
110
  scroll-y
107
111
  :scroll-top="scrollTopList[index]"
108
112
  type="list"
109
113
  :style="'height: ' + optionsHeight + 'px'"
110
114
  >
111
115
  <view :class="'cascader-radio-group-' + index">
112
- <TRadioGroup
116
+ <t-radio-group
113
117
  :value="selectedValue[index]"
114
118
  :keys="keys"
115
119
  :options="options"
@@ -117,21 +121,21 @@
117
121
  placement="right"
118
122
  icon="line"
119
123
  borderless
120
- @change="({ value }) => handleSelect($event, { level: index, value })"
124
+ @change="(e) => handleSelect(e, { level: index, value: e.value })"
121
125
  />
122
126
  </view>
123
127
  </scroll-view>
124
128
  </view>
125
129
  </view>
126
130
  </view>
127
- </TPopup>
131
+ </t-popup>
128
132
  </view>
129
133
  </template>
130
134
  <script>
131
135
  import TIcon from '../icon/icon';
132
136
  import TPopup from '../popup/popup';
133
137
  import TTabs from '../tabs/tabs';
134
- import TTabPanel from '../tab-panel/tab-panel';
138
+ import TTabPanel from '../tab-panel/tab-panel.vue';
135
139
  import TRadioGroup from '../radio-group/radio-group';
136
140
  import { uniComponent } from '../common/src/index';
137
141
  import { prefix } from '../common/config';
@@ -139,9 +143,11 @@ import props from './props';
139
143
  import { getRect, coalesce, nextTick } from '../common/utils';
140
144
 
141
145
  import tools from '../common/utils.wxs';
146
+ import usingConfig from '../mixins/using-config';
142
147
 
143
148
 
144
- const name = `${prefix}-cascader`;
149
+ const componentName = 'cascader';
150
+ const name = `${prefix}-${componentName}`;
145
151
 
146
152
  function parseOptions(options, keys) {
147
153
  const label = coalesce(keys?.label, 'label');
@@ -163,20 +169,7 @@ const defaultState = {
163
169
  stepsInitHeight: 0,
164
170
  };
165
171
 
166
- export default uniComponent({
167
- name,
168
- options: {
169
- styleIsolation: 'shared',
170
- },
171
- controlledProps: [
172
- {
173
- key: 'value',
174
- event: 'change',
175
- },
176
- ],
177
- externalClasses: [
178
- `${prefix}-class`,
179
- ],
172
+ export default {
180
173
  components: {
181
174
  TIcon,
182
175
  TPopup,
@@ -184,338 +177,357 @@ export default uniComponent({
184
177
  TTabPanel,
185
178
  TRadioGroup,
186
179
  },
187
- props: {
188
- ...props,
189
- },
190
- emits: [
191
- 'update:visible',
192
- ],
193
- data() {
194
- return {
195
- prefix,
196
- name,
197
- stepIndex: 0,
198
- selectedIndexes: [],
199
- selectedValue: [],
200
- scrollTopList: [],
201
- steps: [],
202
- optionsHeight: 0,
203
- tools,
204
-
205
- dataVisible: this.visible,
206
- dataValue: coalesce(this.value, this.defaultValue),
207
- items: [],
208
- };
209
- },
210
- computed: {
211
- stepArrowCustomStyle() {
212
- return tools._style({
213
- color: 'var(--td-cascader-step-arrow-color, var(--td-text-color-placeholder, var(--td-font-gray-3, rgba(0, 0, 0, .4))))',
214
- marginLeft: 'auto',
215
- });
180
+ ...uniComponent({
181
+ name,
182
+ mixins: [usingConfig({ componentName })],
183
+ options: {
184
+ styleIsolation: 'shared',
216
185
  },
217
- },
218
- watch: {
219
- visible: {
220
- handler(v) {
221
- this.dataVisible = v;
186
+ controlledProps: [
187
+ {
188
+ key: 'value',
189
+ event: 'change',
222
190
  },
223
- immediate: true,
191
+ ],
192
+ externalClasses: [
193
+ `${prefix}-class`,
194
+ ],
195
+ props: {
196
+ ...props,
224
197
  },
225
- dataVisible: {
226
- handler(v) {
227
- if (v) {
228
- nextTick().then(() => {
229
- const $tabs = this.$refs.tabs;
230
- $tabs?.setTrack();
231
- $tabs?.getTabHeight().then((res) => {
232
- this.state.tabsHeight = res.height;
233
- });
234
- });
235
-
236
- // 不能使用 this.$nextTick,在头条小程序下会报错
237
- nextTick().then(() => {
238
- this.initOptionsHeight(this.steps.length);
239
- this.updateScrollTop();
240
- this.initWithValue();
241
- });
242
- } else {
243
- this.state = { ...defaultState };
244
- }
198
+ emits: [
199
+ 'update:visible',
200
+ ],
201
+ data() {
202
+ return {
203
+ prefix,
204
+ classPrefix: name,
205
+ stepIndex: 0,
206
+ selectedIndexes: [],
207
+ selectedValue: [],
208
+ scrollTopList: [],
209
+ steps: [],
210
+ optionsHeight: 0,
211
+ tools,
212
+
213
+ dataVisible: this.visible,
214
+ dataValue: coalesce(this.value, this.defaultValue),
215
+ items: [],
216
+ };
217
+ },
218
+ computed: {
219
+ stepArrowCustomStyle() {
220
+ return tools._style({
221
+ color: 'var(--td-cascader-step-arrow-color, var(--td-text-color-placeholder, var(--td-font-gray-3, rgba(0, 0, 0, .4))))',
222
+ marginLeft: 'auto',
223
+ });
245
224
  },
246
- immediate: true,
247
225
  },
226
+ watch: {
227
+ visible: {
228
+ handler(v) {
229
+ this.dataVisible = v;
230
+ },
231
+ immediate: true,
232
+ },
233
+ dataVisible: {
234
+ handler(v) {
235
+ if (v) {
236
+ nextTick().then(() => {
237
+ const $tabs = this.$refs.tabs;
238
+ $tabs?.setTrack();
239
+ $tabs?.getTabHeight().then((res) => {
240
+ this.state.tabsHeight = res.height;
241
+ });
242
+ });
248
243
 
249
- value: {
250
- handler(v) {
251
- this.dataValue = v;
244
+ // 不能使用 this.$nextTick,在头条小程序下会报错
245
+ nextTick().then(() => {
246
+ this.initOptionsHeight(this.steps.length);
247
+ this.updateScrollTop();
248
+ this.initWithValue();
249
+ });
250
+ } else {
251
+ this.state = { ...defaultState };
252
+ }
253
+ },
254
+ immediate: true,
252
255
  },
253
- immediate: true,
254
- },
255
256
 
256
- dataValue: {
257
- handler() {
258
- this.initWithValue();
257
+ value: {
258
+ handler(v) {
259
+ this.dataValue = v;
260
+ },
261
+ immediate: true,
259
262
  },
260
- immediate: true,
261
- deep: true,
262
- },
263
263
 
264
- options: {
265
- handler() {
266
- const { selectedValue, steps, items } = this.genItems();
267
-
268
- this.steps = steps;
269
- this.items = items;
270
- this.selectedValue = selectedValue;
271
- this.stepIndex = items.length - 1;
272
- this.setTabParent();
264
+ dataValue: {
265
+ handler() {
266
+ this.initWithValue();
267
+ },
268
+ immediate: true,
269
+ deep: true,
273
270
  },
274
- immediate: true,
275
- deep: true,
276
- },
277
- selectedIndexes: {
278
- handler() {
279
- const { visible, theme } = this;
280
- const { selectedValue, steps, items } = this.genItems();
281
271
 
282
- this.steps = steps;
283
- this.setTabParent();
284
- this.selectedValue = selectedValue;
285
- this.stepIndex = items.length - 1;
272
+ options: {
273
+ handler() {
274
+ const { selectedValue, steps, items } = this.genItems();
286
275
 
287
- if (JSON.stringify(items) !== JSON.stringify(this.items)) {
276
+ this.steps = steps;
288
277
  this.items = items;
289
- }
278
+ this.selectedValue = selectedValue;
279
+ this.stepIndex = items.length - 1;
280
+ this.setTabParent();
281
+ },
282
+ immediate: true,
283
+ deep: true,
284
+ },
285
+ selectedIndexes: {
286
+ handler() {
287
+ const { visible, theme } = this;
288
+ const { selectedValue, steps, items } = this.genItems();
289
+
290
+ this.steps = steps;
291
+ this.setTabParent();
292
+ this.selectedValue = selectedValue;
293
+ this.stepIndex = items.length - 1;
294
+
295
+ if (JSON.stringify(items) !== JSON.stringify(this.items)) {
296
+ this.items = items;
297
+ }
290
298
 
291
299
 
292
- if (visible && theme === 'step') {
293
- this.updateOptionsHeight(steps.length);
294
- }
300
+ if (visible && theme === 'step') {
301
+ this.updateOptionsHeight(steps.length);
302
+ }
303
+ },
304
+ immediate: true,
305
+ deep: true,
295
306
  },
296
- immediate: true,
297
- deep: true,
298
- },
299
307
 
300
- stepIndex: {
301
- handler() {
302
- const { dataVisible: visible } = this;
308
+ stepIndex: {
309
+ handler() {
310
+ const { dataVisible: visible } = this;
303
311
 
304
- if (visible) {
305
- this.updateScrollTop();
306
- }
312
+ if (visible) {
313
+ this.updateScrollTop();
314
+ }
315
+ },
316
+ immediate: true,
317
+ deep: true,
307
318
  },
308
- immediate: true,
309
- deep: true,
310
319
  },
311
- },
312
- created() {
313
- this.state = {
314
- ...defaultState,
315
- };
316
- },
317
- mounted() {
320
+ created() {
321
+ this.state = {
322
+ ...defaultState,
323
+ };
324
+ },
325
+ mounted() {
318
326
 
319
- },
320
- methods: {
321
- setTabParent() {
327
+ },
328
+ methods: {
329
+ setTabParent() {
322
330
  // #ifdef MP-TOUTIAO
323
- nextTick().then(() => {
324
- const tabsRef = this.$refs.tabs;
325
- this.steps.forEach((tools, index) => {
326
- const tabRef = this.$refs[`tab-${index}`];
327
- tabRef?.[0]?.setParent(tabsRef);
331
+ nextTick().then(() => {
332
+ const tabsRef = this.$refs.tabs;
333
+ this.steps.forEach((tools, index) => {
334
+ const tabRef = this.$refs[`tab-${index}`];
335
+ tabRef?.[0]?.setParent(tabsRef);
336
+ });
328
337
  });
329
- });
330
338
  // #endif
331
- },
332
- updateOptionsHeight(steps) {
333
- const { contentHeight, stepsInitHeight, stepHeight, subTitlesHeight } = this.state;
334
- this.optionsHeight = contentHeight - stepsInitHeight - subTitlesHeight - (steps - 1) * stepHeight;
335
- },
336
-
337
- async initOptionsHeight(steps) {
338
- const { theme, subTitles } = this;
339
-
340
- const { height } = await getRect(this, `.${name}__content`);
341
- this.state.contentHeight = height;
339
+ },
340
+ updateOptionsHeight(steps) {
341
+ const { contentHeight, stepsInitHeight, stepHeight, subTitlesHeight } = this.state;
342
+ this.optionsHeight = contentHeight - stepsInitHeight - subTitlesHeight - (steps - 1) * stepHeight;
343
+ },
342
344
 
343
- if (theme === 'step') {
344
- await Promise.all([
345
- getRect(this, `.${name}__steps`),
346
- getRect(this, `.${name}__step`),
347
- ])
348
- .then(([stepsRect, stepRect]) => {
349
- this.state.stepsInitHeight = stepsRect.height - (steps - 1) * stepRect.height;
350
- this.state.stepHeight = stepRect.height;
351
- })
352
- .catch(() => {
353
- });
354
- }
345
+ async initOptionsHeight(steps) {
346
+ const { theme, subTitles, classPrefix } = this;
347
+
348
+ const { height } = await getRect(this, `.${classPrefix}__content`);
349
+ this.state.contentHeight = height;
350
+
351
+ if (theme === 'step') {
352
+ await Promise.all([
353
+ getRect(this, `.${classPrefix}__steps`),
354
+ getRect(this, `.${classPrefix}__step`),
355
+ ])
356
+ .then(([stepsRect, stepRect]) => {
357
+ this.state.stepsInitHeight = stepsRect.height - (steps - 1) * stepRect.height;
358
+ this.state.stepHeight = stepRect.height;
359
+ })
360
+ .catch(() => {
361
+ });
362
+ }
355
363
 
356
- if (subTitles.length > 0) {
357
- const { height } = await getRect(this, `.${name}__options-title`);
358
- this.state.subTitlesHeight = height;
359
- }
364
+ if (subTitles.length > 0) {
365
+ const { height } = await getRect(this, `.${classPrefix}__options-title`);
366
+ this.state.subTitlesHeight = height;
367
+ }
360
368
 
361
- const optionsInitHeight = this.state.contentHeight - this.state.subTitlesHeight;
362
- this.optionsHeight = theme === 'step'
363
- ? optionsInitHeight - this.state.stepsInitHeight - (steps - 1) * this.state.stepHeight
364
- : optionsInitHeight - this.state.tabsHeight;
365
- },
369
+ const optionsInitHeight = this.state.contentHeight - this.state.subTitlesHeight;
370
+ this.optionsHeight = theme === 'step'
371
+ ? optionsInitHeight - this.state.stepsInitHeight - (steps - 1) * this.state.stepHeight
372
+ : optionsInitHeight - this.state.tabsHeight;
373
+ },
366
374
 
367
- initWithValue() {
368
- if (this.dataValue != null && this.dataValue !== '') {
369
- const selectedIndexes = this.getIndexesByValue(this.options, this.dataValue);
375
+ initWithValue() {
376
+ if (this.dataValue != null && this.dataValue !== '') {
377
+ const selectedIndexes = this.getIndexesByValue(this.options, this.dataValue);
370
378
 
371
- if (selectedIndexes) {
372
- this.selectedIndexes = selectedIndexes;
379
+ if (selectedIndexes) {
380
+ this.selectedIndexes = selectedIndexes;
381
+ }
382
+ } else {
383
+ this.selectedIndexes = [];
373
384
  }
374
- } else {
375
- this.selectedIndexes = [];
376
- }
377
- },
378
- getIndexesByValue(options, value) {
379
- const { keys } = this;
385
+ },
386
+ getIndexesByValue(options, value) {
387
+ const { keys } = this;
380
388
 
381
- for (let i = 0, size = options.length; i < size; i += 1) {
382
- const opt = options[i];
383
- if (opt[coalesce(keys?.value, 'value')] === value) {
384
- return [i];
385
- }
386
- if (opt[coalesce(keys?.children, 'children')]) {
387
- const res = this.getIndexesByValue(opt[coalesce(keys?.children, 'children')], value);
388
- if (res) {
389
- return [i, ...res];
389
+ for (let i = 0, size = options.length; i < size; i += 1) {
390
+ const opt = options[i];
391
+ if (opt[coalesce(keys?.value, 'value')] === value) {
392
+ return [i];
393
+ }
394
+ if (opt[coalesce(keys?.children, 'children')]) {
395
+ const res = this.getIndexesByValue(opt[coalesce(keys?.children, 'children')], value);
396
+ if (res) {
397
+ return [i, ...res];
398
+ }
390
399
  }
391
400
  }
392
- }
393
- },
394
- updateScrollTop() {
395
- const { dataVisible: visible, items, selectedIndexes, stepIndex } = this;
401
+ },
402
+ updateScrollTop() {
403
+ const { dataVisible: visible, items, selectedIndexes, stepIndex } = this;
396
404
 
397
- if (visible) {
398
- getRect(this, '.cascader-radio-group-0').then((rect) => {
399
- const eachRadioHeight = rect.height / items[0]?.length;
405
+ if (visible) {
406
+ getRect(this, '.cascader-radio-group-0').then((rect) => {
407
+ const eachRadioHeight = rect.height / items[0]?.length;
400
408
 
401
- this[`scrollTopList[${stepIndex}]`] = eachRadioHeight * selectedIndexes[stepIndex];
402
- })
403
- .catch(() => {
404
- });
405
- }
406
- },
407
- hide(trigger) {
408
- this.dataVisible = false;
409
- this.$emit('close', { trigger });
410
- this.$emit('update:visible', false);
411
- },
412
- onVisibleChange() {
413
- this.hide('overlay');
414
- },
415
- onClose() {
416
- if (this.checkStrictly) {
417
- this.triggerChange();
418
- }
419
- this.hide('close-btn');
420
- },
421
- onStepClick(index) {
422
- this.stepIndex = index;
423
- },
424
- onTabChange(value) {
425
- this.stepIndex = value;
426
- },
427
- genItems() {
428
- const { options, selectedIndexes, keys, placeholder } = this;
429
- const selectedValue = [];
430
- const steps = [];
431
- const items = [parseOptions(options, keys)];
432
-
433
- if (options.length > 0) {
434
- let current = options;
435
- for (let i = 0, size = selectedIndexes.length; i < size; i += 1) {
436
- const index = selectedIndexes[i];
437
- const next = current[index];
438
- current = next[coalesce(keys?.children, 'children')];
439
-
440
- selectedValue.push(next[coalesce(keys?.value, 'value')]);
441
- steps.push(next[coalesce(keys?.label, 'label')]);
442
-
443
- if (next[coalesce(keys?.children, 'children')]) {
444
- items.push(parseOptions(next[coalesce(keys?.children, 'children')], keys));
409
+ this[`scrollTopList[${stepIndex}]`] = eachRadioHeight * selectedIndexes[stepIndex];
410
+ })
411
+ .catch(() => {
412
+ });
413
+ }
414
+ },
415
+ hide(trigger) {
416
+ this.dataVisible = false;
417
+ this.$emit('close', { trigger });
418
+ this.$emit('update:visible', false);
419
+ },
420
+ onVisibleChange() {
421
+ this.hide('overlay');
422
+ },
423
+ onClose() {
424
+ if (this.checkStrictly) {
425
+ this.triggerChange();
426
+ }
427
+ this.hide('close-btn');
428
+ },
429
+ onStepClick(index) {
430
+ this.stepIndex = index;
431
+ },
432
+ onTabChange(value) {
433
+ this.stepIndex = value;
434
+ },
435
+ genItems() {
436
+ const { options, selectedIndexes, keys, placeholder, globalConfig } = this;
437
+ const selectedValue = [];
438
+ const steps = [];
439
+ const items = [parseOptions(options, keys)];
440
+
441
+ if (options.length > 0) {
442
+ let current = options;
443
+ for (let i = 0, size = selectedIndexes.length; i < size; i += 1) {
444
+ const index = selectedIndexes[i];
445
+ const next = current[index];
446
+ current = next[coalesce(keys?.children, 'children')];
447
+
448
+ selectedValue.push(next[coalesce(keys?.value, 'value')]);
449
+ steps.push(next[coalesce(keys?.label, 'label')]);
450
+
451
+ if (next[coalesce(keys?.children, 'children')]) {
452
+ items.push(parseOptions(next[coalesce(keys?.children, 'children')], keys));
453
+ }
445
454
  }
446
455
  }
447
- }
448
456
 
449
- if (steps.length < items.length) {
450
- steps.push(placeholder);
451
- }
457
+ if (steps.length < items.length) {
458
+ steps.push(placeholder || globalConfig.placeholder);
459
+ }
452
460
 
453
- return {
454
- selectedValue,
455
- steps,
456
- items,
457
- };
458
- },
459
- handleSelect(tools, { level, value }) {
460
- const { checkStrictly } = this;
461
- const { selectedIndexes, items, keys, options, selectedValue } = this;
461
+ return {
462
+ selectedValue,
463
+ steps,
464
+ items,
465
+ };
466
+ },
467
+ handleSelect(tools, { level, value }) {
468
+ const { checkStrictly } = this;
469
+ const { selectedIndexes, items, keys, options, selectedValue } = this;
470
+
471
+ const index = items[level].findIndex(item => item[coalesce(keys?.value, 'value')] === value);
472
+
473
+ let item = selectedIndexes.slice(0, level).reduce((acc, item, index) => {
474
+ if (index === 0) {
475
+ return acc[item];
476
+ }
477
+ return acc[coalesce(keys?.children, 'children')][item];
478
+ }, options);
462
479
 
463
- const index = items[level].findIndex(item => item[coalesce(keys?.value, 'value')] === value);
464
480
 
465
- let item = selectedIndexes.slice(0, level).reduce((acc, item, index) => {
466
- if (index === 0) {
467
- return acc[item];
481
+ if (level === 0) {
482
+ item = item[index];
483
+ } else {
484
+ item = item[coalesce(keys?.children, 'children')][index];
468
485
  }
469
- return acc[coalesce(keys?.children, 'children')][item];
470
- }, options);
471
-
472
-
473
- if (level === 0) {
474
- item = item[index];
475
- } else {
476
- item = item[coalesce(keys?.children, 'children')][index];
477
- }
478
-
479
- if (item[coalesce(keys?.disabled, 'disabled')]) {
480
- return;
481
- }
482
- this.$emit('pick', {
483
- value: item[coalesce(keys?.value, 'value')],
484
- label: item[coalesce(keys?.label, 'label')],
485
- index,
486
- level,
487
- });
488
- selectedIndexes[level] = index;
489
- if (checkStrictly && selectedValue.includes(String(value))) {
490
- selectedIndexes.length = level;
491
- this.selectedIndexes = selectedIndexes;
492
- return;
493
- }
494
- selectedIndexes.length = level + 1;
495
-
496
- const { items: newItems } = this.genItems();
497
- if (item?.[coalesce(keys?.children, 'children')]?.length >= 0) {
498
- this.selectedIndexes = selectedIndexes;
499
- this[`items[${level + 1}]`] = newItems[level + 1];
500
- } else {
486
+
487
+ if (item[coalesce(keys?.disabled, 'disabled')]) {
488
+ return;
489
+ }
490
+ this.$emit('pick', {
491
+ value: item[coalesce(keys?.value, 'value')],
492
+ label: item[coalesce(keys?.label, 'label')],
493
+ index,
494
+ level,
495
+ });
496
+ selectedIndexes[level] = index;
497
+ if (checkStrictly && selectedValue.includes(String(value))) {
498
+ selectedIndexes.length = level;
499
+ this.selectedIndexes = selectedIndexes;
500
+ return;
501
+ }
502
+ selectedIndexes.length = level + 1;
503
+
504
+ const { items: newItems } = this.genItems();
505
+ if (item?.[coalesce(keys?.children, 'children')]?.length >= 0) {
506
+ this.selectedIndexes = selectedIndexes;
507
+ this[`items[${level + 1}]`] = newItems[level + 1];
508
+ } else {
501
509
  // setCascaderValue(item.value);
502
- this.selectedIndexes = selectedIndexes;
503
- setTimeout(this.triggerChange);
510
+ this.selectedIndexes = selectedIndexes;
511
+ setTimeout(this.triggerChange);
504
512
 
505
- this.hide('finish');
506
- }
507
- // #ifdef VUE2
508
- this.$set(this, 'selectedIndexes', JSON.parse(JSON.stringify(selectedIndexes)));
513
+ this.hide('finish');
514
+ }
515
+ // #ifdef VUE2
516
+ this.$set(this, 'selectedIndexes', JSON.parse(JSON.stringify(selectedIndexes)));
509
517
  // #endif
518
+ },
519
+ triggerChange() {
520
+ const { items, selectedValue, selectedIndexes } = this;
521
+ this._trigger('change', {
522
+ value: coalesce(selectedValue[selectedValue.length - 1], ''),
523
+ selectedOptions: items.map((item, index) => item[selectedIndexes[index]]).filter(Boolean),
524
+ });
525
+ },
526
+ isShowOverlay(value, defaultValue) {
527
+ return tools.isBoolean(value) ? value : defaultValue;
528
+ },
510
529
  },
511
- triggerChange() {
512
- const { items, selectedValue, selectedIndexes } = this;
513
- this._trigger('change', {
514
- value: coalesce(selectedValue[selectedValue.length - 1], ''),
515
- selectedOptions: items.map((item, index) => item[selectedIndexes[index]]).filter(Boolean),
516
- });
517
- },
518
- },
519
- });
530
+ }),
531
+ };
520
532
  </script>
521
533
  <style scoped src="./cascader.css"></style>