useFormatter.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { datetimeToTime } from '@/utils/validate'
  2. import { Ref } from 'vue'
  3. import { CommonTableFormatter } from '~/common'
  4. export function useFormatter(flag: Ref<boolean>) {
  5. const tableColumnFormatter = (columnLabel: string) => {
  6. return unref(flag) ? columnLabel : columnLabel.replace('/件', '')
  7. }
  8. const tableDataFormatter: CommonTableFormatter = (
  9. row,
  10. { label, property },
  11. cellValue,
  12. index
  13. ) => {
  14. if (!unref(flag)) {
  15. const matched = label.match(/(?<=\()\S+(?=\))/)
  16. if (matched) {
  17. const machedStr = matched[0]
  18. const countIndex = machedStr.split('/').findIndex(str => str === '件')
  19. if (
  20. countIndex > -1 &&
  21. typeof cellValue === 'string' &&
  22. cellValue.split('/')[countIndex]
  23. ) {
  24. return cellValue
  25. .split('/')
  26. .filter((_, index) => index !== countIndex)
  27. .join('/')
  28. }
  29. }
  30. }
  31. // 临时处理-没有发起货站交接这一节点数据时,不显示发起货站交接时间
  32. if (
  33. property === 'requestDepotJoinTime' &&
  34. !row["concat(requestDepotJoinBoard,'/',requestDepotJoin)"]
  35. ) {
  36. return ''
  37. }
  38. if (property.includes('Time') && typeof cellValue === 'string') {
  39. if (
  40. ['planDepartureTime', 'acLandingTime', 'planLandingTime'].includes(
  41. property
  42. )
  43. ) {
  44. return cellValue
  45. .trim()
  46. .slice(5, -3)
  47. .replace(/[T|\s]+/, '\n')
  48. } else {
  49. return datetimeToTime(cellValue, row.flightDate)
  50. }
  51. }
  52. if (property === 'jiahuo') {
  53. return cellValue ? '是' : '否'
  54. }
  55. return String(cellValue ?? '')
  56. }
  57. return {
  58. tableColumnFormatter,
  59. tableDataFormatter,
  60. }
  61. }