Browse Source

fix: 导入文档不能为0

wzl 1 year ago
parent
commit
c54db67a4e

+ 5 - 1
packages/core/src/worker/compdfkit_worker.js

@@ -1065,6 +1065,8 @@ class CPDFWorker {
       Module._LoadDocumentByStream(importDoc, length, buffer.length, passwordPtr)
       const pagesCount = Module._GetPageCount(importDoc)
       let importRange
+      let hasZero = false
+
       if (range === 'all') {
         importRange = '1-' + pagesCount
         // importRange = ''
@@ -1081,6 +1083,7 @@ class CPDFWorker {
         parts.forEach(part => {
           if (part.includes('-')) {
             let [start, end] = part.split('-').map(num => parseInt(num))
+            if (start <= 0) hasZero = true
             if (start > max) {
               return
             } else if (end > max) {
@@ -1089,6 +1092,7 @@ class CPDFWorker {
             result.push((start === max) ? start.toString() : `${start}-${end}`)
           } else {
             let num = parseInt(part)
+            if (num <= 0) hasZero = true
             if (num <= max) {
               result.push(num.toString())
             }
@@ -1097,7 +1101,7 @@ class CPDFWorker {
         importRange = result.join(',')
       }
       // console.log('导入文档的页面范围:' + importRange)
-      if (!importRange) return 0
+      if (!importRange || hasZero) return 0
 
       importRange = stringToNewUTF8(importRange)
 

+ 3 - 3
packages/webview/src/components/Dialogs/InsertPageSettingDialog.vue

@@ -224,13 +224,13 @@ const formatText = (inputText) => {
       .flatMap(match => {
         if (match.includes('-')) {
           const [start, end] = match.split('-')
-          const smallest = Math.min(start, end)
-          const largest = Math.max(start, end)
+          const smallest = Math.max(1, Math.min(start, end))
+          const largest = Math.max(1, start, end)
           return Array.from({ length: largest - smallest + 1 }, (_, i) =>
             String(Number(smallest) + i)
           )
         } else {
-          return match
+          return Math.max(1, match)
         }
       })
       .sort((a, b) => a - b)