Browse Source

细化权限控制,优化获取文件列表权限

Lijiahao 5 hours ago
parent
commit
cee720bb82

+ 27 - 5
xzl-admin/src/main/java/com/xzl/web/controller/KnowledgeFileController.java

@@ -3,6 +3,7 @@ package com.xzl.web.controller;
 
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
+
 import com.xzl.common.core.domain.entity.KnowledgeFile;
 import com.xzl.common.core.domain.model.LoginUser;
 import com.xzl.web.service.ISysFileFolderService;
@@ -44,14 +45,19 @@ public class KnowledgeFileController extends BaseController {
             @RequestParam(value = "beginCreateTime", required = false) String beginCreateTime,
             @RequestParam(value = "endCreateTime", required = false) String endCreateTime,
             @RequestParam(value = "beginUpdateTime", required = false) String beginUpdateTime,
-            @RequestParam(value = "endUpdateTime", required = false) String endUpdateTime
+            @RequestParam(value = "endUpdateTime", required = false) String endUpdateTime,
+            @RequestParam(value = "deptId", required = false) Long deptId
     ) {
+        LoginUser loginUser = getLoginUser();
         // 将可选参数设置到对象中
         knowledge.setFolderId(folderId);
+        knowledge.setDeptId(loginUser.getUserId().equals(1L) ? null : deptId);
         knowledge.setBeginCreateTime(beginCreateTime);
         knowledge.setEndCreateTime(endCreateTime);
         knowledge.setBeginUpdateTime(beginUpdateTime);
         knowledge.setEndUpdateTime(endUpdateTime);
+        logger.info("查询文件列表,参数:{}", knowledge);
+
 
         startPage();
         List<KnowledgeFile> list = knowledgeFileService.selectSysFileList(knowledge);
@@ -89,7 +95,7 @@ public class KnowledgeFileController extends BaseController {
                           @RequestParam("folderId") Long folderId) {
         LoginUser loginUser = getLoginUser();
         try {
-            int result = knowledgeFileService.insertSysFileWithUpload(file,folderId, loginUser.getUser().getNickName());
+            int result = knowledgeFileService.insertSysFileWithUpload(file, folderId, loginUser.getUser().getNickName());
             return toAjax(result);
         } catch (Exception e) {
             return AjaxResult.error("文件上传失败: " + e.getMessage());
@@ -125,6 +131,7 @@ public class KnowledgeFileController extends BaseController {
         }
         return AjaxResult.error("只有管理员或文件所在部门的用户可以删除文件");
     }
+
     /**
      * 修改文件状态
      */
@@ -140,9 +147,9 @@ public class KnowledgeFileController extends BaseController {
                 return AjaxResult.error("fileId 和 status 不能为空");
             }
             return toAjax(knowledgeFileService.updateSysFileStatus(knowledgeFile.getFileId(),
-                    knowledgeFile.getStatus(),loginUser.getUser().getNickName()));
+                    knowledgeFile.getStatus(), loginUser.getUser().getNickName()));
         }
-       return AjaxResult.error("只有管理员或文件所在部门的用户可以修改文件状态");
+        return AjaxResult.error("只有管理员或文件所在部门的用户可以修改文件状态");
     }
 
     /**
@@ -165,4 +172,19 @@ public class KnowledgeFileController extends BaseController {
         knowledgeFileService.downloadTemplate(response);
     }
 
-}
+//    /**
+//     * 获取文件预览URL
+//     *
+//     * @param fileId 文件ID
+//     * @return 预览URL
+//     */
+//    @GetMapping("/preview-url/{fileId}")
+//    public AjaxResult getPreviewUrl(@PathVariable("fileId") Long fileId) {
+//        try {
+//            Map<String, Object> result = knowledgeFileService.getPreviewInfo(fileId);
+//            return AjaxResult.success(result);
+//        } catch (Exception e) {
+//            return AjaxResult.error(e.getMessage());
+//        }
+//    }
+}

+ 2 - 2
xzl-admin/src/main/java/com/xzl/web/controller/SysFileFolderController.java

@@ -92,10 +92,10 @@ public class SysFileFolderController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         // 检查 sysFileFolder.getDeptId() 是否为 null
         if (loginUser.getUserId().equals(1L) ||
-                (sysFileFolder.getDeptId() != null && sysFileFolder.getDeptId().equals(loginUser.getDeptId()))) {
+                (sysFileFolder.getCreateBy().equals(loginUser.getUser().getNickName()))) {
             return toAjax(sysFileFolderService.updateSysFileFolder(sysFileFolder));
         }
