机器人序列号 接口初始化
This commit is contained in:
@@ -40,4 +40,6 @@ export function getJurisdiction(data) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
262
src/api/systemSetting.ts
Normal file
262
src/api/systemSetting.ts
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
import request from './request';
|
||||||
|
|
||||||
|
// ==================== 机器人类型 ====================
|
||||||
|
|
||||||
|
// 查询机器人类型列表
|
||||||
|
export function getRobotTypeListApi(params) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/type/list',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询机器人类型详情
|
||||||
|
export function getRobotTypeDetailApi(id) {
|
||||||
|
return request({
|
||||||
|
url: `/system/robot/type/${id}`,
|
||||||
|
method: 'get'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增机器人类型
|
||||||
|
export function addRobotTypeApi(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/type',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改机器人类型
|
||||||
|
export function updateRobotTypeApi(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/type',
|
||||||
|
method: 'put',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除机器人类型
|
||||||
|
export function deleteRobotTypeApi(ids) {
|
||||||
|
return request({
|
||||||
|
url: `/system/robot/type/${ids}`,
|
||||||
|
method: 'delete'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 机器人省份 ====================
|
||||||
|
|
||||||
|
// 分页查询省份
|
||||||
|
export function getRobotProvincePageApi(params) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/province/page',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询省份列表
|
||||||
|
export function getRobotProvinceListApi(params) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/province/list',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询省份详情
|
||||||
|
export function getRobotProvinceDetailApi(id) {
|
||||||
|
return request({
|
||||||
|
url: `/system/robot/province/${id}`,
|
||||||
|
method: 'get'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增省份
|
||||||
|
export function addRobotProvinceApi(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/province',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改省份
|
||||||
|
export function updateRobotProvinceApi(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/province',
|
||||||
|
method: 'put',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除省份
|
||||||
|
export function deleteRobotProvinceApi(ids) {
|
||||||
|
return request({
|
||||||
|
url: `/system/robot/province/${ids}`,
|
||||||
|
method: 'delete'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分页查询机器人型号
|
||||||
|
export function getRobotModelPageApi(params) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/model/page',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询机器人型号列表(不分页)
|
||||||
|
export function getRobotModelListApi(params) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/model/list',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询机器人型号详情
|
||||||
|
export function getRobotModelDetailApi(id) {
|
||||||
|
return request({
|
||||||
|
url: `/system/robot/model/${id}`,
|
||||||
|
method: 'get'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增机器人型号
|
||||||
|
export function addRobotModel(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/model',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改机器人型号
|
||||||
|
export function updateRobotModelApi(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/model',
|
||||||
|
method: 'put',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除机器人型号
|
||||||
|
export function deleteRobotModelApi(ids) {
|
||||||
|
return request({
|
||||||
|
url: `/system/robot/model/${ids}`,
|
||||||
|
method: 'delete'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 机器人国家 ====================
|
||||||
|
|
||||||
|
// 分页查询国家
|
||||||
|
export function getRobotCountryPageApi(params) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/country/page',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询国家列表(不分页)
|
||||||
|
export function getRobotCountryListApi(params) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/country/list',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询国家详情
|
||||||
|
export function getRobotCountryDetailApi(id) {
|
||||||
|
return request({
|
||||||
|
url: `/system/robot/country/${id}`,
|
||||||
|
method: 'get'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增国家
|
||||||
|
export function addRobotCountryApi(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/country',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改国家
|
||||||
|
export function updateRobotCountryApi(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/country',
|
||||||
|
method: 'put',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除国家
|
||||||
|
export function deleteRobotCountryApi(ids) {
|
||||||
|
return request({
|
||||||
|
url: `/system/robot/country/${ids}`,
|
||||||
|
method: 'delete'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== 机器人配置 ====================
|
||||||
|
|
||||||
|
// 分页查询机器人配置
|
||||||
|
export function getRobotConfigPageApi(params) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/config/page',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询机器人配置列表(不分页)
|
||||||
|
export function getRobotConfigListApi(params) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/config/list',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询机器人配置详情
|
||||||
|
export function getRobotConfigDetailApi(id) {
|
||||||
|
return request({
|
||||||
|
url: `/system/robot/config/${id}`,
|
||||||
|
method: 'get'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增机器人配置
|
||||||
|
export function addRobotConfigApi(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/config',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改机器人配置
|
||||||
|
export function updateRobotConfigApi(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/robot/config',
|
||||||
|
method: 'put',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除机器人配置
|
||||||
|
export function deleteRobotConfigApi(ids) {
|
||||||
|
return request({
|
||||||
|
url: `/system/robot/config/${ids}`,
|
||||||
|
method: 'delete'
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,22 +1,34 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Table, Input, Button, Form, Space, Card, Modal
|
Table, Input, Button, Form, Space, Card, Modal, message
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import { EditOutlined, DeleteOutlined } from '@ant-design/icons';
|
import { EditOutlined, DeleteOutlined } from '@ant-design/icons';
|
||||||
|
|
||||||
|
|
||||||
// 🔥 组件
|
|
||||||
const DictManager = ({
|
const DictManager = ({
|
||||||
title,
|
title,
|
||||||
data,
|
data,
|
||||||
|
fields = [
|
||||||
|
{ name: 'storeValue', label: '存储值', required: true },
|
||||||
|
{ name: 'typeName', label: '名称', required: true },
|
||||||
|
{ name: 'remark', label: '备注', required: false }
|
||||||
|
],
|
||||||
onAdd,
|
onAdd,
|
||||||
onUpdate,
|
onUpdate,
|
||||||
onDelete,
|
onDelete,
|
||||||
|
refresh,
|
||||||
loading,
|
loading,
|
||||||
}) => {
|
}) => {
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [editing, setEditing] = useState(null);
|
const [editing, setEditing] = useState(null);
|
||||||
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
|
|
||||||
|
// 打开新增
|
||||||
|
const handleAddNew = () => {
|
||||||
|
setEditing(null);
|
||||||
|
form.resetFields();
|
||||||
|
setVisible(true);
|
||||||
|
};
|
||||||
|
|
||||||
// 编辑
|
// 编辑
|
||||||
const handleEdit = (record) => {
|
const handleEdit = (record) => {
|
||||||
@@ -25,24 +37,38 @@ const DictManager = ({
|
|||||||
setVisible(true);
|
setVisible(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 提交
|
const handleSubmit = async () => {
|
||||||
const handleSubmit = () => {
|
try {
|
||||||
form.validateFields().then(values => {
|
const values = await form.validateFields();
|
||||||
|
let res;
|
||||||
|
|
||||||
if (editing) {
|
if (editing) {
|
||||||
onUpdate({ ...editing, ...values });
|
res = await onUpdate({ ...editing, ...values });
|
||||||
} else {
|
} else {
|
||||||
onAdd({ id: Date.now(), ...values });
|
res = await onAdd(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (res?.code == 200) {
|
||||||
|
messageApi.success(editing ? "编辑成功" : '新增成功');
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
setEditing(null);
|
setEditing(null);
|
||||||
});
|
refresh?.();
|
||||||
|
} else {
|
||||||
|
messageApi.error(res?.msg || '操作失败');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
messageApi.error('提交失败');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 表格列
|
// 表格列
|
||||||
const columns = [
|
const columns = [
|
||||||
{ title: '存储值', dataIndex: 'value', key: 'value' },
|
...fields.map(item => ({
|
||||||
{ title: '显示名', dataIndex: 'label', key: 'label' },
|
title: item.label,
|
||||||
|
dataIndex: item.name,
|
||||||
|
key: item.name,
|
||||||
|
})),
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
@@ -51,7 +77,24 @@ const DictManager = ({
|
|||||||
<Button type="link" icon={<EditOutlined />} onClick={() => handleEdit(record)}>
|
<Button type="link" icon={<EditOutlined />} onClick={() => handleEdit(record)}>
|
||||||
编辑
|
编辑
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="link" danger icon={<DeleteOutlined />} onClick={() => onDelete(record.id)}>
|
<Button
|
||||||
|
type="link"
|
||||||
|
danger
|
||||||
|
icon={<DeleteOutlined />}
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
const res = await onDelete(record.id);
|
||||||
|
if (res?.code === 200) {
|
||||||
|
messageApi.success('删除成功');
|
||||||
|
refresh?.();
|
||||||
|
} else {
|
||||||
|
messageApi.error(res?.msg || '删除失败');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
messageApi.error('删除失败');
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
删除
|
删除
|
||||||
</Button>
|
</Button>
|
||||||
</Space>
|
</Space>
|
||||||
@@ -61,15 +104,8 @@ const DictManager = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Card size="small" title={title} style={{ marginBottom: 16 }}>
|
<Card size="small" title={title} style={{ marginBottom: 16 }}>
|
||||||
<Button
|
{contextHolder}
|
||||||
type="primary"
|
<Button type="primary" size="small" onClick={handleAddNew}>
|
||||||
size="small"
|
|
||||||
onClick={() => {
|
|
||||||
setEditing(null);
|
|
||||||
form.resetFields();
|
|
||||||
setVisible(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
新增
|
新增
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
@@ -90,15 +126,20 @@ const DictManager = ({
|
|||||||
confirmLoading={loading}
|
confirmLoading={loading}
|
||||||
>
|
>
|
||||||
<Form form={form} layout="vertical">
|
<Form form={form} layout="vertical">
|
||||||
<Form.Item name="value" label="存储值" rules={[{ required: true, message: '请输入' }]}>
|
{fields.map(item => (
|
||||||
<Input />
|
<Form.Item
|
||||||
</Form.Item>
|
key={item.name}
|
||||||
<Form.Item name="label" label="显示名称" rules={[{ required: true, message: '请输入' }]}>
|
name={item.name}
|
||||||
|
label={item.label}
|
||||||
|
rules={[{ required: item.required, message: `请输入${item.label}` }]}
|
||||||
|
>
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
))}
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DictManager;
|
export default DictManager;
|
||||||
|
|||||||
@@ -1,48 +1,28 @@
|
|||||||
import React, { useState, useRef } 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
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import QRCode from 'qrcode';
|
import QRCode from 'qrcode';
|
||||||
import axios from 'axios';
|
|
||||||
import DictManager from "../DictManager";
|
import DictManager from "../DictManager";
|
||||||
|
import request from '../../api/request';
|
||||||
|
|
||||||
|
// 接口导入
|
||||||
|
import {
|
||||||
|
getRobotTypeListApi,
|
||||||
|
addRobotTypeApi,
|
||||||
|
updateRobotTypeApi,
|
||||||
|
deleteRobotTypeApi,
|
||||||
|
getRobotProvinceListApi,
|
||||||
|
addRobotProvinceApi,
|
||||||
|
updateRobotProvinceApi,
|
||||||
|
deleteRobotProvinceApi,
|
||||||
|
getRobotModelPageApi,
|
||||||
|
addRebotModel
|
||||||
|
} from '../../api/systemSetting';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
// 字典数据
|
|
||||||
const useDict = () => {
|
|
||||||
const [types, setTypes] = useState([
|
|
||||||
{ id: 1, value: 'mower', label: '割草机' },
|
|
||||||
{ id: 2, value: 'vacuum', label: '巡检机' },
|
|
||||||
]);
|
|
||||||
const [models, setModels] = useState([
|
|
||||||
{ id: 1, value: 'MC700', label: 'MC700' },
|
|
||||||
{ id: 2, value: 'MC800', label: 'MC800' },
|
|
||||||
]);
|
|
||||||
const [configs, setConfigs] = useState([
|
|
||||||
{ id: 1, value: 'AIR', label: 'AIR' },
|
|
||||||
{ id: 2, value: 'PRO', label: 'PRO' },
|
|
||||||
]);
|
|
||||||
const [countries, setCountries] = useState([
|
|
||||||
{ id: 1, value: 'CN', label: '中国' },
|
|
||||||
{ id: 2, value: 'US', label: '美国' },
|
|
||||||
]);
|
|
||||||
const [provinces, setProvinces] = useState([
|
|
||||||
{ id: 1, value: 'JS', label: '江苏' },
|
|
||||||
{ id: 2, value: 'ZJ', label: '浙江' },
|
|
||||||
{ id: 3, value: 'GD', label: '广东' },
|
|
||||||
]);
|
|
||||||
|
|
||||||
return {
|
|
||||||
types, setTypes,
|
|
||||||
models, setModels,
|
|
||||||
configs, setConfigs,
|
|
||||||
countries, setCountries,
|
|
||||||
provinces, setProvinces,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// 主组件
|
|
||||||
const SerialNumGenerate = () => {
|
const SerialNumGenerate = () => {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [qrUrl, setQrUrl] = useState('');
|
const [qrUrl, setQrUrl] = useState('');
|
||||||
@@ -51,62 +31,90 @@ const SerialNumGenerate = () => {
|
|||||||
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 {
|
// 接口数据
|
||||||
types,
|
const [types, setTypes] = useState([]);
|
||||||
models,
|
const [models, setModels] = useState([]);
|
||||||
configs,
|
const [provinces, setProvinces] = useState([]);
|
||||||
countries,
|
const [countries] = useState([
|
||||||
provinces
|
{ id: 1, value: 'CN', label: '中国' },
|
||||||
} = useDict();
|
{ id: 2, value: 'US', label: '美国' },
|
||||||
|
]);
|
||||||
|
const [configs] = useState([
|
||||||
|
{ id: 1, value: 'AIR', label: 'AIR' },
|
||||||
|
{ id: 2, value: 'PRO', label: 'PRO' },
|
||||||
|
]);
|
||||||
|
|
||||||
// 生成 8 位随机序号 + 2 位校验码
|
// 初始化加载
|
||||||
|
useEffect(() => {
|
||||||
|
loadTypeList();
|
||||||
|
loadModelList();
|
||||||
|
loadProvinceList();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 加载机器人类型
|
||||||
|
const loadTypeList = async () => {
|
||||||
|
try {
|
||||||
|
const res = await getRobotTypeListApi({});
|
||||||
|
setTypes(res.rows || []);
|
||||||
|
} catch (e) {
|
||||||
|
message.error('加载类型失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 加载机器人型号
|
||||||
|
const loadModelList = async () => {
|
||||||
|
try {
|
||||||
|
const res = await getRobotModelPageApi({ pageNum: 1, pageSize: 100 });
|
||||||
|
setModels(res.rows || []);
|
||||||
|
} catch (e) {
|
||||||
|
message.error('加载型号失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 加载省份
|
||||||
|
const loadProvinceList = async () => {
|
||||||
|
try {
|
||||||
|
const res = await getRobotProvinceListApi({});
|
||||||
|
setProvinces(res.rows || []);
|
||||||
|
} catch (e) {
|
||||||
|
message.error('加载省份失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 生成序号
|
||||||
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');
|
||||||
return `${num}-${check}`;
|
return `${num}-${check}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 生成序列号 + JSON二维码
|
// 生成二维码
|
||||||
const generateQRCode = async () => {
|
const generateQRCode = async () => {
|
||||||
try {
|
try {
|
||||||
const values = await form.validateFields();
|
const values = await form.validateFields();
|
||||||
const { model, config, type, country, province } = values;
|
const { model, config, type, country, province } = values;
|
||||||
const ts = Date.now();
|
const ts = Date.now();
|
||||||
const suffix = generateSerialSuffix();
|
const suffix = generateSerialSuffix();
|
||||||
|
|
||||||
// 1. 生成序列号
|
|
||||||
const sn = `${model}${config}-${country}-${province}-${ts}-${suffix}`;
|
const sn = `${model}${config}-${country}-${province}-${ts}-${suffix}`;
|
||||||
setSerialNumber(sn);
|
|
||||||
|
|
||||||
// 2. 二维码内容 = JSON
|
const qrData = { model, config, type, country, province, sn };
|
||||||
const qrData = {
|
|
||||||
model,
|
|
||||||
config,
|
|
||||||
type,
|
|
||||||
country,
|
|
||||||
province,
|
|
||||||
sn: sn
|
|
||||||
};
|
|
||||||
const qrContent = JSON.stringify(qrData, null, 2);
|
const qrContent = JSON.stringify(qrData, null, 2);
|
||||||
setQrJson(qrContent);
|
|
||||||
|
|
||||||
// 3. 生成二维码
|
|
||||||
const url = await QRCode.toDataURL(qrContent);
|
const url = await QRCode.toDataURL(qrContent);
|
||||||
setQrUrl(url);
|
|
||||||
|
|
||||||
|
setSerialNumber(sn);
|
||||||
|
setQrJson(qrContent);
|
||||||
|
setQrUrl(url);
|
||||||
message.success('生成成功!');
|
message.success('生成成功!');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
message.error('请完善信息');
|
message.error('请完善信息');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 下载二维码
|
// 下载
|
||||||
const downloadQRCode = () => {
|
const downloadQRCode = () => {
|
||||||
if (!qrRef.current || !qrUrl) {
|
if (!qrRef.current || !qrUrl) {
|
||||||
message.warning('请先生成二维码');
|
message.warning('请先生成二维码');
|
||||||
@@ -118,49 +126,116 @@ const SerialNumGenerate = () => {
|
|||||||
link.click();
|
link.click();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 保存到数据库
|
// 保存序列号
|
||||||
const saveToDatabase = async () => {
|
const saveToDatabase = async () => {
|
||||||
if (!serialNumber || !qrUrl) {
|
if (!serialNumber) return message.warning('请先生成');
|
||||||
message.warning('请先生成二维码');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
await axios.post('/api/save-qrcode', {
|
await request({
|
||||||
|
url: '/iot/device/saveSerial',
|
||||||
|
method: 'post',
|
||||||
|
data: {
|
||||||
serialNumber,
|
serialNumber,
|
||||||
|
model: form.getFieldValue('model'),
|
||||||
|
config: form.getFieldValue('config'),
|
||||||
|
type: form.getFieldValue('type'),
|
||||||
|
country: form.getFieldValue('country'),
|
||||||
|
province: form.getFieldValue('province'),
|
||||||
qrCode: qrUrl,
|
qrCode: qrUrl,
|
||||||
qrJson: qrJson,
|
qrJson: qrJson
|
||||||
...form.getFieldsValue()
|
}
|
||||||
});
|
});
|
||||||
message.success('保存成功');
|
message.success('保存成功');
|
||||||
} catch {
|
} catch (e) {
|
||||||
message.error('保存失败');
|
message.error('保存失败');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 查询二维码
|
// 查询
|
||||||
const handleQueryQRCode = async () => {
|
const handleQueryQRCode = async () => {
|
||||||
if (!queryCode) return message.warning('请输入序列号');
|
if (!queryCode) return message.warning('请输入序列号');
|
||||||
setQueryLoading(true);
|
setQueryLoading(true);
|
||||||
try {
|
try {
|
||||||
const res = await axios.get('/api/query-qrcode', { params: { sn: queryCode } });
|
const res = await request({
|
||||||
if (res.data?.qrUrl) {
|
url: '/iot/device/querySerial',
|
||||||
setQrUrl(res.data.qrUrl);
|
method: 'get',
|
||||||
setQrJson(res.data.qrJson || '');
|
params: { sn: queryCode }
|
||||||
setSerialNumber(res.data.serialNumber || '');
|
});
|
||||||
|
if (res.data) {
|
||||||
|
setSerialNumber(res.data.serialNumber);
|
||||||
|
setQrUrl(res.data.qrCode);
|
||||||
|
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
|
||||||
|
});
|
||||||
message.success('查询成功');
|
message.success('查询成功');
|
||||||
} else {
|
} else {
|
||||||
message.warning('未找到该序列号');
|
message.warning('未查询到数据');
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (e) {
|
||||||
message.error('查询失败');
|
message.error('查询失败');
|
||||||
} finally {
|
} finally {
|
||||||
setQueryLoading(false);
|
setQueryLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ==================== 机器人类型:增删改查 ====================
|
||||||
|
const handleAddType = async (values) => {
|
||||||
|
const params = {
|
||||||
|
typeName: values.typeName,
|
||||||
|
storeValue: values.storeValue,
|
||||||
|
remark: values.remark || ''
|
||||||
|
};
|
||||||
|
return await addRobotTypeApi(params);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUpdateType = async (values) => {
|
||||||
|
const params = {
|
||||||
|
id: values.id,
|
||||||
|
typeName: values.typeName,
|
||||||
|
storeValue: values.storeValue,
|
||||||
|
remark: values.remark || ''
|
||||||
|
};
|
||||||
|
return await updateRobotTypeApi(params);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ==================== 机器人型号:增删改查 ====================
|
||||||
|
const handleAddModel = async (values) => {
|
||||||
|
const params = {
|
||||||
|
modelName: values.modelName,
|
||||||
|
storeValue: values.storeValue,
|
||||||
|
remark: values.remark || ''
|
||||||
|
};
|
||||||
|
return await addRebotModel(params)
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUpdateModel = async (values) => {
|
||||||
|
const params = {
|
||||||
|
id: values.id,
|
||||||
|
modelName: values.modelName,
|
||||||
|
storeValue: values.storeValue,
|
||||||
|
remark: values.remark || ''
|
||||||
|
};
|
||||||
|
return await request({
|
||||||
|
url: '/system/robot/model',
|
||||||
|
method: 'put',
|
||||||
|
data: params
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteModel = async (id) => {
|
||||||
|
return await request({
|
||||||
|
url: `/system/robot/model/${id}`,
|
||||||
|
method: 'delete'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ padding: '0 20px', minHeight: '100vh' }}>
|
<div style={{ padding: '0 20px', minHeight: '100vh' }}>
|
||||||
<Card
|
<Card
|
||||||
@@ -169,12 +244,13 @@ const SerialNumGenerate = () => {
|
|||||||
extra={<Button type="primary" onClick={() => setManageVisible(true)}>数据管理</Button>}
|
extra={<Button type="primary" onClick={() => setManageVisible(true)}>数据管理</Button>}
|
||||||
>
|
>
|
||||||
<Row gutter={[32, 24]}>
|
<Row gutter={[32, 24]}>
|
||||||
{/* 左侧表单 */}
|
|
||||||
<Col xs={24} md={14}>
|
<Col xs={24} md={14}>
|
||||||
<Form form={form} initialValues={{ type: 'mower' }} labelCol={{ md: 5 }} wrapperCol={{ md: 19 }} size="large">
|
<Form form={form} initialValues={{ type: 'mower' }} 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="选择型号">
|
<Select placeholder="选择型号">
|
||||||
{models.map(m => <Select.Option key={m.value} value={m.value}>{m.label}</Select.Option>)}
|
{models.map(m => (
|
||||||
|
<Select.Option key={m.id} value={m.storeValue}>{m.modelName}</Select.Option>
|
||||||
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
@@ -186,7 +262,9 @@ const SerialNumGenerate = () => {
|
|||||||
|
|
||||||
<Form.Item name="type" label="类型" rules={[{ required: true }]}>
|
<Form.Item name="type" label="类型" rules={[{ required: true }]}>
|
||||||
<Select placeholder="选择类型">
|
<Select placeholder="选择类型">
|
||||||
{types.map(t => <Select.Option key={t.value} value={t.value}>{t.label}</Select.Option>)}
|
{types.map(t => (
|
||||||
|
<Select.Option key={t.id} value={t.storeValue}>{t.typeName}</Select.Option>
|
||||||
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
@@ -198,7 +276,9 @@ const SerialNumGenerate = () => {
|
|||||||
|
|
||||||
<Form.Item name="province" label="省份" rules={[{ required: true }]}>
|
<Form.Item name="province" label="省份" rules={[{ required: true }]}>
|
||||||
<Select placeholder="选择省份">
|
<Select placeholder="选择省份">
|
||||||
{provinces.map(p => <Select.Option key={p.value} value={p.value}>{p.label}</Select.Option>)}
|
{provinces.map(p => (
|
||||||
|
<Select.Option key={p.id} value={p.storeValue}>{p.typeName}</Select.Option>
|
||||||
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
@@ -209,18 +289,13 @@ const SerialNumGenerate = () => {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
{/* 查询模块(已加回) */}
|
|
||||||
<Card size="small" title="查询历史二维码" style={{ marginTop: 20 }}>
|
<Card size="small" title="查询历史二维码" style={{ marginTop: 20 }}>
|
||||||
<Space style={{ width: '100%' }}>
|
<Space style={{ width: '100%' }}>
|
||||||
<Input
|
<Input
|
||||||
value={queryCode}
|
value={queryCode}
|
||||||
onChange={(e) => setQueryCode(e.target.value)}
|
onChange={(e) => setQueryCode(e.value)}
|
||||||
placeholder="输入序列号查询"
|
placeholder="输入序列号查询"
|
||||||
style={
|
style={{ width: '300px' }}
|
||||||
{
|
|
||||||
width: '300px'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<Button type="primary" loading={queryLoading} onClick={handleQueryQRCode}>
|
<Button type="primary" loading={queryLoading} onClick={handleQueryQRCode}>
|
||||||
查询
|
查询
|
||||||
@@ -229,25 +304,19 @@ const SerialNumGenerate = () => {
|
|||||||
</Card>
|
</Card>
|
||||||
</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',
|
padding: 20, background: '#fafafa', borderRadius: 12, border: '1px dashed #d9d9d9',
|
||||||
display: 'flex', flexDirection: 'column', alignItems: 'center', minHeight: 480
|
display: 'flex', flexDirection: 'column', alignItems: 'center', minHeight: 480
|
||||||
}}>
|
}}>
|
||||||
{serialNumber && (
|
{serialNumber && (
|
||||||
<div style={{
|
<div style={{ padding: 12, background: '#e6f7ff', borderRadius: 8, width: '100%', textAlign: 'center', marginBottom: 20 }}>
|
||||||
padding: 12, background: '#e6f7ff', borderRadius: 8,
|
<Text strong style={{ fontSize: 15 }}>序列号:{serialNumber}</Text>
|
||||||
width: '100%', textAlign: 'center', marginBottom: 20
|
|
||||||
}}>
|
|
||||||
<Text strong style={{ fontSize: 15 }}>
|
|
||||||
序列号:{serialNumber}
|
|
||||||
</Text>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{qrUrl ? (
|
{qrUrl ? (
|
||||||
<img ref={qrRef} src={qrUrl} style={{ width: 240, height: 240 }} />
|
<img ref={qrRef} 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>
|
||||||
)}
|
)}
|
||||||
@@ -261,19 +330,57 @@ const SerialNumGenerate = () => {
|
|||||||
</Row>
|
</Row>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{/* 数据管理弹窗 */}
|
|
||||||
<Modal
|
<Modal
|
||||||
open={manageVisible}
|
open={manageVisible}
|
||||||
title="数据管理"
|
title="数据管理"
|
||||||
width={900}
|
width={900}
|
||||||
onCancel={() => setManageVisible(false)}
|
onCancel={() => setManageVisible(false)}
|
||||||
footer={<Button onClick={() => setManageVisible(false)}>关闭</Button>}
|
footer={<Button onClick={() => setManageVisible(false)}>关闭</Button>}
|
||||||
|
destroyOnClose
|
||||||
>
|
>
|
||||||
<DictManager title="机器人类型" data={types} onAdd={() => { }} onUpdate={() => { }} onDelete={() => { }} />
|
{/* 机器人类型 */}
|
||||||
<DictManager title="机器人型号" data={models} onAdd={() => { }} onUpdate={() => { }} onDelete={() => { }} />
|
<DictManager
|
||||||
<DictManager title="配置" data={configs} onAdd={() => { }} onUpdate={() => { }} onDelete={() => { }} />
|
title="机器人类型"
|
||||||
<DictManager title="国家" data={countries} onAdd={() => { }} onUpdate={() => { }} onDelete={() => { }} />
|
data={types}
|
||||||
<DictManager title="省份" data={provinces} onAdd={() => { }} onUpdate={() => { }} onDelete={() => { }} />
|
fields={[
|
||||||
|
{ name: 'typeName', label: '类型名称', required: true },
|
||||||
|
{ name: 'storeValue', label: '存储值', required: true },
|
||||||
|
{ name: 'remark', label: '备注', required: false }
|
||||||
|
]}
|
||||||
|
onAdd={handleAddType}
|
||||||
|
onUpdate={handleUpdateType}
|
||||||
|
onDelete={deleteRobotTypeApi}
|
||||||
|
refresh={loadTypeList}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 机器人型号 */}
|
||||||
|
<DictManager
|
||||||
|
title="机器人型号"
|
||||||
|
data={models}
|
||||||
|
fields={[
|
||||||
|
{ name: 'modelName', label: '型号名称', required: true },
|
||||||
|
{ name: 'storeValue', label: '存储值', required: true },
|
||||||
|
]}
|
||||||
|
onAdd={handleAddModel}
|
||||||
|
onUpdate={handleUpdateModel}
|
||||||
|
onDelete={handleDeleteModel}
|
||||||
|
refresh={loadModelList}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 省份 */}
|
||||||
|
<DictManager
|
||||||
|
title="省份"
|
||||||
|
data={provinces}
|
||||||
|
fields={[
|
||||||
|
{ name: 'typeName', label: '省份名称', required: true },
|
||||||
|
{ name: 'storeValue', label: '存储值', required: true },
|
||||||
|
{ name: 'remark', label: '备注', required: false }
|
||||||
|
]}
|
||||||
|
onAdd={addRobotProvinceApi}
|
||||||
|
onUpdate={updateRobotProvinceApi}
|
||||||
|
onDelete={deleteRobotProvinceApi}
|
||||||
|
refresh={loadProvinceList}
|
||||||
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user