个人中心加机器人生成配置界面

This commit is contained in:
mmc
2026-05-13 13:16:36 +08:00
parent 38ceb37926
commit 07e6488811
9 changed files with 458 additions and 311 deletions

View File

@@ -0,0 +1,104 @@
import React, { useState } from 'react';
import {
Table, Input, Button, Form, Space, Card, Modal
} from 'antd';
import { EditOutlined, DeleteOutlined } from '@ant-design/icons';
// 🔥 组件
const DictManager = ({
title,
data,
onAdd,
onUpdate,
onDelete,
loading,
}) => {
const [visible, setVisible] = useState(false);
const [form] = Form.useForm();
const [editing, setEditing] = useState(null);
// 编辑
const handleEdit = (record) => {
setEditing(record);
form.setFieldsValue(record);
setVisible(true);
};
// 提交
const handleSubmit = () => {
form.validateFields().then(values => {
if (editing) {
onUpdate({ ...editing, ...values });
} else {
onAdd({ id: Date.now(), ...values });
}
setVisible(false);
form.resetFields();
setEditing(null);
});
};
// 表格列
const columns = [
{ title: '存储值', dataIndex: 'value', key: 'value' },
{ title: '显示名', dataIndex: 'label', key: 'label' },
{
title: '操作',
key: 'action',
render: (_, record) => (
<Space>
<Button type="link" icon={<EditOutlined />} onClick={() => handleEdit(record)}>
编辑
</Button>
<Button type="link" danger icon={<DeleteOutlined />} onClick={() => onDelete(record.id)}>
删除
</Button>
</Space>
),
},
];
return (
<Card size="small" title={title} style={{ marginBottom: 16 }}>
<Button
type="primary"
size="small"
onClick={() => {
setEditing(null);
form.resetFields();
setVisible(true);
}}
>
新增
</Button>
<Table
size="small"
columns={columns}
dataSource={data}
rowKey="id"
pagination={false}
style={{ marginTop: 10 }}
/>
<Modal
open={visible}
title={editing ? '编辑' : '新增'}
onCancel={() => setVisible(false)}
onOk={handleSubmit}
confirmLoading={loading}
>
<Form form={form} layout="vertical">
<Form.Item name="value" label="存储值" rules={[{ required: true, message: '请输入' }]}>
<Input />
</Form.Item>
<Form.Item name="label" label="显示名称" rules={[{ required: true, message: '请输入' }]}>
<Input />
</Form.Item>
</Form>
</Modal>
</Card>
);
};
export default DictManager;

View File

