Não pode escolher mais do que 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.
 
 
 

241 linhas
4.9 KiB

  1. <template>
  2. <view class="u-calendar-header u-border-bottom">
  3. <text
  4. class="u-calendar-header__title"
  5. v-if="showTitle"
  6. >{{ title }}</text>
  7. <view
  8. class="u-calendar-header__subtitle-wrap"
  9. v-if="showSubtitle"
  10. >
  11. <text
  12. v-if="showSwitch"
  13. class="u-calendar-header__switch"
  14. :class="{ 'u-calendar-header__switch--disabled': prevYearDisabled }"
  15. @click="prevYear"
  16. >«</text>
  17. <text
  18. v-if="showSwitch"
  19. class="u-calendar-header__switch"
  20. :class="{ 'u-calendar-header__switch--disabled': prevDisabled }"
  21. @click="prev"
  22. >‹</text>
  23. <text class="u-calendar-header__subtitle">{{ subtitle }}</text>
  24. <text
  25. v-if="showSwitch"
  26. class="u-calendar-header__switch"
  27. :class="{ 'u-calendar-header__switch--disabled': nextDisabled }"
  28. @click="next"
  29. >›</text>
  30. <text
  31. v-if="showSwitch"
  32. class="u-calendar-header__switch"
  33. :class="{ 'u-calendar-header__switch--disabled': nextYearDisabled }"
  34. @click="nextYear"
  35. >»</text>
  36. <text
  37. v-if="showToday"
  38. class="u-calendar-header__today"
  39. :class="{ 'u-calendar-header__today--disabled': todayDisabled }"
  40. @click="today"
  41. >{{ todayText }}</text>
  42. </view>
  43. <view class="u-calendar-header__weekdays">
  44. <text class="u-calendar-header__weekdays__weekday">{{ weekText[0] }}</text>
  45. <text class="u-calendar-header__weekdays__weekday">{{ weekText[1] }}</text>
  46. <text class="u-calendar-header__weekdays__weekday">{{ weekText[2] }}</text>
  47. <text class="u-calendar-header__weekdays__weekday">{{ weekText[3] }}</text>
  48. <text class="u-calendar-header__weekdays__weekday">{{ weekText[4] }}</text>
  49. <text class="u-calendar-header__weekdays__weekday">{{ weekText[5] }}</text>
  50. <text class="u-calendar-header__weekdays__weekday">{{ weekText[6] }}</text>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import { mpMixin } from '../../libs/mixin/mpMixin';
  56. import { mixin } from '../../libs/mixin/mixin';
  57. export default {
  58. name: 'u-calendar-header',
  59. mixins: [mpMixin, mixin],
  60. props: {
  61. // 标题
  62. title: {
  63. type: String,
  64. default: ''
  65. },
  66. // 副标题
  67. subtitle: {
  68. type: String,
  69. default: ''
  70. },
  71. // 是否显示标题
  72. showTitle: {
  73. type: Boolean,
  74. default: true
  75. },
  76. // 是否显示副标题
  77. showSubtitle: {
  78. type: Boolean,
  79. default: true
  80. },
  81. // 星期文本
  82. weekText: {
  83. type: Array,
  84. default: () => {
  85. return []
  86. }
  87. },
  88. // 是否显示月份切换按钮
  89. showSwitch: {
  90. type: Boolean,
  91. default: false
  92. },
  93. // 上个月按钮是否禁用
  94. prevDisabled: {
  95. type: Boolean,
  96. default: false
  97. },
  98. // 下个月按钮是否禁用
  99. nextDisabled: {
  100. type: Boolean,
  101. default: false
  102. },
  103. // 上一年按钮是否禁用
  104. prevYearDisabled: {
  105. type: Boolean,
  106. default: false
  107. },
  108. // 下一年按钮是否禁用
  109. nextYearDisabled: {
  110. type: Boolean,
  111. default: false
  112. },
  113. // 是否显示今天按钮
  114. showToday: {
  115. type: Boolean,
  116. default: true
  117. },
  118. // 今天按钮文案
  119. todayText: {
  120. type: String,
  121. default: ''
  122. },
  123. // 今天按钮是否禁用
  124. todayDisabled: {
  125. type: Boolean,
  126. default: false
  127. }
  128. },
  129. data() {
  130. return {
  131. }
  132. },
  133. methods: {
  134. prev() {
  135. if (!this.prevDisabled) {
  136. this.$emit('prev')
  137. }
  138. },
  139. next() {
  140. if (!this.nextDisabled) {
  141. this.$emit('next')
  142. }
  143. },
  144. prevYear() {
  145. if (!this.prevYearDisabled) {
  146. this.$emit('prevYear')
  147. }
  148. },
  149. nextYear() {
  150. if (!this.nextYearDisabled) {
  151. this.$emit('nextYear')
  152. }
  153. },
  154. today() {
  155. if (!this.todayDisabled) {
  156. this.$emit('today')
  157. }
  158. }
  159. },
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .u-calendar-header {
  164. display: flex;
  165. flex-direction: column;
  166. padding-bottom: 4px;
  167. &__title {
  168. font-size: 16px;
  169. color: var(--up-main-color, $u-main-color);
  170. text-align: center;
  171. height: 42px;
  172. line-height: 42px;
  173. font-weight: bold;
  174. }
  175. &__subtitle-wrap {
  176. @include flex;
  177. align-items: center;
  178. justify-content: center;
  179. height: 40px;
  180. }
  181. &__subtitle {
  182. font-size: 14px;
  183. color: var(--up-main-color, $u-main-color);
  184. text-align: center;
  185. font-weight: bold;
  186. min-width: 120px;
  187. }
  188. &__switch {
  189. width: 44px;
  190. height: 40px;
  191. line-height: 40px;
  192. text-align: center;
  193. color: var(--up-main-color, $u-main-color);
  194. font-size: 22px;
  195. font-weight: bold;
  196. flex-shrink: 0;
  197. &--disabled {
  198. opacity: 0.35;
  199. }
  200. }
  201. &__weekdays {
  202. @include flex;
  203. justify-content: space-between;
  204. &__weekday {
  205. font-size: 13px;
  206. color: var(--up-main-color, $u-main-color);
  207. line-height: 30px;
  208. flex: 1;
  209. text-align: center;
  210. }
  211. }
  212. &__today {
  213. margin-left: 4px;
  214. height: 28px;
  215. line-height: 28px;
  216. padding: 0 10px;
  217. border-radius: 14px;
  218. font-size: 13px;
  219. color: var(--up-primary, $u-primary);
  220. border: 1px solid var(--up-primary, $u-primary);
  221. flex-shrink: 0;
  222. &--disabled {
  223. opacity: 0.35;
  224. }
  225. }
  226. }
  227. </style>