WeekCalendar.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div class="weeklyCenterBox">
  3. <div class="selectBox">
  4. <el-icon class="icon1" @click="clickHandle(0)"><ArrowLeftBold /></el-icon>
  5. <p>{{ moment(nowTime).format('YYYY年MM月') }}</p>
  6. <el-icon class="icon1" @click="clickHandle(1)"><ArrowRightBold /></el-icon>
  7. </div>
  8. <div class="contentBox">
  9. <div class="ulBox" v-for="(arr, index) in sourceList" :key="index">
  10. <p :class="['title', index === 0 ? 'color1' : 'color2']">第{{ index + 1 }}周</p>
  11. <ul>
  12. <li
  13. v-for="(cItem, cIndex) in arr"
  14. :key="index + cIndex"
  15. :class="[
  16. cItem['w'] >= 6 || cItem['m'] != moment(nowTime).format('MM') ? 'disabled' : ''
  17. ]"
  18. >
  19. <span>
  20. {{ cItem['d'] }}
  21. </span>
  22. <span v-if="cItem['w'] < 6">
  23. <Icon icon="fa:check" />
  24. </span>
  25. <span v-if="cItem['w'] < 6">
  26. <Icon icon="fa:check" />
  27. </span>
  28. </li>
  29. </ul>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script setup lang="ts">
  35. import moment from 'moment'
  36. import { useComputedDates, isWeekend } from './calendar'
  37. defineOptions({
  38. name: 'WeekCalendar'
  39. })
  40. interface IDate {
  41. dm: string //年月日
  42. m: string | number //月份
  43. d: string | number //日期
  44. w: number | number //星期几
  45. s?: string //用来标记状态
  46. }
  47. type DaysFunType = (lists: any) => Array<Array<IDate>>
  48. const nowTime = ref<string>(moment().format('YYYY-MM'))
  49. const sourceList = ref<Array<Array<IDate>>>([])
  50. //如果总周数大于6并且当月第一天星期大于等于6,删除第一周
  51. const computedDays: DaysFunType = (lists: any) => {
  52. const nlists: Array<Array<IDate>> = [].concat(lists)
  53. const index = isWeekend(nowTime.value)
  54. if (index !== -1) {
  55. nlists.splice(index, 1)
  56. }
  57. return nlists
  58. }
  59. /**
  60. * @param type 0 减法 1 加法
  61. * @return void
  62. * **/
  63. const clickHandle: Function = (type: number): void => {
  64. const typeStr = type === 0 ? 'subtract' : 'add'
  65. const time: string = moment(nowTime.value)[typeStr](1, 'months').format('YYYY-MM')
  66. nowTime.value = moment(time).format('YYYY-MM')
  67. sourceList.value = computedDays(useComputedDates(nowTime.value))
  68. }
  69. onMounted(() => {
  70. sourceList.value = computedDays(useComputedDates(nowTime.value))
  71. })
  72. </script>
  73. <style lang="scss" scoped>
  74. .weeklyCenterBox {
  75. width: 100%;
  76. .selectBox {
  77. display: flex;
  78. align-items: center;
  79. margin-bottom: 10px;
  80. .icon1 {
  81. cursor: pointer;
  82. }
  83. p {
  84. font-weight: 600;
  85. color: #2d333c;
  86. margin: 0 10px;
  87. user-select: none;
  88. cursor: pointer;
  89. }
  90. }
  91. .contentBox {
  92. width: 100%;
  93. display: flex;
  94. align-items: center;
  95. justify-content: space-between;
  96. border: 1px solid #dee0e3;
  97. background-color: #f7f8fa;
  98. padding: 20px;
  99. .ulBox {
  100. flex: 1;
  101. margin-left: 15px;
  102. &:first-child {
  103. margin-left: 0px;
  104. }
  105. > .title {
  106. padding: 3px 0px;
  107. text-align: center;
  108. color: #fff;
  109. &.color1 {
  110. background-color: #34c17d;
  111. }
  112. &.color2 {
  113. background-color: #e94a34;
  114. }
  115. }
  116. > ul {
  117. display: flex;
  118. > li {
  119. flex: 1;
  120. padding: 8px 0px;
  121. text-align: center;
  122. display: flex;
  123. flex-direction: column;
  124. &.disabled {
  125. color: #b9c3c9;
  126. }
  127. > span {
  128. flex: 1;
  129. text-align: center;
  130. padding-top: 4px;
  131. }
  132. }
  133. }
  134. }
  135. }
  136. }
  137. </style>