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

@@ -1,6 +1,6 @@
import { enqueueSnackbar } from 'notistack';
import { snackbarConstants } from 'constants/SnackbarConstants';
import { API } from './api';
import {enqueueSnackbar} from 'notistack';
import {snackbarConstants} from 'constants/SnackbarConstants';
import {API} from './api';
export function getSystemName() {
let system_name = localStorage.getItem('system_name');
@@ -13,15 +13,15 @@ export function isMobile() {
}
// eslint-disable-next-line
export function SnackbarHTMLContent({ htmlContent }) {
return <div dangerouslySetInnerHTML={{ __html: htmlContent }} />;
export function SnackbarHTMLContent({htmlContent}) {
return <div dangerouslySetInnerHTML={{__html: htmlContent}}/>;
}
export function getSnackbarOptions(variant) {
let options = snackbarConstants.Common[variant];
if (isMobile()) {
// 合并 options 和 snackbarConstants.Mobile
options = { ...options, ...snackbarConstants.Mobile };
options = {...options, ...snackbarConstants.Mobile};
}
return options;
}
@@ -51,7 +51,7 @@ export function showError(error) {
export function showNotice(message, isHTML = false) {
if (isHTML) {
enqueueSnackbar(<SnackbarHTMLContent htmlContent={message} />, getSnackbarOptions('NOTICE'));
enqueueSnackbar(<SnackbarHTMLContent htmlContent={message}/>, getSnackbarOptions('NOTICE'));
} else {
enqueueSnackbar(message, getSnackbarOptions('NOTICE'));
}
@@ -71,7 +71,7 @@ export function showInfo(message) {
export async function getOAuthState() {
const res = await API.get('/api/oauth/state');
const { success, message, data } = res.data;
const {success, message, data} = res.data;
if (success) {
return data;
} else {
@@ -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}`;
if (openInNewTab) {
window.open(url);
} else
{
} else {
window.location.href = url;
}
}
@@ -193,7 +192,7 @@ export function renderQuotaWithPrompt(quota, digits) {
}
export function downloadTextAsFile(text, filename) {
let blob = new Blob([text], { type: 'text/plain;charset=utf-8' });
let blob = new Blob([text], {type: 'text/plain;charset=utf-8'});
let url = URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url;
@@ -210,9 +209,10 @@ export function removeTrailingSlash(url) {
}
let channelModels = undefined;
export async function loadChannelModels() {
const res = await API.get('/api/models');
const { success, data } = res.data;
const {success, data} = res.data;
if (!success) {
return;
}
@@ -236,12 +236,25 @@ export function getChannelModels(type) {
}
export function copy(text, name = '') {
try {
navigator.clipboard.writeText(text);
} catch (error) {
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(text).then(() => {
showNotice(`复制${name}成功!`, true);
}, () => {
text = `复制${name}失败,请手动复制:<br /><br />${text}`;
enqueueSnackbar(<SnackbarHTMLContent htmlContent={text} />, getSnackbarOptions('COPY'));
return;
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}`;
enqueueSnackbar(<SnackbarHTMLContent htmlContent={text}/>, getSnackbarOptions('COPY'));
}
document.body.removeChild(textArea);
}
showSuccess(`复制${name}成功!`);
}