From 4c9d0bae023cc4b7fda4eff4e9a7b0aaf1349587 Mon Sep 17 00:00:00 2001 From: "97694732@qq.com" Date: Tue, 23 Jun 2026 17:06:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=97=A0ISBN=E4=B8=8A=E4=BC=A0ISBN?= =?UTF-8?q?=E8=A7=84=E5=88=99=E5=A4=84=E7=90=86-13=E4=BD=8D=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E8=BF=94=E5=9B=9E/10=E4=BD=8D=E8=BD=AC13=E4=BD=8D/?= =?UTF-8?q?=E7=A9=BA=E6=88=96=E6=97=A0=E6=B3=95=E8=AF=86=E5=88=AB=E7=94=9F?= =?UTF-8?q?=E6=88=90678=E9=9A=8F=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/upload/upload.vue | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/pages/upload/upload.vue b/pages/upload/upload.vue index 20a7e7f..36948cd 100644 --- a/pages/upload/upload.vue +++ b/pages/upload/upload.vue @@ -3352,10 +3352,45 @@ export default { } }, - // 无ISBN上传 - 获取ISBN值,为空时生成13位随机数(678开头) + // 无ISBN上传 - 获取ISBN值(按规则处理) getNoIsbnIsbnValue() { - if (this.noIsbnIsbn) return this.noIsbnIsbn + var raw = (this.noIsbnIsbn || '').replace(/[^0-9]/g, '') + + // 1. 13位、978/979开头 → 直接返回 + if (raw.length === 13 && (raw.indexOf('978') === 0 || raw.indexOf('979') === 0)) { + return raw + } + + // 2. 10位 → 换算成13位 + if (raw.length === 10) { + return this.convertIsbn10To13(raw) + } + + // 3. 统一书号 if (this.noIsbnUnifyIsbn) return this.noIsbnUnifyIsbn + + // 4. 其他情况(为空或无法识别)→ 生成678开头的13位随机数 + return this.generateRandomIsbn() + }, + + // 10位ISBN转13位 + convertIsbn10To13(isbn10) { + var prefix = '978' + var first9 = isbn10.substring(0, 9) + var base12 = prefix + first9 + // 重新计算第13位校验码 + var sum = 0 + for (var i = 0; i < 12; i++) { + var weight = (i % 2 === 0) ? 1 : 3 + sum += parseInt(base12[i], 10) * weight + } + var remainder = sum % 10 + var checkDigit = remainder === 0 ? 0 : 10 - remainder + return base12 + checkDigit + }, + + // 生成678开头的13位随机ISBN + generateRandomIsbn() { var rand = '' for (var i = 0; i < 10; i++) { rand += Math.floor(Math.random() * 10)