fix: 修复首页轮播图表单和按钮响应问题

修复内容:
- 在表格中添加标题、类型、描述字段显示
- 更新表单类型定义,添加 type 字段支持
- 修复 CreateForm 和 HomeCarouselForm 组件,添加完整的表单字段
- 改进操作列按钮,使用 array 渲染方式确保点击响应
- 改进新增按钮交互,使用 Link 样式优化视觉效果
- 添加 console.log 便于调试按钮点击事件
- 优化搜索栏字段,支持标题和状态搜索

现在支持显示和编辑以下字段:
- 标题 (title)
- 图片 (imageUrl)
- 跳转链接 (linkUrl)
- 类型 (type)
- 描述 (description)
- 排序 (sort)
- 状态 (status)

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-30 18:41:40 +08:00
co-authored by Claude
parent 636003a8ea
commit ed7fc3fecc
3 changed files with 130 additions and 71 deletions
@@ -1,7 +1,7 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProTable, QueryFilter, ProFormText, ProFormSelect } from '@ant-design/pro-components';
import { Popconfirm, Space, Button, message, Typography, Image as AntImage } from 'antd';
import { PlusOutlined, DeleteOutlined, EditOutlined, UploadOutlined } from '@ant-design/icons';
import { Popconfirm, message, Typography, Image as AntImage } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { ordersApi } from '@/services/orders';
import HomeCarouselForm from './components/HomeCarouselForm';
@@ -17,6 +17,12 @@ const STATUS_OPTIONS = [
{ label: '禁用', value: 0 },
];
const TYPE_OPTIONS = [
{ label: '首页轮播', value: 0 },
{ label: '活动', value: 1 },
{ label: '其他', value: 2 },
];
const HomeCarouselPage: React.FC = () => {
const actionRef = useRef<ActionType>();
const [createOpen, setCreateOpen] = useState(false);
@@ -46,6 +52,12 @@ const HomeCarouselPage: React.FC = () => {
valueType: 'indexBorder',
width: 48,
},
{
title: '标题',
dataIndex: 'title',
ellipsis: true,
copyable: true,
},
{
title: '图片',
dataIndex: 'imageUrl',
@@ -67,9 +79,23 @@ const HomeCarouselPage: React.FC = () => {
dataIndex: 'linkUrl',
ellipsis: true,
render: (url: string) => (
<Link href={url} target="_blank">{url}</Link>
url ? <Link href={url} target="_blank">{url}</Link> : '-'
),
},
{
title: '类型',
dataIndex: 'type',
width: 100,
valueEnum: TYPE_OPTIONS.reduce((acc, curr) => ({
...acc,
[curr.value]: { text: curr.label },
}), {}),
},
{
title: '描述',
dataIndex: 'description',
ellipsis: true,
},
{
title: '排序',
dataIndex: 'sort',
@@ -88,25 +114,29 @@ const HomeCarouselPage: React.FC = () => {
title: '操作',
valueType: 'option',
width: 180,
render: (_, record) => (
<Space>
<Link
onClick={() => {
setCurrent(record);
setEditOpen(true);
}}
>
<EditOutlined /> 编辑
</Link>
<Popconfirm
title="确认删除?"
description="删除后将无法恢复,请谨慎操作"
onConfirm={() => handleDelete(record)}
>
<Link><DeleteOutlined /> 删除</Link>
</Popconfirm>
</Space>
),
fixed: 'right',
render: (_, record) => [
<a
key="edit"
onClick={() => {
console.log('编辑按钮被点击', record);
setCurrent(record);
setEditOpen(true);
}}
>
编辑
</a>,
<Popconfirm
key="delete"
title="确认删除?"
description="删除后将无法恢复,请谨慎操作"
onConfirm={() => handleDelete(record)}
okText="确认"
cancelText="取消"
>
<a>删除</a>
</Popconfirm>,
],
},
];
@@ -155,13 +185,16 @@ const HomeCarouselPage: React.FC = () => {
showQuickJumper: true,
}}
toolBarRender={() => [
<Button
<a
key="add"
type="primary"
onClick={() => setCreateOpen(true)}
onClick={() => {
console.log('新增按钮被点击');
setCreateOpen(true);
}}
style={{ color: '#1890ff', cursor: 'pointer' }}
>
<PlusOutlined /> 新增轮播图
</Button>,
</a>,
]}
/>