From d99ea5db2ecacdccd1bba0c0fd06961da977240c Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Fri, 15 May 2026 10:16:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SystemSetting/SerialNumGenerate.jsx | 244 +++++++----------- 1 file changed, 100 insertions(+), 144 deletions(-) diff --git a/src/components/SystemSetting/SerialNumGenerate.jsx b/src/components/SystemSetting/SerialNumGenerate.jsx index 10c9e79..f02b20f 100644 --- a/src/components/SystemSetting/SerialNumGenerate.jsx +++ b/src/components/SystemSetting/SerialNumGenerate.jsx @@ -5,9 +5,8 @@ import { } from 'antd'; import QRCode from 'qrcode'; import DictManager from "../DictManager"; -import request from '../../api/request'; import { Country, State } from 'country-state-city'; - - +import request from '../../api/request'; +import { Country, State } from 'country-state-city'; // 接口导入 import { @@ -15,18 +14,10 @@ import { addRobotTypeApi, updateRobotTypeApi, deleteRobotTypeApi, - getRobotProvinceListApi, - addRobotProvinceApi, - updateRobotProvinceApi, - deleteRobotProvinceApi, getRobotModelPageApi, addRobotModelApi, updateRobotModelApi, deleteRobotModelApi, - getRobotCountryListApi, - addRobotCountryApi, - updateRobotCountryApi, - deleteRobotCountryApi, getRobotConfigListApi, addRobotConfigApi, updateRobotConfigApi, @@ -34,89 +25,77 @@ import { } from '../../api/systemSetting'; const { Text } = Typography; +const { Option } = Select; const SerialNumGenerate = () => { - // 获取国家 - const countries1 = Country.getAllCountries(); - // 根据国家获取省份 - const states = State.getStatesOfCountry('CN'); + // 表单实例 const [form] = 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 [types, setTypes] = useState([]); const [models, setModels] = useState([]); - const [provinces, setProvinces] = useState([]); - const [countries, setCountries] = useState([]); const [configs, setConfigs] = useState([]); - // 初始化加载 + // 初始化:加载国家列表 useEffect(() => { + const countries = Country.getAllCountries(); + setAllCountries(countries || []); + + // 加载其他数据 loadTypeList(); loadModelList(); - loadProvinceList(); - loadCountryList(); loadConfigList(); }, []); + // 国家改变 → 刷新省份 + const handleCountryChange = (countryCode) => { + const states = State.getStatesOfCountry(countryCode); + setProvinces(states || []); + + // 切换国家时自动清空省份 + form.setFieldsValue({ province: undefined }); + }; + // ==================== 接口加载 ==================== // 加载机器人类型 const loadTypeList = async () => { try { const res = await getRobotTypeListApi({}); - if (res?.code == 200) { - setTypes(res.data || []); - } - } catch (e) { - } + 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 loadProvinceList = async () => { - try { - const res = await getRobotProvinceListApi({}); - setProvinces(res.rows || []); - } catch (e) { - message.error('加载省份失败'); - } - }; - - // 加载国家 - const loadCountryList = async () => { - try { - const res = await getRobotCountryListApi({}); - setCountries(res.rows || []); - } catch (e) { - message.error('加载国家失败'); - } + if (res?.code === 200) setModels(res.data || []); + } catch (e) { } }; // 加载配置 const loadConfigList = async () => { try { const res = await getRobotConfigListApi({}); - setConfigs(res.rows || []); - } catch (e) { - message.error('加载配置失败'); - } + if (res?.code === 200) setConfigs(res.data || []); + } catch (e) { } }; // 生成序号 @@ -148,7 +127,7 @@ const SerialNumGenerate = () => { } }; - // 下载 + // 下载二维码 const downloadQRCode = () => { if (!qrRef.current || !qrUrl) { message.warning('请先生成二维码'); @@ -160,7 +139,7 @@ const SerialNumGenerate = () => { link.click(); }; - // 保存序列号 + // 保存到数据库 const saveToDatabase = async () => { if (!serialNumber) return message.warning('请先生成'); setLoading(true); @@ -187,7 +166,7 @@ const SerialNumGenerate = () => { } }; - // 查询 + // 查询序列号 const handleQueryQRCode = async () => { if (!queryCode) return message.warning('请输入序列号'); setQueryLoading(true); @@ -195,7 +174,7 @@ const SerialNumGenerate = () => { const res = await request({ url: '/iot/device/querySerial', method: 'get', - params: { sn: queryCode } + params: sn.queryCode }); if (res.data) { setSerialNumber(res.data.serialNumber); @@ -219,7 +198,8 @@ const SerialNumGenerate = () => { } }; - // ==================== 类型 ==================== + // ==================== 数据处理方法 ==================== + // 类型 const handleAddType = async (values) => { return await addRobotTypeApi({ storeValue: values.storeValue, @@ -236,65 +216,39 @@ const SerialNumGenerate = () => { }); }; - // ==================== 型号 ==================== + // 型号 const handleAddModel = async (values) => { return await addRobotModelApi({ - modelName: values.modelName, + modelName: values.displayName, storeValue: values.storeValue, - displayName: '' + displayName: values.displayName + }); }; const handleUpdateModel = async (values) => { return await updateRobotModelApi({ id: values.id, - modelName: values.modelName, - displayName: values.displayName - }); - }; - - // ==================== 省份 ==================== - const handleAddProvince = async (values) => { - return await addRobotProvinceApi({ + modelName: values.displayName, storeValue: values.storeValue, - displayName: values.displayName, - remark: values.remark || '' - }); - }; - const handleUpdateProvince = async (values) => { - return await updateRobotProvinceApi({ - id: values.id, - storeValue: values.storeValue, - displayName: values.displayName, - remark: values.remark || '' + displayName: values.displayName + }); }; - // ==================== 国家 ==================== - const handleAddCountry = async (values) => { - return await addRobotCountryApi({ - countryName: values.countryName, - displayName: values.displayName - }); - }; - const handleUpdateCountry = async (values) => { - return await updateRobotCountryApi({ - id: values.id, - countryName: values.countryName, - displayName: values.displayName - }); - }; - - // ==================== 配置 ==================== + // 配置 const handleAddConfig = async (values) => { return await addRobotConfigApi({ - configName: values.configName, + configName: values.displayName, + storeValue: values.storeValue, displayName: values.displayName + }); }; const handleUpdateConfig = async (values) => { return await updateRobotConfigApi({ id: values.id, - configName: values.configName, + configName: values.displayName, + storeValue: values.storeValue, displayName: values.displayName }); }; @@ -308,43 +262,74 @@ const SerialNumGenerate = () => { > -
+ + {/* 型号 */} - + option.children.toLowerCase().includes(input.toLowerCase()) + }> {models.map(m => ( - {m.modelName} + ))} + {/* 配置 */} - {configs.map(c => ( - {c.configName} + ))} + {/* 类型 */} - {types.map(t => ( - {t.storeValue} + ))} + {/* 国家(级联) */} + {/* 国家(级联 + 可清空) */} - + option.children.toLowerCase().includes(input.toLowerCase()) + } + > + {allCountries.map((c) => ( + + {c.name} + ))} + {/* 省份(级联 + 可清空 + 中国显示中文) */} - + option.children.toLowerCase().includes(input.toLowerCase()) + } + > + {provinces.map((p) => ( + + {p.isoCode === 'CN' ? p.name : p.name} + {/* 中国省份默认就是中文,这里直接显示 name 即可 */} + ))} @@ -425,7 +410,7 @@ const SerialNumGenerate = () => { title="机器人型号" data={models} fields={[ - { name: 'modelName', label: '型号名称', required: true }, + { name: 'displayName', label: '型号名称', required: true }, { name: 'storeValue', label: '存储值', required: true }, ]} onAdd={handleAddModel} @@ -434,42 +419,13 @@ const SerialNumGenerate = () => { refresh={loadModelList} /> - {/* 国家 */} - - - {/* 省份 */} - - {/* 配置 */}