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,
|
||||
}}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="title"
|
||||
label="标题"
|
||||
placeholder="请输入轮播图标题"
|
||||
rules={[{ required: true, message: '标题不能为空' }]}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="linkUrl"
|
||||
label="跳转链接"
|
||||
placeholder="请输入跳转链接"
|
||||
rules={[{ type: 'url', message: '请输入正确的URL格式' }]}
|
||||
/>
|
||||
<ProFormDigit
|
||||
width="md"
|
||||
name="sort"
|
||||
label="排序"
|
||||
placeholder="请输入排序号"
|
||||
min={1}
|
||||
fieldProps={{ precision: 0 }}
|
||||
initialValue={1}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="status"
|
||||
label="状态"
|
||||
placeholder="请选择状态"
|
||||
options={[
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
]}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
initialValue={1}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProFormText
|
||||
name="title"
|
||||
label="标题"
|
||||
placeholder="请输入轮播图标题"
|
||||
rules={[{ required: true, message: '标题不能为空' }]}
|
||||
/>
|
||||
<ProFormText
|
||||
name="linkUrl"
|
||||
label="跳转链接"
|
||||
placeholder="请输入跳转链接"
|
||||
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="请输入描述信息"
|
||||
placeholder="请输入轮播图描述"
|
||||
fieldProps={{
|
||||
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 }}>
|
||||
<label style={{ display: 'block', marginBottom: 8, fontWeight: 500 }}>
|
||||
@@ -171,3 +175,4 @@ const CreateForm: React.FC<CreateFormProps> = ({
|
||||
};
|
||||
|
||||
export default CreateForm;
|
||||
|
||||
|
||||
+27
-6
@@ -1,5 +1,5 @@
|
||||
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 {
|
||||
id?: number;
|
||||
@@ -9,6 +9,7 @@ export interface HomeCarouselItem {
|
||||
status?: number;
|
||||
title?: string;
|
||||
description?: string;
|
||||
type?: number;
|
||||
}
|
||||
|
||||
export interface HomeCarouselFormProps {
|
||||
@@ -36,23 +37,43 @@ const HomeCarouselForm: React.FC<HomeCarouselFormProps> = ({
|
||||
maskClosable: false,
|
||||
}}
|
||||
>
|
||||
<ProFormText
|
||||
name="title"
|
||||
label="标题"
|
||||
placeholder="请输入轮播图标题"
|
||||
rules={[{ required: true, message: '标题不能为空' }]}
|
||||
/>
|
||||
<ProFormText
|
||||
name="imageUrl"
|
||||
label="图片地址"
|
||||
placeholder="请输入图片地址或使用上传功能"
|
||||
rules={[{ required: true, message: '请输入图片地址' }]}
|
||||
/>
|
||||
<ProFormText
|
||||
name="title"
|
||||
label="标题"
|
||||
placeholder="请输入轮播图标题"
|
||||
/>
|
||||
<ProFormText
|
||||
name="linkUrl"
|
||||
label="跳转链接"
|
||||
placeholder="请输入跳转链接"
|
||||
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
|
||||
name="sort"
|
||||
label="排序"
|
||||
|
||||
@@ -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>,
|
||||
]}
|
||||
/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user