From 64d27db08163c7b3358d3fa070cc8e6e2d829645 Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Fri, 15 May 2026 13:09:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SystemSetting/SerialNumGenerate.jsx | 420 +++++++++--------- 1 file changed, 204 insertions(+), 216 deletions(-) diff --git a/src/components/SystemSetting/SerialNumGenerate.jsx b/src/components/SystemSetting/SerialNumGenerate.jsx index 813cbae..3104123 100644 --- a/src/components/SystemSetting/SerialNumGenerate.jsx +++ b/src/components/SystemSetting/SerialNumGenerate.jsx @@ -1,7 +1,7 @@ import React, { useState, useRef, useEffect } from 'react'; import { Form, Select, Button, Space, message, Card, Typography, - Row, Col, Modal, Input + Row, Col, Modal, Input, Table, Popconfirm, Tag } from 'antd'; import QRCode from 'qrcode'; import DictManager from "../DictManager"; @@ -23,7 +23,11 @@ import { updateRobotConfigApi, deleteRobotConfigApi, saveCodeApi, - getCodeImgApi + getCodeImgApi, + getCodeListApi, + getCodeListPageApi, + getCodeDeatil, + delteCodesApi } from '../../api/systemSetting'; const { Text } = Typography; @@ -31,34 +35,45 @@ const { Option } = Select; const SerialNumGenerate = () => { const [messageApi, contextHolder] = message.useMessage(); - - // 表单实例 const [form] = Form.useForm(); + const [searchForm] = Form.useForm(); - // 国家/省份 数据 + // 国家/省份 const [allCountries, setAllCountries] = useState([]); const [provinces, setProvinces] = useState([]); - // 二维码相关 + // 二维码生成 const [qrUrl, setQrUrl] = useState(''); const [serialNumber, setSerialNumber] = useState(''); const [qrJson, setQrJson] = useState(''); const [loading, setLoading] = useState(false); const qrRef = useRef(null); - // 查询功能 + // 查询 const [queryCode, setQueryCode] = useState(''); const [queryLoading, setQueryLoading] = useState(false); // 数据管理弹窗 const [manageVisible, setManageVisible] = useState(false); + const [addModalVisible, setAddModalVisible] = useState(false); - // 接口数据 + // 业务数据 const [types, setTypes] = useState([]); const [models, setModels] = useState([]); const [configs, setConfigs] = useState([]); - // 存储完整中文名称映射 + // 二维码列表数据 + const [codeList, setCodeList] = useState([]); + const [codeLoading, setCodeLoading] = useState(false); + const [currentPage, setCurrentPage] = useState(1); + const [pageSize] = useState(10); + const [total, setTotal] = useState(0); + + // 查看二维码弹窗 + const [viewModal, setViewModal] = useState(false); + const [viewRecord, setViewRecord] = useState(null); + + // 映射 const countryNameMap = useRef({}); const provinceNameMap = useRef({}); @@ -66,44 +81,72 @@ const SerialNumGenerate = () => { useEffect(() => { const countries = Country.getAllCountries(); setAllCountries(countries || []); - // 构建 简码=>中文名称 映射 countries.forEach(item => { countryNameMap.current[item.isoCode] = item.name; - }) - + }); loadTypeList(); loadModelList(); loadConfigList(); + loadCodeList(); }, []); - // 国家改变 → 刷新省份 + // 国家切换 const handleCountryChange = (countryCode) => { const states = State.getStatesOfCountry(countryCode); setProvinces(states || []); - // 构建省份简码=>中文名称映射 states.forEach(item => { provinceNameMap.current[item.isoCode] = item.name; - }) + }); form.setFieldsValue({ province: undefined }); }; - // 加载机器人类型 + // 加载二维码列表 + const loadCodeList = async () => { + setCodeLoading(true); + try { + const params = searchForm.getFieldsValue(); + const res = await getCodeListPageApi({ ...params, current: currentPage, size: pageSize }); + if (res?.code === 200) { + const rows = res.data.records || res.data || []; + setCodeList(rows); + setTotal(res.data.total || rows.length); + } + } catch (e) { + } finally { + setCodeLoading(false); + } + }; + + // 删除 + const handleDelete = async (id) => { + try { + await delteCodesApi(id); + messageApi.success('删除成功'); + loadCodeList(); + } catch (e) { + messageApi.error('删除失败'); + } + }; + + // 查看 + const handleView = (record) => { + setViewRecord(record); + setViewModal(true); + }; + + // 加载数据 const loadTypeList = async () => { try { const res = await getRobotTypeListApi({}); if (res?.code === 200) setTypes(res.data || []); } catch (e) { } }; - - // 加载机器人型号 const loadModelList = async () => { try { const res = await getRobotModelPageApi({ pageNum: 1, pageSize: 100 }); if (res?.code === 200) setModels(res.data || []); } catch (e) { } }; - - // 加载配置 const loadConfigList = async () => { try { const res = await getRobotConfigListApi({}); @@ -111,7 +154,7 @@ const SerialNumGenerate = () => { } catch (e) { } }; - // 生成随机后缀 + // 生成序列号 const generateSerialSuffix = () => { const num = Math.floor(Math.random() * 100000000).toString(16).toUpperCase().padStart(8, '0'); const check = Math.floor(Math.random() * 256).toString(16).toUpperCase().padStart(2, '0'); @@ -128,15 +171,13 @@ const SerialNumGenerate = () => { const parts = []; if (model) parts.push(model + config); - //if (config) parts.push(config); if (country) parts.push(country); if (province) parts.push(province); parts.push(ts); parts.push(suffix); - // 用 - 连接所有存在的部分 const serialNumber = parts.join('-'); - // 二维码JSON存入【完整中文名称】,扫码查看完整信息 + const qrData = { model, config, @@ -153,29 +194,24 @@ const SerialNumGenerate = () => { setSerialNumber(serialNumber); setQrJson(qrContent); setQrUrl(url); - } catch (err) { - } + } catch (err) { } }; - // 下载二维码 + // 下载 const downloadQRCode = () => { - if (!qrRef.current || !qrUrl) { - messageApi.warning('请先生成二维码'); - return; - } + if (!qrUrl) return messageApi.warning('请先生成'); const link = document.createElement('a'); link.download = `${serialNumber || 'qrcode'}.png`; link.href = qrUrl; link.click(); }; - // 保存到数据库 + // 保存 const saveToDatabase = async () => { if (!serialNumber) return messageApi.warning('请先生成'); try { setLoading(true); const values = form.getFieldsValue(); - const model = models.find(m => m.displayName === values.model); const config = configs.find(c => c.displayName === values.config); const type = types.find(t => t.displayName === values.type); @@ -185,31 +221,30 @@ const SerialNumGenerate = () => { modelId: model?.id, configId: config?.id, typeId: type?.id, - //countryId: values.country, - //provinceId: values.province, qrCodeUrl: qrUrl, qrJson: qrJson }; const res = await saveCodeApi(data); - if (res?.code == 200) { + if (res?.code === 200) { messageApi.success('保存成功'); - setLoading(false); - + loadCodeList(); + setAddModalVisible(false); + form.resetFields(); + setQrUrl(''); + setSerialNumber(''); + setQrJson(''); } else { - messageApi.error('保存失败' + res?.msg); - + messageApi.error('保存失败:' + res?.msg); } } catch (e) { - setLoading(false); - messageApi.error('保存失败'); } finally { setLoading(false); } }; - // 查询序列号 + // 查询 const handleQueryQRCode = async () => { if (!queryCode) return messageApi.warning('请输入序列号'); setQueryLoading(true); @@ -237,232 +272,185 @@ const SerialNumGenerate = () => { } }; - // 类型 + // 类型/型号/配置 const handleAddType = async (values) => { - return await addRobotTypeApi({ - storeValue: values.storeValue, - displayName: values.displayName, - remark: values.remark || '' - }); + return await addRobotTypeApi({ storeValue: values.storeValue, displayName: values.displayName, remark: values.remark || '' }); }; const handleUpdateType = async (values) => { - return await updateRobotTypeApi({ - id: values.id, - storeValue: values.storeValue, - displayName: values.displayName, - remark: values.remark || '' - }); + return await updateRobotTypeApi({ id: values.id, storeValue: values.storeValue, displayName: values.displayName, remark: values.remark }); }; - - // 型号 const handleAddModel = async (values) => { - return await addRobotModelApi({ - modelName: values.displayName, - storeValue: values.storeValue, - displayName: values.displayName - }); + return await addRobotModelApi({ modelName: values.displayName, storeValue: values.storeValue, displayName: values.displayName }); }; const handleUpdateModel = async (values) => { - return await updateRobotModelApi({ - id: values.id, - modelName: values.displayName, - storeValue: values.storeValue, - displayName: values.displayName - }); + return await updateRobotModelApi({ id: values.id, modelName: values.displayName, storeValue: values.storeValue, displayName: values.displayName }); }; - - // 配置 const handleAddConfig = async (values) => { - return await addRobotConfigApi({ - configName: values.displayName, - storeValue: values.storeValue, - displayName: values.displayName - }); + return await addRobotConfigApi({ configName: values.displayName, storeValue: values.storeValue, displayName: values.displayName }); }; const handleUpdateConfig = async (values) => { - return await updateRobotConfigApi({ - id: values.id, - configName: values.displayName, - storeValue: values.storeValue, - displayName: values.displayName - }); + return await updateRobotConfigApi({ id: values.id, configName: values.displayName, storeValue: values.storeValue, displayName: values.displayName }); }; + // 表格列 + const columns = [ + { title: 'ID', dataIndex: 'id', key: 'id', width: 70 }, + { title: '序列号', width: 380, dataIndex: 'serialNumber', key: 'sn', ellipsis: true }, + { + title: '型号', + key: 'model', + render: (_, r) => models.find(m => m.id === r.modelId)?.modelName || '-' + }, + { + title: '配置', + key: 'config', + render: (_, r) => configs.find(c => c.id === r.configId)?.configName || '-' + }, + { + title: '二维码', + key: 'img', + width: 100, + render: (_, r) => r.qrCodeUrl && qrcode + }, + { + title: '操作', + key: 'opt', + width: 180, + fixed: "right", + render: (_, r) => ( + + + handleDelete(r.id)} + > + + + + ) + } + ]; + return ( -
+
{contextHolder} - setManageVisible(true)}>数据管理} + + + + + + }> + + {/* 筛选栏 */} +
+ + + + + + + + + +
+ + {/* 列表 */} + + + + {/* 新增弹窗 = 原来的生成二维码页面 */} + { + setAddModalVisible(false); + form.resetFields(); + setQrUrl(''); + setSerialNumber(''); + }} + footer={null} + destroyOnClose > - + - {/* 型号 */} - + {models.map(m => )} - - {/* 配置 */} - + {configs.map(c => )} - - {/* 类型 */} - + {types.map(t => )} - - {/* 国家 显示中文 存简码 可清空 */} - - + {allCountries.map(c => )} - - {/* 省份 显示中文 存简码 可清空 */} - - + {provinces.map(p => )} - - + - - - - setQueryCode(e.target.value)} - placeholder="输入序列号查询" - style={{ width: '300px' }} - /> - - - -
+
{serialNumber && (
- 序列号:{serialNumber} + 序列号:{serialNumber}
)} - {qrUrl ? ( - qrcode + qrcode ) : (
请先生成二维码
)} - - +
- + - setManageVisible(false)} - footer={} - destroyOnClose - > - + {/* 查看二维码 */} + setViewModal(false)} footer={null} width={400}> + {viewRecord && ( +
+ qrcode +
序列号:{viewRecord.serialNumber}
+
+ )} +
- - - + {/* 数据管理 */} + setManageVisible(false)} footer={} destroyOnClose> + + +
);