view.jsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { h } from 'vue'
  2. import { formInputViewProps } from '../../form-input-props'
  3. import dayjs from 'dayjs'
  4. import advancedFormat from 'dayjs/plugin/advancedFormat'
  5. import weekYear from 'dayjs/plugin/weekYear'
  6. import weekOfYear from 'dayjs/plugin/weekOfYear'
  7. dayjs.extend(advancedFormat)
  8. dayjs.extend(weekYear)
  9. dayjs.extend(weekOfYear)
  10. /**
  11. * @description 参数配置
  12. * @param viewType 显示日期格式, 默认年月日
  13. * @param format 显示日期格式 优先级最高
  14. * @return modelValue - otherValue
  15. */
  16. export default {
  17. props: formInputViewProps,
  18. setup (props) {
  19. const typeToFormatter = {
  20. year: 'YYYY',
  21. month: 'YYYY-MM',
  22. week: 'YYYY 第 ww 周',
  23. date: 'YYYY-MM-DD',
  24. datetime: 'YYYY-MM-DD HH:mm:ss'
  25. }
  26. const format = props.config.format || typeToFormatter[props.config.viewType] || typeToFormatter.date
  27. const date = () => {
  28. const startDate = props.modelValue ? dayjs(props.modelValue).format(format) : ''
  29. const endDate = props.otherValue ? dayjs(props.otherValue).format(format) : ''
  30. return `${startDate} - ${endDate}`
  31. }
  32. return () => h('span', {}, [date()])
  33. }
  34. }