From 1f8b24c0bf158c644cf7586db95b39eabce62824 Mon Sep 17 00:00:00 2001 From: shirlwang <15254118591@163.com> Date: Fri, 10 Apr 2026 11:15:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=9F=E6=88=90=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=9A=8F=E6=9C=BA=E6=A0=87=E8=AF=86=E7=AC=A6=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E4=BB=A5=E6=94=B9=E8=BF=9B=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageRc/pages/daiban/addbangfu.vue | 31 ++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/packageRc/pages/daiban/addbangfu.vue b/packageRc/pages/daiban/addbangfu.vue index 159914f..0776c28 100644 --- a/packageRc/pages/daiban/addbangfu.vue +++ b/packageRc/pages/daiban/addbangfu.vue @@ -566,15 +566,42 @@ export default { this.serviceForm.practicalSolutionTime = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`; }, + // 使用密码学安全随机源生成标识符 + generateSecureId(length = 16) { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + const charsLength = chars.length; + const randomBytes = new Uint8Array(length); + + // H5/现代浏览器 + if (typeof globalThis !== 'undefined' && globalThis.crypto && typeof globalThis.crypto.getRandomValues === 'function') { + globalThis.crypto.getRandomValues(randomBytes); + } + // 微信小程序环境 + else if (typeof wx !== 'undefined' && typeof wx.getRandomValues === 'function') { + wx.getRandomValues(randomBytes); + } + // 兜底:若运行环境不支持 CSPRNG,显式报错,避免继续使用可预测随机数 + else { + throw new Error('当前环境不支持密码学安全随机数,请在服务端生成标识符'); + } + + let id = ''; + for (let i = 0; i < length; i++) { + id += chars[randomBytes[i] % charsLength]; + } + return id; + }, + // 触发文件上传 triggerFileUpload() { if (this.serviceForm.fileUrl.length < 6) { // 模拟添加文件 const mockFiles = ['文档.pdf', '图片.jpg', '表格.xlsx', '报告.docx']; - const randomFile = mockFiles[Math.floor(Math.random() * mockFiles.length)]; + const secureId = this.generateSecureId(20); + const randomFile = mockFiles[Date.now() % mockFiles.length]; this.serviceForm.fileUrl.push({ name: randomFile, - url: `mock-url/${Date.now()}/${randomFile}` + url: `mock-url/${secureId}/${randomFile}` }); } else { uni.showToast({ title: '最多只能上传6个文件', icon: 'none' });