useTableStyle.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import { Column } from 'element-plus'
  2. import { CommonData, CommonValue, MaybeRef, WarningNode } from '~/common'
  3. import { RowClassGetter } from '../type'
  4. type CellClassGetter = (params: {
  5. column: Column<CommonData>
  6. columns: Column<CommonData>[]
  7. columnIndex: number
  8. cellData: CommonValue
  9. rowData: CommonData
  10. rowIndex: number
  11. }) => string
  12. function getTime(time: string | null) {
  13. const timeString = time?.replace('T', ' ')
  14. const datetime = timeString ? new Date(timeString).getTime() : Date.now()
  15. return datetime
  16. }
  17. function getDuration(
  18. name: string,
  19. takeOffStand: CommonValue
  20. ): { warning: number | null; alarm: number | null } {
  21. const subMap =
  22. HANDOVER_WARNING_MAP[
  23. name.includes('International') ? 'internationalDeparture' : 'departure'
  24. ]
  25. const stand = parseInt(String(takeOffStand))
  26. const matchedKey = Object.keys(subMap).find(key => {
  27. if (key.includes('-')) {
  28. const [start, end] = key.split('-')
  29. const min = Number(start)
  30. const max = Number(end)
  31. if (!Number.isNaN(min) && !Number.isNaN(max)) {
  32. return stand >= min && stand <= max
  33. }
  34. }
  35. return key === takeOffStand
  36. })
  37. let { warning, alarm } = subMap[matchedKey ?? 'all'] ?? {}
  38. if (typeof warning === 'number') {
  39. warning *= 60 * 1000
  40. } else {
  41. warning = null
  42. }
  43. if (typeof alarm === 'number') {
  44. alarm *= 60 * 1000
  45. } else {
  46. alarm = null
  47. }
  48. return {
  49. warning,
  50. alarm,
  51. }
  52. }
  53. export function useTableStyle(
  54. tableName: string,
  55. warningNodes?: MaybeRef<WarningNode[]>
  56. ) {
  57. const rowClass = ({ row, rowIndex }) => {
  58. const classes: string[] = []
  59. if (tableName?.includes('Airport')) {
  60. if (row.hasTakenOff === 'Y' || row.hasLanded === 'Y') {
  61. classes.push('bg-gray')
  62. } else if (row.loadPlaneSureTime) {
  63. classes.push('bg-light')
  64. }
  65. }
  66. return classes.join(' ')
  67. }
  68. const cellClass = ({ row, column, rowIndex, columnIndex }) => {
  69. const classes: string[] = []
  70. if (tableName?.includes('Airport')) {
  71. if (column.property === 'flightNO') {
  72. classes.push('cell-click')
  73. if (row.flightState === 'DLY') {
  74. classes.push('flight-state-delay')
  75. } else if (row.flightState === 'CAN') {
  76. classes.push('flight-state-cancel')
  77. }
  78. }
  79. if (!tableName?.includes('Transfer') && warningNodes) {
  80. const matchedNode = unref(warningNodes).find(
  81. node =>
  82. node.node_code === column.property &&
  83. node.iata_code === row.IATACode &&
  84. node.flight_no === row.flightNO
  85. )
  86. if (matchedNode) {
  87. if (String(matchedNode.alarm_type) === '1') {
  88. classes.push('cell-warning')
  89. }
  90. }
  91. if (matchedNode) {
  92. if (String(matchedNode.alarm_type) === '2') {
  93. classes.push('cell-alarm')
  94. }
  95. }
  96. }
  97. }
  98. if (tableName?.includes('FlightContainer')) {
  99. if (['stowageNo'].includes(column.property)) {
  100. classes.push('cell-click')
  101. }
  102. }
  103. if (tableName?.includes('FlightWaybill')) {
  104. if (
  105. [
  106. 'stockCode',
  107. // 'stowageNum'
  108. ].includes(column.property)
  109. ) {
  110. classes.push('cell-click')
  111. }
  112. }
  113. return classes.join(' ')
  114. }
  115. const rowClassV2: RowClassGetter = ({ columns, rowData, rowIndex }) => {
  116. const classes: string[] = []
  117. return classes.join(' ')
  118. }
  119. const cellClassV2: CellClassGetter = ({
  120. column,
  121. columns,
  122. columnIndex,
  123. cellData,
  124. rowData,
  125. rowIndex,
  126. }) => {
  127. const classes: string[] = []
  128. return classes.join(' ')
  129. }
  130. return {
  131. rowClass,
  132. cellClass,
  133. rowClassV2,
  134. cellClassV2,
  135. }
  136. }