-
-
+ {/* 内容区域 */}
+
+ {/* Logo和标题 */}
+
+
+
-
- 忘记密码?
-
+
智慧农业生产管理系统
+
安全、智能、高效的农业管理平台
-
-
+ {/* 登录表单 */}
+
-
-
- 还没有账户?{' '}
-
- 立即注册
-
-
-
+ {/* 安全提示 */}
+
+
+
+
+
安全保障:
+
+ - • 登录信息加密传输
+ - • 会话自动管理,24小时有效期
+ - • 记录登录IP、设备信息用于安全审计
+
+
+
+
-
-
- © 2024 Crop-X. All rights reserved.
-
+ {/* 页脚 */}
+
+
© 2024 智慧农业生产管理系统. All rights reserved.
+
- )
+ );
}
\ No newline at end of file
diff --git a/crop-x/src/app/(auth)/register/layout.tsx b/crop-x/src/app/(auth)/register/layout.tsx
new file mode 100644
index 0000000..87d67ec
--- /dev/null
+++ b/crop-x/src/app/(auth)/register/layout.tsx
@@ -0,0 +1,17 @@
+import { ReactNode } from 'react'
+import { AuthProvider } from '@/components/auth/AuthContext'
+import '@/styles/globals.css'
+
+export default function RegisterLayout({
+ children,
+}: {
+ children: ReactNode
+}) {
+ return (
+
+
+ {children}
+
+
+ )
+}
\ No newline at end of file
diff --git a/crop-x/src/app/(auth)/register/page.tsx b/crop-x/src/app/(auth)/register/page.tsx
index 2746a71..16e09f7 100644
--- a/crop-x/src/app/(auth)/register/page.tsx
+++ b/crop-x/src/app/(auth)/register/page.tsx
@@ -1,121 +1,550 @@
-import { Metadata } from 'next'
-import Link from 'next/link'
+/**
+ * filekorolheader: 用户注册页面 - 新用户注册功能入口
+ * 功能:用户注册、表单验证、企业选择、短信验证
+ * 路径:/register
+ * 规范:遵循crop-x/docs/开发项目规范.md,使用shadcn/ui语义化样式,支持暗色主题
+ */
-export const metadata: Metadata = {
- title: '注册 - Crop-X 智慧农业管理系统',
- description: '用户注册页面',
-}
+'use client';
+
+import React, { useEffect, useState } from 'react';
+import { Card } from '@/components/ui/card';
+import { Button } from '@/components/ui/button';
+import { Input } from '@/components/ui/input';
+import { Label } from '@/components/ui/label';
+import { Alert, AlertDescription } from '@/components/ui/alert';
+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
+import { CaptchaInput } from '@/components/auth/CaptchaInput';
+import { useAuth } from '@/components/auth/AuthContext';
+import { SmartFieldBackground } from '@/components/auth/SmartFieldBackground';
+import { Enterprise } from '@/types/auth';
+import {
+ User,
+ Lock,
+ Phone,
+ MessageSquare,
+ Mail,
+ UserPlus,
+ Eye,
+ EyeOff,
+ Loader2,
+ Shield,
+ AlertCircle,
+ CheckCircle,
+ ArrowLeft,
+ Building2,
+} from 'lucide-react';
+import { toast } from 'sonner';
export default function RegisterPage() {
+ const { login } = useAuth();
+ const [loading, setLoading] = useState(false);
+ const [showPassword, setShowPassword] = useState(false);
+ const [showConfirmPassword, setShowConfirmPassword] = useState(false);
+ const [sendingCode, setSendingCode] = useState(false);
+ const [countdown, setCountdown] = useState(0);
+ const [error, setError] = useState('');
+ const [success, setSuccess] = useState('');
+ const [enterprises, setEnterprises] = useState
([]);
+
+ const [form, setForm] = useState({
+ username: '',
+ password: '',
+ confirmPassword: '',
+ phone: '',
+ code: '',
+ realName: '',
+ email: '',
+ enterpriseId: '',
+ captcha: '',
+ });
+
+ const [validation, setValidation] = useState({
+ username: '',
+ password: '',
+ confirmPassword: '',
+ phone: '',
+ realName: '',
+ });
+
+ // 加载企业列表
+ useEffect(() => {
+ const mockEnterprises: Enterprise[] = [
+ {
+ id: '1',
+ name: '智慧农业示范农场',
+ code: 'DEMO001',
+ type: '示范农场',
+ status: 'active',
+ createdAt: new Date().toISOString(),
+ },
+ {
+ id: '2',
+ name: '绿色生态农业基地',
+ code: 'ECO002',
+ type: '生态农场',
+ status: 'active',
+ createdAt: new Date().toISOString(),
+ },
+ {
+ id: '3',
+ name: '科技农业产业园',
+ code: 'TECH003',
+ type: '产业园区',
+ status: 'active',
+ createdAt: new Date().toISOString(),
+ },
+ ];
+ setEnterprises(mockEnterprises);
+ }, []);
+
+ // 倒计时效果
+ useEffect(() => {
+ if (countdown > 0) {
+ const timer = setTimeout(() => {
+ setCountdown(prev => prev - 1);
+ }, 1000);
+ return () => clearTimeout(timer);
+ }
+ }, [countdown]);
+
+ // 验证函数
+ const validateUsername = (username: string): string => {
+ if (!username) return '请输入用户名';
+ if (username.length < 3) return '用户名至少3个字符';
+ if (username.length > 20) return '用户名最多20个字符';
+ if (!/^[a-zA-Z0-9_]+$/.test(username)) return '用户名只能包含字母、数字和下划线';
+ return '';
+ };
+
+ const validatePassword = (password: string): string => {
+ if (!password) return '请输入密码';
+ if (password.length < 6) return '密码至少6个字符';
+ if (password.length > 20) return '密码最多20个字符';
+ return '';
+ };
+
+ const validateConfirmPassword = (confirmPassword: string, password: string): string => {
+ if (!confirmPassword) return '请确认密码';
+ if (confirmPassword !== password) return '两次密码输入不一致';
+ return '';
+ };
+
+ const validatePhone = (phone: string): string => {
+ if (!phone) return '请输入手机号';
+ if (!/^1[3-9]\d{9}$/.test(phone)) return '请输入正确的手机号';
+ return '';
+ };
+
+ const validateRealName = (realName: string): string => {
+ if (!realName) return '请输入真实姓名';
+ if (realName.length < 2) return '姓名至少2个字符';
+ if (realName.length > 20) return '姓名最多20个字符';
+ return '';
+ };
+
+ // 发送验证码
+ const handleSendCode = async () => {
+ const phoneError = validatePhone(form.phone);
+
+ if (phoneError) {
+ setValidation(prev => ({ ...prev, phone: phoneError }));
+ toast.error(phoneError);
+ return;
+ }
+
+ setSendingCode(true);
+ setError('');
+
+ try {
+ // 模拟发送验证码
+ await new Promise(resolve => setTimeout(resolve, 1000));
+ toast.success('验证码发送成功!(测试验证码:123456)');
+ setCountdown(60);
+ } catch (err) {
+ setError('发送验证码失败,请稍后重试');
+ toast.error('发送验证码失败');
+ } finally {
+ setSendingCode(false);
+ }
+ };
+
+ // 注册处理
+ const handleRegister = async (e: React.FormEvent) => {
+ e.preventDefault();
+ setError('');
+ setSuccess('');
+
+ // 验证所有字段
+ const usernameError = validateUsername(form.username);
+ const passwordError = validatePassword(form.password);
+ const confirmPasswordError = validateConfirmPassword(form.confirmPassword, form.password);
+ const phoneError = validatePhone(form.phone);
+ const realNameError = validateRealName(form.realName);
+
+ setValidation({
+ username: usernameError,
+ password: passwordError,
+ confirmPassword: confirmPasswordError,
+ phone: phoneError,
+ realName: realNameError,
+ });
+
+ if (usernameError || passwordError || confirmPasswordError || phoneError || realNameError) {
+ setError('请检查表单填写是否正确');
+ return;
+ }
+
+ if (!form.code) {
+ setError('请输入短信验证码');
+ return;
+ }
+
+ if (!form.captcha) {
+ setError('请输入图形验证码');
+ return;
+ }
+
+ setLoading(true);
+
+ try {
+ // 模拟注册
+ await new Promise(resolve => setTimeout(resolve, 1500));
+
+ if (form.code === '123456') {
+ setSuccess('注册成功!正在为您自动登录...');
+ toast.success('注册成功!');
+
+ // 自动登录
+ setTimeout(() => {
+ login({
+ id: '3',
+ username: form.username,
+ realName: form.realName,
+ email: form.email,
+ phone: form.phone,
+ role: 'user',
+ permissions: [],
+ enterpriseId: form.enterpriseId,
+ enterpriseName: enterprises.find(e => e.id === form.enterpriseId)?.name || '',
+ createdAt: new Date().toISOString(),
+ });
+ window.location.href = '/';
+ }, 1500);
+ } else {
+ setError('短信验证码错误');
+ toast.error('短信验证码错误');
+ }
+ } catch (err) {
+ setError('注册失败,请稍后重试');
+ toast.error('注册失败');
+ } finally {
+ setLoading(false);
+ }
+ };
+
return (
-
-
-
🌱
-
- Crop-X 智慧农业
-
-
- 创建您的账户
-
-
+