fix: fix berry copy token (#2041)

* [bugfix]修复copy问题

* [update]两阶段编译代码

---------

Co-authored-by: zicorn <a24395@autel.com>
This commit is contained in:
chenzikun
2025-01-31 16:12:59 +08:00
committed by GitHub
parent 605bb06667
commit f95e6b78b8

View File

@@ -107,8 +107,7 @@ export async function onOidcClicked(auth_url, client_id, openInNewTab = false) {
const url = `${auth_url}?client_id=${client_id}&redirect_uri=${redirect_uri}&response_type=${response_type}&scope=${scope}&state=${state}`; const url = `${auth_url}?client_id=${client_id}&redirect_uri=${redirect_uri}&response_type=${response_type}&scope=${scope}&state=${state}`;
if (openInNewTab) { if (openInNewTab) {
window.open(url); window.open(url);
} else } else {
{
window.location.href = url; window.location.href = url;
} }
} }
@@ -210,6 +209,7 @@ export function removeTrailingSlash(url) {
} }
let channelModels = undefined; let channelModels = undefined;
export async function loadChannelModels() { export async function loadChannelModels() {
const res = await API.get('/api/models'); const res = await API.get('/api/models');
const {success, data} = res.data; const {success, data} = res.data;
@@ -236,12 +236,25 @@ export function getChannelModels(type) {
} }
export function copy(text, name = '') { export function copy(text, name = '') {
try { if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(text); navigator.clipboard.writeText(text).then(() => {
} catch (error) { showNotice(`复制${name}成功!`, true);
}, () => {
text = `复制${name}失败,请手动复制:<br /><br />${text}`;
enqueueSnackbar(<SnackbarHTMLContent htmlContent={text}/>, getSnackbarOptions('COPY'));
});
} else {
const textArea = document.createElement("textarea");
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
try {
document.execCommand('copy');
showNotice(`复制${name}成功!`, true);
} catch (err) {
text = `复制${name}失败,请手动复制:<br /><br />${text}`; text = `复制${name}失败,请手动复制:<br /><br />${text}`;
enqueueSnackbar(<SnackbarHTMLContent htmlContent={text}/>, getSnackbarOptions('COPY')); enqueueSnackbar(<SnackbarHTMLContent htmlContent={text}/>, getSnackbarOptions('COPY'));
return;
} }
showSuccess(`复制${name}成功!`); document.body.removeChild(textArea);
}
} }