import { MyResponseType, renderTextHelper } from '@/common'; import { ProColumns } from '@ant-design/pro-components'; import { Image, Popconfirm, Tag } from 'antd'; type ReturnType = ProColumns, 'text'>; export const MyColumns = { ID(props?: ReturnType): ReturnType { return { title: 'ID', dataIndex: 'id', hideInSearch: true, ...props }; }, DayStatus: (start: string, end: string) => { const now = new Date(); const startDate = new Date(start); const endDate = new Date(end); // 判断当前时间与开始时间和结束时间的关系 if (now < startDate) { return ( 未开始 ); } else if (now > endDate) { return ( 已结束 ); } else { return ( 进行中 ); } }, Images({ ...rest }: ReturnType): ReturnType { return { hideInSearch: true, renderText: renderTextHelper.Images, ...rest, }; }, SoftDelete({ onRestore, onSoftDelete, ...rest }: { onRestore: (data: { id: number }) => Promise; onSoftDelete: (data: { id: number }) => Promise; } & ReturnType): ReturnType { return { title: '启/禁用', render: (_, item, index, action) => item?.deleted_at ? ( { onRestore?.({ id: item.id }).then(() => action?.reload()); }} okText="是" cancelText="否" > 已禁用 ) : ( { onSoftDelete?.({ id: item.id }).then(() => action?.reload()); }} okText="是" cancelText="否" > 已启用 ), search: false, ...rest, }; }, CreatedAt(props?: ReturnType): ReturnType { return { title: '创建时间', dataIndex: 'created_at', hideInSearch: true, valueType: 'dateTime', sorter: true, align: 'right', ...props, }; }, UpdatedAt(): ReturnType { return { title: '最近修改', dataIndex: 'updated_at', hideInSearch: true, valueType: 'dateTime', sorter: true, align: 'right', }; }, FinishedAt(): ReturnType { return { title: '完成时间', dataIndex: 'finished_at', hideInSearch: true, valueType: 'dateTime', sorter: true, align: 'right', }; }, Boolean({ label, ...rest }: { label?: string[] } & ReturnType): ReturnType { const option: { value: boolean; label: string; color: string }[] = [ { value: false, label: label?.[0] ?? '否', color: 'gray' }, { value: true, label: label?.[1] ?? '是', color: 'green' }, ]; return { align: 'center', request: async () => option, renderText(text: boolean) { const item = option.find((item) => item.value === Boolean(text)); return {item?.label}; }, ...rest, }; }, YesOrNo({ yes = '已', no = '未', ...rest }: { yes?: string; no?: string; } & ReturnType): ReturnType { return { align: 'center', renderText(text) { return ( {text ? yes : no} ); }, ...rest, }; }, EnumTag({ ...rest }: ReturnType): ReturnType { return { align: 'left', renderText(text: any) { const _enum: any = rest?.valueEnum ?? {}; if (!_enum) return <>-; const item = _enum[text] ?? undefined; if (!item) return <>-; return {item.text}; // return {item.text}; //修改列表的标签样式 }, ...rest, }; }, Option({ ...rest }: ReturnType): ReturnType { return { title: '操作', valueType: 'option', align: 'right', fixed: 'right', ...rest, }; }, Token({ ...rest }) { return { title: 'Token', renderText(text: string) { return {text}; }, ...rest, }; }, Image({ ...rest }) { return { search: false, renderText(text: { url: string }[]) { return ; }, ...rest, }; }, Ffdefault({ Ffdefault, dataIndex, ...rest }: { Ffdefault: (data: any) => Promise; dataIndex: any; } & ReturnType): ReturnType { return { title: '是否默认', renderText(text: boolean, record: any, index, action: any) { let form: any = { id: record.id }; form[dataIndex] = record[dataIndex] ? 0 : 1; return ( { Ffdefault?.(form).then(() => action?.reload()); }} okText="是" cancelText="否" > {record[dataIndex] ? '是' : '否'} ); }, ...rest, }; }, };