import React, { useRef, useState } from 'react'; import { PageContainer, ProTable, ProFormText, ProFormSelect } from '@ant-design/pro-components'; import { Popconfirm, message, Space, Image as AntImage, Typography } from 'antd'; import { PlusOutlined } from '@ant-design/icons'; import type { ActionType, ProColumns } from '@ant-design/pro-components'; import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui'; import { ordersApi } from '@/services/orders'; import CreateForm from './components/CreateForm'; import type { HomeCarouselItem } from './components/CreateForm'; const { Link } = Typography; // 常量定义 const STATUS_OPTIONS = [ { label: '启用', value: 1 }, { label: '禁用', value: 0 }, ]; const TYPE_OPTIONS = [ { label: '首页轮播', value: 0 }, { label: '活动', value: 1 }, { label: '其他', value: 2 }, ]; const HomeCarouselPage: React.FC = () => { const actionRef = useRef(); const [formOpen, setFormOpen] = useState(false); const [current, setCurrent] = useState(undefined); const [searchParams, setSearchParams] = useState>({}); // 处理删除 const handleDelete = async (record: HomeCarouselItem) => { const hide = message.loading('删除中...'); try { await ordersApi.deleteHomeCarousel(record.id!); message.success('删除成功'); actionRef.current?.reload(); return true; } catch (e) { message.error('删除失败'); return false; } finally { hide(); } }; const columns: ProColumns[] = [ { dataIndex: 'index', valueType: 'indexBorder', width: 48, }, { title: '标题', dataIndex: 'title', ellipsis: true, copyable: true, }, { title: '类型', dataIndex: 'type', width: 100, valueEnum: TYPE_OPTIONS.reduce((acc, curr) => ({ ...acc, [curr.value]: { text: curr.label }, }), {}), }, { title: '图片', dataIndex: 'imageUrl', width: 120, render: (_: any, record: HomeCarouselItem) => ( record.imageUrl ? ( 加载中... } /> ) : ( - ) ), }, { title: '跳转链接', dataIndex: 'redirectUrl', ellipsis: true, render: (_: any, record: HomeCarouselItem) => ( record.linkUrl ? {record.linkUrl} : '-' ), }, { title: '描述', dataIndex: 'description', ellipsis: true, }, { title: '排序', dataIndex: 'sortOrder', width: 80, }, { title: '状态', dataIndex: 'status', width: 80, valueEnum: { 1: { text: '启用', status: 'Success' }, 0: { text: '禁用', status: 'Error' }, }, }, { title: '操作', valueType: 'option', width: 180, fixed: 'right', render: (_, record) => ( { setCurrent(record); setFormOpen(true); }} > 编辑 handleDelete(record)} okText="确认" cancelText="取消" > 删除 ), }, ]; return ( {/* {*/} {/* setSearchParams(values);*/} {/* actionRef.current?.reload();*/} {/* }}*/} {/*>*/} {/* */} {/* */} {/**/} } onClick={() => { setCurrent(undefined); setFormOpen(true); }}> 新增轮播图 } /> rowKey="id" actionRef={actionRef} columns={columns} request={(p) => ordersApi.homeCarousel({ ...(p as any), ...searchParams })} search={false} pagination={{ defaultPageSize: 10, showSizeChanger: true, showQuickJumper: true, }} toolBarRender={false} /> { setFormOpen(visible); if (!visible) { setCurrent(undefined); } }} onFinish={async (values) => { const hide = message.loading('保存中...'); try { if (current?.id) { // 编辑模式 await ordersApi.saveOrUpdateHomeCarousel({ ...(current as any), ...values }); message.success('修改成功'); } else { // 新增模式 await ordersApi.saveOrUpdateHomeCarousel(values); message.success('新增成功'); } actionRef.current?.reload(); return true; } catch (e) { message.error('保存失败'); return false; } finally { hide(); } }} /> ); }; export default HomeCarouselPage;