ソースを参照

pdf下载修改

duy 1 ヶ月 前
コミット
3fce735cf3

+ 1 - 1
package.json

@@ -25,7 +25,7 @@
         "dayjs": "^1.11.13",
         "echarts": "^5.5.1",
         "element-plus": "^2.8.7",
-        "hc-vue3-ui": "^4.9.1",
+        "hc-vue3-ui": "^4.9.2",
         "js-base64": "^3.7.7",
         "js-fast-way": "^0.5.7",
         "js-md5": "^0.8.3",

+ 10 - 0
src/api/modules/data-fill/query.js

@@ -235,4 +235,14 @@ export default {
             params: form,
         })
     },
+    //下载资料查询pdf文件
+
+    async downBussPdf(form) {
+        return HcApi({
+            url: '/api/blade-manager/exceltab/downBussPdf',
+            method: 'get',
+            params: form,
+            responseType: 'blob',
+        })
+    },
 }

+ 35 - 2
src/global/components/hc-pdfs/pdfs.vue

@@ -1,5 +1,13 @@
 <template>
-    <hc-pdf v-if="isPdfDom" :src="pdfUrl" :download="isDownload" :print="isPrint" :is-https="isHttps" :file-name="fileName" />
+    <hc-pdf 
+        v-if="isPdfDom" 
+        :src="pdfUrl" 
+        :download="isDownload" 
+        :print="isPrint" 
+        :is-https="isHttps" 
+        :file-name="fileName" 
+        @download-click="handleDownloadClick" 
+    />
 </template>
 
 <script setup>
@@ -7,6 +15,8 @@ import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
 import { btnAuth, decode } from '~uti/btn-auth'
 import { isNullES } from 'js-fast-way'
 import website from '~src/config'
+import { downloadBlob } from 'js-fast-way'
+import queryApi from '~api/data-fill/query'
 
 const props = defineProps({
     url: {
@@ -21,6 +31,10 @@ const props = defineProps({
         type: String,
         default: '',
     },
+    pdfId: {
+        type: [String, Number],
+        default: '',
+    },
 })
 
 defineOptions({
@@ -31,11 +45,13 @@ defineOptions({
 const queryUrl = ref(props.url)
 const queryCode = ref(props.code)
 const fileName = ref(props.fileName)
-watch(() => [props.url, props.code, props.fileName], ([url, code, name]) => {
+const pdfId = ref(props.pdfId)
+watch(() => [props.url, props.code, props.fileName, props.pdfId], ([url, code, name, idVal]) => {
  
     queryUrl.value = url
     queryCode.value = code
     fileName.value = name
+    pdfId.value = idVal
     setPdfSrcData()
 })
 
@@ -80,4 +96,21 @@ const setPdfSrcData = () => {
 onUnmounted(() => {
     isPdfDom.value = false
 })
+
+//下载按钮点击
+const downLoadTemplateLoading = ref(false)
+const handleDownloadClick = async ()=>{
+
+    
+    downLoadTemplateLoading.value = true
+    const { error, disposition, res, msg } = await queryApi.downBussPdf({ id: pdfId.value })
+    downLoadTemplateLoading.value = false
+    if (!error) {
+        if (disposition) {
+            downloadBlob(res, disposition)
+        } else {
+            window.$message?.error(msg || '数据异常')
+        }
+    }
+}
 </script>

+ 2 - 2
src/utils/btn-auth.js

@@ -19,7 +19,7 @@ export const btnAuth = (key) => {
 }
 
 // 跳转到PDF页面
-export const toPdfPage = (url, name) => {
+export const toPdfPage = (url, name, pdfId) => {
     if (isNullES(url)) {
         window.$message.warning('pdf地址为空')
         return
@@ -27,7 +27,7 @@ export const toPdfPage = (url, name) => {
     if (name) {
         fullDrawer({
             type: 'url',
-            content: '/#/pdf?code=' + encode(url) + '&fileName=' + name,
+            content: '/#/pdf?code=' + encode(url) + '&fileName=' + name + '&pdfId=' + pdfId,
         })
     } else {
         fullDrawer({

+ 7 - 2
src/views/home/pdf.vue

@@ -1,6 +1,6 @@
 <template>
     <div class="hc-pdf-page-box">
-        <hc-pdfs :url="pdfUrl" :code="pdfCode" :file-name="pdfName" />
+        <hc-pdfs :pdf-id="pdfIdVal" :url="pdfUrl" :code="pdfCode" :file-name="pdfName" />
     </div>
 </template>
 
@@ -19,13 +19,18 @@ defineOptions({
 const pdfUrl = ref('')
 const pdfCode = ref('')
 const pdfName = ref('')
+const pdfIdVal = ref('')
 onMounted(() => {
 
     
-    const { url, code, fileName } = useRoutes.query
+    const { url, code, fileName, pdfId } = useRoutes.query
     pdfUrl.value = url
     pdfCode.value = code
     pdfName.value = fileName
+    pdfIdVal.value = pdfId
+
+    
+
 })
 </script>
 

+ 4 - 4
yarn.lock

@@ -2109,10 +2109,10 @@ has-flag@^4.0.0:
   resolved "http://219.151.181.73:9000/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
   integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==
 
-hc-vue3-ui@^4.9.1:
-  version "4.9.1"
-  resolved "http://219.151.181.73:9000/hc-vue3-ui/-/hc-vue3-ui-4.9.1.tgz#5125ee1c3dc48cfcc3971adb051b2b8daf8d1a83"
-  integrity sha512-NGC0+tC3X14RAcyGD44VZh6JFThTGbzazWy1IaEkonl2orwmjv2hihYHG1IBUIrdz6SYQ4g5DDp3ZOl0gTzHGw==
+hc-vue3-ui@^4.9.2:
+  version "4.9.2"
+  resolved "http://219.151.181.73:9000/hc-vue3-ui/-/hc-vue3-ui-4.9.2.tgz#90a761d5ddbdfe394b023b2aaf751908d2fae0df"
+  integrity sha512-r49Kkts/EqPTq49jpj8OoIKqj7v/qHt8wHnYW5euyqreml+kgvt9oBuoN1PibgfBz4NdcmEoDfjU2F6r1CwXyA==
   dependencies:
     axios "^1.7.7"
     dayjs "^1.11.13"