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), });