@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.
- package/CHANGELOG.md +23 -0
- package/README.md +1 -1
- package/dist/action-sheet/README.md +1 -1
- package/dist/action-sheet/action-sheet.vue +158 -150
- package/dist/action-sheet/props.ts +2 -2
- package/dist/action-sheet/type.ts +1 -1
- package/dist/avatar/avatar.vue +89 -87
- package/dist/avatar-group/avatar-group.vue +69 -67
- package/dist/back-top/back-top.vue +60 -58
- package/dist/badge/badge.vue +69 -59
- package/dist/button/button.vue +121 -116
- package/dist/button/props.ts +2 -2
- package/dist/button/type.ts +1 -1
- package/dist/calendar/calendar-header.vue +4 -4
- package/dist/calendar/calendar.vue +308 -297
- package/dist/calendar/template.vue +1 -1
- package/dist/cascader/README.en-US.md +2 -1
- package/dist/cascader/README.md +2 -1
- package/dist/cascader/cascader.vue +340 -328
- package/dist/cascader/props.ts +6 -1
- package/dist/cascader/type.ts +6 -0
- package/dist/cell/cell.vue +127 -121
- package/dist/cell-group/cell-group.vue +32 -30
- package/dist/check-tag/check-tag.vue +73 -71
- package/dist/checkbox/checkbox.vue +127 -127
- package/dist/checkbox/props.ts +6 -6
- package/dist/checkbox/type.ts +3 -3
- package/dist/checkbox-group/checkbox-group.vue +175 -173
- package/dist/checkbox-group/props.ts +6 -6
- package/dist/checkbox-group/type.ts +4 -4
- package/dist/col/col.vue +26 -24
- package/dist/collapse/collapse.vue +83 -81
- package/dist/collapse-panel/collapse-panel.vue +121 -119
- package/dist/collapse-panel/props.ts +4 -4
- package/dist/collapse-panel/type.ts +2 -2
- package/dist/color-picker/README.md +1 -1
- package/dist/color-picker/color-picker.vue +324 -322
- package/dist/color-picker/props.ts +2 -2
- package/dist/color-picker/template.vue +14 -10
- package/dist/common/common.ts +1 -0
- package/dist/common/style/theme/index.css +5 -5
- package/dist/common/utils.js +7 -2
- package/dist/common/validator.js +172 -0
- package/dist/config-provider/README.en-US.md +184 -0
- package/dist/config-provider/README.md +234 -0
- package/dist/config-provider/config-provider.vue +105 -0
- package/dist/config-provider/config-store.js +70 -0
- package/dist/config-provider/props.ts +16 -0
- package/dist/config-provider/reactive-state.js +39 -0
- package/dist/config-provider/type.ts +401 -0
- package/dist/config-provider/use-config.js +29 -0
- package/dist/config-provider/utils.js +29 -0
- package/dist/count-down/count-down.vue +98 -97
- package/dist/date-time-picker/date-time-picker.vue +410 -395
- package/dist/demo/demo.vue +1 -0
- package/dist/dialog/dialog.vue +175 -173
- package/dist/divider/divider.vue +38 -36
- package/dist/draggable/draggable.vue +60 -58
- package/dist/drawer/README.md +1 -1
- package/dist/drawer/drawer.vue +48 -46
- package/dist/dropdown-item/dropdown-item.vue +209 -207
- package/dist/dropdown-item/props.ts +4 -4
- package/dist/dropdown-item/type.ts +3 -3
- package/dist/dropdown-menu/dropdown-menu.vue +93 -99
- package/dist/empty/empty.vue +43 -42
- package/dist/fab/fab.vue +88 -86
- package/dist/footer/footer.vue +36 -34
- package/dist/form/README.en-US.md +17 -24
- package/dist/form/README.md +18 -25
- package/dist/form/form.css +1 -166
- package/dist/form/form.vue +251 -236
- package/dist/form/props.ts +2 -21
- package/dist/form/type.ts +7 -70
- package/dist/form-item/README.en-US.md +4 -5
- package/dist/form-item/README.md +4 -5
- package/dist/form-item/form-item.css +69 -96
- package/dist/form-item/form-item.vue +315 -336
- package/dist/form-item/form-model.ts +125 -173
- package/dist/form-item/props.ts +4 -17
- package/dist/form-item/type.ts +43 -1
- package/dist/grid/grid.vue +53 -51
- package/dist/grid-item/grid-item.vue +121 -119
- package/dist/guide/README.md +1 -1
- package/dist/guide/guide.vue +281 -277
- package/dist/icon/README.md +2 -4
- package/dist/icon/icon.vue +78 -76
- package/dist/image/README.md +1 -1
- package/dist/image/image.vue +103 -101
- package/dist/image-viewer/image-viewer.vue +160 -158
- package/dist/image-viewer/props.ts +2 -2
- package/dist/image-viewer/type.ts +1 -1
- package/dist/index.js +3 -0
- package/dist/indexes/indexes.vue +264 -267
- package/dist/indexes-anchor/indexes-anchor.vue +41 -41
- package/dist/input/input.vue +192 -192
- package/dist/input/props.ts +6 -6
- package/dist/input/type.ts +3 -3
- package/dist/link/link.vue +73 -71
- package/dist/loading/loading.vue +59 -59
- package/dist/locale/ar_KW.ts +157 -0
- package/dist/locale/en_US.ts +146 -0
- package/dist/locale/it_IT.ts +145 -0
- package/dist/locale/ja_JP.ts +132 -0
- package/dist/locale/ko_KR.ts +132 -0
- package/dist/locale/ru_RU.ts +157 -0
- package/dist/locale/zh_CN.ts +133 -0
- package/dist/locale/zh_TW.ts +132 -0
- package/dist/message/message.vue +181 -173
- package/dist/message/props.ts +2 -2
- package/dist/message/type.ts +1 -1
- package/dist/message-item/message-item.vue +192 -184
- package/dist/mixins/using-config.js +39 -0
- package/dist/navbar/navbar.vue +201 -199
- package/dist/notice-bar/notice-bar.vue +175 -171
- package/dist/notice-bar/props.ts +2 -2
- package/dist/notice-bar/type.ts +1 -1
- package/dist/npm/dayjs/esm/locale/ar.js +81 -0
- package/dist/npm/dayjs/esm/locale/it.js +39 -0
- package/dist/overlay/overlay.vue +50 -48
- package/dist/picker/picker.vue +168 -161
- package/dist/picker-item/picker-item.vue +269 -269
- package/dist/popover/README.md +1 -1
- package/dist/popover/popover.vue +262 -261
- package/dist/popover/props.ts +4 -4
- package/dist/popover/type.ts +2 -2
- package/dist/popup/popup.vue +46 -45
- package/dist/progress/README.md +1 -1
- package/dist/progress/progress.vue +76 -76
- package/dist/pull-down-refresh/props.ts +2 -2
- package/dist/pull-down-refresh/pull-down-refresh.vue +240 -234
- package/dist/pull-down-refresh/type.ts +1 -1
- package/dist/qrcode/README.md +1 -1
- package/dist/qrcode/components/qrcode-canvas/qrcode-canvas.vue +340 -338
- package/dist/qrcode/components/qrcode-status/qrcode-status.vue +6 -6
- package/dist/qrcode/qrcode.vue +93 -87
- package/dist/radio/props.ts +6 -6
- package/dist/radio/radio.vue +118 -120
- package/dist/radio/type.ts +3 -3
- package/dist/radio-group/props.ts +4 -4
- package/dist/radio-group/radio-group.vue +136 -134
- package/dist/radio-group/type.ts +4 -4
- package/dist/rate/computed.js +2 -2
- package/dist/rate/props.ts +4 -4
- package/dist/rate/rate.vue +155 -154
- package/dist/rate/type.ts +2 -2
- package/dist/result/result.vue +41 -39
- package/dist/row/row.vue +38 -36
- package/dist/scroll-view/scroll-view.vue +24 -22
- package/dist/search/props.ts +2 -2
- package/dist/search/search.vue +127 -125
- package/dist/search/type.ts +1 -1
- package/dist/side-bar/side-bar.vue +57 -55
- package/dist/side-bar-item/side-bar-item.vue +86 -86
- package/dist/skeleton/skeleton.vue +126 -124
- package/dist/slider/README.md +1 -1
- package/dist/slider/props.ts +2 -2
- package/dist/slider/slider.vue +457 -457
- package/dist/slider/type.ts +1 -1
- package/dist/step-item/step-item.vue +77 -75
- package/dist/stepper/props.ts +2 -2
- package/dist/stepper/stepper.vue +168 -149
- package/dist/stepper/type.ts +1 -1
- package/dist/steps/props.ts +2 -2
- package/dist/steps/steps.vue +83 -81
- package/dist/steps/type.ts +1 -1
- package/dist/sticky/sticky.vue +104 -102
- package/dist/swipe-cell/swipe-cell.vue +91 -89
- package/dist/swiper/README.md +1 -1
- package/dist/swiper/swiper.vue +91 -89
- package/dist/swiper-nav/swiper-nav.vue +38 -36
- package/dist/switch/props.ts +2 -2
- package/dist/switch/switch.vue +62 -62
- package/dist/switch/type.ts +1 -1
- package/dist/tab-bar/tab-bar.vue +88 -86
- package/dist/tab-bar-item/tab-bar-item.vue +85 -82
- package/dist/tab-panel/tab-panel.vue +66 -64
- package/dist/tabs/tabs.vue +294 -287
- package/dist/tag/tag.vue +79 -77
- package/dist/textarea/props.ts +6 -6
- package/dist/textarea/textarea.vue +127 -126
- package/dist/textarea/type.ts +3 -3
- package/dist/toast/toast.vue +107 -106
- package/dist/transition/transition.vue +30 -28
- package/dist/tree-select/tree-select.vue +151 -151
- package/dist/types/config-provider.d.ts +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/popover.d.ts +7 -0
- package/dist/upload/README.en-US.md +13 -14
- package/dist/upload/README.md +11 -12
- package/dist/upload/props.ts +2 -4
- package/dist/upload/type.ts +12 -11
- package/dist/upload/upload.css +1 -1
- package/dist/upload/upload.vue +672 -512
- package/dist/watermark/watermark.vue +151 -149
- package/global.d.ts +2 -0
- package/package.json +15 -3
- package/dist/form/form-item-props.ts +0 -56
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view>
|
|
3
|
-
<
|
|
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="
|
|
14
|
+
:style="'' + tools._style([customStyle])"
|
|
15
|
+
:class="classPrefix"
|
|
12
16
|
>
|
|
13
|
-
<view :class="
|
|
17
|
+
<view :class="classPrefix + '__title'">
|
|
14
18
|
<slot name="title" />
|
|
15
|
-
{{ title }}
|
|
19
|
+
{{ title || globalConfig.title || '' }}
|
|
16
20
|
</view>
|
|
17
21
|
<view
|
|
18
|
-
:class="
|
|
22
|
+
:class="classPrefix + '__close-btn'"
|
|
19
23
|
@click="onClose"
|
|
20
24
|
>
|
|
21
25
|
<slot name="close-btn" />
|
|
22
|
-
<
|
|
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="
|
|
35
|
+
<view :class="classPrefix + '__content'">
|
|
32
36
|
<block v-if="steps && steps.length">
|
|
33
37
|
<view
|
|
34
38
|
v-if="theme == 'step'"
|
|
35
|
-
:class="
|
|
39
|
+
:class="classPrefix + '__steps'"
|
|
36
40
|
>
|
|
37
41
|
<view
|
|
38
42
|
v-for="(item, index) in steps"
|
|
39
43
|
:key="index"
|
|
40
|
-
:class="
|
|
44
|
+
:class="classPrefix + '__step'"
|
|
41
45
|
:data-index="index"
|
|
42
46
|
@click="() => onStepClick(index)"
|
|
43
47
|
>
|
|
44
48
|
<view
|
|
45
49
|
:class="
|
|
46
|
-
|
|
50
|
+
classPrefix +
|
|
47
51
|
'__step-dot ' +
|
|
48
|
-
|
|
52
|
+
classPrefix +
|
|
49
53
|
'__step-dot--' +
|
|
50
54
|
(item !== placeholder ? 'active' : '') +
|
|
51
55
|
' ' +
|
|
52
|
-
|
|
56
|
+
classPrefix +
|
|
53
57
|
'__step-dot--' +
|
|
54
58
|
(index === steps.length - 1 ? 'last' : '')
|
|
55
59
|
"
|
|
56
60
|
/>
|
|
57
61
|
|
|
58
|
-
<view :class="
|
|
62
|
+
<view :class="classPrefix + '__step-label ' + classPrefix + '__step-label--' + (index === stepIndex ? 'active' : '')">
|
|
59
63
|
{{ item }}
|
|
60
64
|
</view>
|
|
61
65
|
|
|
62
|
-
<
|
|
66
|
+
<t-icon
|
|
63
67
|
name="chevron-right"
|
|
64
68
|
size="44rpx"
|
|
65
|
-
:t-class="
|
|
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
|
-
<
|
|
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
|
-
<
|
|
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
|
-
</
|
|
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="
|
|
97
|
+
:class="classPrefix + '__options-title'"
|
|
94
98
|
>
|
|
95
99
|
{{ subTitles[stepIndex] }}
|
|
96
100
|
</view>
|
|
97
101
|
|
|
98
102
|
<view
|
|
99
|
-
:class="
|
|
100
|
-
:style="'
|
|
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="
|
|
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
|
-
<
|
|
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="(
|
|
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
|
-
</
|
|
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
|
|
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
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
this.dataVisible = v;
|
|
186
|
+
controlledProps: [
|
|
187
|
+
{
|
|
188
|
+
key: 'value',
|
|
189
|
+
event: 'change',
|
|
222
190
|
},
|
|
223
|
-
|
|
191
|
+
],
|
|
192
|
+
externalClasses: [
|
|
193
|
+
`${prefix}-class`,
|
|
194
|
+
],
|
|
195
|
+
props: {
|
|
196
|
+
...props,
|
|
224
197
|
},
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
this.stepIndex = items.length - 1;
|
|
272
|
+
options: {
|
|
273
|
+
handler() {
|
|
274
|
+
const { selectedValue, steps, items } = this.genItems();
|
|
286
275
|
|
|
287
|
-
|
|
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
|
-
|
|
293
|
-
|
|
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
|
-
|
|
301
|
-
|
|
302
|
-
|
|
308
|
+
stepIndex: {
|
|
309
|
+
handler() {
|
|
310
|
+
const { dataVisible: visible } = this;
|
|
303
311
|
|
|
304
|
-
|
|
305
|
-
|
|
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
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
mounted() {
|
|
320
|
+
created() {
|
|
321
|
+
this.state = {
|
|
322
|
+
...defaultState,
|
|
323
|
+
};
|
|
324
|
+
},
|
|
325
|
+
mounted() {
|
|
318
326
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
327
|
+
},
|
|
328
|
+
methods: {
|
|
329
|
+
setTabParent() {
|
|
322
330
|
// #ifdef MP-TOUTIAO
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
364
|
+
if (subTitles.length > 0) {
|
|
365
|
+
const { height } = await getRect(this, `.${classPrefix}__options-title`);
|
|
366
|
+
this.state.subTitlesHeight = height;
|
|
367
|
+
}
|
|
360
368
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
368
|
-
|
|
369
|
-
|
|
375
|
+
initWithValue() {
|
|
376
|
+
if (this.dataValue != null && this.dataValue !== '') {
|
|
377
|
+
const selectedIndexes = this.getIndexesByValue(this.options, this.dataValue);
|
|
370
378
|
|
|
371
|
-
|
|
372
|
-
|
|
379
|
+
if (selectedIndexes) {
|
|
380
|
+
this.selectedIndexes = selectedIndexes;
|
|
381
|
+
}
|
|
382
|
+
} else {
|
|
383
|
+
this.selectedIndexes = [];
|
|
373
384
|
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
},
|
|
378
|
-
getIndexesByValue(options, value) {
|
|
379
|
-
const { keys } = this;
|
|
385
|
+
},
|
|
386
|
+
getIndexesByValue(options, value) {
|
|
387
|
+
const { keys } = this;
|
|
380
388
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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
|
-
|
|
395
|
-
const { dataVisible: visible, items, selectedIndexes, stepIndex } = this;
|
|
401
|
+
},
|
|
402
|
+
updateScrollTop() {
|
|
403
|
+
const { dataVisible: visible, items, selectedIndexes, stepIndex } = this;
|
|
396
404
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
405
|
+
if (visible) {
|
|
406
|
+
getRect(this, '.cascader-radio-group-0').then((rect) => {
|
|
407
|
+
const eachRadioHeight = rect.height / items[0]?.length;
|
|
400
408
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
|
|
457
|
+
if (steps.length < items.length) {
|
|
458
|
+
steps.push(placeholder || globalConfig.placeholder);
|
|
459
|
+
}
|
|
452
460
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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
|
-
|
|
466
|
-
|
|
467
|
-
|
|
481
|
+
if (level === 0) {
|
|
482
|
+
item = item[index];
|
|
483
|
+
} else {
|
|
484
|
+
item = item[coalesce(keys?.children, 'children')][index];
|
|
468
485
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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
|
-
|
|
503
|
-
|
|
510
|
+
this.selectedIndexes = selectedIndexes;
|
|
511
|
+
setTimeout(this.triggerChange);
|
|
504
512
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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
|
-
|
|
512
|
-
|
|
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>
|