From 560f844dce23f8cff8b086a2bd5047636e66f964 Mon Sep 17 00:00:00 2001 From: cc <94575594@qq.com> Date: Fri, 20 Mar 2026 17:15:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=BC=E5=AE=B9=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20crypto.randomUUID=20=E7=9A=84=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/Pronunciation.vue | 16 ++++++++++++++-- src/views/SpellPractice.vue | 14 +++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/views/Pronunciation.vue b/src/views/Pronunciation.vue index 639fc8e..8902a89 100644 --- a/src/views/Pronunciation.vue +++ b/src/views/Pronunciation.vue @@ -9,6 +9,18 @@ const selectedVoice = ref("1"); const activeCategory = ref("all"); const isGenerating = ref(false); +// 兼容不支持 crypto.randomUUID 的浏览器 +const generateUUID = () => { + if (typeof crypto.randomUUID === 'function') { + return crypto.randomUUID(); + } + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { + const r = Math.random() * 16 | 0; + const v = c === 'x' ? r : (r & 0x3 | 0x8); + return v.toString(16); + }); +}; + // 真实音频播放相关状态 const audioUrl = ref(null); const isPlaying = ref(false); @@ -419,7 +431,7 @@ const handleDemoPlay = async (id) => { "X-Api-App-Id": DOUBAO_APP_ID, "X-Api-Access-Key": DOUBAO_ACCESS_TOKEN, "X-Api-Resource-Id": DOUBAO_RESOURCE_ID, - "X-Api-Request-Id": crypto.randomUUID(), + "X-Api-Request-Id": generateUUID(), }, body: JSON.stringify(payload), }); @@ -604,7 +616,7 @@ const handleGenerate = async () => { "X-Api-App-Id": DOUBAO_APP_ID, "X-Api-Access-Key": DOUBAO_ACCESS_TOKEN, "X-Api-Resource-Id": DOUBAO_RESOURCE_ID, - "X-Api-Request-Id": crypto.randomUUID(), + "X-Api-Request-Id": generateUUID(), }, body: JSON.stringify(payload), }); diff --git a/src/views/SpellPractice.vue b/src/views/SpellPractice.vue index 0df670e..7d0a662 100644 --- a/src/views/SpellPractice.vue +++ b/src/views/SpellPractice.vue @@ -12,6 +12,18 @@ import { const router = useRouter(); +// 兼容不支持 crypto.randomUUID 的浏览器 +const generateUUID = () => { + if (typeof crypto.randomUUID === 'function') { + return crypto.randomUUID(); + } + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { + const r = Math.random() * 16 | 0; + const v = c === 'x' ? r : (r & 0x3 | 0x8); + return v.toString(16); + }); +}; + // 单词输入 const wordInput = ref(""); const wordList = computed(() => { @@ -121,7 +133,7 @@ const preloadAudio = async (word) => { "X-Api-App-Id": DOUBAO_APP_ID, "X-Api-Access-Key": DOUBAO_ACCESS_TOKEN, "X-Api-Resource-Id": DOUBAO_RESOURCE_ID, - "X-Api-Request-Id": crypto.randomUUID(), + "X-Api-Request-Id": generateUUID(), }, body: JSON.stringify(payload), });