Header.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { createNamespace } from '../../utils';
  2. import { t, bem } from '../utils';
  3. var _createNamespace = createNamespace('calendar-header'),
  4. createComponent = _createNamespace[0];
  5. export default createComponent({
  6. props: {
  7. title: String,
  8. subtitle: String,
  9. showTitle: Boolean,
  10. showSubtitle: Boolean,
  11. firstDayOfWeek: Number
  12. },
  13. methods: {
  14. genTitle: function genTitle() {
  15. var h = this.$createElement;
  16. if (this.showTitle) {
  17. var title = this.slots('title') || this.title || t('title');
  18. return h("div", {
  19. "class": bem('header-title')
  20. }, [title]);
  21. }
  22. },
  23. genSubtitle: function genSubtitle() {
  24. var h = this.$createElement;
  25. if (this.showSubtitle) {
  26. return h("div", {
  27. "class": bem('header-subtitle')
  28. }, [this.subtitle]);
  29. }
  30. },
  31. genWeekDays: function genWeekDays() {
  32. var h = this.$createElement;
  33. var weekdays = t('weekdays');
  34. var firstDayOfWeek = this.firstDayOfWeek;
  35. var renderWeekDays = [].concat(weekdays.slice(firstDayOfWeek, 7), weekdays.slice(0, firstDayOfWeek));
  36. return h("div", {
  37. "class": bem('weekdays')
  38. }, [renderWeekDays.map(function (item) {
  39. return h("span", {
  40. "class": bem('weekday')
  41. }, [item]);
  42. })]);
  43. }
  44. },
  45. render: function render() {
  46. var h = arguments[0];
  47. return h("div", {
  48. "class": bem('header')
  49. }, [this.genTitle(), this.genSubtitle(), this.genWeekDays()]);
  50. }
  51. });