mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-20 03:30:50 +08:00
Handle clipboard copy failures in auth files page
This commit is contained in:
@@ -170,6 +170,34 @@ const writeAuthFilesUiState = (state: AuthFilesUiState) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const copyToClipboard = async (text: string): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
|
||||||
|
await navigator.clipboard.writeText(text);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// fallback below
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const textarea = document.createElement('textarea');
|
||||||
|
textarea.value = text;
|
||||||
|
textarea.style.position = 'fixed';
|
||||||
|
textarea.style.opacity = '0';
|
||||||
|
textarea.style.left = '-9999px';
|
||||||
|
textarea.style.top = '0';
|
||||||
|
document.body.appendChild(textarea);
|
||||||
|
textarea.focus();
|
||||||
|
textarea.select();
|
||||||
|
const copied = document.execCommand('copy');
|
||||||
|
document.body.removeChild(textarea);
|
||||||
|
return copied;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
interface PrefixProxyEditorState {
|
interface PrefixProxyEditorState {
|
||||||
fileName: string;
|
fileName: string;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
@@ -1016,6 +1044,16 @@ export function AuthFilesPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const copyTextWithNotification = async (text: string) => {
|
||||||
|
const copied = await copyToClipboard(text);
|
||||||
|
showNotification(
|
||||||
|
copied
|
||||||
|
? t('notification.link_copied', { defaultValue: 'Copied to clipboard' })
|
||||||
|
: t('notification.copy_failed', { defaultValue: 'Copy failed' }),
|
||||||
|
copied ? 'success' : 'error'
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// 检查模型是否被 OAuth 排除
|
// 检查模型是否被 OAuth 排除
|
||||||
const isModelExcluded = (modelId: string, providerType: string): boolean => {
|
const isModelExcluded = (modelId: string, providerType: string): boolean => {
|
||||||
const providerKey = normalizeProviderKey(providerType);
|
const providerKey = normalizeProviderKey(providerType);
|
||||||
@@ -2050,9 +2088,7 @@ export function AuthFilesPage() {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (selectedFile) {
|
if (selectedFile) {
|
||||||
const text = JSON.stringify(selectedFile, null, 2);
|
const text = JSON.stringify(selectedFile, null, 2);
|
||||||
navigator.clipboard.writeText(text).then(() => {
|
void copyTextWithNotification(text);
|
||||||
showNotification(t('notification.link_copied'), 'success');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -2108,11 +2144,7 @@ export function AuthFilesPage() {
|
|||||||
key={model.id}
|
key={model.id}
|
||||||
className={`${styles.modelItem} ${isExcluded ? styles.modelItemExcluded : ''}`}
|
className={`${styles.modelItem} ${isExcluded ? styles.modelItemExcluded : ''}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigator.clipboard.writeText(model.id);
|
void copyTextWithNotification(model.id);
|
||||||
showNotification(
|
|
||||||
t('notification.link_copied', { defaultValue: '已复制到剪贴板' }),
|
|
||||||
'success'
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
title={
|
title={
|
||||||
isExcluded
|
isExcluded
|
||||||
|
|||||||
Reference in New Issue
Block a user