二维码保存和 查询

This commit is contained in:
mmc
2026-05-15 12:59:51 +08:00
parent 8673baa57e
commit c01621d724
4 changed files with 92 additions and 24 deletions

View File

@@ -22,7 +22,8 @@ import {
addRobotConfigApi,
updateRobotConfigApi,
deleteRobotConfigApi,
saveCodeApi
saveCodeApi,
getCodeImgApi
} from '../../api/systemSetting';
const { Text } = Typography;
@@ -125,9 +126,16 @@ const SerialNumGenerate = () => {
const ts = Date.now();
const suffix = generateSerialSuffix();
// 序列号使用 国家简码+省份简码
const serialNumber = `${model}${config}-${country}-${province}-${ts}-${suffix}`;
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,
@@ -164,26 +172,37 @@ const SerialNumGenerate = () => {
// 保存到数据库
const saveToDatabase = async () => {
if (!serialNumber) return messageApi.warning('请先生成');
setLoading(true);
const data = {
serialNumber,
modelId: form.getFieldValue('model'),
configId: form.getFieldValue('config'),
typeId: form.getFieldValue('type'),
countryId: form.getFieldValue('country'),
provinceId: form.getFieldValue('province'),
qrCode: qrUrl,
qrJson: qrJson
}
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);
const data = {
serialNumber,
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) {
messageApi.success('保存成功');
setLoading(false);
} else {
messageApi.error('保存失败' + res?.msg);
}
} catch (e) {
setLoading(false);
messageApi.error('保存失败');
} finally {
setLoading(false);
@@ -195,11 +214,7 @@ const SerialNumGenerate = () => {
if (!queryCode) return messageApi.warning('请输入序列号');
setQueryLoading(true);
try {
const res = await request({
url: '/iot/device/querySerial',
method: 'get',
params: { sn: queryCode }
});
const res = await getCodeImgApi(queryCode);
if (res.data) {
setSerialNumber(res.data.serialNumber);
setQrUrl(res.data.qrCode);
@@ -314,7 +329,7 @@ const SerialNumGenerate = () => {
</Form.Item>
{/* 国家 显示中文 存简码 可清空 */}
<Form.Item name="country" label="国家" rules={[{ required: true }]}>
<Form.Item name="country" label="国家" >
<Select
placeholder="选择国家"
showSearch
@@ -334,7 +349,7 @@ const SerialNumGenerate = () => {
</Form.Item>
{/* 省份 显示中文 存简码 可清空 */}
<Form.Item name="province" label="省份" rules={[{ required: true }]}>
<Form.Item name="province" label="省份" >
<Select
placeholder="请先选择国家"
showSearch