@@ -10,6 +10,8 @@ import {
message,
Modal,
Tabs,
Card,
InputNumber,
} from 'antd';
import {
SearchOutlined,
@@ -18,6 +20,7 @@ import {
EditOutlined,
DeleteOutlined,
} from '@ant-design/icons';
import SerialNumGenerate from "./SerialNumGenerate"
// 模拟数据
const allDeviceList = [
@@ -43,6 +46,8 @@ const tabs = [
{ key: 'smart', label: '智能装备', filter: (item) => ['CLEANING_DEVICE', 'ROBOT', 'DRONE'].includes(item.type) },
];
export default function DeviceManagementPage() {
const [activeTab, setActiveTab] = useState('all');
const [form] = Form.useForm();
@@ -50,7 +55,7 @@ export default function DeviceManagementPage() {
const [deviceList, setDeviceList] = useState(allDeviceList);
// 根据 Tab 过滤数据
const filteredByTab = deviceList.filter(tabs.find(t => t.key === activeTab).filter);
const filteredByTab = deviceList.filter(tabs.find(t => t.key === activeTab)?.filter || (() => false));
// 表格列定义
const columns = [
@@ -144,40 +149,49 @@ export default function DeviceManagementPage() {
<Tabs.TabPane key="all" tab="设备管理" />
<Tabs.TabPane key="camera" tab="摄像头管理" />
<Tabs.TabPane key="smart" tab="智能装备" />
<Tabs.TabPane key="serialGenerate" tab="机器人生成" />
</Tabs>
{/* 筛选栏 */}
<div style={{ marginBottom: 16 }}>
<Form form={form} layout="inline">
<Form.Item name="keyword">
<Input placeholder="请输入设备名称" style={{ width: 220 }} />
</Form.Item>
<Form.Item>
<Button type="primary" icon={<SearchOutlined />} onClick={handleSearch}>查询</Button>
</Form.Item>
<Form.Item>
<Button icon={<ReloadOutlined />} onClick={handleReset}>重置</Button>
</Form.Item>
<Form.Item>
<Button type="primary" icon={<PlusOutlined />} onClick={handleAdd}>新增</Button>
</Form.Item>
</Form>
</div>
{/* ====================== 判断显示内容 ====================== */}
{activeTab === 'serialGenerate' ? (
<SerialNumGenerate />
) : (
// 显示原来的设备列表
<>
{/* 筛选栏 */}
<div style={{ marginBottom: 16 }}>
<Form form={form} layout="inline">
<Form.Item name="keyword">
<Input placeholder="请输入设备名称" style={{ width: 220 }} />
</Form.Item>
<Form.Item>
<Button type="primary" icon={<SearchOutlined />} onClick={handleSearch}>查询</Button>
</Form.Item>
<Form.Item>
<Button icon={<ReloadOutlined />} onClick={handleReset}>重置</Button>
</Form.Item>
<Form.Item>
<Button type="primary" icon={<PlusOutlined />} onClick={handleAdd}>新增</Button>
</Form.Item>
</Form>
</div>
{/* 表格 */}
<Table
rowKey="id"
columns={columns}
dataSource={filteredByTab}
loading={loading}
pagination={{
total: filteredByTab.length,
pageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
showTotal: (total) => `共 ${total} 条`,
}}
/>
{/* 表格 */}
<Table
rowKey="id"
columns={columns}
dataSource={filteredByTab}
loading={loading}
pagination={{
total: filteredByTab.length,
pageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
showTotal: (total) => `共 ${total} 条`,
}}
/>
</>
)}
</div>
);
}

View File

@@ -0,0 +1,257 @@
import React, { useState, useRef, useEffect } from 'react';
import {
Form, Select, Input, Button, Space, message, Card, Typography,
Row, Col, Modal, Table, Tag, Divider
} from 'antd';
import QRCode from 'qrcode';
import axios from 'axios';
import DictManager from "../DictManager"
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' },
{ id: 3, value: 'MC900', label: 'MC900' },
]);
// 配置
const [configs, setConfigs] = useState([
{ id: 1, value: 'AIR', label: 'AIR' },
{ id: 2, value: 'PRO', label: 'PRO' },
{ id: 3, value: 'MAX', label: 'MAX' },
]);
// 国家
const [countries, setCountries] = useState([
{ id: 1, value: '中国', label: '中国' },
{ id: 2, value: '美国', label: '美国' },
{ id: 3, value: '日本', label: '日本' },
]);
// 省份
const [provinces, setProvinces] = useState([
{ id: 1, value: '江苏', label: '江苏' },
{ id: 2, value: '浙江', label: '浙江' },
{ id: 3, value: '广东', label: '广东' },
]);
return {
types, setTypes,
models, setModels,
configs, setConfigs,
countries, setCountries,
provinces, setProvinces,
};
};
// ====================== 主组件 ======================
const SerialNumGenerate = () => {
const [form] = Form.useForm();
const [qrUrl, setQrUrl] = useState('');
const [qrText, setQrText] = useState('');
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, setTypes,
models, setModels,
configs, setConfigs,
countries, setCountries,
provinces, setProvinces,
} = useDict();
// 生成二维码
const generateQRCode = async () => {
try {
const values = await form.validateFields();
const timestamp = new Date().getTime();
const qrContent = `${values.model}-${values.config}-${values.type}-${values.country}-${values.province}-${values.code}-${timestamp}`;
const url = await QRCode.toDataURL(qrContent);
setQrUrl(url);
setQrText(qrContent);
message.success('生成成功!');
} catch (e) { message.error('请完善信息'); }
};
// 保存
const saveToDatabase = async () => {
if (!qrUrl) return message.warning('先生成二维码');
setLoading(true);
try {
const values = await form.validateFields();
await axios.post('/api/save-qrcode', { ...values, qrCode: qrUrl, qrText });
message.success('保存成功');
} catch {
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: { code: queryCode } });
if (res.data?.qrCode) {
setQrUrl(res.data.qrCode);
setQrText(res.data.qrText || '');
message.success('查询成功');
} else message.warning('未找到');
} catch {
message.error('查询失败');
} finally {
setQueryLoading(false);
}
};
return (
<div style={{ padding: '0 20px', minHeight: '100vh' }}>
<Card
title="机器人序列号二维码生成器"
style={{ maxWidth: 1000, margin: '0 auto', borderRadius: 12, boxShadow: '0 4px 20px rgba(0,0,0,0.08)' }}
headStyle={{ fontSize: 20, fontWeight: 600, textAlign: 'center' }}
extra={<Button type="primary" onClick={() => setManageVisible(true)}>数据管理</Button>}
>
<Row gutter={[32, 24]}>
{/* 左侧表单 */}
<Col xs={24} md={14}>
<Form form={form} initialValues={{ type: 'mower' }} labelCol={{ md: 5 }} wrapperCol={{ md: 19 }} size="large">
<Form.Item name="model" label="型号" rules={[{ required: true }]}>
<Select placeholder="选择型号">
{models.map(m => <Select.Option key={m.value} value={m.value}>{m.label}</Select.Option>)}
</Select>
</Form.Item>
<Form.Item name="config" label="配置" rules={[{ required: true }]}>
<Select placeholder="选择配置">
{configs.map(c => <Select.Option key={c.value} value={c.value}>{c.label}</Select.Option>)}
</Select>
</Form.Item>
<Form.Item name="type" label="类型" rules={[{ required: true }]}>
<Select placeholder="选择类型">
{types.map(t => <Select.Option key={t.value} value={t.value}>{t.label}</Select.Option>)}
</Select>
</Form.Item>
<Form.Item name="country" label="国家" rules={[{ required: true }]}>
<Select placeholder="选择国家">
{countries.map(c => <Select.Option key={c.value} value={c.value}>{c.label}</Select.Option>)}
</Select>
</Form.Item>
<Form.Item name="province" label="省份" rules={[{ required: true }]}>
<Select placeholder="选择省份">
{provinces.map(p => <Select.Option key={p.value} value={p.value}>{p.label}</Select.Option>)}
</Select>
</Form.Item>
<Form.Item name="code" label="编号" rules={[{ required: true }]}>
<Input placeholder="唯一编号" />
</Form.Item>
<Form.Item wrapperCol={{ offset: 5 }}>
<Button type="primary" onClick={generateQRCode} block>生成二维码</Button>
</Form.Item>
</Form>
{/* 查询 */}
<Card size="small" title="查询历史二维码" style={{ marginTop: 20 }}>
<Space.Compact style={{ width: '100%' }}>
<Input value={queryCode} onChange={e => setQueryCode(e.target.value)} placeholder="输入编号" />
<Button type="primary" loading={queryLoading} onClick={handleQueryQRCode}>查询</Button>
</Space.Compact>
</Card>
</Col>
{/* 右侧二维码 */}
<Col xs={24} md={10}>
<div style={{
padding: 20, background: '#fafafa', borderRadius: 12, border: '1px dashed #d9d9d9',
display: 'flex', flexDirection: 'column', alignItems: 'center', minHeight: 480
}}>
{qrText && (
<div style={{ padding: 12, background: '#e6f7ff', borderRadius: 8, width: '100%', textAlign: 'center', marginBottom: 20 }}>
<Text strong style={{ wordBreak: 'break-all' }}>{qrText}</Text>
</div>
)}
{qrUrl ? (
<img ref={qrRef} src={qrUrl} style={{ width: 240, height: 240, borderRadius: 8 }} />
) : (
<div style={{ color: '#999', padding: '60px 0' }}>请先生成二维码</div>
)}
<Space style={{ marginTop: 24 }}>
<Button onClick={() => window.open(qrRef.current.src)}>下载</Button>
<Button type="primary" loading={loading} onClick={saveToDatabase}>保存到数据库</Button>
</Space>
</div>
</Col>
</Row>
</Card>
{/* ====================== 数据管理弹窗 ====================== */}
<Modal
open={manageVisible}
title="机器人数据管理(型号/类型/配置/国家/省份)"
width={900}
footer={<Button onClick={() => setManageVisible(false)}>关闭</Button>}
destroyOnClose
onCancel={() => setManageVisible(false)}
>
<DictManager
title="机器人类型"
data={types}
onAdd={(item) => setTypes([...types, { id: Date.now(), ...item }])}
onUpdate={(item) => setTypes(types.map(t => t.id === item.id ? item : t))}
onDelete={(id) => setTypes(types.filter(t => t.id !== id))}
/>
<DictManager
title="机器人型号"
data={models}
onAdd={(item) => setModels([...models, { id: Date.now(), ...item }])}
onUpdate={(item) => setModels(models.map(m => m.id === item.id ? item : m))}
onDelete={(id) => setModels(models.filter(m => m.id !== id))}
/>
<DictManager
title="配置"
data={configs}
onAdd={(item) => setConfigs([...configs, { id: Date.now(), ...item }])}
onUpdate={(item) => setConfigs(configs.map(c => c.id === item.id ? item : c))}
onDelete={(id) => setConfigs(configs.filter(c => c.id !== id))}
/>
<DictManager
title="国家"
data={countries}
onAdd={(item) => setCountries([...countries, { id: Date.now(), ...item }])}
onUpdate={(item) => setCountries(countries.map(c => c.id === item.id ? item : c))}
onDelete={(id) => setCountries(countries.filter(c => c.id !== id))}
/>
<DictManager
title="省份"
data={provinces}
onAdd={(item) => setProvinces([...provinces, { id: Date.now(), ...item }])}
onUpdate={(item) => setProvinces(provinces.map(p => p.id === item.id ? item : p))}
onDelete={(id) => setProvinces(provinces.filter(p => p.id !== id))}
/>
</Modal>
</div>
);
};
export default SerialNumGenerate;

