import { useState } from 'react'; import { Form, Input, Button, Card, message, Steps, Select, Space, Typography } from 'antd'; import { UserOutlined, LockOutlined, HddOutlined } from '@ant-design/icons'; import { adaptersApi } from '../api/adapters'; import { useAuth } from '../contexts/AuthContext'; const { Title, Text } = Typography; const { Step } = Steps; const SetupPage = () => { const [loading, setLoading] = useState(false); const [currentStep, setCurrentStep] = useState(0); const [form] = Form.useForm(); const { login, register } = useAuth(); const onFinish = async (values: any) => { setLoading(true); try { await register(values.username, values.password, values.email, values.full_name); await login(values.username, values.password); message.success('初始化成功!正在为您登录,请不要刷新。'); setTimeout(async () => { await adaptersApi.create({ name: values.adapter_name, type: values.adapter_type, config: { root: values.root_dir }, sub_path: null, path: values.path, enabled: true }); window.location.href = '/'; }, 2000); } catch (error: any) { console.log(error) message.error(error.response?.data?.msg || '初始化失败,请稍后重试'); } finally { setLoading(false); } }; const stepFields = [ ['db_driver', 'vector_db_driver'], ['adapter_name', 'adapter_type', 'path', 'root_dir'], ['username', 'full_name', 'email', 'password', 'confirm'], ] const next = () => { form.validateFields(stepFields[currentStep]).then(() => { setCurrentStep(currentStep + 1); }) }; const prev = () => { setCurrentStep(currentStep - 1); }; const steps = [ { title: '数据库设置', content: ( <> 选择数据库驱动 选择用于存储系统数据的数据库和向量数据库。 ) }, { title: '初始化挂载', content: ( <> 配置初始存储 为您的文件创建第一个存储挂载点。 } /> } /> ) }, { title: '创建管理员', content: ( <> 创建管理员账户 这是系统的第一个账户,将拥有最高权限。 } /> } /> } /> } /> ({ validator(_, value) { if (!value || getFieldValue('password') === value) { return Promise.resolve(); } return Promise.reject(new Error('两次输入的密码不一致!')); }, }), ]} > } /> ) }, ]; return (
Foxel Logo 系统初始化
{steps.map(item => ( ))}
{steps.map((step, index) => (
{step.content}
))}
{currentStep > 0 && ( )} {currentStep < steps.length - 1 && ( )} {currentStep === steps.length - 1 && ( )}
); }; export default SetupPage;