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

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

@@ -123,12 +123,13 @@ const Profile: React.FC = () => {
: null;
return (
<div style={{ padding: '32px 40px', background: '#f5f7fa', minHeight: '100vh' }}>
<div style={{ padding: '20px 40px', background: '#f5f7fa', minHeight: '100vh' }}>
<Title level={4} style={{ marginBottom: 24, fontWeight: 600 }}>
个人中心
</Title>
<Row gutter={24}>
{/* 🔥 关键:给 Row 添加 align="stretch" 让两列自动等高 */}
<Row gutter={24} align="stretch">
{/* 左侧信息卡片 */}
<Col xs={24} sm={24} md={8} lg={7} xl={6}>
<Card
@@ -138,9 +139,12 @@ const Profile: React.FC = () => {
boxShadow: '0 2px 12px rgba(0,0,0,0.06)',
textAlign: 'center',
overflow: 'hidden',
height: '100%', // 🔥 高度 100%
display: 'flex',
flexDirection: 'column',
}}
>
<div style={{ padding: '20px 0' }}>
<div style={{ padding: '20px 0', flex: 1 }}> {/* 🔥 自动填充高度 */}
<Avatar
size={120}
src={avatarUrl}
@@ -208,6 +212,7 @@ const Profile: React.FC = () => {
borderRadius: 12,
boxShadow: '0 2px 12px rgba(0,0,0,0.06)',
overflow: 'hidden',
height: '100%', // 🔥 高度 100%
}}
>
<Tabs

View File

