mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-08 17:53:41 +08:00
fix: fix berry copy token (#2041)
* [bugfix]修复copy问题 * [update]两阶段编译代码 --------- Co-authored-by: zicorn <a24395@autel.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { enqueueSnackbar } from 'notistack';
|
import {enqueueSnackbar} from 'notistack';
|
||||||
import { snackbarConstants } from 'constants/SnackbarConstants';
|
import {snackbarConstants} from 'constants/SnackbarConstants';
|
||||||
import { API } from './api';
|
import {API} from './api';
|
||||||
|
|
||||||
export function getSystemName() {
|
export function getSystemName() {
|
||||||
let system_name = localStorage.getItem('system_name');
|
let system_name = localStorage.getItem('system_name');
|
||||||
@@ -13,15 +13,15 @@ export function isMobile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
export function SnackbarHTMLContent({ htmlContent }) {
|
export function SnackbarHTMLContent({htmlContent}) {
|
||||||
return <div dangerouslySetInnerHTML={{ __html: htmlContent }} />;
|
return <div dangerouslySetInnerHTML={{__html: htmlContent}}/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSnackbarOptions(variant) {
|
export function getSnackbarOptions(variant) {
|
||||||
let options = snackbarConstants.Common[variant];
|
let options = snackbarConstants.Common[variant];
|
||||||
if (isMobile()) {
|
if (isMobile()) {
|
||||||
// 合并 options 和 snackbarConstants.Mobile
|
// 合并 options 和 snackbarConstants.Mobile
|
||||||
options = { ...options, ...snackbarConstants.Mobile };
|
options = {...options, ...snackbarConstants.Mobile};
|
||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ export function showError(error) {
|
|||||||
|
|
||||||
export function showNotice(message, isHTML = false) {
|
export function showNotice(message, isHTML = false) {
|
||||||
if (isHTML) {
|
if (isHTML) {
|
||||||
enqueueSnackbar(<SnackbarHTMLContent htmlContent={message} />, getSnackbarOptions('NOTICE'));
|
enqueueSnackbar(<SnackbarHTMLContent htmlContent={message}/>, getSnackbarOptions('NOTICE'));
|
||||||
} else {
|
} else {
|
||||||
enqueueSnackbar(message, getSnackbarOptions('NOTICE'));
|
enqueueSnackbar(message, getSnackbarOptions('NOTICE'));
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ export function showInfo(message) {
|
|||||||
|
|
||||||
export async function getOAuthState() {
|
export async function getOAuthState() {
|
||||||
const res = await API.get('/api/oauth/state');
|
const res = await API.get('/api/oauth/state');
|
||||||
const { success, message, data } = res.data;
|
const {success, message, data} = res.data;
|
||||||
if (success) {
|
if (success) {
|
||||||
return data;
|
return data;
|
||||||
} else {
|
} 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}`;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,7 +192,7 @@ export function renderQuotaWithPrompt(quota, digits) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function downloadTextAsFile(text, filename) {
|
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 url = URL.createObjectURL(blob);
|
||||||
let a = document.createElement('a');
|
let a = document.createElement('a');
|
||||||
a.href = url;
|
a.href = url;
|
||||||
@@ -210,9 +209,10 @@ 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;
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -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}`;
|
text = `复制${name}失败,请手动复制:<br /><br />${text}`;
|
||||||
enqueueSnackbar(<SnackbarHTMLContent htmlContent={text} />, getSnackbarOptions('COPY'));
|
enqueueSnackbar(<SnackbarHTMLContent htmlContent={text}/>, getSnackbarOptions('COPY'));
|
||||||
return;
|
});
|
||||||
|
} 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}成功!`);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user