View File

@@ -1,9 +1,9 @@
import React, { useState, useEffect } from 'react';
import {
Card, Table, Tag, Space, Button,
Drawer, Descriptions, Form, Select, Pagination, message
Drawer, Descriptions, Form, Select, Pagination, message, DatePicker, Input
} from 'antd';
import { EyeOutlined, NotificationOutlined } from '@ant-design/icons';
import { EyeOutlined } from '@ant-design/icons';
import dayjs from 'dayjs';
// 接口
@@ -13,6 +13,7 @@ import {
} from '../../api/alarmApi.js';
const { Option } = Select;
const { RangePicker } = DatePicker;
// ====================== 枚举配置 ======================
const alarmTypeMap = {
@@ -66,8 +67,11 @@ const AlarmHistory = () => {
// 查询条件
const [queryParams, setQueryParams] = useState({
deviceId: '',
alarmLevel: '',
handleStatus: '',
startTime: '',
endTime: '',
});
// 获取列表
@@ -106,7 +110,20 @@ const AlarmHistory = () => {
// 搜索
const handleSearch = (values) => {
setQueryParams(values);
let startTime = '';
let endTime = '';
if (values.timeRange && values.timeRange.length === 2) {
startTime = values.timeRange[0].format('YYYY-MM-DD HH:mm:ss');
endTime = values.timeRange[1].format('YYYY-MM-DD HH:mm:ss');
}
setQueryParams({
deviceId: values.deviceId || '',
alarmLevel: values.alarmLevel || '',
handleStatus: values.handleStatus || '',
startTime,
endTime,
});
setPageNum(1);
};
@@ -123,6 +140,7 @@ const AlarmHistory = () => {
width: 190,
render: (t) => t ? dayjs(t).format('YYYY-MM-DD HH:mm:ss') : '-'
},
{ title: '设备ID', dataIndex: 'deviceId', width: 160 },
{ title: '设备名称', dataIndex: 'deviceName', ellipsis: true },
{
title: '告警级别',
@@ -169,6 +187,11 @@ const AlarmHistory = () => {
onFinish={handleSearch}
style={{ marginBottom: 16, flexWrap: 'wrap', gap: 16 }}
>
{/* 设备ID */}
<Form.Item name="deviceId" label="设备ID">
<Input placeholder="请输入设备ID" style={{ width: 160 }} allowClear />
</Form.Item>
<Form.Item name="alarmLevel" label="告警级别">
<Select placeholder="全部" style={{ width: 130 }} allowClear>
<Option value={1}>严重</Option>
@@ -187,6 +210,15 @@ const AlarmHistory = () => {
</Select>
</Form.Item>
{/* 时间范围 */}
<Form.Item name="timeRange" label="时间范围">
<RangePicker
showTime
format="YYYY-MM-DD HH:mm:ss"
style={{ width: 350 }}
/>
</Form.Item>
<Form.Item>
<Space>
<Button type="primary" htmlType="submit">查询</Button>
@@ -217,7 +249,7 @@ const AlarmHistory = () => {
</div>
</Card>
{/* 右侧详情抽屉 —— 新版设计稿样式 */}
{/* 右侧详情抽屉 */}
<Drawer
title="告警详情"
open={drawerVisible}
@@ -266,21 +298,18 @@ const AlarmHistory = () => {
<Card size="small" title="通知订阅" style={{ marginTop: 16 }}>
<Space style={{ width: '100%' }}>
<Space>
<svg t="1778634297838" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9839" width="16" height="16"><path d="M761.984 1009.28H253.696C138.368 1009.28 44.8 915.712 44.8 800.384V292.096C44.8 176.768 138.368 83.2 253.696 83.2h508.288c115.328 0 208.896 93.568 208.896 208.896v508.288c0 115.328-93.568 208.896-208.896 208.896z" fill="#00E560" p-id="9840"></path><path d="M507.776 265.856c-72.576 0-139.776 20.352-193.536 54.528-54.272 34.432-94.592 83.2-113.408 139.264-7.552 22.528-11.648 46.464-11.648 71.04 0 92.16 56.448 172.928 142.208 220.544 7.68 4.224 11.648 13.44 8.32 21.632-6.4 15.616-14.592 30.592-24.32 44.672-3.072 4.352 0.768 10.368 6.016 8.96 29.44-7.808 56.96-19.072 81.92-33.28 9.088-5.248 19.456-6.912 29.696-4.864 23.936 4.736 49.024 7.296 74.88 7.296 176 0 318.592-118.656 318.592-264.832 0-146.304-142.72-264.96-318.72-264.96z" fill="#FFFFFF" p-id="9841"></path></svg>
<span>短信</span>
<span>短信:</span>
<Tag color={currentAlarm.notifySms === 1 ? 'green' : 'default'}>
{currentAlarm.notifySms === 1 ? '已开启' : '已关闭'}
</Tag>
</Space>
<Space>
<svg t="1778634173765" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8764" width="16" height="16"><path d="M512.003 79C272.855 79 79 272.855 79 512.003 79 751.145 272.855 945 512.003 945 751.145 945 945 751.145 945 512.003 945 272.855 751.145 79 512.003 79z m200.075 375.014c-0.867 3.764-3.117 9.347-6.234 16.012h0.087l-0.347 0.648c-18.183 38.86-65.631 115.108-65.631 115.108l-0.215-0.52-13.856 24.147h66.8L565.063 779l29.002-115.368h-52.598l18.27-76.29c-14.76 3.55-32.253 8.436-52.945 15.1 0 0-27.967 16.36-80.607-31.5 0 0-35.501-31.29-14.891-39.078 8.744-3.33 42.466-7.573 69.004-11.122 35.93-4.845 57.965-7.441 57.965-7.441s-110.607 1.643-136.841-2.468c-26.237-4.11-59.525-47.905-66.626-86.377 0 0-10.953-21.117 23.595-11.122 34.547 10 177.535 38.95 177.535 38.95s-185.933-56.992-198.36-70.929c-12.381-13.846-36.406-75.902-33.289-113.981 0 0 1.343-9.521 11.127-6.926 0 0 137.49 62.75 231.475 97.152 94.028 34.403 175.76 51.885 165.2 96.414z" fill="#3AA2EB" p-id="8765"></path></svg>
<span>钉钉</span>
<span>钉钉:</span>
<Tag color={currentAlarm.notifyTelegram === 1 ? 'green' : 'default'}>
{currentAlarm.notifyTelegram === 1 ? '已开启' : '已关闭'}
</Tag>
</Space>
<Space>
<svg t="1778634149974" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7716" width="16" height="16"><path d="M512 512m-448 0a448 448 0 1 0 896 0 448 448 0 1 0-896 0Z" fill="#608BE9" p-id="7717"></path><path d="M192 302m32 0l576 0q32 0 32 32l0 356q0 32-32 32l-576 0q-32 0-32-32l0-356q0-32 32-32Z" fill="#EAEDF5" p-id="7718"></path><path d="M224 722h576c17.673 0 32-14.327 32-32v-58C660.96 493.333 554.294 424 512 424c-42.294 0-148.96 69.333-320 208v58c0 17.673 14.327 32 32 32z" fill="#CCDAF7" p-id="7719"></path><path d="M224 302h576c17.673 0 32 14.327 32 32v58C651.35 517.333 544.683 580 512 580c-32.683 0-139.35-62.667-320-188v-58c0-17.673 14.327-32 32-32z" fill="#FFFFFF" p-id="7720"></path></svg>
<span>邮件:</span>
<Tag color={currentAlarm.notifyEmail === 1 ? 'green' : 'default'}>
{currentAlarm.notifyEmail === 1 ? '已开启' : '已关闭'}

View File

@@ -75,7 +75,7 @@ export default function AlarmCenterPage() {
deviceId: '',
alarmLevel: '',
handleStatus: '',
beginTime: '',
startTime: '',
endTime: '',
});
@@ -319,7 +319,7 @@ export default function AlarmCenterPage() {
if (arr) {
setQueryParams({
...queryParams,
beginTime: arr[0].format('YYYY-MM-DD HH:mm:ss'),
startTime: arr[0].format('YYYY-MM-DD HH:mm:ss'),
endTime: arr[1].format('YYYY-MM-DD HH:mm:ss')
});
}
@@ -329,7 +329,7 @@ export default function AlarmCenterPage() {
<Col>
<Space>
<Button style={{ borderRadius: 8 }} onClick={() => {
setQueryParams({ deviceId: '', alarmLevel: '', handleStatus: '', beginTime: '', endTime: '' });
setQueryParams({ deviceId: '', alarmLevel: '', handleStatus: '', startTime: '', endTime: '' });
fetchList();
}}>重置</Button>
<Button type="primary" style={{ borderRadius: 8, background: '#165DFF' }} onClick={fetchList}>