@@ -1,260 +0,0 @@
import React, { useState, useRef } from 'react';
import { Form, Select, Input, Button, Space, message, Card, Typography, Row, Col } from 'antd';
import QRCode from 'qrcode';
import axios from 'axios';
const { Text } = Typography;
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 initialValues = {
model: 'MC700',
config: 'AIR',
country: '中国',
province: '江苏',
code: '',
type: 'mower',
};
// 生成二维码(纯字符串+显示明文)
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 (error) {
message.error('请完善信息');
console.error(error);
}
};
// 保存到数据库
const saveToDatabase = async () => {
if (!qrUrl) {
message.warning('先生成二维码');
return;
}
setLoading(true);
try {
const values = await form.validateFields();
const timestamp = new Date().getTime();
const data = { ...values, timestamp, qrCode: qrUrl, qrText: qrText };
await axios.post('/api/save-qrcode', data);
message.success('已保存到数据库!');
} catch (err) {
message.error('保存失败');
} finally {
setLoading(false);
}
};
// 查询二维码
const handleQueryQRCode = async () => {
if (!queryCode) {
message.warning('请输入编号');
return;
}
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 (err) {
message.error('查询失败');
} finally {
setQueryLoading(false);
}
};
return (
<div style={{ padding: '40px 20px', background: '#f0f2f5', minHeight: '100vh' }}>
<Card
title="序列号二维码生成器"
style={{
maxWidth: 900,
margin: '0 auto',
borderRadius: 12,
boxShadow: '0 4px 20px rgba(0,0,0,0.08)',
padding: '20px',
}}
headStyle={{
fontSize: '20px',
fontWeight: 600,
textAlign: 'center',
borderBottom: '1px solid #f0f0f0',
paddingBottom: 16,
}}
>
{/* 核心:Row+Col 左右分栏布局 */}
<Row gutter={[32, 24]}>
{/* 左侧:表单区域 */}
<Col xs={24} md={14}>
<Form
form={form}
initialValues={initialValues}
labelCol={{ md: 5 }}
wrapperCol={{ md: 19 }}
size="large"
>
<Form.Item name="model" label="型号" rules={[{ required: true, message: '请选择型号' }]}>
<Select placeholder="选择型号">
<Select.Option value="MC700">MC700</Select.Option>
<Select.Option value="MC800">MC800</Select.Option>
<Select.Option value="MC900">MC900</Select.Option>
</Select>
</Form.Item>
<Form.Item name="config" label="配置" rules={[{ required: true, message: '请选择配置' }]}>
<Select placeholder="选择配置">
<Select.Option value="AIR">AIR</Select.Option>
<Select.Option value="PRO">PRO</Select.Option>
<Select.Option value="MAX">MAX</Select.Option>
</Select>
</Form.Item>
<Form.Item name="type" label="类型" rules={[{ required: true, message: '请选择类型' }]}>
<Select placeholder="选择类型">
<Select.Option value="mower">割草机</Select.Option>
<Select.Option value="vacuum">巡检机</Select.Option>
</Select>
</Form.Item>
<Form.Item name="country" label="国家" rules={[{ required: true, message: '请选择国家' }]}>
<Select placeholder="选择国家">
<Select.Option value="中国">中国</Select.Option>
<Select.Option value="美国">美国</Select.Option>
<Select.Option value="日本">日本</Select.Option>
</Select>
</Form.Item>
<Form.Item name="province" label="省份" rules={[{ required: true, message: '请选择省份' }]}>
<Select placeholder="选择省份">
<Select.Option value="江苏">江苏</Select.Option>
<Select.Option value="浙江">浙江</Select.Option>
<Select.Option value="广东">广东</Select.Option>
</Select>
</Form.Item>
<Form.Item name="code" label="编号" rules={[{ required: true, message: '请输入编号' }]}>
<Input placeholder="请输入唯一编号" />
</Form.Item>
<Form.Item wrapperCol={{ offset: 5 }} style={{ marginTop: 10 }}>
<Button type="primary" onClick={generateQRCode} block>
生成二维码(带时间戳)
</Button>
</Form.Item>
</Form>
{/* 查询区域(放在左侧底部) */}
<div style={{
marginTop: 20,
padding: '16px',
background: '#f9fbfc',
borderRadius: 8,
border: '1px solid #e8e8e8'
}}>
<div style={{ marginBottom: 10, fontWeight: 500, color: '#1677ff' }}>
🔍 查询历史二维码
</div>
<Space.Compact style={{ width: '100%' }}>
<Input
placeholder="输入编号查询"
value={queryCode}
onChange={(e) => setQueryCode(e.target.value)}
/>
<Button type="primary" loading={queryLoading} onClick={handleQueryQRCode}>
查询二维码
</Button>
</Space.Compact>
</div>
</Col>
{/* 右侧:二维码内容+图片区域(固定在右侧,不拉长页面) */}
<Col xs={24} md={10}>
<div style={{
height: '100%',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
padding: '20px',
background: '#fafafa',
borderRadius: 12,
border: '1px dashed #d9d9d9',
minHeight: 480,
}}>
{/* 二维码内容文字(右侧顶部) */}
{qrText && (
<div style={{
padding: '12px 16px',
background: '#e6f7ff',
borderRadius: 8,
marginBottom: 20,
width: '100%',
textAlign: 'center',
}}>
<Text strong style={{ fontSize: 14, color: '#0050b3', wordBreak: 'break-all' }}>
二维码内容:{qrText}
</Text>
</div>
)}
{/* 二维码图片(右侧中间) */}
{qrUrl ? (
<div style={{ textAlign: 'center' }}>
<img
ref={qrRef}
src={qrUrl}
alt="二维码"
style={{
width: 240,
height: 240,
borderRadius: 8,
boxShadow: '0 2px 12px rgba(0,0,0,0.1)',
}}
/>
</div>
) : (
<div style={{ color: '#999', textAlign: 'center', padding: '60px 0' }}>
请先生成二维码
</div>
)}
{/* 操作按钮(右侧底部) */}
<Space size="middle" style={{ marginTop: 24 }}>
<Button onClick={() => qrRef.current && window.open(qrRef.current.src)}>
下载二维码
</Button>
<Button type="primary" loading={loading} onClick={saveToDatabase}>
保存到数据库
</Button>
</Space>
</div>
</Col>
</Row>
</Card>
</div>
);
};
export default SerialNumGenerate;