uni-calendar-item.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="uni-calendar-item__weeks-box" :class="{
  3. 'uni-calendar-item--disable':weeks.disable,
  4. 'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
  5. 'uni-calendar-item--checked':(calendar.fullDate === weeks.fullDate && !weeks.isDay) ,
  6. 'uni-calendar-item--before-checked':weeks.beforeMultiple,
  7. 'uni-calendar-item--multiple': weeks.multiple,
  8. 'uni-calendar-item--after-checked':weeks.afterMultiple,
  9. }"
  10. @click="choiceDate(weeks)">
  11. <view class="uni-calendar-item__weeks-box-item">
  12. <text v-if="selected&&weeks.extraInfo" class="uni-calendar-item__weeks-box-circle"></text>
  13. <text class="uni-calendar-item__weeks-box-text" :class="{
  14. 'uni-calendar-item--isDay-text': weeks.isDay,
  15. 'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
  16. 'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
  17. 'uni-calendar-item--before-checked':weeks.beforeMultiple,
  18. 'uni-calendar-item--multiple': weeks.multiple,
  19. 'uni-calendar-item--after-checked':weeks.afterMultiple,
  20. 'uni-calendar-item--disable':weeks.disable,
  21. }">{{weeks.date}}</text>
  22. <text v-if="!lunar&&!weeks.extraInfo && weeks.isDay" class="uni-calendar-item__weeks-lunar-text" :class="{
  23. 'uni-calendar-item--isDay-text':weeks.isDay,
  24. 'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
  25. 'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
  26. 'uni-calendar-item--before-checked':weeks.beforeMultiple,
  27. 'uni-calendar-item--multiple': weeks.multiple,
  28. 'uni-calendar-item--after-checked':weeks.afterMultiple,
  29. }">{{todayText}}</text>
  30. <text v-if="lunar&&!weeks.extraInfo" class="uni-calendar-item__weeks-lunar-text" :class="{
  31. 'uni-calendar-item--isDay-text':weeks.isDay,
  32. 'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
  33. 'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
  34. 'uni-calendar-item--before-checked':weeks.beforeMultiple,
  35. 'uni-calendar-item--multiple': weeks.multiple,
  36. 'uni-calendar-item--after-checked':weeks.afterMultiple,
  37. 'uni-calendar-item--disable':weeks.disable,
  38. }">{{weeks.isDay ? todayText : (weeks.lunar.IDayCn === '初一'?weeks.lunar.IMonthCn:weeks.lunar.IDayCn)}}</text>
  39. <text v-if="weeks.extraInfo&&weeks.extraInfo.info" class="uni-calendar-item__weeks-lunar-text" :class="{
  40. 'uni-calendar-item--extra':weeks.extraInfo.info,
  41. 'uni-calendar-item--isDay-text':weeks.isDay,
  42. 'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
  43. 'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
  44. 'uni-calendar-item--before-checked':weeks.beforeMultiple,
  45. 'uni-calendar-item--multiple': weeks.multiple,
  46. 'uni-calendar-item--after-checked':weeks.afterMultiple,
  47. 'uni-calendar-item--disable':weeks.disable,
  48. }">{{weeks.extraInfo.info}}</text>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import {
  54. initVueI18n
  55. } from '@dcloudio/uni-i18n'
  56. import messages from './i18n/index.js'
  57. const { t } = initVueI18n(messages)
  58. export default {
  59. emits:['change'],
  60. props: {
  61. weeks: {
  62. type: Object,
  63. default () {
  64. return {}
  65. }
  66. },
  67. calendar: {
  68. type: Object,
  69. default: () => {
  70. return {}
  71. }
  72. },
  73. selected: {
  74. type: Array,
  75. default: () => {
  76. return []
  77. }
  78. },
  79. lunar: {
  80. type: Boolean,
  81. default: false
  82. }
  83. },
  84. computed: {
  85. todayText() {
  86. return t("uni-calender.today")
  87. },
  88. },
  89. methods: {
  90. choiceDate(weeks) {
  91. this.$emit('change', weeks)
  92. }
  93. }
  94. }
  95. </script>
  96. <style lang="scss" scoped>
  97. $uni-font-size-base:14px;
  98. $uni-text-color:#333;
  99. $uni-font-size-sm:12px;
  100. $uni-color-error: #e43d33;
  101. $uni-opacity-disabled: 0.3;
  102. $uni-text-color-disable:#c0c0c0;
  103. $uni-color-primary: #2979ff;
  104. .uni-calendar-item__weeks-box {
  105. flex: 1;
  106. /* #ifndef APP-NVUE */
  107. display: flex;
  108. /* #endif */
  109. flex-direction: column;
  110. justify-content: center;
  111. align-items: center;
  112. }
  113. .uni-calendar-item__weeks-box-text {
  114. font-size: $uni-font-size-base;
  115. color: $uni-text-color;
  116. }
  117. .uni-calendar-item__weeks-lunar-text {
  118. font-size: $uni-font-size-sm;
  119. color: $uni-text-color;
  120. }
  121. .uni-calendar-item__weeks-box-item {
  122. position: relative;
  123. /* #ifndef APP-NVUE */
  124. display: flex;
  125. /* #endif */
  126. flex-direction: column;
  127. justify-content: center;
  128. align-items: center;
  129. width: 100rpx;
  130. height: 100rpx;
  131. }
  132. .uni-calendar-item__weeks-box-circle {
  133. position: absolute;
  134. top: 5px;
  135. right: 5px;
  136. width: 8px;
  137. height: 8px;
  138. border-radius: 8px;
  139. background-color: $uni-color-error;
  140. }
  141. .uni-calendar-item--disable {
  142. background-color: rgba(249, 249, 249, $uni-opacity-disabled);
  143. color: $uni-text-color-disable;
  144. }
  145. .uni-calendar-item--isDay-text {
  146. color: $uni-color-primary;
  147. }
  148. .uni-calendar-item--isDay {
  149. background-color: $uni-color-primary;
  150. opacity: 0.8;
  151. color: #fff;
  152. }
  153. .uni-calendar-item--extra {
  154. color: $uni-color-error;
  155. opacity: 0.8;
  156. }
  157. .uni-calendar-item--checked {
  158. background-color: $uni-color-primary;
  159. color: #fff;
  160. opacity: 0.8;
  161. }
  162. .uni-calendar-item--multiple {
  163. background-color: $uni-color-primary;
  164. color: #fff;
  165. opacity: 0.8;
  166. }
  167. .uni-calendar-item--before-checked {
  168. background-color: #ff5a5f;
  169. color: #fff;
  170. }
  171. .uni-calendar-item--after-checked {
  172. background-color: #ff5a5f;
  173. color: #fff;
  174. }
  175. </style>