fix: 兼容不支持 crypto.randomUUID 的浏览器
This commit is contained in:
parent
6fb13bd12f
commit
560f844dce
|
|
@ -9,6 +9,18 @@ const selectedVoice = ref("1");
|
||||||
const activeCategory = ref("all");
|
const activeCategory = ref("all");
|
||||||
const isGenerating = ref(false);
|
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 audioUrl = ref(null);
|
||||||
const isPlaying = ref(false);
|
const isPlaying = ref(false);
|
||||||
|
|
@ -419,7 +431,7 @@ const handleDemoPlay = async (id) => {
|
||||||
"X-Api-App-Id": DOUBAO_APP_ID,
|
"X-Api-App-Id": DOUBAO_APP_ID,
|
||||||
"X-Api-Access-Key": DOUBAO_ACCESS_TOKEN,
|
"X-Api-Access-Key": DOUBAO_ACCESS_TOKEN,
|
||||||
"X-Api-Resource-Id": DOUBAO_RESOURCE_ID,
|
"X-Api-Resource-Id": DOUBAO_RESOURCE_ID,
|
||||||
"X-Api-Request-Id": crypto.randomUUID(),
|
"X-Api-Request-Id": generateUUID(),
|
||||||
},
|
},
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
|
|
@ -604,7 +616,7 @@ const handleGenerate = async () => {
|
||||||
"X-Api-App-Id": DOUBAO_APP_ID,
|
"X-Api-App-Id": DOUBAO_APP_ID,
|
||||||
"X-Api-Access-Key": DOUBAO_ACCESS_TOKEN,
|
"X-Api-Access-Key": DOUBAO_ACCESS_TOKEN,
|
||||||
"X-Api-Resource-Id": DOUBAO_RESOURCE_ID,
|
"X-Api-Resource-Id": DOUBAO_RESOURCE_ID,
|
||||||
"X-Api-Request-Id": crypto.randomUUID(),
|
"X-Api-Request-Id": generateUUID(),
|
||||||
},
|
},
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,18 @@ import {
|
||||||
|
|
||||||
const router = useRouter();
|
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 wordInput = ref("");
|
||||||
const wordList = computed(() => {
|
const wordList = computed(() => {
|
||||||
|
|
@ -121,7 +133,7 @@ const preloadAudio = async (word) => {
|
||||||
"X-Api-App-Id": DOUBAO_APP_ID,
|
"X-Api-App-Id": DOUBAO_APP_ID,
|
||||||
"X-Api-Access-Key": DOUBAO_ACCESS_TOKEN,
|
"X-Api-Access-Key": DOUBAO_ACCESS_TOKEN,
|
||||||
"X-Api-Resource-Id": DOUBAO_RESOURCE_ID,
|
"X-Api-Resource-Id": DOUBAO_RESOURCE_ID,
|
||||||
"X-Api-Request-Id": crypto.randomUUID(),
|
"X-Api-Request-Id": generateUUID(),
|
||||||
},
|
},
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue