diff --git a/src/api/device.ts b/src/api/device.ts
index bb03138..9939800 100644
--- a/src/api/device.ts
+++ b/src/api/device.ts
@@ -40,4 +40,6 @@ export function getJurisdiction(data) {
})
}
+//
+
diff --git a/src/api/systemSetting.ts b/src/api/systemSetting.ts
new file mode 100644
index 0000000..f72a082
--- /dev/null
+++ b/src/api/systemSetting.ts
@@ -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'
+ });
+}
diff --git a/src/components/DictManager.jsx b/src/components/DictManager.jsx
index 7507588..d763558 100644
--- a/src/components/DictManager.jsx
+++ b/src/components/DictManager.jsx
@@ -1,22 +1,34 @@
import React, { useState } from 'react';
import {
- Table, Input, Button, Form, Space, Card, Modal
+ Table, Input, Button, Form, Space, Card, Modal, message
} from 'antd';
import { EditOutlined, DeleteOutlined } from '@ant-design/icons';
-
-// 🔥 组件
const DictManager = ({
title,
data,
+ fields = [
+ { name: 'storeValue', label: '存储值', required: true },
+ { name: 'typeName', label: '名称', required: true },
+ { name: 'remark', label: '备注', required: false }
+ ],
onAdd,
onUpdate,
onDelete,
+ refresh,
loading,
}) => {
const [visible, setVisible] = useState(false);
const [form] = Form.useForm();
const [editing, setEditing] = useState(null);
+ const [messageApi, contextHolder] = message.useMessage();
+
+ // 打开新增
+ const handleAddNew = () => {
+ setEditing(null);
+ form.resetFields();
+ setVisible(true);
+ };
// 编辑
const handleEdit = (record) => {
@@ -25,24 +37,38 @@ const DictManager = ({
setVisible(true);
};
- // 提交
- const handleSubmit = () => {
- form.validateFields().then(values => {
+ const handleSubmit = async () => {
+ try {
+ const values = await form.validateFields();
+ let res;
+
if (editing) {
- onUpdate({ ...editing, ...values });
+ res = await onUpdate({ ...editing, ...values });
} else {
- onAdd({ id: Date.now(), ...values });
+ res = await onAdd(values);
}
- setVisible(false);
- form.resetFields();
- setEditing(null);
- });
+
+ if (res?.code == 200) {
+ messageApi.success(editing ? "编辑成功" : '新增成功');
+ setVisible(false);
+ form.resetFields();
+ setEditing(null);
+ refresh?.();
+ } else {
+ messageApi.error(res?.msg || '操作失败');
+ }
+ } catch (err) {
+ messageApi.error('提交失败');
+ }
};
// 表格列
const columns = [
- { title: '存储值', dataIndex: 'value', key: 'value' },
- { title: '显示名', dataIndex: 'label', key: 'label' },
+ ...fields.map(item => ({
+ title: item.label,
+ dataIndex: item.name,
+ key: item.name,
+ })),
{
title: '操作',
key: 'action',
@@ -51,7 +77,24 @@ const DictManager = ({
} onClick={() => handleEdit(record)}>
编辑
- } onClick={() => onDelete(record.id)}>
+ }
+ 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('删除失败');
+ }
+ }}
+ >
删除
@@ -61,15 +104,8 @@ const DictManager = ({
return (
-
);
};
+
export default DictManager;
diff --git a/src/components/SystemSetting/SerialNumGenerate.jsx b/src/components/SystemSetting/SerialNumGenerate.jsx
index 3faaa42..15dbe15 100644
--- a/src/components/SystemSetting/SerialNumGenerate.jsx
+++ b/src/components/SystemSetting/SerialNumGenerate.jsx
@@ -1,48 +1,28 @@
-import React, { useState, useRef } from 'react';
+import React, { useState, useRef, useEffect } from 'react';
import {
Form, Select, Button, Space, message, Card, Typography,
Row, Col, Modal, Input
} from 'antd';
import QRCode from 'qrcode';
-import axios from 'axios';
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 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 [form] = Form.useForm();
const [qrUrl, setQrUrl] = useState('');
@@ -51,62 +31,90 @@ const SerialNumGenerate = () => {
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,
- models,
- configs,
- countries,
- provinces
- } = useDict();
+ // 接口数据
+ const [types, setTypes] = useState([]);
+ const [models, setModels] = useState([]);
+ const [provinces, setProvinces] = useState([]);
+ const [countries] = useState([
+ { id: 1, value: 'CN', label: '中国' },
+ { 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 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');
return `${num}-${check}`;
};
- // 生成序列号 + JSON二维码
+ // 生成二维码
const generateQRCode = async () => {
try {
const values = await form.validateFields();
const { model, config, type, country, province } = values;
const ts = Date.now();
const suffix = generateSerialSuffix();
-
- // 1. 生成序列号
const sn = `${model}${config}-${country}-${province}-${ts}-${suffix}`;
- setSerialNumber(sn);
- // 2. 二维码内容 = JSON
- const qrData = {
- model,
- config,
- type,
- country,
- province,
- sn: sn
- };
+ const qrData = { model, config, type, country, province, sn };
const qrContent = JSON.stringify(qrData, null, 2);
- setQrJson(qrContent);
-
- // 3. 生成二维码
const url = await QRCode.toDataURL(qrContent);
- setQrUrl(url);
+ setSerialNumber(sn);
+ setQrJson(qrContent);
+ setQrUrl(url);
message.success('生成成功!');
} catch (err) {
message.error('请完善信息');
}
};
- // 下载二维码
+ // 下载
const downloadQRCode = () => {
if (!qrRef.current || !qrUrl) {
message.warning('请先生成二维码');
@@ -118,49 +126,116 @@ const SerialNumGenerate = () => {
link.click();
};
- // 保存到数据库
+ // 保存序列号
const saveToDatabase = async () => {
- if (!serialNumber || !qrUrl) {
- message.warning('请先生成二维码');
- return;
- }
+ if (!serialNumber) return message.warning('请先生成');
setLoading(true);
try {
- await axios.post('/api/save-qrcode', {
- serialNumber,
- qrCode: qrUrl,
- qrJson: qrJson,
- ...form.getFieldsValue()
+ await request({
+ url: '/iot/device/saveSerial',
+ method: 'post',
+ data: {
+ serialNumber,
+ model: form.getFieldValue('model'),
+ config: form.getFieldValue('config'),
+ type: form.getFieldValue('type'),
+ country: form.getFieldValue('country'),
+ province: form.getFieldValue('province'),
+ qrCode: qrUrl,
+ qrJson: qrJson
+ }
});
message.success('保存成功');
- } catch {
+ } catch (e) {
message.error('保存失败');
} finally {
setLoading(false);
}
};
- // 查询二维码
+ // 查询
const handleQueryQRCode = async () => {
if (!queryCode) return message.warning('请输入序列号');
setQueryLoading(true);
try {
- const res = await axios.get('/api/query-qrcode', { params: { sn: queryCode } });
- if (res.data?.qrUrl) {
- setQrUrl(res.data.qrUrl);
- setQrJson(res.data.qrJson || '');
- setSerialNumber(res.data.serialNumber || '');
+ const res = await request({
+ url: '/iot/device/querySerial',
+ method: 'get',
+ params: { sn: queryCode }
+ });
+ 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('查询成功');
} else {
- message.warning('未找到该序列号');
+ message.warning('未查询到数据');
}
- } catch {
+ } catch (e) {
message.error('查询失败');
} finally {
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 (
{
extra={ setManageVisible(true)}>数据管理}
>
- {/* 左侧表单 */}
@@ -186,7 +262,9 @@ const SerialNumGenerate = () => {
@@ -198,7 +276,9 @@ const SerialNumGenerate = () => {
@@ -209,18 +289,13 @@ const SerialNumGenerate = () => {
- {/* 查询模块(已加回) */}
setQueryCode(e.target.value)}
+ onChange={(e) => setQueryCode(e.value)}
placeholder="输入序列号查询"
- style={
- {
- width: '300px'
- }
- }
+ style={{ width: '300px' }}
/>
查询
@@ -229,25 +304,19 @@ const SerialNumGenerate = () => {
- {/* 右侧二维码 */}
{serialNumber && (
-
-
- 序列号:{serialNumber}
-
+
+ 序列号:{serialNumber}
)}
{qrUrl ? (
-

+

) : (
请先生成二维码
)}
@@ -261,19 +330,57 @@ const SerialNumGenerate = () => {
- {/* 数据管理弹窗 */}
setManageVisible(false)}
footer={ setManageVisible(false)}>关闭}
+ destroyOnClose
>
- { }} onUpdate={() => { }} onDelete={() => { }} />
- { }} onUpdate={() => { }} onDelete={() => { }} />
- { }} onUpdate={() => { }} onDelete={() => { }} />
- { }} onUpdate={() => { }} onDelete={() => { }} />
- { }} onUpdate={() => { }} onDelete={() => { }} />
+ {/* 机器人类型 */}
+
+
+ {/* 机器人型号 */}
+
+
+ {/* 省份 */}
+
);