Please enter the commit message for your changes. Lines starting
with '#' will be ignored, and an empty message aborts the commit. On branch develop Your branch is ahead of 'goflyapp/develop' by 2 commits. (use "git push" to publish your local commits) Changes to be committed: modified: README.md modified: pom.xml modified: zlt-business/device-center/pom.xml modified: zlt-business/device-center/src/main/java/com/central/device/controller/AgeDeviceController.java modified: zlt-business/device-center/src/main/java/com/central/device/controller/ApiDeviceController.java modified: zlt-business/device-center/src/main/java/com/central/device/controller/LineFileController.java modified: zlt-business/device-center/src/main/java/com/central/device/feign/OrderCenterService.java modified: zlt-business/device-center/src/main/java/com/central/device/feign/fallback/OrderCenterServiceFallbackFactory.java modified: zlt-business/device-center/src/main/java/com/central/device/listener/DeviceImportListener.java modified: zlt-business/device-center/src/main/java/com/central/device/model/AgeDevice.java modified: zlt-business/device-center/src/main/java/com/central/device/model/LineFile.java modified: zlt-business/device-center/src/main/java/com/central/device/model/excel/AgeDeviceExcel.java modified: zlt-business/device-center/src/main/java/com/central/device/service/IAgeDeviceService.java modified: zlt-business/device-center/src/main/java/com/central/device/service/ILineFileService.java modified: zlt-business/device-center/src/main/java/com/central/device/service/impl/AgeDeviceServiceImpl.java modified: zlt-business/device-center/src/main/java/com/central/device/service/impl/LineFileServiceImpl.java modified: zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java modified: zlt-business/file-center/src/main/java/com/central/file/service/impl/OssService.java modified: zlt-business/file-center/src/main/resources/application.yml modified: zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java modified: zlt-business/order-center/src/main/java/com/central/order/controller/QrCodeController.java modified: zlt-business/order-center/src/main/java/com/central/order/feign/DeviceCenterService.java modified: zlt-business/order-center/src/main/java/com/central/order/feign/fallback/DeviceCenterServiceFallbackFactory.java modified: zlt-business/order-center/src/main/java/com/central/order/model/Order.java modified: zlt-commons/zlt-common-core/src/main/java/com/central/common/model/FileInfo.java modified: zlt-web/react-web/src/main/frontend/config/config.ts modified: zlt-web/react-web/src/main/frontend/config/routes.ts modified: zlt-web/react-web/src/main/frontend/nginx.conf modified: zlt-web/react-web/src/main/frontend/package.json new file: zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/UpdateForm.tsx new file: zlt-web/react-web/src/main/frontend/src/pages/device/Device/index.tsx modified: zlt-web/react-web/src/main/frontend/src/pages/device/Wayline/components/UpdateForm.tsx modified: zlt-web/react-web/src/main/frontend/src/pages/device/Wayline/index.tsx deleted: zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/components/UpdateForm.tsx deleted: zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/index.less deleted: zlt-web/react-web/src/main/frontend/src/pages/device/Wayline1/index.tsx modified: zlt-web/react-web/src/main/frontend/src/pages/orders/OrderFile/index.tsx modified: zlt-web/react-web/src/main/frontend/src/services/device/api.ts modified: zlt-web/react-web/src/main/frontend/src/services/device/typings.d.ts
This commit is contained in:
@@ -71,7 +71,7 @@ export default defineConfig({
|
||||
},
|
||||
],
|
||||
nodeModulesTransform: { type: 'none' },
|
||||
mfsu: {},
|
||||
mfsu: false,
|
||||
webpack5: {},
|
||||
exportStatic: {},
|
||||
history: {
|
||||
|
||||
@@ -54,6 +54,10 @@
|
||||
path: '/device/wayline.html',
|
||||
component: './device/Wayline',
|
||||
},
|
||||
{
|
||||
path: '/device/device.html',
|
||||
component: './device/Device',
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ server {
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# 重要:确保所有路由都指向 index.html
|
||||
# 支持 history 路由
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
"@ant-design/charts": "^1.4.2",
|
||||
"@ant-design/icons": "^4.7.0",
|
||||
"@ant-design/pro-components": "1.1.1",
|
||||
"@babel/runtime": "^7.27.0",
|
||||
"@umijs/route-utils": "^2.0.0",
|
||||
"antd": "^4.20.0",
|
||||
"classnames": "^2.3.0",
|
||||
@@ -63,6 +64,7 @@
|
||||
"react-helmet-async": "^1.2.0",
|
||||
"react-intl": "6.4.4",
|
||||
"react-json-tree": "^0.17.0",
|
||||
"spark-md5": "^3.0.2",
|
||||
"treeify-js": "^1.0.8",
|
||||
"umi": "^3.5.0",
|
||||
"uuid": "^9.0.0"
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormSelect,
|
||||
ProFormText,
|
||||
ProFormTextArea,
|
||||
} from '@ant-design/pro-components';
|
||||
import React from 'react';
|
||||
|
||||
interface UpdateFormProps {
|
||||
onSubmit: (values: DEVICE.Device) => Promise<boolean>;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
updateModalVisible: boolean;
|
||||
values?: DEVICE.Device;
|
||||
}
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const { onSubmit, onVisibleChange, updateModalVisible, values } = props;
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
title="修改设备信息"
|
||||
width="800px"
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
onFinish={onSubmit}
|
||||
initialValues={values}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
disabled
|
||||
width="md"
|
||||
name="deviceSn"
|
||||
label="设备序列号"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '设备名称不能为空' }]}
|
||||
width="md"
|
||||
name="deviceName"
|
||||
label="设备名称"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="nickname"
|
||||
label="昵称"
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '工作区不能为空' }]}
|
||||
width="md"
|
||||
name="workspaceId"
|
||||
label="工作区"
|
||||
options={[
|
||||
{ label: '工作区1', value: '1' },
|
||||
{ label: '工作区2', value: '2' },
|
||||
]}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '设备类型不能为空' }]}
|
||||
width="md"
|
||||
name="deviceType"
|
||||
label="设备类型"
|
||||
options={[
|
||||
{ label: '类型1', value: 0 },
|
||||
{ label: '类型2', value: 1 },
|
||||
]}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="firmwareVersion"
|
||||
label="固件版本"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
<ProFormTextArea
|
||||
name="deviceDesc"
|
||||
label="设备描述"
|
||||
placeholder="请输入设备描述"
|
||||
/>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default UpdateForm;
|
||||
@@ -0,0 +1,394 @@
|
||||
import {
|
||||
device,
|
||||
saveOrUpdateDevice,
|
||||
deleteDevice,
|
||||
updateDeviceBoundStatus,
|
||||
} from '@/services/device/api';
|
||||
import { PlusOutlined, ExportOutlined, ImportOutlined, DownloadOutlined } from '@ant-design/icons';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
ModalForm,
|
||||
PageContainer,
|
||||
ProForm,
|
||||
ProFormText,
|
||||
ProFormSelect,
|
||||
ProFormTextArea,
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Button, message, Popconfirm, Typography, Space, Switch, Upload } from 'antd';
|
||||
import type { RcFile } from 'antd/lib/upload';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import moment from 'moment';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
// 定义常量对象而不是使用命名空间
|
||||
const DEVICE_TYPE = {
|
||||
DOCK: 1,
|
||||
DRONE: 2,
|
||||
REMOTE_CONTROL: 3,
|
||||
} as const;
|
||||
|
||||
const BOUND_STATUS = {
|
||||
UNBOUND: 0,
|
||||
BOUND: 1,
|
||||
} as const;
|
||||
|
||||
const COMPATIBLE_STATUS = {
|
||||
INCONSISTENT: 0,
|
||||
CONSISTENT: 1,
|
||||
} as const;
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const [searchParams, setSearchParams] = useState<Record<string, string | number>>({});
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [createModalVisible, setCreateModalVisible] = useState<boolean>(false);
|
||||
const [updateModalVisible, setUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<DEVICE.Device>();
|
||||
|
||||
// 统一的API请求处理函数
|
||||
const handleRequest = async (
|
||||
action: () => Promise<any>,
|
||||
loadingMessage: string,
|
||||
successMessage: string,
|
||||
) => {
|
||||
const hide = message.loading(loadingMessage);
|
||||
try {
|
||||
const result = await action();
|
||||
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 switchBoundStatus = async (record: DEVICE.Device) => {
|
||||
const success = await handleRequest(
|
||||
() => updateDeviceBoundStatus(record.deviceSn, record.boundStatus === 1 ? 0 : 1),
|
||||
'正在更新',
|
||||
'更新成功'
|
||||
);
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
};
|
||||
|
||||
// 处理导出
|
||||
const handleExport = async () => {
|
||||
const hide = message.loading('正在导出...');
|
||||
try {
|
||||
const response = await fetch('/api-device/device/export', {
|
||||
method: 'POST',
|
||||
});
|
||||
if (response.ok) {
|
||||
const blob = await response.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = `设备信息_${moment().format('YYYY-MM-DD')}.xlsx`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
window.URL.revokeObjectURL(url);
|
||||
message.success('导出成功');
|
||||
} else {
|
||||
throw new Error('导出失败');
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('导出失败');
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
};
|
||||
|
||||
// 下载模板
|
||||
const handleDownloadTemplate = () => {
|
||||
window.location.href = '/api-device/device/template';
|
||||
};
|
||||
|
||||
const columns: ProColumns<DEVICE.Device>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
},
|
||||
{
|
||||
title: '设备序列号',
|
||||
dataIndex: 'deviceSn',
|
||||
copyable: true,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
title: '设备名称',
|
||||
dataIndex: 'deviceName',
|
||||
},
|
||||
{
|
||||
title: '昵称',
|
||||
dataIndex: 'nickname',
|
||||
},
|
||||
{
|
||||
title: '设备类型',
|
||||
dataIndex: 'deviceType',
|
||||
valueType: 'select',
|
||||
valueEnum: {
|
||||
[DEVICE_TYPE.DOCK]: { text: '机场' },
|
||||
[DEVICE_TYPE.DRONE]: { text: '无人机' },
|
||||
[DEVICE_TYPE.REMOTE_CONTROL]: { text: '遥控器' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '固件版本',
|
||||
dataIndex: 'firmwareVersion',
|
||||
},
|
||||
{
|
||||
title: '固件状态',
|
||||
dataIndex: 'compatibleStatus',
|
||||
valueType: 'select',
|
||||
valueEnum: {
|
||||
[COMPATIBLE_STATUS.CONSISTENT]: { text: '一致', status: 'Success' },
|
||||
[COMPATIBLE_STATUS.INCONSISTENT]: { text: '不一致', status: 'Error' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '绑定状态',
|
||||
dataIndex: 'boundStatus',
|
||||
render: (_, record) => (
|
||||
<Switch
|
||||
checkedChildren="已绑定"
|
||||
unCheckedChildren="未绑定"
|
||||
checked={record.boundStatus === 1}
|
||||
onClick={() => switchBoundStatus(record)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '最后登录',
|
||||
dataIndex: 'loginTime',
|
||||
valueType: 'dateTime',
|
||||
render: (text) => (text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '-'),
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
render: (text) => (text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '-'),
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setCurrentRow(record);
|
||||
setUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</Link>
|
||||
<Popconfirm
|
||||
title={`确认删除设备[${record.deviceSn}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleRequest(
|
||||
() => deleteDevice(record.deviceSn),
|
||||
'正在删除',
|
||||
'删除成功'
|
||||
);
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
// 表单字段定义
|
||||
const renderModalContent = () => (
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '设备序列号不能为空' }]}
|
||||
width="md"
|
||||
name="deviceSn"
|
||||
label="设备序列号"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '设备名称不能为空' }]}
|
||||
width="md"
|
||||
name="deviceName"
|
||||
label="设备名称"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '设备昵称不能为空' }]}
|
||||
width="md"
|
||||
name="nickname"
|
||||
label="设备昵称"
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '设备类型不能为空' }]}
|
||||
width="md"
|
||||
name="deviceType"
|
||||
label="设备类型"
|
||||
options={[
|
||||
{ label: '机场', value: DEVICE_TYPE.DOCK },
|
||||
{ label: '无人机', value: DEVICE_TYPE.DRONE },
|
||||
{ label: '遥控器', value: DEVICE_TYPE.REMOTE_CONTROL },
|
||||
]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="subType"
|
||||
label="设备子类型"
|
||||
options={[
|
||||
// 根据实际需求添加子类型选项
|
||||
]}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="firmwareVersion"
|
||||
label="固件版本"
|
||||
/>
|
||||
<ProFormTextArea
|
||||
name="deviceDesc"
|
||||
label="设备描述"
|
||||
placeholder="请输入设备描述"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
);
|
||||
|
||||
return (
|
||||
<PageContainer header={{ subTitle: '管理系统中的设备' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
split
|
||||
className="query-filter"
|
||||
onFinish={async (values) => setSearchParams(values)}
|
||||
>
|
||||
<ProFormSelect
|
||||
name="searchKey"
|
||||
label="搜索"
|
||||
valueEnum={{
|
||||
deviceSn: '设备序列号',
|
||||
deviceName: '设备名称',
|
||||
nickname: '昵称',
|
||||
}}
|
||||
/>
|
||||
<ProFormText name="searchValue" />
|
||||
</QueryFilter>
|
||||
<ProTable<DEVICE.Device>
|
||||
rowKey="deviceSn"
|
||||
headerTitle="设备管理"
|
||||
actionRef={actionRef}
|
||||
request={device}
|
||||
columns={columns}
|
||||
search={false}
|
||||
params={searchParams}
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<Button
|
||||
key="template"
|
||||
onClick={handleDownloadTemplate}
|
||||
>
|
||||
<DownloadOutlined /> 下载模板
|
||||
</Button>,
|
||||
<Button
|
||||
key="export"
|
||||
onClick={handleExport}
|
||||
>
|
||||
<ExportOutlined /> 导出
|
||||
</Button>,
|
||||
<Upload
|
||||
key="import"
|
||||
name="file"
|
||||
accept=".xlsx,.xls"
|
||||
maxCount={1}
|
||||
action="/api-device/device/import"
|
||||
showUploadList={false}
|
||||
onChange={(info) => {
|
||||
if (info.file.status === 'uploading') {
|
||||
message.loading('正在导入...');
|
||||
}
|
||||
if (info.file.status === 'done') {
|
||||
if (info.file.response.resp_code === 0) {
|
||||
message.success('导入成功');
|
||||
// 刷新表格数据
|
||||
actionRef.current?.reload();
|
||||
} else {
|
||||
message.error(info.file.response.resp_msg || '导入失败');
|
||||
}
|
||||
} else if (info.file.status === 'error') {
|
||||
message.error('导入失败');
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Button>
|
||||
<ImportOutlined /> 导入
|
||||
</Button>
|
||||
</Upload>,
|
||||
<Button
|
||||
type="primary"
|
||||
key="add"
|
||||
onClick={() => setCreateModalVisible(true)}
|
||||
>
|
||||
<PlusOutlined /> 新增
|
||||
</Button>,
|
||||
]}
|
||||
/>
|
||||
<ModalForm
|
||||
title="新增设备"
|
||||
width="800px"
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={setCreateModalVisible}
|
||||
onFinish={async (values) => {
|
||||
const success = await handleRequest(
|
||||
() => saveOrUpdateDevice(values as DEVICE.Device),
|
||||
'正在添加',
|
||||
'添加成功',
|
||||
);
|
||||
if (success) {
|
||||
setCreateModalVisible(false);
|
||||
actionRef.current?.reload();
|
||||
}
|
||||
return success;
|
||||
}}
|
||||
>
|
||||
{renderModalContent()}
|
||||
</ModalForm>
|
||||
<UpdateForm
|
||||
onSubmit={async (values) => {
|
||||
const success = await handleRequest(
|
||||
() => saveOrUpdateDevice({ ...currentRow, ...values }),
|
||||
'正在更新',
|
||||
'更新成功',
|
||||
);
|
||||
if (success) {
|
||||
setUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
actionRef.current?.reload();
|
||||
}
|
||||
return success;
|
||||
}}
|
||||
onVisibleChange={setUpdateModalVisible}
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default TableList;
|
||||
+116
-56
@@ -8,9 +8,10 @@ import {
|
||||
} from '@ant-design/pro-components';
|
||||
import { Button, Form, message, Upload } from 'antd';
|
||||
import { RcFile } from 'antd/lib/upload';
|
||||
import { useState } from 'react';
|
||||
import { useState, useRef, useEffect } from 'react';
|
||||
import styles from '../index.less';
|
||||
import { TOURISM_OPTIONS, TYPE_OPTIONS, WORKSPACE_OPTIONS } from '../index';
|
||||
import SparkMD5 from 'spark-md5';
|
||||
|
||||
export type FormValueType = Partial<ORDERS.TourismFile>;
|
||||
|
||||
@@ -22,97 +23,156 @@ export type UpdateFormProps = {
|
||||
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 calculateFileMD5 = (file: File): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
const spark = new SparkMD5.ArrayBuffer();
|
||||
|
||||
reader.onload = (e) => {
|
||||
if (e.target?.result) {
|
||||
spark.append(e.target.result as ArrayBuffer);
|
||||
const md5 = spark.end();
|
||||
resolve(md5);
|
||||
} else {
|
||||
reject(new Error('Failed to read file'));
|
||||
}
|
||||
};
|
||||
|
||||
reader.onerror = (error) => reject(error);
|
||||
reader.readAsArrayBuffer(file);
|
||||
});
|
||||
};
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const { onSubmit, onVisibleChange, updateModalVisible, values, onUpload } = props;
|
||||
const [hasNewFile, setHasNewFile] = useState(false);
|
||||
const [fileInfo, setFileInfo] = useState<FileResponse | undefined>();
|
||||
const formRef = useRef<any>();
|
||||
|
||||
// 确保所有的hooks都在组件顶层
|
||||
useEffect(() => {
|
||||
if (values) {
|
||||
formRef.current?.setFieldsValue(values);
|
||||
}
|
||||
}, [values]);
|
||||
|
||||
const handleFileUpload = async (file: RcFile) => {
|
||||
const hide = message.loading('正在上传文件...');
|
||||
try {
|
||||
const sign = await calculateFileMD5(file);
|
||||
console.log('新文件签名:', sign);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('sign', sign);
|
||||
|
||||
const result = await importImage(formData);
|
||||
console.log('上传接口返回结果:', result);
|
||||
|
||||
if (!result || !result.id) {
|
||||
hide();
|
||||
message.error('上传失败:未获取到文件信息');
|
||||
return false;
|
||||
}
|
||||
|
||||
const newFileInfo = {
|
||||
id: result.id,
|
||||
name: result.name || file.name,
|
||||
url: result.url || '',
|
||||
sign: sign
|
||||
};
|
||||
|
||||
setFileInfo(newFileInfo);
|
||||
formRef.current?.setFieldsValue({
|
||||
waylineId: newFileInfo.id,
|
||||
name: newFileInfo.name,
|
||||
sign: newFileInfo.sign
|
||||
});
|
||||
|
||||
onUpload?.(newFileInfo);
|
||||
|
||||
hide();
|
||||
message.success('文件上传成功');
|
||||
return false;
|
||||
} catch (error: any) {
|
||||
hide();
|
||||
console.error('文件上传错误:', error);
|
||||
message.error('文件上传失败:' + (error?.message || '未知错误'));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
title="修改航线"
|
||||
formRef={formRef}
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={(visible) => {
|
||||
onVisibleChange(visible);
|
||||
onVisibleChange?.(visible);
|
||||
if (!visible) {
|
||||
setHasNewFile(false);
|
||||
setFileInfo(undefined);
|
||||
}
|
||||
}}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={async (formValues) => {
|
||||
// 只提交已修改的字段
|
||||
const changedValues: Partial<DEVICE.Wayline> = {};
|
||||
Object.keys(formValues).forEach(key => {
|
||||
if (formValues[key] !== values?.[key]) {
|
||||
changedValues[key] = formValues[key];
|
||||
}
|
||||
});
|
||||
|
||||
if (Object.keys(changedValues).length === 0 && !hasNewFile) {
|
||||
return true;
|
||||
onFinish={async (values) => {
|
||||
if (onSubmit) {
|
||||
const updatedValues = {
|
||||
...values,
|
||||
...(fileInfo ? {
|
||||
waylineId: fileInfo.id,
|
||||
sign: fileInfo.sign
|
||||
} : {})
|
||||
};
|
||||
return onSubmit(updatedValues);
|
||||
}
|
||||
|
||||
await onSubmit(changedValues);
|
||||
return false;
|
||||
}}
|
||||
initialValues={values}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '航线名称不能为空' }]}
|
||||
width="md"
|
||||
name="name"
|
||||
label="航线名称"
|
||||
placeholder="请输入航线名称"
|
||||
rules={[{ required: true, message: '航线名称不能为空' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '工作区不能为空' }]}
|
||||
width="md"
|
||||
name="workspaceId"
|
||||
label="工作区"
|
||||
placeholder="请选择工作区"
|
||||
options={WORKSPACE_OPTIONS}
|
||||
rules={[{ required: true, message: '工作区不能为空' }]}
|
||||
/>
|
||||
|
||||
<div style={{ width: '328px' }}>
|
||||
<ProFormText
|
||||
hidden
|
||||
name="waylineId"
|
||||
/>
|
||||
<ProFormText
|
||||
hidden
|
||||
name="sign"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<div style={{ width: '328px', marginBottom: 24 }}>
|
||||
<div style={{ marginBottom: 8 }}>航线文件:</div>
|
||||
{values?.fileUrl && !hasNewFile && (
|
||||
<div style={{ marginBottom: 8 }}>
|
||||
当前文件:{values.name}
|
||||
</div>
|
||||
)}
|
||||
<Upload
|
||||
maxCount={1}
|
||||
action="/api-file/files-anon"
|
||||
accept=".kmz,.kml"
|
||||
showUploadList={false}
|
||||
beforeUpload={async (file) => {
|
||||
const result = await handleImport(file);
|
||||
if (result) {
|
||||
onUpload(result);
|
||||
setHasNewFile(true);
|
||||
message.success('文件上传成功');
|
||||
}
|
||||
return false;
|
||||
}}
|
||||
beforeUpload={handleFileUpload}
|
||||
>
|
||||
<Button icon={<UploadOutlined />}>
|
||||
{hasNewFile ? '重新上传' : '上传文件'}
|
||||
重新上传航线文件
|
||||
</Button>
|
||||
</Upload>
|
||||
{hasNewFile && <div style={{ marginTop: 8, color: '#52c41a' }}>已上传新文件</div>}
|
||||
{fileInfo && (
|
||||
<div style={{ marginTop: 8 }}>
|
||||
<div style={{ color: '#52c41a' }}>
|
||||
已上传:{fileInfo.name}
|
||||
</div>
|
||||
<div style={{ color: '#666', fontSize: '12px' }}>
|
||||
文件签名:{fileInfo.sign}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
|
||||
@@ -16,6 +16,8 @@ import type { RcFile } from 'antd/lib/upload';
|
||||
import React, { useRef, useState, useCallback } from 'react';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
import styles from './index.less';
|
||||
import SparkMD5 from 'spark-md5';
|
||||
import { DefaultOptionType } from 'antd/es/select';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
@@ -26,11 +28,11 @@ const statusColorMap = {
|
||||
};
|
||||
|
||||
// 提取常量
|
||||
export const WORKSPACE_OPTIONS = [
|
||||
{ label: '工作区1', value: 1 },
|
||||
{ label: '工作区2', value: 2 },
|
||||
const WORKSPACE_OPTIONS: DefaultOptionType[] = [
|
||||
{ label: '工作区1', value: '1' },
|
||||
{ label: '工作区2', value: '2' },
|
||||
// ... 根据实际需求添加更多选项
|
||||
] as const;
|
||||
];
|
||||
|
||||
// 统一错误处理
|
||||
const handleApiRequest = async (
|
||||
@@ -83,34 +85,40 @@ const handleDelete = async (tourismFile: DEVICE.Wayline) => {
|
||||
);
|
||||
};
|
||||
|
||||
const handleImport = async (file: RcFile) => {
|
||||
return handleApiRequest(
|
||||
async () => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return await importImage(formData);
|
||||
},
|
||||
'正在上传',
|
||||
'上传素材成功'
|
||||
);
|
||||
const calculateFileMD5 = (file: File): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
const spark = new SparkMD5.ArrayBuffer();
|
||||
|
||||
reader.onload = (e) => {
|
||||
if (e.target?.result) {
|
||||
spark.append(e.target.result as ArrayBuffer);
|
||||
const md5 = spark.end();
|
||||
resolve(md5);
|
||||
} else {
|
||||
reject(new Error('Failed to read file'));
|
||||
}
|
||||
};
|
||||
|
||||
reader.onerror = (error) => reject(error);
|
||||
reader.readAsArrayBuffer(file);
|
||||
});
|
||||
};
|
||||
|
||||
// 渲染函数
|
||||
const renderStatus = (status: {} | null | undefined) => {
|
||||
const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
|
||||
};
|
||||
|
||||
const renderType = (type: {} | null | undefined) => {
|
||||
const typeInfo = typeColorMap[type] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={typeInfo.color}>{typeInfo.text}</Tag>;
|
||||
const checkSignExists = async (sign: string) => {
|
||||
const response = await fetch(`/api/wayline/check-sign?sign=${sign}`);
|
||||
return response.json();
|
||||
};
|
||||
|
||||
interface FileResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
url: string;
|
||||
// ... 其他字段
|
||||
sign?: string;
|
||||
}
|
||||
|
||||
interface ExtendedWayline extends DEVICE.Wayline {
|
||||
fileUrl?: string;
|
||||
}
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
@@ -118,48 +126,82 @@ const TableList: React.FC = () => {
|
||||
const [params, setParams] = useState<Record<string, string | number>>({});
|
||||
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
|
||||
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<DEVICE.Wayline>();
|
||||
const [currentRow, setCurrentRow] = useState<ExtendedWayline>();
|
||||
const [fileInfo, setFileInfo] = useState<FileResponse>();
|
||||
const formRef = useRef();
|
||||
const formRef = useRef<any>();
|
||||
|
||||
const handleFileUpload = async (file: RcFile) => {
|
||||
const hide = message.loading('正在上传文件...');
|
||||
try {
|
||||
const sign = await calculateFileMD5(file);
|
||||
console.log('文件签名:', sign);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('sign', sign);
|
||||
|
||||
const result = await importImage(formData);
|
||||
if (result) {
|
||||
setFileInfo(result);
|
||||
formRef.current?.setFieldsValue({
|
||||
waylineId: result.id,
|
||||
name: result.name
|
||||
});
|
||||
message.success('文件上传成功');
|
||||
console.log('上传接口返回结果:', result);
|
||||
|
||||
if (!result || !result.id) {
|
||||
hide();
|
||||
message.error('上传失败:未获取到文件信息');
|
||||
return false;
|
||||
}
|
||||
|
||||
const fileResponse: FileResponse = {
|
||||
id: result.id,
|
||||
name: result.name || file.name,
|
||||
url: result.url || '',
|
||||
sign: sign
|
||||
};
|
||||
|
||||
setFileInfo(fileResponse);
|
||||
formRef.current?.setFieldsValue({
|
||||
waylineId: fileResponse.id,
|
||||
name: fileResponse.name,
|
||||
sign: fileResponse.sign
|
||||
});
|
||||
|
||||
hide();
|
||||
message.success('文件上传成功');
|
||||
return false;
|
||||
} catch (error) {
|
||||
message.error('文件上传失败');
|
||||
} catch (error: any) {
|
||||
hide();
|
||||
console.error('文件上传错误:', error);
|
||||
message.error('文件上传失败:' + (error?.message || '未知错误'));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleTableAction = useCallback(async (
|
||||
action: 'add' | 'edit' | 'delete',
|
||||
record?: DEVICE.Wayline,
|
||||
record?: ExtendedWayline,
|
||||
values?: Partial<DEVICE.Wayline>
|
||||
) => {
|
||||
): Promise<boolean> => {
|
||||
let success = false;
|
||||
switch (action) {
|
||||
case 'add':
|
||||
if (!fileInfo) {
|
||||
message.error('请上传航线文件');
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
success = await handleAdd({
|
||||
...values,
|
||||
fileUrl: fileInfo.url,
|
||||
if (!fileInfo.sign) {
|
||||
message.error('文件签名获取失败');
|
||||
return false;
|
||||
}
|
||||
const waylineData: Omit<DEVICE.Wayline, 'id' | 'createTime' | 'tenantId' | 'updateTime'> = {
|
||||
waylineId: fileInfo.id,
|
||||
name: values.name || fileInfo.name
|
||||
} as DEVICE.Wayline);
|
||||
name: values?.name || fileInfo.name,
|
||||
sign: fileInfo.sign,
|
||||
droneModelKey: values?.droneModelKey || '',
|
||||
payloadModelKeys: values?.payloadModelKeys || '',
|
||||
workspaceId: values?.workspaceId || '',
|
||||
favorited: (values?.favorited?.toString() || '0') as string,
|
||||
templateTypes: values?.templateTypes || '',
|
||||
userName: values?.userName || ''
|
||||
};
|
||||
success = await handleAdd(waylineData as DEVICE.Wayline);
|
||||
if (success) {
|
||||
handleModalVisible(false);
|
||||
setFileInfo(undefined);
|
||||
@@ -171,7 +213,8 @@ const TableList: React.FC = () => {
|
||||
...values,
|
||||
...(fileInfo ? {
|
||||
fileUrl: fileInfo.url,
|
||||
waylineId: fileInfo.id
|
||||
waylineId: fileInfo.id,
|
||||
sign: fileInfo.sign
|
||||
} : {})
|
||||
};
|
||||
success = await handleEdit(record, updateData);
|
||||
@@ -183,15 +226,18 @@ const TableList: React.FC = () => {
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
success = await handleDelete(record!);
|
||||
if (record) {
|
||||
success = await handleDelete(record);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
return success;
|
||||
}, [fileInfo]);
|
||||
|
||||
const columns: ProColumns<DEVICE.Wayline>[] = [
|
||||
const columns: ProColumns<ExtendedWayline>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
@@ -216,14 +262,14 @@ const TableList: React.FC = () => {
|
||||
{
|
||||
title: '航线文件',
|
||||
dataIndex: 'fileUrl',
|
||||
render: (fileUrl, record) => fileUrl ? (
|
||||
render: (_, record) => record.fileUrl ? (
|
||||
<a
|
||||
href={fileUrl}
|
||||
href={record.fileUrl}
|
||||
download={record.name}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
const link = document.createElement('a');
|
||||
link.href = fileUrl;
|
||||
link.href = record.fileUrl || '';
|
||||
link.download = record.name || 'wayline.kmz';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
@@ -234,6 +280,12 @@ const TableList: React.FC = () => {
|
||||
</a>
|
||||
) : '-'
|
||||
},
|
||||
{
|
||||
title: '文件签名',
|
||||
dataIndex: 'sign',
|
||||
copyable: true,
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
@@ -275,7 +327,7 @@ const TableList: React.FC = () => {
|
||||
>
|
||||
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
|
||||
</QueryFilter>
|
||||
<ProTable<DEVICE.Wayline>
|
||||
<ProTable<ExtendedWayline>
|
||||
rowKey="id"
|
||||
headerTitle="航线列表"
|
||||
request={wayline}
|
||||
@@ -343,6 +395,10 @@ const TableList: React.FC = () => {
|
||||
hidden
|
||||
name="waylineId"
|
||||
/>
|
||||
<ProFormText
|
||||
hidden
|
||||
name="sign"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
@@ -359,15 +415,22 @@ const TableList: React.FC = () => {
|
||||
</Button>
|
||||
</Upload>
|
||||
{fileInfo && (
|
||||
<div style={{ marginTop: 8, color: '#52c41a' }}>
|
||||
已上传:{fileInfo.name}
|
||||
<div style={{ marginTop: 8 }}>
|
||||
<div style={{ color: '#52c41a' }}>
|
||||
已上传:{fileInfo.name}
|
||||
</div>
|
||||
<div style={{ color: '#666', fontSize: '12px' }}>
|
||||
文件签名:{fileInfo.sign}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
<UpdateForm
|
||||
onSubmit={(values) => handleTableAction('edit', currentRow, values)}
|
||||
onSubmit={async (values) => {
|
||||
await handleTableAction('edit', currentRow, values);
|
||||
}}
|
||||
onVisibleChange={(visible) => {
|
||||
handleUpdateModalVisible(visible);
|
||||
if (!visible) {
|
||||
|
||||
-69
@@ -1,69 +0,0 @@
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormText,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Form } from 'antd';
|
||||
|
||||
export type FormValueType = Partial<ORDERS.Tourism>;
|
||||
|
||||
export type UpdateFormProps = {
|
||||
onVisibleChange: (flag: boolean) => void;
|
||||
onSubmit: (values: FormValueType) => Promise<void>;
|
||||
updateModalVisible: boolean;
|
||||
values?: ORDERS.Tourism;
|
||||
};
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const [form] = Form.useForm();
|
||||
return (
|
||||
<ModalForm
|
||||
title="修改二维码"
|
||||
form={form}
|
||||
visible={props.updateModalVisible}
|
||||
onFinish={props.onSubmit}
|
||||
onVisibleChange={props.onVisibleChange}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '名称不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="tourismName"
|
||||
label="名称"
|
||||
placeholder="输入名称"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '地址不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="tourismAddress"
|
||||
label="地址"
|
||||
placeholder="输入地址"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '手机号不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="tourismPhone"
|
||||
label="手机号"
|
||||
placeholder="输入手机号"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default UpdateForm;
|
||||
@@ -1 +0,0 @@
|
||||
@import (reference) '~antd/es/style/themes/index';
|
||||
@@ -1,293 +0,0 @@
|
||||
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 <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
|
||||
};
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [params, setParams] = useState<Record<string, string | number>>({ });
|
||||
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
|
||||
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<ORDERS.Qrcode>();
|
||||
const columns: ProColumns<ORDERS.Qrcode>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
},
|
||||
{
|
||||
title: 'ID',
|
||||
dataIndex: 'id',
|
||||
},
|
||||
{
|
||||
title: 'CodeID',
|
||||
dataIndex: 'codeId',
|
||||
},
|
||||
{
|
||||
title: '景区ID',
|
||||
dataIndex: 'tourismId',
|
||||
},
|
||||
{
|
||||
title: '文件',
|
||||
dataIndex: 'viewUrl',
|
||||
render: (viewUrl) => <Image src={viewUrl} width={100} />
|
||||
},
|
||||
{
|
||||
title: '价格',
|
||||
dataIndex: 'price',
|
||||
},
|
||||
{
|
||||
title: '设备SN',
|
||||
dataIndex: 'deviceSn',
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
render: (status) => renderStatus(status),
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, entity) =>
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setCurrentRow(entity);
|
||||
handleUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</Link>
|
||||
<Popconfirm
|
||||
title={`确认删除景区[${entity.codeId}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleDelete(entity);
|
||||
if (success) {
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ subTitle: '管理任务' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
split
|
||||
span={6}
|
||||
className="query-filter"
|
||||
onFinish={async (values) => setParams(values)}
|
||||
>
|
||||
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
|
||||
</QueryFilter>
|
||||
<ProTable<ORDERS.Qrcode>
|
||||
rowKey="id"
|
||||
headerTitle="二维码列表"
|
||||
request={qrcode}
|
||||
actionRef={actionRef}
|
||||
columns={columns}
|
||||
search={false}
|
||||
params={params}
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
handleModalVisible(true);
|
||||
}}
|
||||
>
|
||||
<PlusOutlined /> 添加
|
||||
</Button>
|
||||
</>,
|
||||
]}
|
||||
/>
|
||||
<ModalForm
|
||||
title="添加二维码"
|
||||
// layout="horizontal"
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={handleModalVisible}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={async (values) => {
|
||||
|
||||
const success = await handleAdd(values);
|
||||
if (success) {
|
||||
handleModalVisible(false);
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '景区不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="tourismId"
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={[
|
||||
{ label: '北塘古镇', value: 33 },
|
||||
{ label: '海丝首港', value: 32 },
|
||||
{ label: '武汉东湖牡丹园', value: 35 },
|
||||
{ label: '武汉东湖樱花园', value: 36 },
|
||||
// 添加更多选项...
|
||||
]}
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '价格不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="price"
|
||||
label="景点打卡价格"
|
||||
placeholder="输入价格(单位:分)"
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '设备不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="deviceSn"
|
||||
label="设备编号"
|
||||
placeholder="输入设备编号"
|
||||
options={[
|
||||
{ label: '7CTDM6F00B744S', value: '7CTDM6F00B744S' },
|
||||
{ label: '8UUXN2A00A00LR', value: '8UUXN2A00A00LR' },
|
||||
{ label: '5YSZMBS0030BJ8', value: '5YSZMBS0030BJ8' },
|
||||
// 添加更多选项...
|
||||
]}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
<UpdateForm
|
||||
onSubmit={async (values) => {
|
||||
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}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default TableList;
|
||||
@@ -32,10 +32,18 @@ const TYPE_COLORS = {
|
||||
};
|
||||
|
||||
// 获取文件类型标签颜色
|
||||
const getTypeColor = (fileType: string) => {
|
||||
const getTypeColor = (fileType: string | null) => {
|
||||
if (!fileType) return TYPE_COLORS.default;
|
||||
return TYPE_COLORS[fileType] || TYPE_COLORS.default;
|
||||
};
|
||||
|
||||
// 获取文件类型显示文本
|
||||
const getFileTypeDisplay = (fileType: string | null) => {
|
||||
if (!fileType) return 'UNKNOWN';
|
||||
const parts = fileType.split('/');
|
||||
return parts.length > 1 ? parts[1].toUpperCase() : fileType.toUpperCase();
|
||||
};
|
||||
|
||||
// 处理文件删除
|
||||
const handleDelete = async (file: ORDERS.OrderFile) => {
|
||||
const hide = message.loading('正在删除文件...');
|
||||
@@ -77,7 +85,7 @@ const TableList: React.FC = () => {
|
||||
width: 200,
|
||||
render: (viewUrl, record) => (
|
||||
<Space direction="vertical">
|
||||
{FILE_CONFIG.imageTypes.includes(record.fileType) ? (
|
||||
{record.fileType && FILE_CONFIG.imageTypes.includes(record.fileType) ? (
|
||||
<Image
|
||||
src={viewUrl as string}
|
||||
width={100}
|
||||
@@ -85,7 +93,7 @@ const TableList: React.FC = () => {
|
||||
/>
|
||||
) : (
|
||||
<Tag color={getTypeColor(record.fileType)}>
|
||||
{record.fileType.split('/')[1].toUpperCase()}
|
||||
{getFileTypeDisplay(record.fileType)}
|
||||
</Tag>
|
||||
)}
|
||||
<Space>
|
||||
@@ -104,8 +112,8 @@ const TableList: React.FC = () => {
|
||||
dataIndex: 'fileType',
|
||||
width: 120,
|
||||
render: (type) => (
|
||||
<Tag color={getTypeColor(type as string)}>
|
||||
{(type as string).split('/')[1].toUpperCase()}
|
||||
<Tag color={getTypeColor(type as string | null)}>
|
||||
{getFileTypeDisplay(type as string | null)}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -28,5 +28,68 @@ export async function deleteWayline(id: number) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 获取设备列表
|
||||
export async function device(params?: { [key: string]: any }) {
|
||||
const { current, pageSize, ...rest } = params ?? {};
|
||||
try {
|
||||
const result = await request<API.Result<DEVICE.Device[]>>('/api-device/device', {
|
||||
method: 'GET',
|
||||
params: {
|
||||
page: current,
|
||||
limit: pageSize,
|
||||
...rest,
|
||||
},
|
||||
});
|
||||
|
||||
// 根据实际返回的数据结构进行处理
|
||||
return {
|
||||
data: result.data || [], // 直接使用返回的数组
|
||||
success: result.resp_code === 0,
|
||||
total: result.count || 0, // 使用返回的count作为总数
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取设备列表失败:', error);
|
||||
return {
|
||||
data: [],
|
||||
success: false,
|
||||
total: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 新增或更新设备
|
||||
export async function saveOrUpdateDevice(data: Partial<DEVICE.Device>): Promise<API.Result<DEVICE.Device>> {
|
||||
return request('/api-device/device', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
...data,
|
||||
createTime: data.createTime || Date.now(),
|
||||
updateTime: Date.now(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 删除设备
|
||||
export async function deleteDevice(deviceSn: string) {
|
||||
return request<API.Result<void>>(`/api-device/device/${deviceSn}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
// 获取设备详情
|
||||
export async function getDevice(deviceSn: string) {
|
||||
return request<API.Result<DEVICE.Device>>(`/api-device/device/${deviceSn}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
|
||||
// 更新设备绑定状态
|
||||
export async function updateDeviceBoundStatus(deviceSn: string, boundStatus: DEVICE.BoundStatus) {
|
||||
return request<API.Result<void>>(`/api-device/device/${deviceSn}/bound-status`, {
|
||||
method: 'PUT',
|
||||
data: { boundStatus },
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -18,5 +18,49 @@ declare namespace DEVICE {
|
||||
tenantId?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
|
||||
type Device = {
|
||||
id?: number;
|
||||
deviceSn: string; // 设备序列号
|
||||
deviceName: string; // 设备型号名称
|
||||
userId?: string; // 绑定账号
|
||||
nickname: string; // 设备自定义名称
|
||||
workspaceId?: string; // 所属工作区
|
||||
deviceType: number; // 设备类型
|
||||
subType: number; // 设备子类型
|
||||
domain: number; // 设备域
|
||||
firmwareVersion?: string; // 固件版本
|
||||
compatibleStatus: 0 | 1; // 固件版本一致性状态
|
||||
version?: string; // 协议版本
|
||||
deviceIndex?: string; // 设备索引(A控/B控)
|
||||
childSn?: string; // 网关控制的设备
|
||||
createTime?: number; // 创建时间
|
||||
updateTime?: number; // 更新时间
|
||||
boundTime?: number; // 绑定时间
|
||||
boundStatus: 0 | 1; // 绑定状态
|
||||
loginTime?: number; // 最后登录时间
|
||||
deviceDesc?: string; // 设备描述
|
||||
urlNormal?: string; // 设备图标
|
||||
urlSelect?: string; // 设备选中图标
|
||||
tenantId?: string; // 租户ID
|
||||
}
|
||||
|
||||
// 设备类型枚举
|
||||
enum DeviceType {
|
||||
DOCK = 1,
|
||||
DRONE = 2,
|
||||
REMOTE_CONTROL = 3,
|
||||
}
|
||||
|
||||
// 设备绑定状态
|
||||
enum BoundStatus {
|
||||
UNBOUND = 0,
|
||||
BOUND = 1,
|
||||
}
|
||||
|
||||
// 固件兼容状态
|
||||
enum CompatibleStatus {
|
||||
INCONSISTENT = 0,
|
||||
CONSISTENT = 1,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user