From 2417a23dc04d04bd422d6f978958e10bf1633548 Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期六, 15 十一月 2025 23:44:56 +0800
Subject: [PATCH] 修改代码

---
 src/views/archiveDoublePdf/index.vue |  219 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 219 insertions(+), 0 deletions(-)

diff --git a/src/views/archiveDoublePdf/index.vue b/src/views/archiveDoublePdf/index.vue
new file mode 100644
index 0000000..c5b58dc
--- /dev/null
+++ b/src/views/archiveDoublePdf/index.vue
@@ -0,0 +1,219 @@
+<template>
+  <div class="app-container">
+    <!-- 姘村钩鎺掑垪瀹瑰櫒 -->
+    <div style="display: flex; align-items: center; gap: 20px;">
+      <!-- 涓婁紶鍖哄煙 -->
+      <div class="upload-container" style="width: 400px; height: 200px;">
+        <el-upload
+            class="upload-demo"
+            ref="upload"
+            :action="uploadUrl"
+            :headers="uploadHeaders"
+            :on-success="handleUploadSuccess"
+            :on-error="handleUploadError"
+            :before-upload="beforeUpload"
+            accept=".pdf"
+            :auto-upload="true"
+            drag
+          >
+          <i class="el-icon-upload"></i>
+          <div class="el-upload__text">灏嗘枃浠舵嫋鍒版澶勶紝鎴�<em>鐐瑰嚮涓婁紶</em></div>
+          <div class="el-upload__tip" slot="tip">鏀寔鍗曚釜鎴栨壒閲忎笂浼狅紝璇烽�夋嫨PDF鏂囦欢</div>
+        </el-upload>
+      </div>
+      
+      <!-- 涓嬭浇鎸夐挳鍖哄煙 - 涓婁紶鍓嶇鐢紝涓婁紶鍚庡彲鐢� -->
+      <div class="download-container" style="white-space: nowrap;">
+        <el-button 
+          type="primary" 
+          icon="el-icon-download" 
+          @click="downloadFile"
+          :disabled="!canDownload"
+        >
+          鑾峰彇涓嬭浇閾炬帴
+        </el-button>
+        <!-- 鏄剧ず涓嬭浇閾炬帴鍖哄煙 -->
+        <div v-if="showDownloadLink" style="margin-left: 10px;">
+          <div style="margin-bottom: 5px;">
+            <span>涓嬭浇閾炬帴:</span>
+          </div>
+          <div style="margin-bottom: 5px;">
+            <a :href="displayedDownloadLink" target="_blank" style="color: #409EFF; word-break: break-all; max-width: 400px; display: inline-block;">
+              {{ displayedDownloadLink }}
+            </a>
+          </div>
+          <div>
+            <el-button 
+              type="text" 
+              icon="el-icon-copy-document" 
+              @click="copyLink"
+              size="small"
+            >
+              澶嶅埗
+            </el-button>
+          </div>
+        </div>
+      </div>
+    </div>
+  </div>
+</template>
+
+<script>
+import { getToken } from '@/utils/auth'
+import { getPdfFile } from '@/api/system/dpdf'
+export default {
+  name: "DoublePdf",
+  data() {
+    return {
+      fid: '',
+      // 閬僵灞�
+      loading: true,
+      // 閫変腑鏁扮粍
+      ids: [],
+      // 闈炲崟涓鐢�
+      single: true,
+      // 闈炲涓鐢�
+      multiple: true,
+      // 鏄剧ず鎼滅储鏉′欢
+      showSearch: true,
+      // 鎬绘潯鏁�
+      total: 0,
+      // 銆愯濉啓鍔熻兘鍚嶇О銆戣〃鏍兼暟鎹�
+      categoryList: [],
+      // 寮瑰嚭灞傛爣棰�
+      title: "",
+      // 鏄惁鏄剧ず寮瑰嚭灞�
+      open: false,
+      // 鏌ヨ鍙傛暟
+      queryParams: {
+        pageNum: 1,
+        pageSize: 10,
+        numb: null,
+        nname: null
+      },
+      // 琛ㄥ崟鍙傛暟
+      form: {},
+      // 琛ㄥ崟鏍¢獙
+      rules: {
+        numb: [
+          { required: true, message: '璇疯緭鍏ョ紪鍙�', trigger: 'blur' }
+        ],
+        nname: [
+          { required: true, message: '璇疯緭鍏ュ悕绉�', trigger: 'blur' }
+        ]
+      },
+      // 鏂囦欢涓婁紶鐩稿叧
+      uploadUrl: process.env.VUE_APP_BASE_API + "/system/doublePdf/upload", // 涓婁紶鎺ュ彛
+      uploadHeaders: {
+        Authorization: 'Bearer ' + getToken()
+      },
+      // 鏂囦欢涓嬭浇鐩稿叧
+      canDownload: false, // 鏄惁鍙互涓嬭浇
+      uploadedFileName: '', // 宸蹭笂浼犵殑鏂囦欢鍚�
+      downloadUrl: '', // 涓嬭浇閾炬帴
+      showDownloadLink: false, // 鏄惁鏄剧ず涓嬭浇閾炬帴
+      displayedDownloadLink: '' // 鏄剧ず鐨勪笅杞介摼鎺�
+    }
+  },
+  created() {
+    this.getList()
+  },
+  methods: {
+    /** 鏌ヨ銆愯濉啓鍔熻兘鍚嶇О銆戝垪琛� */
+    getList() {
+      this.loading = true
+    },
+    
+    /** 涓婁紶鍓嶆鏌� */
+    beforeUpload(file) {
+      const isPdf = file.type === 'application/pdf'
+      const isLt50M = file.size / 1024 / 1024 < 50
+      
+      if (!isPdf) {
+        this.$message.error('涓婁紶鏂囦欢鍙兘鏄� PDF 鏍煎紡!')
+      }
+      if (!isLt50M) {
+        this.$message.error('涓婁紶鏂囦欢澶у皬涓嶈兘瓒呰繃 50MB!')
+      }
+      
+      return isPdf && isLt50M
+    },
+    
+    /** 涓婁紶鎴愬姛澶勭悊 */
+    handleUploadSuccess(response) {
+      console.log(response)
+      console.log("-------------")
+      if (response.code === 200) {
+        this.$message.success('涓婁紶鎴愬姛')
+        // 璁剧疆涓嬭浇鐩稿叧淇℃伅
+        this.canDownload = true
+        // 鍋囪鍝嶅簲涓寘鍚枃浠跺悕鍜屼笅杞介摼鎺�
+        this.fid = (response.data.data)
+        // this.uploadedFileName = response.fileName || '涓婁紶鐨勬枃浠�'
+        // this.downloadUrl = response.downloadUrl || (process.env.VUE_APP_BASE_API + "/system/doublePdf/download?fileId=" + response.fileId)
+        // // 鍙互鍦ㄨ繖閲屽埛鏂板垪琛ㄦ暟鎹�
+        // // this.getList()
+      } else {
+        this.$message.error(response.msg || '涓婁紶澶辫触')
+      }
+    },
+    
+    /** 鑾峰彇涓嬭浇閾炬帴 */
+    downloadFile() {
+      // 鍙戣捣ajax璇锋眰鑾峰彇涓嬭浇閾炬帴
+      getPdfFile(this.fid).then(response => {
+        console.log(response)
+          // 纭繚response.data.data鏄瓧绗︿覆绫诲瀷
+          const dataStr = String(response.data.data)
+          alert(dataStr)
+          if(dataStr.includes("浠诲姟灏氭湭缁撴潫锛屾棤娉曡幏鍙栨枃浠�")) {
+            this.$message.success("鏂囦欢娌℃湁澶勭悊瀹岋紝绋嶇瓑鐗囧埢")
+            return;
+          }
+        if (response.code === 200 && response.data) {
+          // 鍋囪鍝嶅簲涓寘鍚笅杞介摼鎺�
+          this.displayedDownloadLink = response.data.data || response.data.downloadUrl || response.data
+          this.showDownloadLink = true
+          this.$message.success('涓嬭浇閾炬帴宸茶幏鍙�')
+        } else {
+          this.$message.error('鑾峰彇涓嬭浇閾炬帴澶辫触: ' + (response.msg || '鏈煡閿欒'))
+        }
+      }).catch(error => {
+        console.error('鑾峰彇涓嬭浇閾炬帴澶辫触:', error)
+        this.$message.error('鑾峰彇涓嬭浇閾炬帴澶辫触锛岃閲嶈瘯')
+      })
+    },
+    
+    /** 澶嶅埗閾炬帴鍒板壀璐存澘 */
+    copyLink() {
+      if (this.displayedDownloadLink) {
+        // 鍒涘缓涓存椂鏂囨湰鍖哄煙
+        const textarea = document.createElement('textarea')
+        textarea.value = this.displayedDownloadLink
+        textarea.style.position = 'fixed'
+        textarea.style.opacity = '0'
+        document.body.appendChild(textarea)
+        textarea.select()
+        
+        try {
+          document.execCommand('copy')
+          this.$message.success('閾炬帴宸插鍒跺埌鍓创鏉�')
+        } catch (err) {
+          this.$message.error('澶嶅埗澶辫触锛岃鎵嬪姩澶嶅埗')
+          console.error('Copy error:', err)
+        } finally {
+          document.body.removeChild(textarea)
+        }
+      }
+    },
+    
+    /** 涓婁紶澶辫触澶勭悊 */
+    handleUploadError(err) {
+      this.$message.error('涓婁紶澶辫触锛岃閲嶈瘯')
+      console.error('Upload error:', err)
+    }
+  }
+}
+    /** 鎻愪氦鎸夐挳 */
+
+</script>

--
Gitblit v1.9.1