样式修改

This commit is contained in:
mmc
2026-05-15 13:09:28 +08:00
parent c01621d724
commit 64d27db081

View File

@@ -1,7 +1,7 @@
import React, { useState, useRef, useEffect } from 'react'; import React, { useState, useRef, useEffect } from 'react';
import { import {
Form, Select, Button, Space, message, Card, Typography, Form, Select, Button, Space, message, Card, Typography,
Row, Col, Modal, Input Row, Col, Modal, Input, Table, Popconfirm, Tag
} from 'antd'; } from 'antd';
import QRCode from 'qrcode'; import QRCode from 'qrcode';
import DictManager from "../DictManager"; import DictManager from "../DictManager";
@@ -23,7 +23,11 @@ import {
updateRobotConfigApi, updateRobotConfigApi,
deleteRobotConfigApi, deleteRobotConfigApi,
saveCodeApi, saveCodeApi,
getCodeImgApi getCodeImgApi,
getCodeListApi,
getCodeListPageApi,
getCodeDeatil,
delteCodesApi
} from '../../api/systemSetting'; } from '../../api/systemSetting';
const { Text } = Typography; const { Text } = Typography;
@@ -31,34 +35,45 @@ const { Option } = Select;
const SerialNumGenerate = () => { const SerialNumGenerate = () => {
const [messageApi, contextHolder] = message.useMessage(); const [messageApi, contextHolder] = message.useMessage();
// 表单实例
const [form] = Form.useForm(); const [form] = Form.useForm();
const [searchForm] = Form.useForm();
// 国家/省份 数据 // 国家/省份
const [allCountries, setAllCountries] = useState([]); const [allCountries, setAllCountries] = useState([]);
const [provinces, setProvinces] = useState([]); const [provinces, setProvinces] = useState([]);
// 二维码相关 // 二维码生成
const [qrUrl, setQrUrl] = useState(''); const [qrUrl, setQrUrl] = useState('');
const [serialNumber, setSerialNumber] = useState(''); const [serialNumber, setSerialNumber] = useState('');
const [qrJson, setQrJson] = useState(''); const [qrJson, setQrJson] = useState('');
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const qrRef = useRef(null); const qrRef = useRef(null);
// 查询功能 // 查询
const [queryCode, setQueryCode] = useState(''); const [queryCode, setQueryCode] = useState('');
const [queryLoading, setQueryLoading] = useState(false); const [queryLoading, setQueryLoading] = useState(false);
// 数据管理弹窗 // 数据管理弹窗
const [manageVisible, setManageVisible] = useState(false); const [manageVisible, setManageVisible] = useState(false);
const [addModalVisible, setAddModalVisible] = useState(false);
// 接口数据 // 业务数据
const [types, setTypes] = useState([]); const [types, setTypes] = useState([]);
const [models, setModels] = useState([]); const [models, setModels] = useState([]);
const [configs, setConfigs] = 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 countryNameMap = useRef({});
const provinceNameMap = useRef({}); const provinceNameMap = useRef({});
@@ -66,44 +81,72 @@ const SerialNumGenerate = () => {
useEffect(() => { useEffect(() => {
const countries = Country.getAllCountries(); const countries = Country.getAllCountries();
setAllCountries(countries || []); setAllCountries(countries || []);
// 构建 简码=>中文名称 映射
countries.forEach(item => { countries.forEach(item => {
countryNameMap.current[item.isoCode] = item.name; countryNameMap.current[item.isoCode] = item.name;
}) });
loadTypeList(); loadTypeList();
loadModelList(); loadModelList();
loadConfigList(); loadConfigList();
loadCodeList();
}, []); }, []);
// 国家改变 → 刷新省份 // 国家切换
const handleCountryChange = (countryCode) => { const handleCountryChange = (countryCode) => {
const states = State.getStatesOfCountry(countryCode); const states = State.getStatesOfCountry(countryCode);
setProvinces(states || []); setProvinces(states || []);
// 构建省份简码=>中文名称映射
states.forEach(item => { states.forEach(item => {
provinceNameMap.current[item.isoCode] = item.name; provinceNameMap.current[item.isoCode] = item.name;
}) });
form.setFieldsValue({ province: undefined }); 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 () => { const loadTypeList = async () => {
try { try {
const res = await getRobotTypeListApi({}); const res = await getRobotTypeListApi({});
if (res?.code === 200) setTypes(res.data || []); if (res?.code === 200) setTypes(res.data || []);
} catch (e) { } } catch (e) { }
}; };
// 加载机器人型号
const loadModelList = async () => { const loadModelList = async () => {
try { try {
const res = await getRobotModelPageApi({ pageNum: 1, pageSize: 100 }); const res = await getRobotModelPageApi({ pageNum: 1, pageSize: 100 });
if (res?.code === 200) setModels(res.data || []); if (res?.code === 200) setModels(res.data || []);
} catch (e) { } } catch (e) { }
}; };
// 加载配置
const loadConfigList = async () => { const loadConfigList = async () => {
try { try {
const res = await getRobotConfigListApi({}); const res = await getRobotConfigListApi({});
@@ -111,7 +154,7 @@ const SerialNumGenerate = () => {
} catch (e) { } } catch (e) { }
}; };
// 生成随机后缀 // 生成序列号
const generateSerialSuffix = () => { const generateSerialSuffix = () => {
const num = Math.floor(Math.random() * 100000000).toString(16).toUpperCase().padStart(8, '0'); 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'); const check = Math.floor(Math.random() * 256).toString(16).toUpperCase().padStart(2, '0');
@@ -128,15 +171,13 @@ const SerialNumGenerate = () => {
const parts = []; const parts = [];
if (model) parts.push(model + config); if (model) parts.push(model + config);
//if (config) parts.push(config);
if (country) parts.push(country); if (country) parts.push(country);
if (province) parts.push(province); if (province) parts.push(province);
parts.push(ts); parts.push(ts);
parts.push(suffix); parts.push(suffix);
// 用 - 连接所有存在的部分
const serialNumber = parts.join('-'); const serialNumber = parts.join('-');
// 二维码JSON存入【完整中文名称】,扫码查看完整信息
const qrData = { const qrData = {
model, model,
config, config,
@@ -153,29 +194,24 @@ const SerialNumGenerate = () => {
setSerialNumber(serialNumber); setSerialNumber(serialNumber);
setQrJson(qrContent); setQrJson(qrContent);
setQrUrl(url); setQrUrl(url);
} catch (err) { } catch (err) { }
}
}; };
// 下载二维码 // 下载
const downloadQRCode = () => { const downloadQRCode = () => {
if (!qrRef.current || !qrUrl) { if (!qrUrl) return messageApi.warning('请先生成');
messageApi.warning('请先生成二维码');
return;
}
const link = document.createElement('a'); const link = document.createElement('a');
link.download = `${serialNumber || 'qrcode'}.png`; link.download = `${serialNumber || 'qrcode'}.png`;
link.href = qrUrl; link.href = qrUrl;
link.click(); link.click();
}; };
// 保存到数据库 // 保存
const saveToDatabase = async () => { const saveToDatabase = async () => {
if (!serialNumber) return messageApi.warning('请先生成'); if (!serialNumber) return messageApi.warning('请先生成');
try { try {
setLoading(true); setLoading(true);
const values = form.getFieldsValue(); const values = form.getFieldsValue();
const model = models.find(m => m.displayName === values.model); const model = models.find(m => m.displayName === values.model);
const config = configs.find(c => c.displayName === values.config); const config = configs.find(c => c.displayName === values.config);
const type = types.find(t => t.displayName === values.type); const type = types.find(t => t.displayName === values.type);
@@ -185,31 +221,30 @@ const SerialNumGenerate = () => {
modelId: model?.id, modelId: model?.id,
configId: config?.id, configId: config?.id,
typeId: type?.id, typeId: type?.id,
//countryId: values.country,
//provinceId: values.province,
qrCodeUrl: qrUrl, qrCodeUrl: qrUrl,
qrJson: qrJson qrJson: qrJson
}; };
const res = await saveCodeApi(data); const res = await saveCodeApi(data);
if (res?.code == 200) { if (res?.code === 200) {
messageApi.success('保存成功'); messageApi.success('保存成功');
setLoading(false); loadCodeList();
setAddModalVisible(false);
form.resetFields();
setQrUrl('');
setSerialNumber('');
setQrJson('');
} else { } else {
messageApi.error('保存失败' + res?.msg); messageApi.error('保存失败:' + res?.msg);
} }
} catch (e) { } catch (e) {
setLoading(false);
messageApi.error('保存失败'); messageApi.error('保存失败');
} finally { } finally {
setLoading(false); setLoading(false);
} }
}; };
// 查询序列号 // 查询
const handleQueryQRCode = async () => { const handleQueryQRCode = async () => {
if (!queryCode) return messageApi.warning('请输入序列号'); if (!queryCode) return messageApi.warning('请输入序列号');
setQueryLoading(true); setQueryLoading(true);
@@ -237,232 +272,185 @@ const SerialNumGenerate = () => {
} }
}; };
// 类型 // 类型/型号/配置
const handleAddType = async (values) => { const handleAddType = async (values) => {
return await addRobotTypeApi({ return await addRobotTypeApi({ storeValue: values.storeValue, displayName: values.displayName, remark: values.remark || '' });
storeValue: values.storeValue,
displayName: values.displayName,
remark: values.remark || ''
});
}; };
const handleUpdateType = async (values) => { const handleUpdateType = async (values) => {
return await updateRobotTypeApi({ return await updateRobotTypeApi({ id: values.id, storeValue: values.storeValue, displayName: values.displayName, remark: values.remark });
id: values.id,
storeValue: values.storeValue,
displayName: values.displayName,
remark: values.remark || ''
});
}; };
// 型号
const handleAddModel = async (values) => { const handleAddModel = async (values) => {
return await addRobotModelApi({ return await addRobotModelApi({ modelName: values.displayName, storeValue: values.storeValue, displayName: values.displayName });
modelName: values.displayName,
storeValue: values.storeValue,
displayName: values.displayName
});
}; };
const handleUpdateModel = async (values) => { const handleUpdateModel = async (values) => {
return await updateRobotModelApi({ return await updateRobotModelApi({ id: values.id, modelName: values.displayName, storeValue: values.storeValue, displayName: values.displayName });
id: values.id,
modelName: values.displayName,
storeValue: values.storeValue,
displayName: values.displayName
});
}; };
// 配置
const handleAddConfig = async (values) => { const handleAddConfig = async (values) => {
return await addRobotConfigApi({ return await addRobotConfigApi({ configName: values.displayName, storeValue: values.storeValue, displayName: values.displayName });
configName: values.displayName,
storeValue: values.storeValue,
displayName: values.displayName
});
}; };
const handleUpdateConfig = async (values) => { const handleUpdateConfig = async (values) => {
return await updateRobotConfigApi({ return await updateRobotConfigApi({ id: values.id, configName: values.displayName, storeValue: values.storeValue, displayName: values.displayName });
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 && <img src={r.qrCodeUrl} style={{ width: 50, height: 50 }} alt="qrcode" />
},
{
title: '操作',
key: 'opt',
width: 180,
fixed: "right",
render: (_, r) => (
<Space>
<Button type="link" onClick={() => handleView(r)}>查看</Button>
<Popconfirm
title="确定删除?"
onConfirm={() => handleDelete(r.id)}
>
<Button type="link" danger>删除</Button>
</Popconfirm>
</Space>
)
}
];
return ( return (
<div style={{ padding: '0 20px', minHeight: '100vh' }}> <div style={{ padding: '0px 20px 40px', minHeight: '100vh' }}>
{contextHolder} {contextHolder}
<Card
title="机器人序列号二维码生成器" <Card style={{ maxWidth: 1400, margin: '0 auto' }}
style={{ maxWidth: 1000, margin: '0 auto', borderRadius: 12 }} title="机器人二维码管理"
extra={<Button type="primary" onClick={() => setManageVisible(true)}>数据管理</Button>} extra={
> <Space>
<Row gutter={[32, 24]}> <Button type="primary" onClick={() => setAddModalVisible(true)}>新增</Button>
<Col xs={24} md={14}> <Button onClick={() => setManageVisible(true)}>数据管理</Button>
<Form form={form} labelCol={{ md: 5 }} wrapperCol={{ md: 19 }} size="large"> </Space>
{/* 型号 */}
<Form.Item name="model" label="型号" rules={[{ required: true }]}>
<Select placeholder="选择型号" showSearch optionFilterProp="children" filterOption={(input, option) =>
option.children.toLowerCase().includes(input.toLowerCase())
}> }>
{models.map(m => (
<Option key={m.id} value={m.displayName}>{m.modelName}</Option>
))}
</Select>
</Form.Item>
{/* 配置 */} {/* 筛选栏 */}
<Form.Item name="config" label="配置" rules={[{ required: true }]}> <Form form={searchForm} layout="inline" style={{ marginBottom: 16 }}>
<Select placeholder="选择配置" showSearch optionFilterProp="children"> <Form.Item name="serialNumber" label="序列号">
{configs.map(c => ( <Input placeholder="请输入序列号" style={{ width: 220 }} />
<Option key={c.id} value={c.displayName}>{c.configName}</Option>
))}
</Select>
</Form.Item> </Form.Item>
<Form.Item>
{/* 类型 */} <Space>
<Form.Item name="type" label="类型" rules={[{ required: true }]}> <Button type="primary" onClick={loadCodeList}>搜索</Button>
<Select placeholder="选择类型" showSearch optionFilterProp="children"> <Button onClick={() => { searchForm.resetFields(); loadCodeList(); }}>重置</Button>
{types.map(t => ( </Space>
<Option key={t.id} value={t.displayName}>{t.storeValue}</Option>
))}
</Select>
</Form.Item>
{/* 国家 显示中文 存简码 可清空 */}
<Form.Item name="country" label="国家" >
<Select
placeholder="选择国家"
showSearch
allowClear
optionFilterProp="children"
onChange={handleCountryChange}
filterOption={(input, option) =>
option.children.toLowerCase().includes(input.toLowerCase())
}
>
{allCountries.map((c) => (
<Select.Option key={c.isoCode} value={c.isoCode}>
{c.name}
</Select.Option>
))}
</Select>
</Form.Item>
{/* 省份 显示中文 存简码 可清空 */}
<Form.Item name="province" label="省份" >
<Select
placeholder="请先选择国家"
showSearch
allowClear
disabled={provinces.length === 0}
optionFilterProp="children"
filterOption={(input, option) =>
option.children.toLowerCase().includes(input.toLowerCase())
}
>
{provinces.map((p) => (
<Select.Option key={p.isoCode} value={p.isoCode}>
{p.name}
</Select.Option>
))}
</Select>
</Form.Item>
<Form.Item wrapperCol={{ offset: 5 }}>
<Button type="primary" onClick={generateQRCode} block>
生成序列号 & 二维码
</Button>
</Form.Item> </Form.Item>
</Form> </Form>
<Card size="small" title="查询历史二维码" style={{ marginTop: 20 }}> {/* 列表 */}
<Space style={{ width: '100%' }}> <Table
<Input rowKey="id"
value={queryCode} columns={columns}
onChange={(e) => setQueryCode(e.target.value)} dataSource={codeList}
placeholder="输入序列号查询" loading={codeLoading}
style={{ width: '300px' }} pagination={{ current: currentPage, pageSize, total, onChange: setCurrentPage }}
/> />
<Button type="primary" loading={queryLoading} onClick={handleQueryQRCode}>
查询
</Button>
</Space>
</Card> </Card>
{/* 新增弹窗 = 原来的生成二维码页面 */}
<Modal
title="生成机器人二维码"
open={addModalVisible}
width={900}
onCancel={() => {
setAddModalVisible(false);
form.resetFields();
setQrUrl('');
setSerialNumber('');
}}
footer={null}
destroyOnClose
>
<Row gutter={[24, 16]}>
<Col xs={24} md={14}>
<Form form={form} labelCol={{ md: 5 }} wrapperCol={{ md: 19 }} size="large">
<Form.Item name="model" label="型号" rules={[{ required: true }]}>
<Select placeholder="选择型号" showSearch>
{models.map(m => <Option key={m.id} value={m.displayName}>{m.modelName}</Option>)}
</Select>
</Form.Item>
<Form.Item name="config" label="配置" rules={[{ required: true }]}>
<Select placeholder="选择配置" showSearch>
{configs.map(c => <Option key={c.id} value={c.displayName}>{c.configName}</Option>)}
</Select>
</Form.Item>
<Form.Item name="type" label="类型" rules={[{ required: true }]}>
<Select placeholder="选择类型" showSearch>
{types.map(t => <Option key={t.id} value={t.displayName}>{t.storeValue}</Option>)}
</Select>
</Form.Item>
<Form.Item name="country" label="国家">
<Select placeholder="选择国家" showSearch allowClear onChange={handleCountryChange}>
{allCountries.map(c => <Option key={c.isoCode} value={c.isoCode}>{c.name}</Option>)}
</Select>
</Form.Item>
<Form.Item name="province" label="省份">
<Select placeholder="请先选择国家" showSearch allowClear disabled={provinces.length === 0}>
{provinces.map(p => <Option key={p.isoCode} value={p.isoCode}>{p.name}</Option>)}
</Select>
</Form.Item>
<Form.Item wrapperCol={{ offset: 5 }}>
<Button type="primary" onClick={generateQRCode} block>生成序列号 & 二维码</Button>
</Form.Item>
</Form>
</Col> </Col>
<Col xs={24} md={10}> <Col xs={24} md={10}>
<div style={{ <div style={{ padding: 20, background: '#fafafa', borderRadius: 12, border: '1px dashed #d9d9d9', alignItems: 'center', minHeight: 400 }}>
padding: 20, background: '#fafafa', borderRadius: 12, border: '1px dashed #d9d9d9',
display: 'flex', flexDirection: 'column', alignItems: 'center', minHeight: 480
}}>
{serialNumber && ( {serialNumber && (
<div style={{ padding: 12, background: '#e6f7ff', borderRadius: 8, width: '100%', textAlign: 'center', marginBottom: 20 }}> <div style={{ padding: 12, background: '#e6f7ff', borderRadius: 8, width: '100%', textAlign: 'center', marginBottom: 20 }}>
<Text strong style={{ fontSize: 15 }}>序列号:{serialNumber}</Text> <Text strong>序列号:{serialNumber}</Text>
</div> </div>
)} )}
{qrUrl ? ( {qrUrl ? (
<img ref={qrRef} src={qrUrl} style={{ width: 240, height: 240 }} alt="qrcode" /> <img src={qrUrl} style={{ width: 240, height: 240 }} alt="qrcode" />
) : ( ) : (
<div style={{ color: '#999', padding: '60px 0' }}>请先生成二维码</div> <div style={{ color: '#999', padding: '60px 0' }}>请先生成二维码</div>
)} )}
<Space style={{ marginTop: 24 }}> <Space style={{ marginTop: 24 }}>
<Button onClick={downloadQRCode}>下载二维码</Button> <Button onClick={downloadQRCode}>下载</Button>
<Button type="primary" loading={loading} onClick={saveToDatabase}>保存</Button> <Button type="primary" loading={loading} onClick={saveToDatabase}>保存</Button>
</Space> </Space>
</div> </div>
</Col> </Col>
</Row> </Row>
</Card> </Modal>
<Modal {/* 查看二维码 */}
open={manageVisible} <Modal open={viewModal} title="二维码详情" onCancel={() => setViewModal(false)} footer={null} width={400}>
title="数据管理" {viewRecord && (
width={900} <div style={{ textAlign: 'center' }}>
onCancel={() => setManageVisible(false)} <img src={viewRecord.qrCodeUrl} style={{ width: 200, height: 200 }} alt="qrcode" />
footer={<Button onClick={() => setManageVisible(false)}>关闭</Button>} <div style={{ marginTop: 16 }}>序列号:{viewRecord.serialNumber}</div>
destroyOnClose </div>
> )}
<DictManager </Modal>
title="机器人类型"
data={types}
fields={[
{ name: 'storeValue', label: '类型名称', required: true },
{ name: 'displayName', label: '存储值', required: true },
{ name: 'remark', label: '备注', required: false }
]}
onAdd={handleAddType}
onUpdate={handleUpdateType}
onDelete={deleteRobotTypeApi}
refresh={loadTypeList}
/>
<DictManager {/* 数据管理 */}
title="机器人型号" <Modal open={manageVisible} title="数据管理" width={900} onCancel={() => setManageVisible(false)} footer={<Button onClick={() => setManageVisible(false)}>关闭</Button>} destroyOnClose>
data={models} <DictManager title="机器人类型" data={types} fields={[{ name: 'storeValue', label: '类型名称', required: true }, { name: 'displayName', label: '存储值', required: true }, { name: 'remark', label: '备注' }]} onAdd={handleAddType} onUpdate={handleUpdateType} onDelete={deleteRobotTypeApi} refresh={loadTypeList} />
fields={[ <DictManager title="机器人型号" data={models} fields={[{ name: 'displayName', label: '型号名称', required: true }, { name: 'storeValue', label: '存储值', required: true }]} onAdd={handleAddModel} onUpdate={handleUpdateModel} onDelete={deleteRobotModelApi} refresh={loadModelList} />
{ name: 'displayName', label: '型号名称', required: true }, <DictManager title="配置" data={configs} fields={[{ name: 'displayName', label: '配置名称', required: true }, { name: 'storeValue', label: '存储值', required: true }]} onAdd={handleAddConfig} onUpdate={handleUpdateConfig} onDelete={deleteRobotConfigApi} refresh={loadConfigList} />
{ name: 'storeValue', label: '存储值', required: true },
]}
onAdd={handleAddModel}
onUpdate={handleUpdateModel}
onDelete={deleteRobotModelApi}
refresh={loadModelList}
/>
<DictManager
title="配置"
data={configs}
fields={[
{ name: 'displayName', label: '配置名称', required: true },
{ name: 'storeValue', label: '存储值', required: true },
]}
onAdd={handleAddConfig}
onUpdate={handleUpdateConfig}
onDelete={deleteRobotConfigApi}
refresh={loadConfigList}
/>
</Modal> </Modal>
</div> </div>
); );