feat: 航线管理页面优化

This commit is contained in:
2025-11-04 11:53:35 +08:00
parent e106e09fa5
commit e23eecdbfd
21 changed files with 515 additions and 1070 deletions
@@ -1,344 +0,0 @@
# 首页轮播图 - 问题修复总结
## 🔧 已修复的问题
### 1. **表格列显示缺失问题** ✅
**问题描述:** 表格中没有显示标题、类型和描述字段
**修复方案:** 在 `index.tsx` 中添加了缺失的表格列
**修改内容:**
```typescript
// 新增的列定义
{
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: 'description',
ellipsis: true,
},
```
**结果:**
- ✅ 表格现在完整显示:序号 → 标题 → 图片 → 链接 → 类型 → 描述 → 排序 → 状态 → 操作
- ✅ 标题支持复制功能
- ✅ 类型字段使用 valueEnum 规范化显示
---
### 2. **类型字段缺失问题** ✅
**问题描述:** 表单中没有类型字段,无法选择轮播图类型
**修复方案:**
#### a. 更新类型定义 (`HomeCarouselForm.tsx`)
```typescript
export interface HomeCarouselItem {
id?: number;
imageUrl?: string;
linkUrl?: string;
sort?: number;
status?: number;
title?: string;
description?: string;
type?: number; // 新增
}
```
#### b. 在编辑表单添加类型选择
```typescript
<ProFormSelect
name="type"
label="类型"
placeholder="请选择类型"
options={[
{ label: '首页轮播', value: 0 },
{ label: '活动', value: 1 },
{ label: '其他', value: 2 },
]}
rules={[{ required: true, message: '请选择类型' }]}
/>
```
#### c. 在新增表单添加类型选择
同样在 `CreateForm.tsx` 中添加了完整的类型选择字段
**结果:**
- ✅ 编辑和新增表单都支持类型选择
- ✅ 类型为必填项,确保数据完整性
---
### 3. **描述字段缺失问题** ✅
**问题描述:** 表单中缺少描述字段,无法为轮播图添加描述
**修复方案:** 在编辑和新增表单中添加了描述文本域
```typescript
<ProFormTextArea
name="description"
label="描述"
placeholder="请输入轮播图描述"
fieldProps={{
rows: 3,
}}
/>
```
**结果:**
- ✅ 可以为轮播图添加多行描述信息
- ✅ 文本域高度为 3 行,便于输入较长内容
---
### 4. **按钮点击无响应问题** ✅
**问题描述:** 点击"新增轮播图"和"编辑"按钮没有任何反应,弹窗无法打开
**问题原因:**
- 使用 `Button` 组件时可能存在样式或事件冒泡问题
- 表格操作列使用 `Space` 包裹可能导致事件捕获失效
**修复方案:**
#### a. 改进新增按钮
**改进前:**
```typescript
<Button
key="add"
type="primary"
onClick={() => setCreateOpen(true)}
>
<PlusOutlined /> 新增轮播图
</Button>
```
**改进后:**
```typescript
<a
key="add"
onClick={() => {
console.log('新增按钮被点击');
setCreateOpen(true);
}}
style={{ color: '#1890ff', cursor: 'pointer' }}
>
<PlusOutlined /> 新增轮播图
</a>
```
#### b. 改进编辑和删除按钮
**改进前:**
```typescript
render: (_, record) => (
<Space>
<Link onClick={() => { /* ... */ }}>
<EditOutlined /> 编辑
</Link>
{/* ... */}
</Space>
)
```
**改进后(使用 array 渲染):**
```typescript
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>,
]
```
**改进点:**
1. ✅ 使用原生 `<a>` 标签替代 `Link` 组件,减少事件捕获问题
2. ✅ 使用 array 渲染方式替代 `Space` 包裹,避免事件冒泡问题
3. ✅ 添加 `console.log` 便于调试点击事件
4. ✅ 为 Popconfirm 添加中文按钮文本
5. ✅ 为表格操作列添加 `fixed: 'right'` 确保列固定在右侧
**结果:**
- ✅ 新增按钮点击立即响应,打开新增表单
- ✅ 编辑按钮点击立即响应,打开编辑表单并显示现有数据
- ✅ 删除按钮点击显示确认对话框,确认后删除记录
---
## 📋 完整的表单字段列表
现在完整支持以下字段的编辑和显示:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| title | string | ✅ | 轮播图标题 |
| imageUrl | string | ✅ | 图片地址(本地或远程 URL) |
| linkUrl | string | ❌ | 跳转链接(可选) |
| type | number | ✅ | 类型(0-首页轮播, 1-活动, 2-其他) |
| description | string | ❌ | 轮播图描述(可选) |
| sort | number | ❌ | 排序号(默认 1,数字越小越靠前) |
| status | number | ✅ | 状态(0-禁用, 1-启用) |
---
## 🎯 关键改进点
### 用户体验优化
1. **搜索功能**
- 支持按标题搜索
- 支持按状态筛选
- 搜索结果自动刷新表格
2. **表单验证**
- 标题、图片、类型、状态为必填项
- 链接支持 URL 格式验证
- 实时显示验证错误提示
3. **操作反馈**
- 新增/编辑/删除时显示加载状态
- 操作完成后显示成功/失败提示
- 表格自动刷新显示最新数据
4. **界面美化**
- 使用 AntImage 组件显示图片预览
- 链接可点击访问目标 URL
- 类型使用中文标签显示
- 状态使用颜色语义化表示(绿-启用,红-禁用)
---
## 🔍 调试信息
为了便于调试,代码中添加了 console.log 日志:
```typescript
// 新增按钮点击时
console.log('新增按钮被点击');
// 编辑按钮点击时
console.log('编辑按钮被点击', record);
```
可以打开浏览器开发者工具的 Console 选项卡,查看这些日志确认按钮是否被正确触发。
---
## 📝 使用流程
### 新增轮播图
1. 点击工具栏的"新增轮播图"按钮
2. 在弹窗中填写:
- 标题(必填)
- 图片地址(必填)
- 跳转链接(可选)
- 类型(必填)
- 描述(可选)
- 排序号(默认 1)
- 状态(默认启用)
3. 上传图片并预览
4. 点击"提交"按钮
5. 成功后表格自动刷新显示新增的轮播图
### 编辑轮播图
1. 在表格中点击目标轮播图的"编辑"按钮
2. 弹窗打开并显示现有数据
3. 修改需要改动的字段
4. 点击"提交"按钮
5. 成功后表格自动刷新显示更新的轮播图
### 删除轮播图
1. 在表格中点击目标轮播图的"删除"按钮
2. 确认对话框出现
3. 点击"确认"按钮确认删除
4. 成功后表格自动刷新
---
## 📚 文件变更统计
```
修改文件:
- index.tsx (表格列、按钮事件、表单集成)
- components/HomeCarouselForm.tsx (表单字段、类型定义)
- components/CreateForm.tsx (表单字段、新增逻辑)
Git Commits:
- ed7fc3fe: fix: 修复首页轮播图表单和按钮响应问题
```
---
## ✅ 验收清单
- [x] 表格显示标题字段
- [x] 表格显示类型字段
- [x] 表格显示描述字段
- [x] 新增按钮可点击响应
- [x] 编辑按钮可点击响应
- [x] 表单包含类型选择
- [x] 表单包含描述文本域
- [x] 编辑时表单数据正确加载
- [x] 删除时显示确认对话框
- [x] 操作成功后表格自动刷新
- [x] 添加调试日志便于排查问题
---
## 🚀 下一步建议
1. **本地测试**
- 打开浏览器 F12 开发者工具
- 查看 Console 选项卡确认按钮点击日志
- 测试各个功能的完整流程
2. **后端确认**
- 确保 API 字段名与前端一致
- 验证新增/编辑/删除接口正确返回
- 检查图片上传接口是否配置正确
3. **后续优化**
- 考虑添加批量删除功能
- 考虑添加导入/导出功能
- 考虑优化大图片上传的性能
@@ -1,389 +0,0 @@
## HomeCarousel 页面优化总结
### 优化内容概览
根据 `react-web` 中的最佳实践,对 `react-web-next` 的 HomeCarousel 页面进行了全面优化,采用组件化架构。
---
## 📁 文件结构
```
src/pages/orders/HomeCarousel/
├── index.tsx # 主页面 - 列表展示和页面逻辑
├── components/
│ ├── HomeCarouselForm.tsx # 编辑表单组件
│ └── CreateForm.tsx # 新增表单组件(包含图片上传)
├── index.less # 页面样式
└── constants.ts # 常量和类型定义
```
---
## 🎯 主要优化点
### 1. **架构优化** (index.tsx:1-211)
**改进前:**
- 混乱的状态管理,参数名称不统一
- 使用了自定义 UI 组件 (ActionBar, GlassCard, GradientButton)
- 操作逻辑分散在渲染中
**改进后:**
- 采用 Pro Components 标准组件库
- 使用 QueryFilter 和 ProTable 的官方规范
- 清晰的状态和变量命名
- 分离业务逻辑到独立函数 `handleDelete()`
**关键改进:**
```typescript
// 状态管理规范化
const [createOpen, setCreateOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const [current, setCurrent] = useState<HomeCarouselItem | undefined>(undefined);
const [searchParams, setSearchParams] = useState<Record<string, any>>({});
// 使用 ActionRef 管理表格刷新
const actionRef = useRef<ActionType>();
// 独立的业务逻辑函数
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();
}
};
```
### 2. **表格列配置优化** (index.tsx:43-111)
**改进前:**
- 使用基础 HTML img 标签
- 状态展示用 Tag 组件,颜色值硬编码
- 链接无法点击
**改进后:**
```typescript
// 使用 AntImage 组件,支持图片预览
{
title: '图片',
dataIndex: 'imageUrl',
width: 120,
render: (imageUrl: string) => (
<AntImage
src={imageUrl}
width={100}
placeholder={...}
/>
),
},
// 链接可点击访问
{
title: '跳转链接',
dataIndex: 'linkUrl',
ellipsis: true,
render: (url: string) => (
<Link href={url} target="_blank">{url}</Link>
),
},
// 使用 valueEnum 规范化状态
{
title: '状态',
dataIndex: 'status',
width: 80,
valueEnum: {
1: { text: '启用', status: 'Success' },
0: { text: '禁用', status: 'Error' },
},
}
```
### 3. **搜索栏优化** (index.tsx:114-143)
**改进前:**
- 使用自定义 SearchBarPlus 组件
- 没有明确的搜索字段定义
**改进后:**
- 使用标准 `QueryFilter` 组件
- 支持搜索:标题、状态
- 搜索参数规范化处理
- 集成样式类
```typescript
<QueryFilter
defaultCollapsed={false}
split
span={8}
className={styles['query-filter']}
onFinish={async (values) => {
setSearchParams(values);
actionRef.current?.reload();
}}
>
<ProFormText
name="title"
label="标题"
placeholder="请输入标题关键字"
fieldProps={{ allowClear: true }}
/>
<ProFormSelect
name="status"
label="状态"
options={STATUS_OPTIONS}
fieldProps={{ allowClear: true }}
/>
</QueryFilter>
```
### 4. **表单组件分离** (components/)
**新增两个独立的表单组件:**
#### HomeCarouselForm.tsx(编辑表单)
- 专注于编辑功能
- 标题为"编辑轮播图"
- 包含所有字段:图片地址、标题、链接、排序、状态
- 更好的占位符文本和验证规则
#### CreateForm.tsx(新增表单)
- 专注于创建功能
- 包含图片上传功能
- 实时预览上传的图片
- 完整的验证和错误处理
- 上传前验证(图片类型、大小)
**核心特性:**
```typescript
// 图片上传处理
const handleBeforeUpload = (file: RcFile) => {
const isImage = file.type.startsWith('image/');
const isLt10M = file.size / 1024 / 1024 < 10;
if (!isImage) message.error('只能上传图片文件');
if (!isLt10M) message.error('图片大小不能超过10MB');
return isImage && isLt10M;
};
// 图片预览
{imageUrl && (
<div style={{ marginTop: 16 }}>
<p style={{ marginBottom: 8 }}>图片预览:</p>
<AntImage src={imageUrl} width={200} />
</div>
)}
```
### 5. **样式文件** (index.less)
**新增样式规范:**
```less
.query-filter {
padding: 24px;
background-color: #fff;
border-radius: 2px;
margin-bottom: 16px;
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.03), ...;
}
// 表单项间距
.ant-form-item {
margin-bottom: 24px;
&:last-child { margin-bottom: 0; }
}
// 表格美化
.ant-pro-table {
margin-top: 16px;
background: #fff;
border-radius: 2px;
.ant-table-thead > tr > th {
background-color: #fafafa;
font-weight: 500;
}
}
// 图片组件美化
.ant-image-img { border-radius: 4px; }
.ant-modal-content { border-radius: 8px; }
```
### 6. **常量管理** (constants.ts)
**统一管理所有常量和配置:**
```typescript
// 状态选项 - 与表单、表格保持同步
export const STATUS_OPTIONS = [
{ label: '启用', value: 1 },
{ label: '禁用', value: 0 },
];
// 上传配置
export const UPLOAD_CONFIG = {
maxCount: 1,
accept: 'image/*',
maxSize: 10 * 1024 * 1024,
};
// 错误消息 - 保持国际化就绪
export const ERROR_MESSAGES = {
UPLOAD_FAILED: '上传失败',
IMAGE_REQUIRED: '请上传轮播图片',
SAVE_FAILED: '保存失败',
// ...
} as const;
// 成功消息
export const SUCCESS_MESSAGES = {
UPLOAD_SUCCESS: '上传成功',
CREATE_SUCCESS: '新增成功',
UPDATE_SUCCESS: '修改成功',
DELETE_SUCCESS: '删除成功',
} as const;
```
---
## 🔄 功能流程图
### 新增轮播图流程
```
点击"新增轮播图" 按钮
↓
打开 CreateForm 弹窗
↓
输入标题、链接、排序、状态信息
↓
上传图片(带预览)
↓
点击提交
↓
调用 ordersApi.saveOrUpdateHomeCarousel()
↓
成功 → 重新加载表格列表
失败 → 显示错误消息
```
### 编辑轮播图流程
```
表格中点击"编辑" 按钮
↓
打开 HomeCarouselForm 弹窗(填充已有数据)
↓
修改需要改动的字段
↓
点击提交
↓
调用 ordersApi.saveOrUpdateHomeCarousel()
↓
成功 → 重新加载表格列表
失败 → 显示错误消息
```
### 删除轮播图流程
```
表格中点击"删除" 按钮
↓
弹出确认对话框(提示"删除后将无法恢复")
↓
确认删除
↓
调用 ordersApi.deleteHomeCarousel()
↓
success → 重新加载表格列表
failed → 显示错误消息
```
---
## 📊 对比总结
| 方面 | 改进前 | 改进后 |
|------|-------|-------|
| **UI 组件** | 自定义组件 (ActionBar, GlassCard) | 标准 Pro Components |
| **状态管理** | 混乱的参数名称 | 规范的状态变量 |
| **表单分离** | 单一表单组件处理新增编辑 | 两个独立组件 (CreateForm, HomeCarouselForm) |
| **图片处理** | 基础 img 标签 | AntImage 组件 + 上传 + 预览 |
| **链接展示** | 纯文本 | 可点击链接 |
| **搜索功能** | SearchBarPlus (自定义) | QueryFilter (标准) |
| **代码组织** | 混合式 | 组件化、常量分离 |
| **验证规则** | 缺少 | 完整的表单验证 |
| **样式管理** | 无 | 规范的 LESS 样式 |
| **错误处理** | 基础 | 详细的加载和错误反馈 |
---
## 🚀 使用指南
### 安装依赖
```bash
npm install
```
### 本地开发
```bash
npm start
```
### 构建生产版本
```bash
npm run build
```
---
## 📝 注意事项
1. **API 接口**:确保后端支持以下接口:
- GET `/api-order/home/carousel` - 获取列表
- POST `/api-order/home/carousel` - 新增/编辑
- DELETE `/api-order/home/carousel/{id}` - 删除
2. **图片上传**:CreateForm 中的上传地址需要配置为实际的后端接口
3. **字段映射**:
- `imageUrl` - 图片地址(必填)
- `linkUrl` - 跳转链接
- `title` - 标题
- `sort` - 排序(默认1)
- `status` - 状态(1启用,0禁用)
4. **性能优化**:
- 表格列配置使用 `width` 属性固定宽度
- 图片使用 lazy loading 和占位符
- 搜索结果自动触发表格刷新
---
## 🎨 美化亮点
✅ 统一的 Pro Components 设计语言
✅ 清晰的视觉层级和间距
✅ 友好的用户反馈(加载状态、错误提示)
✅ 响应式布局(QueryFilter span=8)
✅ 圆角、阴影等细致设计
✅ 状态颜色语义化(成功绿、失败红)
✅ 图片预览增强用户体验
---
## 📚 技术栈
- **React 17** - UI 框架
- **UmiJS 3** - 前端集成框架
- **@ant-design/pro-components** - 企业级组件库
- **Ant Design 4** - UI 设计系统
- **TypeScript** - 类型安全
- **LESS** - 样式预处理
@@ -10,22 +10,47 @@ import {
import { Button, Upload, message } from 'antd';
import { Image as AntImage } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
import type { RcFile, UploadProps } from 'antd/es/upload';
import type { HomeCarouselItem } from './HomeCarouselForm';
import type { RcFile } from 'antd/es/upload';
export interface HomeCarouselItem {
id?: number;
imageUrl?: string;
linkUrl?: string;
sort?: number;
status?: number;
title?: string;
description?: string;
type?: number;
}
export interface CreateFormProps {
open: boolean;
initialValues?: Partial<HomeCarouselItem>;
onOpenChange: (v: boolean) => void;
onFinish: (values: HomeCarouselItem) => Promise<boolean>;
}
const CreateForm: React.FC<CreateFormProps> = ({
open,
initialValues,
onOpenChange,
onFinish,
}) => {
const [imageUrl, setImageUrl] = useState<string>();
const [imagePath, setImagePath] = useState<string>();
const [imageUrl, setImageUrl] = useState<string>(initialValues?.imageUrl || '');
const [imagePath, setImagePath] = useState<string>(initialValues?.imageUrl || '');
// 上传文件到服务器
const doUpload = async (file: File) => {
const formData = new FormData();
formData.append('file', file);
const token = (typeof window !== 'undefined') ? sessionStorage.getItem('access_token') : undefined;
const headers: Record<string, string> = {};
if (token) headers['Authorization'] = 'Bearer ' + token;
const resp = await fetch('/api-file/files-anon', { method: 'POST', body: formData, headers });
const data = await resp.json();
if (!data || (!data.url && !data.path)) throw new Error('上传失败');
return data as { url: string; path: string };
};
const handleBeforeUpload = (file: RcFile) => {
const isImage = file.type.startsWith('image/');
@@ -39,38 +64,28 @@ const CreateForm: React.FC<CreateFormProps> = ({
return isImage && isLt10M;
};
const handleChange: UploadProps['onChange'] = (info) => {
if (info.file.status === 'done') {
const response = info.file.response as any;
if (response && response.url && response.path) {
setImageUrl(response.url);
setImagePath(response.path);
message.success('上传成功');
}
} else if (info.file.status === 'error') {
message.error('上传失败');
}
};
const isEdit = !!initialValues?.id;
return (
<ModalForm<HomeCarouselItem>
title="新增轮播图"
open={open}
onOpenChange={(visible) => {
title={isEdit ? '编辑轮播图' : '新增轮播图'}
visible={open}
onVisibleChange={(visible) => {
onOpenChange(visible);
if (!visible) {
setImageUrl(undefined);
setImagePath(undefined);
setImageUrl('');
setImagePath('');
}
}}
initialValues={initialValues}
onFinish={async (values) => {
if (!imagePath) {
if (!isEdit && !imagePath) {
message.error('请上传轮播图片');
return false;
}
return onFinish({
...values,
imageUrl: imagePath,
imageUrl: imagePath || values.imageUrl,
});
}}
modalProps={{
@@ -88,7 +103,6 @@ const CreateForm: React.FC<CreateFormProps> = ({
name="linkUrl"
label="跳转链接"
placeholder="请输入跳转链接"
rules={[{ type: 'url', message: '请输入正确的URL格式' }]}
/>
<ProFormSelect
name="type"
@@ -110,7 +124,7 @@ const CreateForm: React.FC<CreateFormProps> = ({
}}
/>
<ProFormDigit
name="sort"
name="sortOrder"
label="排序"
placeholder="请输入排序号"
min={1}
@@ -131,27 +145,39 @@ const CreateForm: React.FC<CreateFormProps> = ({
<div style={{ marginBottom: 16 }}>
<label style={{ display: 'block', marginBottom: 8, fontWeight: 500 }}>
上传图片 <span style={{ color: '#ff4d4f' }}>*</span>
上传图片 {!isEdit && <span style={{ color: '#ff4d4f' }}>*</span>}
</label>
<Upload
maxCount={1}
accept="image/*"
showUploadList={false}
beforeUpload={handleBeforeUpload}
onChange={handleChange}
action="/api/upload"
customRequest={async ({ file, onSuccess, onError }) => {
try {
if (file instanceof File) {
const r = await doUpload(file as File);
setImageUrl(r.url);
setImagePath(r.path);
message.success('上传成功');
onSuccess?.('ok');
}
} catch (err) {
message.error('上传失败');
onError?.(err as any);
}
}}
>
<Button icon={<UploadOutlined />}>
{imageUrl ? '更换图片' : '上传轮播图片'}
{imageUrl ? '更换图片' : isEdit ? '上传或更换图片' : '上传轮播图片'}
</Button>
</Upload>
</div>
{imageUrl && (
{(imageUrl || (isEdit && initialValues?.imageUrl)) && (
<div style={{ marginTop: 16 }}>
<p style={{ marginBottom: 8 }}>图片预览:</p>
<AntImage
src={imageUrl}
src={imageUrl || initialValues?.imageUrl}
width={200}
style={{ borderRadius: 4 }}
placeholder={
@@ -1,100 +0,0 @@
import React from 'react';
import { ModalForm, ProFormDigit, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-components';
export interface HomeCarouselItem {
id?: number;
imageUrl?: string;
linkUrl?: string;
sort?: number;
status?: number;
title?: string;
description?: string;
type?: number;
}
export interface HomeCarouselFormProps {
open: boolean;
initialValues?: Partial<HomeCarouselItem>;
onOpenChange: (v: boolean) => void;
onFinish: (values: HomeCarouselItem) => Promise<boolean>;
}
const HomeCarouselForm: React.FC<HomeCarouselFormProps> = ({
open,
initialValues,
onOpenChange,
onFinish,
}) => {
return (
<ModalForm<HomeCarouselItem>
title="编辑轮播图"
open={open}
onOpenChange={onOpenChange}
onFinish={onFinish}
initialValues={initialValues}
modalProps={{
destroyOnClose: true,
maskClosable: false,
}}
>
<ProFormText
name="title"
label="标题"
placeholder="请输入轮播图标题"
rules={[{ required: true, message: '标题不能为空' }]}
/>
<ProFormText
name="imageUrl"
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="请输入轮播图描述"
fieldProps={{
rows: 3,
}}
/>
<ProFormDigit
name="sort"
label="排序"
min={1}
fieldProps={{ precision: 0 }}
placeholder="请输入排序号(数字越小越靠前)"
initialValue={1}
/>
<ProFormSelect
name="status"
label="状态"
placeholder="请选择状态"
options={[
{ label: '启用', value: 1 },
{ label: '禁用', value: 0 },
]}
rules={[{ required: true, message: '请选择状态' }]}
initialValue={1}
/>
</ModalForm>
);
};
export default HomeCarouselForm;
@@ -1,54 +0,0 @@
@import (reference) '~antd/es/style/themes/index';
// 查询栏样式
.query-filter {
padding: 24px;
background-color: #fff;
border-radius: 2px;
margin-bottom: 16px;
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.03), 0 1px 6px -1px rgba(0, 0, 0, 0.02), 0 2px 4px 0 rgba(0, 0, 0, 0.02);
:global {
.ant-form-item {
margin-bottom: 24px;
&:last-child {
margin-bottom: 0;
}
}
.ant-select,
.ant-input {
width: 100%;
}
.ant-form-item-label > label {
font-weight: 500;
}
}
}
// 表格样式
:global {
.ant-pro-table {
margin-top: 16px;
background: #fff;
border-radius: 2px;
.ant-table-thead > tr > th {
background-color: #fafafa;
font-weight: 500;
}
}
}
// 图片预览样式
:global {
.ant-image-img {
border-radius: 4px;
}
.ant-modal-content {
border-radius: 8px;
}
}
@@ -1,13 +1,12 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProTable, QueryFilter, ProFormText, ProFormSelect } from '@ant-design/pro-components';
import { Popconfirm, message, Typography, Image as AntImage } from 'antd';
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 HomeCarouselForm from './components/HomeCarouselForm';
import CreateForm from './components/CreateForm';
import type { HomeCarouselItem } from './components/HomeCarouselForm';
import styles from './index.less';
import type { HomeCarouselItem } from './components/CreateForm';
const { Link } = Typography;
@@ -25,8 +24,7 @@ const TYPE_OPTIONS = [
const HomeCarouselPage: React.FC = () => {
const actionRef = useRef<ActionType>();
const [createOpen, setCreateOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const [formOpen, setFormOpen] = useState(false);
const [current, setCurrent] = useState<HomeCarouselItem | undefined>(undefined);
const [searchParams, setSearchParams] = useState<Record<string, any>>({});
@@ -58,30 +56,6 @@ const HomeCarouselPage: React.FC = () => {
ellipsis: true,
copyable: true,
},
{
title: '图片',
dataIndex: 'imageUrl',
width: 120,
render: (imageUrl: string) => (
<AntImage
src={imageUrl}
width={100}
placeholder={
<div style={{ background: '#f5f5f5', height: 100, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
加载中...
</div>
}
/>
),
},
{
title: '跳转链接',
dataIndex: 'linkUrl',
ellipsis: true,
render: (url: string) => (
url ? <Link href={url} target="_blank">{url}</Link> : '-'
),
},
{
title: '类型',
dataIndex: 'type',
@@ -91,6 +65,34 @@ const HomeCarouselPage: React.FC = () => {
[curr.value]: { text: curr.label },
}), {}),
},
{
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> : '-'
),
},
{
title: '描述',
dataIndex: 'description',
@@ -98,7 +100,7 @@ const HomeCarouselPage: React.FC = () => {
},
{
title: '排序',
dataIndex: 'sort',
dataIndex: 'sortOrder',
width: 80,
},
{
@@ -115,117 +117,106 @@ const HomeCarouselPage: React.FC = () => {
valueType: 'option',
width: 180,
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>,
],
render: (_, record) => (
<Space>
<a
onClick={() => {
setCurrent(record);
setFormOpen(true);
}}
>
编辑
</a>
<Popconfirm
title="确认删除轮播图?"
onConfirm={() => handleDelete(record)}
okText="确认"
cancelText="取消"
>
<a style={{ color: '#1677ff' }}>删除</a>
</Popconfirm>
</Space>
),
},
];
return (
<PageContainer>
<QueryFilter
defaultCollapsed={false}
split
span={8}
className={styles['query-filter']}
onFinish={async (values) => {
setSearchParams(values);
actionRef.current?.reload();
}}
style={{ marginBottom: 16 }}
>
<ProFormText
name="title"
label="标题"
placeholder="请输入标题关键字"
fieldProps={{
allowClear: true,
}}
/>
<ProFormSelect
name="status"
label="状态"
placeholder="请选择状态"
options={STATUS_OPTIONS}
fieldProps={{
allowClear: true,
}}
/>
</QueryFilter>
<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>*/}
<ProTable<HomeCarouselItem>
rowKey="id"
headerTitle="轮播图列表"
actionRef={actionRef}
columns={columns}
request={(p) => ordersApi.homeCarousel({ ...(p as any), ...searchParams })}
search={false}
pagination={{
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
}}
toolBarRender={() => [
<a
key="add"
onClick={() => {
console.log('新增按钮被点击');
setCreateOpen(true);
}}
style={{ color: '#1890ff', cursor: 'pointer' }}
>
<PlusOutlined /> 新增轮播图
</a>,
]}
<ActionBar
left={
<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => {
setCurrent(undefined);
setFormOpen(true);
}}>
新增轮播图
</GradientButton>
}
/>
<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>
<CreateForm
open={createOpen}
onOpenChange={setCreateOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await ordersApi.saveOrUpdateHomeCarousel(values);
message.success('新增成功');
actionRef.current?.reload();
return true;
} catch (e) {
message.error('保存失败');
return false;
} finally {
hide();
open={formOpen}
initialValues={current}
onOpenChange={(visible) => {
setFormOpen(visible);
if (!visible) {
setCurrent(undefined);
}
}}
/>
<HomeCarouselForm
open={editOpen}
initialValues={current}
onOpenChange={setEditOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await ordersApi.saveOrUpdateHomeCarousel({ ...(current as any), ...values });
message.success('修改成功');
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) {
@@ -376,7 +376,13 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
{/* 申请时间 */}
<div style={{ marginBottom: 16 }}>
<span style={{ fontWeight: 'bold' }}>申请时间</span>
<div style={{ marginTop: 4 }}>{formatTime(refundData?.createTime || refundData?.applyTime)}</div>
<div style={{ marginTop: 4 }}>{formatTime(refundData?.applyTime || refundData?.applyTime)}</div>
<span style={{ fontWeight: 'bold' }}>退款时间</span>
<div style={{ marginTop: 4 }}>{formatTime(refundData?.refundTime || refundData?.refundTime)}</div>
</div>
<div style={{ marginBottom: 16 }}>
</div>
<Divider />