import { Ref } from 'vue' import { CellRenderProps } from '../../type' export function useFormatter(flag: Ref) { const tableColumnFormatter = (columnLabel: string) => { return unref(flag) ? columnLabel : columnLabel.replace('/件', '') } const tableDataFormatter = ({ cellData, column: { columnName, columnLabel }, }: CellRenderProps) => { if (!unref(flag)) { const matched = columnLabel.match(/(?<=\()\S+(?=\))/) if (matched) { const machedStr = matched[0] const countIndex = machedStr.split('/').findIndex(str => str === '件') if ( countIndex > -1 && typeof cellData === 'string' && cellData.split('/')[countIndex] ) { return cellData .split('/') .filter((_, index) => index !== countIndex) .join('/') } } } if (columnName.includes('Time') && typeof cellData === 'string') { return cellData.slice(5, -3).replace('T', '\n') } return cellData } return { tableColumnFormatter, tableDataFormatter, } }