diff --git a/zlt-business/device-center/src/main/java/com/central/device/controller/ApiDeviceController.java b/zlt-business/device-center/src/main/java/com/central/device/controller/ApiDeviceController.java index fa5193dd..02da12c8 100644 --- a/zlt-business/device-center/src/main/java/com/central/device/controller/ApiDeviceController.java +++ b/zlt-business/device-center/src/main/java/com/central/device/controller/ApiDeviceController.java @@ -114,4 +114,8 @@ public class ApiDeviceController { } + @GetMapping("/wayline") + public Result getWayline(@RequestParam String no){ + return Result.succeed(orderCenterService.getOrderStatusByOrderNo(no)); + } } diff --git a/zlt-business/order-center/src/main/java/com/central/order/controller/QrCodeController.java b/zlt-business/order-center/src/main/java/com/central/order/controller/QrCodeController.java index fad13d7e..c02f813e 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/controller/QrCodeController.java +++ b/zlt-business/order-center/src/main/java/com/central/order/controller/QrCodeController.java @@ -73,22 +73,23 @@ public class QrCodeController { @Operation(summary = "生成景区二维码") @PostMapping public Result saveOrUpdateQrcode(@RequestBody QrCode qrCode) throws Exception { - String codeId = ""; - if (qrCode.getId() == null){ - codeId = UUID.randomUUID().toString(); - } - Result result = fileCenterService.uploadQrCodeFile(codeId); - if (result.getResp_code() == 0){ - qrCode.setCodeId(codeId); - qrCode.setFilePath(result.getData().get("filePath").toString()); - qrCode.setFileId(result.getData().get("fileId").toString()); - boolean res = qrCodeService.saveOrUpdate(qrCode); - if (res) { - return Result.succeed(qrCode,"qrcode创建成功"); - } else { - return Result.failed("qrcode创建失败"); + if (qrCode.getId() == null){ + String codeId = UUID.randomUUID().toString(); + Result result = fileCenterService.uploadQrCodeFile(codeId); + if (result.getResp_code() == 0){ + qrCode.setCodeId(codeId); + qrCode.setFilePath(result.getData().get("filePath").toString()); + qrCode.setFileId(result.getData().get("fileId").toString()); + if (qrCodeService.saveOrUpdate(qrCode)) { + return Result.succeed(qrCode,"qrcode创建成功"); + } else { + return Result.failed("qrcode创建失败"); + } } + }else { + qrCodeService.saveOrUpdate(qrCode); + return Result.succeed(qrCode,"qrcode修改成功"); } return Result.failed("创建失败"); diff --git a/zlt-business/order-center/src/main/java/com/central/order/model/Tourism.java b/zlt-business/order-center/src/main/java/com/central/order/model/Tourism.java index 217bb51c..443d2197 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/model/Tourism.java +++ b/zlt-business/order-center/src/main/java/com/central/order/model/Tourism.java @@ -38,8 +38,7 @@ public class Tourism extends SuperEntity { private Date createTime; @TableField(fill = FieldFill.INSERT_UPDATE) private Date updateTime; - - private Long createId; + //租户ID private Long tenantId; private String company; diff --git a/zlt-web/react-web/src/main/frontend/config/proxy.ts b/zlt-web/react-web/src/main/frontend/config/proxy.ts index 2a5df10a..7a403694 100644 --- a/zlt-web/react-web/src/main/frontend/config/proxy.ts +++ b/zlt-web/react-web/src/main/frontend/config/proxy.ts @@ -43,6 +43,11 @@ target: 'http://119.45.169.13:9900', changeOrigin: true, }, + '/api-device/': { + // target: 'http://127.0.0.1:9900', + target: 'http://119.45.169.13:9900', + changeOrigin: true, + }, }, test: { '/api/': { diff --git a/zlt-web/react-web/src/main/frontend/config/routes.ts b/zlt-web/react-web/src/main/frontend/config/routes.ts index cb032bd7..a4b218aa 100644 --- a/zlt-web/react-web/src/main/frontend/config/routes.ts +++ b/zlt-web/react-web/src/main/frontend/config/routes.ts @@ -47,6 +47,15 @@ } ], }, + { + path: '/device', + routes: [ + { + path: '/device/wayline.html', + component: './device/Wayline', + }, + ] + }, { path: '/orders', routes: [ diff --git a/zlt-web/react-web/src/main/frontend/src/locales/zh-CN/menu.ts b/zlt-web/react-web/src/main/frontend/src/locales/zh-CN/menu.ts index fecb70a4..4f640e8b 100644 --- a/zlt-web/react-web/src/main/frontend/src/locales/zh-CN/menu.ts +++ b/zlt-web/react-web/src/main/frontend/src/locales/zh-CN/menu.ts @@ -49,4 +49,5 @@ export default { 'menu.editor.flow': '流程编辑器', 'menu.editor.mind': '脑图编辑器', 'menu.editor.koni': '拓扑编辑器', + 'menu.首页': '首页', }; diff --git a/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline/components/UpdateForm.tsx b/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline/components/UpdateForm.tsx new file mode 100644 index 00000000..886c4164 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline/components/UpdateForm.tsx @@ -0,0 +1,122 @@ +import { importImage } from '@/services/system/api'; +import { UploadOutlined } from '@ant-design/icons'; +import { + ModalForm, + ProForm, + ProFormSelect, + ProFormText, +} from '@ant-design/pro-components'; +import { Button, Form, message, Upload } from 'antd'; +import { RcFile } from 'antd/lib/upload'; +import { useState } from 'react'; +import styles from '../index.less'; +import { TOURISM_OPTIONS, TYPE_OPTIONS, WORKSPACE_OPTIONS } from '../index'; + +export type FormValueType = Partial; + +export type UpdateFormProps = { + onSubmit: (values: Partial) => Promise; + onVisibleChange: (visible: boolean) => void; + updateModalVisible: boolean; + values?: DEVICE.Wayline; + onUpload: (fileInfo: FileResponse) => void; +}; + +const handleImport = async (file: RcFile) => { + const hide = message.loading('正在导入'); + try { + const formData = new FormData(); + formData.append('file', file); + const result = await importImage(formData); + hide(); + message.success('上传素材成功'); + return result; + } catch (error) { + hide(); + message.error('上传素材失败'); + return null; + } +}; + +const UpdateForm: React.FC = (props) => { + const { onSubmit, onVisibleChange, updateModalVisible, values, onUpload } = props; + const [hasNewFile, setHasNewFile] = useState(false); + + return ( + { + onVisibleChange(visible); + if (!visible) { + setHasNewFile(false); + } + }} + 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 && !hasNewFile) { + return true; + } + + await onSubmit(changedValues); + }} + initialValues={values} + > + + + + +
+
航线文件:
+ {values?.fileUrl && !hasNewFile && ( +
+ 当前文件:{values.name} +
+ )} + { + const result = await handleImport(file); + if (result) { + onUpload(result); + setHasNewFile(true); + message.success('文件上传成功'); + } + return false; + }} + > + + + {hasNewFile &&
已上传新文件
} +
+
+
+ ); +}; + +export default UpdateForm; diff --git a/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline/index.less b/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline/index.less new file mode 100644 index 00000000..8d289828 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline/index.less @@ -0,0 +1 @@ +@import (reference) '~antd/es/style/themes/index'; diff --git a/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline/index.tsx new file mode 100644 index 00000000..482879ce --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline/index.tsx @@ -0,0 +1,385 @@ +import { deleteWayline, saveOrUpdateWayline, wayline } from '@/services/device/api'; +import { importImage } from '@/services/system/api'; +import { PlusOutlined, UploadOutlined } from '@ant-design/icons'; +import type { ActionType, ProColumns } from '@ant-design/pro-components'; +import { + ModalForm, + PageContainer, + ProForm, + ProFormSelect, + ProFormText, + 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 UpdateForm from './components/UpdateForm'; +import styles from './index.less'; + +const { Link } = Typography; + +// 状态映射 +const statusColorMap = { + 0: { color: 'green', text: '启用' }, + 1: { color: 'red', text: '未启用' }, +}; + +// 提取常量 +export const WORKSPACE_OPTIONS = [ + { label: '工作区1', value: 1 }, + { label: '工作区2', value: 2 }, + // ... 根据实际需求添加更多选项 +] as const; + +// 统一错误处理 +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: DEVICE.Wayline) => { + return handleApiRequest( + () => saveOrUpdateWayline({ ...fields }), + '正在添加', + '添加成功' + ); +}; + +const handleEdit = async (original: DEVICE.Wayline, fields: Partial) => { + return handleApiRequest( + () => saveOrUpdateWayline({ + id: original.id, + ...fields + }), + '正在更新', + '修改成功' + ); +}; + +const handleDelete = async (tourismFile: DEVICE.Wayline) => { + return handleApiRequest( + () => deleteWayline(tourismFile.id), + '正在删除', + '删除成功' + ); +}; + +const handleImport = async (file: RcFile) => { + return handleApiRequest( + async () => { + const formData = new FormData(); + formData.append('file', file); + return await importImage(formData); + }, + '正在上传', + '上传素材成功' + ); +}; + +// 渲染函数 +const renderStatus = (status: {} | null | undefined) => { + const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' }; + return {statusInfo.text}; +}; + +const renderType = (type: {} | null | undefined) => { + const typeInfo = typeColorMap[type] || { color: 'gray', text: '未知状态' }; + return {typeInfo.text}; +}; + +interface FileResponse { + id: string; + name: string; + url: string; + // ... 其他字段 +} + +const TableList: React.FC = () => { + const actionRef = useRef(); + const [params, setParams] = useState>({}); + const [createModalVisible, handleModalVisible] = useState(false); + const [updateModalVisible, handleUpdateModalVisible] = useState(false); + const [currentRow, setCurrentRow] = useState(); + const [fileInfo, setFileInfo] = useState(); + const formRef = useRef(); + + const handleFileUpload = async (file: RcFile) => { + try { + const formData = new FormData(); + formData.append('file', file); + const result = await importImage(formData); + if (result) { + setFileInfo(result); + formRef.current?.setFieldsValue({ + waylineId: result.id, + name: result.name + }); + message.success('文件上传成功'); + } + return false; + } catch (error) { + message.error('文件上传失败'); + return false; + } + }; + + const handleTableAction = useCallback(async ( + action: 'add' | 'edit' | 'delete', + record?: DEVICE.Wayline, + values?: Partial + ) => { + let success = false; + switch (action) { + case 'add': + if (!fileInfo) { + message.error('请上传航线文件'); + return; + } + success = await handleAdd({ + ...values, + fileUrl: fileInfo.url, + waylineId: fileInfo.id, + name: values.name || fileInfo.name + } as DEVICE.Wayline); + if (success) { + handleModalVisible(false); + setFileInfo(undefined); + } + break; + case 'edit': + if (record) { + const updateData = { + ...values, + ...(fileInfo ? { + fileUrl: fileInfo.url, + waylineId: fileInfo.id + } : {}) + }; + success = await handleEdit(record, updateData); + if (success) { + handleUpdateModalVisible(false); + setCurrentRow(undefined); + setFileInfo(undefined); + } + } + break; + case 'delete': + success = await handleDelete(record!); + break; + } + if (success && actionRef.current) { + actionRef.current.reload(); + } + }, [fileInfo]); + + const columns: ProColumns[] = [ + { + dataIndex: 'index', + valueType: 'indexBorder', + }, + { + title: '航线名称', + dataIndex: 'name', + }, + { + title: '航线id', + dataIndex: 'waylineId', + }, + { + title: '地区ID', + dataIndex: 'workspaceId', + }, + { + title: '创建时间', + dataIndex: 'createTime', + valueType: 'dateTime', + }, + { + title: '航线文件', + dataIndex: 'fileUrl', + render: (fileUrl, record) => fileUrl ? ( + { + e.preventDefault(); + const link = document.createElement('a'); + link.href = fileUrl; + link.download = record.name || 'wayline.kmz'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + }} + > + 下载文件 + + ) : '-' + }, + { + title: '操作', + key: 'action', + render: (_, entity) => + + { + setCurrentRow(entity); + handleUpdateModalVisible(true); + }} + > + 修改 + + { + const success = await handleTableAction('delete', entity); + if (success) { + if (actionRef.current) { + actionRef.current.reload(); + } + } + }} + > + 删除 + + + }, + ]; + + return ( + + setParams(values)} + > + + + + rowKey="id" + headerTitle="航线列表" + request={wayline} + actionRef={actionRef} + columns={columns} + search={false} + params={params} + pagination={{ + showSizeChanger: true, + showQuickJumper: true, + }} + toolBarRender={() => [ + , + ]} + /> + { + handleModalVisible(visible); + if (!visible) { + setFileInfo(undefined); + } + }} + modalProps={{ + destroyOnClose: true, + onCancel: () => { + setFileInfo(undefined); + } + }} + onFinish={async (values) => { + if (!fileInfo) { + message.error('请上传航线文件'); + return false; + } + return handleTableAction('add', undefined, values); + }} + > + + + + + + +
+
航线文件:
+ + + + {fileInfo && ( +
+ 已上传:{fileInfo.name} +
+ )} +
+
+
+ handleTableAction('edit', currentRow, values)} + onVisibleChange={(visible) => { + handleUpdateModalVisible(visible); + if (!visible) { + setFileInfo(undefined); + } + }} + updateModalVisible={updateModalVisible} + values={currentRow} + onUpload={setFileInfo} + /> +
+ ); +}; + +export default TableList; diff --git a/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/components/UpdateForm.tsx b/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/components/UpdateForm.tsx new file mode 100644 index 00000000..bad86a1e --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/components/UpdateForm.tsx @@ -0,0 +1,69 @@ +import { + ModalForm, + ProForm, + ProFormText, +} from '@ant-design/pro-components'; +import { Form } from 'antd'; + +export type FormValueType = Partial; + +export type UpdateFormProps = { + onVisibleChange: (flag: boolean) => void; + onSubmit: (values: FormValueType) => Promise; + updateModalVisible: boolean; + values?: ORDERS.Tourism; +}; + +const UpdateForm: React.FC = (props) => { + const [form] = Form.useForm(); + return ( + + + + + + + + ); +}; + +export default UpdateForm; diff --git a/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/index.less b/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/index.less new file mode 100644 index 00000000..8d289828 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/index.less @@ -0,0 +1 @@ +@import (reference) '~antd/es/style/themes/index'; diff --git a/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/index.tsx new file mode 100644 index 00000000..2e420a2a --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/index.tsx @@ -0,0 +1,293 @@ +import { deleteQrcode, qrcode, saveOrUpdateQrcode } from '@/services/orders/api'; +import { PlusOutlined } from '@ant-design/icons'; +import type { ActionType, ProColumns } from '@ant-design/pro-components'; +import { + ModalForm, + PageContainer, + ProForm, + ProFormSelect, + ProFormText, + ProTable, + QueryFilter, +} from '@ant-design/pro-components'; +import { Typography, Popconfirm, Space, message, Image, Button, Tag } from 'antd'; +import React, { useRef, useState } from 'react'; +import UpdateForm from './components/UpdateForm'; + +const { Link } = Typography; + +const handleAdd = async (fields: ORDERS.Qrcode) => { + const hide = message.loading('正在添加'); + try { + const result = await saveOrUpdateQrcode({ ...fields }); + hide(); + if (result.resp_code === 0) { + message.success('添加成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('添加失败'); + return false; + } +}; + +const handleEdit = async (fields: ORDERS.Qrcode) => { + const hide = message.loading('正在更新'); + try { + const result = await saveOrUpdateQrcode({ ...fields }); + hide(); + if (result.resp_code === 0) { + message.success('修改成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('修改失败'); + return false; + } +}; + +const handleDelete = async (qrcode: ORDERS.Qrcode) => { + const hide = message.loading('正在删除'); + try { + const result = await deleteQrcode(qrcode.id); + hide(); + if (result.resp_code === 0) { + message.success('删除成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('删除失败'); + return false; + } +}; + +// 状态颜色映射 +const statusColorMap = { + 0: { color: 'green', text: '启用' }, + 1: { color: 'red', text: '未启用' }, + + +}; + +// 渲染状态标签 +const renderStatus = (status: {} | null | undefined) => { + const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' }; + return {statusInfo.text}; +}; + +const TableList: React.FC = () => { + const actionRef = useRef(); + const [params, setParams] = useState>({ }); + const [createModalVisible, handleModalVisible] = useState(false); + const [updateModalVisible, handleUpdateModalVisible] = useState(false); + const [currentRow, setCurrentRow] = useState(); + const columns: ProColumns[] = [ + { + dataIndex: 'index', + valueType: 'indexBorder', + }, + { + title: 'ID', + dataIndex: 'id', + }, + { + title: 'CodeID', + dataIndex: 'codeId', + }, + { + title: '景区ID', + dataIndex: 'tourismId', + }, + { + title: '文件', + dataIndex: 'viewUrl', + render: (viewUrl) => + }, + { + title: '价格', + dataIndex: 'price', + }, + { + title: '设备SN', + dataIndex: 'deviceSn', + }, + { + title: '状态', + dataIndex: 'status', + render: (status) => renderStatus(status), + }, + { + title: '创建时间', + dataIndex: 'createTime', + valueType: 'dateTime', + }, + { + title: '操作', + key: 'action', + render: (_, entity) => + + { + setCurrentRow(entity); + handleUpdateModalVisible(true); + }} + > + 修改 + + { + const success = await handleDelete(entity); + if (success) { + if (actionRef.current) { + actionRef.current.reload(); + } + } + }} + > + 删除 + + + }, + ]; + + return ( + + setParams(values)} + > + + + + rowKey="id" + headerTitle="二维码列表" + request={qrcode} + actionRef={actionRef} + columns={columns} + search={false} + params={params} + pagination={{ + showSizeChanger: true, + showQuickJumper: true, + }} + toolBarRender={() => [ + <> + + , + ]} + /> + { + + const success = await handleAdd(values); + if (success) { + handleModalVisible(false); + if (actionRef.current) { + actionRef.current.reload(); + } + } + }} + > + + + + + + + { + if (currentRow) { + + const success = await handleEdit({ ...currentRow, ...values }); + if (success) { + handleUpdateModalVisible(false); + if (actionRef.current) { + actionRef.current.reload(); + } + } + setCurrentRow(undefined); + } + }} + onVisibleChange={handleUpdateModalVisible} + updateModalVisible={updateModalVisible} + values={currentRow} + /> + + ); +}; + +export default TableList; 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 c6b19743..808e2d03 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 @@ -1,66 +1,115 @@ import { ModalForm, ProForm, + ProFormSelect, ProFormText, } from '@ant-design/pro-components'; -import { Form } from 'antd'; - -export type FormValueType = Partial; +import { Button, Upload } 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'; export type UpdateFormProps = { - onVisibleChange: (flag: boolean) => void; - onSubmit: (values: FormValueType) => Promise; + onSubmit: (values: Partial) => Promise; + onVisibleChange: (visible: boolean) => void; updateModalVisible: boolean; values?: ORDERS.HomeCarousel; + onUpload: (fileUrl: string) => void; }; const UpdateForm: React.FC = (props) => { - const [form] = Form.useForm(); + const { onSubmit, onVisibleChange, updateModalVisible, values, onUpload } = props; + + // 导入处理函数 + const handleImport = async (file: RcFile) => { + 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); + } + return false; + } catch (error) { + hide(); + message.error('上传素材失败'); + return 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); + }} + initialValues={values} > - + + + + {/* 添加图片上传组件 */} +
+
当前图片:
+ + +
+ +
+
+
); 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 2acf4d71..a9ed46a7 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,4 +1,4 @@ -import {deleteHomeCarousel, saveOrUpdateHomeCarousel, homeCarousel } from '@/services/orders/api'; +import { deleteHomeCarousel, saveOrUpdateHomeCarousel, homeCarousel } from '@/services/orders/api'; import { importImage } from '@/services/system/api'; import { PlusOutlined, UploadOutlined } from '@ant-design/icons'; import type { ActionType, ProColumns } from '@ant-design/pro-components'; @@ -11,86 +11,21 @@ import { ProTable, QueryFilter, } from '@ant-design/pro-components'; -import { Typography, Popconfirm, Space, message, Image, Button, Tag } from 'antd'; -import React, { useRef, useState } from 'react'; +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 UpdateForm from './components/UpdateForm'; -import Upload, { RcFile } from 'antd/lib/upload'; import styles from './index.less'; const { Link } = Typography; -const handleAdd = async (fields: ORDERS.HomeCarousel) => { - const hide = message.loading('正在添加'); - try { - const result = await saveOrUpdateHomeCarousel({ ...fields }); - hide(); - if (result.resp_code === 0) { - message.success('添加成功'); - return true; - } else { - message.error(result.resp_msg); - return false; - } - } catch (error) { - hide(); - message.error('添加失败'); - return false; - } -}; +// 提取常量 +export const TYPE_OPTIONS = [ + { label: '首页轮播', value: 0 }, + { label: '活动', value: 1 }, + { label: '其他', value: 2 }, +] as const; -const handleEdit = async (fields: ORDERS.HomeCarousel) => { - const hide = message.loading('正在更新'); - try { - const result = await saveOrUpdateHomeCarousel({ ...fields }); - hide(); - if (result.resp_code === 0) { - message.success('修改成功'); - return true; - } else { - message.error(result.resp_msg); - return false; - } - } catch (error) { - hide(); - message.error('修改失败'); - return false; - } -}; - -const handleDelete = async (qrcode: ORDERS.HomeCarousel) => { - const hide = message.loading('正在删除'); - try { - const result = await deleteHomeCarousel(qrcode.id); - hide(); - if (result.resp_code === 0) { - message.success('删除成功'); - return true; - } else { - message.error(result.resp_msg); - return false; - } - } catch (error) { - hide(); - message.error('删除失败'); - return false; - } -}; - -const handleImport = async (file: RcFile) => { - const hide = message.loading('正在导入'); - try { - const formData = new FormData(); - formData.append('file', file); - const result = await importImage(formData); - hide(); - message.success('上传素材成功'); - return result; - } catch (error) { - hide(); - message.error('上传素材失败'); - return null; - } -}; // 类型颜色映射 const typeColorMap = { 0: { color: 'yellow', text: '首页轮播' }, @@ -98,21 +33,118 @@ const typeColorMap = { 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}; }; + const TableList: React.FC = () => { const actionRef = useRef(); - const [params, setParams] = useState>({ }); + const [params, setParams] = useState>({}); const [createModalVisible, handleModalVisible] = useState(false); const [updateModalVisible, handleUpdateModalVisible] = useState(false); const [currentRow, setCurrentRow] = useState(); - const [file, setFile] = useState(); - // const setImage = (imageUrl: string) => { - // setFile({ ...file, imageUrl}); - // } + const [file, setFile] = useState(); + const [updateFile, setUpdateFile] = 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; + } + if (success && actionRef.current) { + actionRef.current.reload(); + } + }, [file, updateFile]); + const columns: ProColumns[] = [ { dataIndex: 'index', @@ -134,7 +166,7 @@ const TableList: React.FC = () => { { title: '类型', dataIndex: 'type', - render: (type) => renderType(type), + render: renderType, }, { title: '描述', @@ -152,30 +184,24 @@ const TableList: React.FC = () => { { title: '操作', key: 'action', - render: (_, entity) => - - { - setCurrentRow(entity); - handleUpdateModalVisible(true); - }} - > - 修改 - - { - const success = await handleDelete(entity); - if (success) { - if (actionRef.current) { - actionRef.current.reload(); - } - } - }} - > - 删除 - - + render: (_, entity) => ( + + { + setCurrentRow(entity); + handleUpdateModalVisible(true); + }} + > + 修改 + + handleTableAction('delete', entity)} + > + 删除 + + + ), }, ]; @@ -190,7 +216,7 @@ const TableList: React.FC = () => { > - + rowKey="id" headerTitle="素材列表" request={homeCarousel} @@ -203,112 +229,84 @@ const TableList: React.FC = () => { showQuickJumper: true, }} toolBarRender={() => [ - <> - - , + , ]} /> { - - values.imageUrl = file - const success = await handleAdd(values); - if (success) { - handleModalVisible(false); - if (actionRef.current) { - actionRef.current.reload(); - } + onFinish={(values) => handleTableAction('add', undefined, values)} + > + + + + + + { + const result = await handleImport(file); + if (result && result.name) { + setFile(result.name); + } + return false; + }} + > +
+ +
+
+
+
+ handleTableAction('edit', currentRow, values)} + onVisibleChange={(visible) => { + handleUpdateModalVisible(visible); + if (!visible) { + setUpdateFile(undefined); } }} - > - - - - - - { - const result = await handleImport(file); - if (result && result.name) { - setFile(result.name); - } - return false; - }} - > -
- -
-
-
- - { - if (currentRow) { - - const success = await handleEdit({ ...currentRow, ...values }); - if (success) { - handleUpdateModalVisible(false); - if (actionRef.current) { - actionRef.current.reload(); - } - } - setCurrentRow(undefined); - } - }} - onVisibleChange={handleUpdateModalVisible} - updateModalVisible={updateModalVisible} - values={currentRow} - /> ); }; diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/components/UpdateForm.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/components/UpdateForm.tsx new file mode 100644 index 00000000..1bab925c --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/components/UpdateForm.tsx @@ -0,0 +1,50 @@ +import { + ModalForm, + ProForm, + ProFormSelect, +} from '@ant-design/pro-components'; +import React from 'react'; +import { STATUS_OPTIONS } from '../constants'; + +interface UpdateFormProps { + onSubmit: (values: { orderStatus: number }) => Promise; + onVisibleChange: (visible: boolean) => void; + updateModalVisible: boolean; + values?: ORDERS.Order; +} + +const UpdateForm: React.FC = ({ + onSubmit, + onVisibleChange, + updateModalVisible, + values, +}) => { + return ( + { + await onSubmit(formValues); + }} + > + + + + + ); +}; + +export default UpdateForm; \ No newline at end of file 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 new file mode 100644 index 00000000..64003d64 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/constants.ts @@ -0,0 +1,31 @@ +// 抽离常量配置 +export const ORDER_STATUS = { + UNPAID: 0, + PAID_QUEUING: 1, + CANCELLED: 2, + COMPLETED: 3, + SERVING: 4, + UPLOADING: 5, + UPLOAD_COMPLETED: 6, + REFUNDING: 7, + REFUNDED: 8, + REFUND_FAILED: 9, +} 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: '退款失败' }, +} as const; + +export const STATUS_OPTIONS = Object.entries(STATUS_CONFIG).map(([value, config]) => ({ + label: config.text, + value: Number(value), +})); \ No newline at end of file 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 7cfee2d2..99439075 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 @@ -1,113 +1,153 @@ -import { order } from '@/services/orders/api'; +import { order, updateOrder } from '@/services/orders/api'; import type { ActionType, ProColumns } from '@ant-design/pro-components'; import { PageContainer, ProFormText, ProTable, QueryFilter, + ProFormSelect, } from '@ant-design/pro-components'; -import { Typography, Popconfirm, Tag } from 'antd'; -import React, { useRef, useState } from 'react'; +import { Typography, Space, Tag, message } from 'antd'; +import React, { useRef, useState, useCallback } from 'react'; +import { STATUS_CONFIG, STATUS_OPTIONS } from './constants'; +import UpdateForm from './components/UpdateForm'; const { Link } = Typography; -// const handleDelete = async (deletefile: FILES.File) => { -// const hide = message.loading('正在删除'); -// try { -// const result = await deleteFile(deletefile.id); -// hide(); -// if (result.resp_code === 0) { -// message.success('删除File成功'); -// return true; -// } else { -// message.error(result.resp_msg); -// return false; -// } -// } catch (error) { -// hide(); -// message.error('删除File失败'); -// return false; -// } -// }; - -const statusColorMap = { - 0: { color: 'yellow', text: '待支付' }, - 1: { color: 'orange', text: '已支付排队中' }, - 2: { color: 'gray', text: '已取消' }, - 3: { color: 'red', text: '设备执行完成' }, - 4: { color: 'lightblue', text: '正在服务中' }, - 5: { color: 'pink', text: '素材上传中' }, - 6: { color: 'green', text: '素材上传完成' }, - 7: { color: 'darkgray', text: '退款中' }, - 8: { color: 'cyan', text: '已退款' }, - 9: { color: 'purple', text: '退款失败' } -}; - -// 渲染状态标签 -const renderStatus = (status: {} | null | undefined) => { - const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' }; - return {statusInfo.text}; -}; - const TableList: React.FC = () => { const actionRef = useRef(); - const [params, setParams] = useState>({ }); + const [params, setParams] = useState>({}); + const [updateModalVisible, setUpdateModalVisible] = useState(false); + const [currentRow, setCurrentRow] = useState(); + + // 渲染状态标签 + const renderStatus = useCallback((status: number) => { + const statusInfo = STATUS_CONFIG[status] || { color: 'gray', text: '未知状态' }; + return {statusInfo.text}; + }, []); + + // 处理修改操作 + const handleEdit = useCallback(async (fields: { orderStatus: number }) => { + const hide = message.loading('正在更新'); + try { + if (!currentRow) return false; + + const result = await updateOrder({ + id: currentRow.id, + orderStatus: fields.orderStatus, + }); + + hide(); + if (result.resp_code === 0) { + message.success('修改成功'); + return true; + } + message.error(result.resp_msg); + return false; + } catch (error) { + hide(); + message.error('修改失败,请重试'); + return false; + } + }, [currentRow]); + const columns: ProColumns[] = [ { dataIndex: 'index', valueType: 'indexBorder', + width: 48, }, { title: '订单ID', dataIndex: 'id', + copyable: true, + width: 180, }, { title: '订单编号', dataIndex: 'orderNo', + copyable: true, + ellipsis: true, + }, + { + title: '二维码ID', + dataIndex: 'codeId', + copyable: true, + ellipsis: true, + }, + { + title: '设备编号', + dataIndex: 'deviceSn', + copyable: true, + ellipsis: true, }, { title: '状态', dataIndex: 'orderStatus', - render: (status) => renderStatus(status), + render: (status) => renderStatus(status as number), + width: 120, + filters: STATUS_OPTIONS, + filterMultiple: false, }, { title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', + width: 180, + sorter: true, + }, + { + title: '支付时间', + dataIndex: 'payTime', + valueType: 'dateTime', + width: 180, + sorter: true, }, { title: '操作', key: 'action', - render: (_, entity) => { - // const success = await handleDelete(entity); - // if (success) { - // if (actionRef.current) { - // actionRef.current.reload(); - // } - // } - }} - > - 删除 - , + width: 80, + render: (_, record) => ( + + { + setCurrentRow(record); + setUpdateModalVisible(true); + }} + > + 修改状态 + + + ), }, ]; return ( - + setParams(values)} > - + + + rowKey="id" - headerTitle="任务列表" + headerTitle="订单列表" request={order} actionRef={actionRef} columns={columns} @@ -116,7 +156,27 @@ const TableList: React.FC = () => { pagination={{ showSizeChanger: true, showQuickJumper: true, + defaultPageSize: 10, + pageSizeOptions: ['10', '20', '50'], }} + dateFormatter="string" + toolbar={{ + actions: [], + }} + /> + + { + const success = await handleEdit(values); + if (success) { + setUpdateModalVisible(false); + setCurrentRow(undefined); + actionRef.current?.reload(); + } + }} + onVisibleChange={setUpdateModalVisible} + updateModalVisible={updateModalVisible} + values={currentRow} /> ); 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 bad86a1e..19e5aea3 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,65 +1,125 @@ +import { wayline } from '@/services/device/api'; import { ModalForm, ProForm, + ProFormSelect, ProFormText, } from '@ant-design/pro-components'; -import { Form } from 'antd'; - -export type FormValueType = Partial; +import { message } from 'antd'; +import React, { useState, useEffect } from 'react'; +import { TOURISM_OPTIONS, DEVICE_OPTIONS, STATUS_OPTIONS } from '../index'; export type UpdateFormProps = { - onVisibleChange: (flag: boolean) => void; - onSubmit: (values: FormValueType) => Promise; + onSubmit: (values: Partial) => Promise; + onVisibleChange: (visible: boolean) => void; updateModalVisible: boolean; - values?: ORDERS.Tourism; + values?: ORDERS.Qrcode; }; const UpdateForm: React.FC = (props) => { - const [form] = Form.useForm(); + 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]); + 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); + }} > - { + // 可以在这里处理航线选择后的联动逻辑 + console.log('选择的航线:', option); + } + }} + /> + - + diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/index.tsx index 2e420a2a..9bf4ab66 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/index.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/index.tsx @@ -11,66 +11,77 @@ import { QueryFilter, } from '@ant-design/pro-components'; import { Typography, Popconfirm, Space, message, Image, Button, Tag } from 'antd'; -import React, { useRef, useState } from 'react'; +import React, { useRef, useState, useCallback, useEffect } from 'react'; import UpdateForm from './components/UpdateForm'; +import { wayline } from '@/services/device/api'; const { Link } = Typography; -const handleAdd = async (fields: ORDERS.Qrcode) => { - const hide = message.loading('正在添加'); +export const STATUS_OPTIONS = [ + { label: '启用', value: 0 }, + { label: '未启用', value: 1 }, +] as const; + +export const TOURISM_OPTIONS = [ + { label: '北塘古镇', value: 33 }, + { label: '海丝首港', value: 32 }, + { label: '武汉东湖牡丹园', value: 35 }, + { label: '武汉东湖樱花园', value: 36 }, +] as const; + +export const DEVICE_OPTIONS = [ + { label: '7CTDM6F00B744S', value: '7CTDM6F00B744S' }, + { label: '8UUXN2A00A00LR', value: '8UUXN2A00A00LR' }, + { label: '5YSZMBS0030BJ8', value: '5YSZMBS0030BJ8' }, +] as const; + +const handleApiRequest = async ( + apiCall: () => Promise, + loadingMessage: string, + successMessage: string, +) => { + const hide = message.loading(loadingMessage); try { - const result = await saveOrUpdateQrcode({ ...fields }); + const result = await apiCall(); hide(); if (result.resp_code === 0) { - message.success('添加成功'); + message.success(successMessage); return true; - } else { - message.error(result.resp_msg); - return false; } + message.error(result.resp_msg); + return false; } catch (error) { hide(); - message.error('添加失败'); + message.error(`${successMessage}失败`); return false; } }; -const handleEdit = async (fields: ORDERS.Qrcode) => { - const hide = message.loading('正在更新'); - try { - const result = await saveOrUpdateQrcode({ ...fields }); - hide(); - if (result.resp_code === 0) { - message.success('修改成功'); - return true; - } else { - message.error(result.resp_msg); - return false; - } - } catch (error) { - hide(); - message.error('修改失败'); - return false; - } +const handleAdd = async (fields: ORDERS.Qrcode) => { + return handleApiRequest( + () => saveOrUpdateQrcode({ ...fields }), + '正在添加', + '添加成功' + ); +}; + +const handleEdit = async (original: ORDERS.Qrcode, fields: Partial) => { + return handleApiRequest( + () => saveOrUpdateQrcode({ + id: original.id, // 保留原始ID + ...fields // 只包含修改的字段 + }), + '正在更新', + '修改成功' + ); }; const handleDelete = async (qrcode: ORDERS.Qrcode) => { - const hide = message.loading('正在删除'); - try { - const result = await deleteQrcode(qrcode.id); - hide(); - if (result.resp_code === 0) { - message.success('删除成功'); - return true; - } else { - message.error(result.resp_msg); - return false; - } - } catch (error) { - hide(); - message.error('删除失败'); - return false; - } + return handleApiRequest( + () => deleteQrcode(qrcode.id), + '正在删除', + '删除成功' + ); }; // 状态颜色映射 @@ -93,6 +104,67 @@ const TableList: React.FC = () => { const [createModalVisible, handleModalVisible] = useState(false); const [updateModalVisible, handleUpdateModalVisible] = useState(false); const [currentRow, setCurrentRow] = useState(); + const [waylineOptions, setWaylineOptions] = useState([]); + const formRef = useRef(); + + const handleTableAction = useCallback(async ( + action: 'add' | 'edit' | 'delete', + record?: ORDERS.Qrcode, + values?: Partial + ) => { + let success = false; + switch (action) { + case 'add': + success = await handleAdd(values as ORDERS.Qrcode); + success && handleModalVisible(false); + break; + case 'edit': + if (record) { + success = await handleEdit(record, values || {}); + if (success) { + handleUpdateModalVisible(false); + setCurrentRow(undefined); + } + } + break; + case 'delete': + success = await handleDelete(record!); + break; + } + if (success && actionRef.current) { + actionRef.current.reload(); + } + }, []); + + const fetchWaylineOptions = async () => { + console.log('Fetching wayline options...'); + try { + const result = await wayline({ current: 1, pageSize: 100 }); + console.log('Wayline result:', result); + 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(() => { + console.log('Modal visible changed:', updateModalVisible); + if (updateModalVisible) { + fetchWaylineOptions(); + } + }, [updateModalVisible]); + + useEffect(() => { + console.log('Current wayline options:', waylineOptions); + }, [waylineOptions]); + const columns: ProColumns[] = [ { dataIndex: 'index', @@ -140,7 +212,10 @@ const TableList: React.FC = () => { { - setCurrentRow(entity); + setCurrentRow({ + ...entity, + waylineId: entity.waylineId, + }); handleUpdateModalVisible(true); }} > @@ -149,12 +224,7 @@ const TableList: React.FC = () => { { - const success = await handleDelete(entity); - if (success) { - if (actionRef.current) { - actionRef.current.reload(); - } - } + const success = await handleTableAction('delete', entity); }} > 删除 @@ -201,88 +271,66 @@ const TableList: React.FC = () => { /> { - - const success = await handleAdd(values); - if (success) { - handleModalVisible(false); - if (actionRef.current) { - actionRef.current.reload(); - } - } - }} + onFinish={async (values) => handleTableAction('add', undefined, values)} > - - - + + + + + { - if (currentRow) { - - const success = await handleEdit({ ...currentRow, ...values }); - if (success) { - handleUpdateModalVisible(false); - if (actionRef.current) { - actionRef.current.reload(); - } - } + console.log('提交的修改值:', values); + return handleTableAction('edit', currentRow, values); + }} + onVisibleChange={(visible) => { + console.log('修改弹窗可见性变化:', visible); + handleUpdateModalVisible(visible); + if (!visible) { setCurrentRow(undefined); } }} - onVisibleChange={handleUpdateModalVisible} updateModalVisible={updateModalVisible} values={currentRow} /> diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/constants.ts b/zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/constants.ts new file mode 100644 index 00000000..1293cce1 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/constants.ts @@ -0,0 +1,12 @@ +// 将常量配置提取到单独文件 +export const STATUS_CONFIG = { + 7: { color: 'yellow', text: '退款申请中' }, + 8: { color: 'green', text: '已退款' }, + 9: { color: 'red', text: '退款失败' }, +} as const; + +export const STATE_CONFIG = { + 0: { color: 'yellow', text: '待审核' }, + 1: { color: 'green', text: '已通过' }, + 2: { color: 'red', text: '已拒绝' }, +} as const; \ No newline at end of file diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/index.tsx index 5a5020b3..740aed44 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/index.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/index.tsx @@ -7,64 +7,59 @@ import { QueryFilter, } from '@ant-design/pro-components'; import { Typography, Tag, Space, message } from 'antd'; -import React, { useRef, useState } from 'react'; +import React, { useRef, useState, useCallback } from 'react'; +import { STATUS_CONFIG, STATE_CONFIG } from './constants'; import UpdateForm from './components/UpdateForm'; +import type { RefundItem } from './types'; const { Link } = Typography; -const handleEdit = async (fields: ORDERS.Refund) => { - const hide = message.loading('正在更新'); - try { - const result = await updateRefund({ ...fields }); - hide(); - if (result.resp_code === 0) { - message.success('审核成功'); - return true; - } else { - message.error(result.resp_msg); - return false; - } - } catch (error) { - hide(); - message.error('审核失败'); - return false; - } -}; - -// 状态颜色映射 -const statusColorMap = { - 7: { color: 'yellow', text: '退款申请中' }, - 8: { color: 'green', text: '已退款' }, - 9: { color: 'red', text: '退款失败' }, - -}; - -// 状态颜色映射 -const stateColorMap = { - 0: { color: 'yellow', text: '待审核' }, - 1: { color: 'green', text: '已通过' }, - 2: { color: 'red', text: '已拒绝' }, - -}; - -// 渲染状态标签 -const renderStatus = (status: {} | null | undefined) => { - const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' }; - return {statusInfo.text}; -}; - -// 渲染状态标签 -const renderState = (state: {} | null | undefined) => { - const stateInfo = stateColorMap[state] || { color: 'gray', text: '未知状态' }; - return {stateInfo.text}; +// 将渲染标签的函数移到组件外部 +const renderTag = (value: number, config: typeof STATUS_CONFIG | typeof STATE_CONFIG) => { + const info = config[value] || { color: 'gray', text: '未知状态' }; + return {info.text}; }; const TableList: React.FC = () => { + // 1. 所有 hooks 放在组件最顶部 const actionRef = useRef(); - const [params, setParams] = useState>({ }); - const [updateModalVisible, handleUpdateModalVisible] = useState(false); - const [currentRow, setCurrentRow] = useState(); - const columns: ProColumns[] = [ + const [params, setParams] = useState>({}); + const [updateModalVisible, setUpdateModalVisible] = useState(false); + const [currentRow, setCurrentRow] = useState(); + + // 2. 处理编辑的回调函数 + const handleEdit = useCallback(async (fields: RefundItem) => { + const hide = message.loading('正在更新'); + try { + const result = await updateRefund({ ...fields }); + hide(); + if (result.resp_code === 0) { + message.success('审核成功'); + return true; + } + message.error(result.resp_msg); + return false; + } catch (error) { + hide(); + message.error('审核失败'); + return false; + } + }, []); + + // 3. 处理表单提交的回调函数 + const handleSubmit = useCallback(async (values: Partial) => { + if (!currentRow) return; + + const success = await handleEdit({ ...currentRow, ...values }); + if (success) { + setUpdateModalVisible(false); + actionRef.current?.reload(); + setCurrentRow(undefined); + } + }, [currentRow, handleEdit]); + + // 4. 定义表格列 + const columns: ProColumns[] = [ { dataIndex: 'index', valueType: 'indexBorder', @@ -80,20 +75,22 @@ const TableList: React.FC = () => { { title: '订单金额', dataIndex: 'orderAmount', + valueType: 'money', }, { title: '退款金额', dataIndex: 'refundAmount', + valueType: 'money', }, { title: '订单状态', dataIndex: 'status', - render: (status) => renderStatus(status), + render: (status) => renderTag(status as number, STATUS_CONFIG), }, { title: '退款状态', dataIndex: 'state', - render: (state) => renderState(state), + render: (state) => renderTag(state as number, STATE_CONFIG), }, { title: '创建时间', @@ -103,22 +100,23 @@ const TableList: React.FC = () => { { title: '操作', key: 'action', - render: (_, entity) => + render: (_, entity) => ( { setCurrentRow(entity); - handleUpdateModalVisible(true); + setUpdateModalVisible(true); }} > 修改 + ), }, ]; return ( - + { > - + + rowKey="id" - headerTitle="任务列表" + headerTitle="退款列表" request={refund} actionRef={actionRef} columns={columns} @@ -141,24 +140,13 @@ const TableList: React.FC = () => { showQuickJumper: true, }} /> + { - if (currentRow) { - - const success = await handleEdit({ ...currentRow, ...values }); - if (success) { - handleUpdateModalVisible(false); - if (actionRef.current) { - actionRef.current.reload(); - } - } - setCurrentRow(undefined); - } - }} - onVisibleChange={handleUpdateModalVisible} - updateModalVisible={updateModalVisible} - values={currentRow} - /> + onSubmit={handleSubmit} + onVisibleChange={setUpdateModalVisible} + updateModalVisible={updateModalVisible} + values={currentRow} + /> ); }; diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/types.ts b/zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/types.ts new file mode 100644 index 00000000..20bfc0f3 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/types.ts @@ -0,0 +1,10 @@ +export interface RefundItem { + id: string; + refundNo: string; + orderAmount: number; + refundAmount: number; + status: number; + state: number; + createTime: string; + [key: string]: any; +} \ No newline at end of file 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 9452b0f8..59cb7dfe 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 @@ -3,59 +3,55 @@ import { ProForm, ProFormText, } from '@ant-design/pro-components'; -import { Form } from 'antd'; - -export type FormValueType = Partial; +import React from 'react'; export type UpdateFormProps = { - onVisibleChange: (flag: boolean) => void; - onSubmit: (values: FormValueType) => Promise; + onSubmit: (values: Partial) => Promise; + onVisibleChange: (visible: boolean) => void; updateModalVisible: boolean; values?: ORDERS.Tourism; }; const UpdateForm: React.FC = (props) => { - const [form] = Form.useForm(); + const { onSubmit, onVisibleChange, updateModalVisible, values } = props; + 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); + }} + initialValues={values} > { - const hide = message.loading('正在添加'); +const handleApiRequest = async ( + apiCall: () => Promise, + loadingMessage: string, + successMessage: string, +) => { + const hide = message.loading(loadingMessage); try { - const result = await saveOrUpdateTourism({ ...fields }); + const result = await apiCall(); hide(); if (result.resp_code === 0) { - message.success('添加用户成功'); + message.success(successMessage); return true; - } else { - message.error(result.resp_msg); - return false; } + message.error(result.resp_msg); + return false; } catch (error) { hide(); - message.error('添加用户失败'); + message.error(`${successMessage}失败`); return false; } }; -const handleEdit = async (fields: ORDERS.Tourism) => { - const hide = message.loading('正在更新'); - try { - const result = await saveOrUpdateTourism({ ...fields }); - hide(); - if (result.resp_code === 0) { - message.success('修改景区成功'); - return true; - } else { - message.error(result.resp_msg); - return false; - } - } catch (error) { - hide(); - message.error('修改景区失败'); - 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) => { - const hide = message.loading('正在删除'); - try { - const result = await deleteTourism(tourism.id); - hide(); - if (result.resp_code === 0) { - message.success('删除景区成功'); - return true; - } else { - message.error(result.resp_msg); - return false; - } - } catch (error) { - hide(); - message.error('删除景区失败'); - return false; - } + return handleApiRequest( + () => deleteTourism(tourism.id), + '正在删除', + '删除景区成功' + ); }; const TableList: React.FC = () => { - const [params, setParams] = useState>({}); + // 1. 先定义所有的 hooks const actionRef = useRef(); + const [params, setParams] = useState>({}); const [createModalVisible, handleModalVisible] = useState(false); const [updateModalVisible, handleUpdateModalVisible] = 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); + } + } + break; + case 'delete': + success = await handleDelete(record!); + break; + } + if (success && actionRef.current) { + actionRef.current.reload(); + } + }, []); // 添加依赖数组 + const columns: ProColumns[] = [ { dataIndex: 'index', @@ -126,18 +151,11 @@ const TableList: React.FC = () => { { - const success = await handleDelete(entity); - if (success) { - if (actionRef.current) { - actionRef.current.reload(); - } - } - }} + onConfirm={() => handleTableAction('delete', entity)} > 删除 - + }, ]; @@ -179,20 +197,10 @@ const TableList: React.FC = () => { /> { - - const success = await handleAdd(values); - if (success) { - handleModalVisible(false); - if (actionRef.current) { - actionRef.current.reload(); - } - } - }} + onFinish={(values) => handleTableAction('add', undefined, values)} > { { - if (currentRow) { - - const success = await handleEdit({ ...currentRow, ...values }); - if (success) { - handleUpdateModalVisible(false); - if (actionRef.current) { - actionRef.current.reload(); - } - } - setCurrentRow(undefined); - } - }} + onSubmit={(values) => handleTableAction('edit', currentRow, values)} onVisibleChange={handleUpdateModalVisible} updateModalVisible={updateModalVisible} values={currentRow} 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 5b7e15b7..0ee4963f 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 @@ -6,115 +6,124 @@ import { ProFormSelect, ProFormText, } from '@ant-design/pro-components'; -import { Button, Form, message, Upload } from 'antd'; -import { RcFile } from 'antd/lib/upload'; -import { useState } from 'react'; +import { Button, Upload, Image, message } from 'antd'; +import type { RcFile } from 'antd/lib/upload'; +import React, { useState } from 'react'; +import { TOURISM_OPTIONS, TYPE_OPTIONS } from '../constants'; import styles from '../index.less'; -export type FormValueType = Partial; - -export type UpdateFormProps = { - onVisibleChange: (flag: boolean) => void; - onSubmit: (values: FormValueType) => Promise; +interface UpdateFormProps { + onSubmit: (values: Partial) => Promise; + onVisibleChange: (visible: boolean) => void; updateModalVisible: boolean; - values?: ORDERS.Tourism; -}; + values?: ORDERS.TourismFile; + tourismOptions: { label: string; value: number; }[]; +} + +const UpdateForm: React.FC = ({ + onSubmit, + onVisibleChange, + updateModalVisible, + values, + tourismOptions, +}) => { + const [imageUrl, setImageUrl] = useState(values?.imageUrl || ''); + + 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 handleImport = async (file: RcFile) => { - const hide = message.loading('正在导入'); - try { - const formData = new FormData(); - formData.append('file', file); - const result = await importImage(formData); - hide(); - message.success('上传素材成功'); - return result; - } catch (error) { - hide(); - message.error('上传素材失败'); - return null; - } -}; -const UpdateForm: React.FC = (props) => { - const [form] = Form.useForm(); - const [file, setFile] = useState(); return ( { + const submitData = { + ...formValues, + imageUrl: imageUrl || values?.imageUrl, + }; + await onSubmit(submitData); + }} > - - - - - { - const result = await handleImport(file); - if (result && result.name) { - setFile(result.name); - } - return false; - }} - > -
- + + + + + + +
+ {imageUrl || values?.imageUrl ? ( + + ) : null} + + +
- ); diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/constants.ts b/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/constants.ts new file mode 100644 index 00000000..0519ecba --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/constants.ts @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/index.less b/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/index.less index 8d289828..7ed5980a 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/index.less +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/index.less @@ -1 +1,15 @@ @import (reference) '~antd/es/style/themes/index'; + +.imageUpload { + width: 100%; + margin-top: 16px; + + .preview { + display: block; + margin-bottom: 8px; + } +} + +.button_view { + margin-top: 16px; +} diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/index.tsx index 86f2b3ce..470f6a65 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/index.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/index.tsx @@ -1,4 +1,4 @@ -import {deleteTourismFile, saveOrUpdateTourismFile, tourismFile } from '@/services/orders/api'; +import { deleteTourismFile, saveOrUpdateTourismFile, tourismFile, tourism } from '@/services/orders/api'; import { importImage } from '@/services/system/api'; import { PlusOutlined, UploadOutlined } from '@ant-design/icons'; import type { ActionType, ProColumns } from '@ant-design/pro-components'; @@ -11,102 +11,28 @@ import { ProTable, QueryFilter, } from '@ant-design/pro-components'; -import { Typography, Popconfirm, Space, message, Image, Button, Tag } from 'antd'; -import React, { useRef, useState } from 'react'; +import { Typography, Popconfirm, Space, message, Image, Button, Tag, Upload } from 'antd'; +import type { RcFile } from 'antd/lib/upload'; +import React, { useRef, useState, useCallback, useEffect } from 'react'; import UpdateForm from './components/UpdateForm'; -import Upload, { RcFile } from 'antd/lib/upload'; import styles from './index.less'; const { Link } = Typography; -const handleAdd = async (fields: ORDERS.TourismFile) => { - const hide = message.loading('正在添加'); - try { - const result = await saveOrUpdateTourismFile({ ...fields }); - hide(); - if (result.resp_code === 0) { - message.success('添加成功'); - return true; - } else { - message.error(result.resp_msg); - return false; - } - } catch (error) { - hide(); - message.error('添加失败'); - return false; - } -}; +// 提取常量 +export const TYPE_OPTIONS = [ + { label: '展示大图', value: 4 }, + { label: '拍照引导图', value: 3 }, + { label: '拍照角度展示图', value: 2 }, + { label: '活动', value: 1 }, +] as const; -const handleEdit = async (fields: ORDERS.TourismFile) => { - const hide = message.loading('正在更新'); - try { - const result = await saveOrUpdateTourismFile({ ...fields }); - hide(); - if (result.resp_code === 0) { - message.success('修改成功'); - return true; - } else { - message.error(result.resp_msg); - return false; - } - } catch (error) { - hide(); - message.error('修改失败'); - return false; - } -}; - -const handleDelete = async (qrcode: ORDERS.TourismFile) => { - const hide = message.loading('正在删除'); - try { - const result = await deleteTourismFile(qrcode.id); - hide(); - if (result.resp_code === 0) { - message.success('删除成功'); - return true; - } else { - message.error(result.resp_msg); - return false; - } - } catch (error) { - hide(); - message.error('删除失败'); - return false; - } -}; - -const handleImport = async (file: RcFile) => { - const hide = message.loading('正在导入'); - try { - const formData = new FormData(); - formData.append('file', file); - const result = await importImage(formData); - hide(); - message.success('上传素材成功'); - return result; - } catch (error) { - hide(); - message.error('上传素材失败'); - return null; - } -}; - -// 状态颜色映射 +// 状态映射 const statusColorMap = { 0: { color: 'green', text: '启用' }, 1: { color: 'red', text: '未启用' }, - - }; -// 渲染状态标签 -const renderStatus = (status: {} | null | undefined) => { - const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' }; - return {statusInfo.text}; -}; - -// 状态颜色映射 const typeColorMap = { 0: { color: 'yellow', text: '待审核' }, 1: { color: 'green', text: '活动' }, @@ -115,31 +41,151 @@ const typeColorMap = { 4: { color: 'green', 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.TourismFile) => { + return handleApiRequest( + () => saveOrUpdateTourismFile({ ...fields }), + '正在添加', + '添加成功' + ); +}; + +const handleEdit = async (original: ORDERS.TourismFile, fields: Partial) => { + return handleApiRequest( + () => saveOrUpdateTourismFile({ + id: original.id, + ...fields + }), + '正在更新', + '修改成功' + ); +}; + +const handleDelete = async (tourismFile: ORDERS.TourismFile) => { + return handleApiRequest( + () => deleteTourismFile(tourismFile.id), + '正在删除', + '删除成功' + ); +}; + +const handleImport = async (file: RcFile) => { + return handleApiRequest( + async () => { + const formData = new FormData(); + formData.append('file', file); + return await importImage(formData); + }, + '正在上传', + '上传素材成功' + ); +}; + +// 渲染函数 +const renderStatus = (status: {} | null | undefined) => { + const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' }; + return {statusInfo.text}; +}; + const renderType = (type: {} | null | undefined) => { const typeInfo = typeColorMap[type] || { color: 'gray', text: '未知状态' }; return {typeInfo.text}; }; - const TableList: React.FC = () => { const actionRef = useRef(); - const [params, setParams] = useState>({ }); + const [params, setParams] = useState>({}); const [createModalVisible, handleModalVisible] = useState(false); const [updateModalVisible, handleUpdateModalVisible] = useState(false); const [currentRow, setCurrentRow] = useState(); - const [file, setFile] = useState(); - // const setImage = (imageUrl: string) => { - // setFile({ ...file, imageUrl}); - // } + const [file, setFile] = useState(); + const [tourismOptions, setTourismOptions] = useState<{ label: string; value: number; }[]>([]); + + // 获取景区列表 + const fetchTourismList = useCallback(async () => { + try { + const result = await tourism({ + pageSize: 100, + current: 1, + }); + if (result.resp_code === 0 && result.data) { + const options = result.data.records?.map(item => ({ + label: item.name, + value: item.id, + })) || []; + setTourismOptions(options); + } + } catch (error) { + message.error('获取景区列表失败'); + } + }, []); + + // 在组件挂载时获取景区列表 + useEffect(() => { + fetchTourismList(); + }, [fetchTourismList]); + + const handleTableAction = useCallback(async ( + action: 'add' | 'edit' | 'delete', + record?: ORDERS.TourismFile, + values?: Partial + ) => { + let success = false; + switch (action) { + case 'add': + success = await handleAdd({ ...values, imageUrl: file } as ORDERS.TourismFile); + success && handleModalVisible(false); + break; + case 'edit': + if (record) { + success = await handleEdit(record, values || {}); + if (success) { + handleUpdateModalVisible(false); + setCurrentRow(undefined); + } + } + break; + case 'delete': + success = await handleDelete(record!); + break; + } + if (success && actionRef.current) { + actionRef.current.reload(); + } + }, [file]); + const columns: ProColumns[] = [ { dataIndex: 'index', valueType: 'indexBorder', }, { - title: '景区ID', + title: '景区名称', dataIndex: 'tourismId', + ellipsis: true, }, { title: '素材', @@ -185,7 +231,7 @@ const TableList: React.FC = () => { { - const success = await handleDelete(entity); + const success = await handleTableAction('delete', entity); if (success) { if (actionRef.current) { actionRef.current.reload(); @@ -200,7 +246,7 @@ const TableList: React.FC = () => { ]; return ( - + { > - + rowKey="id" headerTitle="素材列表" request={tourismFile} @@ -237,112 +283,72 @@ const TableList: React.FC = () => { /> { - - values.imageUrl = file - const success = await handleAdd(values); - if (success) { - handleModalVisible(false); - if (actionRef.current) { - actionRef.current.reload(); - } - } - }} + onFinish={(values) => handleTableAction('add', undefined, values)} > - - + + + + + { + const result = await handleImport(file); + if (result && result.name) { + setFile(result.name); + } + return false; + }} + > +
+ +
+
+
+
+ handleTableAction('edit', currentRow, values)} + onVisibleChange={handleUpdateModalVisible} + updateModalVisible={updateModalVisible} + values={currentRow} + tourismOptions={tourismOptions} /> - - - - { - const result = await handleImport(file); - if (result && result.name) { - setFile(result.name); - } - return false; - }} - > -
- -
-
- - - { - if (currentRow) { - - const success = await handleEdit({ ...currentRow, ...values }); - if (success) { - handleUpdateModalVisible(false); - if (actionRef.current) { - actionRef.current.reload(); - } - } - setCurrentRow(undefined); - } - }} - onVisibleChange={handleUpdateModalVisible} - updateModalVisible={updateModalVisible} - values={currentRow} - />
); }; diff --git a/zlt-web/react-web/src/main/frontend/src/services/device/api.ts b/zlt-web/react-web/src/main/frontend/src/services/device/api.ts new file mode 100644 index 00000000..5769b975 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/services/device/api.ts @@ -0,0 +1,32 @@ +// @ts-ignore +/* eslint-disable */ +import { request } from 'umi'; + + +export async function wayline(params?: { [key: string]: string | number }) { + const { current, pageSize, ...rest } = params ?? {}; + const result = await request>('/api-device/wayline', { + method: 'GET', + params: { page: current, limit: pageSize, ...rest }, + }); + return { data: result.data, total: result.count }; +} + +export async function saveOrUpdateWayline(data: ORDERS.Tourism): Promise> { + const result = await request>('/api-device/wayline', { + method: 'POST', + data, + }); + return result; +} + +export async function deleteWayline(id: number) { + const url = `/api-device/wayline/${id}`; + const result = await request>(url, { + method: 'DELETE', + }); + return result; +} + + + diff --git a/zlt-web/react-web/src/main/frontend/src/services/device/index.ts b/zlt-web/react-web/src/main/frontend/src/services/device/index.ts new file mode 100644 index 00000000..7e0bd079 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/services/device/index.ts @@ -0,0 +1,8 @@ +// @ts-ignore +/* eslint-disable */ +// API 更新时间: +// API 唯一标识: +import * as api from './api'; +export default { + api, +}; diff --git a/zlt-web/react-web/src/main/frontend/src/services/device/typings.d.ts b/zlt-web/react-web/src/main/frontend/src/services/device/typings.d.ts new file mode 100644 index 00000000..26105a03 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/services/device/typings.d.ts @@ -0,0 +1,22 @@ +// @ts-ignore +/* eslint-disable */ + +declare namespace DEVICE { + + type Wayline = { + id: number; + name: string; + waylineId: string; + droneModelKey: string; + payloadModelKeys: string; + workspaceId: string; + sign: string; + favorited: string; + templateTypes: string; + userName:string; + createTime?: string; + tenantId?: string; + updateTime?: string; + } + +} \ No newline at end of file diff --git a/zlt-web/react-web/src/main/frontend/src/services/orders/api.ts b/zlt-web/react-web/src/main/frontend/src/services/orders/api.ts index ffb2155b..efd8049b 100644 --- a/zlt-web/react-web/src/main/frontend/src/services/orders/api.ts +++ b/zlt-web/react-web/src/main/frontend/src/services/orders/api.ts @@ -146,3 +146,13 @@ export async function updateRefund(data: ORDERS.Refund): Promise>('/api-order/tourism', { + method: 'GET', + params: { + pageSize: params?.pageSize || 100, + current: params?.current || 1, + }, + }); +} + diff --git a/zlt-web/react-web/src/main/frontend/src/services/orders/typings.d.ts b/zlt-web/react-web/src/main/frontend/src/services/orders/typings.d.ts index c2227041..d684e282 100644 --- a/zlt-web/react-web/src/main/frontend/src/services/orders/typings.d.ts +++ b/zlt-web/react-web/src/main/frontend/src/services/orders/typings.d.ts @@ -93,4 +93,18 @@ declare namespace ORDERS { tenantId?: string; updateTime?: string; } +} + +declare namespace API { + interface Tourism { + id: number; + name: string; + // ... 其他景区相关字段 + } + + interface Response { + resp_code: number; + resp_msg: string; + data: T; + } } \ No newline at end of file