import { Column } from 'element-plus' import { CommonData, CommonValue, MaybeRef, WarningNode } from '~/common' import { RowClassGetter } from '../type' type CellClassGetter = (params: { column: Column columns: Column[] columnIndex: number cellData: CommonValue rowData: CommonData rowIndex: number }) => string function getTime(time: string | null) { const timeString = time?.replace('T', ' ') const datetime = timeString ? new Date(timeString).getTime() : Date.now() return datetime } function getDuration( name: string, takeOffStand: CommonValue ): { warning: number | null; alarm: number | null } { const subMap = HANDOVER_WARNING_MAP[ name.includes('International') ? 'internationalDeparture' : 'departure' ] const stand = parseInt(String(takeOffStand)) const matchedKey = Object.keys(subMap).find(key => { if (key.includes('-')) { const [start, end] = key.split('-') const min = Number(start) const max = Number(end) if (!Number.isNaN(min) && !Number.isNaN(max)) { return stand >= min && stand <= max } } return key === takeOffStand }) let { warning, alarm } = subMap[matchedKey ?? 'all'] ?? {} if (typeof warning === 'number') { warning *= 60 * 1000 } else { warning = null } if (typeof alarm === 'number') { alarm *= 60 * 1000 } else { alarm = null } return { warning, alarm, } } export function useTableStyle( tableName: string, warningNodes?: MaybeRef ) { const rowClass = ({ row, rowIndex }) => { const classes: string[] = [] if (tableName?.includes('Airport')) { if (row.hasTakenOff === 'Y' || row.hasLanded === 'Y') { classes.push('bg-gray') } else if (row.loadPlaneSureTime) { classes.push('bg-light') } } return classes.join(' ') } const cellClass = ({ row, column, rowIndex, columnIndex }) => { const classes: string[] = [] if (tableName?.includes('Airport')) { if (column.property === 'flightNO') { classes.push('cell-click') if (row.flightState === 'DLY') { classes.push('flight-state-delay') } else if (row.flightState === 'CAN') { classes.push('flight-state-cancel') } } if (!tableName?.includes('Transfer') && warningNodes) { const matchedNode = unref(warningNodes).find( node => node.node_code === column.property && node.iata_code === row.IATACode && node.flight_no === row.flightNO ) if (matchedNode) { if (String(matchedNode.alarm_type) === '1') { classes.push('cell-warning') } } if (matchedNode) { if (String(matchedNode.alarm_type) === '2') { classes.push('cell-alarm') } } } } if (tableName?.includes('FlightContainer')) { if (['stowageNo'].includes(column.property)) { classes.push('cell-click') } } if (tableName?.includes('FlightWaybill')) { if ( [ 'stockCode', // 'stowageNum' ].includes(column.property) ) { classes.push('cell-click') } } return classes.join(' ') } const rowClassV2: RowClassGetter = ({ columns, rowData, rowIndex }) => { const classes: string[] = [] return classes.join(' ') } const cellClassV2: CellClassGetter = ({ column, columns, columnIndex, cellData, rowData, rowIndex, }) => { const classes: string[] = [] return classes.join(' ') } return { rowClass, cellClass, rowClassV2, cellClassV2, } }