calendar.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  1. <template>
  2. <view class="uni-calendar" @mouseleave="leaveCale">
  3. <view v-if="!insert && show" class="uni-calendar__mask" :class="{ 'uni-calendar--mask-show': aniMaskShow }"
  4. @click="maskClick"></view>
  5. <view v-if="insert || show" class="uni-calendar__content"
  6. :class="{ 'uni-calendar--fixed': !insert, 'uni-calendar--ani-show': aniMaskShow, 'uni-calendar__content-mobile': aniMaskShow }">
  7. <view class="uni-calendar__header" :class="{ 'uni-calendar__header-mobile': !insert }">
  8. <view class="uni-calendar__header-btn-box" @click.stop="changeMonth('pre')">
  9. <view class="uni-calendar__header-btn uni-calendar--left"></view>
  10. </view>
  11. <view class="uni-calendar__header-date" @click="togglePickerPanel">
  12. <text class="uni-calendar__header-year" @click.stop="showYearPicker = true">{{ nowDate.year || '' }}{{ yearText }}</text>
  13. <text class="uni-calendar__header-divider">/</text>
  14. <text class="uni-calendar__header-month" @click.stop="showMonthPicker = true">{{ nowDate.month || '' }}{{ monthText }}</text>
  15. </view>
  16. <view class="uni-calendar__header-btn-box" @click.stop="changeMonth('next')">
  17. <view class="uni-calendar__header-btn uni-calendar--right"></view>
  18. </view>
  19. <view v-if="!insert" class="dialog-close" @click="maskClick">
  20. <view class="dialog-close-plus" data-id="close"></view>
  21. <view class="dialog-close-plus dialog-close-rotate" data-id="close"></view>
  22. </view>
  23. </view>
  24. <view v-if="showYearPicker" class="uni-calendar__picker-mask" @click="showYearPicker = false"></view>
  25. <view v-if="showYearPicker" class="uni-calendar__picker-panel">
  26. <view class="uni-calendar__picker-header">
  27. <view class="uni-calendar__picker-btn" @click="changeYearDecade(-1)">
  28. <text>«</text>
  29. </view>
  30. <text class="uni-calendar__picker-title">{{ decadeStart }} - {{ decadeEnd }}</text>
  31. <view class="uni-calendar__picker-btn" @click="changeYearDecade(1)">
  32. <text>»</text>
  33. </view>
  34. </view>
  35. <view class="uni-calendar__picker-body">
  36. <view v-for="year in yearList" :key="year"
  37. class="uni-calendar__picker-item"
  38. :class="{ 'uni-calendar__picker-item--active': year === nowDate.year }"
  39. @click="selectYear(year)">
  40. {{ year }}
  41. </view>
  42. </view>
  43. </view>
  44. <view v-if="showMonthPicker" class="uni-calendar__picker-mask" @click="showMonthPicker = false"></view>
  45. <view v-if="showMonthPicker" class="uni-calendar__picker-panel">
  46. <view class="uni-calendar__picker-body">
  47. <view v-for="month in monthList" :key="month"
  48. class="uni-calendar__picker-item"
  49. :class="{ 'uni-calendar__picker-item--active': month === nowDate.month }"
  50. @click="selectMonth(month)">
  51. {{ month }}{{ monthText }}
  52. </view>
  53. </view>
  54. </view>
  55. <view class="uni-calendar__box">
  56. <view v-if="showMonth" class="uni-calendar__box-bg">
  57. <text class="uni-calendar__box-bg-text">{{ nowDate.month }}</text>
  58. </view>
  59. <view class="uni-calendar__weeks" style="padding-bottom: 7px;">
  60. <view class="uni-calendar__weeks-day">
  61. <text class="uni-calendar__weeks-day-text">{{ SUNText }}</text>
  62. </view>
  63. <view class="uni-calendar__weeks-day">
  64. <text class="uni-calendar__weeks-day-text">{{ MONText }}</text>
  65. </view>
  66. <view class="uni-calendar__weeks-day">
  67. <text class="uni-calendar__weeks-day-text">{{ TUEText }}</text>
  68. </view>
  69. <view class="uni-calendar__weeks-day">
  70. <text class="uni-calendar__weeks-day-text">{{ WEDText }}</text>
  71. </view>
  72. <view class="uni-calendar__weeks-day">
  73. <text class="uni-calendar__weeks-day-text">{{ THUText }}</text>
  74. </view>
  75. <view class="uni-calendar__weeks-day">
  76. <text class="uni-calendar__weeks-day-text">{{ FRIText }}</text>
  77. </view>
  78. <view class="uni-calendar__weeks-day">
  79. <text class="uni-calendar__weeks-day-text">{{ SATText }}</text>
  80. </view>
  81. </view>
  82. <view class="uni-calendar__weeks" v-for="(item, weekIndex) in weeks" :key="weekIndex">
  83. <view class="uni-calendar__weeks-item" v-for="(weeks, weeksIndex) in item" :key="weeksIndex">
  84. <calendar-item class="uni-calendar-item--hook" :weeks="weeks" :calendar="calendar"
  85. :selected="selected" :checkHover="range" @change="choiceDate" @handleMouse="handleMouse">
  86. </calendar-item>
  87. </view>
  88. </view>
  89. </view>
  90. <view v-if="!insert && !range && hasTime" class="uni-date-changed uni-calendar--fixed-top"
  91. style="padding: 0 80px;">
  92. <view class="uni-date-changed--time-date">{{ tempSingleDate ? tempSingleDate : selectDateText }}</view>
  93. <time-picker type="time" :start="timepickerStartTime" :end="timepickerEndTime" v-model="time"
  94. :disabled="!tempSingleDate" :border="false" :hide-second="hideSecond" class="time-picker-style">
  95. </time-picker>
  96. </view>
  97. <view v-if="!insert && range && hasTime" class="uni-date-changed uni-calendar--fixed-top">
  98. <view class="uni-date-changed--time-start">
  99. <view class="uni-date-changed--time-date">{{ tempRange.before ? tempRange.before : startDateText }}
  100. </view>
  101. <time-picker type="time" :start="timepickerStartTime" v-model="timeRange.startTime" :border="false"
  102. :hide-second="hideSecond" :disabled="!tempRange.before" class="time-picker-style">
  103. </time-picker>
  104. </view>
  105. <view style="line-height: 50px;">
  106. <uni-icons type="arrowthinright" color="#999"></uni-icons>
  107. </view>
  108. <view class="uni-date-changed--time-end">
  109. <view class="uni-date-changed--time-date">{{ tempRange.after ? tempRange.after : endDateText }}
  110. </view>
  111. <time-picker type="time" :end="timepickerEndTime" v-model="timeRange.endTime" :border="false"
  112. :hide-second="hideSecond" :disabled="!tempRange.after" class="time-picker-style">
  113. </time-picker>
  114. </view>
  115. </view>
  116. <view v-if="!insert" class="uni-date-changed uni-date-btn--ok">
  117. <view class="uni-datetime-picker--btn" @click="confirm">{{ confirmText }}</view>
  118. </view>
  119. </view>
  120. </view>
  121. </template>
  122. <script>
  123. import {
  124. Calendar,
  125. getDate,
  126. getTime
  127. } from './util.js';
  128. import calendarItem from './calendar-item.vue'
  129. import timePicker from './time-picker.vue'
  130. import {
  131. initVueI18n
  132. } from '@dcloudio/uni-i18n'
  133. import i18nMessages from './i18n/index.js'
  134. const {
  135. t
  136. } = initVueI18n(i18nMessages)
  137. /**
  138. * Calendar 日历
  139. * @description 日历组件可以查看日期,选择任意范围内的日期,打点操作。常用场景如:酒店日期预订、火车机票选择购买日期、上下班打卡等
  140. * @tutorial https://ext.dcloud.net.cn/plugin?id=56
  141. * @property {String} date 自定义当前时间,默认为今天
  142. * @property {String} startDate 日期选择范围-开始日期
  143. * @property {String} endDate 日期选择范围-结束日期
  144. * @property {Boolean} range 范围选择
  145. * @property {Boolean} insert = [true|false] 插入模式,默认为false
  146. * @value true 弹窗模式
  147. * @value false 插入模式
  148. * @property {Boolean} clearDate = [true|false] 弹窗模式是否清空上次选择内容
  149. * @property {Array} selected 打点,期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}]
  150. * @property {Boolean} showMonth 是否选择月份为背景
  151. * @property {[String} defaultValue 选择器打开时默认显示的时间
  152. * @event {Function} change 日期改变,`insert :ture` 时生效
  153. * @event {Function} confirm 确认选择`insert :false` 时生效
  154. * @event {Function} monthSwitch 切换月份时触发
  155. * @example <uni-calendar :insert="true" :start-date="'2019-3-2'":end-date="'2019-5-20'"@change="change" />
  156. */
  157. export default {
  158. components: {
  159. calendarItem,
  160. timePicker
  161. },
  162. options: {
  163. // #ifdef MP-TOUTIAO
  164. virtualHost: false,
  165. // #endif
  166. // #ifndef MP-TOUTIAO
  167. virtualHost: true
  168. // #endif
  169. },
  170. props: {
  171. date: {
  172. type: String,
  173. default: ''
  174. },
  175. defTime: {
  176. type: [String, Object],
  177. default: ''
  178. },
  179. selectableTimes: {
  180. type: [Object],
  181. default() {
  182. return {}
  183. }
  184. },
  185. selected: {
  186. type: Array,
  187. default() {
  188. return []
  189. }
  190. },
  191. startDate: {
  192. type: String,
  193. default: ''
  194. },
  195. endDate: {
  196. type: String,
  197. default: ''
  198. },
  199. startPlaceholder: {
  200. type: String,
  201. default: ''
  202. },
  203. endPlaceholder: {
  204. type: String,
  205. default: ''
  206. },
  207. range: {
  208. type: Boolean,
  209. default: false
  210. },
  211. hasTime: {
  212. type: Boolean,
  213. default: false
  214. },
  215. insert: {
  216. type: Boolean,
  217. default: true
  218. },
  219. showMonth: {
  220. type: Boolean,
  221. default: true
  222. },
  223. clearDate: {
  224. type: Boolean,
  225. default: true
  226. },
  227. checkHover: {
  228. type: Boolean,
  229. default: true
  230. },
  231. hideSecond: {
  232. type: [Boolean],
  233. default: false
  234. },
  235. pleStatus: {
  236. type: Object,
  237. default() {
  238. return {
  239. before: '',
  240. after: '',
  241. data: [],
  242. fulldate: ''
  243. }
  244. }
  245. },
  246. defaultValue: {
  247. type: [String, Object, Array],
  248. default: ''
  249. }
  250. },
  251. data() {
  252. return {
  253. show: false,
  254. weeks: [],
  255. calendar: {},
  256. nowDate: {},
  257. aniMaskShow: false,
  258. firstEnter: true,
  259. time: '',
  260. timeRange: {
  261. startTime: '',
  262. endTime: ''
  263. },
  264. tempSingleDate: '',
  265. tempRange: {
  266. before: '',
  267. after: ''
  268. },
  269. showYearPicker: false,
  270. showMonthPicker: false,
  271. currentDecadeStart: 2020
  272. }
  273. },
  274. watch: {
  275. date: {
  276. immediate: true,
  277. handler(newVal) {
  278. if (!this.range) {
  279. this.tempSingleDate = newVal
  280. setTimeout(() => {
  281. this.init(newVal)
  282. }, 100)
  283. }
  284. }
  285. },
  286. defTime: {
  287. immediate: true,
  288. handler(newVal) {
  289. if (!this.range) {
  290. this.time = newVal
  291. } else {
  292. this.timeRange.startTime = newVal.start
  293. this.timeRange.endTime = newVal.end
  294. }
  295. }
  296. },
  297. startDate(val) {
  298. // 字节小程序 watch 早于 created
  299. if (!this.cale) {
  300. return
  301. }
  302. this.cale.setStartDate(val)
  303. this.cale.setDate(this.nowDate.fullDate)
  304. this.weeks = this.cale.weeks
  305. },
  306. endDate(val) {
  307. // 字节小程序 watch 早于 created
  308. if (!this.cale) {
  309. return
  310. }
  311. this.cale.setEndDate(val)
  312. this.cale.setDate(this.nowDate.fullDate)
  313. this.weeks = this.cale.weeks
  314. },
  315. selected(newVal) {
  316. // 字节小程序 watch 早于 created
  317. if (!this.cale) {
  318. return
  319. }
  320. this.cale.setSelectInfo(this.nowDate.fullDate, newVal)
  321. this.weeks = this.cale.weeks
  322. },
  323. pleStatus: {
  324. immediate: true,
  325. handler(newVal) {
  326. const {
  327. before,
  328. after,
  329. fulldate,
  330. which
  331. } = newVal
  332. this.tempRange.before = before
  333. this.tempRange.after = after
  334. setTimeout(() => {
  335. if (fulldate) {
  336. this.cale.setHoverMultiple(fulldate)
  337. if (before && after) {
  338. this.cale.lastHover = true
  339. if (this.rangeWithinMonth(after, before)) return
  340. this.setDate(before)
  341. } else {
  342. this.cale.setMultiple(fulldate)
  343. this.setDate(this.nowDate.fullDate)
  344. this.calendar.fullDate = ''
  345. this.cale.lastHover = false
  346. }
  347. } else {
  348. // 字节小程序 watch 早于 created
  349. if (!this.cale) {
  350. return
  351. }
  352. this.cale.setDefaultMultiple(before, after)
  353. if (which === 'left' && before) {
  354. this.setDate(before)
  355. this.weeks = this.cale.weeks
  356. } else if (after) {
  357. this.setDate(after)
  358. this.weeks = this.cale.weeks
  359. }
  360. this.cale.lastHover = true
  361. }
  362. }, 16)
  363. }
  364. }
  365. },
  366. computed: {
  367. timepickerStartTime() {
  368. const activeDate = this.range ? this.tempRange.before : this.calendar.fullDate
  369. return activeDate === this.startDate ? this.selectableTimes.start : ''
  370. },
  371. timepickerEndTime() {
  372. const activeDate = this.range ? this.tempRange.after : this.calendar.fullDate
  373. return activeDate === this.endDate ? this.selectableTimes.end : ''
  374. },
  375. /**
  376. * for i18n
  377. */
  378. selectDateText() {
  379. return t("uni-datetime-picker.selectDate")
  380. },
  381. startDateText() {
  382. return this.startPlaceholder || t("uni-datetime-picker.startDate")
  383. },
  384. endDateText() {
  385. return this.endPlaceholder || t("uni-datetime-picker.endDate")
  386. },
  387. okText() {
  388. return t("uni-datetime-picker.ok")
  389. },
  390. yearText() {
  391. return t("uni-datetime-picker.year")
  392. },
  393. monthText() {
  394. return t("uni-datetime-picker.month")
  395. },
  396. MONText() {
  397. return t("uni-calender.MON")
  398. },
  399. TUEText() {
  400. return t("uni-calender.TUE")
  401. },
  402. WEDText() {
  403. return t("uni-calender.WED")
  404. },
  405. THUText() {
  406. return t("uni-calender.THU")
  407. },
  408. FRIText() {
  409. return t("uni-calender.FRI")
  410. },
  411. SATText() {
  412. return t("uni-calender.SAT")
  413. },
  414. SUNText() {
  415. return t("uni-calender.SUN")
  416. },
  417. confirmText() {
  418. return t("uni-calender.confirm")
  419. },
  420. decadeStart() {
  421. return this.currentDecadeStart
  422. },
  423. decadeEnd() {
  424. return this.currentDecadeStart + 9
  425. },
  426. yearList() {
  427. const years = []
  428. for (let i = 0; i < 10; i++) {
  429. years.push(this.currentDecadeStart + i)
  430. }
  431. return years
  432. },
  433. monthList() {
  434. return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
  435. }
  436. },
  437. created() {
  438. // 获取日历方法实例
  439. this.cale = new Calendar({
  440. selected: this.selected,
  441. startDate: this.startDate,
  442. endDate: this.endDate,
  443. range: this.range,
  444. })
  445. // 选中某一天
  446. this.init(this.date)
  447. },
  448. methods: {
  449. leaveCale() {
  450. this.firstEnter = true
  451. },
  452. handleMouse(weeks) {
  453. if (weeks.disable) return
  454. if (this.cale.lastHover) return
  455. let {
  456. before,
  457. after
  458. } = this.cale.multipleStatus
  459. if (!before) return
  460. this.calendar = weeks
  461. // 设置范围选
  462. this.cale.setHoverMultiple(this.calendar.fullDate)
  463. this.weeks = this.cale.weeks
  464. // hover时,进入一个日历,更新另一个
  465. if (this.firstEnter) {
  466. this.$emit('firstEnterCale', this.cale.multipleStatus)
  467. this.firstEnter = false
  468. }
  469. },
  470. rangeWithinMonth(A, B) {
  471. const [yearA, monthA] = A.split('-')
  472. const [yearB, monthB] = B.split('-')
  473. return yearA === yearB && monthA === monthB
  474. },
  475. // 蒙版点击事件
  476. maskClick() {
  477. this.close()
  478. this.$emit('maskClose')
  479. },
  480. clearCalender() {
  481. if (this.range) {
  482. this.timeRange.startTime = ''
  483. this.timeRange.endTime = ''
  484. this.tempRange.before = ''
  485. this.tempRange.after = ''
  486. this.cale.multipleStatus.before = ''
  487. this.cale.multipleStatus.after = ''
  488. this.cale.multipleStatus.data = []
  489. this.cale.lastHover = false
  490. } else {
  491. this.time = ''
  492. this.tempSingleDate = ''
  493. }
  494. this.calendar.fullDate = ''
  495. this.setDate(new Date())
  496. },
  497. bindDateChange(e) {
  498. const value = e.detail.value + '-1'
  499. this.setDate(value)
  500. },
  501. /**
  502. * 初始化日期显示
  503. * @param {Object} date
  504. */
  505. init(date) {
  506. // 字节小程序 watch 早于 created
  507. if (!this.cale) {
  508. return
  509. }
  510. this.cale.setDate(date || new Date())
  511. this.weeks = this.cale.weeks
  512. this.nowDate = this.cale.getInfo(date)
  513. this.calendar = {
  514. ...this.nowDate
  515. }
  516. if (!date) {
  517. // 优化date为空默认不选中今天
  518. this.calendar.fullDate = ''
  519. if (this.defaultValue && !this.range) {
  520. // 暂时只支持移动端非范围选择
  521. const defaultDate = new Date(this.defaultValue)
  522. const fullDate = getDate(defaultDate)
  523. const year = defaultDate.getFullYear()
  524. const month = defaultDate.getMonth() + 1
  525. const date = defaultDate.getDate()
  526. const day = defaultDate.getDay()
  527. this.calendar = {
  528. fullDate,
  529. year,
  530. month,
  531. date,
  532. day
  533. },
  534. this.tempSingleDate = fullDate
  535. this.time = getTime(defaultDate, this.hideSecond)
  536. }
  537. }
  538. },
  539. /**
  540. * 打开日历弹窗
  541. */
  542. open() {
  543. // 弹窗模式并且清理数据
  544. if (this.clearDate && !this.insert) {
  545. this.cale.cleanMultipleStatus()
  546. this.init(this.date)
  547. }
  548. this.show = true
  549. this.$nextTick(() => {
  550. setTimeout(() => {
  551. this.aniMaskShow = true
  552. }, 50)
  553. })
  554. },
  555. /**
  556. * 关闭日历弹窗
  557. */
  558. close() {
  559. this.aniMaskShow = false
  560. this.$nextTick(() => {
  561. setTimeout(() => {
  562. this.show = false
  563. this.$emit('close')
  564. }, 300)
  565. })
  566. },
  567. /**
  568. * 确认按钮
  569. */
  570. confirm() {
  571. this.setEmit('confirm')
  572. this.close()
  573. },
  574. /**
  575. * 变化触发
  576. */
  577. change(isSingleChange) {
  578. if (!this.insert && !isSingleChange) return
  579. this.setEmit('change')
  580. },
  581. /**
  582. * 选择月份触发
  583. */
  584. monthSwitch() {
  585. let {
  586. year,
  587. month
  588. } = this.nowDate
  589. this.$emit('monthSwitch', {
  590. year,
  591. month: Number(month)
  592. })
  593. },
  594. /**
  595. * 派发事件
  596. * @param {Object} name
  597. */
  598. setEmit(name) {
  599. if (!this.range) {
  600. if (!this.calendar.fullDate) {
  601. this.calendar = this.cale.getInfo(new Date())
  602. this.tempSingleDate = this.calendar.fullDate
  603. }
  604. if (this.hasTime && !this.time) {
  605. this.time = getTime(new Date(), this.hideSecond)
  606. }
  607. }
  608. let {
  609. year,
  610. month,
  611. date,
  612. fullDate,
  613. extraInfo
  614. } = this.calendar
  615. this.$emit(name, {
  616. range: this.cale.multipleStatus,
  617. year,
  618. month,
  619. date,
  620. time: this.time,
  621. timeRange: this.timeRange,
  622. fulldate: fullDate,
  623. extraInfo: extraInfo || {}
  624. })
  625. },
  626. /**
  627. * 选择天触发
  628. * @param {Object} weeks
  629. */
  630. choiceDate(weeks) {
  631. if (weeks.disable) return
  632. this.calendar = weeks
  633. this.calendar.userChecked = true
  634. // 设置多选
  635. this.cale.setMultiple(this.calendar.fullDate, true)
  636. this.weeks = this.cale.weeks
  637. this.tempSingleDate = this.calendar.fullDate
  638. const beforeDate = new Date(this.cale.multipleStatus.before).getTime()
  639. const afterDate = new Date(this.cale.multipleStatus.after).getTime()
  640. if (beforeDate > afterDate && afterDate) {
  641. this.tempRange.before = this.cale.multipleStatus.after
  642. this.tempRange.after = this.cale.multipleStatus.before
  643. } else {
  644. this.tempRange.before = this.cale.multipleStatus.before
  645. this.tempRange.after = this.cale.multipleStatus.after
  646. }
  647. this.change(true)
  648. },
  649. changeMonth(type) {
  650. let newDate
  651. if (type === 'pre') {
  652. newDate = this.cale.getPreMonthObj(this.nowDate.fullDate).fullDate
  653. } else if (type === 'next') {
  654. newDate = this.cale.getNextMonthObj(this.nowDate.fullDate).fullDate
  655. }
  656. this.setDate(newDate)
  657. this.monthSwitch()
  658. },
  659. togglePickerPanel() {
  660. this.showYearPicker = !this.showYearPicker
  661. this.showMonthPicker = false
  662. },
  663. changeYearDecade(direction) {
  664. this.currentDecadeStart += direction * 10
  665. },
  666. selectYear(year) {
  667. const month = this.nowDate.month || 1
  668. this.setDate(`${year}-${month}-1`)
  669. this.showYearPicker = false
  670. this.showMonthPicker = true
  671. this.monthSwitch()
  672. },
  673. selectMonth(month) {
  674. const year = this.nowDate.year || new Date().getFullYear()
  675. this.setDate(`${year}-${month}-1`)
  676. this.showMonthPicker = false
  677. this.monthSwitch()
  678. },
  679. /**
  680. * 设置日期
  681. * @param {Object} date
  682. */
  683. setDate(date) {
  684. this.cale.setDate(date)
  685. this.weeks = this.cale.weeks
  686. this.nowDate = this.cale.getInfo(date)
  687. }
  688. }
  689. }
  690. </script>
  691. <style lang="scss">
  692. $uni-primary: #007aff !default;
  693. .uni-calendar {
  694. /* #ifndef APP-NVUE */
  695. display: flex;
  696. /* #endif */
  697. flex-direction: column;
  698. }
  699. .uni-calendar__mask {
  700. position: fixed;
  701. bottom: 0;
  702. top: 0;
  703. left: 0;
  704. right: 0;
  705. background-color: rgba(0, 0, 0, 0.4);
  706. transition-property: opacity;
  707. transition-duration: 0.3s;
  708. opacity: 0;
  709. /* #ifndef APP-NVUE */
  710. z-index: 11199;
  711. /* #endif */
  712. }
  713. .uni-calendar--mask-show {
  714. opacity: 1
  715. }
  716. .uni-calendar--fixed {
  717. position: fixed;
  718. bottom: calc(var(--window-bottom));
  719. left: 0;
  720. right: 0;
  721. transition-property: transform;
  722. transition-duration: 0.3s;
  723. transform: translateY(460px);
  724. /* #ifndef APP-NVUE */
  725. z-index: 11200;
  726. /* #endif */
  727. }
  728. .uni-calendar--ani-show {
  729. transform: translateY(0);
  730. }
  731. .uni-calendar__content {
  732. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  733. }
  734. .uni-calendar__content-mobile {
  735. border-top-left-radius: 10px;
  736. border-top-right-radius: 10px;
  737. box-shadow: 0px 0px 5px 3px rgba(0, 0, 0, 0.1);
  738. }
  739. .uni-calendar__header {
  740. position: relative;
  741. /* #ifndef APP-NVUE */
  742. display: flex;
  743. /* #endif */
  744. flex-direction: row;
  745. justify-content: center;
  746. align-items: center;
  747. height: 50px;
  748. picker{
  749. z-index: 1000;
  750. }
  751. }
  752. :deep(.uni-picker-container){
  753. z-index: 11201!important;
  754. }
  755. .uni-calendar__header-mobile {
  756. padding: 10px;
  757. padding-bottom: 0;
  758. }
  759. .uni-calendar--fixed-top {
  760. /* #ifndef APP-NVUE */
  761. display: flex;
  762. /* #endif */
  763. flex-direction: row;
  764. justify-content: space-between;
  765. border-top-color: rgba(0, 0, 0, 0.4);
  766. border-top-style: solid;
  767. border-top-width: 1px;
  768. }
  769. .uni-calendar--fixed-width {
  770. width: 50px;
  771. }
  772. .uni-calendar__backtoday {
  773. position: absolute;
  774. right: 0;
  775. top: 25rpx;
  776. padding: 0 5px;
  777. padding-left: 10px;
  778. height: 25px;
  779. line-height: 25px;
  780. font-size: 12px;
  781. border-top-left-radius: 25px;
  782. border-bottom-left-radius: 25px;
  783. color: #fff;
  784. background-color: #f1f1f1;
  785. }
  786. .uni-calendar__header-text {
  787. text-align: center;
  788. width: 100px;
  789. font-size: 15px;
  790. color: var(--bs-heading-color);
  791. }
  792. .uni-calendar__header-date {
  793. display: flex;
  794. align-items: center;
  795. justify-content: center;
  796. cursor: pointer;
  797. padding: 0 10px;
  798. }
  799. .uni-calendar__header-year,
  800. .uni-calendar__header-month {
  801. font-size: 15px;
  802. color: var(--bs-heading-color);
  803. padding: 4px 8px;
  804. border-radius: 4px;
  805. transition: background-color 0.2s;
  806. }
  807. .uni-calendar__header-year:hover,
  808. .uni-calendar__header-month:hover {
  809. background-color: #f5f5f5;
  810. }
  811. .uni-calendar__header-divider {
  812. margin: 0 4px;
  813. color: #999;
  814. }
  815. .uni-calendar__picker-mask {
  816. position: fixed;
  817. top: 0;
  818. left: 0;
  819. right: 0;
  820. bottom: 0;
  821. background-color: rgba(0, 0, 0, 0.5);
  822. z-index: 11201;
  823. }
  824. .uni-calendar__picker-panel {
  825. position: absolute;
  826. top: 50px;
  827. left: 0;
  828. right: 0;
  829. background-color: #fff;
  830. border-radius: 4px;
  831. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  832. z-index: 11202;
  833. padding: 10px;
  834. max-height: 300px;
  835. overflow-y: auto;
  836. }
  837. .uni-calendar__picker-header {
  838. display: flex;
  839. align-items: center;
  840. justify-content: space-between;
  841. padding-bottom: 10px;
  842. border-bottom: 1px solid #eee;
  843. margin-bottom: 10px;
  844. }
  845. .uni-calendar__picker-btn {
  846. width: 30px;
  847. height: 30px;
  848. display: flex;
  849. align-items: center;
  850. justify-content: center;
  851. cursor: pointer;
  852. border-radius: 4px;
  853. transition: background-color 0.2s;
  854. font-size: 16px;
  855. color: #666;
  856. }
  857. .uni-calendar__picker-btn:hover {
  858. background-color: #f5f5f5;
  859. }
  860. .uni-calendar__picker-title {
  861. font-size: 14px;
  862. font-weight: bold;
  863. color: var(--bs-heading-color);
  864. }
  865. .uni-calendar__picker-body {
  866. display: flex;
  867. flex-wrap: wrap;
  868. gap: 8px;
  869. }
  870. .uni-calendar__picker-item {
  871. flex: 0 0 calc(20% - 6.4px);
  872. text-align: center;
  873. padding: 10px 0;
  874. border-radius: 4px;
  875. cursor: pointer;
  876. font-size: 14px;
  877. color: var(--bs-heading-color);
  878. transition: all 0.2s;
  879. }
  880. .uni-calendar__picker-item:hover {
  881. background-color: #e8f4fd;
  882. }
  883. .uni-calendar__picker-item--active {
  884. background-color: #2979ff;
  885. color: #fff;
  886. }
  887. .uni-calendar__button-text {
  888. text-align: center;
  889. width: 100px;
  890. font-size: 14px;
  891. color: $uni-primary;
  892. /* #ifndef APP-NVUE */
  893. letter-spacing: 3px;
  894. /* #endif */
  895. }
  896. .uni-calendar__header-btn-box {
  897. /* #ifndef APP-NVUE */
  898. display: flex;
  899. /* #endif */
  900. flex-direction: row;
  901. align-items: center;
  902. justify-content: center;
  903. width: 50px;
  904. height: 50px;
  905. }
  906. .uni-calendar__header-btn {
  907. width: 9px;
  908. height: 9px;
  909. border-left-color: #808080;
  910. border-left-style: solid;
  911. border-left-width: 1px;
  912. border-top-color: #555555;
  913. border-top-style: solid;
  914. border-top-width: 1px;
  915. }
  916. .uni-calendar--left {
  917. transform: rotate(-45deg);
  918. }
  919. .uni-calendar--right {
  920. transform: rotate(135deg);
  921. }
  922. .uni-calendar__weeks {
  923. position: relative;
  924. /* #ifndef APP-NVUE */
  925. display: flex;
  926. /* #endif */
  927. flex-direction: row;
  928. }
  929. .uni-calendar__weeks-item {
  930. flex: 1;
  931. }
  932. .uni-calendar__weeks-day {
  933. flex: 1;
  934. /* #ifndef APP-NVUE */
  935. display: flex;
  936. /* #endif */
  937. flex-direction: column;
  938. justify-content: center;
  939. align-items: center;
  940. height: 40px;
  941. border-bottom-color: #F5F5F5;
  942. border-bottom-style: solid;
  943. border-bottom-width: 1px;
  944. }
  945. .uni-calendar__weeks-day-text {
  946. font-size: 12px;
  947. color: #B2B2B2;
  948. }
  949. .uni-calendar__box {
  950. position: relative;
  951. // padding: 0 10px;
  952. padding-bottom: 7px;
  953. }
  954. .uni-calendar__box-bg {
  955. /* #ifndef APP-NVUE */
  956. display: flex;
  957. /* #endif */
  958. justify-content: center;
  959. align-items: center;
  960. position: absolute;
  961. top: 0;
  962. left: 0;
  963. right: 0;
  964. bottom: 0;
  965. }
  966. .uni-calendar__box-bg-text {
  967. font-size: 200px;
  968. font-weight: bold;
  969. color: var(--bs-heading-color);
  970. opacity: 0.1;
  971. text-align: center;
  972. /* #ifndef APP-NVUE */
  973. line-height: 1;
  974. /* #endif */
  975. }
  976. .uni-date-changed {
  977. padding: 0 10px;
  978. // line-height: 50px;
  979. text-align: center;
  980. color: var(--bs-heading-color);
  981. border-top-color: #DCDCDC;
  982. ;
  983. border-top-style: solid;
  984. border-top-width: 1px;
  985. flex: 1;
  986. }
  987. .uni-date-btn--ok {
  988. padding: 20px 15px;
  989. }
  990. .uni-date-changed--time-start {
  991. /* #ifndef APP-NVUE */
  992. display: flex;
  993. /* #endif */
  994. align-items: center;
  995. }
  996. .uni-date-changed--time-end {
  997. /* #ifndef APP-NVUE */
  998. display: flex;
  999. /* #endif */
  1000. align-items: center;
  1001. }
  1002. .uni-date-changed--time-date {
  1003. color: var(--bs-heading-color);
  1004. line-height: 50px;
  1005. /* #ifdef MP-TOUTIAO */
  1006. font-size: 16px;
  1007. /* #endif */
  1008. margin-right: 5px;
  1009. // opacity: 0.6;
  1010. }
  1011. .time-picker-style {
  1012. // width: 62px;
  1013. /* #ifndef APP-NVUE */
  1014. display: flex;
  1015. /* #endif */
  1016. justify-content: center;
  1017. align-items: center
  1018. }
  1019. .mr-10 {
  1020. margin-right: 10px;
  1021. }
  1022. .dialog-close {
  1023. position: absolute;
  1024. top: 0;
  1025. right: 0;
  1026. bottom: 0;
  1027. /* #ifndef APP-NVUE */
  1028. display: flex;
  1029. /* #endif */
  1030. flex-direction: row;
  1031. align-items: center;
  1032. padding: 0 25px;
  1033. margin-top: 10px;
  1034. }
  1035. .dialog-close-plus {
  1036. width: 16px;
  1037. height: 2px;
  1038. background-color: #737987;
  1039. border-radius: 2px;
  1040. transform: rotate(45deg);
  1041. }
  1042. .dialog-close-rotate {
  1043. position: absolute;
  1044. transform: rotate(-45deg);
  1045. }
  1046. .uni-datetime-picker--btn {
  1047. border-radius: 100px;
  1048. height: 40px;
  1049. line-height: 40px;
  1050. background-color: $uni-primary;
  1051. color: #fff;
  1052. font-size: 16px;
  1053. letter-spacing: 2px;
  1054. }
  1055. /* #ifndef APP-NVUE */
  1056. .uni-datetime-picker--btn:active {
  1057. opacity: 0.7;
  1058. }
  1059. /* #endif */
  1060. </style>