|
|
@@ -9,6 +9,7 @@ import MinioUploader from '@/client/mobile/components/MinioUploader';
|
|
|
import { Check, Upload, Eye, X, File as FileIcon, Image as ImageIcon } from 'lucide-react';
|
|
|
import { cn } from '@/client/lib/utils';
|
|
|
import type { InferResponseType } from 'hono/client';
|
|
|
+import { useAuth } from '@/client/mobile/hooks/AuthProvider';
|
|
|
|
|
|
type FileType = InferResponseType<typeof fileClient.$get, 200>['data'][0]
|
|
|
|
|
|
@@ -26,6 +27,8 @@ export interface FileSelectorProps {
|
|
|
description?: string;
|
|
|
filterType?: 'image' | 'all' | string;
|
|
|
allowMultiple?: boolean;
|
|
|
+ /** 是否只显示当前用户自己上传的文件 */
|
|
|
+ onlyCurrentUser?: boolean;
|
|
|
}
|
|
|
|
|
|
export const FileSelector: React.FC<FileSelectorProps> = ({
|
|
|
@@ -42,10 +45,12 @@ export const FileSelector: React.FC<FileSelectorProps> = ({
|
|
|
description = '上传新文件或从已有文件中选择',
|
|
|
filterType = 'all',
|
|
|
allowMultiple = false,
|
|
|
+ onlyCurrentUser = false,
|
|
|
}) => {
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
const [selectedFile, setSelectedFile] = useState<FileType | null>(null);
|
|
|
const [localSelectedFiles, setLocalSelectedFiles] = useState<number[]>([]);
|
|
|
+ const { user } = useAuth();
|
|
|
|
|
|
// 获取当前选中的文件详情 - 支持单值和数组
|
|
|
const { data: currentFiles } = useQuery<FileType[]>({
|
|
|
@@ -102,19 +107,30 @@ export const FileSelector: React.FC<FileSelectorProps> = ({
|
|
|
|
|
|
// 获取文件列表
|
|
|
const { data: filesData, isLoading, refetch } = useQuery({
|
|
|
- queryKey: ['files-for-selection', filterType] as const,
|
|
|
+ queryKey: ['files-for-selection', filterType, onlyCurrentUser, user?.id] as const,
|
|
|
queryFn: async () => {
|
|
|
+ // 构建筛选条件
|
|
|
+ const filters: any = {};
|
|
|
+
|
|
|
+ // 如果设置为只显示当前用户的文件,并且用户已登录
|
|
|
+ if (onlyCurrentUser && user?.id) {
|
|
|
+ filters.uploadUserId = user.id;
|
|
|
+ }
|
|
|
+
|
|
|
const response = await fileClient.$get({
|
|
|
query: {
|
|
|
page: 1,
|
|
|
pageSize: 50,
|
|
|
- ...(filterType !== 'all' && { keyword: filterType })
|
|
|
+ ...(filterType !== 'all' && { keyword: filterType }),
|
|
|
+ ...(Object.keys(filters).length > 0 && {
|
|
|
+ filters: JSON.stringify(filters)
|
|
|
+ })
|
|
|
}
|
|
|
});
|
|
|
if (response.status !== 200) throw new Error('获取文件列表失败');
|
|
|
return response.json();
|
|
|
},
|
|
|
- enabled: isOpen,
|
|
|
+ enabled: isOpen && (!onlyCurrentUser || !!user),
|
|
|
});
|
|
|
|
|
|
const files = filesData?.data?.filter((f) => {
|