uni-calendar-item.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 { initVueI18n } from '@dcloudio/uni-i18n'
  54. import i18nMessages from './i18n/index.js'
  55. const { t } = initVueI18n(i18nMessages)
  56. export default {
  57. emits:['change'],
  58. props: {
  59. weeks: {
  60. type: Object,
  61. default () {
  62. return {}
  63. }
  64. },
  65. calendar: {
  66. type: Object,
  67. default: () => {
  68. return {}
  69. }
  70. },
  71. selected: {
  72. type: Array,
  73. default: () => {
  74. return []
  75. }
  76. },
  77. lunar: {
  78. type: Boolean,
  79. default: false
  80. }
  81. },
  82. computed: {
  83. todayText() {
  84. return t("uni-calender.today")
  85. },
  86. },
  87. methods: {
  88. choiceDate(weeks) {
  89. this.$emit('change', weeks)
  90. }
  91. }
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. $uni-font-size-base:14px;
  96. $uni-text-color:#333;
  97. $uni-font-size-sm:12px;
  98. $uni-color-error: #e43d33;
  99. $uni-opacity-disabled: 0.3;
  100. $uni-text-color-disable:#c0c0c0;
  101. $uni-primary: #2979ff !default;
  102. .uni-calendar-item__weeks-box {
  103. flex: 1;
  104. /* #ifndef APP-NVUE */
  105. display: flex;
  106. /* #endif */
  107. flex-direction: column;
  108. justify-content: center;
  109. align-items: center;
  110. }
  111. .uni-calendar-item__weeks-box-text {
  112. font-size: $uni-font-size-base;
  113. color: $uni-text-color;
  114. }
  115. .uni-calendar-item__weeks-lunar-text {
  116. font-size: $uni-font-size-sm;
  117. color: $uni-text-color;
  118. }
  119. .uni-calendar-item__weeks-box-item {
  120. position: relative;
  121. /* #ifndef APP-NVUE */
  122. display: flex;
  123. /* #endif */
  124. flex-direction: column;
  125. justify-content: center;
  126. align-items: center;
  127. width: 100rpx;
  128. height: 100rpx;
  129. }
  130. .uni-calendar-item__weeks-box-circle {
  131. position: absolute;
  132. top: 5px;
  133. right: 5px;
  134. width: 8px;
  135. height: 8px;
  136. border-radius: 8px;
  137. background-color: $uni-color-error;
  138. }
  139. .uni-calendar-item--disable {
  140. background-color: rgba(249, 249, 249, $uni-opacity-disabled);
  141. color: $uni-text-color-disable;
  142. }
  143. .uni-calendar-item--isDay-text {
  144. color: $uni-primary;
  145. }
  146. .uni-calendar-item--isDay {
  147. background-color: $uni-primary;
  148. opacity: 0.8;
  149. color: #fff;
  150. }
  151. .uni-calendar-item--extra {
  152. color: $uni-color-error;
  153. opacity: 0.8;
  154. }
  155. .uni-calendar-item--checked {
  156. background-color: $uni-primary;
  157. color: #fff;
  158. opacity: 0.8;
  159. }
  160. .uni-calendar-item--multiple {
  161. background-color: $uni-primary;
  162. color: #fff;
  163. opacity: 0.8;
  164. }
  165. .uni-calendar-item--before-checked {
  166. background-color: #ff5a5f;
  167. color: #fff;
  168. }
  169. .uni-calendar-item--after-checked {
  170. background-color: #ff5a5f;
  171. color: #fff;
  172. }
  173. </style>