综合办公系统
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

calendar-item.vue 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 && !multiple,
  5. 'uv-calendar-item--checked':(calendar.fullDate === weeks.fullDate && !weeks.isDay && !multiple) ,
  6. 'uv-calendar-item--before-checked':weeks.beforeRange,
  7. 'uv-calendar-item--range': weeks.range,
  8. 'uv-calendar-item--after-checked':weeks.afterRange,
  9. 'uv-calendar-item--multiple':weeks.multiple
  10. }" :style="[itemBoxStyle]" @click="choiceDate(weeks)">
  11. <view class="uv-calendar-item__weeks-box-item">
  12. <text v-if="selected&&weeks.extraInfo&&weeks.extraInfo.badge" class="uv-calendar-item__weeks-box-circle"></text>
  13. <text class="uv-calendar-item__weeks-top-text" v-if="weeks.extraInfo&&weeks.extraInfo.topinfo" :style="[infoStyle('top')]">{{weeks.extraInfo&&weeks.extraInfo.topinfo}}</text>
  14. <text class="uv-calendar-item__weeks-box-text" :class="{
  15. 'uv-calendar-item--isDay-text': weeks.isDay,
  16. 'uv-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay && !multiple,
  17. 'uv-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay && !multiple,
  18. 'uv-calendar-item--before-checked':weeks.beforeRange,
  19. 'uv-calendar-item--range': weeks.range,
  20. 'uv-calendar-item--after-checked':weeks.afterRange,
  21. 'uv-calendar-item--multiple':weeks.multiple,
  22. 'uv-calendar-item--disable':weeks.disable || (weeks.extraInfo&&weeks.extraInfo.disable)
  23. }" :style="[itemBoxStyle]">{{weeks.date}}</text>
  24. <text v-if="!lunar&&!weeks.extraInfo && weeks.isDay" class="uv-calendar-item__weeks-lunar-text" :class="{
  25. 'uv-calendar-item--isDay-text':weeks.isDay,
  26. 'uv-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay && !multiple,
  27. 'uv-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay && !multiple,
  28. 'uv-calendar-item--before-checked':weeks.beforeRange,
  29. 'uv-calendar-item--range': weeks.range,
  30. 'uv-calendar-item--after-checked':weeks.afterRange,
  31. 'uv-calendar-item--multiple':weeks.multiple
  32. }" :style="[itemBoxStyle]">{{todayText}}</text>
  33. <text v-if="lunar&&!weeks.extraInfo" class="uv-calendar-item__weeks-lunar-text" :class="{
  34. 'uv-calendar-item--isDay-text':weeks.isDay,
  35. 'uv-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay && !multiple,
  36. 'uv-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay && !multiple,
  37. 'uv-calendar-item--before-checked':weeks.beforeRange,
  38. 'uv-calendar-item--range': weeks.range,
  39. 'uv-calendar-item--after-checked':weeks.afterRange,
  40. 'uv-calendar-item--multiple':weeks.multiple,
  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 v-if="weeks.extraInfo&&weeks.extraInfo.info" class="uv-calendar-item__weeks-lunar-text" :class="{
  44. 'uv-calendar-item__weeks-lunar-text--equal': weeks.dateEqual
  45. }" :style="[infoStyle('bottom')]">{{weeks.extraInfo.info}}</text>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import { colorGradient } from '@/uni_modules/uv-ui-tools/libs/function/colorGradient.js';
  51. import { initVueI18n } from '@dcloudio/uni-i18n'
  52. import i18nMessages from './i18n/index.js'
  53. const { t } = initVueI18n(i18nMessages)
  54. export default {
  55. emits: ['change'],
  56. props: {
  57. weeks: {
  58. type: Object,
  59. default () {
  60. return {}
  61. }
  62. },
  63. calendar: {
  64. type: Object,
  65. default: () => {
  66. return {}
  67. }
  68. },
  69. selected: {
  70. type: Array,
  71. default: () => {
  72. return []
  73. }
  74. },
  75. lunar: {
  76. type: Boolean,
  77. default: false
  78. },
  79. color: {
  80. type: String,
  81. default: '#3c9cff'
  82. },
  83. range: {
  84. type: Boolean,
  85. default: false
  86. },
  87. multiple: {
  88. type: Boolean,
  89. default: false
  90. }
  91. },
  92. computed: {
  93. todayText() {
  94. return t("uv-calender.today")
  95. },
  96. itemBoxStyle() {
  97. const style = {};
  98. if (this.multiple) { // 多选状态
  99. if (this.weeks.multiple) {
  100. style.backgroundColor = this.color;
  101. style.color = '#fff';
  102. } else if (this.weeks.isDay) {
  103. style.color = this.color;
  104. }
  105. } else if (this.range) { // 范围选择
  106. if (this.weeks.beforeRange || this.weeks.afterRange) {
  107. style.backgroundColor = this.color;
  108. } else if (this.weeks.range) {
  109. style.backgroundColor = colorGradient(this.color, '#ffffff', 100)[90]
  110. style.color = this.color;
  111. style.opacity = 0.8;
  112. style.borderRadius = 0;
  113. }
  114. } else {
  115. if (this.weeks.isDay) {
  116. style.color = this.color;
  117. }
  118. if (this.calendar.fullDate === this.weeks.fullDate) {
  119. style.backgroundColor = this.color;
  120. style.color = '#fff';
  121. }
  122. }
  123. return style;
  124. },
  125. infoStyle(val) {
  126. return val => {
  127. const style = {};
  128. if (!this.weeks.multiple) {
  129. if (val == 'top') {
  130. style.color = this.weeks.extraInfo.topinfoColor ? this.weeks.extraInfo.topinfoColor : '#606266';
  131. } else if (val == 'bottom') {
  132. style.color = this.weeks.extraInfo.infoColor ? this.weeks.extraInfo.infoColor : '#f56c6c';
  133. }
  134. if (this.weeks.range) {
  135. style.color = this.color;
  136. }
  137. if (this.calendar.fullDate === this.weeks.fullDate || this.weeks.beforeRange || this.weeks.afterRange) {
  138. style.color = this.multiple ? style.color : '#fff';
  139. }
  140. } else {
  141. style.color = '#fff';
  142. }
  143. return style;
  144. }
  145. }
  146. },
  147. methods: {
  148. choiceDate(weeks) {
  149. if (this.weeks.extraInfo && this.weeks.extraInfo.disable) return;
  150. this.$emit('change', weeks)
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. @mixin flex($direction: row) {
  157. /* #ifndef APP-NVUE */
  158. display: flex;
  159. /* #endif */
  160. flex-direction: $direction;
  161. }
  162. $uv-font-size-base: 14px;
  163. $uv-text-color: #333;
  164. $uv-font-size-sm: 24rpx;
  165. $uv-error: #f56c6c !default;
  166. $uv-opacity-disabled: 0.3;
  167. $uv-text-color-disable: #c0c0c0;
  168. $uv-primary: #3c9cff !default;
  169. $info-height: 32rpx;
  170. .uv-calendar-item__weeks-box {
  171. flex: 1;
  172. @include flex(column);
  173. justify-content: center;
  174. align-items: center;
  175. border-radius: 4px;
  176. }
  177. .uv-calendar-item__weeks-top-text {
  178. height: $info-height;
  179. line-height: $info-height;
  180. font-size: $uv-font-size-sm;
  181. }
  182. .uv-calendar-item__weeks-box-text {
  183. font-size: $uv-font-size-base;
  184. color: $uv-text-color;
  185. }
  186. .uv-calendar-item__weeks-lunar-text {
  187. height: $info-height;
  188. line-height: $info-height;
  189. font-size: $uv-font-size-sm;
  190. color: $uv-text-color;
  191. }
  192. .uv-calendar-item__weeks-lunar-text--equal {
  193. /* #ifdef H5 */
  194. white-space: nowrap;
  195. transform: scale(.8);
  196. /* #endif */
  197. /* #ifndef H5 */
  198. font-size: 20rpx;
  199. /* #endif */
  200. }
  201. .uv-calendar-item__weeks-box-item {
  202. position: relative;
  203. @include flex(column);
  204. justify-content: center;
  205. align-items: center;
  206. width: 106rpx;
  207. height: 56px;
  208. }
  209. .uv-calendar-item__weeks-box-circle {
  210. position: absolute;
  211. top: 5px;
  212. right: 5px;
  213. width: 8px;
  214. height: 8px;
  215. border-radius: 8px;
  216. background-color: $uv-error;
  217. }
  218. .uv-calendar-item--disable {
  219. background-color: rgba(249, 249, 249, $uv-opacity-disabled);
  220. color: $uv-text-color-disable;
  221. }
  222. .uv-calendar-item--isDay-text {
  223. color: $uv-primary;
  224. }
  225. .uv-calendar-item--isDay {
  226. background-color: $uv-primary;
  227. color: #fff;
  228. }
  229. .uv-calendar-item--checked {
  230. background-color: $uv-primary;
  231. color: #fff;
  232. border-radius: 4px;
  233. }
  234. // .uv-calendar-item--range {
  235. // background-color: $uv-primary;
  236. // color: #fff;
  237. // }
  238. .uv-calendar-item--before-checked {
  239. color: #fff;
  240. }
  241. .uv-calendar-item--after-checked {
  242. color: #fff;
  243. }
  244. .uv-calendar-item--multiple {
  245. background-color: $uv-primary;
  246. color: #fff;
  247. }
  248. </style>