فهرست منبع

预览pdf编码修改

duy 3 هفته پیش
والد
کامیت
6378c7e020

+ 2 - 1
src/plugins/HcPdfSign.js

@@ -1,4 +1,5 @@
 import { getArrValue, getRandom, isNullES, isNumber, isString } from 'js-fast-way'
+import encodeFullUrl from '~src/utils/safe-url-encoder'
 
 // PDF签章类
 export default class HcPdfSign {
@@ -124,7 +125,7 @@ export default class HcPdfSign {
     static createIframe(dom, url, isShowYinzhang) {
         const iframe = document.createElement('iframe')
         iframe.setAttribute('id', 'pdf-sign-' + getRandom(6))
-        iframe.src = `/plugins/pdfjs/sign/web/viewer.html?file=${encodeURIComponent(url)}#zoom=100`
+        iframe.src = `/plugins/pdfjs/sign/web/viewer.html?file=${encodeFullUrl(url)}#zoom=100`
         iframe.style.width = '100%'
         iframe.style.height = '100%'
         iframe.style.border = '1px solid #ccc'

+ 3 - 1
src/utils/btn-auth.js

@@ -3,6 +3,8 @@ import { useAppStore } from '~src/store'
 import { decode, encode } from 'js-base64'
 import { getObjVal, isNullES } from 'js-fast-way'
 import { fullDrawer } from 'hc-vue3-ui'
+import encodeFullUrl from '~src/utils/safe-url-encoder'
+
 
 //初始变量
 const store = useAppStore(pinia)
@@ -24,7 +26,7 @@ export const toPdfPage = (url) => {
         return
     }
     let rawUrl = url
-    const encodedUrl = encodeURIComponent(rawUrl)
+    const encodedUrl = encodeFullUrl(rawUrl)
 console.log(encodedUrl, 'encodedUrl')
 
     fullDrawer({

+ 109 - 0
src/utils/safe-url-encoder.js

@@ -0,0 +1,109 @@
+/**
+ * 安全地编码完整URL中的文件名部分
+ * @param {string} fullUrl - 需要编码的完整URL
+ * @returns {string} 编码后的URL
+ */
+function encodeFullUrl(fullUrl) {
+    if (!fullUrl || fullUrl === '') {
+        return fullUrl
+    }
+
+    // 查找最后一个斜杠位置
+    const lastSlashIndex = fullUrl.lastIndexOf('/')
+
+    // 如果没有斜杠,直接返回原URL
+    if (lastSlashIndex === -1) {
+        return fullUrl
+    }
+
+    // 分割URL为基本部分和文件名
+    const baseUrl = fullUrl.substring(0, lastSlashIndex + 1)
+    const fileName = fullUrl.substring(lastSlashIndex + 1)
+
+    // 只对文件名进行安全编码
+    const safeFileName = encodeURLComponent(fileName)
+
+    // 重新组合URL
+    return baseUrl + safeFileName
+}
+
+/**
+ * 编码URL组件,只对不安全字符进行编码
+ * @param {string} input - 需要编码的字符串
+ * @returns {string} 编码后的字符串
+ */
+function encodeURLComponent(input) {
+    if (!input || input === '') {
+        return input
+    }
+
+    // 检查是否只包含安全字符
+    if (isSafeString(input)) {
+        return input
+    }
+
+    // 需要编码的特殊处理
+    return encodeSpecial(input)
+}
+
+/**
+ * 检查字符串是否只包含安全字符
+ * @param {string} input - 需要检查的字符串
+ * @returns {boolean} 如果只包含安全字符返回true,否则返回false
+ */
+function isSafeString(input) {
+    for (let i = 0; i < input.length; i++) {
+        const c = input.charAt(i)
+        if (!isSafeCharacter(c)) {
+            return false
+        }
+    }
+    return true
+}
+
+/**
+ * 检查字符是否为安全字符
+ * @param {string} c - 需要检查的字符
+ * @returns {boolean} 如果是安全字符返回true,否则返回false
+ */
+function isSafeCharacter(c) {
+    return /^[a-zA-Z0-9\-_.~*]$/.test(c)
+}
+
+/**
+ * 特殊字符编码处理
+ * @param {string} input - 需要编码的字符串
+ * @returns {string} 编码后的字符串
+ */
+function encodeSpecial(input) {
+    try {
+        // 首先处理百分号(防止双重编码)
+        let percentFixed = input.replace(/%/g, '%25')
+
+        // 执行URL编码
+        let encoded = encodeURIComponent(percentFixed)
+
+        // 处理空格和修复双重编码问题
+        return encoded
+            .replace(/\+/g, '%20')
+            .replace(/%2525/g, '%25')
+    } catch (e) {
+        return input // 出错时返回原始输入
+    }
+}
+
+
+
+
+
+// 导出方法
+export {
+    encodeFullUrl,
+    encodeURLComponent,
+    isSafeString,
+    isSafeCharacter,
+    encodeSpecial,
+}
+
+// 默认导出主要方法
+export default encodeFullUrl

+ 3 - 2
src/views/archives/manage/carryDrawer/carrySpotChecksDrawer.vue

@@ -142,6 +142,7 @@ import MetaTable from '../components/meta-table.vue'
 import archiveQueryApi from '~api/using/query.js'
 import { getArrValue } from 'js-fast-way'
 import tuningApi from '~api/archiveConfig/tuning.js'
+import encodeFullUrl from '~src/utils/safe-url-encoder'
 
 
 //参数
@@ -297,7 +298,7 @@ const getArchiveFileListData = async () => {
                    checkmetaFileId.value = cscTableData1.value[0].id
             // pdfUrl.value = cscTableData1.value[0].pdfFileUrl
                 let rawUrl = cscTableData1.value[0].pdfFileUrl
-                const encodedUrl = encodeURIComponent(rawUrl)
+                const encodedUrl = encodeFullUrl(rawUrl)
                 pdfUrl.value = encodedUrl
                 checkId.value = cscTableData1.value[0].id
                 getmetaInfo()
@@ -338,7 +339,7 @@ const changePdf = (row) => {
     }, 100)
 
     let rawUrl = row['pdfFileUrl'] || ''
-    const encodedUrl = encodeURIComponent(rawUrl)
+    const encodedUrl = encodeFullUrl(rawUrl)
     pdfUrl.value = encodedUrl
     checkId.value = row.id
     checkmetaFileId.value = row.id

+ 15 - 12
src/views/archives/manage/inspects.vue

@@ -184,6 +184,7 @@ import tuningApi from '~api/archiveConfig/tuning.js'
 import archiveQueryApi from '~api/using/query.js'
 import inspectApi from '~api/transfer/inspects.js'
 import tuning from '../../../api/modules/archiveConfig/tuning'
+import encodeFullUrl from '~src/utils/safe-url-encoder'
 
 //变量
 const useAppState = useAppStore()
@@ -324,16 +325,18 @@ const tableRowClick = async ({ row }) => {
     // checkId.value = ''
 
 
-    const url = await viewPdf(row.id)
-        pdfUrl.value = url
-        if (pdfUrl.value && pdfUrl?.value.length > 0 && isCarrySpotChecksDrawer.value) {
-            setTimeout(() => {
-                if (isCarrySpotChecksDrawer.value) {
-                    serReviewFile()
-                }
+    // const url = await viewPdf(row.id)
+    //     pdfUrl.value = url
+    console.log(row, 'row')
+    
+        // if (pdfUrl.value && pdfUrl?.value.length > 0 && isCarrySpotChecksDrawer.value) {
+        //     setTimeout(() => {
+        //         if (isCarrySpotChecksDrawer.value) {
+        //             serReviewFile()
+        //         }
 
-            }, 30000)
-        }
+        //     }, 30000)
+        // }
 }
 //获取卷内文件数据
 const getArchiveFileListData = async ()=>{
@@ -348,9 +351,9 @@ const getArchiveFileListData = async ()=>{
         cscTableData1.value = getArrValue(data['approvalFileList'])
         if (cscTableData1.value.length > 0) {
             checkmetaFileId.value = cscTableData1.value[0].id
-            // pdfUrl.value = cscTableData1.value[0]?.pdfFileUrl || ''
             let rawUrl = cscTableData1.value[0]?.pdfFileUrl || ''
-        const encodedUrl = encodeURIComponent(rawUrl)
+
+        const encodedUrl = encodeFullUrl(rawUrl)
         pdfUrl.value = encodedUrl
         console.log(encodedUrl, 'encodedUrl')
         
@@ -394,7 +397,7 @@ const changePdf = (row)=>{
     // pdfUrl.value = row['pdfFileUrl'] || ''
 
     let rawUrl = row['pdfFileUrl'] || ''
-        const encodedUrl = encodeURIComponent(rawUrl)
+            const encodedUrl = encodeFullUrl(rawUrl)
         pdfUrl.value = encodedUrl
     checkId.value = row.id
     checkmetaFileId.value = row.id

+ 4 - 3
src/views/archives/manage/query.vue

@@ -546,6 +546,7 @@ import imageViewGui from '~src/assets/view/gui.png'
 import imageViewGui1 from '~src/assets/view/gui1.png'
 import imageViewGui2 from '~src/assets/view/gui2.png'
 import { setTimeString } from '~src/utils/tools'
+import encodeFullUrl from '~src/utils/safe-url-encoder'
 
 //变量
 const useAppState = useAppStore()
@@ -1125,7 +1126,7 @@ const getArchiveFileListData = async () => {
         cscTableData1.value = getArrValue(data['approvalFileList'])
         // pdfUrl.value = tableFileData.value[0]?.pdfFileUrl
         let rawUrl = tableFileData.value[0]?.pdfFileUrl
-        const encodedUrl = encodeURIComponent(rawUrl)
+        const encodedUrl = encodeFullUrl(rawUrl)
         pdfUrl.value = encodedUrl
         checkId.value = tableFileData.value[0]?.id
 
@@ -1199,7 +1200,7 @@ const consultFileClick = async (row, type) => {
         checkId.value = row.id
         // pdfUrl.value = row.pdfFileUrl
         let rawUrl = row.pdfFileUrl
-        const encodedUrl = encodeURIComponent(rawUrl)
+        const encodedUrl = encodeFullUrl(rawUrl)
         pdfUrl.value = encodedUrl
         getmetaInfo(checkId.value)
         isCarrySpotChecksDrawer.value = true
@@ -1232,7 +1233,7 @@ const changePdf = (row, index) => {
     // pdfUrl.value = row['pdfFileUrl'] || ''
  
     let rawUrl = row['pdfFileUrl'] || ''
-        const encodedUrl = encodeURIComponent(rawUrl)
+        const encodedUrl = encodeFullUrl(rawUrl)
         pdfUrl.value = encodedUrl
     checkId.value = row.id
     isFile.value = 2

+ 3 - 2
src/views/transfer/components/carry-spot-checks.vue

@@ -173,6 +173,7 @@ import archiveQueryApi from '~api/using/query.js'
 import { getArrValue, getObjValue, getRandom } from 'js-fast-way'
 import tuningApi from '~api/archiveConfig/tuning.js'
 import initialgApi from '~api/initial/initial'
+import encodeFullUrl from '~src/utils/safe-url-encoder'
 
 //参数
 const props = defineProps({
@@ -328,7 +329,7 @@ const getArchiveFileListData = async () => {
             checkmetaFileId.value = cscTableData1.value[0].id
             // pdfUrl.value = cscTableData1.value[0].pdfFileUrl
             let rawUrl = cscTableData1.value[0].pdfFileUrl
-        const encodedUrl = encodeURIComponent(rawUrl)
+        const encodedUrl = encodeFullUrl(rawUrl)
         pdfUrl.value = encodedUrl
             checkId.value = cscTableData1.value[0].id
             getmetaInfo()
@@ -367,7 +368,7 @@ const changePdf = (row) => {
     }, 100)
     // pdfUrl.value = row['pdfFileUrl'] || ''
     let rawUrl = row['pdfFileUrl'] || ''
-    const encodedUrl = encodeURIComponent(rawUrl)
+    const encodedUrl = encodeFullUrl(rawUrl)
     pdfUrl.value = encodedUrl
     checkId.value = row.id
     checkmetaFileId.value = row.id