@vtj/materials 0.10.1-alpha.1 → 0.10.1-alpha.2

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 (53) hide show
  1. package/dist/assets/antdv/index.umd.js +2 -2
  2. package/dist/assets/charts/index.umd.js +2 -2
  3. package/dist/assets/element/index.umd.js +2 -2
  4. package/dist/assets/ui/index.umd.js +2 -2
  5. package/dist/assets/uni-h5/index.umd.js +2 -2
  6. package/dist/assets/uni-ui/index.umd.js +3 -3
  7. package/dist/assets/vant/index.umd.js +2 -2
  8. package/dist/deps/@vtj/charts/index.umd.js +2 -2
  9. package/dist/deps/@vtj/icons/index.umd.js +2 -2
  10. package/dist/deps/@vtj/ui/index.umd.js +2 -2
  11. package/dist/deps/@vtj/uni/index.umd.js +2 -2
  12. package/dist/deps/@vtj/utils/index.umd.js +2 -2
  13. package/dist/deps/mockjs/mock-min.js +10 -0
  14. package/dist/deps/uni-ui/index.umd.js +1 -1
  15. package/dist/deps/uni-ui/style.css +1 -1
  16. package/package.json +5 -5
  17. package/src/uni-ui/components/badge.ts +52 -0
  18. package/src/uni-ui/index.ts +197 -3
  19. package/src/uni-ui/lib/uni-datetime-picker/calendar-item.vue +177 -0
  20. package/src/uni-ui/lib/uni-datetime-picker/calendar.vue +947 -0
  21. package/src/uni-ui/lib/uni-datetime-picker/i18n/en.json +22 -0
  22. package/src/uni-ui/lib/uni-datetime-picker/i18n/index.js +8 -0
  23. package/src/uni-ui/lib/uni-datetime-picker/i18n/zh-Hans.json +22 -0
  24. package/src/uni-ui/lib/uni-datetime-picker/i18n/zh-Hant.json +22 -0
  25. package/src/uni-ui/lib/uni-datetime-picker/time-picker.vue +940 -0
  26. package/src/uni-ui/lib/uni-datetime-picker/uni-datetime-picker.vue +1232 -0
  27. package/src/uni-ui/lib/uni-datetime-picker/util.js +421 -0
  28. package/src/uni-ui/lib/uni-forms/uni-forms.vue +416 -0
  29. package/src/uni-ui/lib/uni-forms/utils.js +293 -0
  30. package/src/uni-ui/lib/uni-forms/validate.js +486 -0
  31. package/src/uni-ui/lib/uni-popup/i18n/en.json +7 -0
  32. package/src/uni-ui/lib/uni-popup/i18n/index.js +8 -0
  33. package/src/uni-ui/lib/uni-popup/i18n/zh-Hans.json +7 -0
  34. package/src/uni-ui/lib/uni-popup/i18n/zh-Hant.json +7 -0
  35. package/src/uni-ui/lib/uni-popup/keypress.js +45 -0
  36. package/src/uni-ui/lib/uni-popup/popup.js +26 -0
  37. package/src/uni-ui/lib/uni-popup/uni-popup.uvue +90 -0
  38. package/src/uni-ui/lib/uni-popup/uni-popup.vue +552 -0
  39. package/src/uni-ui/lib/uni-swipe-action-item/bindingx.js +302 -0
  40. package/src/uni-ui/lib/uni-swipe-action-item/isPC.js +12 -0
  41. package/src/uni-ui/lib/uni-swipe-action-item/mpalipay.js +195 -0
  42. package/src/uni-ui/lib/uni-swipe-action-item/mpother.js +260 -0
  43. package/src/uni-ui/lib/uni-swipe-action-item/mpwxs.js +84 -0
  44. package/src/uni-ui/lib/uni-swipe-action-item/render.js +270 -0
  45. package/src/uni-ui/lib/uni-swipe-action-item/uni-swipe-action-item.vue +494 -0
  46. package/src/uni-ui/lib/uni-swipe-action-item/wx.wxs +341 -0
  47. package/src/uni-ui/lib/uni-th/filter-dropdown.vue +511 -0
  48. package/src/uni-ui/lib/uni-th/uni-th.vue +295 -0
  49. package/src/uni-ui/lib/uni-tr/table-checkbox.vue +179 -0
  50. package/src/uni-ui/lib/uni-tr/uni-tr.vue +184 -0
  51. package/src/uni-ui/lib/uni.scss +76 -0
  52. package/src/uni-ui/polyfill.ts +41 -0
  53. package/src/version.ts +2 -2
