wu-calendar-block.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view class="wu-calendar-block">
  3. <view v-if="showMonth && FoldShowMonth" class="wu-calendar__box-bg">
  4. <text class="wu-calendar__box-bg-text">{{month}}</text>
  5. </view>
  6. <!-- 月或周日历 -->
  7. <view class="wu-calendar__weeks" v-for="(item, index) in weeks" :key="index">
  8. <template v-for="(weeks, weeksIndex) in item">
  9. <wu-calendar-item :key="weeksIndex" v-if="!monthShowCurrentMonth || !weeks.empty" class="wu-calendar-item--hook" :weekItemStyle="weekItemStyle" :weeks="weeks" :calendar="calendar"
  10. :selected="selected" :lunar="lunar" @change="choiceDate" :color="color" :actBadgeColor="actBadgeColor"
  11. :startText="startText" :endText="endText" :itemHeight="itemHeight - defaultMargin" :todayDefaultStyle="todayDefaultStyle"></wu-calendar-item>
  12. <view v-else class="wu-calendar__weeks-item" :style="[weekItemStyle]"></view>
  13. </template>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import mpMixin from '@/uni_modules/wu-ui-tools/libs/mixin/mpMixin.js';
  19. import mixin from '@/uni_modules/wu-ui-tools/libs/mixin/mixin.js';
  20. import props from './props.js';
  21. import {
  22. initVueI18n
  23. } from '@dcloudio/uni-i18n'
  24. import i18nMessages from '../i18n/index.js'
  25. const {
  26. t
  27. } = initVueI18n(i18nMessages)
  28. export default {
  29. emits: ['change'],
  30. mixins: [mpMixin, mixin, props],
  31. data() {
  32. return {
  33. FoldShowMonth: false,
  34. }
  35. },
  36. mounted() {
  37. this.FoldShowMonth = this.FoldStatus == 'open';
  38. },
  39. computed: {
  40. weekItemStyle() {
  41. let weeksLength = Object.keys(this.weeks).length;
  42. let calendarHeight = this.FoldStatus === 'open' ? this.itemHeight * 6 : this.itemHeight;
  43. let margin = weeksLength && this.weeks[weeksLength - 1][0].empty ? this.itemHeight / (weeksLength - 1) + this.defaultMargin : this.defaultMargin
  44. return {
  45. marginTop: margin / 2 + 'px',
  46. marginBottom: margin / 2 + 'px',
  47. height: this.itemHeight - this.defaultMargin + 'px'
  48. }
  49. }
  50. },
  51. watch: {
  52. FoldStatus(newVal) {
  53. this.$nextTick(()=>{
  54. this.FoldShowMonth = this.FoldStatus == 'open';
  55. })
  56. }
  57. },
  58. methods: {
  59. choiceDate(weeks) {
  60. this.$emit('change', weeks)
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. $wu-text-color-grey: #999;
  67. .wu-calendar-block {
  68. .wu-calendar__weeks {
  69. position: relative;
  70. /* #ifndef APP-NVUE */
  71. display: flex;
  72. /* #endif */
  73. flex-direction: row;
  74. padding: 0 8rpx;
  75. }
  76. .wu-calendar__weeks-item {
  77. flex: 1;
  78. }
  79. .wu-calendar__box-bg {
  80. /* #ifndef APP-NVUE */
  81. display: flex;
  82. /* #endif */
  83. justify-content: center;
  84. align-items: center;
  85. position: absolute;
  86. top: 0;
  87. left: 0;
  88. right: 0;
  89. bottom: 0;
  90. }
  91. .wu-calendar__box-bg-text {
  92. font-size: 100rpx;
  93. transform: scale(4);
  94. font-weight: bold;
  95. color: $wu-text-color-grey;
  96. opacity: 0.1;
  97. text-align: center;
  98. /* #ifndef APP-NVUE */
  99. line-height: 1;
  100. /* #endif */
  101. }
  102. }
  103. </style>