-        return error("只有超级管理员或部门管理员可以修改");
+        return error("只有超级管理员或创建者可以修改");
     }
 
     /**

+ 5 - 4
xzl-admin/src/main/java/com/xzl/web/service/KnowledgeFileService.java

@@ -6,7 +6,6 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
-
 /**
  * 文件Service接口
  *
@@ -53,12 +52,12 @@ public interface KnowledgeFileService {
      * @param status 新状态
      * @return 影响行数
      */
-    int updateSysFileStatus(Long fileId, String status,String updateBy);
+    int updateSysFileStatus(Long fileId, String status, String updateBy);
 
     /**
      * 文件上传
      *
-     * @param file 文件
+     * @param file     文件
      * @param folderId 文件夹ID
      * @param createBy 创建人
      * @return 影响行数
@@ -68,7 +67,7 @@ public interface KnowledgeFileService {
     /**
      * 文件下载
      *
-     * @param fileId 文件ID
+     * @param fileId   文件ID
      * @param response 响应
      */
     void download(Long fileId, HttpServletResponse response);
@@ -80,4 +79,6 @@ public interface KnowledgeFileService {
      * @param response 响应
      */
     void downloadTemplate(HttpServletResponse response);
+
+//    Map<String, Object> getPreviewInfo(Long fileId);
 }

+ 114 - 41
xzl-admin/src/main/java/com/xzl/web/service/impl/KnowledgeFileServiceImpl.java

@@ -2,8 +2,12 @@ package com.xzl.web.service.impl;
 
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.URLConnection;
 import java.net.URLEncoder;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+
 
 import com.xzl.common.core.domain.entity.KnowledgeFile;
 import com.xzl.common.core.domain.entity.SysFileFolder;
@@ -16,6 +20,7 @@ import com.xzl.web.service.ISysFileFolderService;
 import com.xzl.web.service.KnowledgeFileService;
 import io.minio.*;
 
