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:
@@ -78,52 +78,56 @@ const CreateForm: React.FC<CreateFormProps> = ({
|
|||||||
maskClosable: false,
|
maskClosable: false,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ProForm.Group>
|
<ProFormText
|
||||||
<ProFormText
|
name="title"
|
||||||
width="md"
|
label="标题"
|
||||||
name="title"
|
placeholder="请输入轮播图标题"
|
||||||
label="标题"
|
rules={[{ required: true, message: '标题不能为空' }]}
|
||||||
placeholder="请输入轮播图标题"
|
/>
|
||||||
rules={[{ required: true, message: '标题不能为空' }]}
|
<ProFormText
|
||||||
/>
|
name="linkUrl"
|
||||||
<ProFormText
|
label="跳转链接"
|
||||||
width="md"
|
placeholder="请输入跳转链接"
|
||||||
name="linkUrl"
|
rules={[{ type: 'url', message: '请输入正确的URL格式' }]}
|
||||||
label="跳转链接"
|
/>
|
||||||
placeholder="请输入跳转链接"
|
<ProFormSelect
|
||||||
rules={[{ type: 'url', message: '请输入正确的URL格式' }]}
|
name="type"
|
||||||
/>
|
label="类型"
|
||||||
<ProFormDigit
|
placeholder="请选择类型"
|
||||||
width="md"
|
options={[
|
||||||
name="sort"
|
{ label: '首页轮播', value: 0 },
|
||||||
label="排序"
|
{ label: '活动', value: 1 },
|
||||||
placeholder="请输入排序号"
|
{ label: '其他', value: 2 },
|
||||||
min={1}
|
]}
|
||||||
fieldProps={{ precision: 0 }}
|
rules={[{ required: true, message: '请选择类型' }]}
|
||||||
initialValue={1}
|
/>
|
||||||
/>
|
|
||||||
<ProFormSelect
|
|
||||||
width="md"
|
|
||||||
name="status"
|
|
||||||
label="状态"
|
|
||||||
placeholder="请选择状态"
|
|
||||||
options={[
|
|
||||||
{ label: '启用', value: 1 },
|
|
||||||
{ label: '禁用', value: 0 },
|
|
||||||
]}
|
|
||||||
rules={[{ required: true, message: '请选择状态' }]}
|
|
||||||
initialValue={1}
|
|
||||||
/>
|
|
||||||
</ProForm.Group>
|
|
||||||
|
|
||||||
<ProFormTextArea
|
<ProFormTextArea
|
||||||
name="description"
|
name="description"
|
||||||
label="描述"
|
label="描述"
|
||||||
placeholder="请输入描述信息"
|
placeholder="请输入轮播图描述"
|
||||||
fieldProps={{
|
fieldProps={{
|
||||||
rows: 3,
|
rows: 3,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<ProFormDigit
|
||||||
|
name="sort"
|
||||||
|
label="排序"
|
||||||
|
placeholder="请输入排序号"
|
||||||
|
min={1}
|
||||||
|
fieldProps={{ precision: 0 }}
|
||||||
|
initialValue={1}
|
||||||
|
/>
|
||||||
|
<ProFormSelect
|
||||||
|
name="status"
|
||||||
|
label="状态"
|
||||||
|
placeholder="请选择状态"
|
||||||
|
options={[
|
||||||
|
{ label: '启用', value: 1 },
|
||||||
|
{ label: '禁用', value: 0 },
|
||||||
|
]}
|
||||||
|
rules={[{ required: true, message: '请选择状态' }]}
|
||||||
|
initialValue={1}
|
||||||
|
/>
|
||||||
|
|
||||||
<div style={{ marginBottom: 16 }}>
|
<div style={{ marginBottom: 16 }}>
|
||||||
<label style={{ display: 'block', marginBottom: 8, fontWeight: 500 }}>
|
<label style={{ display: 'block', marginBottom: 8, fontWeight: 500 }}>
|
||||||
@@ -171,3 +175,4 @@ const CreateForm: React.FC<CreateFormProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default CreateForm;
|
export default CreateForm;
|
||||||
|
|
||||||
|
|||||||
+27
-6
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { ModalForm, ProFormDigit, ProFormSelect, ProFormText } from '@ant-design/pro-components';
|
import { ModalForm, ProFormDigit, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-components';
|
||||||
|
|
||||||
export interface HomeCarouselItem {
|
export interface HomeCarouselItem {
|
||||||
id?: number;
|
id?: number;
|
||||||
@@ -9,6 +9,7 @@ export interface HomeCarouselItem {
|
|||||||
status?: number;
|
status?: number;
|
||||||
title?: string;
|
title?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
type?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HomeCarouselFormProps {
|
export interface HomeCarouselFormProps {
|
||||||
@@ -36,23 +37,43 @@ const HomeCarouselForm: React.FC<HomeCarouselFormProps> = ({
|
|||||||
maskClosable: false,
|
maskClosable: false,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<ProFormText
|
||||||
|
name="title"
|
||||||
|
label="标题"
|
||||||
|
placeholder="请输入轮播图标题"
|
||||||
|
rules={[{ required: true, message: '标题不能为空' }]}
|
||||||
|
/>
|
||||||
<ProFormText
|
<ProFormText
|
||||||
name="imageUrl"
|
name="imageUrl"
|
||||||
label="图片地址"
|
label="图片地址"
|
||||||
placeholder="请输入图片地址或使用上传功能"
|
placeholder="请输入图片地址或使用上传功能"
|
||||||
rules={[{ required: true, message: '请输入图片地址' }]}
|
rules={[{ required: true, message: '请输入图片地址' }]}
|
||||||
/>
|
/>
|
||||||
<ProFormText
|
|
||||||
name="title"
|
|
||||||
label="标题"
|
|
||||||
placeholder="请输入轮播图标题"
|
|
||||||
/>
|
|
||||||
<ProFormText
|
<ProFormText
|
||||||
name="linkUrl"
|
name="linkUrl"
|
||||||
label="跳转链接"
|
label="跳转链接"
|
||||||
placeholder="请输入跳转链接"
|
placeholder="请输入跳转链接"
|
||||||
rules={[{ type: 'url', message: '请输入正确的URL格式' }]}
|
rules={[{ type: 'url', message: '请输入正确的URL格式' }]}
|
||||||
/>
|
/>
|
||||||
|
<ProFormSelect
|
||||||
|
name="type"
|
||||||
|
label="类型"
|
||||||
|
placeholder="请选择类型"
|
||||||
|
options={[
|
||||||
|
{ label: '首页轮播', value: 0 },
|
||||||
|
{ label: '活动', value: 1 },
|
||||||
|
{ label: '其他', value: 2 },
|
||||||
|
]}
|
||||||
|
rules={[{ required: true, message: '请选择类型' }]}
|
||||||
|
/>
|
||||||
|
<ProFormTextArea
|
||||||
|
name="description"
|
||||||
|
label="描述"
|
||||||
|
placeholder="请输入轮播图描述"
|
||||||
|
fieldProps={{
|
||||||
|
rows: 3,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<ProFormDigit
|
<ProFormDigit
|
||||||
name="sort"
|
name="sort"
|
||||||
label="排序"
|
label="排序"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useRef, useState } from 'react';
|
import React, { useRef, useState } from 'react';
|
||||||
import { PageContainer, ProTable, QueryFilter, ProFormText, ProFormSelect } from '@ant-design/pro-components';
|
import { PageContainer, ProTable, QueryFilter, ProFormText, ProFormSelect } from '@ant-design/pro-components';
|
||||||
import { Popconfirm, Space, Button, message, Typography, Image as AntImage } from 'antd';
|
import { Popconfirm, message, Typography, Image as AntImage } from 'antd';
|
||||||
import { PlusOutlined, DeleteOutlined, EditOutlined, UploadOutlined } from '@ant-design/icons';
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||||
import { ordersApi } from '@/services/orders';
|
import { ordersApi } from '@/services/orders';
|
||||||
import HomeCarouselForm from './components/HomeCarouselForm';
|
import HomeCarouselForm from './components/HomeCarouselForm';
|
||||||
@@ -17,6 +17,12 @@ const STATUS_OPTIONS = [
|
|||||||
{ label: '禁用', value: 0 },
|
{ label: '禁用', value: 0 },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const TYPE_OPTIONS = [
|
||||||
|
{ label: '首页轮播', value: 0 },
|
||||||
|
{ label: '活动', value: 1 },
|
||||||
|
{ label: '其他', value: 2 },
|
||||||
|
];
|
||||||
|
|
||||||
const HomeCarouselPage: React.FC = () => {
|
const HomeCarouselPage: React.FC = () => {
|
||||||
const actionRef = useRef<ActionType>();
|
const actionRef = useRef<ActionType>();
|
||||||
const [createOpen, setCreateOpen] = useState(false);
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
@@ -46,6 +52,12 @@ const HomeCarouselPage: React.FC = () => {
|
|||||||
valueType: 'indexBorder',
|
valueType: 'indexBorder',
|
||||||
width: 48,
|
width: 48,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '标题',
|
||||||
|
dataIndex: 'title',
|
||||||
|
ellipsis: true,
|
||||||
|
copyable: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '图片',
|
title: '图片',
|
||||||
dataIndex: 'imageUrl',
|
dataIndex: 'imageUrl',
|
||||||
@@ -67,9 +79,23 @@ const HomeCarouselPage: React.FC = () => {
|
|||||||
dataIndex: 'linkUrl',
|
dataIndex: 'linkUrl',
|
||||||
ellipsis: true,
|
ellipsis: true,
|
||||||
render: (url: string) => (
|
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: '排序',
|
title: '排序',
|
||||||
dataIndex: 'sort',
|
dataIndex: 'sort',
|
||||||
@@ -88,25 +114,29 @@ const HomeCarouselPage: React.FC = () => {
|
|||||||
title: '操作',
|
title: '操作',
|
||||||
valueType: 'option',
|
valueType: 'option',
|
||||||
width: 180,
|
width: 180,
|
||||||
render: (_, record) => (
|
fixed: 'right',
|
||||||
<Space>
|
render: (_, record) => [
|
||||||
<Link
|
<a
|
||||||
onClick={() => {
|
key="edit"
|
||||||
setCurrent(record);
|
onClick={() => {
|
||||||
setEditOpen(true);
|
console.log('编辑按钮被点击', record);
|
||||||
}}
|
setCurrent(record);
|
||||||
>
|
setEditOpen(true);
|
||||||
<EditOutlined /> 编辑
|
}}
|
||||||
</Link>
|
>
|
||||||
<Popconfirm
|
编辑
|
||||||
title="确认删除?"
|
</a>,
|
||||||
description="删除后将无法恢复,请谨慎操作"
|
<Popconfirm
|
||||||
onConfirm={() => handleDelete(record)}
|
key="delete"
|
||||||
>
|
title="确认删除?"
|
||||||
<Link><DeleteOutlined /> 删除</Link>
|
description="删除后将无法恢复,请谨慎操作"
|
||||||
</Popconfirm>
|
onConfirm={() => handleDelete(record)}
|
||||||
</Space>
|
okText="确认"
|
||||||
),
|
cancelText="取消"
|
||||||
|
>
|
||||||
|
<a>删除</a>
|
||||||
|
</Popconfirm>,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -155,13 +185,16 @@ const HomeCarouselPage: React.FC = () => {
|
|||||||
showQuickJumper: true,
|
showQuickJumper: true,
|
||||||
}}
|
}}
|
||||||
toolBarRender={() => [
|
toolBarRender={() => [
|
||||||
<Button
|
<a
|
||||||
key="add"
|
key="add"
|
||||||
type="primary"
|
onClick={() => {
|
||||||
onClick={() => setCreateOpen(true)}
|
console.log('新增按钮被点击');
|
||||||
|
setCreateOpen(true);
|
||||||
|
}}
|
||||||
|
style={{ color: '#1890ff', cursor: 'pointer' }}
|
||||||
>
|
>
|
||||||
<PlusOutlined /> 新增轮播图
|
<PlusOutlined /> 新增轮播图
|
||||||
</Button>,
|
</a>,
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user