wu-calendar-item.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <view ref="$weeksBox" class="wu-calendar-item__weeks-box" :style="[calendarItemStyle, weekItemStyle, {
  3. borderTopLeftRadius: weeks.beforeRange ? '12rpx' : '',
  4. borderBottomLeftRadius: weeks.beforeRange ? '12rpx' : '',
  5. borderTopRightRadius: weeks.afterRange ? '12rpx' : '',
  6. borderBottomRightRadius: weeks.afterRange ? '12rpx' : '',
  7. }]" @click="choiceDate(weeks)">
  8. <view class="wu-calendar-item__weeks-box-item" :style="[actMultipleStyle, {width: itemWidth, height: itemHeight + 'px'}]">
  9. <!-- 自定义打点上方信息 -->
  10. <text v-if="weeks.extraInfo && weeks.extraInfo.topInfo" class="wu-calendar-item__weeks-lunar-text" :style="[{color: weeks.extraInfo.topInfoColor || '#e43d33'}, calendarItemStyle, actMultipleStyle]">{{weeks.extraInfo.topInfo}}</text>
  11. <!-- 徽标 -->
  12. <text v-if="selected && weeks.extraInfo && weeks.extraInfo.badge" class="wu-calendar-item__weeks-box-circle" :style="[badgeStyle]"></text>
  13. <!-- 日期文字 -->
  14. <text class="wu-calendar-item__weeks-box-text" :style="[calendarItemStyle, actMultipleStyle]">{{weeks.date}}</text>
  15. <!-- 今日的文字 -->
  16. <text v-if="!lunar && !weeks.extraInfo && weeks.isDay && !weeks.beforeRange && !weeks.afterRange" class="wu-calendar-item__weeks-lunar-text" :style="[calendarItemStyle, actMultipleStyle]">{{todayText}}</text>
  17. <!-- 农历文字 -->
  18. <text v-if="lunar && !weeks.extraInfo && !weeks.beforeRange && !weeks.afterRange" class="wu-calendar-item__weeks-lunar-text" :style="[calendarItemStyle, actMultipleStyle]">{{dayText}}</text>
  19. <!-- 选中的文字展示 -->
  20. <text v-if="!weeks.extraInfo && (weeks.beforeRange || weeks.afterRange)" class="wu-calendar-item__weeks-lunar-text" :style="[calendarItemStyle, actMultipleStyle]">{{multipleText}}</text>
  21. <!-- 自定义打点下方信息 -->
  22. <text v-if="weeks.extraInfo && weeks.extraInfo.info" class="wu-calendar-item__weeks-lunar-text" :style="[{color: weeks.extraInfo.infoColor || '#e43d33'}, calendarItemStyle, actMultipleStyle]">{{weeks.extraInfo.info}}</text>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import mpMixin from '@/uni_modules/wu-ui-tools/libs/mixin/mpMixin.js';
  28. import mixin from '@/uni_modules/wu-ui-tools/libs/mixin/mixin.js';
  29. import props from './props.js';
  30. import {
  31. initVueI18n
  32. } from '@dcloudio/uni-i18n'
  33. import i18nMessages from '../i18n/index.js'
  34. import { nextTick } from 'vue';
  35. const {
  36. t
  37. } = initVueI18n(i18nMessages)
  38. export default {
  39. emits: ['change'],
  40. mixins: [mpMixin, mixin, props],
  41. computed: {
  42. todayText() {
  43. return t("wu-calender.today")
  44. },
  45. // 每项日历样式
  46. calendarItemStyle() {
  47. let style = {};
  48. let color = this.$w.Color.gradient(this.color, this.$w.Color.isLight(this.color) ? '#000' : '#fff', 100)[6]
  49. // 有顺序别乱动
  50. // 选中的日期范围内的样式
  51. if (this.weeks.rangeMultiple) {
  52. style = {
  53. backgroundColor: this.$w.Color.gradient(this.color, '#fff', 100)[80],
  54. color
  55. }
  56. };
  57. // 今天的日期样式
  58. if (this.weeks.isDay && this.todayDefaultStyle) {
  59. style.color = color;
  60. }
  61. // 禁用的日期样式
  62. if(this.weeks.disable) {
  63. style = {
  64. backgroundColor: 'rgba(249, 249, 249, 0.3)',
  65. color: '#c0c0c0'
  66. }
  67. }
  68. return style;
  69. },
  70. // 选中的日期样式
  71. actMultipleStyle() {
  72. if ((this.weeks.beforeRange || this.weeks.afterRange || this.weeks.multiples || (this.calendar.fullDate === this.weeks
  73. .fullDate && this.weeks.mode === 'single')) && !this.weeks.disable) {
  74. // #ifdef APP-NVUE
  75. if(this.itemWidth == '100%') return {};
  76. return {
  77. backgroundColor: this.color,
  78. color: '#fff',
  79. borderRadius: '12rpx'
  80. }
  81. // #endif
  82. // #ifndef APP-NVUE
  83. return {
  84. backgroundColor: this.color,
  85. color: '#fff',
  86. borderRadius: '12rpx'
  87. }
  88. // #endif
  89. }
  90. },
  91. // 徽标样式
  92. badgeStyle() {
  93. let style = {
  94. backgroundColor: this.weeks.disable ? '#c0c0c0' : '#e43d33',
  95. width: '16rpx',
  96. height: '16rpx'
  97. };
  98. if(this.weeks.extraInfo) {
  99. if(this.weeks.extraInfo.badgeColor) {
  100. // 如果当前是选中日期的徽标且徽标颜色与主题色一致 为了保证 徽标颜色可以被看见 再选中时将其设置为 #fff
  101. if ((this.weeks.beforeRange || this.weeks.afterRange || this.weeks.multiples || (this.calendar.fullDate === this.weeks
  102. .fullDate && this.weeks.mode === 'single')) && !this.weeks.disable && this.$w.Color.convertFormat(this.weeks.extraInfo.badgeColor) == this.$w.Color.convertFormat(this.color)) {
  103. style.backgroundColor = this.actBadgeColor;
  104. } else {
  105. style.backgroundColor = this.weeks.extraInfo.badgeColor
  106. }
  107. }
  108. if(this.weeks.extraInfo.badgeSize) {
  109. style.width = this.weeks.extraInfo.badgeSize
  110. style.height = this.weeks.extraInfo.badgeSize
  111. }
  112. if(!this.weeks.extraInfo.badgePosition) {
  113. style.right = '10rpx';
  114. style.top = '10rpx';
  115. } else if(this.weeks.extraInfo.badgePosition == 'top-left'){
  116. style.top = '10rpx';
  117. style.left = '10rpx';
  118. } else if(this.weeks.extraInfo.badgePosition == 'top-center'){
  119. style.top = '10rpx';
  120. style.left = 'center';
  121. } else if(this.weeks.extraInfo.badgePosition == 'top-right'){
  122. style.top = '10rpx';
  123. style.right = '10rpx';
  124. } else if(this.weeks.extraInfo.badgePosition == 'bottom-left'){
  125. style.bottom = '10rpx';
  126. style.left = '10rpx';
  127. } else if(this.weeks.extraInfo.badgePosition == 'bottom-center'){
  128. style.bottom = '10rpx';
  129. style.left = 'center';
  130. } else if(this.weeks.extraInfo.badgePosition == 'bottom-right'){
  131. style.bottom = '10rpx';
  132. style.right = '10rpx';
  133. }
  134. }
  135. return style
  136. },
  137. // 日期文字
  138. dayText() {
  139. let text = '';
  140. if (this.weeks.isDay) {
  141. text = this.todayText
  142. } else if(this.weeks.lunar.festival) {
  143. text = this.weeks.lunar.festival
  144. } else if(this.weeks.lunar.isTerm) {
  145. text = this.weeks.lunar.Term
  146. } else if (this.weeks.lunar.IDayCn === '初一') {
  147. text = this.weeks.lunar.IMonthCn
  148. } else {
  149. text = this.weeks.lunar.IDayCn
  150. }
  151. return text
  152. },
  153. // 选中的文字
  154. multipleText() {
  155. let text = '';
  156. if (this.weeks.afterRange) {
  157. text = this.endText
  158. } else if (this.weeks.beforeRange) {
  159. text = this.startText
  160. }
  161. return text;
  162. }
  163. },
  164. data() {
  165. return {
  166. itemWidth: '100%'
  167. }
  168. },
  169. methods: {
  170. choiceDate(weeks) {
  171. this.$emit('change', weeks)
  172. }
  173. },
  174. mounted() {
  175. // #ifdef APP-NVUE
  176. setTimeout(()=>{
  177. const dom = uni.requireNativePlugin('dom');
  178. dom.getComponentRect(this.$refs.$weeksBox, res=> {
  179. this.itemWidth = res.size.width + 'px';
  180. })
  181. }, 10)
  182. // #endif
  183. }
  184. }
  185. </script>
  186. <style lang="scss" scoped>
  187. @import '@/uni_modules/wu-ui-tools/theme.scss';
  188. $wu-font-size-base: 28rpx;
  189. $wu-text-color: #333;
  190. $wu-font-size-sm: 24rpx;
  191. $wu-color-error: #e43d33;
  192. $wu-opacity-disabled: 0.3;
  193. $wu-text-color-disable: #c0c0c0;
  194. .wu-calendar-item__weeks-box {
  195. flex: 1;
  196. /* #ifndef APP-NVUE */
  197. display: flex;
  198. /* #endif */
  199. flex-direction: column;
  200. justify-content: center;
  201. align-items: center;
  202. padding: 0 0.5px;
  203. }
  204. .wu-calendar-item__weeks-box-text {
  205. font-size: $wu-font-size-base;
  206. color: $wu-text-color;
  207. }
  208. .wu-calendar-item__weeks-lunar-text {
  209. font-size: $wu-font-size-sm;
  210. color: $wu-text-color;
  211. }
  212. .wu-calendar-item__weeks-box-item {
  213. flex: 1;
  214. position: relative;
  215. /* #ifndef APP-NVUE */
  216. display: flex;
  217. /* #endif */
  218. flex-direction: column;
  219. justify-content: center;
  220. align-items: center;
  221. }
  222. .wu-calendar-item__weeks-box-circle {
  223. position: absolute;
  224. border-radius: 16rpx;
  225. background-color: $wu-color-error;
  226. }
  227. .wu-calendar-item--disable {
  228. background-color: rgba(249, 249, 249, $wu-opacity-disabled);
  229. color: $wu-text-color-disable;
  230. }
  231. .wu-calendar-item--extra {
  232. color: $wu-color-error;
  233. opacity: 0.8;
  234. }
  235. .wu-calendar-item--checked {
  236. color: #fff;
  237. }
  238. </style>