diff --git a/zlt-business/device-center/src/main/java/com/central/device/controller/LineFileController.java b/zlt-business/device-center/src/main/java/com/central/device/controller/LineFileController.java index fb8cd858..b2f8081a 100644 --- a/zlt-business/device-center/src/main/java/com/central/device/controller/LineFileController.java +++ b/zlt-business/device-center/src/main/java/com/central/device/controller/LineFileController.java @@ -1,8 +1,11 @@ package com.central.device.controller; +import cn.hutool.core.bean.BeanUtil; import com.central.common.model.PageResult; import com.central.common.model.Result; +import com.central.device.feign.FileCenterService; import com.central.device.model.LineFile; +import com.central.device.model.vo.WaypointInfoVO; import com.central.device.service.ILineFileService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -13,6 +16,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -32,6 +36,9 @@ import java.util.stream.Collectors; public class LineFileController { private final ILineFileService lineFileService; + @Resource + private FileCenterService fileCenterService; + /** * 列表 */ @@ -56,7 +63,11 @@ public class LineFileController { if (model == null) { return Result.failed("未找到对应的航线文件信息"); } - return Result.succeed(model, "查询成功"); + String fileurl = fileCenterService.getFileViewUrl(model.getWaylineId()); + WaypointInfoVO infoVO = new WaypointInfoVO(); + BeanUtil.copyProperties(model,infoVO); + infoVO.setFileUrl(fileurl); + return Result.succeed(infoVO, "查询成功"); } catch (Exception e) { log.error("查询航线文件失败,id: {}", id, e); return Result.failed("查询航线文件失败:" + e.getMessage()); diff --git a/zlt-business/device-center/src/main/java/com/central/device/feign/FileCenterService.java b/zlt-business/device-center/src/main/java/com/central/device/feign/FileCenterService.java new file mode 100644 index 00000000..4fe58f37 --- /dev/null +++ b/zlt-business/device-center/src/main/java/com/central/device/feign/FileCenterService.java @@ -0,0 +1,73 @@ +package com.central.device.feign; + +import com.central.common.constant.ServiceNameConstants; +import com.central.common.model.FileInfo; +import com.central.common.model.Result; +import com.central.device.feign.fallback.FileCenterServiceFallbackFactory; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; + +/** + * user-center模块远程调用 + * + * @author lsl + * @version 1.0 + * @description user-center模块远程调用 + * @create 2025/1/13 + **/ +@FeignClient(name = ServiceNameConstants.FILE_SERVICE, fallbackFactory = FileCenterServiceFallbackFactory.class, dismiss404 = true) +public interface FileCenterService { + + /** + * 通过ID查询预览地址 + * + * @param id 文件ID + * @return + */ + @GetMapping("/file/{id}") + String getFileViewUrl(@PathVariable("id") String id); + + @GetMapping("/type/{id}") + String getFileContentType(@PathVariable("id") String id); + + @GetMapping("/qrcode/{codeId}") + Result uploadQrCodeFile(@PathVariable("codeId") String codeId) throws Exception; + + @PostMapping("/path") + FileInfo creatFileInfo(@RequestBody String path); + + @GetMapping("/files/path") + String getViewUrlByPath(@RequestParam("path") String path) ; + + @GetMapping("/files/path/style") + String getViewUrlByPathStyle(@RequestParam("params") Map params) ; + + @GetMapping("/list/files") + List getListFiles(@RequestParam("prefix") String prefix) ; + + /** + * 预热文件到CDN + * + * @param urls 需要预热的URL列表 + * @param area 预热范围:domestic-仅中国内地,overseas-全球(不包含中国内地),不传-全球 + * @return 预热任务ID + */ + @PostMapping("/cdn/prefetch") + Result prefetchFiles(@RequestBody List urls, @RequestParam(value = "area", required = false) String area); + + /** + * 批量预热文件到CDN + * + * @param urls 需要预热的URL列表 + * @param batchSize 每批次处理的URL数量 + * @param area 预热范围 + * @return 预热任务执行结果 + */ + @PostMapping("/cdn/batch/prefetch") + Result batchPrefetchFiles(@RequestBody List urls, + @RequestParam(value = "batchSize", defaultValue = "100") int batchSize, + @RequestParam(value = "area", required = false) String area); +} diff --git a/zlt-business/device-center/src/main/java/com/central/device/feign/fallback/FileCenterServiceFallbackFactory.java b/zlt-business/device-center/src/main/java/com/central/device/feign/fallback/FileCenterServiceFallbackFactory.java new file mode 100644 index 00000000..88c14a09 --- /dev/null +++ b/zlt-business/device-center/src/main/java/com/central/device/feign/fallback/FileCenterServiceFallbackFactory.java @@ -0,0 +1,78 @@ +package com.central.device.feign.fallback; + +import com.central.common.model.FileInfo; +import com.central.common.model.Result; +import com.central.device.feign.FileCenterService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cloud.openfeign.FallbackFactory; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; + +/** + * 文件中心调用失败回调 + * + * @author lsl + * @version 1.0 + * @description 用户中心调用失败回调 + * @create 2025/1/17 11:33 + **/ +@Slf4j +@Component +public class FileCenterServiceFallbackFactory implements FallbackFactory { + + @Override + public FileCenterService create(Throwable cause) { + return new FileCenterService() { + + @Override + public String getFileViewUrl(String id) { + return ""; + } + + @Override + public String getFileContentType(String id) { + return ""; + } + + @Override + public Result uploadQrCodeFile(String codeId) throws Exception { + return null; + } + + @Override + public FileInfo creatFileInfo(String path) { + return null; + } + + @Override + public String getViewUrlByPath(String path) { + return ""; + } + + @Override + public String getViewUrlByPathStyle(Map params) { + return ""; + } + + @Override + public List getListFiles(String prefix) { + return List.of(); + } + + @Override + public Result prefetchFiles(List urls, String area) { + log.warn("CDN预热文件失败,URLs: {}, area: {}", urls, area, cause); + return Result.failed("CDN预热文件失败: " + cause.getMessage()); + } + + @Override + public Result batchPrefetchFiles(List urls, int batchSize, String area) { + log.warn("CDN批量预热文件失败,URLs: {}, batchSize: {}, area: {}", urls, batchSize, area, cause); + return Result.failed("CDN批量预热文件失败: " + cause.getMessage()); + } + + }; + } +} diff --git a/zlt-business/device-center/src/main/java/com/central/device/model/LineFile.java b/zlt-business/device-center/src/main/java/com/central/device/model/LineFile.java index 29240efa..972d790a 100644 --- a/zlt-business/device-center/src/main/java/com/central/device/model/LineFile.java +++ b/zlt-business/device-center/src/main/java/com/central/device/model/LineFile.java @@ -38,4 +38,6 @@ public class LineFile extends SuperEntity { @TableField(fill = FieldFill.INSERT_UPDATE) private Date updateTime; private String tenantId; + + } diff --git a/zlt-business/device-center/src/main/java/com/central/device/model/vo/WaypointInfoVO.java b/zlt-business/device-center/src/main/java/com/central/device/model/vo/WaypointInfoVO.java new file mode 100644 index 00000000..592f6090 --- /dev/null +++ b/zlt-business/device-center/src/main/java/com/central/device/model/vo/WaypointInfoVO.java @@ -0,0 +1,10 @@ +package com.central.device.model.vo; + +import com.central.device.model.LineFile; +import lombok.Data; + +@Data +public class WaypointInfoVO extends LineFile { + + private String fileUrl; +} diff --git a/zlt-business/device-center/src/main/resources/mapper/LineFileMapper.xml b/zlt-business/device-center/src/main/resources/mapper/LineFileMapper.xml index b5fcb3e5..f8639965 100644 --- a/zlt-business/device-center/src/main/resources/mapper/LineFileMapper.xml +++ b/zlt-business/device-center/src/main/resources/mapper/LineFileMapper.xml @@ -3,6 +3,22 @@ diff --git a/zlt-business/order-center/src/main/java/com/central/order/service/impl/RefundServiceImpl.java b/zlt-business/order-center/src/main/java/com/central/order/service/impl/RefundServiceImpl.java index bffd30ba..f72a0934 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/service/impl/RefundServiceImpl.java +++ b/zlt-business/order-center/src/main/java/com/central/order/service/impl/RefundServiceImpl.java @@ -95,7 +95,7 @@ public class RefundServiceImpl extends SuperServiceImpl im result.put("reason", refund.getRefundReason()); result.put("refundReason", refund.getRefundReason()); result.put("approveReason", refund.getApproveReason()); - result.put("createTime", refund.getCreateTime()); + result.put("refundTime", refund.getRefundTime()); result.put("applyTime", refund.getCreateTime()); // 处理图片列表 - refundImgs 可能是逗号分隔的字符串或JSON diff --git a/zlt-web/react-web-next/src/assets/beijing.png b/zlt-web/react-web-next/src/assets/beijing.png index ddc337b8..be2db0a5 100644 Binary files a/zlt-web/react-web-next/src/assets/beijing.png and b/zlt-web/react-web-next/src/assets/beijing.png differ diff --git a/zlt-web/react-web-next/src/layouts/BasicLayout.tsx b/zlt-web/react-web-next/src/layouts/BasicLayout.tsx index 8b63eec9..568f3daf 100644 --- a/zlt-web/react-web-next/src/layouts/BasicLayout.tsx +++ b/zlt-web/react-web-next/src/layouts/BasicLayout.tsx @@ -59,7 +59,8 @@ const BasicLayout: React.FC = (props: any) => { if (!cand) return undefined; const lower = cand.toLowerCase(); if (lower.startsWith('http')) return cand; // 澶栭摼 - if (lower.endsWith('.html')) return cand.startsWith('/') ? cand : `/${cand}`; // 闈欐€佽矾鐢? if (lower === '/welcome' || lower === 'welcome') return '/welcome'; + if (lower.endsWith('.html')) return cand.startsWith('/') ? cand : `/${cand}`; // 闈欐€佽矾鐢? + if (lower === '/welcome' || lower === 'welcome') return '/welcome'; // 鍏煎鍚庣鑿滃崟鏈甫 .html 鐨勫彾瀛愯矾鐢憋紝渚嬪 /system/tenant => /system/tenant.html const ensureSlash = cand.startsWith('/') ? cand : `/${cand}`; const parts = ensureSlash.split('/').filter(Boolean); @@ -96,7 +97,7 @@ const BasicLayout: React.FC = (props: any) => { const item: MenuDataItem = { key: keyStr, - name: menu.name || `鑿滃崟${index + 1}`, + name: menu.name || `保存中${index + 1}`, path, icon: getIcon(path), children: childrenList.map((child: MenuNode, i: number) => normalize(child, i, keyStr)), diff --git a/zlt-web/react-web-next/src/pages/device/Wayline/components/WaylineForm.tsx b/zlt-web/react-web-next/src/pages/device/Wayline/components/WaylineForm.tsx index daffb68e..01b723ed 100644 --- a/zlt-web/react-web-next/src/pages/device/Wayline/components/WaylineForm.tsx +++ b/zlt-web/react-web-next/src/pages/device/Wayline/components/WaylineForm.tsx @@ -2,6 +2,7 @@ import { ModalForm, ProForm, ProFormSelect, ProFormText } from '@ant-design/pro-components'; import { Button, Upload, message } from 'antd'; import { UploadOutlined } from '@ant-design/icons'; +import { deviceApi } from '@/services/device'; export type WaylineFormValues = { id?: number; @@ -33,21 +34,57 @@ async function uploadWaylineFile(file: File) { const WaylineForm: React.FC = ({ title, visible, onVisibleChange, onFinish, initialValues, workspaceOptions }) => { const formRef = useRef(); const [fileInfo, setFileInfo] = useState<{ id: string; url: string } | undefined>(); + const [loading, setLoading] = useState(false); + /** + * 当编辑页面打开时,如果有waylineId,调用接口获取完整信息 + */ useEffect(() => { - if (initialValues) { + if (visible && initialValues?.waylineId) { + setLoading(true); + deviceApi + .getWaylineInfoByWaylineId(initialValues.waylineId) + .then((data) => { + if (data) { + formRef.current?.setFieldsValue({ + id: data.id, + name: data.name, + waylineId: data.waylineId, + workspaceId: data.workspaceId, + sign: data.sign, + }); + // 如果有fileUrl,设置文件信息 + if (data.fileUrl) { + setFileInfo({ + id: data.waylineId || data.id?.toString() || '', + url: data.fileUrl, + }); + } + } + }) + .catch((err) => { + console.error('获取航线信息失败:', err); + message.error('获取航线信息失败'); + }) + .finally(() => setLoading(false)); + } else if (visible && initialValues) { + // 新增时直接回显 formRef.current?.setFieldsValue(initialValues); } - }, [initialValues]); + }, [visible, initialValues?.waylineId]); return ( title={title} visible={visible} formRef={formRef} + loading={loading} onVisibleChange={(v) => { onVisibleChange?.(v); - if (!v) setFileInfo(undefined); + if (!v) { + setFileInfo(undefined); + setLoading(false); + } }} onFinish={async (values) => { if (!values.waylineId && !fileInfo) { diff --git a/zlt-web/react-web-next/src/pages/device/Wayline/components/WaylineTable.tsx b/zlt-web/react-web-next/src/pages/device/Wayline/components/WaylineTable.tsx index 72901414..8f9ae2a9 100644 --- a/zlt-web/react-web-next/src/pages/device/Wayline/components/WaylineTable.tsx +++ b/zlt-web/react-web-next/src/pages/device/Wayline/components/WaylineTable.tsx @@ -2,7 +2,8 @@ import React, { forwardRef, useImperativeHandle, useRef } from 'react'; import type { ActionType } from '@ant-design/pro-components'; import { ProTable } from '@ant-design/pro-components'; import type { ProColumns } from '@ant-design/pro-components'; -import { Space } from 'antd'; +import { Space, message } from 'antd'; +import { DownloadOutlined } from '@ant-design/icons'; import { deviceApi } from '@/services/device'; import { downloadByUrl } from '@/utils/download'; @@ -21,27 +22,64 @@ const WaylineTable = forwardRef(({ params, o useImperativeHandle(ref, () => ({ reload: () => actionRef.current?.reload() })); + /** + * 处理航线文件下载 + * 先通过waylineId获取航线信息(包含fileUrl),再使用fileUrl下载 + */ + const handleDownload = async (record: any) => { + try { + if (!record.waylineId) { + message.error('航线ID缺失'); + return; + } + + const hide = message.loading('获取航线信息中...'); + try { + // 通过waylineId获取航线完整信息,包括fileUrl + const waylineInfo = await deviceApi.getWaylineInfoByWaylineId(record.waylineId); + hide(); + + if (!waylineInfo) { + message.error('无法获取航线信息'); + return; + } + + const fileUrl = waylineInfo.fileUrl; + if (!fileUrl) { + message.error('航线文件URL不存在'); + return; + } + + // 使用fileUrl直接下载 + const fileName = record.name || `wayline_${record.waylineId}`; + downloadByUrl(fileUrl, fileName); + message.success('开始下载航线文件'); + } catch (error) { + hide(); + console.error('获取航线信息失败:', error); + message.error('获取航线信息失败'); + } + } catch (error) { + message.error('下载失败'); + console.error('下载航线文件错误:', error); + } + }; + const columns: ProColumns[] = [ { dataIndex: 'index', valueType: 'indexBorder', width: 48 }, { title: '航线名称', dataIndex: 'name' }, { title: '航线ID', dataIndex: 'waylineId' }, { title: '空间ID', dataIndex: 'workspaceId' }, { title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 }, - { - title: '航线文件', dataIndex: 'fileUrl', search: false, - render: (_, record) => record.fileUrl ? ( - { e.preventDefault(); downloadByUrl(record.fileUrl, record.name || 'wayline.kmz'); }} - >下载文件 - ) : '-' - }, { title: '文件签名', dataIndex: 'sign', ellipsis: true, copyable: true }, { title: '操作', key: 'action', valueType: 'option', render: (_, record) => ( onEdit?.(record)}>编辑 + handleDownload(record)} title="下载航线文件"> + 下载 + onDelete?.(record)}>删除 ) @@ -62,3 +100,4 @@ const WaylineTable = forwardRef(({ params, o }); export default WaylineTable; + diff --git a/zlt-web/react-web-next/src/pages/device/Wayline/index.tsx b/zlt-web/react-web-next/src/pages/device/Wayline/index.tsx index 4ffce1d7..bf71d67b 100644 --- a/zlt-web/react-web-next/src/pages/device/Wayline/index.tsx +++ b/zlt-web/react-web-next/src/pages/device/Wayline/index.tsx @@ -62,8 +62,15 @@ const WaylinePage: React.FC = () => { return ( - tableRef.current?.reload()} onFinish={async (values) => setQuery(values)}> - + tableRef.current?.reload()} + onFinish={async (values) => setQuery(values)}> + + } onClick={() => setCreateOpen(true)}>新增} /> diff --git a/zlt-web/react-web-next/src/pages/orders/HomeCarousel/FIX_REPORT.md b/zlt-web/react-web-next/src/pages/orders/HomeCarousel/FIX_REPORT.md deleted file mode 100644 index 9c636528..00000000 --- a/zlt-web/react-web-next/src/pages/orders/HomeCarousel/FIX_REPORT.md +++ /dev/null @@ -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 - -``` - -#### c. 在新增表单添加类型选择 - -同样在 `CreateForm.tsx` 中添加了完整的类型选择字段 - -**结果:** -- ✅ 编辑和新增表单都支持类型选择 -- ✅ 类型为必填项,确保数据完整性 - ---- - -### 3. **描述字段缺失问题** ✅ - -**问题描述:** 表单中缺少描述字段,无法为轮播图添加描述 - -**修复方案:** 在编辑和新增表单中添加了描述文本域 - -```typescript - -``` - -**结果:** -- ✅ 可以为轮播图添加多行描述信息 -- ✅ 文本域高度为 3 行,便于输入较长内容 - ---- - -### 4. **按钮点击无响应问题** ✅ - -**问题描述:** 点击"新增轮播图"和"编辑"按钮没有任何反应,弹窗无法打开 - -**问题原因:** -- 使用 `Button` 组件时可能存在样式或事件冒泡问题 -- 表格操作列使用 `Space` 包裹可能导致事件捕获失效 - -**修复方案:** - -#### a. 改进新增按钮 - -**改进前:** -```typescript - -``` - -**改进后:** -```typescript - { - console.log('新增按钮被点击'); - setCreateOpen(true); - }} - style={{ color: '#1890ff', cursor: 'pointer' }} -> - 新增轮播图 - -``` - -#### b. 改进编辑和删除按钮 - -**改进前:** -```typescript -render: (_, record) => ( - - { /* ... */ }}> - 编辑 - - {/* ... */} - -) -``` - -**改进后(使用 array 渲染):** -```typescript -render: (_, record) => [ - { - console.log('编辑按钮被点击', record); - setCurrent(record); - setEditOpen(true); - }} - > - 编辑 - , - handleDelete(record)} - okText="确认" - cancelText="取消" - > - 删除 - , -] -``` - -**改进点:** -1. ✅ 使用原生 `` 标签替代 `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. **后续优化** - - 考虑添加批量删除功能 - - 考虑添加导入/导出功能 - - 考虑优化大图片上传的性能 - diff --git a/zlt-web/react-web-next/src/pages/orders/HomeCarousel/README.md b/zlt-web/react-web-next/src/pages/orders/HomeCarousel/README.md deleted file mode 100644 index be68531c..00000000 --- a/zlt-web/react-web-next/src/pages/orders/HomeCarousel/README.md +++ /dev/null @@ -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(undefined); -const [searchParams, setSearchParams] = useState>({}); - -// 使用 ActionRef 管理表格刷新 -const actionRef = useRef(); - -// 独立的业务逻辑函数 -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) => ( - - ), -}, - -// 链接可点击访问 -{ - title: '跳转链接', - dataIndex: 'linkUrl', - ellipsis: true, - render: (url: string) => ( - {url} - ), -}, - -// 使用 valueEnum 规范化状态 -{ - title: '状态', - dataIndex: 'status', - width: 80, - valueEnum: { - 1: { text: '启用', status: 'Success' }, - 0: { text: '禁用', status: 'Error' }, - }, -} -``` - -### 3. **搜索栏优化** (index.tsx:114-143) - -**改进前:** -- 使用自定义 SearchBarPlus 组件 -- 没有明确的搜索字段定义 - -**改进后:** -- 使用标准 `QueryFilter` 组件 -- 支持搜索:标题、状态 -- 搜索参数规范化处理 -- 集成样式类 - -```typescript - { - setSearchParams(values); - actionRef.current?.reload(); - }} -> - - - -``` - -### 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 && ( -
-

图片预览:

- -
-)} -``` - -### 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** - 样式预处理 - diff --git a/zlt-web/react-web-next/src/pages/orders/HomeCarousel/components/CreateForm.tsx b/zlt-web/react-web-next/src/pages/orders/HomeCarousel/components/CreateForm.tsx index d7bd4abf..fd9674a1 100644 --- a/zlt-web/react-web-next/src/pages/orders/HomeCarousel/components/CreateForm.tsx +++ b/zlt-web/react-web-next/src/pages/orders/HomeCarousel/components/CreateForm.tsx @@ -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; onOpenChange: (v: boolean) => void; onFinish: (values: HomeCarouselItem) => Promise; } const CreateForm: React.FC = ({ open, + initialValues, onOpenChange, onFinish, }) => { - const [imageUrl, setImageUrl] = useState(); - const [imagePath, setImagePath] = useState(); + const [imageUrl, setImageUrl] = useState(initialValues?.imageUrl || ''); + const [imagePath, setImagePath] = useState(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 = {}; + 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 = ({ 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 ( - 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 = ({ name="linkUrl" label="跳转链接" placeholder="请输入跳转链接" - rules={[{ type: 'url', message: '请输入正确的URL格式' }]} /> = ({ }} /> = ({
{ + 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); + } + }} >
- {imageUrl && ( + {(imageUrl || (isEdit && initialValues?.imageUrl)) && (

图片预览:

; - onOpenChange: (v: boolean) => void; - onFinish: (values: HomeCarouselItem) => Promise; -} - -const HomeCarouselForm: React.FC = ({ - open, - initialValues, - onOpenChange, - onFinish, -}) => { - return ( - - title="编辑轮播图" - open={open} - onOpenChange={onOpenChange} - onFinish={onFinish} - initialValues={initialValues} - modalProps={{ - destroyOnClose: true, - maskClosable: false, - }} - > - - - - - - - - - ); -}; - -export default HomeCarouselForm; diff --git a/zlt-web/react-web-next/src/pages/orders/HomeCarousel/index.less b/zlt-web/react-web-next/src/pages/orders/HomeCarousel/index.less deleted file mode 100644 index c49cc8f5..00000000 --- a/zlt-web/react-web-next/src/pages/orders/HomeCarousel/index.less +++ /dev/null @@ -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; - } -} diff --git a/zlt-web/react-web-next/src/pages/orders/HomeCarousel/index.tsx b/zlt-web/react-web-next/src/pages/orders/HomeCarousel/index.tsx index 11eda415..2dc5e95d 100644 --- a/zlt-web/react-web-next/src/pages/orders/HomeCarousel/index.tsx +++ b/zlt-web/react-web-next/src/pages/orders/HomeCarousel/index.tsx @@ -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(); - const [createOpen, setCreateOpen] = useState(false); - const [editOpen, setEditOpen] = useState(false); + const [formOpen, setFormOpen] = useState(false); const [current, setCurrent] = useState(undefined); const [searchParams, setSearchParams] = useState>({}); @@ -58,30 +56,6 @@ const HomeCarouselPage: React.FC = () => { ellipsis: true, copyable: true, }, - { - title: '图片', - dataIndex: 'imageUrl', - width: 120, - render: (imageUrl: string) => ( - - 加载中... -
- } - /> - ), - }, - { - title: '跳转链接', - dataIndex: 'linkUrl', - ellipsis: true, - render: (url: string) => ( - url ? {url} : '-' - ), - }, { 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 ? ( + + 加载中... + + } + /> + ) : ( + - + ) + ), + }, + { + title: '跳转链接', + dataIndex: 'redirectUrl', + ellipsis: true, + render: (_: any, record: HomeCarouselItem) => ( + record.linkUrl ? {record.linkUrl} : '-' + ), + }, { 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) => [ -
{ - console.log('编辑按钮被点击', record); - setCurrent(record); - setEditOpen(true); - }} - > - 编辑 - , - handleDelete(record)} - okText="确认" - cancelText="取消" - > - 删除 - , - ], + render: (_, record) => ( + + { + setCurrent(record); + setFormOpen(true); + }} + > + 编辑 + + handleDelete(record)} + okText="确认" + cancelText="取消" + > + 删除 + + + ), }, ]; return ( - - { - setSearchParams(values); - actionRef.current?.reload(); - }} - style={{ marginBottom: 16 }} - > - - - + + {/* {*/} + {/* setSearchParams(values);*/} + {/* actionRef.current?.reload();*/} + {/* }}*/} + {/*>*/} + {/* */} + {/* */} + {/*
*/} - - 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={() => [ - { - console.log('新增按钮被点击'); - setCreateOpen(true); - }} - style={{ color: '#1890ff', cursor: 'pointer' }} - > - 新增轮播图 - , - ]} + } onClick={() => { + setCurrent(undefined); + setFormOpen(true); + }}> + 新增轮播图 + + } /> + + + 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} + /> + + { - 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); } }} - /> - - { 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) { diff --git a/zlt-web/react-web-next/src/pages/orders/Order/components/RefundReviewModal.tsx b/zlt-web/react-web-next/src/pages/orders/Order/components/RefundReviewModal.tsx index 34be85f3..a6cb9f69 100644 --- a/zlt-web/react-web-next/src/pages/orders/Order/components/RefundReviewModal.tsx +++ b/zlt-web/react-web-next/src/pages/orders/Order/components/RefundReviewModal.tsx @@ -376,7 +376,13 @@ const RefundReviewModal: React.FC = ({ {/* 申请时间 */}
申请时间 -
{formatTime(refundData?.createTime || refundData?.applyTime)}
+
{formatTime(refundData?.applyTime || refundData?.applyTime)}
+ 退款时间 +
{formatTime(refundData?.refundTime || refundData?.refundTime)}
+
+ +
+
diff --git a/zlt-web/react-web-next/src/pages/system/TenantManage/components/TenantForm.tsx b/zlt-web/react-web-next/src/pages/system/TenantManage/components/TenantForm.tsx index 65f0cd80..5de2ace3 100644 --- a/zlt-web/react-web-next/src/pages/system/TenantManage/components/TenantForm.tsx +++ b/zlt-web/react-web-next/src/pages/system/TenantManage/components/TenantForm.tsx @@ -87,7 +87,7 @@ const TenantForm: React.FC = ({ visible, title, initialValues, - +