stellar-ui-v2 1.40.26 → 1.40.28
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/components/ste-date-picker/ste-date-picker.vue +391 -407
- package/components/ste-index-item/ste-index-item.vue +10 -5
- package/components/ste-radio/README.md +16 -16
- package/components/ste-scroll-to/mixin.js +3 -2
- package/components/ste-scroll-to/ste-scroll-to.vue +0 -4
- package/components/ste-scroll-to-item/ste-scroll-to-item.vue +7 -2
- package/components/ste-slider/README.md +79 -65
- package/components/ste-slider/ste-slider.vue +552 -551
- package/components/ste-swipe-action/ste-swipe-action.vue +2 -2
- package/components/ste-swiper-item/ste-swiper-item.vue +49 -55
- package/components/ste-tab/ste-tab.vue +39 -8
- package/components/ste-table/ste-table.vue +4 -24
- package/components/ste-table-column/ste-table-column.vue +6 -13
- package/components/ste-tabs/ste-tabs.vue +25 -13
- package/package.json +1 -1
- package/utils/mixin.js +27 -19
|
@@ -1,407 +1,391 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view class="ste-date-picker-root">
|
|
3
|
-
<ste-picker
|
|
4
|
-
:columns="columns"
|
|
5
|
-
:title="title"
|
|
6
|
-
:showToolbar="showToolbar"
|
|
7
|
-
:cancelText="cancelText"
|
|
8
|
-
:cancelColor="cancelColor"
|
|
9
|
-
:confirmText="confirmText"
|
|
10
|
-
:confirmColor="cmpConfirmColor"
|
|
11
|
-
:visibleItemCount="visibleItemCount"
|
|
12
|
-
:defaultIndex="innerDefaultIndex"
|
|
13
|
-
:itemHeight="itemHeight"
|
|
14
|
-
@change="change"
|
|
15
|
-
@cancel="cancel"
|
|
16
|
-
@confirm="confirm"
|
|
17
|
-
rootClass="ste-date-picker-view"
|
|
18
|
-
></ste-picker>
|
|
19
|
-
</view>
|
|
20
|
-
</template>
|
|
21
|
-
|
|
22
|
-
<script>
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
* @
|
|
30
|
-
* @
|
|
31
|
-
* @property {
|
|
32
|
-
* @property {
|
|
33
|
-
* @property {String}
|
|
34
|
-
* @
|
|
35
|
-
* @value
|
|
36
|
-
* @value
|
|
37
|
-
* @value
|
|
38
|
-
* @value
|
|
39
|
-
* @value
|
|
40
|
-
* @value
|
|
41
|
-
* @value
|
|
42
|
-
* @
|
|
43
|
-
* @property {Number}
|
|
44
|
-
* @property {
|
|
45
|
-
* @property {Function}
|
|
46
|
-
* @property {
|
|
47
|
-
* @property {String
|
|
48
|
-
* @property {String}
|
|
49
|
-
* @property {String}
|
|
50
|
-
* @property {String}
|
|
51
|
-
* @property {String}
|
|
52
|
-
* @
|
|
53
|
-
* @event {Function}
|
|
54
|
-
* @event {Function}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
this.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
this.
|
|
176
|
-
this.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
formatter('
|
|
193
|
-
formatter('
|
|
194
|
-
formatter('
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
case '
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
case '
|
|
208
|
-
startFlag =
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if (
|
|
299
|
-
month =
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
this.$emit('cancel');
|
|
393
|
-
},
|
|
394
|
-
confirm() {
|
|
395
|
-
this.$emit('confirm', this.innerValue);
|
|
396
|
-
},
|
|
397
|
-
},
|
|
398
|
-
};
|
|
399
|
-
</script>
|
|
400
|
-
|
|
401
|
-
<style lang="scss" scoped>
|
|
402
|
-
.ste-date-picker-root {
|
|
403
|
-
// ::v-deep view {
|
|
404
|
-
// padding: 0 42rpx;
|
|
405
|
-
// }
|
|
406
|
-
}
|
|
407
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<view class="ste-date-picker-root">
|
|
3
|
+
<ste-picker
|
|
4
|
+
:columns="columns"
|
|
5
|
+
:title="title"
|
|
6
|
+
:showToolbar="showToolbar"
|
|
7
|
+
:cancelText="cancelText"
|
|
8
|
+
:cancelColor="cancelColor"
|
|
9
|
+
:confirmText="confirmText"
|
|
10
|
+
:confirmColor="cmpConfirmColor"
|
|
11
|
+
:visibleItemCount="visibleItemCount"
|
|
12
|
+
:defaultIndex="innerDefaultIndex"
|
|
13
|
+
:itemHeight="itemHeight"
|
|
14
|
+
@change="change"
|
|
15
|
+
@cancel="cancel"
|
|
16
|
+
@confirm="confirm"
|
|
17
|
+
rootClass="ste-date-picker-view"
|
|
18
|
+
></ste-picker>
|
|
19
|
+
</view>
|
|
20
|
+
</template>
|
|
21
|
+
|
|
22
|
+
<script>
|
|
23
|
+
import dayjs from '../../utils/dayjs.min.js';
|
|
24
|
+
import useColor from '../../config/color.js';
|
|
25
|
+
let color = useColor();
|
|
26
|
+
/**
|
|
27
|
+
* ste-date-picker 时间日期选择器
|
|
28
|
+
* @description 此选择器用于时间日期
|
|
29
|
+
* @tutorial https://stellar-ui.intecloud.com.cn/?projectName=stellar-ui&menu=%E7%BB%84%E4%BB%B6&active=ste-date-picker
|
|
30
|
+
* @property {String | Number} value 绑定值
|
|
31
|
+
* @property {Boolean} showToolbar 是否显示顶部的操作栏 ( 默认 true )
|
|
32
|
+
* @property {String} title 顶部标题
|
|
33
|
+
* @property {String} mode 展示格式 (默认 all)
|
|
34
|
+
* @value all 年月日时分秒 {{String}}
|
|
35
|
+
* @value datetime 年月日时分 {{String}}
|
|
36
|
+
* @value date 年月日 {{String}}
|
|
37
|
+
* @value year-month 年月 {{String}}
|
|
38
|
+
* @value month-day 月日 {{String}}
|
|
39
|
+
* @value time 时分秒 {{String}}
|
|
40
|
+
* @value hour-minute 时分 {{String}}
|
|
41
|
+
* @value minute-second 分秒 {{String}}
|
|
42
|
+
* @property {Number} maxDate 可选的最大时间 默认值为后10年
|
|
43
|
+
* @property {Number} minDate 可选的最小时间 默认值为前10年
|
|
44
|
+
* @property {Function} filter 选项过滤函数
|
|
45
|
+
* @property {Function} formatter 选项格式化函数
|
|
46
|
+
* @property {String | Number} itemHeight 各列中,单个选项的高度 ( 默认 36 )
|
|
47
|
+
* @property {String} cancelText 取消按钮的文字 ( 默认 '取消' )
|
|
48
|
+
* @property {String} confirmText 确认按钮的文字 ( 默认 '确认' )
|
|
49
|
+
* @property {String} cancelColor 取消按钮的颜色 ( 默认 '#909193' )
|
|
50
|
+
* @property {String} confirmColor 确认按钮的颜色 ( 默认 '#3c9cff' )
|
|
51
|
+
* @property {String | Number} visibleItemCount 每列中可见选项的数量 ( 默认 5 )
|
|
52
|
+
* @event {Function} confirm 点击确定按钮,返回当前选择的值
|
|
53
|
+
* @event {Function} change 当选择值变化时触发
|
|
54
|
+
* @event {Function} cancel 点击取消按钮
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
const DEFAULT_DATE = dayjs(new Date(1970, 1, 1, 0, 0, 0));
|
|
58
|
+
|
|
59
|
+
const padZero = (value) => {
|
|
60
|
+
return `00${value}`.slice(-2);
|
|
61
|
+
};
|
|
62
|
+
const times = (n, iteratee) => {
|
|
63
|
+
let index = -1;
|
|
64
|
+
const result = Array(n < 0 ? 0 : n);
|
|
65
|
+
while (++index < n) {
|
|
66
|
+
result[index] = iteratee(index);
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export default {
|
|
72
|
+
group: '表单组件',
|
|
73
|
+
title: 'DatePicker 时间选择器',
|
|
74
|
+
name: 'ste-date-picker',
|
|
75
|
+
props: {
|
|
76
|
+
// 是否展示顶部的操作栏
|
|
77
|
+
showToolbar: {
|
|
78
|
+
type: [Boolean, null],
|
|
79
|
+
default: true,
|
|
80
|
+
},
|
|
81
|
+
// 绑定值
|
|
82
|
+
value: {
|
|
83
|
+
type: [String, Number, null],
|
|
84
|
+
default: '',
|
|
85
|
+
},
|
|
86
|
+
// 顶部标题
|
|
87
|
+
title: {
|
|
88
|
+
type: [String, null],
|
|
89
|
+
default: '',
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* 年月日时分秒(all),年月日时分(datetime),年月日(date),年月(year-month),月日(month-day),时分秒(time),时分(hour-minute),分秒(minute-second),
|
|
93
|
+
*/
|
|
94
|
+
mode: {
|
|
95
|
+
type: [String, null],
|
|
96
|
+
default: 'all',
|
|
97
|
+
},
|
|
98
|
+
// 可选的最大时间
|
|
99
|
+
maxDate: {
|
|
100
|
+
type: [Number, String, null],
|
|
101
|
+
// 最大默认值为后10年
|
|
102
|
+
default: new Date(new Date().getFullYear() + 10, 11, 31, 23, 59, 59).getTime(),
|
|
103
|
+
},
|
|
104
|
+
// 可选的最小时间
|
|
105
|
+
minDate: {
|
|
106
|
+
type: [Number, String, Object, null],
|
|
107
|
+
// 最小默认值为前10年
|
|
108
|
+
default: new Date(new Date().getFullYear() - 10, 0, 1).getTime(),
|
|
109
|
+
},
|
|
110
|
+
// 选项过滤函数
|
|
111
|
+
filter: {
|
|
112
|
+
type: [Function, null],
|
|
113
|
+
default: null,
|
|
114
|
+
},
|
|
115
|
+
// 选项格式化函数
|
|
116
|
+
formatter: {
|
|
117
|
+
type: [Function, null],
|
|
118
|
+
default: null,
|
|
119
|
+
},
|
|
120
|
+
// 各列中,单个选项的高度
|
|
121
|
+
itemHeight: {
|
|
122
|
+
type: [String, Number, null],
|
|
123
|
+
default: 43,
|
|
124
|
+
},
|
|
125
|
+
// 取消按钮的文字
|
|
126
|
+
cancelText: {
|
|
127
|
+
type: [String, null],
|
|
128
|
+
default: '取消',
|
|
129
|
+
},
|
|
130
|
+
// 确认按钮的文字
|
|
131
|
+
confirmText: {
|
|
132
|
+
type: [String, null],
|
|
133
|
+
default: '确认',
|
|
134
|
+
},
|
|
135
|
+
// 取消按钮的颜色
|
|
136
|
+
cancelColor: {
|
|
137
|
+
type: [String, null],
|
|
138
|
+
default: '#969799',
|
|
139
|
+
},
|
|
140
|
+
// 确认按钮的颜色
|
|
141
|
+
confirmColor: {
|
|
142
|
+
type: [String, null],
|
|
143
|
+
default: '',
|
|
144
|
+
},
|
|
145
|
+
// 每列中可见选项的数量
|
|
146
|
+
visibleItemCount: {
|
|
147
|
+
type: [String, Number, null],
|
|
148
|
+
default: 5,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
data() {
|
|
153
|
+
return {
|
|
154
|
+
columns: [],
|
|
155
|
+
innerValue: '',
|
|
156
|
+
innerDefaultIndex: [],
|
|
157
|
+
innerFormatter: (type, value) => value,
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
computed: {
|
|
161
|
+
cmpConfirmColor() {
|
|
162
|
+
return this.confirmColor ? this.confirmColor : color.getColor().steThemeColor;
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
created() {
|
|
166
|
+
this.init();
|
|
167
|
+
},
|
|
168
|
+
methods: {
|
|
169
|
+
init() {
|
|
170
|
+
this.innerValue = this.correctValue(this.value);
|
|
171
|
+
this.updateColumnValue(this.innerValue);
|
|
172
|
+
},
|
|
173
|
+
updateColumnValue(value) {
|
|
174
|
+
this.innerValue = value;
|
|
175
|
+
this.updateColumns();
|
|
176
|
+
this.updateIndexs();
|
|
177
|
+
},
|
|
178
|
+
updateColumns() {
|
|
179
|
+
const formatter = this.formatter || this.innerFormatter;
|
|
180
|
+
const result = this.getOriginColumns().map((column) => column.values.map((value) => formatter(column.type, value)));
|
|
181
|
+
this.columns = result;
|
|
182
|
+
},
|
|
183
|
+
// 更新索引
|
|
184
|
+
updateIndexs() {
|
|
185
|
+
let value = this.innerValue;
|
|
186
|
+
let values = [];
|
|
187
|
+
const formatter = this.formatter || this.innerFormatter;
|
|
188
|
+
values.push(
|
|
189
|
+
formatter('year', `${dayjs(value).year()}`),
|
|
190
|
+
formatter('month', padZero(dayjs(value).month() + 1)),
|
|
191
|
+
formatter('day', padZero(dayjs(value).date())),
|
|
192
|
+
formatter('hour', padZero(dayjs(value).hour())),
|
|
193
|
+
formatter('minute', padZero(dayjs(value).minute())),
|
|
194
|
+
formatter('second', padZero(dayjs(value).second()))
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
// 不同mode下的时间是连续值,需要计算不同mode下对应完整时间的初始替换下标即可
|
|
198
|
+
let startFlag = 0;
|
|
199
|
+
switch (this.mode) {
|
|
200
|
+
case 'month-day':
|
|
201
|
+
startFlag = 1;
|
|
202
|
+
break;
|
|
203
|
+
case 'time':
|
|
204
|
+
case 'hour-minute':
|
|
205
|
+
startFlag = 3;
|
|
206
|
+
break;
|
|
207
|
+
case 'minute-second':
|
|
208
|
+
startFlag = 4;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// 根据当前各列的所有值,从各列默认值中找到默认值在各列中的索引
|
|
212
|
+
const indexs = this.columns.map((column, index) => {
|
|
213
|
+
// 通过取大值,可以保证不会出现找不到索引的-1情况
|
|
214
|
+
return Math.max(
|
|
215
|
+
0,
|
|
216
|
+
column.findIndex((item) => item === values[index + startFlag])
|
|
217
|
+
);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
this.innerDefaultIndex = indexs;
|
|
221
|
+
},
|
|
222
|
+
getOriginColumns() {
|
|
223
|
+
// 生成各列的值
|
|
224
|
+
const results = this.getRanges().map(({ type, range }) => {
|
|
225
|
+
let values = times(range[1] - range[0] + 1, (index) => {
|
|
226
|
+
let value = range[0] + index;
|
|
227
|
+
value = type === 'year' ? `${value}` : padZero(value);
|
|
228
|
+
return value;
|
|
229
|
+
});
|
|
230
|
+
// 进行过滤
|
|
231
|
+
if (this.filter) {
|
|
232
|
+
values = this.filter(type, values);
|
|
233
|
+
}
|
|
234
|
+
return { type, values };
|
|
235
|
+
});
|
|
236
|
+
return results;
|
|
237
|
+
},
|
|
238
|
+
// 获取每列的最大和最小值
|
|
239
|
+
getRanges() {
|
|
240
|
+
const { maxYear, maxDate, maxMonth, maxHour, maxMinute, maxSecond } = this.getBoundary('max', this.innerValue);
|
|
241
|
+
const { minYear, minDate, minMonth, minHour, minMinute, minSecond } = this.getBoundary('min', this.innerValue);
|
|
242
|
+
|
|
243
|
+
const result = [
|
|
244
|
+
{
|
|
245
|
+
type: 'year',
|
|
246
|
+
range: [minYear, maxYear],
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
type: 'month',
|
|
250
|
+
range: [minMonth, maxMonth],
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
type: 'day',
|
|
254
|
+
range: [minDate, maxDate],
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
type: 'hour',
|
|
258
|
+
range: [minHour, maxHour],
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
type: 'minute',
|
|
262
|
+
range: [minMinute, maxMinute],
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
type: 'second',
|
|
266
|
+
range: [minSecond, maxSecond],
|
|
267
|
+
},
|
|
268
|
+
];
|
|
269
|
+
let temp = result;
|
|
270
|
+
if (this.mode === 'datetime') temp = result.splice(0, 5);
|
|
271
|
+
if (this.mode === 'date') temp = result.splice(0, 3);
|
|
272
|
+
if (this.mode === 'year-month') temp = result.splice(0, 2);
|
|
273
|
+
if (this.mode === 'month-day') temp = result.splice(1, 2);
|
|
274
|
+
if (this.mode === 'time') temp = result.splice(3, 3);
|
|
275
|
+
if (this.mode === 'hour-minute') temp = result.splice(3, 2);
|
|
276
|
+
if (this.mode === 'minute-second') temp = result.splice(4, 2);
|
|
277
|
+
return temp;
|
|
278
|
+
},
|
|
279
|
+
// 根据minDate、maxDate、minHour、maxHour等边界值,判断各列的开始和结束边界值
|
|
280
|
+
getBoundary(type, innerValue) {
|
|
281
|
+
const value = dayjs(innerValue);
|
|
282
|
+
const boundary = dayjs(this[`${type}Date`]);
|
|
283
|
+
const year = boundary.year();
|
|
284
|
+
let month = 1;
|
|
285
|
+
let date = 1;
|
|
286
|
+
let hour = 0;
|
|
287
|
+
let minute = 0;
|
|
288
|
+
|
|
289
|
+
if (type === 'max') {
|
|
290
|
+
month = 12;
|
|
291
|
+
date = dayjs(value).daysInMonth();
|
|
292
|
+
hour = 23;
|
|
293
|
+
minute = 59;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// 获取边界值,逻辑是:当年达到了边界值(最大或最小年),就检查月允许的最大和最小值,以此类推
|
|
297
|
+
let second = minute;
|
|
298
|
+
if (value.year() === year) {
|
|
299
|
+
month = boundary.month() + 1;
|
|
300
|
+
if (value.month() + 1 === month) {
|
|
301
|
+
date = boundary.date();
|
|
302
|
+
if (value.date() === date) {
|
|
303
|
+
hour = boundary.hour();
|
|
304
|
+
if (value.hour() === hour) {
|
|
305
|
+
minute = boundary.minute();
|
|
306
|
+
if (value.minute() === minute) second = boundary.second();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return {
|
|
313
|
+
[`${type}Year`]: year,
|
|
314
|
+
[`${type}Month`]: month,
|
|
315
|
+
[`${type}Date`]: date,
|
|
316
|
+
[`${type}Hour`]: hour,
|
|
317
|
+
[`${type}Minute`]: minute,
|
|
318
|
+
[`${type}Second`]: second,
|
|
319
|
+
};
|
|
320
|
+
},
|
|
321
|
+
// 得出合法的时间
|
|
322
|
+
correctValue(value) {
|
|
323
|
+
let date = dayjs(value);
|
|
324
|
+
if (date.isValid()) {
|
|
325
|
+
if (date.isBefore(dayjs(this.minDate))) {
|
|
326
|
+
date = this.minDate;
|
|
327
|
+
} else if (date.isAfter(dayjs(this.maxDate))) {
|
|
328
|
+
date = this.maxDate;
|
|
329
|
+
}
|
|
330
|
+
} else {
|
|
331
|
+
date = dayjs();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return date.valueOf();
|
|
335
|
+
},
|
|
336
|
+
change(e) {
|
|
337
|
+
const { indexs, values } = e;
|
|
338
|
+
let selectValue = '';
|
|
339
|
+
|
|
340
|
+
// 取默认时间中的值,然后再通过mode和变化值来替换默认值
|
|
341
|
+
let dateArr = [DEFAULT_DATE.year(), DEFAULT_DATE.month() + 1, DEFAULT_DATE.day(), DEFAULT_DATE.hour(), DEFAULT_DATE.minute(), DEFAULT_DATE.second()];
|
|
342
|
+
// 不同mode下的时间是连续值,需要计算不同mode下对应完整时间的初始替换下标即可
|
|
343
|
+
let startFlag = 0;
|
|
344
|
+
switch (this.mode) {
|
|
345
|
+
case 'month-day':
|
|
346
|
+
startFlag = 1;
|
|
347
|
+
break;
|
|
348
|
+
case 'time':
|
|
349
|
+
case 'hour-minute':
|
|
350
|
+
startFlag = 3;
|
|
351
|
+
break;
|
|
352
|
+
case 'minute-second':
|
|
353
|
+
startFlag = 4;
|
|
354
|
+
}
|
|
355
|
+
indexs.forEach((e, i) => {
|
|
356
|
+
let v = parseInt(values[i][e]);
|
|
357
|
+
dateArr[startFlag + i] = v;
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
// 此月份的最大天数
|
|
361
|
+
const maxDay = dayjs(`${dateArr[0]}-${dateArr[1]}`).daysInMonth();
|
|
362
|
+
dateArr[2] = Math.min(maxDay, dateArr[2]) || 1;
|
|
363
|
+
|
|
364
|
+
selectValue = Number(new Date(dateArr[0], dateArr[1] - 1, dateArr[2], dateArr[3], dateArr[4], dateArr[5]));
|
|
365
|
+
selectValue = this.correctValue(selectValue);
|
|
366
|
+
this.innerValue = selectValue;
|
|
367
|
+
this.updateColumnValue(selectValue);
|
|
368
|
+
|
|
369
|
+
// 发出change事件,value为当前选中的时间戳
|
|
370
|
+
this.$emit('change', {
|
|
371
|
+
value: selectValue,
|
|
372
|
+
mode: this.mode,
|
|
373
|
+
});
|
|
374
|
+
},
|
|
375
|
+
cancel() {
|
|
376
|
+
this.$emit('cancel');
|
|
377
|
+
},
|
|
378
|
+
confirm() {
|
|
379
|
+
this.$emit('confirm', this.innerValue);
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
};
|
|
383
|
+
</script>
|
|
384
|
+
|
|
385
|
+
<style lang="scss" scoped>
|
|
386
|
+
.ste-date-picker-root {
|
|
387
|
+
// ::v-deep view {
|
|
388
|
+
// padding: 0 42rpx;
|
|
389
|
+
// }
|
|
390
|
+
}
|
|
391
|
+
</style>
|