From f3f6ce9c49167018b2451d6a7bc9224bdeb4e95e Mon Sep 17 00:00:00 2001 From: Iamasoldier <1272745473@qq.com> Date: Sun, 30 Mar 2025 15:49:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86)?= =?UTF-8?q?=EF=BC=9A=EF=BC=8C=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=98=BE=E7=A4=BA=E6=9D=A1=E4=BB=B6=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E7=AD=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/mapper/OrderFileMapper.xml | 11 +- .../src/main/resources/mapper/OrderMapper.xml | 11 +- .../HomeCarousel/components/UpdateForm.tsx | 183 ++++--- .../src/pages/orders/HomeCarousel/index.tsx | 456 +++++++++++------- .../src/pages/orders/Order/constants.ts | 55 ++- .../frontend/src/pages/orders/Order/index.tsx | 25 +- .../src/pages/orders/OrderFile/index.tsx | 174 ++++--- .../orders/Qrcode/components/UpdateForm.tsx | 98 ++-- .../src/pages/orders/Qrcode/index.tsx | 60 ++- .../orders/Tourism/components/UpdateForm.tsx | 67 +-- .../src/pages/orders/Tourism/index.tsx | 286 +++++------ .../TourismFile/components/CreateForm.tsx | 159 ++++++ .../TourismFile/components/SearchForm.tsx | 41 ++ .../TourismFile/components/UpdateForm.tsx | 39 +- .../src/pages/orders/TourismFile/constants.ts | 21 +- .../src/pages/orders/TourismFile/index.tsx | 164 ++++--- 16 files changed, 1237 insertions(+), 613 deletions(-) create mode 100644 zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/components/CreateForm.tsx create mode 100644 zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/components/SearchForm.tsx diff --git a/zlt-business/order-center/src/main/resources/mapper/OrderFileMapper.xml b/zlt-business/order-center/src/main/resources/mapper/OrderFileMapper.xml index 9ce7a945..efb715c9 100644 --- a/zlt-business/order-center/src/main/resources/mapper/OrderFileMapper.xml +++ b/zlt-business/order-center/src/main/resources/mapper/OrderFileMapper.xml @@ -3,7 +3,16 @@ diff --git a/zlt-business/order-center/src/main/resources/mapper/OrderMapper.xml b/zlt-business/order-center/src/main/resources/mapper/OrderMapper.xml index 5203807f..cddf87da 100644 --- a/zlt-business/order-center/src/main/resources/mapper/OrderMapper.xml +++ b/zlt-business/order-center/src/main/resources/mapper/OrderMapper.xml @@ -4,7 +4,16 @@ diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/HomeCarousel/components/UpdateForm.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/HomeCarousel/components/UpdateForm.tsx index 808e2d03..1dc3f5b0 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/HomeCarousel/components/UpdateForm.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/HomeCarousel/components/UpdateForm.tsx @@ -3,114 +3,175 @@ import { ProForm, ProFormSelect, ProFormText, + ProFormTextArea, } from '@ant-design/pro-components'; -import { Button, Upload } from 'antd'; +import { Button, message, Upload } from 'antd'; +import { Image as AntImage } from 'antd'; import { UploadOutlined } from '@ant-design/icons'; -import React from 'react'; -import { TYPE_OPTIONS } from '../index'; -import type { RcFile } from 'antd/lib/upload'; -import styles from '../index.less'; +import React, { useState } from 'react'; +import type { RcFile } from 'antd/es/upload'; +import { importImage } from '@/services/system/api'; -export type UpdateFormProps = { - onSubmit: (values: Partial) => Promise; +interface UpdateFormProps { + onSubmit: (values: any) => Promise; onVisibleChange: (visible: boolean) => void; updateModalVisible: boolean; values?: ORDERS.HomeCarousel; - onUpload: (fileUrl: string) => void; -}; + onUpload: (url: string, path: string) => void; + imageUrl?: string; +} -const UpdateForm: React.FC = (props) => { - const { onSubmit, onVisibleChange, updateModalVisible, values, onUpload } = props; +interface UploadResponse { + id: string; + name: string; + url: string; // 添加 url 字段 + isImg: boolean; + contentType: string; + size: number; + path: string; + source: string; + createTime: string; + updateTime: string; +} - // 导入处理函数 - const handleImport = async (file: RcFile) => { - const hide = message.loading('正在上传'); +const UpdateForm: React.FC = ({ + onSubmit, + onVisibleChange, + updateModalVisible, + values, + onUpload, + imageUrl, +}) => { + const [uploading, setUploading] = useState(false); + + // 修改文件上传处理逻辑 + const handleUpload = async (file: RcFile) => { + setUploading(true); + const hide = message.loading('正在上传...'); + try { const formData = new FormData(); formData.append('file', file); const result = await importImage(formData); + hide(); - if (result && result.name) { - message.success('上传素材成功'); - onUpload(result.name); + + if (result.url && result.path) { + message.success('上传成功'); + onUpload(result.url, result.path); // 传递两个值 + return true; } + + message.error('上传失败:未获取到文件信息'); return false; } catch (error) { + console.error('Upload error:', error); hide(); - message.error('上传素材失败'); + message.error('上传失败:' + (error.message || '未知错误')); return false; + } finally { + setUploading(false); } }; return ( { - // 只提交已修改的字段 - const changedValues: Partial = {}; - Object.keys(formValues).forEach(key => { - if (formValues[key] !== values?.[key]) { - changedValues[key] = formValues[key]; - } - }); - - if (Object.keys(changedValues).length === 0) { - return true; - } - - await onSubmit(changedValues); + modalProps={{ + destroyOnClose: true, + confirmLoading: uploading, }} initialValues={values} + onFinish={async (formValues) => { + if (uploading) { + message.warning('请等待图片上传完成'); + return false; + } + return onSubmit(formValues); + }} > - + - - {/* 添加图片上传组件 */} -
-
当前图片:
- - -
- -
-
-
+ +
+ { + try { + const success = await handleUpload(file as RcFile); + if (success) { + onSuccess?.('ok'); + } else { + onError?.(new Error('上传失败')); + } + } catch (error) { + onError?.(error); + } + }} + > + + +
+ + {/* 显示图片预览 */} +
+ {(imageUrl || values?.imageUrl) && ( + + )} +
); }; diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/HomeCarousel/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/HomeCarousel/index.tsx index a9ed46a7..9fcc91f6 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/HomeCarousel/index.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/HomeCarousel/index.tsx @@ -1,6 +1,6 @@ import { deleteHomeCarousel, saveOrUpdateHomeCarousel, homeCarousel } from '@/services/orders/api'; import { importImage } from '@/services/system/api'; -import { PlusOutlined, UploadOutlined } from '@ant-design/icons'; +import { PlusOutlined, UploadOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons'; import type { ActionType, ProColumns } from '@ant-design/pro-components'; import { ModalForm, @@ -8,197 +8,187 @@ import { ProForm, ProFormSelect, ProFormText, + ProFormTextArea, ProTable, QueryFilter, } from '@ant-design/pro-components'; -import { Typography, Popconfirm, Space, message, Image, Button, Tag, Upload } from 'antd'; -import type { RcFile } from 'antd/lib/upload'; -import React, { useRef, useState, useCallback } from 'react'; +import { Typography, Popconfirm, Space, message, Button, Tag, Upload } from 'antd'; +import { Image as AntImage } from 'antd'; +import type { RcFile, UploadProps } from 'antd/es/upload'; +import React, { useRef, useState } from 'react'; import UpdateForm from './components/UpdateForm'; import styles from './index.less'; const { Link } = Typography; -// 提取常量 -export const TYPE_OPTIONS = [ +// 状态常量 +const STATUS_OPTIONS = [ + { label: '启用', value: '1' }, + { label: '禁用', value: '0' }, +]; + +// 类型常量 +const TYPE_OPTIONS = [ { label: '首页轮播', value: 0 }, { label: '活动', value: 1 }, { label: '其他', value: 2 }, -] as const; +]; -// 类型颜色映射 -const typeColorMap = { - 0: { color: 'yellow', text: '首页轮播' }, - 1: { color: 'orange', text: '活动' }, - 2: { color: 'red', text: '其他' }, -}; - -// 统一错误处理 -const handleApiRequest = async ( - apiCall: () => Promise, - loadingMessage: string, - successMessage: string, -) => { - const hide = message.loading(loadingMessage); - try { - const result = await apiCall(); - hide(); - if (result.resp_code === 0) { - message.success(successMessage); - return true; - } - message.error(result.resp_msg); - return false; - } catch (error) { - hide(); - message.error(`${successMessage}失败`); - return false; - } -}; - -// 处理函数优化 -const handleAdd = async (fields: ORDERS.HomeCarousel) => { - return handleApiRequest( - () => saveOrUpdateHomeCarousel({ ...fields }), - '正在添加', - '添加成功' - ); -}; - -const handleEdit = async (original: ORDERS.HomeCarousel, fields: Partial) => { - return handleApiRequest( - () => saveOrUpdateHomeCarousel({ - id: original.id, - ...fields - }), - '正在更新', - '修改成功' - ); -}; - -const handleDelete = async (carousel: ORDERS.HomeCarousel) => { - return handleApiRequest( - () => deleteHomeCarousel(carousel.id), - '正在删除', - '删除成功' - ); -}; - -const handleImport = async (file: RcFile) => { - return handleApiRequest( - async () => { - const formData = new FormData(); - formData.append('file', file); - return await importImage(formData); - }, - '正在上传', - '上传素材成功' - ); -}; - -// 渲染函数 -const renderType = (type: {} | null | undefined) => { - const typeInfo = typeColorMap[type] || { color: 'gray', text: '未知状态' }; - return {typeInfo.text}; -}; +interface UploadResponse { + id: string; + name: string; + url: string; + path: string; + isImg: boolean; + contentType: string; + size: number; + source: string; + createTime: string; + updateTime: string; +} const TableList: React.FC = () => { const actionRef = useRef(); - const [params, setParams] = useState>({}); - const [createModalVisible, handleModalVisible] = useState(false); - const [updateModalVisible, handleUpdateModalVisible] = useState(false); + const [searchParams, setSearchParams] = useState>({}); + const [createModalVisible, setCreateModalVisible] = useState(false); + const [updateModalVisible, setUpdateModalVisible] = useState(false); const [currentRow, setCurrentRow] = useState(); - const [file, setFile] = useState(); - const [updateFile, setUpdateFile] = useState(); + const [createImageUrl, setCreateImageUrl] = useState(); + const [createImagePath, setCreateImagePath] = useState(); + const [updateImageUrl, setUpdateImageUrl] = useState(); + const [updateImagePath, setUpdateImagePath] = useState(); - const handleTableAction = useCallback(async ( - action: 'add' | 'edit' | 'delete', - record?: ORDERS.HomeCarousel, - values?: Partial - ) => { - let success = false; - switch (action) { - case 'add': - success = await handleAdd({ ...values, imageUrl: file } as ORDERS.HomeCarousel); - success && handleModalVisible(false); - break; - case 'edit': - if (record) { - const updateData = { - ...values, - ...(updateFile ? { imageUrl: updateFile } : {}) - }; - success = await handleEdit(record, updateData); - if (success) { - handleUpdateModalVisible(false); - setCurrentRow(undefined); - setUpdateFile(undefined); - } - } - break; - case 'delete': - success = await handleDelete(record!); - break; + // 处理文件上传 + const handleUpload = async (file: RcFile) => { + const hide = message.loading('正在上传...'); + try { + const formData = new FormData(); + formData.append('file', file); + const result = await importImage(formData); + hide(); + + if (result.url && result.path) { + message.success('上传成功'); + return { + url: result.url, + path: result.path + }; + } + message.error('上传失败:未获取到文件信息'); + return false; + } catch (error) { + hide(); + message.error('上传失败:' + (error.message || '未知错误')); + return false; } - if (success && actionRef.current) { - actionRef.current.reload(); + }; + + // 处理删除操作 + const handleDelete = async (record: ORDERS.HomeCarousel) => { + const hide = message.loading('正在删除...'); + try { + const result = await deleteHomeCarousel(record.id); + hide(); + if (result.resp_code === 0) { + message.success('删除成功'); + actionRef.current?.reload(); + return true; + } + message.error(result.resp_msg); + return false; + } catch (error) { + hide(); + message.error('删除失败'); + return false; } - }, [file, updateFile]); + }; const columns: ProColumns[] = [ { + title: '序号', dataIndex: 'index', valueType: 'indexBorder', + width: 48, }, { title: '标题', dataIndex: 'title', + ellipsis: true, + copyable: true, }, { - title: '素材', + title: '素材预览', dataIndex: 'imageUrl', - render: (imageUrl) => + width: 120, + render: (imageUrl) => ( + + 加载中... + + } + /> + ), }, { title: '跳转链接', dataIndex: 'redirectUrl', + ellipsis: true, + render: (url) => ( + {url} + ), }, { title: '类型', dataIndex: 'type', - render: renderType, + width: 100, + valueEnum: TYPE_OPTIONS.reduce((acc, curr) => ({ + ...acc, + [curr.value]: { text: curr.label }, + }), {}), }, { title: '描述', dataIndex: 'description', + ellipsis: true, }, { title: '状态', dataIndex: 'status', + width: 80, + valueEnum: { + '1': { text: '启用', status: 'Success' }, + '0': { text: '禁用', status: 'Error' }, + }, }, { title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', + width: 180, }, { title: '操作', - key: 'action', - render: (_, entity) => ( + valueType: 'option', + width: 180, + render: (_, record) => ( { - setCurrentRow(entity); - handleUpdateModalVisible(true); + setCurrentRow(record); + setUpdateModalVisible(true); }} > - 修改 + 编辑 handleTableAction('delete', entity)} + title="确认删除该轮播图?" + description="删除后将无法恢复,请谨慎操作" + onConfirm={() => handleDelete(record)} > - 删除 + 删除 ), @@ -206,50 +196,104 @@ const TableList: React.FC = () => { ]; return ( - + setParams(values)} + onFinish={setSearchParams} > - + + + + rowKey="id" - headerTitle="素材列表" - request={homeCarousel} + headerTitle="轮播图列表" actionRef={actionRef} columns={columns} + request={homeCarousel} + params={searchParams} search={false} - params={params} pagination={{ + defaultPageSize: 10, showSizeChanger: true, showQuickJumper: true, }} toolBarRender={() => [ , ]} /> + handleTableAction('add', undefined, values)} + onVisibleChange={(visible) => { + setCreateModalVisible(visible); + if (!visible) { + setCreateImageUrl(undefined); + setCreateImagePath(undefined); + } + }} + modalProps={{ + destroyOnClose: true, + maskClosable: false, + }} + onFinish={async (values) => { + if (!createImagePath) { + message.error('请上传轮播图片'); + return false; + } + + const hide = message.loading('正在添加...'); + try { + const result = await saveOrUpdateHomeCarousel({ + ...values, + imageUrl: createImagePath, + }); + + hide(); + if (result.resp_code === 0) { + message.success('添加成功'); + setCreateModalVisible(false); + setCreateImageUrl(undefined); + setCreateImagePath(undefined); + actionRef.current?.reload(); + return true; + } + message.error(result.resp_msg || '添加失败'); + return false; + } catch (error) { + hide(); + message.error('添加失败:' + (error.message || '未知错误')); + return false; + } + }} > { - + + + +
{ - const result = await handleImport(file); - if (result && result.name) { - setFile(result.name); + customRequest={async ({ file, onSuccess, onError }) => { + try { + if (file instanceof File) { + const result = await handleUpload(file as RcFile); + if (result) { + setCreateImageUrl(result.url); + setCreateImagePath(result.path); + onSuccess?.('ok'); + } else { + onError?.(new Error('上传失败')); + } + } + } catch (error) { + onError?.(error); } - return false; }} > -
- -
+
- +
+ + {createImageUrl && ( +
+ + 加载中... +
+ } + /> + + )}
+ handleTableAction('edit', currentRow, values)} + onSubmit={async (values) => { + const hide = message.loading('正在更新...'); + try { + const result = await saveOrUpdateHomeCarousel({ + id: currentRow?.id, + ...values, + imageUrl: updateImagePath || currentRow?.imageUrl, + }); + + hide(); + if (result.resp_code === 0) { + message.success('更新成功'); + setUpdateModalVisible(false); + setCurrentRow(undefined); + setUpdateImageUrl(undefined); + setUpdateImagePath(undefined); + actionRef.current?.reload(); + return true; + } + message.error(result.resp_msg || '更新失败'); + return false; + } catch (error) { + hide(); + message.error('更新失败:' + (error.message || '未知错误')); + return false; + } + }} onVisibleChange={(visible) => { - handleUpdateModalVisible(visible); + setUpdateModalVisible(visible); if (!visible) { - setUpdateFile(undefined); + setCurrentRow(undefined); + setUpdateImageUrl(undefined); + setUpdateImagePath(undefined); } }} updateModalVisible={updateModalVisible} values={currentRow} - onUpload={setUpdateFile} + onUpload={(url, path) => { + setUpdateImageUrl(url); + setUpdateImagePath(path); + }} + imageUrl={updateImageUrl} />
); diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/constants.ts b/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/constants.ts index 64003d64..7abaa518 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/constants.ts +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/constants.ts @@ -13,16 +13,51 @@ export const ORDER_STATUS = { } as const; export const STATUS_CONFIG = { - [ORDER_STATUS.UNPAID]: { color: 'yellow', text: '待支付' }, - [ORDER_STATUS.PAID_QUEUING]: { color: 'orange', text: '已支付排队中' }, - [ORDER_STATUS.CANCELLED]: { color: 'gray', text: '已取消' }, - [ORDER_STATUS.COMPLETED]: { color: 'red', text: '设备执行完成' }, - [ORDER_STATUS.SERVING]: { color: 'lightblue', text: '正在服务中' }, - [ORDER_STATUS.UPLOADING]: { color: 'pink', text: '素材上传中' }, - [ORDER_STATUS.UPLOAD_COMPLETED]: { color: 'green', text: '素材上传完成' }, - [ORDER_STATUS.REFUNDING]: { color: 'darkgray', text: '退款中' }, - [ORDER_STATUS.REFUNDED]: { color: 'cyan', text: '已退款' }, - [ORDER_STATUS.REFUND_FAILED]: { color: 'purple', text: '退款失败' }, + // 正常流程状态 + [ORDER_STATUS.UNPAID]: { + color: 'gold', // 使用金色表示待支付,引起注意 + text: '待支付' + }, + [ORDER_STATUS.PAID_QUEUING]: { + color: '#1890ff', // 使用蓝色表示进行中的状态 + text: '已支付排队中' + }, + [ORDER_STATUS.SERVING]: { + color: '#13c2c2', // 使用青色表示服务进行中 + text: '正在服务中' + }, + [ORDER_STATUS.UPLOADING]: { + color: '#722ed1', // 使用紫色表示上传中 + text: '素材上传中' + }, + [ORDER_STATUS.UPLOAD_COMPLETED]: { + color: '#52c41a', // 使用绿色表示完成状态 + text: '素材上传完成' + }, + [ORDER_STATUS.COMPLETED]: { + color: '#389e0d', // 使用深绿色表示最终完成 + text: '任务完成' + }, + + // 退款相关状态 + [ORDER_STATUS.REFUNDING]: { + color: '#fa8c16', // 使用橙色表示退款处理中 + text: '退款中' + }, + [ORDER_STATUS.REFUNDED]: { + color: '#d48806', // 使用深橙色表示退款完成 + text: '已退款' + }, + [ORDER_STATUS.REFUND_FAILED]: { + color: '#f5222d', // 使用红色表示退款失败 + text: '退款失败' + }, + + // 取消状态 + [ORDER_STATUS.CANCELLED]: { + color: '#8c8c8c', // 使用灰色表示已取消 + text: '已取消' + }, } as const; export const STATUS_OPTIONS = Object.entries(STATUS_CONFIG).map(([value, config]) => ({ diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/index.tsx index 99439075..8122f7a6 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/index.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/index.tsx @@ -129,7 +129,18 @@ const TableList: React.FC = () => { split span={8} className="query-filter" - onFinish={async (values) => setParams(values)} + onFinish={async (values) => { + // 处理查询参数 + const params = { + orderNo: values.orderNo?.trim(), // 去除空格 + orderStatus: values.orderStatus, // 状态 + }; + // 过滤掉空值 + const validParams = Object.fromEntries( + Object.entries(params).filter(([_, value]) => value !== undefined && value !== '') + ); + setParams(validParams); + }} > { rowKey="id" headerTitle="订单列表" - request={order} + request={async (params) => { + // 处理表格请求参数 + const { current, pageSize, orderNo, orderStatus } = params; + const result = await order({ + current, + pageSize, + orderNo, + orderStatus: orderStatus ? Number(orderStatus) : undefined, + }); + return result; + }} actionRef={actionRef} columns={columns} search={false} diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/OrderFile/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/OrderFile/index.tsx index e2752181..43ede048 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/OrderFile/index.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/OrderFile/index.tsx @@ -1,132 +1,184 @@ -import { orderFiles,deleteFile } from '@/services/orders/api'; +import { orderFiles, deleteFile } from '@/services/orders/api'; import type { ActionType, ProColumns } from '@ant-design/pro-components'; import { PageContainer, ProFormText, + ProFormDateRangePicker, ProTable, QueryFilter, } from '@ant-design/pro-components'; -import { Typography, message, Popconfirm, Image } from 'antd'; +import { Typography, message, Popconfirm, Image, Space, Tag } from 'antd'; import React, { useRef, useState } from 'react'; const { Link } = Typography; -const handleDelete = async (deletefile: ORDERS.OrderFile) => { - const hide = message.loading('正在删除'); +// 文件类型配置 +const FILE_CONFIG = { + imageTypes: ['image/jpeg', 'image/png', 'image/gif'], + videoTypes: ['video/mp4', 'video/mpeg'], + documentTypes: ['application/pdf', 'application/msword'], +}; + +// 文件类型标签颜色映射 +const TYPE_COLORS = { + 'image/jpeg': 'blue', + 'image/png': 'blue', + 'image/gif': 'blue', + 'video/mp4': 'green', + 'video/mpeg': 'green', + 'application/pdf': 'orange', + 'application/msword': 'orange', + 'default': 'default', +}; + +// 获取文件类型标签颜色 +const getTypeColor = (fileType: string) => { + return TYPE_COLORS[fileType] || TYPE_COLORS.default; +}; + +// 处理文件删除 +const handleDelete = async (file: ORDERS.OrderFile) => { + const hide = message.loading('正在删除文件...'); try { - const result = await deleteFile(deletefile.id); + const result = await deleteFile(file.id); hide(); if (result.resp_code === 0) { - message.success('删除File成功'); + message.success('删除文件成功'); return true; - } else { - message.error(result.resp_msg); - return false; } + message.error(result.resp_msg); + return false; } catch (error) { hide(); - message.error('删除File失败'); + message.error('删除文件失败'); return false; } }; -const imagePreviewTypes = ['image/jpeg', 'image/png', 'image/gif']; // 可预览的图片类型 - const TableList: React.FC = () => { const actionRef = useRef(); - const [params, setParams] = useState>({ }); + const [searchParams, setSearchParams] = useState>({}); + const columns: ProColumns[] = [ { dataIndex: 'index', valueType: 'indexBorder', + width: 48, }, { - title: '订单文件ID', - dataIndex: 'id', + title: '订单编号', + dataIndex: 'orderNo', + copyable: true, + ellipsis: true, }, { - title: '文件ID', - dataIndex: 'fileId', - }, - { - title: '文件', + title: '文件预览', dataIndex: 'viewUrl', - render: (viewUrl, entity) => ( - <> - {imagePreviewTypes.includes(entity.fileType) ? ( - + width: 200, + render: (viewUrl, record) => ( + + {FILE_CONFIG.imageTypes.includes(record.fileType) ? ( + 加载中...} + /> ) : ( - - 下载文件 - + + {record.fileType.split('/')[1].toUpperCase()} + )} - - 预览原图 - - + + + 下载 + + + 预览 + + + ), }, { - title: '媒体类型', + title: '文件类型', dataIndex: 'fileType', + width: 120, + render: (type) => ( + + {(type as string).split('/')[1].toUpperCase()} + + ), }, - { - title: '任务编号', - dataIndex: 'orderNo', - }, - { title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', + sorter: true, + width: 180, }, { title: '操作', - key: 'action', - render: (_, entity) => { - const success = await handleDelete(entity); - if (success) { - if (actionRef.current) { + valueType: 'option', + width: 120, + render: (_, record) => ( + { + const success = await handleDelete(record); + if (success && actionRef.current) { actionRef.current.reload(); } - } - }} - > - 删除 - , + }} + > + 删除 + + ), }, ]; return ( - + setParams(values)} + onFinish={setSearchParams} > - + + + rowKey="id" - headerTitle="任务列表" - request={orderFiles} + headerTitle="文件列表" actionRef={actionRef} columns={columns} + request={orderFiles} + params={searchParams} search={false} - params={params} pagination={{ + defaultPageSize: 10, showSizeChanger: true, showQuickJumper: true, }} + dateFormatter="string" + toolbar={{ + settings: { + draggable: true, + checkable: true, + checkedReset: true, + extra: '表格列设置', + }, + }} /> ); diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/components/UpdateForm.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/components/UpdateForm.tsx index 19e5aea3..457f8924 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/components/UpdateForm.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/components/UpdateForm.tsx @@ -1,51 +1,30 @@ -import { wayline } from '@/services/device/api'; import { ModalForm, ProForm, ProFormSelect, ProFormText, } from '@ant-design/pro-components'; -import { message } from 'antd'; -import React, { useState, useEffect } from 'react'; -import { TOURISM_OPTIONS, DEVICE_OPTIONS, STATUS_OPTIONS } from '../index'; +import React from 'react'; +import { STATUS_OPTIONS } from '../index'; -export type UpdateFormProps = { - onSubmit: (values: Partial) => Promise; +interface UpdateFormProps { + onSubmit: (values: any) => Promise; onVisibleChange: (visible: boolean) => void; updateModalVisible: boolean; values?: ORDERS.Qrcode; -}; + waylineOptions: any[]; // 从父组件接收航线选项 + tourismOptions: any[]; // 从父组件接收景区选项 +} const UpdateForm: React.FC = (props) => { - const { onSubmit, onVisibleChange, updateModalVisible, values } = props; - const [waylineOptions, setWaylineOptions] = useState([]); - - // 获取航线列表 - const fetchWaylineOptions = async () => { - try { - const result = await wayline({ - current: 1, - pageSize: 100, - }); - if (result?.data) { - const options = result.data.map((item: any) => ({ - label: item.name, - value: item.waylineId, - wayline: item, - })); - setWaylineOptions(options); - } - } catch (error) { - message.error('获取航线列表失败'); - } - }; - - // 在弹窗显示时获取航线列表 - useEffect(() => { - if (updateModalVisible) { - fetchWaylineOptions(); - } - }, [updateModalVisible]); + const { + onSubmit, + onVisibleChange, + updateModalVisible, + values, + waylineOptions, + tourismOptions, + } = props; return ( = (props) => { visible={updateModalVisible} onVisibleChange={onVisibleChange} modalProps={{ destroyOnClose: true }} - initialValues={{ - ...values, - waylineId: values?.waylineId, - status: values?.status, // 确保状态值被正确初始化 - }} - onFinish={async (formValues) => { - const changedValues: Partial = {}; - Object.keys(formValues).forEach(key => { - if (formValues[key] !== values?.[key]) { - changedValues[key] = formValues[key]; - } - }); - - if (Object.keys(changedValues).length === 0) { - return true; - } - - await onSubmit(changedValues); - }} + initialValues={values} + onFinish={onSubmit} > = (props) => { options={waylineOptions} rules={[{ required: true, message: '请选择航线' }]} fieldProps={{ - loading: waylineOptions.length === 0, + loading: !waylineOptions.length, showSearch: true, - onChange: (value, option: any) => { - // 可以在这里处理航线选择后的联动逻辑 - console.log('选择的航线:', option); - } + filterOption: (input, option) => + (option?.label ?? '').toLowerCase().includes(input.toLowerCase()), }} /> = (props) => { name="tourismId" label="景区" placeholder="请选择景区" - options={TOURISM_OPTIONS} + options={tourismOptions} rules={[{ required: true, message: '请选择景区' }]} + fieldProps={{ + loading: !tourismOptions.length, + showSearch: true, + filterOption: (input, option) => + (option?.label ?? '').toLowerCase().includes(input.toLowerCase()), + }} /> - { const [updateModalVisible, handleUpdateModalVisible] = useState(false); const [currentRow, setCurrentRow] = useState(); const [waylineOptions, setWaylineOptions] = useState([]); + const [tourismOptions, setTourismOptions] = useState([]); const formRef = useRef(); const handleTableAction = useCallback(async ( @@ -154,16 +155,31 @@ const TableList: React.FC = () => { } }; - useEffect(() => { - console.log('Modal visible changed:', updateModalVisible); - if (updateModalVisible) { - fetchWaylineOptions(); + const fetchTourismList = useCallback(async () => { + try { + const result = await tourism({ + limit: 100, + page: 1, + }); + + if (result.data) { + const options = result.data.map(item => ({ + label: item.tourismName, + value: item.id, + })); + setTourismOptions(options); + } + } catch (error) { + message.error('获取景区列表失败'); } - }, [updateModalVisible]); + }, []); useEffect(() => { - console.log('Current wayline options:', waylineOptions); - }, [waylineOptions]); + if (updateModalVisible || createModalVisible) { + fetchTourismList(); + fetchWaylineOptions(); + } + }, [updateModalVisible, createModalVisible, fetchTourismList]); const columns: ProColumns[] = [ { @@ -272,7 +288,13 @@ const TableList: React.FC = () => { { + handleModalVisible(visible); + if (!visible) { + setWaylineOptions([]); + setTourismOptions([]); + } + }} modalProps={{ destroyOnClose: true }} onFinish={async (values) => handleTableAction('add', undefined, values)} > @@ -284,14 +306,26 @@ const TableList: React.FC = () => { placeholder="请选择航线" options={waylineOptions} rules={[{ required: true, message: '请选择航线' }]} + fieldProps={{ + loading: !waylineOptions.length, + showSearch: true, + filterOption: (input, option) => + (option?.label ?? '').toLowerCase().includes(input.toLowerCase()), + }} /> + (option?.label ?? '').toLowerCase().includes(input.toLowerCase()), + }} /> { handleUpdateModalVisible(visible); if (!visible) { setCurrentRow(undefined); + setWaylineOptions([]); + setTourismOptions([]); } }} updateModalVisible={updateModalVisible} values={currentRow} + waylineOptions={waylineOptions} + tourismOptions={tourismOptions} /> ); diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/components/UpdateForm.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/components/UpdateForm.tsx index 59cb7dfe..7b81b14c 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/components/UpdateForm.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/components/UpdateForm.tsx @@ -2,18 +2,34 @@ import { ModalForm, ProForm, ProFormText, + ProFormSelect, } from '@ant-design/pro-components'; import React from 'react'; -export type UpdateFormProps = { - onSubmit: (values: Partial) => Promise; +// 状态选项 +const STATUS_OPTIONS = [ + { label: '启用', value: '1' }, + { label: '未启用', value: '0' }, +]; + +interface UpdateFormProps { + onSubmit: (values: any) => Promise; onVisibleChange: (visible: boolean) => void; updateModalVisible: boolean; values?: ORDERS.Tourism; -}; +} -const UpdateForm: React.FC = (props) => { - const { onSubmit, onVisibleChange, updateModalVisible, values } = props; +const UpdateForm: React.FC = ({ + onSubmit, + onVisibleChange, + updateModalVisible, + values, +}) => { + // 表单字段验证规则 + const formRules = { + required: { required: true, message: '此项为必填项' }, + phone: { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号' }, + }; return ( = (props) => { visible={updateModalVisible} onVisibleChange={onVisibleChange} modalProps={{ destroyOnClose: true }} - onFinish={async (formValues) => { - // 只提交已修改的字段 - const changedValues: Partial = {}; - Object.keys(formValues).forEach(key => { - if (formValues[key] !== values?.[key]) { - changedValues[key] = formValues[key]; - } - }); - - if (Object.keys(changedValues).length === 0) { - return true; // 如果没有修改任何字段,直接关闭 - } - - await onSubmit(changedValues); - }} initialValues={values} + onFinish={onSubmit} > + diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/index.tsx index 0e337189..014fd78d 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/index.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/index.tsx @@ -8,246 +8,256 @@ import { ProForm, ProFormText, ProTable, - QueryFilter, + ProFormSelect, } from '@ant-design/pro-components'; import { Typography, message, Popconfirm, Button, Space } from 'antd'; import React, { useRef, useState, useCallback } from 'react'; const { Link } = Typography; +// 状态常量 +const STATUS_OPTIONS = [ + { label: '启用', value: '1' }, + { label: '未启用', value: '0' }, +]; + +// 统一的消息处理 +const showMessage = { + success: (msg: string) => message.success(msg), + error: (msg: string) => message.error(msg), + loading: (msg: string) => message.loading(msg), +}; + +// API 请求处理器 const handleApiRequest = async ( apiCall: () => Promise, loadingMessage: string, successMessage: string, -) => { - const hide = message.loading(loadingMessage); +): Promise => { + const hide = showMessage.loading(loadingMessage); try { const result = await apiCall(); hide(); if (result.resp_code === 0) { - message.success(successMessage); + showMessage.success(successMessage); return true; } - message.error(result.resp_msg); + showMessage.error(result.resp_msg); return false; } catch (error) { hide(); - message.error(`${successMessage}失败`); + showMessage.error(`${successMessage}失败: ${error.message}`); return false; } }; -const handleAdd = async (fields: ORDERS.Tourism) => { - return handleApiRequest( - () => saveOrUpdateTourism({ ...fields }), - '正在添加', - '添加景区成功' - ); -}; - -const handleEdit = async (original: ORDERS.Tourism, fields: Partial) => { - return handleApiRequest( - () => saveOrUpdateTourism({ - id: original.id, // 保留原始ID - ...fields // 只包含修改的字段 - }), - '正在更新', - '修改景区成功' - ); -}; - -const handleDelete = async (tourism: ORDERS.Tourism) => { - return handleApiRequest( - () => deleteTourism(tourism.id), - '正在删除', - '删除景区成功' - ); -}; - const TableList: React.FC = () => { - // 1. 先定义所有的 hooks const actionRef = useRef(); - const [params, setParams] = useState>({}); - const [createModalVisible, handleModalVisible] = useState(false); - const [updateModalVisible, handleUpdateModalVisible] = useState(false); + const [searchParams, setSearchParams] = useState>({}); + const [createModalVisible, setCreateModalVisible] = useState(false); + const [updateModalVisible, setUpdateModalVisible] = useState(false); const [currentRow, setCurrentRow] = useState(); - // 2. 然后定义 handleTableAction + // 表格操作处理 const handleTableAction = useCallback(async ( action: 'add' | 'edit' | 'delete', record?: ORDERS.Tourism, values?: Partial ) => { - let success = false; - switch (action) { - case 'add': - success = await handleAdd(values as ORDERS.Tourism); - success && handleModalVisible(false); - break; - case 'edit': - if (record) { - success = await handleEdit(record, values || {}); - if (success) { - handleUpdateModalVisible(false); - setCurrentRow(undefined); - } + const actions = { + add: async () => { + const success = await handleApiRequest( + () => saveOrUpdateTourism(values as ORDERS.Tourism), + '正在添加景区...', + '添加景区成功' + ); + success && setCreateModalVisible(false); + return success; + }, + edit: async () => { + if (!record) return false; + const success = await handleApiRequest( + () => saveOrUpdateTourism({ id: record.id, ...values }), + '正在更新景区...', + '修改景区成功' + ); + if (success) { + setUpdateModalVisible(false); + setCurrentRow(undefined); } - break; - case 'delete': - success = await handleDelete(record!); - break; - } + return success; + }, + delete: async () => { + if (!record) return false; + return handleApiRequest( + () => deleteTourism(record.id), + '正在删除景区...', + '删除景区成功' + ); + }, + }; + + const success = await actions[action](); if (success && actionRef.current) { actionRef.current.reload(); } - }, []); // 添加依赖数组 + }, []); + // 表格列定义 const columns: ProColumns[] = [ { dataIndex: 'index', valueType: 'indexBorder', + width: 48, }, { title: 'ID', dataIndex: 'id', + hideInSearch: true, + width: 80, }, { title: '编号', dataIndex: 'tourismNo', + copyable: true, }, { title: '名称', dataIndex: 'tourismName', + ellipsis: true, }, { title: '地址', dataIndex: 'tourismAddress', + ellipsis: true, }, { title: '联系电话', dataIndex: 'tourismPhone', + copyable: true, }, { title: '状态', dataIndex: 'status', + valueType: 'select', + valueEnum: { + '1': { text: '启用', status: 'Success' }, + '0': { text: '未启用', status: 'Error' }, + }, }, { title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', + hideInSearch: true, }, { title: '操作', - key: 'action', - render: (_, entity) => - - { - setCurrentRow(entity); - handleUpdateModalVisible(true); - }} - > - 修改 - - handleTableAction('delete', entity)} - > - 删除 - - + valueType: 'option', + width: 180, + render: (_, record) => ( + + { + setCurrentRow(record); + setUpdateModalVisible(true); + }} + > + 修改 + + handleTableAction('delete', record)} + > + 删除 + + + ), }, ]; + // 表单字段验证规则 + const formRules = { + required: { required: true, message: '此项为必填项' }, + phone: { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号' }, + }; + return ( - - setParams(values)} - > - - + rowKey="id" headerTitle="景区列表" - request={tourism} actionRef={actionRef} columns={columns} - search={false} - params={params} + request={tourism} + params={searchParams} + search={{ + labelWidth: 'auto', + }} pagination={{ + defaultPageSize: 10, showSizeChanger: true, showQuickJumper: true, }} toolBarRender={() => [ - <> - - , + , ]} /> + + {/* 新增表单 */} handleTableAction('add', undefined, values)} > - - - + + + + + + {/* 修改表单 */} handleTableAction('edit', currentRow, values)} - onVisibleChange={handleUpdateModalVisible} + onVisibleChange={setUpdateModalVisible} updateModalVisible={updateModalVisible} values={currentRow} /> - ); }; diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/components/CreateForm.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/components/CreateForm.tsx new file mode 100644 index 00000000..a3ef77e3 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/components/CreateForm.tsx @@ -0,0 +1,159 @@ +import { ModalForm, ProForm, ProFormSelect, ProFormText } from '@ant-design/pro-components'; +import { Button, Upload, message } from 'antd'; +import { UploadOutlined } from '@ant-design/icons'; +import React, { useState } from 'react'; +import { TYPE_OPTIONS } from '../constants'; +import { importImage, saveOrUpdateTourismFile } from '@/services/orders/api'; +import type { RcFile } from 'antd/lib/upload'; +import styles from '../index.less'; + +interface CreateFormProps { + visible: boolean; + onVisibleChange: (visible: boolean) => void; + tourismOptions: { label: string; value: number; }[]; + onSuccess: () => void; +} + +const CreateForm: React.FC = ({ + visible, + onVisibleChange, + tourismOptions, + onSuccess, +}) => { + const [imageUrl, setImageUrl] = useState(); + + const handleUpload = async (file: RcFile) => { + const hide = message.loading('正在上传'); + try { + const formData = new FormData(); + formData.append('file', file); + const result = await importImage(formData); + hide(); + if (result.name) { + setImageUrl(result.name); + message.success('上传成功'); + } + } catch (error) { + hide(); + message.error('上传失败'); + } + return false; + }; + + const handleSubmit = async (values: Record) => { + if (!imageUrl) { + message.error('请上传素材图片'); + return false; + } + + const hide = message.loading('正在提交'); + try { + const result = await saveOrUpdateTourismFile({ + ...values, + imageUrl, + status: 0, // 默认启用 + }); + hide(); + + if (result.resp_code === 0) { + message.success('创建成功'); + onSuccess(); + return true; + } + message.error(result.resp_msg); + return false; + } catch (error) { + hide(); + message.error('创建失败'); + return false; + } + }; + + return ( + { + if (!visible) { + setImageUrl(undefined); + } + onVisibleChange(visible); + }} + modalProps={{ + destroyOnClose: true, + maskClosable: false, + }} + onFinish={handleSubmit} + > + + + (option?.label ?? '').toLowerCase().includes(input.toLowerCase()), + }} + /> + + + + +
+
+ 素材图片: + * +
+ {imageUrl && ( +
+ preview +
+ )} + + + +
+
+
+ ); +}; + +export default CreateForm; \ No newline at end of file diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/components/SearchForm.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/components/SearchForm.tsx new file mode 100644 index 00000000..06b2a8d0 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/components/SearchForm.tsx @@ -0,0 +1,41 @@ +import { ProFormSelect, ProFormText, QueryFilter } from '@ant-design/pro-components'; +import { TYPE_OPTIONS } from '../constants'; +import React from 'react'; + +interface SearchFormProps { + tourismOptions: { label: string; value: number; }[]; + onSearch: (values: Record) => void; +} + +const SearchForm: React.FC = ({ tourismOptions, onSearch }) => { + return ( + + + + + + ); +}; + +export default SearchForm; \ No newline at end of file diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/components/UpdateForm.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/components/UpdateForm.tsx index 0ee4963f..6afba3e5 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/components/UpdateForm.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/components/UpdateForm.tsx @@ -8,16 +8,16 @@ import { } from '@ant-design/pro-components'; import { Button, Upload, Image, message } from 'antd'; import type { RcFile } from 'antd/lib/upload'; -import React, { useState } from 'react'; +import React, { useState, useEffect, useCallback } from 'react'; import { TOURISM_OPTIONS, TYPE_OPTIONS } from '../constants'; import styles from '../index.less'; +import { tourism } from '@/services/orders/api'; interface UpdateFormProps { onSubmit: (values: Partial) => Promise; onVisibleChange: (visible: boolean) => void; updateModalVisible: boolean; values?: ORDERS.TourismFile; - tourismOptions: { label: string; value: number; }[]; } const UpdateForm: React.FC = ({ @@ -25,9 +25,9 @@ const UpdateForm: React.FC = ({ onVisibleChange, updateModalVisible, values, - tourismOptions, }) => { const [imageUrl, setImageUrl] = useState(values?.imageUrl || ''); + const [tourismOptions, setTourismOptions] = useState([]); const handleUpload = async (file: RcFile) => { const hide = message.loading('正在上传'); @@ -47,6 +47,33 @@ const UpdateForm: React.FC = ({ return false; }; + // 获取景区列表 + const fetchTourismList = useCallback(async () => { + try { + const result = await tourism({ + limit: 100, + page: 1, + }); + + if (result.data) { + const options = result.data.map(item => ({ + label: item.tourismName, + value: item.id, + })); + setTourismOptions(options); + } + } catch (error) { + message.error('获取景区列表失败'); + } + }, []); + + // 在组件挂载和弹窗打开时获取数据 + useEffect(() => { + if (updateModalVisible) { + fetchTourismList(); + } + }, [updateModalVisible, fetchTourismList]); + return ( = ({ > = ({ showSearch fieldProps={{ loading: !tourismOptions.length, + filterOption: (input, option) => + (option?.label ?? '').toLowerCase().includes(input.toLowerCase()), }} /> { const TableList: React.FC = () => { const actionRef = useRef(); const [params, setParams] = useState>({}); - const [createModalVisible, handleModalVisible] = useState(false); - const [updateModalVisible, handleUpdateModalVisible] = useState(false); + const [createModalVisible, setCreateModalVisible] = useState(false); + const [updateModalVisible, setUpdateModalVisible] = useState(false); const [currentRow, setCurrentRow] = useState(); const [file, setFile] = useState(); - const [tourismOptions, setTourismOptions] = useState<{ label: string; value: number; }[]>([]); + const [tourismOptions, setTourismOptions] = useState<{ label: string; value: number; info?: any }[]>([]); // 获取景区列表 const fetchTourismList = useCallback(async () => { try { + console.log('开始获取景区列表...'); + const result = await tourism({ - pageSize: 100, - current: 1, + limit: 100, + page: 1, }); - if (result.resp_code === 0 && result.data) { - const options = result.data.records?.map(item => ({ - label: item.name, + + console.log('tourism接口返回数据:', result); + + if (result.data) { + const options = result.data.map(item => ({ + label: item.tourismName, value: item.id, - })) || []; + })); + + console.log('转换后的选项数据:', options); setTourismOptions(options); } } catch (error) { + console.error('获取景区列表失败:', error); message.error('获取景区列表失败'); } }, []); - // 在组件挂载时获取景区列表 + // 在组件挂载时获取数据 useEffect(() => { fetchTourismList(); }, [fetchTourismList]); @@ -157,13 +168,13 @@ const TableList: React.FC = () => { switch (action) { case 'add': success = await handleAdd({ ...values, imageUrl: file } as ORDERS.TourismFile); - success && handleModalVisible(false); + success && setCreateModalVisible(false); break; case 'edit': if (record) { success = await handleEdit(record, values || {}); if (success) { - handleUpdateModalVisible(false); + setUpdateModalVisible(false); setCurrentRow(undefined); } } @@ -179,69 +190,85 @@ const TableList: React.FC = () => { const columns: ProColumns[] = [ { + title: '序号', dataIndex: 'index', valueType: 'indexBorder', + width: 48, }, { title: '景区名称', - dataIndex: 'tourismId', + dataIndex: 'tourismName', ellipsis: true, }, { - title: '素材', + title: '素材预览', dataIndex: 'imageUrl', - render: (imageUrl) => + width: 120, + render: (imageUrl) => ( + + ), }, { title: '页面链接', dataIndex: 'linkUrl', + ellipsis: true, + copyable: true, }, { title: '描述', dataIndex: 'description', + ellipsis: true, }, { title: '状态', dataIndex: 'status', - render: (status) => renderStatus(status), + width: 100, + render: renderStatus, }, { title: "类型", dataIndex: 'type', - render: (type) => renderType(type) + width: 120, + render: renderType, }, { title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', + width: 180, }, { title: '操作', key: 'action', - render: (_, entity) => - - { - setCurrentRow(entity); - handleUpdateModalVisible(true); - }} - > - 修改 - - { - const success = await handleTableAction('delete', entity); - if (success) { - if (actionRef.current) { - actionRef.current.reload(); + width: 120, + render: (_, record) => ( + + { + setCurrentRow(record); + setUpdateModalVisible(true); + }} + > + 修改 + + { + const success = await handleTableAction('delete', record); + if (success) { + actionRef.current?.reload(); } - } - }} - > - 删除 - - + }} + > + 删除 + + + ), }, ]; @@ -250,12 +277,30 @@ const TableList: React.FC = () => { setParams(values)} > - + + + + rowKey="id" headerTitle="素材列表" @@ -267,30 +312,36 @@ const TableList: React.FC = () => { pagination={{ showSizeChanger: true, showQuickJumper: true, + defaultPageSize: 10, + pageSizeOptions: ['10', '20', '50'], }} toolBarRender={() => [ - <> - - , + , ]} /> + { + console.log('Modal visible changed:', visible); + setCreateModalVisible(visible); + if (visible) { + fetchTourismList(); + } + }} modalProps={{ destroyOnClose: true }} onFinish={(values) => handleTableAction('add', undefined, values)} > { showSearch fieldProps={{ loading: !tourismOptions.length, + filterOption: (input, option) => + (option?.label ?? '').toLowerCase().includes(input.toLowerCase()), }} /> { + handleTableAction('edit', currentRow, values)} - onVisibleChange={handleUpdateModalVisible} + onVisibleChange={setUpdateModalVisible} updateModalVisible={updateModalVisible} values={currentRow} tourismOptions={tourismOptions}