index.vue 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <uni-shadow-root class="vant-calendar-components-header-index"><view class="van-calendar__header">
  3. <block v-if="showTitle">
  4. <view class="van-calendar__header-title"><slot name="title"></slot></view>
  5. <view class="van-calendar__header-title">{{ title }}</view>
  6. </block>
  7. <view v-if="showSubtitle" class="van-calendar__header-subtitle" @click="onClickSubtitle">
  8. {{ subtitle }}
  9. </view>
  10. <view class="van-calendar__weekdays">
  11. <view v-for="(item,index) in (weekdays)" :key="item.index" class="van-calendar__weekday">
  12. {{ item }}
  13. </view>
  14. </view>
  15. </view></uni-shadow-root>
  16. </template>
  17. <script>
  18. global['__wxRoute'] = 'vant/calendar/components/header/index'
  19. import { VantComponent } from '../../../common/component';
  20. VantComponent({
  21. props: {
  22. title: {
  23. type: String,
  24. value: '日期选择',
  25. },
  26. subtitle: String,
  27. showTitle: Boolean,
  28. showSubtitle: Boolean,
  29. firstDayOfWeek: {
  30. type: Number,
  31. observer: 'initWeekDay',
  32. },
  33. },
  34. data: {
  35. weekdays: [],
  36. },
  37. created() {
  38. this.initWeekDay();
  39. },
  40. methods: {
  41. initWeekDay() {
  42. const defaultWeeks = ['日', '一', '二', '三', '四', '五', '六'];
  43. const firstDayOfWeek = this.data.firstDayOfWeek || 0;
  44. this.setData({
  45. weekdays: [
  46. ...defaultWeeks.slice(firstDayOfWeek, 7),
  47. ...defaultWeeks.slice(0, firstDayOfWeek),
  48. ],
  49. });
  50. },
  51. onClickSubtitle(event) {
  52. this.$emit('click-subtitle', event);
  53. },
  54. },
  55. });
  56. export default global['__wxComponents']['vant/calendar/components/header/index']
  57. </script>
  58. <style platform="mp-weixin">
  59. @import '../../../common/index.css';.van-calendar__header{flex-shrink:0;box-shadow:0 2px 10px rgba(125,126,128,.16);box-shadow:var(--calendar-header-box-shadow,0 2px 10px rgba(125,126,128,.16))}.van-calendar__header-subtitle,.van-calendar__header-title{text-align:center;height:44px;height:var(--calendar-header-title-height,44px);font-weight:500;font-weight:var(--font-weight-bold,500);line-height:44px;line-height:var(--calendar-header-title-height,44px)}.van-calendar__header-title+.van-calendar__header-title,.van-calendar__header-title:empty{display:none}.van-calendar__header-title:empty+.van-calendar__header-title{display:block!important}.van-calendar__weekdays{display:flex}.van-calendar__weekday{flex:1;text-align:center;font-size:12px;font-size:var(--calendar-weekdays-font-size,12px);line-height:30px;line-height:var(--calendar-weekdays-height,30px)}
  60. </style>