xx
This commit is contained in:
@@ -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, Table, Popconfirm, Tag
|
Row, Col, Modal, Input, Table, Popconfirm, Checkbox
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import QRCode from 'qrcode';
|
import QRCode from 'qrcode';
|
||||||
import DictManager from "../DictManager";
|
import DictManager from "../DictManager";
|
||||||
@@ -47,13 +47,11 @@ const SerialNumGenerate = () => {
|
|||||||
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 [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 [addModalVisible, setAddModalVisible] = useState(false);
|
||||||
|
|
||||||
@@ -62,13 +60,16 @@ const SerialNumGenerate = () => {
|
|||||||
const [models, setModels] = useState([]);
|
const [models, setModels] = useState([]);
|
||||||
const [configs, setConfigs] = useState([]);
|
const [configs, setConfigs] = useState([]);
|
||||||
|
|
||||||
// 二维码列表数据
|
// 二维码列表
|
||||||
const [codeList, setCodeList] = useState([]);
|
const [codeList, setCodeList] = useState([]);
|
||||||
const [codeLoading, setCodeLoading] = useState(false);
|
const [codeLoading, setCodeLoading] = useState(false);
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const [pageSize] = useState(10);
|
const [pageSize] = useState(10);
|
||||||
const [total, setTotal] = useState(0);
|
const [total, setTotal] = useState(0);
|
||||||
|
|
||||||
|
// 多选删除
|
||||||
|
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
||||||
|
|
||||||
// 查看二维码弹窗
|
// 查看二维码弹窗
|
||||||
const [viewModal, setViewModal] = useState(false);
|
const [viewModal, setViewModal] = useState(false);
|
||||||
const [viewRecord, setViewRecord] = useState(null);
|
const [viewRecord, setViewRecord] = useState(null);
|
||||||
@@ -77,6 +78,16 @@ const SerialNumGenerate = () => {
|
|||||||
const countryNameMap = useRef({});
|
const countryNameMap = useRef({});
|
||||||
const provinceNameMap = useRef({});
|
const provinceNameMap = useRef({});
|
||||||
|
|
||||||
|
// 工具方法:解析 qrJson
|
||||||
|
const parseQrJson = (qrJson) => {
|
||||||
|
if (!qrJson) return {};
|
||||||
|
try {
|
||||||
|
return JSON.parse(qrJson);
|
||||||
|
} catch {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const countries = Country.getAllCountries();
|
const countries = Country.getAllCountries();
|
||||||
@@ -88,15 +99,12 @@ const SerialNumGenerate = () => {
|
|||||||
loadModelList();
|
loadModelList();
|
||||||
loadConfigList();
|
loadConfigList();
|
||||||
loadCodeList();
|
loadCodeList();
|
||||||
}, []);
|
}, [currentPage]);
|
||||||
|
|
||||||
// 国家切换
|
// 国家切换
|
||||||
const handleCountryChange = (countryCode) => {
|
const handleCountryChange = (countryCode) => {
|
||||||
const states = State.getStatesOfCountry(countryCode);
|
const states = State.getStatesOfCountry(countryCode);
|
||||||
setProvinces(states || []);
|
setProvinces(states || []);
|
||||||
states.forEach(item => {
|
|
||||||
provinceNameMap.current[item.isoCode] = item.name;
|
|
||||||
});
|
|
||||||
form.setFieldsValue({ province: undefined });
|
form.setFieldsValue({ province: undefined });
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -110,6 +118,7 @@ const SerialNumGenerate = () => {
|
|||||||
const rows = res.data.records || res.data || [];
|
const rows = res.data.records || res.data || [];
|
||||||
setCodeList(rows);
|
setCodeList(rows);
|
||||||
setTotal(res.data.total || rows.length);
|
setTotal(res.data.total || rows.length);
|
||||||
|
setSelectedRowKeys([]);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
} finally {
|
} finally {
|
||||||
@@ -128,6 +137,21 @@ const SerialNumGenerate = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 批量删除
|
||||||
|
const handleBatchDelete = async () => {
|
||||||
|
if (selectedRowKeys.length === 0) {
|
||||||
|
message.warning('请选择要删除的数据');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await delteCodesApi(selectedRowKeys.join(','));
|
||||||
|
messageApi.success('批量删除成功');
|
||||||
|
loadCodeList();
|
||||||
|
} catch (e) {
|
||||||
|
messageApi.error('批量删除失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 查看
|
// 查看
|
||||||
const handleView = (record) => {
|
const handleView = (record) => {
|
||||||
setViewRecord(record);
|
setViewRecord(record);
|
||||||
@@ -221,7 +245,7 @@ const SerialNumGenerate = () => {
|
|||||||
modelId: model?.id,
|
modelId: model?.id,
|
||||||
configId: config?.id,
|
configId: config?.id,
|
||||||
typeId: type?.id,
|
typeId: type?.id,
|
||||||
qrCodeUrl: qrUrl,
|
qrCode: qrUrl,
|
||||||
qrJson: qrJson
|
qrJson: qrJson
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -246,22 +270,19 @@ const SerialNumGenerate = () => {
|
|||||||
|
|
||||||
// 查询
|
// 查询
|
||||||
const handleQueryQRCode = async () => {
|
const handleQueryQRCode = async () => {
|
||||||
if (!queryCode) return messageApi.warning('请输入序列号');
|
// 从搜索表单中获取序列号
|
||||||
|
const serialNumber = searchForm.getFieldValue('serialNumber');
|
||||||
|
|
||||||
|
if (!serialNumber) {
|
||||||
|
loadCodeList();
|
||||||
|
return;
|
||||||
|
}
|
||||||
setQueryLoading(true);
|
setQueryLoading(true);
|
||||||
try {
|
try {
|
||||||
const res = await getCodeImgApi(queryCode);
|
const res = await getCodeImgApi(serialNumber);
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
setSerialNumber(res.data.serialNumber);
|
|
||||||
setQrUrl(res.data.qrCode);
|
setCodeList([res.data]);
|
||||||
setQrJson(res.data.qrJson);
|
|
||||||
form.setFieldsValue({
|
|
||||||
model: res.data.model,
|
|
||||||
config: res.data.config,
|
|
||||||
type: res.data.type,
|
|
||||||
country: res.data.country,
|
|
||||||
province: res.data.province
|
|
||||||
});
|
|
||||||
messageApi.success('查询成功');
|
|
||||||
} else {
|
} else {
|
||||||
messageApi.warning('未查询到数据');
|
messageApi.warning('未查询到数据');
|
||||||
}
|
}
|
||||||
@@ -294,29 +315,48 @@ const SerialNumGenerate = () => {
|
|||||||
|
|
||||||
// 表格列
|
// 表格列
|
||||||
const columns = [
|
const columns = [
|
||||||
{ title: 'ID', dataIndex: 'id', key: 'id', width: 70 },
|
{
|
||||||
|
title: '序号',
|
||||||
|
key: 'idx',
|
||||||
|
width: 70,
|
||||||
|
render: (_, __, index) => (currentPage - 1) * pageSize + index + 1
|
||||||
|
},
|
||||||
{ title: '序列号', width: 380, dataIndex: 'serialNumber', key: 'sn', ellipsis: true },
|
{ title: '序列号', width: 380, dataIndex: 'serialNumber', key: 'sn', ellipsis: true },
|
||||||
{
|
{
|
||||||
title: '型号',
|
title: '型号',
|
||||||
key: 'model',
|
key: 'model',
|
||||||
render: (_, r) => models.find(m => m.id === r.modelId)?.modelName || '-'
|
render: (_, r) => parseQrJson(r.qrJson).model || '-'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '配置',
|
title: '配置',
|
||||||
key: 'config',
|
key: 'config',
|
||||||
render: (_, r) => configs.find(c => c.id === r.configId)?.configName || '-'
|
render: (_, r) => parseQrJson(r.qrJson).config || '-'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类型',
|
||||||
|
key: 'type',
|
||||||
|
render: (_, r) => parseQrJson(r.qrJson).type || '-'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '国家',
|
||||||
|
key: 'country',
|
||||||
|
render: (_, r) => parseQrJson(r.qrJson).countryFullName || '-'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '省份',
|
||||||
|
key: 'province',
|
||||||
|
render: (_, r) => parseQrJson(r.qrJson).provinceFullName || '-'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '二维码',
|
title: '二维码',
|
||||||
key: 'img',
|
key: 'img',
|
||||||
width: 100,
|
width: 100,
|
||||||
render: (_, r) => r.qrCodeUrl && <img src={r.qrCodeUrl} style={{ width: 50, height: 50 }} alt="qrcode" />
|
render: (_, r) => r.qrCodeBase64 && <img src={r.qrCodeBase64} style={{ width: 50, height: 50 }} alt="qrcode" />
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'opt',
|
key: 'opt',
|
||||||
width: 180,
|
width: 180,
|
||||||
fixed: "right",
|
|
||||||
render: (_, r) => (
|
render: (_, r) => (
|
||||||
<Space>
|
<Space>
|
||||||
<Button type="link" onClick={() => handleView(r)}>查看</Button>
|
<Button type="link" onClick={() => handleView(r)}>查看</Button>
|
||||||
@@ -331,27 +371,38 @@ const SerialNumGenerate = () => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// 多选配置
|
||||||
|
const rowSelection = {
|
||||||
|
selectedRowKeys,
|
||||||
|
onChange: setSelectedRowKeys
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ padding: '0px 20px 40px', minHeight: '100vh' }}>
|
<div style={{ padding: '0px 20px 40px', minHeight: '100vh' }}>
|
||||||
{contextHolder}
|
{contextHolder}
|
||||||
|
|
||||||
<Card style={{ maxWidth: 1400, margin: '0 auto' }}
|
<Card
|
||||||
|
style={{ maxWidth: '100%', margin: '0 auto' }}
|
||||||
title="机器人二维码管理"
|
title="机器人二维码管理"
|
||||||
extra={
|
extra={
|
||||||
<Space>
|
<Space wrap>
|
||||||
<Button type="primary" onClick={() => setAddModalVisible(true)}>新增</Button>
|
<Button type="primary" onClick={() => setAddModalVisible(true)}>新增</Button>
|
||||||
<Button onClick={() => setManageVisible(true)}>数据管理</Button>
|
<Button onClick={() => setManageVisible(true)}>数据管理</Button>
|
||||||
|
<Popconfirm title="确定删除选中项?" onConfirm={handleBatchDelete}>
|
||||||
|
<Button danger disabled={selectedRowKeys.length === 0}>批量删除</Button>
|
||||||
|
</Popconfirm>
|
||||||
</Space>
|
</Space>
|
||||||
}>
|
}
|
||||||
|
>
|
||||||
|
|
||||||
{/* 筛选栏 */}
|
{/* 筛选栏 */}
|
||||||
<Form form={searchForm} layout="inline" style={{ marginBottom: 16 }}>
|
<Form form={searchForm} layout="inline" style={{ marginBottom: 16 }}>
|
||||||
<Form.Item name="serialNumber" label="序列号">
|
<Form.Item name="serialNumber" label="序列号">
|
||||||
<Input placeholder="请输入序列号" style={{ width: 220 }} />
|
<Input placeholder="请输入序列号" style={{ width: 420 }} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
<Space>
|
<Space wrap>
|
||||||
<Button type="primary" onClick={loadCodeList}>搜索</Button>
|
<Button type="primary" onClick={handleQueryQRCode}>搜索</Button>
|
||||||
<Button onClick={() => { searchForm.resetFields(); loadCodeList(); }}>重置</Button>
|
<Button onClick={() => { searchForm.resetFields(); loadCodeList(); }}>重置</Button>
|
||||||
</Space>
|
</Space>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -363,15 +414,18 @@ const SerialNumGenerate = () => {
|
|||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={codeList}
|
dataSource={codeList}
|
||||||
loading={codeLoading}
|
loading={codeLoading}
|
||||||
|
rowSelection={rowSelection}
|
||||||
pagination={{ current: currentPage, pageSize, total, onChange: setCurrentPage }}
|
pagination={{ current: currentPage, pageSize, total, onChange: setCurrentPage }}
|
||||||
|
style={{ width: '100%' }}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{/* 新增弹窗 = 原来的生成二维码页面 */}
|
{/* 新增弹窗 */}
|
||||||
<Modal
|
<Modal
|
||||||
title="生成机器人二维码"
|
title="生成机器人二维码"
|
||||||
open={addModalVisible}
|
open={addModalVisible}
|
||||||
width={900}
|
width="90%"
|
||||||
|
style={{ maxWidth: 900 }}
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
setAddModalVisible(false);
|
setAddModalVisible(false);
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
@@ -382,7 +436,7 @@ const SerialNumGenerate = () => {
|
|||||||
destroyOnClose
|
destroyOnClose
|
||||||
>
|
>
|
||||||
<Row gutter={[24, 16]}>
|
<Row gutter={[24, 16]}>
|
||||||
<Col xs={24} md={14}>
|
<Col xs={24} lg={14}>
|
||||||
<Form form={form} labelCol={{ md: 5 }} wrapperCol={{ md: 19 }} size="large">
|
<Form form={form} labelCol={{ md: 5 }} wrapperCol={{ md: 19 }} size="large">
|
||||||
<Form.Item name="model" label="型号" rules={[{ required: true }]}>
|
<Form.Item name="model" label="型号" rules={[{ required: true }]}>
|
||||||
<Select placeholder="选择型号" showSearch>
|
<Select placeholder="选择型号" showSearch>
|
||||||
@@ -415,15 +469,15 @@ const SerialNumGenerate = () => {
|
|||||||
</Form>
|
</Form>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col xs={24} md={10}>
|
<Col xs={24} lg={10}>
|
||||||
<div style={{ padding: 20, background: '#fafafa', borderRadius: 12, border: '1px dashed #d9d9d9', alignItems: 'center', minHeight: 400 }}>
|
<div style={{ padding: 20, background: '#fafafa', borderRadius: 12, border: '1px dashed #d9d9d9', display: 'flex', flexDirection: 'column', alignItems: 'center', minHeight: 400 }}>
|
||||||
{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>序列号:{serialNumber}</Text>
|
<Text strong>序列号:{serialNumber}</Text>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{qrUrl ? (
|
{qrUrl ? (
|
||||||
<img src={qrUrl} style={{ width: 240, height: 240 }} alt="qrcode" />
|
<img src={qrUrl} style={{ width: 240, height: 240, maxWidth: '100%' }} alt="qrcode" />
|
||||||
) : (
|
) : (
|
||||||
<div style={{ color: '#999', padding: '60px 0' }}>请先生成二维码</div>
|
<div style={{ color: '#999', padding: '60px 0' }}>请先生成二维码</div>
|
||||||
)}
|
)}
|
||||||
@@ -440,14 +494,14 @@ const SerialNumGenerate = () => {
|
|||||||
<Modal open={viewModal} title="二维码详情" onCancel={() => setViewModal(false)} footer={null} width={400}>
|
<Modal open={viewModal} title="二维码详情" onCancel={() => setViewModal(false)} footer={null} width={400}>
|
||||||
{viewRecord && (
|
{viewRecord && (
|
||||||
<div style={{ textAlign: 'center' }}>
|
<div style={{ textAlign: 'center' }}>
|
||||||
<img src={viewRecord.qrCodeUrl} style={{ width: 200, height: 200 }} alt="qrcode" />
|
<img src={viewRecord.qrCodeUrl} style={{ width: 200, height: 200, maxWidth: '100%' }} alt="qrcode" />
|
||||||
<div style={{ marginTop: 16 }}>序列号:{viewRecord.serialNumber}</div>
|
<div style={{ marginTop: 16 }}>序列号:{viewRecord.serialNumber}</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
{/* 数据管理 */}
|
{/* 数据管理 */}
|
||||||
<Modal open={manageVisible} title="数据管理" width={900} onCancel={() => setManageVisible(false)} footer={<Button onClick={() => setManageVisible(false)}>关闭</Button>} destroyOnClose>
|
<Modal open={manageVisible} title="数据管理" width="90%" style={{ maxWidth: 900 }} onCancel={() => setManageVisible(false)} footer={<Button onClick={() => setManageVisible(false)}>关闭</Button>} destroyOnClose>
|
||||||
<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} />
|
<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} />
|
||||||
<DictManager title="机器人型号" data={models} fields={[{ name: 'displayName', label: '型号名称', required: true }, { name: 'storeValue', label: '存储值', required: true }]} onAdd={handleAddModel} onUpdate={handleUpdateModel} onDelete={deleteRobotModelApi} refresh={loadModelList} />
|
<DictManager title="机器人型号" data={models} fields={[{ name: 'displayName', label: '型号名称', required: true }, { 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} />
|
<DictManager title="配置" data={configs} fields={[{ name: 'displayName', label: '配置名称', required: true }, { name: 'storeValue', label: '存储值', required: true }]} onAdd={handleAddConfig} onUpdate={handleUpdateConfig} onDelete={deleteRobotConfigApi} refresh={loadConfigList} />
|
||||||
|
|||||||
Reference in New Issue
Block a user