|
58 | 58 |
|
59 | 59 | <view class="uni-calendar__weeks" v-for="(item,weekIndex) in weeks" :key="weekIndex">
|
60 | 60 | <view class="uni-calendar__weeks-item" v-for="(weeks,weeksIndex) in item" :key="weeksIndex">
|
61 |
| - <calendar-item class="uni-calendar-item--hook" :weeks="weeks" :calendar="calendar" |
62 |
| - :selected="selected" :checkHover="range" @change="choiceDate" |
63 |
| - @handleMouse="handleMouse"> |
| 61 | + <calendar-item class="uni-calendar-item--hook" :weeks="weeks" :calendar="calendar" :selected="selected" |
| 62 | + :checkHover="range" @change="choiceDate" @handleMouse="handleMouse"> |
64 | 63 | </calendar-item>
|
65 | 64 | </view>
|
66 | 65 | </view>
|
|
101 | 100 | </template>
|
102 | 101 |
|
103 | 102 | <script>
|
104 |
| - import { Calendar, getDate, getTime } from './util.js'; |
| 103 | + import { |
| 104 | + Calendar, |
| 105 | + getDate, |
| 106 | + getTime |
| 107 | + } from './util.js'; |
105 | 108 | import calendarItem from './calendar-item.vue'
|
106 | 109 | import timePicker from './time-picker.vue'
|
107 | 110 |
|
108 |
| - import { initVueI18n } from '@dcloudio/uni-i18n' |
| 111 | + import { |
| 112 | + initVueI18n |
| 113 | + } from '@dcloudio/uni-i18n' |
109 | 114 | import i18nMessages from './i18n/index.js'
|
110 |
| - const { t } = initVueI18n(i18nMessages) |
| 115 | + const { |
| 116 | + t |
| 117 | + } = initVueI18n(i18nMessages) |
111 | 118 |
|
112 | 119 | /**
|
113 | 120 | * Calendar 日历
|
|
134 | 141 | calendarItem,
|
135 | 142 | timePicker
|
136 | 143 | },
|
| 144 | +
|
| 145 | + options: { |
| 146 | + // #ifdef MP-TOUTIAO |
| 147 | + virtualHost: false, |
| 148 | + // #endif |
| 149 | + // #ifndef MP-TOUTIAO |
| 150 | + virtualHost: true |
| 151 | + // #endif |
| 152 | + }, |
137 | 153 | props: {
|
138 | 154 | date: {
|
139 | 155 | type: String,
|
|
163 | 179 | type: String,
|
164 | 180 | default: ''
|
165 | 181 | },
|
166 |
| - startPlaceholder: { |
167 |
| - type: String, |
| 182 | + startPlaceholder: { |
| 183 | + type: String, |
168 | 184 | default: ''
|
169 | 185 | },
|
170 | 186 | endPlaceholder: {
|
|
210 | 226 | }
|
211 | 227 | }
|
212 | 228 | },
|
213 |
| - defaultValue: { |
214 |
| - type: [String, Object, Array], |
215 |
| - default: '' |
216 |
| - } |
| 229 | + defaultValue: { |
| 230 | + type: [String, Object, Array], |
| 231 | + default: '' |
| 232 | + } |
217 | 233 | },
|
218 | 234 | data() {
|
219 | 235 | return {
|
|
260 | 276 | },
|
261 | 277 | startDate(val) {
|
262 | 278 | // 字节小程序 watch 早于 created
|
263 |
| - if(!this.cale){ |
| 279 | + if (!this.cale) { |
264 | 280 | return
|
265 | 281 | }
|
266 | 282 | this.cale.setStartDate(val)
|
|
269 | 285 | },
|
270 | 286 | endDate(val) {
|
271 | 287 | // 字节小程序 watch 早于 created
|
272 |
| - if(!this.cale){ |
| 288 | + if (!this.cale) { |
273 | 289 | return
|
274 | 290 | }
|
275 | 291 | this.cale.setEndDate(val)
|
|
278 | 294 | },
|
279 | 295 | selected(newVal) {
|
280 | 296 | // 字节小程序 watch 早于 created
|
281 |
| - if(!this.cale){ |
| 297 | + if (!this.cale) { |
282 | 298 | return
|
283 | 299 | }
|
284 | 300 | this.cale.setSelectInfo(this.nowDate.fullDate, newVal)
|
|
309 | 325 | this.cale.lastHover = false
|
310 | 326 | }
|
311 | 327 | } else {
|
312 |
| - // 字节小程序 watch 早于 created |
313 |
| - if(!this.cale){ |
314 |
| - return |
315 |
| - } |
| 328 | + // 字节小程序 watch 早于 created |
| 329 | + if (!this.cale) { |
| 330 | + return |
| 331 | + } |
316 | 332 |
|
317 | 333 | this.cale.setDefaultMultiple(before, after)
|
318 | 334 | if (which === 'left' && before) {
|
319 | 335 | this.setDate(before)
|
320 | 336 | this.weeks = this.cale.weeks
|
321 |
| - } else if(after) { |
| 337 | + } else if (after) { |
322 | 338 | this.setDate(after)
|
323 | 339 | this.weeks = this.cale.weeks
|
324 | 340 | }
|
|
423 | 439 | },
|
424 | 440 | // 蒙版点击事件
|
425 | 441 | maskClick() {
|
426 |
| - this.close() |
| 442 | + this.close() |
427 | 443 | this.$emit('maskClose')
|
428 | 444 | },
|
429 | 445 |
|
|
454 | 470 | * @param {Object} date
|
455 | 471 | */
|
456 | 472 | init(date) {
|
457 |
| - // 字节小程序 watch 早于 created |
458 |
| - if(!this.cale){ |
| 473 | + // 字节小程序 watch 早于 created |
| 474 | + if (!this.cale) { |
459 | 475 | return
|
460 | 476 | }
|
461 | 477 | this.cale.setDate(date || new Date())
|
462 | 478 | this.weeks = this.cale.weeks
|
463 | 479 | this.nowDate = this.cale.getInfo(date)
|
464 |
| - this.calendar = {...this.nowDate} |
465 |
| - if(!date){ |
466 |
| - // 优化date为空默认不选中今天 |
467 |
| - this.calendar.fullDate = '' |
468 |
| - if(this.defaultValue && !this.range){ |
469 |
| - // 暂时只支持移动端非范围选择 |
470 |
| - const defaultDate = new Date(this.defaultValue) |
471 |
| - const fullDate = getDate(defaultDate) |
472 |
| - const year = defaultDate.getFullYear() |
473 |
| - const month = defaultDate.getMonth()+1 |
474 |
| - const date = defaultDate.getDate() |
475 |
| - const day = defaultDate.getDay() |
476 |
| - this.calendar = { |
477 |
| - fullDate, |
478 |
| - year, |
479 |
| - month, |
480 |
| - date, |
481 |
| - day |
482 |
| - }, |
483 |
| - this.tempSingleDate = fullDate |
484 |
| - this.time = getTime(defaultDate, this.hideSecond) |
485 |
| - } |
486 |
| - } |
| 480 | + this.calendar = { |
| 481 | + ...this.nowDate |
| 482 | + } |
| 483 | + if (!date) { |
| 484 | + // 优化date为空默认不选中今天 |
| 485 | + this.calendar.fullDate = '' |
| 486 | + if (this.defaultValue && !this.range) { |
| 487 | + // 暂时只支持移动端非范围选择 |
| 488 | + const defaultDate = new Date(this.defaultValue) |
| 489 | + const fullDate = getDate(defaultDate) |
| 490 | + const year = defaultDate.getFullYear() |
| 491 | + const month = defaultDate.getMonth() + 1 |
| 492 | + const date = defaultDate.getDate() |
| 493 | + const day = defaultDate.getDay() |
| 494 | + this.calendar = { |
| 495 | + fullDate, |
| 496 | + year, |
| 497 | + month, |
| 498 | + date, |
| 499 | + day |
| 500 | + }, |
| 501 | + this.tempSingleDate = fullDate |
| 502 | + this.time = getTime(defaultDate, this.hideSecond) |
| 503 | + } |
| 504 | + } |
487 | 505 | },
|
488 | 506 | /**
|
489 | 507 | * 打开日历弹窗
|
|
545 | 563 | * @param {Object} name
|
546 | 564 | */
|
547 | 565 | setEmit(name) {
|
548 |
| - if(!this.range){ |
549 |
| - if(!this.calendar.fullDate){ |
550 |
| - this.calendar = this.cale.getInfo(new Date()) |
551 |
| - this.tempSingleDate = this.calendar.fullDate |
| 566 | + if (!this.range) { |
| 567 | + if (!this.calendar.fullDate) { |
| 568 | + this.calendar = this.cale.getInfo(new Date()) |
| 569 | + this.tempSingleDate = this.calendar.fullDate |
552 | 570 | }
|
553 |
| - if(this.hasTime && !this.time) { |
554 |
| - this.time = getTime(new Date(), this.hideSecond) |
| 571 | + if (this.hasTime && !this.time) { |
| 572 | + this.time = getTime(new Date(), this.hideSecond) |
555 | 573 | }
|
556 | 574 | }
|
557 | 575 | let {
|
|
595 | 613 | }
|
596 | 614 | this.change()
|
597 | 615 | },
|
598 |
| - changeMonth(type) { |
599 |
| - let newDate |
600 |
| - if(type === 'pre') { |
601 |
| - newDate = this.cale.getPreMonthObj(this.nowDate.fullDate).fullDate |
602 |
| - } else if(type === 'next') { |
603 |
| - newDate = this.cale.getNextMonthObj(this.nowDate.fullDate).fullDate |
604 |
| - } |
| 616 | + changeMonth(type) { |
| 617 | + let newDate |
| 618 | + if (type === 'pre') { |
| 619 | + newDate = this.cale.getPreMonthObj(this.nowDate.fullDate).fullDate |
| 620 | + } else if (type === 'next') { |
| 621 | + newDate = this.cale.getNextMonthObj(this.nowDate.fullDate).fullDate |
| 622 | + } |
605 | 623 |
|
606 |
| - this.setDate(newDate) |
| 624 | + this.setDate(newDate) |
607 | 625 | this.monthSwitch()
|
608 |
| - }, |
| 626 | + }, |
609 | 627 | /**
|
610 | 628 | * 设置日期
|
611 | 629 | * @param {Object} date
|
|
619 | 637 | }
|
620 | 638 | </script>
|
621 | 639 |
|
622 |
| -<style lang="scss" > |
| 640 | +<style lang="scss"> |
623 | 641 | $uni-primary: #007aff !default;
|
624 | 642 |
|
625 | 643 | .uni-calendar {
|
|
855 | 873 |
|
856 | 874 | .uni-date-changed--time-end {
|
857 | 875 | /* #ifndef APP-NVUE */
|
858 |
| - display: flex; |
| 876 | + display: flex; |
859 | 877 | /* #endif */
|
860 | 878 | align-items: center;
|
861 | 879 | }
|
862 | 880 |
|
863 | 881 | .uni-date-changed--time-date {
|
864 |
| - color: #999; |
| 882 | + color: #999; |
865 | 883 | line-height: 50px;
|
866 |
| - /* #ifdef MP-TOUTIAO */ |
867 |
| - font-size: 16px; |
868 |
| - /* #endif */ |
| 884 | + /* #ifdef MP-TOUTIAO */ |
| 885 | + font-size: 16px; |
| 886 | + /* #endif */ |
869 | 887 | margin-right: 5px;
|
870 | 888 | // opacity: 0.6;
|
871 | 889 | }
|
|
924 | 942 | .uni-datetime-picker--btn:active {
|
925 | 943 | opacity: 0.7;
|
926 | 944 | }
|
| 945 | +
|
927 | 946 | /* #endif */
|
928 |
| -</style> |
| 947 | +</style> |
0 commit comments