|
28 | 28 | </view> |
29 | 29 |
|
30 | 30 | <view v-show="popup" class="uni-date-mask" @click="close"></view> |
31 | | - <view ref="datePicker" v-show="popup" class="uni-date-picker__container"> |
| 31 | + <view ref="datePicker" v-show="popup" class="uni-date-picker__container"> |
32 | 32 | <view v-if="!isRange" class="uni-date-single--x" :style="popover"> |
33 | 33 | <view v-show="hasTime" class="uni-date-changed popup-x-header"> |
34 | 34 | <input class="uni-date__input uni-date-range__input" type="text" v-model="tempSingleDate" |
|
44 | 44 | <view v-if="hasTime" class="popup-x-footer"> |
45 | 45 | <!-- <text class="">此刻</text> --> |
46 | 46 | <text class="confirm" @click="confirmSingleChange">确定</text> |
47 | | - </view> |
| 47 | + </view> |
| 48 | + <view class="uni-date-popper__arrow"></view> |
48 | 49 | </view> |
49 | 50 |
|
50 | 51 | <view v-else class="uni-date-range--x" :style="popover"> |
51 | 52 | <view v-show="hasTime" class="popup-x-header uni-date-changed"> |
52 | 53 | <view class="popup-x-header--datetime"> |
53 | 54 | <input class="uni-date__input uni-date-range__input" type="text" v-model="tempRange.startDate" |
54 | 55 | placeholder="开始日期" /> |
55 | | - <time-picker type="time" v-model="tempRange.startTime" :start="reactStartTime" |
56 | | - :border="false" :disabled="!tempRange.startDate"> |
| 56 | + <time-picker type="time" v-model="tempRange.startTime" :start="reactStartTime" :border="false" |
| 57 | + :disabled="!tempRange.startDate"> |
57 | 58 | <input class="uni-date__input uni-date-range__input" type="text" |
58 | 59 | v-model="tempRange.startTime" placeholder="开始时间" :disabled="!tempRange.startDate" /> |
59 | 60 | </time-picker> |
|
111 | 112 |
|
112 | 113 | export default { |
113 | 114 | components: { |
114 | | - uniCalendar, |
| 115 | + uniCalendar, |
115 | 116 | timePicker |
116 | 117 | }, |
117 | 118 | data() { |
|
357 | 358 | if (systemInfo.windowWidth <= 500) { |
358 | 359 | this.$refs.mobile.open() |
359 | 360 | return |
360 | | - } |
361 | | - this.popover = { |
362 | | - top: '10px' |
| 361 | + } |
| 362 | + this.popover = { |
| 363 | + top: '10px' |
363 | 364 | } |
364 | 365 | // const dateEditor = uni.createSelectorQuery().in(this).select(".uni-date-editor--x") |
365 | 366 | // dateEditor.boundingClientRect(rect => { |
|
370 | 371 | // left = '15px' |
371 | 372 | // } |
372 | 373 | // this.popover = { |
373 | | - // // top: rect.top + rect.height + 15 + 'px', |
| 374 | + // // top: rect.top + rect.height + 15 + 'px', |
374 | 375 | // top: '40px', |
375 | 376 | // left: 0, |
376 | 377 | // } |
|
389 | 390 | }, |
390 | 391 | setEmit(value) { |
391 | 392 | if (this.returnType === "timestamp") { |
392 | | - if (!Array.isArray(value)) { |
| 393 | + if (!Array.isArray(value)) { |
393 | 394 | if (!this.hasTime) { |
394 | 395 | value = value + ' ' + '00:00:00' |
395 | 396 | } |
396 | | - value = Date.parse(new Date(value)) |
397 | | - } else { |
| 397 | + value = this.createTimestamp(value) |
| 398 | + } else { |
398 | 399 | if (!this.hasTime) { |
399 | 400 | value[0] = value[0] + ' ' + '00:00:00' |
400 | 401 | value[1] = value[1] + ' ' + '00:00:00' |
401 | 402 | } |
402 | | - value[0] = Date.parse(new Date(value[0])) |
403 | | - value[1] = Date.parse(new Date(value[1])) |
| 403 | + value[0] = this.createTimestamp(value[0]) |
| 404 | + value[1] = this.createTimestamp(value[1]) |
404 | 405 | } |
405 | 406 | } |
406 | 407 | this.$emit('change', value) |
407 | 408 | this.$emit('input', value) |
| 409 | + }, |
| 410 | + createTimestamp(date) { |
| 411 | + date = this.fixIosDateFormat(date) |
| 412 | + return Date.parse(new Date(date)) |
408 | 413 | }, |
409 | 414 | singleChange(e) { |
410 | 415 | this.tempSingleDate = e.fulldate |
411 | 416 | if (this.hasTime) return |
412 | 417 | this.confirmSingleChange() |
413 | 418 | }, |
414 | 419 |
|
415 | | - confirmSingleChange() { |
416 | | - if (!this.tempSingleDate) { |
417 | | - this.popup = false |
418 | | - return |
| 420 | + confirmSingleChange() { |
| 421 | + if (!this.tempSingleDate) { |
| 422 | + this.popup = false |
| 423 | + return |
419 | 424 | } |
420 | 425 | if (this.hasTime) { |
421 | 426 | this.singleVal = this.tempSingleDate + ' ' + (this.time ? this.time : '00:00:00') |
|
493 | 498 | this.confirmRangeChange() |
494 | 499 | }, |
495 | 500 |
|
496 | | - confirmRangeChange() { |
497 | | - if (!this.tempRange.startDate && !this.tempRange.endDate) { |
498 | | - this.popup = false |
499 | | - return |
| 501 | + confirmRangeChange() { |
| 502 | + if (!this.tempRange.startDate && !this.tempRange.endDate) { |
| 503 | + this.popup = false |
| 504 | + return |
500 | 505 | } |
501 | 506 | let start, end |
502 | 507 | if (!this.hasTime) { |
|
549 | 554 | this.$emit('input', '') |
550 | 555 | } else { |
551 | 556 | this.range.startDate = '' |
552 | | - this.range.endDate = '' |
| 557 | + this.range.endDate = '' |
553 | 558 | this.tempRange = {} |
554 | 559 | this.$refs.left.cale.multipleStatus.before = '' |
555 | 560 | this.$refs.left.cale.multipleStatus.after = '' |
|
568 | 573 | // if (this.popup) this.popup = false |
569 | 574 | }, |
570 | 575 |
|
571 | | - parseDate(date) { |
| 576 | + parseDate(date) { |
| 577 | + date = this.fixIosDateFormat(date) |
572 | 578 | const defVal = new Date(date) |
573 | 579 | const year = defVal.getFullYear() |
574 | 580 | const month = defVal.getMonth() + 1 |
|
588 | 594 | return item < 10 ? '0' + item : item |
589 | 595 | }, |
590 | 596 |
|
| 597 | + //兼容 iOS、safari 日期格式 |
| 598 | + fixIosDateFormat(value) { |
| 599 | + if (typeof value === 'string') { |
| 600 | + value = value.replace(/-/g, '/') |
| 601 | + } |
| 602 | + return value |
| 603 | + }, |
591 | 604 |
|
592 | 605 | leftMonthSwitch(e) { |
593 | 606 | // console.log('leftMonthSwitch 返回:', e) |
|
621 | 634 | position: relative; |
622 | 635 | } |
623 | 636 |
|
624 | | - .uni-date-editor--x:hover .uni-date__icon-clear { |
| 637 | + .uni-date-editor--x:hover .uni-date__icon-clear { |
625 | 638 | position: absolute; |
626 | 639 | top: 5px; |
627 | 640 | right: 0; |
|
650 | 663 | text-align: center; |
651 | 664 | } |
652 | 665 |
|
653 | | - .uni-date-picker__container { |
| 666 | + .uni-date-picker__container { |
654 | 667 | position: relative; |
655 | 668 | /* position: fixed; |
656 | 669 | left: 0; |
|
673 | 686 | z-index: 996; |
674 | 687 | } |
675 | 688 |
|
676 | | - .uni-date-single--x { |
| 689 | + .uni-date-single--x { |
| 690 | + /* padding: 0 8px; */ |
677 | 691 | position: absolute; |
678 | 692 | top: 0; |
679 | 693 | left: 0; |
680 | 694 | z-index: 999; |
681 | 695 | /* width: 375px; */ |
682 | | - border: 1px solid #F1F1F1; |
| 696 | + border: 1px solid #e4e7ed; |
| 697 | + box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%); |
683 | 698 | border-radius: 4px; |
684 | 699 | } |
685 | 700 |
|
686 | | - .uni-date-range--x { |
| 701 | + .uni-date-range--x { |
| 702 | + padding: 0 8px; |
687 | 703 | background-color: #fff; |
688 | 704 | position: absolute; |
689 | 705 | top: 0; |
690 | 706 | left: 0; |
691 | 707 | z-index: 999; |
692 | 708 | /* width: 733px; */ |
693 | | - border: 1px solid #F1F1F1; |
| 709 | + border: 1px solid #e4e7ed; |
| 710 | + box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%); |
694 | 711 | border-radius: 4px; |
695 | 712 | } |
696 | 713 |
|
|
772 | 789 | .uni-date-changed--time-date { |
773 | 790 | color: #333; |
774 | 791 | opacity: 0.6; |
775 | | - } |
| 792 | + } |
| 793 | +
|
| 794 | + /* .uni-date-popper__arrow { |
| 795 | + width: 10px; |
| 796 | + height: 10px; |
| 797 | + top: -6px; |
| 798 | + left: 35px; |
| 799 | + margin-right: 3px; |
| 800 | + border-top-width: 0; |
| 801 | + border-bottom-color: #ebeef5; |
| 802 | + border-width: 6px; |
| 803 | + filter: drop-shadow(0 2px 12px rgba(0,0,0,.03)); |
| 804 | + } |
| 805 | + .uni-date-popper__arrow:after { |
| 806 | + content: " "; |
| 807 | + position: absolute; |
| 808 | + display: block; |
| 809 | + width: 0; |
| 810 | + height: 0; |
| 811 | + border-color: transparent; |
| 812 | + border-style: solid; |
| 813 | + } */ |
776 | 814 |
|
777 | 815 | .mr-50 { |
778 | 816 | margin-right: 50px; |
779 | | - } |
| 817 | + } |
| 818 | +
|
780 | 819 | </style> |
0 commit comments