2025-10-30 18:31:39 +08:00
|
|
|
import React, { useRef, useState } from 'react';
|
2025-11-04 11:53:35 +08:00
|
|
|
import { PageContainer, ProTable, ProFormText, ProFormSelect } from '@ant-design/pro-components';
|
|
|
|
|
import { Popconfirm, message, Space, Image as AntImage, Typography } from 'antd';
|
2025-10-30 18:41:40 +08:00
|
|
|
import { PlusOutlined } from '@ant-design/icons';
|
2025-10-30 18:31:39 +08:00
|
|
|
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
2025-11-04 11:53:35 +08:00
|
|
|
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
|
2025-09-23 10:32:35 +08:00
|
|
|
import { ordersApi } from '@/services/orders';
|
2025-10-30 18:31:39 +08:00
|
|
|
import CreateForm from './components/CreateForm';
|
2025-11-04 11:53:35 +08:00
|
|
|
import type { HomeCarouselItem } from './components/CreateForm';
|
2025-10-30 18:31:39 +08:00
|
|
|
|
|
|
|
|
const { Link } = Typography;
|
|
|
|
|
|
|
|
|
|
// 常量定义
|
|
|
|
|
const STATUS_OPTIONS = [
|
|
|
|
|
{ label: '启用', value: 1 },
|
|
|
|
|
{ label: '禁用', value: 0 },
|
|
|
|
|
];
|
2025-09-23 10:32:35 +08:00
|
|
|
|
2025-10-30 18:41:40 +08:00
|
|
|
const TYPE_OPTIONS = [
|
|
|
|
|
{ label: '首页轮播', value: 0 },
|
|
|
|
|
{ label: '活动', value: 1 },
|
|
|
|
|
{ label: '其他', value: 2 },
|
|
|
|
|
];
|
|
|
|
|
|
2025-09-23 10:32:35 +08:00
|
|
|
const HomeCarouselPage: React.FC = () => {
|
2025-10-30 18:31:39 +08:00
|
|
|
const actionRef = useRef<ActionType>();
|
2025-11-04 11:53:35 +08:00
|
|
|
const [formOpen, setFormOpen] = useState(false);
|
2025-09-23 10:32:35 +08:00
|
|
|
const [current, setCurrent] = useState<HomeCarouselItem | undefined>(undefined);
|
2025-10-30 18:31:39 +08:00
|
|
|
const [searchParams, setSearchParams] = useState<Record<string, any>>({});
|
2025-09-23 10:32:35 +08:00
|
|
|
|
2025-10-30 18:31:39 +08:00
|
|
|
// 处理删除
|
|
|
|
|
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<HomeCarouselItem>[] = [
|
2025-09-23 10:32:35 +08:00
|
|
|
{
|
2025-10-30 18:31:39 +08:00
|
|
|
dataIndex: 'index',
|
|
|
|
|
valueType: 'indexBorder',
|
|
|
|
|
width: 48,
|
|
|
|
|
},
|
2025-10-30 18:41:40 +08:00
|
|
|
{
|
|
|
|
|
title: '标题',
|
|
|
|
|
dataIndex: 'title',
|
|
|
|
|
ellipsis: true,
|
|
|
|
|
copyable: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '类型',
|
|
|
|
|
dataIndex: 'type',
|
|
|
|
|
width: 100,
|
|
|
|
|
valueEnum: TYPE_OPTIONS.reduce((acc, curr) => ({
|
|
|
|
|
...acc,
|
|
|
|
|
[curr.value]: { text: curr.label },
|
|
|
|
|
}), {}),
|
|
|
|
|
},
|
2025-11-04 11:53:35 +08:00
|
|
|
{
|
|
|
|
|
title: '图片',
|
|
|
|
|
dataIndex: 'imageUrl',
|
|
|
|
|
width: 120,
|
|
|
|
|
render: (_: any, record: HomeCarouselItem) => (
|
|
|
|
|
record.imageUrl ? (
|
|
|
|
|
<AntImage
|
|
|
|
|
src={record.imageUrl}
|
|
|
|
|
width={100}
|
|
|
|
|
placeholder={
|
|
|
|
|
<div style={{ background: '#f5f5f5', height: 100, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
|
|
|
|
加载中...
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<span>-</span>
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '跳转链接',
|
|
|
|
|
dataIndex: 'redirectUrl',
|
|
|
|
|
ellipsis: true,
|
|
|
|
|
render: (_: any, record: HomeCarouselItem) => (
|
|
|
|
|
record.linkUrl ? <Link href={record.linkUrl} target="_blank">{record.linkUrl}</Link> : '-'
|
|
|
|
|
),
|
|
|
|
|
},
|
2025-10-30 18:41:40 +08:00
|
|
|
{
|
|
|
|
|
title: '描述',
|
|
|
|
|
dataIndex: 'description',
|
|
|
|
|
ellipsis: true,
|
|
|
|
|
},
|
2025-10-30 18:31:39 +08:00
|
|
|
{
|
|
|
|
|
title: '排序',
|
2025-11-04 11:53:35 +08:00
|
|
|
dataIndex: 'sortOrder',
|
2025-10-30 18:31:39 +08:00
|
|
|
width: 80,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '状态',
|
|
|
|
|
dataIndex: 'status',
|
|
|
|
|
width: 80,
|
|
|
|
|
valueEnum: {
|
|
|
|
|
1: { text: '启用', status: 'Success' },
|
|
|
|
|
0: { text: '禁用', status: 'Error' },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '操作',
|
|
|
|
|
valueType: 'option',
|
|
|
|
|
width: 180,
|
2025-10-30 18:41:40 +08:00
|
|
|
fixed: 'right',
|
2025-11-04 11:53:35 +08:00
|
|
|
render: (_, record) => (
|
|
|
|
|
<Space>
|
|
|
|
|
<a
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setCurrent(record);
|
|
|
|
|
setFormOpen(true);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
编辑
|
|
|
|
|
</a>
|
|
|
|
|
<Popconfirm
|
|
|
|
|
title="确认删除轮播图?"
|
|
|
|
|
onConfirm={() => handleDelete(record)}
|
|
|
|
|
okText="确认"
|
|
|
|
|
cancelText="取消"
|
|
|
|
|
>
|
|
|
|
|
<a style={{ color: '#1677ff' }}>删除</a>
|
|
|
|
|
</Popconfirm>
|
|
|
|
|
</Space>
|
|
|
|
|
),
|
2025-09-23 10:32:35 +08:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return (
|
2025-11-04 11:53:35 +08:00
|
|
|
<PageContainer header={{ title: '轮播图管理' }}>
|
|
|
|
|
{/*<SearchBarPlus*/}
|
|
|
|
|
{/* defaultCollapsed*/}
|
|
|
|
|
{/* split*/}
|
|
|
|
|
{/* span={8}*/}
|
|
|
|
|
{/* hideReset*/}
|
|
|
|
|
{/* showTenant={false}*/}
|
|
|
|
|
{/* onFinish={async (values) => {*/}
|
|
|
|
|
{/* setSearchParams(values);*/}
|
|
|
|
|
{/* actionRef.current?.reload();*/}
|
|
|
|
|
{/* }}*/}
|
|
|
|
|
{/*>*/}
|
|
|
|
|
{/* <ProFormText*/}
|
|
|
|
|
{/* name="title"*/}
|
|
|
|
|
{/* label="标题"*/}
|
|
|
|
|
{/* placeholder="请输入标题关键字"*/}
|
|
|
|
|
{/* />*/}
|
|
|
|
|
{/* <ProFormSelect*/}
|
|
|
|
|
{/* name="status"*/}
|
|
|
|
|
{/* label="状态"*/}
|
|
|
|
|
{/* placeholder="请选择状态"*/}
|
|
|
|
|
{/* options={STATUS_OPTIONS}*/}
|
|
|
|
|
{/* fieldProps={{*/}
|
|
|
|
|
{/* allowClear: true,*/}
|
|
|
|
|
{/* }}*/}
|
|
|
|
|
{/* />*/}
|
|
|
|
|
{/*</SearchBarPlus>*/}
|
2025-10-30 18:31:39 +08:00
|
|
|
|
2025-11-04 11:53:35 +08:00
|
|
|
<ActionBar
|
|
|
|
|
left={
|
|
|
|
|
<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => {
|
|
|
|
|
setCurrent(undefined);
|
|
|
|
|
setFormOpen(true);
|
|
|
|
|
}}>
|
|
|
|
|
新增轮播图
|
|
|
|
|
</GradientButton>
|
|
|
|
|
}
|
2025-09-29 19:29:41 +08:00
|
|
|
/>
|
2025-09-23 10:32:35 +08:00
|
|
|
|
2025-11-04 11:53:35 +08:00
|
|
|
<GlassCard>
|
|
|
|
|
<ProTable<HomeCarouselItem>
|
|
|
|
|
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}
|
|
|
|
|
/>
|
|
|
|
|
</GlassCard>
|
|
|
|
|
|
2025-10-30 18:31:39 +08:00
|
|
|
<CreateForm
|
2025-11-04 11:53:35 +08:00
|
|
|
open={formOpen}
|
|
|
|
|
initialValues={current}
|
|
|
|
|
onOpenChange={(visible) => {
|
|
|
|
|
setFormOpen(visible);
|
|
|
|
|
if (!visible) {
|
|
|
|
|
setCurrent(undefined);
|
2025-10-30 18:31:39 +08:00
|
|
|
}
|
2025-09-23 10:32:35 +08:00
|
|
|
}}
|
|
|
|
|
onFinish={async (values) => {
|
|
|
|
|
const hide = message.loading('保存中...');
|
|
|
|
|
try {
|
2025-11-04 11:53:35 +08:00
|
|
|
if (current?.id) {
|
|
|
|
|
// 编辑模式
|
|
|
|
|
await ordersApi.saveOrUpdateHomeCarousel({ ...(current as any), ...values });
|
|
|
|
|
message.success('修改成功');
|
|
|
|
|
} else {
|
|
|
|
|
// 新增模式
|
|
|
|
|
await ordersApi.saveOrUpdateHomeCarousel(values);
|
|
|
|
|
message.success('新增成功');
|
|
|
|
|
}
|
2025-10-30 18:31:39 +08:00
|
|
|
actionRef.current?.reload();
|
2025-09-23 10:32:35 +08:00
|
|
|
return true;
|
|
|
|
|
} catch (e) {
|
2025-10-30 18:31:39 +08:00
|
|
|
message.error('保存失败');
|
2025-09-23 10:32:35 +08:00
|
|
|
return false;
|
2025-10-30 18:31:39 +08:00
|
|
|
} finally {
|
|
|
|
|
hide();
|
|
|
|
|
}
|
2025-09-23 10:32:35 +08:00
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</PageContainer>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default HomeCarouselPage;
|
|
|
|
|
|