uv-calendar-item.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view class="uv-calendar-item__weeks-box" :class="{
  3. 'uv-calendar-item--disable':weeks.disable || (weeks.extraInfo&&weeks.extraInfo.disable),
  4. 'uv-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
  5. 'uv-calendar-item--checked':(calendar.fullDate === weeks.fullDate && !weeks.isDay) ,
  6. 'uv-calendar-item--before-checked':weeks.beforeMultiple,
  7. 'uv-calendar-item--multiple': weeks.multiple,
  8. 'uv-calendar-item--after-checked':weeks.afterMultiple,
  9. }" :style="[itemBoxStyle]" @click="choiceDate(weeks)">
  10. <view class="uv-calendar-item__weeks-box-item">
  11. <text v-if="selected&&weeks.extraInfo&&weeks.extraInfo.badge" class="uv-calendar-item__weeks-box-circle"></text>
  12. <text
  13. class="uv-calendar-item__weeks-top-text"
  14. v-if="weeks.extraInfo&&weeks.extraInfo.topinfo"
  15. :style="[infoStyle('top')]"
  16. >{{weeks.extraInfo&&weeks.extraInfo.topinfo}}</text>
  17. <text class="uv-calendar-item__weeks-box-text" :class="{
  18. 'uv-calendar-item--isDay-text': weeks.isDay,
  19. 'uv-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
  20. 'uv-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
  21. 'uv-calendar-item--before-checked':weeks.beforeMultiple,
  22. 'uv-calendar-item--multiple': weeks.multiple,
  23. 'uv-calendar-item--after-checked':weeks.afterMultiple,
  24. 'uv-calendar-item--disable':weeks.disable || (weeks.extraInfo&&weeks.extraInfo.disable),
  25. }" :style="[itemBoxStyle]">{{weeks.date}}</text>
  26. <text v-if="!lunar&&!weeks.extraInfo && weeks.isDay" class="uv-calendar-item__weeks-lunar-text" :class="{
  27. 'uv-calendar-item--isDay-text':weeks.isDay,
  28. 'uv-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
  29. 'uv-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
  30. 'uv-calendar-item--before-checked':weeks.beforeMultiple,
  31. 'uv-calendar-item--multiple': weeks.multiple,
  32. 'uv-calendar-item--after-checked':weeks.afterMultiple,
  33. }" :style="[itemBoxStyle]">{{todayText}}</text>
  34. <text v-if="lunar&&!weeks.extraInfo" class="uv-calendar-item__weeks-lunar-text" :class="{
  35. 'uv-calendar-item--isDay-text':weeks.isDay,
  36. 'uv-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
  37. 'uv-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
  38. 'uv-calendar-item--before-checked':weeks.beforeMultiple,
  39. 'uv-calendar-item--multiple': weeks.multiple,
  40. 'uv-calendar-item--after-checked':weeks.afterMultiple,
  41. 'uv-calendar-item--disable':weeks.disable || (weeks.extraInfo&&weeks.extraInfo.disable),
  42. }" :style="[itemBoxStyle]">{{weeks.isDay ? todayText : (weeks.lunar.IDayCn === '初一'?weeks.lunar.IMonthCn:weeks.lunar.IDayCn)}}</text>
  43. <text
  44. v-if="weeks.extraInfo&&weeks.extraInfo.info"
  45. class="uv-calendar-item__weeks-lunar-text"
  46. :style="[infoStyle('bottom')]"
  47. >{{weeks.extraInfo.info}}</text>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import { colorGradient } from '@/uni_modules/uv-ui-tools/libs/function/colorGradient.js';
  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. color: {
  82. type: String,
  83. default: '#3c9cff'
  84. }
  85. },
  86. computed: {
  87. todayText() {
  88. return t("uv-calender.today")
  89. },
  90. itemBoxStyle() {
  91. const style = {};
  92. if (this.weeks.beforeMultiple || this.weeks.afterMultiple) {
  93. style.backgroundColor = this.color;
  94. } else if (this.weeks.multiple) {
  95. style.backgroundColor = colorGradient(this.color, '#ffffff', 100)[90]
  96. style.color = this.color;
  97. style.opacity = 0.8;
  98. style.borderRadius = 0;
  99. } else if (this.calendar.fullDate === this.weeks.fullDate && !this.weeks.isDay) {
  100. style.backgroundColor = this.color;
  101. style.color = '#fff';
  102. } else if (this.weeks.isDay && this.calendar.fullDate === this.weeks.fullDate) {
  103. style.backgroundColor = this.color;
  104. style.color = '#fff';
  105. } else if (this.weeks.isDay) {
  106. style.color = this.color;
  107. }
  108. return style;
  109. },
  110. infoStyle(val) {
  111. return val => {
  112. const style = {};
  113. if (val == 'top') {
  114. style.color = this.weeks.extraInfo.topinfoColor ? this.weeks.extraInfo.topinfoColor : '#606266';
  115. } else if (val == 'bottom') {
  116. style.color = this.weeks.extraInfo.infoColor ? this.weeks.extraInfo.infoColor : '#f56c6c';
  117. }
  118. if (this.weeks.multiple) {
  119. style.color = this.color;
  120. }
  121. if (this.calendar.fullDate === this.weeks.fullDate || this.weeks.beforeMultiple || this.weeks.afterMultiple) {
  122. style.color = '#fff';
  123. }
  124. return style;
  125. }
  126. }
  127. },
  128. methods: {
  129. choiceDate(weeks) {
  130. if (this.weeks.extraInfo && this.weeks.extraInfo.disable) return;
  131. this.$emit('change', weeks)
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. @mixin flex($direction: row) {
  138. /* #ifndef APP-NVUE */
  139. display: flex;
  140. /* #endif */
  141. flex-direction: $direction;
  142. }
  143. $uv-font-size-base: 14px;
  144. $uv-text-color: #333;
  145. $uv-font-size-sm: 24rpx;
  146. $uv-error: #f56c6c !default;
  147. $uv-opacity-disabled: 0.3;
  148. $uv-text-color-disable: #c0c0c0;
  149. $uv-primary: #3c9cff !default;
  150. $info-height: 32rpx;
  151. .uv-calendar-item__weeks-box {
  152. flex: 1;
  153. @include flex(column);
  154. justify-content: center;
  155. align-items: center;
  156. border-radius: 4px;
  157. }
  158. .uv-calendar-item__weeks-top-text {
  159. height: $info-height;
  160. line-height: $info-height;
  161. font-size: $uv-font-size-sm;
  162. }
  163. .uv-calendar-item__weeks-box-text {
  164. font-size: $uv-font-size-base;
  165. color: $uv-text-color;
  166. }
  167. .uv-calendar-item__weeks-lunar-text {
  168. height: $info-height;
  169. line-height: $info-height;
  170. font-size: $uv-font-size-sm;
  171. color: $uv-text-color;
  172. }
  173. .uv-calendar-item__weeks-box-item {
  174. position: relative;
  175. @include flex(column);
  176. justify-content: center;
  177. align-items: center;
  178. width: 106rpx;
  179. height: 56px;
  180. }
  181. .uv-calendar-item__weeks-box-circle {
  182. position: absolute;
  183. top: 5px;
  184. right: 5px;
  185. width: 8px;
  186. height: 8px;
  187. border-radius: 8px;
  188. background-color: $uv-error;
  189. }
  190. .uv-calendar-item--disable {
  191. background-color: rgba(249, 249, 249, $uv-opacity-disabled);
  192. color: $uv-text-color-disable;
  193. }
  194. .uv-calendar-item--isDay-text {
  195. color: $uv-primary;
  196. }
  197. .uv-calendar-item--isDay {
  198. background-color: $uv-primary;
  199. color: #fff;
  200. }
  201. .uv-calendar-item--checked {
  202. background-color: $uv-primary;
  203. color: #fff;
  204. border-radius: 4px;
  205. }
  206. .uv-calendar-item--multiple {
  207. background-color: $uv-primary;
  208. color: #fff;
  209. }
  210. .uv-calendar-item--before-checked {
  211. color: #fff;
  212. }
  213. .uv-calendar-item--after-checked {
  214. color: #fff;
  215. }
  216. </style>