123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- import { Column } from 'element-plus'
- import { CommonData, CommonValue, MaybeRef, WarningNode } from '~/common'
- import { RowClassGetter } from '../type'
- type CellClassGetter = (params: {
- column: Column<CommonData>
- columns: Column<CommonData>[]
- 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<WarningNode[]>
- ) {
- 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,
- }
- }
|