fix: 兼容不支持 crypto.randomUUID 的浏览器

This commit is contained in:
cc 2026-03-20 17:15:52 +08:00
parent 6fb13bd12f
commit 560f844dce
2 changed files with 27 additions and 3 deletions

View File

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

View File

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