+
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Service;
@@ -38,12 +43,32 @@ public class KnowledgeFileServiceImpl implements KnowledgeFileService {
     private final ISysFileFolderService sysFileFolderService;
     private final MinioUtil minioUtil;
 
+
+    // 手动维护的文件扩展名与 ContentType 映射表
+    private static final Map<String, String> CONTENT_TYPE_MAP = new HashMap<>();
+    static {
+        CONTENT_TYPE_MAP.put(".xls", "application/vnd.ms-excel");
+        CONTENT_TYPE_MAP.put(".pdf", "application/pdf");
+        CONTENT_TYPE_MAP.put(".jpg", "image/jpeg");
+        CONTENT_TYPE_MAP.put(".jpeg", "image/jpeg");
+        CONTENT_TYPE_MAP.put(".png", "image/png");
+        CONTENT_TYPE_MAP.put(".txt", "text/plain");
+        CONTENT_TYPE_MAP.put(".html", "text/html");
+        CONTENT_TYPE_MAP.put(".doc", "application/msword");
+        CONTENT_TYPE_MAP.put(".ppt", "application/vnd.ms-powerpoint");
+        CONTENT_TYPE_MAP.put(".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
+        CONTENT_TYPE_MAP.put(".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+        CONTENT_TYPE_MAP.put(".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation");
+        // 可以根据需要添加更多文件类型
+    }
+
     public KnowledgeFileServiceImpl(KnowledgeFileMapper knowledgeFileMapper, ISysFileFolderService sysFileFolderService, MinioUtil minioUtil) {
         this.knowledgeFileMapper = knowledgeFileMapper;
         this.sysFileFolderService = sysFileFolderService;
         this.minioUtil = minioUtil;
     }
 
+
     private static final String BUCKET_NAME = "your-bucket-name";
 
     /**
@@ -124,9 +149,9 @@ public class KnowledgeFileServiceImpl implements KnowledgeFileService {
     /**
      * 上传文件并插入数据库
      *
-     * @param file       文件对象
-     * @param folderId   文件夹ID
-     * @param createBy   创建人
+     * @param file     文件对象
+     * @param folderId 文件夹ID
+     * @param createBy 创建人
      * @return 插入结果
      */
     @Override
@@ -134,10 +159,13 @@ public class KnowledgeFileServiceImpl implements KnowledgeFileService {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         String originalFileName = file.getOriginalFilename();
 
+        if (originalFileName == null) {
+            throw new IllegalArgumentException("上传文件的原文件名不能为空");
+        }
+
         // 获取原始文件名和扩展名
         String fileName = originalFileName;
         String ext = "";
-        assert originalFileName != null;
         int dotIndex = originalFileName.lastIndexOf(".");
         if (dotIndex > 0) {
             fileName = originalFileName.substring(0, dotIndex);
@@ -180,13 +208,60 @@ public class KnowledgeFileServiceImpl implements KnowledgeFileService {
         knowledgeFile.setCreateBy(loginUser.getUser().getNickName());
         knowledgeFile.setStatus("0");
         knowledgeFile.setDelFlag("0");
+
+        String contentType = CONTENT_TYPE_MAP.get(ext);
+        if (contentType == null) {
+            contentType = URLConnection.guessContentTypeFromName(originalFileName);
+            if (contentType == null) {
+                contentType = "application/octet-stream"; // 默认类型
+            }
+        }
+
         // 上传文件到 MinIO
-        uploadFile(BUCKET_NAME, objectName, file);
+        uploadFile(BUCKET_NAME, objectName, file, contentType);
 
         return knowledgeFileMapper.insertSysFile(knowledgeFile);
     }
 
-/**
+    /**
+     * 上传文件
+     *
+     * @param bucketName  存储桶名称
+     * @param objectName  文件对象名称
+     * @param file        文件对象
+     * @param contentType 文件内容类型
+     */
+    public void uploadFile(String bucketName, String objectName, MultipartFile file, String contentType) {
+        try {
+            MinioClient minioClient = getMinioClient();
+
+            // 检查存储桶是否存在,不存在则创建
+            boolean found = minioClient.bucketExists(BucketExistsArgs.builder()
+                    .bucket(bucketName)
+                    .build());
+
+            if (!found) {
+                minioClient.makeBucket(MakeBucketArgs.builder()
+                        .bucket(bucketName)
+                        .build());
+            }
+
+            // 上传文件
+            minioClient.putObject(
+                    PutObjectArgs.builder()
+                            .bucket(bucketName)
+                            .object(objectName)
+                            .stream(file.getInputStream(), file.getSize(), -1)
+                            .contentType(contentType)
+                            .build());
+
+            System.out.println("文件上传成功: " + objectName);
+        } catch (Exception e) {
+            System.err.println("上传失败: " + e.getMessage());
+        }
+    }
+
+    /**
      * 获取所有父级文件夹的拼音形式
      *
      * @param folderId 文件夹ID
@@ -245,41 +320,6 @@ public class KnowledgeFileServiceImpl implements KnowledgeFileService {
         }
     }
 
-    /**
-     * 上传文件
-     *
-     * @param bucketName 存储桶名称
-     * @param objectName 文件对象名称
-     * @param file       文件对象
-     */
-    public void uploadFile(String bucketName, String objectName, MultipartFile file) {
-        try {
-            MinioClient minioClient = getMinioClient();
-
-            // 检查存储桶是否存在,不存在则创建
-            boolean found = minioClient.bucketExists(BucketExistsArgs.builder()
-                    .bucket(bucketName)
-                    .build());
-
-            if (!found) {
-                minioClient.makeBucket(MakeBucketArgs.builder()
-                        .bucket(bucketName)
-                        .build());
-            }
-
-            // 上传文件
-            minioClient.putObject(
-                    PutObjectArgs.builder()
-                            .bucket(bucketName)
-                            .object(objectName)
-                            .stream(file.getInputStream(), file.getSize() - 1, 10485760) // 10MB part size
-                            .build());
-
-            System.out.println("文件上传成功: " + objectName);
-        } catch (Exception e) {
-            System.err.println("上传失败: " + e.getMessage());
-        }
-    }
 
     /**
      * 下载模板
@@ -306,6 +346,39 @@ public class KnowledgeFileServiceImpl implements KnowledgeFileService {
             throw new RuntimeException("文件下载失败: " + e.getMessage(), e);
         }
     }
+
+    /*
+      获取文件预览信息
+
+      @param fileId 文件ID
+     * @return 包含预览URL、文件类型和文件名的Map
+     */
+//    @Override
+//    public Map<String, Object> getPreviewInfo(Long fileId) {
+//        KnowledgeFile file = selectSysFileByFileId(fileId);
+//        if (file == null) {
+//            throw new RuntimeException("文件不存在");
+//        }
+//
+//        try {
+//            // 生成预览URL(这里使用MinIO的临时下载链接)
+//            int expiry = 3600; // 1小时有效期
+//            String previewUrl = minioUtil.getDownloadUrl(BUCKET_NAME, file.getFilePath(), expiry);
+//            // 替换URL中的localhost为实际可访问地址
+//            String finalPreviewUrl = previewUrl.replace("http://localhost:9000/", "http://127.0.0.1:52920/");
+//
+//            // 根据文件类型返回不同的预览信息
+//            String fileType = file.getFileType().toLowerCase();
+//            Map<String, Object> result = new HashMap<>();
+//            result.put("previewUrl", finalPreviewUrl);
+//            result.put("fileType", fileType);
+//            result.put("fileName", file.getFileName());
+//
+//            return result;
+//        } catch (Exception e) {
+//            throw new RuntimeException("获取预览链接失败: " + e.getMessage());
+//        }
+//    }
 }
 
 

+ 97 - 73
xzl-common/src/main/java/com/xzl/common/core/domain/entity/KnowledgeFile.java

@@ -2,7 +2,6 @@ package com.xzl.common.core.domain.entity;
 
 import com.xzl.common.annotation.Excel;
 import com.xzl.common.core.domain.BaseEntity;
-import jdk.nashorn.internal.ir.annotations.Ignore;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 import org.springframework.format.annotation.DateTimeFormat;
@@ -11,152 +10,166 @@ import org.springframework.format.annotation.DateTimeFormat;
  * 文件对象 sys_file
  *
  * @author xzl
- * @date 2025-06-17
+ * &#064;date  2025-06-17
  */
-public class KnowledgeFile extends BaseEntity
-{
+public class KnowledgeFile extends BaseEntity {
     private static final long serialVersionUID = 1L;
 
-    /** 文件ID */
+    /**
+     * 文件ID
+     */
     private Long fileId;
 
-    /** 所属文件夹ID */
+    /**
+     * 所属文件夹ID
+     */
     @Excel(name = "所属文件夹ID")
     private Long folderId;
 
-    /** 文件名称 */
+    /**
+     * 文件名称
+     */
     @Excel(name = "文件名称")
     private String fileName;
 
-    /** 文件类型 */
+    /**
+     * 文件类型
+     */
     @Excel(name = "文件类型")
     private String fileType;
 
-    /** 文件大小(字节) */
+    /**
+     * 文件大小(字节)
+     */
     @Excel(name = "文件大小", readConverterExp = "字=节")
     private Long fileSize;
 
-    /** 文件存储路径 */
+    /**
+     * 文件存储路径
+     */
     @Excel(name = "文件存储路径")
     private String filePath;
 
-    /** 下载次数 */
+    /**
+     * 下载次数
+     */
     @Excel(name = "下载次数")
     private Long downloadCount;
 
-    /** 状态(0正常 1停用) */
+    /**
+     * 状态(0正常 1停用)
+     */
     @Excel(name = "状态", readConverterExp = "0=正常,1=停用")
     private String status;
 
-    /** 删除标志(0存在 2删除) */
+    /**
+     * 删除标志(0存在 2删除)
+     */
     private String delFlag;
-    // 添加文件夹名称属性
-    @Ignore
-    private String folderName;
 
+    /**
+     * 部门ID
+     */
     private Long deptId;
 
+    /**
+     * 创建者
+     */
     private String createBy;
 
+    /**
+     * 更新者
+     */
+    private String updateBy;
+
+    /**
+     * 创建时间
+     */
     @DateTimeFormat(pattern = "yyyy-MM-dd")
     private String beginCreateTime;
 
+    // 结束创建时间
     @DateTimeFormat(pattern = "yyyy-MM-dd")
     private String endCreateTime;
 
+    // 开始更新时间
     @DateTimeFormat(pattern = "yyyy-MM-dd")
     private String beginUpdateTime;
 
+    // 结束更新时间
     @DateTimeFormat(pattern = "yyyy-MM-dd")
     private String endUpdateTime;
-    // 省略其他getter和setter
 
-    public String getFolderName() {
-        return folderName;
-    }
 
-    public void setFolderName(String folderName) {
-        this.folderName = folderName;
-    }
-    public void setFileId(Long fileId)
-    {
+    public void setFileId(Long fileId) {
         this.fileId = fileId;
     }
 
-    public Long getFileId()
-    {
+    public Long getFileId() {
         return fileId;
     }
-    public void setFolderId(Long folderId)
-    {
+
+    public void setFolderId(Long folderId) {
         this.folderId = folderId;
     }
 
-    public Long getFolderId()
-    {
+    public Long getFolderId() {
         return folderId;
     }
-    public void setFileName(String fileName)
-    {
+
+    public void setFileName(String fileName) {
         this.fileName = fileName;
     }
 
-    public String getFileName()
-    {
+    public String getFileName() {
         return fileName;
     }
-    public void setFileType(String fileType)
-    {
+
+    public void setFileType(String fileType) {
         this.fileType = fileType;
     }
 
-    public String getFileType()
-    {
+    public String getFileType() {
         return fileType;
     }
-    public void setFileSize(Long fileSize)
-    {
+
+    public void setFileSize(Long fileSize) {
         this.fileSize = fileSize;
     }
 
-    public Long getFileSize()
-    {
+    public Long getFileSize() {
         return fileSize;
     }
-    public void setFilePath(String filePath)
-    {
+
+    public void setFilePath(String filePath) {
         this.filePath = filePath;
     }
 
-    public String getFilePath()
-    {
+    public String getFilePath() {
         return filePath;
     }
-    public void setDownloadCount(Long downloadCount)
-    {
+
+    public void setDownloadCount(Long downloadCount) {
         this.downloadCount = downloadCount;
     }
 
-    public Long getDownloadCount()
-    {
+    public Long getDownloadCount() {
         return downloadCount;
     }
-    public void setStatus(String status)
-    {
+
+    public void setStatus(String status) {
         this.status = status;
     }
 
-    public String getStatus()
-    {
+    public String getStatus() {
         return status;
     }
-    public void setDelFlag(String delFlag)
-    {
+
+    public void setDelFlag(String delFlag) {
         this.delFlag = delFlag;
     }
 
-    public String getDelFlag()
-    {
+    public String getDelFlag() {
         return delFlag;
     }
 
@@ -164,24 +177,25 @@ public class KnowledgeFile extends BaseEntity
     @Override
     public String toString() {
         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
-            .append("fileId", getFileId())
-            .append("folderId", getFolderId())
-            .append("fileName", getFileName())
-            .append("fileType", getFileType())
-            .append("fileSize", getFileSize())
-            .append("filePath", getFilePath())
-            .append("downloadCount", getDownloadCount())
-            .append("status", getStatus())
-            .append("delFlag", getDelFlag())
-            .append("createBy", getCreateBy())
-            .append("createTime", getCreateTime())
-            .append("updateBy", getUpdateBy())
-            .append("updateTime", getUpdateTime())
+                .append("fileId", getFileId())
+                .append("folderId", getFolderId())
+                .append("fileName", getFileName())
+                .append("fileType", getFileType())
+                .append("fileSize", getFileSize())
+                .append("filePath", getFilePath())
+                .append("downloadCount", getDownloadCount())
+                .append("status", getStatus())
+                .append("delFlag", getDelFlag())
+                .append("createBy", getCreateBy())
+                .append("createTime", getCreateTime())
+                .append("updateBy", getUpdateBy())
+                .append("updateTime", getUpdateTime())
                 .append("beginCreateTime", getBeginCreateTime())
                 .append("endCreateTime", getEndCreateTime())
                 .append("beginUpdateTime", getBeginUpdateTime())
                 .append("endUpdateTime", getEndUpdateTime())
-            .toString();
+                .append("deptId", getDeptId())
+                .toString();
     }
 
     public String getBeginCreateTime() {
@@ -233,4 +247,14 @@ public class KnowledgeFile extends BaseEntity
     public void setDeptId(Long deptId) {
         this.deptId = deptId;
     }
+
+    @Override
+    public String getUpdateBy() {
+        return updateBy;
+    }
+
+    @Override
+    public void setUpdateBy(String updateBy) {
+        this.updateBy = updateBy;
+    }
 }

+ 17 - 1
xzl-common/src/main/java/com/xzl/common/utils/MinioUtil.java

@@ -7,7 +7,6 @@ import io.minio.messages.Item;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import javax.annotation.Resource;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
@@ -104,4 +103,21 @@ public class MinioUtil {
     public void deleteObject(String objectName) throws Exception{
         minioClient.removeObject(RemoveObjectArgs.builder().object(objectName).build());
     }
+
+
+//    public String getDownloadUrl(String bucketName, String objectName, int expiry) {
+//        try {
+//            return minioClient.getPresignedObjectUrl(
+//                GetPresignedObjectUrlArgs.builder()
+//                    .method(Method.GET)
+//                    .bucket(bucketName)
+//                    .object(objectName)
+//                    .expiry(expiry)
+//                    .build()
+//            );
+//        } catch (Exception e) {
+//            throw new RuntimeException("获取预览链接失败: " + e.getMessage());
+//        }
+//    }
+
 }

+ 8 - 0
xzl-ui/src/api/system/file.js

@@ -74,4 +74,12 @@ export function downloadTemplate() {
   })
 }
 
+// 获取文件预览URL
+export function getPreviewUrl(fileId) {
+  return request({
+    url: '/system/file/preview-url/' + fileId,
+    method: 'get'
+  })
+}
+
 

+ 182 - 75
xzl-ui/src/views/fileTree/folder/index.vue

@@ -64,8 +64,6 @@
     @click="handleAddFolder(data)">
     新增
   </el-button>
-
-
       <!-- 修改按钮始终显示 -->
   <el-button
     size="mini"
@@ -75,7 +73,6 @@
     @click="handleUpdateFolderName(data)">
     修改
   </el-button>
-
       <!-- 删除按钮始终显示 -->
   <el-button
     size="mini"
@@ -86,7 +83,6 @@
     删除
   </el-button>
 </el-dropdown-menu>
-
       </template>
   </el-dropdown>
 </span>
@@ -154,16 +150,16 @@
             >上传文件
             </el-button>
           </el-col>
-          <el-col :span="1.5">
-            <el-button
-              type="warning"
-              plain
-              icon="el-icon-download"
-              size="mini"
-              @click="handleExport"
-            >导出文件
-            </el-button>
-          </el-col>
+<!--          <el-col :span="1.5">-->
+<!--            <el-button-->
+<!--              type="warning"-->
+<!--              plain-->
+<!--              icon="el-icon-download"-->
+<!--              size="mini"-->
+<!--              @click="handleExport"-->
+<!--            >导出文件-->
+<!--            </el-button>-->
+<!--          </el-col>-->
           <el-col :span="1.5">
             <el-button
               type="warning"
@@ -186,7 +182,6 @@
           </el-col>
           <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
         </el-row>
-
         <!-- 文件列表 --->
         <el-table v-loading="loading" :data="fileList" @selection-change="handleSelectionChange">
           <el-table-column type="selection" width="50" align="center"/>
@@ -227,7 +222,7 @@
           <el-table-column
             label="操作"
             align="center"
-            width="160"
+            width="200"
             class-name="small-padding fixed-width"
           >
             <template #default="scope">
@@ -238,6 +233,13 @@
                 @click="handleDownload(scope.row)"
               >下载
               </el-button>
+<!--              <el-button-->
+<!--                v-if="['pdf', 'doc', 'docx', 'xls', 'xlsx'].includes(scope.row.fileType.toLowerCase())"-->
+<!--                size="mini"-->
+<!--                type="text"-->
+<!--                icon="el-icon-view"-->
+<!--                @click="handlePreview(scope.row)"-->
+<!--              >预览</el-button>-->
             </template>
           </el-table-column>
         </el-table>
@@ -251,6 +253,7 @@
         />
       </el-col>
     </el-row>
+
     <!-- 新增文件夹对话框 -->
     <el-dialog
       :title="isAddFolder ? '新增文件夹' : '修改文件夹名称'"
@@ -279,6 +282,32 @@
         </span>
       </template>
     </el-dialog>
+<!--    &lt;!&ndash; 文件预览对话框 &ndash;&gt;-->
+<!--    <el-dialog-->
+<!--      :title="previewFile.fileName"-->
+<!--      :visible.sync="previewDialogVisible"-->
+<!--      width="80%"-->
+<!--      :close-on-click-modal="false"-->
+<!--      @closed="handlePreviewClosed"-->
+<!--    >-->
+<!--      <div v-if="previewFile.fileType === 'pdf'" class="preview-container">-->
+<!--        &lt;!&ndash; 使用Google Docs在线预览PDF &ndash;&gt;-->
+<!--        <iframe-->
+<!--          :src="'https://docs.google.com/gview?url=' + encodeURIComponent(previewFile.url) + '&embedded=true'"      style="width:100%; height:600px;"-->
+<!--          frameborder="0"-->
+<!--        ></iframe>-->
+<!--      </div>-->
+<!--      <div v-else-if="['doc', 'docx', 'xls', 'xlsx'].includes(previewFile.fileType)" class="preview-container">-->
+<!--        &lt;!&ndash; 使用Office Online Server预览文档 &ndash;&gt;-->
+<!--        <iframe-->
+<!--          :src="'https://view.officeapps.live.com/op/embed.aspx?src=' + encodeURIComponent(previewFile.url)"      style="width:100%; height:600px;"-->
+<!--          frameborder="0"-->
+<!--        ></iframe>-->
+<!--      </div>-->
+<!--      <div v-else class="preview-container">-->
+<!--        <p>该类型文件不支持在线预览</p>-->
+<!--      </div>-->
+<!--    </el-dialog>-->
 
     <!-- 文件导入对话框 -->
     <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
@@ -306,6 +335,33 @@
         <el-button @click="upload.open = false">取 消</el-button>
       </div>
     </el-dialog>
+
+<!--    &lt;!&ndash; 文件预览对话框 &ndash;&gt;-->
+<!--    <el-dialog-->
+<!--      :title="previewFile.fileName"-->
+<!--      :visible.sync="previewDialogVisible"-->
+<!--      width="80%"-->
+<!--      :close-on-click-modal="false"-->
+<!--      @closed="handlePreviewClosed"-->
+<!--    >-->
+<!--      <div v-if="previewFile.fileType === 'pdf'" class="preview-container">-->
+<!--        <iframe-->
+<!--          :src="'https://docs.google.com/gview?url=' + encodeURIComponent(previewFile.url) + '&embedded=true'"-->
+<!--          style="width:100%; height:600px;"-->
+<!--          frameborder="0"-->
+<!--        ></iframe>-->
+<!--      </div>-->
+<!--      <div v-else-if="['doc', 'docx', 'xls', 'xlsx'].includes(previewFile.fileType)" class="preview-container">-->
+<!--        <iframe-->
+<!--          :src="'https://view.officeapps.live.com/op/embed.aspx?src=' + encodeURIComponent(previewFile.url)"-->
+<!--          style="width:100%; height:600px;"-->
+<!--          frameborder="0"-->
+<!--        ></iframe>-->
+<!--      </div>-->
+<!--      <div v-else class="preview-container">-->
+<!--        <p>该类型文件不支持在线预览</p>-->
+<!--      </div>-->
+<!--    </el-dialog>-->
   </div>
 </template>
 
@@ -321,7 +377,15 @@ import {
   getFolder,
   updateFolder
 } from "@/api/system/folder";
-import {addFile, delFile, download, downloadTemplate, listFile, updateFile, updateFileStatus} from "@/api/system/file";
+import {
+  addFile,
+  delFile,
+  download,
+  downloadTemplate,
+  listFile,
+  updateFile,
+  updateFileStatus
+} from "@/api/system/file";
 import dict from "@/utils/dict";
 import {parseTime} from "@/utils/xzl";
 import {listDept} from "@/api/system/dept";
@@ -392,6 +456,12 @@ export default {
           { required: true, message: '请选择部门', trigger: 'change' }
         ]
       },
+      previewDialogVisible: false,
+      previewFile: {
+        fileName: '',
+        url: '',
+        fileType: ''
+      },
       // 是否为新增文件夹操作
       isAddFolder: true,
       // 当前用户部门ID
@@ -435,6 +505,7 @@ export default {
         status: undefined,
         folderId: undefined,
         createBy: undefined,
+        deptId: undefined,
         beginCreateTime: undefined,
         endCreateTime: undefined,
         beginUpdateTime: undefined,
@@ -496,7 +567,6 @@ export default {
     this.getConfigKey("sys.user.initPassword").then(response => {
       this.initPassword = response.msg;
     });
-    console.log('dict.type.sys_file_status:', dict.type.sys_file_status);
   },
   methods: {
     parseTime,
@@ -532,6 +602,7 @@ export default {
         this.loading = false;
       });
     },
+    /** 获取部门下拉树结构 */
     getFileTree() {
       folderTreeSelectByDeptId().then(response => {
         this.fileOptions = response.data;
@@ -549,23 +620,17 @@ export default {
       this.selectedFolderId = data.id;
       this.handleQuery();
     },
+   /** 获取用户信息 */
    getUserInfo() {
-       getUserProfile().then(response => {
-        this.userDeptId = response.data.deptId;
-      });
-    },
-    // 文件状态修改
-    handleStatusChange(row) {
-      const text = row.status === "0" ? "启用" : "停用";
-      this.$modal.confirm('确认要"' + text + '"文件吗?').then(() => {
-        return updateFileStatus(row.fileId, row.status);
-      }).then(() => {
-        this.$modal.msgSuccess(text + "成功");
-      }).catch(() => {
-        // 如果接口失败,回滚状态
-        row.status = row.status === "0" ? "1" : "0";
-      });
+     getUserProfile().then(response => {
+       this.userDeptId = response.data.deptId;
+       // 将部门 ID 赋值给 queryParams
+       this.queryParams.deptId = this.userDeptId;
+       // 调用获取文件列表方法
+       this.getList();
+     });
     },
+    /** 重置按钮操作 */
     // 取消按钮
     cancel() {
       this.open = false;
@@ -591,6 +656,15 @@ export default {
       };
       this.resetForm("form");
     },
+/** 获取部门列表 */
+    async getDeptList() {
+      try {
+        const response = await listDept();
+        this.deptOptions = response.data;
+      } catch (error) {
+        this.$message.error('获取部门列表失败');
+      }
+    },
     /** 搜索按钮操作 */
     handleQuery() {
       this.queryParams.pageNum = 1;
@@ -617,6 +691,7 @@ export default {
         fileType: undefined,
         status: undefined,
         folderId: undefined,
+        deptId: undefined,
         beginCreateTime: undefined,
         endCreateTime: undefined,
         beginUpdateTime: undefined,
@@ -722,24 +797,83 @@ export default {
       // 支持分页:当前页码 * 每页条数 + 当前行索引
       return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
     },
-
-    async getDeptList() {
+    // 文件状态修改
+    handleStatusChange(row) {
+      const text = row.status === "0" ? "启用" : "停用";
+      this.$modal.confirm('确认要"' + text + '"文件吗?').then(() => {
+        return updateFileStatus(row.fileId, row.status);
+      }).then(() => {
+        this.$modal.msgSuccess(text + "成功");
+      }).catch(() => {
+        // 如果接口失败,回滚状态
+        row.status = row.status === "0" ? "1" : "0";
+      });
+    },
+    // 删除文件
+    handleDelete() {
+      if (this.ids.length === 0) {
+        this.$message.warning('您未选择文件,请选择要删除的文件');
+        return;
+      }
+      delFile(this.ids).then(() => {
+        this.$modal.msgSuccess("删除成功");
+        this.getList(); // 刷新文件列表
+      });
+    },
+    // 文件下载
+    async handleDownload(row) {
       try {
-        const response = await listDept();
-        this.deptOptions = response.data;
+        // 等待Promise解析,获取响应对象
+        const response = await download(row.fileId) // fileId替换为实际的文件标识
+        console.log(row.fileName)
+        this.parseBlob(response, row.fileName)
+
       } catch (error) {
-        this.$message.error('获取部门列表失败');
+        this.$modal.msgError('下载失败:' + error.message)
       }
     },
-
+    parseBlob(blob, fileName) {
+      const url = window.URL.createObjectURL(new Blob([blob]))
+      const link = document.createElement('a')
+      link.href = url
+      link.setAttribute('download', fileName) // 设置下载文件名
+      document.body.appendChild(link)
+      link.click()
+      document.body.removeChild(link)
+      window.URL.revokeObjectURL(url) // 释放内存
+    },
+//     async handlePreview(row) {
+//       try {
+//         const response = await getPreviewUrl(row.fileId);
+//         if (response.code === 200) {
+//           this.previewFile = {
+//             fileName: row.fileName,
+//             url: response.data.previewUrl,
+//             fileType: response.data.fileType
+//           };
+//           this.previewDialogVisible = true;
+//         } else {
+//           this.$message.error(response.msg || '获取预览链接失败');
+//         }
+//       } catch (error) {
+//         this.$message.error('文件预览失败:' + error.message);
+//       }
+//     },
+// // 处理预览对话框关闭
+//     handlePreviewClosed() {
+//       // 可选:在这里添加清理逻辑,如撤销预览URL等
+//     },
     // 新增文件夹
-    handleAddFolder(data) {
+    async handleAddFolder(data) {
       this.isAddFolder = true;
+      let deptId = null;
+      const res = await getFolder(data.id);
+      deptId = res.data?.deptId;
       this.folderForm = {
         parentId: data.id,
         folderName: '',
-        deptId: this.userDeptId
-      };
+        deptId: deptId
+    };
       this.folderDialogVisible = true;
     },
     // 提交文件夹表单
@@ -787,7 +921,8 @@ export default {
       }).then(({value}) => {
         getFolder(data.id).then(res => {
           const deptId = res.data.deptId;
-        updateFolder({folderId: data.id, folderName: value, deptId: deptId}).then(() => {
+          const createBy = res.data.createBy;
+        updateFolder({folderId: data.id, folderName: value, deptId: deptId,createBy: createBy}).then(() => {
           this.$modal.msgSuccess("修改成功");
           this.getFileTree(); // 刷新树
         });
@@ -824,37 +959,9 @@ export default {
         });
       });
     },
-    handleDelete() {
-      if (this.ids.length === 0) {
-        this.$message.warning('您未选择文件,请选择要删除的文件');
-        return;
-      }
-      delFile(this.ids).then(() => {
-        this.$modal.msgSuccess("删除成功");
-        this.getList(); // 刷新文件列表
-      });
-    },
-    async handleDownload(row) {
-      try {
-        // 等待Promise解析,获取响应对象
-        const response = await download(row.fileId) // fileId替换为实际的文件标识
-        console.log(row.fileName)
-        this.parseBlob(response, row.fileName)
-
-      } catch (error) {
-        this.$modal.msgError('下载失败:' + error.message)
-      }
-    },
-    parseBlob(blob, fileName) {
-      const url = window.URL.createObjectURL(new Blob([blob]))
-      const link = document.createElement('a')
-      link.href = url
-      link.setAttribute('download', fileName) // 设置下载文件名
-      document.body.appendChild(link)
-      link.click()
-      document.body.removeChild(link)
-      window.URL.revokeObjectURL(url) // 释放内存
-    }
-  },
+  }
 }
 </script>
+
+<style scoped>
+</style>