import React, { useRef } from 'react'; import { useFormContext, Controller } from 'react-hook-form'; import { Box, Typography, TextField, FormControl, InputLabel, Select, MenuItem, Grid, Avatar, Button, IconButton, } from '@mui/material'; import { PhotoCamera as PhotoCameraIcon, Delete as DeleteIcon, } from '@mui/icons-material'; function GeneralForm() { const { control, watch, setValue } = useFormContext(); const fileInputRef = useRef(null); const handleAvatarUpload = (event: React.ChangeEvent) => { const file = event.target.files?.[0]; if (file) { const reader = new FileReader(); reader.onload = (e) => { setValue('avatar', e.target?.result as string); }; reader.readAsDataURL(file); } }; const handleAvatarDelete = () => { setValue('avatar', undefined); }; const handleAvatarClick = () => { fileInputRef.current?.click(); }; const avatar = watch('avatar'); return ( 基础信息 {!avatar && } {avatar && ( )} {/* 表单字段 */} ( )} /> ( )} /> ( 权限设置 )} /> ); } export default GeneralForm;