@@ -0,0 +1,1232 @@
1
+ <template>
2
+ <view class="uni-date">
3
+ <view class="uni-date-editor" @click="show">
4
+ <slot>
5
+ <view
6
+ class="uni-date-editor--x"
7
+ :class="{
8
+ 'uni-date-editor--x__disabled': disabled,
9
+ 'uni-date-x--border': border
10
+ }">
11
+ <view v-if="!isRange" class="uni-date-x uni-date-single">
12
+ <uni-icons
13
+ class="icon-calendar"
14
+ type="calendar"
15
+ color="#c0c4cc"
16
+ size="22"></uni-icons>
17
+ <view class="uni-date__x-input">{{
18
+ displayValue || singlePlaceholderText
19
+ }}</view>
20
+ </view>
21
+
22
+ <view v-else class="uni-date-x uni-date-range">
23
+ <uni-icons
24
+ class="icon-calendar"
25
+ type="calendar"
26
+ color="#c0c4cc"
27
+ size="22"></uni-icons>
28
+ <view class="uni-date__x-input text-center">{{
29
+ displayRangeValue.startDate || startPlaceholderText
30
+ }}</view>
31
+
32
+ <view class="range-separator">{{ rangeSeparator }}</view>
33
+
34
+ <view class="uni-date__x-input text-center">{{
35
+ displayRangeValue.endDate || endPlaceholderText
36
+ }}</view>
37
+ </view>
38
+
39
+ <view
40
+ v-if="showClearIcon"
41
+ class="uni-date__icon-clear"
42
+ @click.stop="clear">
43
+ <uni-icons type="clear" color="#c0c4cc" size="22"></uni-icons>
44
+ </view>
45
+ </view>
46
+ </slot>
47
+ </view>
48
+
49
+ <view
50
+ v-show="pickerVisible"
51
+ class="uni-date-mask--pc"
52
+ @click="close"></view>
53
+
54
+ <view
55
+ v-if="!isPhone"
56
+ v-show="pickerVisible"
57
+ ref="datePicker"
58
+ class="uni-date-picker__container">
59
+ <view
60
+ v-if="!isRange"
61
+ class="uni-date-single--x"
62
+ :style="pickerPositionStyle">
63
+ <view class="uni-popper__arrow"></view>
64
+
65
+ <view v-if="hasTime" class="uni-date-changed popup-x-header">
66
+ <input
67
+ class="uni-date__input text-center"
68
+ type="text"
69
+ v-model="inputDate"
70
+ :placeholder="selectDateText" />
71
+
72
+ <time-picker
73
+ type="time"
74
+ v-model="pickerTime"
75
+ :border="false"
76
+ :disabled="!inputDate"
77
+ :start="timepickerStartTime"
78
+ :end="timepickerEndTime"
79
+ :hideSecond="hideSecond"
80
+ style="width: 100%">
81
+ <input
82
+ class="uni-date__input text-center"
83
+ type="text"
84
+ v-model="pickerTime"
85
+ :placeholder="selectTimeText"
86
+ :disabled="!inputDate" />
87
+ </time-picker>
88
+ </view>
89
+
90
+ <Calendar
91
+ ref="pcSingle"
92
+ :showMonth="false"
93
+ :start-date="calendarRange.startDate"
94
+ :end-date="calendarRange.endDate"
95
+ :date="calendarDate"
96
+ @change="singleChange"
97
+ :default-value="defaultValue"
98
+ style="padding: 0 8px" />
99
+
100
+ <view v-if="hasTime" class="popup-x-footer">
101
+ <text class="confirm-text" @click="confirmSingleChange">{{
102
+ okText
103
+ }}</text>
104
+ </view>
105
+ </view>
106
+
107
+ <view v-else class="uni-date-range--x" :style="pickerPositionStyle">
108
+ <view class="uni-popper__arrow"></view>
109
+ <view v-if="hasTime" class="popup-x-header uni-date-changed">
110
+ <view class="popup-x-header--datetime">
111
+ <input
112
+ class="uni-date__input uni-date-range__input"
113
+ type="text"
114
+ v-model="tempRange.startDate"
115
+ :placeholder="startDateText" />
116
+
117
+ <time-picker
118
+ type="time"
119
+ v-model="tempRange.startTime"
120
+ :start="timepickerStartTime"
121
+ :border="false"
122
+ :disabled="!tempRange.startDate"
123
+ :hideSecond="hideSecond">
124
+ <input
125
+ class="uni-date__input uni-date-range__input"
126
+ type="text"
127
+ v-model="tempRange.startTime"
128
+ :placeholder="startTimeText"
129
+ :disabled="!tempRange.startDate" />
130
+ </time-picker>
131
+ </view>
132
+
133
+ <uni-icons
134
+ type="arrowthinright"
135
+ color="#999"
136
+ style="line-height: 40px"></uni-icons>
137
+
138
+ <view class="popup-x-header--datetime">
139
+ <input
140
+ class="uni-date__input uni-date-range__input"
141
+ type="text"
142
+ v-model="tempRange.endDate"
143
+ :placeholder="endDateText" />
144
+
145
+ <time-picker
146
+ type="time"
147
+ v-model="tempRange.endTime"
148
+ :end="timepickerEndTime"
149
+ :border="false"
150
+ :disabled="!tempRange.endDate"
151
+ :hideSecond="hideSecond">
152
+ <input
153
+ class="uni-date__input uni-date-range__input"
154
+ type="text"
155
+ v-model="tempRange.endTime"
156
+ :placeholder="endTimeText"
157
+ :disabled="!tempRange.endDate" />
158
+ </time-picker>
159
+ </view>
160
+ </view>
161
+
162
+ <view class="popup-x-body">
163
+ <Calendar
164
+ ref="left"
165
+ :showMonth="false"
166
+ :start-date="calendarRange.startDate"
167
+ :end-date="calendarRange.endDate"
168
+ :range="true"
169
+ :pleStatus="endMultipleStatus"
170
+ @change="leftChange"
171
+ @firstEnterCale="updateRightCale"
172
+ style="padding: 0 8px" />
173
+ <Calendar
174
+ ref="right"
175
+ :showMonth="false"
176
+ :start-date="calendarRange.startDate"
177
+ :end-date="calendarRange.endDate"
178
+ :range="true"
179
+ @change="rightChange"
180
+ :pleStatus="startMultipleStatus"
181
+ @firstEnterCale="updateLeftCale"
182
+ style="padding: 0 8px; border-left: 1px solid #f1f1f1" />
183
+ </view>
184
+
185
+ <view v-if="hasTime" class="popup-x-footer">
186
+ <text @click="clear">{{ clearText }}</text>
187
+ <text class="confirm-text" @click="confirmRangeChange">{{
188
+ okText
189
+ }}</text>
190
+ </view>
191
+ </view>
192
+ </view>
193
+
194
+ <Calendar
195
+ v-if="isPhone"
196
+ ref="mobile"
197
+ :clearDate="false"
198
+ :date="calendarDate"
199
+ :defTime="mobileCalendarTime"
200
+ :start-date="calendarRange.startDate"
201
+ :end-date="calendarRange.endDate"
202
+ :selectableTimes="mobSelectableTime"
203
+ :startPlaceholder="startPlaceholder"
204
+ :endPlaceholder="endPlaceholder"
205
+ :default-value="defaultValue"
206
+ :pleStatus="endMultipleStatus"
207
+ :showMonth="false"
208
+ :range="isRange"
209
+ :hasTime="hasTime"
210
+ :insert="false"
211
+ :hideSecond="hideSecond"
212
+ @confirm="mobileChange"
213
+ @maskClose="close"
214
+ @change="calendarClick" />
215
+ </view>
216
+ </template>
217
+ <script>
218
+ /**
219
+ * DatetimePicker 时间选择器
220
+ * @description 同时支持 PC 和移动端使用日历选择日期和日期范围
221
+ * @tutorial https://ext.dcloud.net.cn/plugin?id=3962
222
+ * @property {String} type 选择器类型
223
+ * @property {String|Number|Array|Date} value 绑定值
224
+ * @property {String} placeholder 单选择时的占位内容
225
+ * @property {String} start 起始时间
226
+ * @property {String} end 终止时间
227
+ * @property {String} start-placeholder 范围选择时开始日期的占位内容
228
+ * @property {String} end-placeholder 范围选择时结束日期的占位内容
229
+ * @property {String} range-separator 选择范围时的分隔符
230
+ * @property {Boolean} border = [true|false] 是否有边框
231
+ * @property {Boolean} disabled = [true|false] 是否禁用
232
+ * @property {Boolean} clearIcon = [true|false] 是否显示清除按钮(仅PC端适用)
233
+ * @property {[String} defaultValue 选择器打开时默认显示的时间
234
+ * @event {Function} change 确定日期时触发的事件
235
+ * @event {Function} maskClick 点击遮罩层触发的事件
236
+ * @event {Function} show 打开弹出层
237
+ * @event {Function} close 关闭弹出层
238
+ * @event {Function} clear 清除上次选中的状态和值
239
+ **/
240
+ import Calendar from './calendar.vue';
241
+ import TimePicker from './time-picker.vue';
242
+ import { initVueI18n } from '@dcloudio/uni-i18n';
243
+ import i18nMessages from './i18n/index.js';
244
+ import {
245
+ getDateTime,
246
+ getDate,
247
+ getTime,
248
+ getDefaultSecond,
249
+ dateCompare,
250
+ checkDate,
251
+ fixIosDateFormat
252
+ } from './util';
253
+
254
+ export default {
255
+ name: 'UniDatetimePicker',
256
+
257
+ options: {
258
+ // #ifdef MP-TOUTIAO
259
+ virtualHost: false,
260
+ // #endif
261
+ // #ifndef MP-TOUTIAO
262
+ virtualHost: true
263
+ // #endif
264
+ },
265
+ components: {
266
+ Calendar,
267
+ TimePicker
268
+ },
269
+ data() {
270
+ return {
271
+ isRange: false,
272
+ hasTime: false,
273
+ displayValue: '',
274
+ inputDate: '',
275
+ calendarDate: '',
276
+ pickerTime: '',
277
+ calendarRange: {
278
+ startDate: '',
279
+ startTime: '',
280
+ endDate: '',
281
+ endTime: ''
282
+ },
283
+ displayRangeValue: {
284
+ startDate: '',
285
+ endDate: ''
286
+ },
287
+ tempRange: {
288
+ startDate: '',
289
+ startTime: '',
290
+ endDate: '',
291
+ endTime: ''
292
+ },
293
+ // 左右日历同步数据
294
+ startMultipleStatus: {
295
+ before: '',
296
+ after: '',
297
+ data: [],
298
+ fulldate: ''
299
+ },
300
+ endMultipleStatus: {
301
+ before: '',
302
+ after: '',
303
+ data: [],
304
+ fulldate: ''
305
+ },
306
+ pickerVisible: false,
307
+ pickerPositionStyle: null,
308
+ isEmitValue: false,
309
+ isPhone: false,
310
+ isFirstShow: true,
311
+ i18nT: () => {}
312
+ };
313
+ },
314
+ props: {
315
+ type: {
316
+ type: String,
317
+ default: 'datetime'
318
+ },
319
+ value: {
320
+ type: [String, Number, Array, Date],
321
+ default: ''
322
+ },
323
+ modelValue: {
324
+ type: [String, Number, Array, Date],
325
+ default: ''
326
+ },
327
+ start: {
328
+ type: [Number, String],
329
+ default: ''
330
+ },
331
+ end: {
332
+ type: [Number, String],
333
+ default: ''
334
+ },
335
+ returnType: {
336
+ type: String,
337
+ default: 'string'
338
+ },
339
+ placeholder: {
340
+ type: String,
341
+ default: ''
342
+ },
343
+ startPlaceholder: {
344
+ type: String,
345
+ default: ''
346
+ },
347
+ endPlaceholder: {
348
+ type: String,
349
+ default: ''
350
+ },
351
+ rangeSeparator: {
352
+ type: String,
353
+ default: '-'
354
+ },
355
+ border: {
356
+ type: [Boolean],
357
+ default: true
358
+ },
359
+ disabled: {
360
+ type: [Boolean],
361
+ default: false
362
+ },
363
+ clearIcon: {
364
+ type: [Boolean],
365
+ default: true
366
+ },
367
+ hideSecond: {
368
+ type: [Boolean],
369
+ default: false
370
+ },
371
+ defaultValue: {
372
+ type: [String, Object, Array],
373
+ default: ''
374
+ }
375
+ },
376
+ watch: {
377
+ type: {
378
+ immediate: true,
379
+ handler(newVal) {
380
+ this.hasTime = newVal.indexOf('time') !== -1;
381
+ this.isRange = newVal.indexOf('range') !== -1;
382
+ }
383
+ },
384
+ // #ifndef VUE3
385
+ value: {
386
+ immediate: true,
387
+ handler(newVal) {
388
+ if (this.isEmitValue) {
389
+ this.isEmitValue = false;
390
+ return;
391
+ }
392
+ this.initPicker(newVal);
393
+ }
394
+ },
395
+ // #endif
396
+ // #ifdef VUE3
397
+ modelValue: {
398
+ immediate: true,
399
+ handler(newVal) {
400
+ if (this.isEmitValue) {
401
+ this.isEmitValue = false;
402
+ return;
403
+ }
404
+ this.initPicker(newVal);
405
+ }
406
+ },
407
+ // #endif
408
+ start: {
409
+ immediate: true,
410
+ handler(newVal) {
411
+ if (!newVal) return;
412
+ this.calendarRange.startDate = getDate(newVal);
413
+ if (this.hasTime) {
414
+ this.calendarRange.startTime = getTime(newVal);
415
+ }
416
+ }
417
+ },
418
+ end: {
419
+ immediate: true,
420
+ handler(newVal) {
421
+ if (!newVal) return;
422
+ this.calendarRange.endDate = getDate(newVal);
423
+ if (this.hasTime) {
424
+ this.calendarRange.endTime = getTime(newVal, this.hideSecond);
425
+ }
426
+ }
427
+ }
428
+ },
429
+ computed: {
430
+ timepickerStartTime() {
431
+ const activeDate = this.isRange
432
+ ? this.tempRange.startDate
433
+ : this.inputDate;
434
+ return activeDate === this.calendarRange.startDate
435
+ ? this.calendarRange.startTime
436
+ : '';
437
+ },
438
+ timepickerEndTime() {
439
+ const activeDate = this.isRange
440
+ ? this.tempRange.endDate
441
+ : this.inputDate;
442
+ return activeDate === this.calendarRange.endDate
443
+ ? this.calendarRange.endTime
444
+ : '';
445
+ },
446
+ mobileCalendarTime() {
447
+ const timeRange = {
448
+ start: this.tempRange.startTime,
449
+ end: this.tempRange.endTime
450
+ };
451
+ return this.isRange ? timeRange : this.pickerTime;
452
+ },
453
+ mobSelectableTime() {
454
+ return {
455
+ start: this.calendarRange.startTime,
456
+ end: this.calendarRange.endTime
457
+ };
458
+ },
459
+ datePopupWidth() {
460
+ // todo
461
+ return this.isRange ? 653 : 301;
462
+ },
463
+
464
+ /**
465
+ * for i18n
466
+ */
467
+ singlePlaceholderText() {
468
+ return (
469
+ this.placeholder ||
470
+ (this.type === 'date' ? this.selectDateText : this.selectDateTimeText)
471
+ );
472
+ },
473
+ startPlaceholderText() {
474
+ return this.startPlaceholder || this.startDateText;
475
+ },
476
+ endPlaceholderText() {
477
+ return this.endPlaceholder || this.endDateText;
478
+ },
479
+ selectDateText() {
480
+ return this.i18nT('uni-datetime-picker.selectDate');
481
+ },
482
+ selectDateTimeText() {
483
+ return this.i18nT('uni-datetime-picker.selectDateTime');
484
+ },
485
+ selectTimeText() {
486
+ return this.i18nT('uni-datetime-picker.selectTime');
487
+ },
488
+ startDateText() {
489
+ return (
490
+ this.startPlaceholder || this.i18nT('uni-datetime-picker.startDate')
491
+ );
492
+ },
493
+ startTimeText() {
494
+ return this.i18nT('uni-datetime-picker.startTime');
495
+ },
496
+ endDateText() {
497
+ return this.endPlaceholder || this.i18nT('uni-datetime-picker.endDate');
498
+ },
499
+ endTimeText() {
500
+ return this.i18nT('uni-datetime-picker.endTime');
501
+ },
502
+ okText() {
503
+ return this.i18nT('uni-datetime-picker.ok');
504
+ },
505
+ clearText() {
506
+ return this.i18nT('uni-datetime-picker.clear');
507
+ },
508
+ showClearIcon() {
509
+ return (
510
+ this.clearIcon &&
511
+ !this.disabled &&
512
+ (this.displayValue ||
513
+ (this.displayRangeValue.startDate &&
514
+ this.displayRangeValue.endDate))
515
+ );
516
+ }
517
+ },
518
+ created() {
519
+ this.initI18nT();
520
+ this.platform();
521
+ },
522
+ methods: {
523
+ initI18nT() {
524
+ const vueI18n = initVueI18n(i18nMessages);
525
+ this.i18nT = vueI18n.t;
526
+ },
527
+ initPicker(newVal) {
528
+ if (
529
+ (!newVal && !this.defaultValue) ||
530
+ (Array.isArray(newVal) && !newVal.length)
531
+ ) {
532
+ this.$nextTick(() => {
533
+ this.clear(false);
534
+ });
535
+ return;
536
+ }
537
+
538
+ if (!Array.isArray(newVal) && !this.isRange) {
539
+ if (newVal) {
540
+ this.displayValue =
541
+ this.inputDate =
542
+ this.calendarDate =
543
+ getDate(newVal);
544
+ if (this.hasTime) {
545
+ this.pickerTime = getTime(newVal, this.hideSecond);
546
+ this.displayValue = `${this.displayValue} ${this.pickerTime}`;
547
+ }
548
+ } else if (this.defaultValue) {
549
+ this.inputDate = this.calendarDate = getDate(this.defaultValue);
550
+ if (this.hasTime) {
551
+ this.pickerTime = getTime(this.defaultValue, this.hideSecond);
552
+ }
553
+ }
554
+ } else {
555
+ const [before, after] = newVal;
556
+ if (!before && !after) return;
557
+ const beforeDate = getDate(before);
558
+ const beforeTime = getTime(before, this.hideSecond);
559
+
560
+ const afterDate = getDate(after);
561
+ const afterTime = getTime(after, this.hideSecond);
562
+ const startDate = beforeDate;
563
+ const endDate = afterDate;
564
+ this.displayRangeValue.startDate = this.tempRange.startDate =
565
+ startDate;
566
+ this.displayRangeValue.endDate = this.tempRange.endDate = endDate;
567
+
568
+ if (this.hasTime) {
569
+ this.displayRangeValue.startDate = `${beforeDate} ${beforeTime}`;
570
+ this.displayRangeValue.endDate = `${afterDate} ${afterTime}`;
571
+ this.tempRange.startTime = beforeTime;
572
+ this.tempRange.endTime = afterTime;
573
+ }
574
+ const defaultRange = {
575
+ before: beforeDate,
576
+ after: afterDate
577
+ };
578
+ this.startMultipleStatus = Object.assign(
579
+ {},
580
+ this.startMultipleStatus,
581
+ defaultRange,
582
+ {
583
+ which: 'right'
584
+ }
585
+ );
586
+ this.endMultipleStatus = Object.assign(
587
+ {},
588
+ this.endMultipleStatus,
589
+ defaultRange,
590
+ {
591
+ which: 'left'
592
+ }
593
+ );
594
+ }
595
+ },
596
+ updateLeftCale(e) {
597
+ const left = this.$refs.left;
598
+ // 设置范围选
599
+ left.cale.setHoverMultiple(e.after);
600
+ left.setDate(this.$refs.left.nowDate.fullDate);
601
+ },
602
+ updateRightCale(e) {
603
+ const right = this.$refs.right;
604
+ // 设置范围选
605
+ right.cale.setHoverMultiple(e.after);
606
+ right.setDate(this.$refs.right.nowDate.fullDate);
607
+ },
608
+ platform() {
609
+ if (typeof navigator !== 'undefined') {
610
+ this.isPhone =
611
+ navigator.userAgent.toLowerCase().indexOf('mobile') !== -1;
612
+ return;
613
+ }
614
+ // #ifdef MP-WEIXIN
615
+ const { windowWidth } = uni.getWindowInfo();
616
+ // #endif
617
+ // // #ifndef MP-WEIXIN
618
+ // const {
619
+ // windowWidth
620
+ // } = uni.getSystemInfoSync()
621
+ // // #endif
622
+ this.isPhone = windowWidth <= 500;
623
+ this.windowWidth = windowWidth;
624
+ },
625
+ show() {
626
+ this.$emit('show');
627
+ if (this.disabled) {
628
+ return;
629
+ }
630
+ this.platform();
631
+ if (this.isPhone) {
632
+ setTimeout(() => {
633
+ this.$refs.mobile.open();
634
+ }, 0);
635
+ return;
636
+ }
637
+ this.pickerPositionStyle = {
638
+ top: '10px'
639
+ };
640
+ const dateEditor = uni
641
+ .createSelectorQuery()
642
+ .in(this)
643
+ .select('.uni-date-editor');
644
+ dateEditor
645
+ .boundingClientRect((rect) => {
646
+ if (this.windowWidth - rect.left < this.datePopupWidth) {
647
+ this.pickerPositionStyle.right = 0;
648
+ }
649
+ })
650
+ .exec();
651
+ setTimeout(() => {
652
+ this.pickerVisible = !this.pickerVisible;
653
+ if (!this.isPhone && this.isRange && this.isFirstShow) {
654
+ this.isFirstShow = false;
655
+ const { startDate, endDate } = this.calendarRange;
656
+ if (startDate && endDate) {
657
+ if (this.diffDate(startDate, endDate) < 30) {
658
+ this.$refs.right.changeMonth('pre');
659
+ }
660
+ } else {
661
+ // this.$refs.right.changeMonth('next')
662
+ if (this.isPhone) {
663
+ this.$refs.right.cale.lastHover = false;
664
+ }
665
+ }
666
+ }
667
+ }, 50);
668
+ },
669
+ close() {
670
+ setTimeout(() => {
671
+ this.pickerVisible = false;
672
+ this.$emit('maskClick', this.value);
673
+ this.$refs.mobile && this.$refs.mobile.close();
674
+ }, 20);
675
+ },
676
+ setEmit(value) {
677
+ if (this.returnType === 'timestamp' || this.returnType === 'date') {
678
+ if (!Array.isArray(value)) {
679
+ if (!this.hasTime) {
680
+ value = value + ' ' + '00:00:00';
681
+ }
682
+ value = this.createTimestamp(value);
683
+ if (this.returnType === 'date') {
684
+ value = new Date(value);
685
+ }
686
+ } else {
687
+ if (!this.hasTime) {
688
+ value[0] = value[0] + ' ' + '00:00:00';
689
+ value[1] = value[1] + ' ' + '00:00:00';
690
+ }
691
+ value[0] = this.createTimestamp(value[0]);
692
+ value[1] = this.createTimestamp(value[1]);
693
+ if (this.returnType === 'date') {
694
+ value[0] = new Date(value[0]);
695
+ value[1] = new Date(value[1]);
696
+ }
697
+ }
698
+ }
699
+
700
+ this.$emit('update:modelValue', value);
701
+ this.$emit('input', value);
702
+ this.$emit('change', value);
703
+ this.isEmitValue = true;
704
+ },
705
+ createTimestamp(date) {
706
+ date = fixIosDateFormat(date);
707
+ return Date.parse(new Date(date));
708
+ },
709
+ singleChange(e) {
710
+ this.calendarDate = this.inputDate = e.fulldate;
711
+ if (this.hasTime) return;
712
+ this.confirmSingleChange();
713
+ },
714
+ confirmSingleChange() {
715
+ if (!checkDate(this.inputDate)) {
716
+ const now = new Date();
717
+ this.calendarDate = this.inputDate = getDate(now);
718
+ this.pickerTime = getTime(now, this.hideSecond);
719
+ }
720
+
721
+ let startLaterInputDate = false;
722
+ let startDate, startTime;
723
+ if (this.start) {
724
+ let startString = this.start;
725
+ if (typeof this.start === 'number') {
726
+ startString = getDateTime(this.start, this.hideSecond);
727
+ }
728
+ [startDate, startTime] = startString.split(' ');
729
+ if (this.start && !dateCompare(startDate, this.inputDate)) {
730
+ startLaterInputDate = true;
731
+ this.inputDate = startDate;
732
+ }
733
+ }
734
+
735
+ let endEarlierInputDate = false;
736
+ let endDate, endTime;
737
+ if (this.end) {
738
+ let endString = this.end;
739
+ if (typeof this.end === 'number') {
740
+ endString = getDateTime(this.end, this.hideSecond);
741
+ }
742
+ [endDate, endTime] = endString.split(' ');
743
+ if (this.end && !dateCompare(this.inputDate, endDate)) {
744
+ endEarlierInputDate = true;
745
+ this.inputDate = endDate;
746
+ }
747
+ }
748
+ if (this.hasTime) {
749
+ if (startLaterInputDate) {
750
+ this.pickerTime = startTime || getDefaultSecond(this.hideSecond);
751
+ }
752
+ if (endEarlierInputDate) {
753
+ this.pickerTime = endTime || getDefaultSecond(this.hideSecond);
754
+ }
755
+ if (!this.pickerTime) {
756
+ this.pickerTime = getTime(Date.now(), this.hideSecond);
757
+ }
758
+ this.displayValue = `${this.inputDate} ${this.pickerTime}`;
759
+ } else {
760
+ this.displayValue = this.inputDate;
761
+ }
762
+ this.setEmit(this.displayValue);
763
+ this.pickerVisible = false;
764
+ },
765
+ leftChange(e) {
766
+ const { before, after } = e.range;
767
+ this.rangeChange(before, after);
768
+ const obj = {
769
+ before: e.range.before,
770
+ after: e.range.after,
771
+ data: e.range.data,
772
+ fulldate: e.fulldate
773
+ };
774
+ this.startMultipleStatus = Object.assign(
775
+ {},
776
+ this.startMultipleStatus,
777
+ obj
778
+ );
779
+ this.$emit('calendarClick', e);
780
+ },
781
+ rightChange(e) {
782
+ const { before, after } = e.range;
783
+ this.rangeChange(before, after);
784
+ const obj = {
785
+ before: e.range.before,
786
+ after: e.range.after,
787
+ data: e.range.data,
788
+ fulldate: e.fulldate
789
+ };
790
+ this.endMultipleStatus = Object.assign({}, this.endMultipleStatus, obj);
791
+ this.$emit('calendarClick', e);
792
+ },
793
+ mobileChange(e) {
794
+ if (this.isRange) {
795
+ const { before, after } = e.range;
796
+ if (!before) {
797
+ return;
798
+ }
799
+
800
+ this.handleStartAndEnd(before, after, true);
801
+ if (this.hasTime) {
802
+ const { startTime, endTime } = e.timeRange;
803
+ this.tempRange.startTime = startTime;
804
+ this.tempRange.endTime = endTime;
805
+ }
806
+ this.confirmRangeChange();
807
+ } else {
808
+ if (this.hasTime) {
809
+ this.displayValue = e.fulldate + ' ' + e.time;
810
+ } else {
811
+ this.displayValue = e.fulldate;
812
+ }
813
+ this.setEmit(this.displayValue);
814
+ }
815
+ this.$refs.mobile.close();
816
+ },
817
+ rangeChange(before, after) {
818
+ if (!(before && after)) return;
819
+ this.handleStartAndEnd(before, after, true);
820
+ if (this.hasTime) return;
821
+ this.confirmRangeChange();
822
+ },
823
+ confirmRangeChange() {
824
+ if (!this.tempRange.startDate || !this.tempRange.endDate) {
825
+ this.pickerVisible = false;
826
+ return;
827
+ }
828
+ if (!checkDate(this.tempRange.startDate)) {
829
+ this.tempRange.startDate = getDate(Date.now());
830
+ }
831
+ if (!checkDate(this.tempRange.endDate)) {
832
+ this.tempRange.endDate = getDate(Date.now());
833
+ }
834
+
835
+ let start, end;
836
+
837
+ let startDateLaterRangeStartDate = false;
838
+ let startDateLaterRangeEndDate = false;
839
+ let startDate, startTime;
840
+ if (this.start) {
841
+ let startString = this.start;
842
+ if (typeof this.start === 'number') {
843
+ startString = getDateTime(this.start, this.hideSecond);
844
+ }
845
+ [startDate, startTime] = startString.split(' ');
846
+ if (
847
+ this.start &&
848
+ !dateCompare(
849
+ this.start,
850
+ `${this.tempRange.startDate} ${this.tempRange.startTime}`
851
+ )
852
+ ) {
853
+ startDateLaterRangeStartDate = true;
854
+ this.tempRange.startDate = startDate;
855
+ }
856
+ if (
857
+ this.start &&
858
+ !dateCompare(
859
+ this.start,
860
+ `${this.tempRange.endDate} ${this.tempRange.endTime}`
861
+ )
862
+ ) {
863
+ startDateLaterRangeEndDate = true;
864
+ this.tempRange.endDate = startDate;
865
+ }
866
+ }
867
+ let endDateEarlierRangeStartDate = false;
868
+ let endDateEarlierRangeEndDate = false;
869
+ let endDate, endTime;
870
+ if (this.end) {
871
+ let endString = this.end;
872
+ if (typeof this.end === 'number') {
873
+ endString = getDateTime(this.end, this.hideSecond);
874
+ }
875
+ [endDate, endTime] = endString.split(' ');
876
+
877
+ if (
878
+ this.end &&
879
+ !dateCompare(
880
+ `${this.tempRange.startDate} ${this.tempRange.startTime}`,
881
+ this.end
882
+ )
883
+ ) {
884
+ endDateEarlierRangeStartDate = true;
885
+ this.tempRange.startDate = endDate;
886
+ }
887
+ if (
888
+ this.end &&
889
+ !dateCompare(
890
+ `${this.tempRange.endDate} ${this.tempRange.endTime}`,
891
+ this.end
892
+ )
893
+ ) {
894
+ endDateEarlierRangeEndDate = true;
895
+ this.tempRange.endDate = endDate;
896
+ }
897
+ }
898
+ if (!this.hasTime) {
899
+ start = this.displayRangeValue.startDate = this.tempRange.startDate;
900
+ end = this.displayRangeValue.endDate = this.tempRange.endDate;
901
+ } else {
902
+ if (startDateLaterRangeStartDate) {
903
+ this.tempRange.startTime =
904
+ startTime || getDefaultSecond(this.hideSecond);
905
+ } else if (endDateEarlierRangeStartDate) {
906
+ this.tempRange.startTime =
907
+ endTime || getDefaultSecond(this.hideSecond);
908
+ }
909
+ if (!this.tempRange.startTime) {
910
+ this.tempRange.startTime = getTime(Date.now(), this.hideSecond);
911
+ }
912
+
913
+ if (startDateLaterRangeEndDate) {
914
+ this.tempRange.endTime =
915
+ startTime || getDefaultSecond(this.hideSecond);
916
+ } else if (endDateEarlierRangeEndDate) {
917
+ this.tempRange.endTime =
918
+ endTime || getDefaultSecond(this.hideSecond);
919
+ }
920
+ if (!this.tempRange.endTime) {
921
+ this.tempRange.endTime = getTime(Date.now(), this.hideSecond);
922
+ }
923
+ start =
924
+ this.displayRangeValue.startDate = `${this.tempRange.startDate} ${this.tempRange.startTime}`;
925
+ end =
926
+ this.displayRangeValue.endDate = `${this.tempRange.endDate} ${this.tempRange.endTime}`;
927
+ }
928
+ if (!dateCompare(start, end)) {
929
+ [start, end] = [end, start];
930
+ }
931
+ this.displayRangeValue.startDate = start;
932
+ this.displayRangeValue.endDate = end;
933
+ const displayRange = [start, end];
934
+ this.setEmit(displayRange);
935
+ this.pickerVisible = false;
936
+ },
937
+ handleStartAndEnd(before, after, temp = false) {
938
+ if (!before) return;
939
+ if (!after) after = before;
940
+ const type = temp ? 'tempRange' : 'range';
941
+ const isStartEarlierEnd = dateCompare(before, after);
942
+ this[type].startDate = isStartEarlierEnd ? before : after;
943
+ this[type].endDate = isStartEarlierEnd ? after : before;
944
+ },
945
+ /**
946
+ * 比较时间大小
947
+ */
948
+ dateCompare(startDate, endDate) {
949
+ // 计算截止时间
950
+ startDate = new Date(startDate.replace('-', '/').replace('-', '/'));
951
+ // 计算详细项的截止时间
952
+ endDate = new Date(endDate.replace('-', '/').replace('-', '/'));
953
+ return startDate <= endDate;
954
+ },
955
+
956
+ /**
957
+ * 比较时间差
958
+ */
959
+ diffDate(startDate, endDate) {
960
+ // 计算截止时间
961
+ startDate = new Date(startDate.replace('-', '/').replace('-', '/'));
962
+ // 计算详细项的截止时间
963
+ endDate = new Date(endDate.replace('-', '/').replace('-', '/'));
964
+ const diff = (endDate - startDate) / (24 * 60 * 60 * 1000);
965
+ return Math.abs(diff);
966
+ },
967
+
968
+ clear(needEmit = true) {
969
+ if (!this.isRange) {
970
+ this.displayValue = '';
971
+ this.inputDate = '';
972
+ this.pickerTime = '';
973
+ if (this.isPhone) {
974
+ this.$refs.mobile && this.$refs.mobile.clearCalender();
975
+ } else {
976
+ this.$refs.pcSingle && this.$refs.pcSingle.clearCalender();
977
+ }
978
+ if (needEmit) {
979
+ this.$emit('change', '');
980
+ this.$emit('input', '');
981
+ this.$emit('update:modelValue', '');
982
+ }
983
+ } else {
984
+ this.displayRangeValue.startDate = '';
985
+ this.displayRangeValue.endDate = '';
986
+ this.tempRange.startDate = '';
987
+ this.tempRange.startTime = '';
988
+ this.tempRange.endDate = '';
989
+ this.tempRange.endTime = '';
990
+ if (this.isPhone) {
991
+ this.$refs.mobile && this.$refs.mobile.clearCalender();
992
+ } else {
993
+ this.$refs.left && this.$refs.left.clearCalender();
994
+ this.$refs.right && this.$refs.right.clearCalender();
995
+ this.$refs.right && this.$refs.right.changeMonth('next');
996
+ }
997
+ if (needEmit) {
998
+ this.$emit('change', []);
999
+ this.$emit('input', []);
1000
+ this.$emit('update:modelValue', []);
1001
+ }
1002
+ }
1003
+ },
1004
+
1005
+ calendarClick(e) {
1006
+ this.$emit('calendarClick', e);
1007
+ }
1008
+ }
1009
+ };
1010
+ </script>
1011
+
1012
+ <style lang="scss">
1013
+ $uni-primary: #007aff !default;
1014
+
1015
+ .uni-date {
1016
+ width: 100%;
1017
+ flex: 1;
1018
+ }
1019
+
1020
+ .uni-date-x {
1021
+ display: flex;
1022
+ flex-direction: row;
1023
+ align-items: center;
1024
+ justify-content: center;
1025
+ border-radius: 4px;
1026
+ background-color: #fff;
1027
+ color: #666;
1028
+ font-size: 14px;
1029
+ flex: 1;
1030
+
1031
+ .icon-calendar {
1032
+ padding-left: 3px;
1033
+ }
1034
+
1035
+ .range-separator {
1036
+ height: 35px;
1037
+ /* #ifndef MP */
1038
+ padding: 0 2px;
1039
+ /* #endif */
1040
+ line-height: 35px;
1041
+ }
1042
+ }
1043
+
1044
+ .uni-date-x--border {
1045
+ box-sizing: border-box;
1046
+ border-radius: 4px;
1047
+ border: 1px solid #e5e5e5;
1048
+ }
1049
+
1050
+ .uni-date-editor--x {
1051
+ display: flex;
1052
+ align-items: center;
1053
+ position: relative;
1054
+ }
1055
+
1056
+ .uni-date-editor--x .uni-date__icon-clear {
1057
+ padding-right: 3px;
1058
+ display: flex;
1059
+ align-items: center;
1060
+ /* #ifdef H5 */
1061
+ cursor: pointer;
1062
+ /* #endif */
1063
+ }
1064
+
1065
+ .uni-date__x-input {
1066
+ width: auto;
1067
+ height: 35px;
1068
+ /* #ifndef MP */
1069
+ padding-left: 5px;
1070
+ /* #endif */
1071
+ position: relative;
1072
+ flex: 1;
1073
+ line-height: 35px;
1074
+ font-size: 14px;
1075
+ overflow: hidden;
1076
+ }
1077
+
1078
+ .text-center {
1079
+ text-align: center;
1080
+ }
1081
+
1082
+ .uni-date__input {
1083
+ height: 40px;
1084
+ width: 100%;
1085
+ line-height: 40px;
1086
+ font-size: 14px;
1087
+ }
1088
+
1089
+ .uni-date-range__input {
1090
+ text-align: center;
1091
+ max-width: 142px;
1092
+ }
1093
+
1094
+ .uni-date-picker__container {
1095
+ position: relative;
1096
+ }
1097
+
1098
+ .uni-date-mask--pc {
1099
+ position: fixed;
1100
+ bottom: 0px;
1101
+ top: 0px;
1102
+ left: 0px;
1103
+ right: 0px;
1104
+ background-color: rgba(0, 0, 0, 0);
1105
+ transition-duration: 0.3s;
1106
+ z-index: 996;
1107
+ }
1108
+
1109
+ .uni-date-single--x {
1110
+ background-color: #fff;
1111
+ position: absolute;
1112
+ top: 0;
1113
+ z-index: 999;
1114
+ border: 1px solid #ebeef5;
1115
+ box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
1116
+ border-radius: 4px;
1117
+ }
1118
+
1119
+ .uni-date-range--x {
1120
+ background-color: #fff;
1121
+ position: absolute;
1122
+ top: 0;
1123
+ z-index: 999;
1124
+ border: 1px solid #ebeef5;
1125
+ box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
1126
+ border-radius: 4px;
1127
+ }
1128
+
1129
+ .uni-date-editor--x__disabled {
1130
+ opacity: 0.4;
1131
+ cursor: default;
1132
+ }
1133
+
1134
+ .uni-date-editor--logo {
1135
+ width: 16px;
1136
+ height: 16px;
1137
+ vertical-align: middle;
1138
+ }
1139
+
1140
+ /* 添加时间 */
1141
+ .popup-x-header {
1142
+ /* #ifndef APP-NVUE */
1143
+ display: flex;
1144
+ /* #endif */
1145
+ flex-direction: row;
1146
+ }
1147
+
1148
+ .popup-x-header--datetime {
1149
+ /* #ifndef APP-NVUE */
1150
+ display: flex;
1151
+ /* #endif */
1152
+ flex-direction: row;
1153
+ flex: 1;
1154
+ }
1155
+
1156
+ .popup-x-body {
1157
+ display: flex;
1158
+ }
1159
+
1160
+ .popup-x-footer {
1161
+ padding: 0 15px;
1162
+ border-top-color: #f1f1f1;
1163
+ border-top-style: solid;
1164
+ border-top-width: 1px;
1165
+ line-height: 40px;
1166
+ text-align: right;
1167
+ color: #666;
1168
+ }
1169
+
1170
+ .popup-x-footer text:hover {
1171
+ color: $uni-primary;
1172
+ cursor: pointer;
1173
+ opacity: 0.8;
1174
+ }
1175
+
1176
+ .popup-x-footer .confirm-text {
1177
+ margin-left: 20px;
1178
+ color: $uni-primary;
1179
+ }
1180
+
1181
+ .uni-date-changed {
1182
+ text-align: center;
1183
+ color: #333;
1184
+ border-bottom-color: #f1f1f1;
1185
+ border-bottom-style: solid;
1186
+ border-bottom-width: 1px;
1187
+ }
1188
+
1189
+ .uni-date-changed--time text {
1190
+ height: 50px;
1191
+ line-height: 50px;
1192
+ }
1193
+
1194
+ .uni-date-changed .uni-date-changed--time {
1195
+ flex: 1;
1196
+ }
1197
+
1198
+ .uni-date-changed--time-date {
1199
+ color: #333;
1200
+ opacity: 0.6;
1201
+ }
1202
+
1203
+ .mr-50 {
1204
+ margin-right: 50px;
1205
+ }
1206
+
1207
+ /* picker 弹出层通用的指示小三角, todo:扩展至上下左右方向定位 */
1208
+ .uni-popper__arrow,
1209
+ .uni-popper__arrow::after {
1210
+ position: absolute;
1211
+ display: block;
1212
+ width: 0;
1213
+ height: 0;
1214
+ border: 6px solid transparent;
1215
+ border-top-width: 0;
1216
+ }
1217
+
1218
+ .uni-popper__arrow {
1219
+ filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.03));
1220
+ top: -6px;
1221
+ left: 10%;
1222
+ margin-right: 3px;
1223
+ border-bottom-color: #ebeef5;
1224
+ }
1225
+
1226
+ .uni-popper__arrow::after {
1227
+ content: ' ';
1228
+ top: 1px;
1229
+ margin-left: -6px;
1230
+ border-bottom-color: #fff;
1231
+ }
1232
+ </style>