Zhangtf vor 3 Wochen
Ursprung
Commit
82fc12f9af

+ 4 - 11
xzl-admin/src/main/java/com/xzl/web/core/config/MinIOConfig.java

@@ -1,26 +1,19 @@
 package com.xzl.web.core.config;
-import io.minio.BucketExistsArgs;
-import io.minio.MakeBucketArgs;
 import io.minio.MinioClient;
-import io.minio.PutObjectArgs;
-import io.minio.errors.*;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
-import java.io.FileInputStream;
-
 @Configuration
 public class MinIOConfig {
-    private static final String ENDPOINT = "http://192.168.1.12:9000";
+    private static final String ENDPOINT = "http://127.0.0.1:9000";
     private static final String ACCESS_KEY = "your-access-key";
     private static final String SECRET_KEY = "your-secret-key";
 
     @Bean
-    public static MinioClient getMinioClient() throws Exception {
-
-
+    public MinioClient getMinioClient() throws Exception {
+        System.out.println("minioClient ...");
         return MinioClient.builder()
-                .endpoint("http://192.168.1.80:9000")
+                .endpoint("http://127.0.0.1:9000")
                 .credentials("minioadmin", "minioadmin")
                 .build();
     }

+ 7 - 4
xzl-admin/src/main/java/com/xzl/web/service/impl/KnowledgeFileServiceImpl.java

@@ -22,6 +22,7 @@ import com.xzl.web.service.KnowledgeFileService;
 import io.minio.*;
 
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Service;
@@ -30,7 +31,6 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 
-import static com.xzl.web.core.config.MinIOConfig.getMinioClient;
 
 /**
  * 文件Service业务层处理
@@ -44,6 +44,9 @@ public class KnowledgeFileServiceImpl implements KnowledgeFileService {
     private final ISysFileFolderService sysFileFolderService;
     private final MinioUtil minioUtil;
 
+    @Autowired
+    private MinioClient minioClient;
+
 
     // 手动维护的文件扩展名与 ContentType 映射表
     private static final Map<String, String> CONTENT_TYPE_MAP = new HashMap<>();
@@ -121,7 +124,7 @@ public class KnowledgeFileServiceImpl implements KnowledgeFileService {
         // 删除MinIO存储桶中的文件
         for (KnowledgeFile file : files) {
             try {
-                MinioClient minioClient = getMinioClient();
+//                MinioClient minioClient = getMinioClient();
                 minioClient.removeObject(RemoveObjectArgs.builder()
                         .bucket(BUCKET_NAME)
                         .object(file.getFilePath())
@@ -234,7 +237,7 @@ public class KnowledgeFileServiceImpl implements KnowledgeFileService {
      */
     public void uploadFile(String bucketName, String objectName, MultipartFile file, String contentType) {
         try {
-            MinioClient minioClient = getMinioClient();
+//            MinioClient minioClient = getMinioClient();
 
             // 检查存储桶是否存在,不存在则创建
             boolean found = minioClient.bucketExists(BucketExistsArgs.builder()
@@ -350,7 +353,7 @@ public class KnowledgeFileServiceImpl implements KnowledgeFileService {
             // 记录详细错误日志
             System.err.println("文件下载失败: " + e.getMessage());
             e.printStackTrace();
-            
+
             // 提供更友好的错误响应
             try {
                 response.reset();

+ 1 - 1
xzl-admin/src/main/resources/application-dev.yml

@@ -71,7 +71,7 @@ sqlFilePath: /usr/local/sql
 ERImagePath: /usr/local/ERImage
 
 minio:
-    endpoint: http://192.168.1.80:9000
+    endpoint: http://192.168.145.1:9000
     access-key: minioadmin
     secret-key: minioadmin
     bucket-name: mc-kb

+ 50 - 6
xzl-ui/src/views/fileTree/folder/MindmapView.vue

@@ -3,10 +3,14 @@
     <div class="header">
       <h1>麻城知识库思维导图</h1>
       <div class="controls">
-        <button @click="toggleFullscreen" class="control-btn">
-          <i :class="isFullscreen ? 'el-icon-shrink' : 'el-icon-full-screen'"></i>
-          {{ isFullscreen ? '退出全屏' : '全屏显示' }}
+        <button @click="downloadSvg" class="control-btn">
+          <i class="el-icon-download"></i>
+          下载SVG
         </button>
+        <!--        <button @click="toggleFullscreen" class="control-btn">-->
+        <!--          <i :class="isFullscreen ? 'el-icon-shrink' : 'el-icon-full-screen'"></i>-->
+        <!--          {{ isFullscreen ? '退出全屏' : '全屏显示' }}-->
+        <!--        </button>-->
       </div>
     </div>
 
@@ -66,11 +70,9 @@ export default {
     getQueryData() {
       const query = this.$route.query;
       this.markdownContent = decodeURIComponent(query.data);
-
     },
     loadMarkmap() {
-
-this.getQueryData();
+      this.getQueryData();
       // 动态加载markmap
       const script = document.createElement('script');
       script.src = 'https://cdn.jsdelivr.net/npm/markmap-autoloader';
@@ -121,6 +123,48 @@ this.getQueryData();
       this.$nextTick(() => {
         setTimeout(this.fixSvgDimensions, 300);
       });
+    },
+
+    downloadSvg() {
+      const svgElement = document.querySelector('.markmap svg');
+      if (!svgElement) {
+        console.error('未找到SVG元素');
+        return;
+      }
+
+      try {
+        // 克隆SVG元素以避免影响原始显示
+        const clonedSvg = svgElement.cloneNode(true);
+
+        // 设置固定的宽度和高度以确保导出质量
+        const bbox = svgElement.getBBox();
+        clonedSvg.setAttribute('width', bbox.width + 100);
+        clonedSvg.setAttribute('height', bbox.height + 100);
+        clonedSvg.setAttribute('viewBox', `${bbox.x - 50} ${bbox.y - 50} ${bbox.width + 100} ${bbox.height + 100}`);
+
+        // 序列化SVG
+        const serializer = new XMLSerializer();
+        const svgStr = serializer.serializeToString(clonedSvg);
+
+        // 创建Blob并下载
+        const blob = new Blob([svgStr], { type: 'image/svg+xml' });
+        const url = URL.createObjectURL(blob);
+        const downloadLink = document.createElement('a');
+
+        // 生成文件名
+        const fileName = `麻城知识库思维导图_${new Date().toISOString().slice(0, 10)}.svg`;
+
+        downloadLink.href = url;
+        downloadLink.download = fileName;
+        document.body.appendChild(downloadLink);
+        downloadLink.click();
+        document.body.removeChild(downloadLink);
+
+        // 清理URL
+        setTimeout(() => URL.revokeObjectURL(url), 100);
+      } catch (error) {
+        console.error('下载SVG时出错:', error);
+      }
     }
   }
 };

+ 30 - 6
xzl-ui/src/views/fileTree/folder/index.vue

@@ -73,6 +73,15 @@
     @click="handleUpdateFolderName(data)">
     修改
   </el-button>
+
+        <el-button
+          size="mini"
+          type="primary"
+          plain
+          style="width: 120px;border: none; text-align: center;"
+          @click="swdt(data)">
+    查看思维导图
+  </el-button>
       <!-- 删除按钮始终显示 -->
   <el-button
     size="mini"
@@ -702,11 +711,7 @@ export default {
       generateMarkdown(node, 2);
       return markdownContent;
     },
-
-    // 修改后的handleNodeClick方法
-    handleNodeClick(data) {
-      // ...原有文件列表加载逻辑
-
+    swdt(data){
       // 新增:生成Markdown格式思维导图并跳转
       try {
         const subTree = this.getSubTree(data.id);
@@ -719,7 +724,16 @@ export default {
         console.log('生成的Markdown格式数据:', markdownData);
 
         // 跳转到思维导图页面
-        this.$router.push({
+        // this.$router.push({
+        //   path: '/mindmap',
+        //   query: {
+        //     data: encodeURIComponent(markdownData),
+        //     title: data.label,
+        //     format: 'markdown'
+        //   }
+        // });
+
+        const routeData = this.$router.resolve({
           path: '/mindmap',
           query: {
             data: encodeURIComponent(markdownData),
@@ -727,11 +741,21 @@ export default {
             format: 'markdown'
           }
         });
+        window.open(routeData.href, '_blank');
       } catch (error) {
         console.error('生成思维导图失败:', error);
         this.$message.error('生成思维导图失败');
       }
     },
+    // 修改后的handleNodeClick方法
+    handleNodeClick(data) {
+      // ...原有文件列表加载逻辑
+
+      this.queryParams.folderId = data.id;
+      this.selectedFolderId = data.id;
+      this.handleQuery();
+
+    },
 // 验证思维导图数据格式
     validateMermaidData(data) {
       if (!data) return false;