ソースを参照

♻️ refactor(components): 重构文件选择和上传组件结构

- 将MinioUploader和FileSelector组件从admin目录移动到公共components目录,使其可被全局使用
- 更新相关组件的导入路径以适应新的文件结构

✨ feat(mobile): 为移动端文件选择器添加用户文件筛选功能

- 添加onlyCurrentUser属性,支持只显示当前用户上传的文件
- 集成用户认证信息,实现基于用户ID的文件筛选
- 优化查询逻辑,根据筛选条件动态构建API请求参数
yourname 6 ヶ月 前
コミット
b331c450ac

+ 1 - 1
src/client/admin/components/AvatarSelector.tsx

@@ -5,7 +5,7 @@ import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, D
 import { Card, CardContent } from '@/client/components/ui/card';
 import { toast } from 'sonner';
 import { fileClient } from '@/client/api';
-import MinioUploader from '@/client/admin/components/MinioUploader';
+import MinioUploader from '@/client/components/MinioUploader';
 import { Check, Upload, Eye, X } from 'lucide-react';
 import { Avatar, AvatarFallback, AvatarImage } from '@/client/components/ui/avatar';
 import { cn } from '@/client/lib/utils';

+ 1 - 1
src/client/admin/pages/Files.tsx

@@ -15,7 +15,7 @@ import { Eye, Download, Edit, Trash2, Search, FileText, Upload } from 'lucide-re
 import { fileClient } from '@/client/api';
 import type { InferResponseType, InferRequestType } from 'hono/client';
 import dayjs from 'dayjs';
-import MinioUploader from '@/client/admin/components/MinioUploader';
+import MinioUploader from '@/client/components/MinioUploader';
 import { UpdateFileDto } from '@/server/modules/files/file.schema';
 import * as z from 'zod';
 

+ 1 - 1
src/client/admin/components/FileSelector.tsx → src/client/components/FileSelector.tsx

@@ -5,7 +5,7 @@ import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, D
 import { Card, CardContent } from '@/client/components/ui/card';
 import { toast } from 'sonner';
 import { fileClient } from '@/client/api';
-import MinioUploader from '@/client/admin/components/MinioUploader';
+import MinioUploader from '@/client/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';

+ 0 - 0
src/client/admin/components/MinioUploader.tsx → src/client/components/MinioUploader.tsx


+ 19 - 3
src/client/mobile/components/FileSelector.tsx

@@ -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) => {