import React, { useState } from "react";
import { Button, Card, Space, Divider, Toast, Switch } from "antd-mobile";
import Layout from "@/components/Layout/Layout";
import NavCommon from "@/components/NavCommon";
import ImageUpload from "@/components/Upload/ImageUpload";
import AvatarUpload from "@/components/Upload/AvatarUpload";
import VideoUpload from "@/components/Upload/VideoUpload";
import styles from "./upload.module.scss";
// 错误边界组件
class ErrorBoundary extends React.Component<
{ children: React.ReactNode },
{ hasError: boolean; error: Error | null }
> {
constructor(props: { children: React.ReactNode }) {
super(props);
this.state = { hasError: false, error: null };
}
static getDerivedStateFromError(error: Error) {
return { hasError: true, error };
}
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error("Error caught by boundary:", error, errorInfo);
}
render() {
if (this.state.hasError) {
return (
组件出现错误
错误信息: {this.state.error?.message}
);
}
return this.props.children;
}
}
const UploadTestPage: React.FC = () => {
// 搜索状态
const [searchQuery, setSearchQuery] = useState("");
const [loading, setLoading] = useState(false);
// 图片上传状态
const [imageUrls, setImageUrls] = useState([]);
const [imageCount, setImageCount] = useState(9);
const [imageDisabled, setImageDisabled] = useState(false);
// 头像上传状态
const [avatarUrl, setAvatarUrl] = useState("");
const [avatarSize, setAvatarSize] = useState(100);
const [avatarDisabled, setAvatarDisabled] = useState(false);
// 视频上传状态
const [videoUrl, setVideoUrl] = useState("");
const [videoDisabled, setVideoDisabled] = useState(false);
return (
} loading={loading}>
{/* 图片上传测试 */}
图片上传组件测试
支持多图片上传,可设置数量限制
当前图片URLs:
{imageUrls.length > 0 ? (
imageUrls.map((url, index) => (
{index + 1}.
{typeof url === "string" ? url : "无效URL"}
))
) : (
暂无图片
)}
{/* 头像上传测试 */}
头像上传组件测试
支持单张图片上传,圆形显示
当前头像URL:
{avatarUrl ? (
{typeof avatarUrl === "string" ? avatarUrl : "无效URL"}
) : (
暂无头像
)}
{/* 视频上传测试 */}
视频上传组件测试
支持视频文件上传,最大50MB,支持预览功能
当前视频URL:
{videoUrl ? (
{typeof videoUrl === "string" ? videoUrl : "无效URL"}
) : (
暂无视频
)}
);
};
export default UploadTestPage;