feat: 自行开发设计 ui样式优化 超管端-控制台 相关的页面

This commit is contained in:
zhanjunhao
2026-11-09 21:45:37 +08:00
parent 6ad95e2baa
commit 5713d541b0
242 changed files with 9242 additions and 5043 deletions
+123
View File
@@ -0,0 +1,123 @@
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
// Keep clipboard access in one place so HTTP deployments can use the fallback.
export async function copyText(text) {
if (text === null || text === undefined) return false;
const value = String(text);
try {
if (globalThis.navigator?.clipboard?.writeText) {
await globalThis.navigator.clipboard.writeText(value);
return true;
}
} catch {
// Permission denial can still allow a copy initiated by a user gesture.
}
const doc = globalThis.document;
if (!doc?.body || typeof doc.execCommand !== 'function') return false;
const activeElement = doc.activeElement;
const selection = doc.getSelection?.();
const ranges = [];
for (let i = 0; i < (selection?.rangeCount || 0); i++) {
ranges.push(selection.getRangeAt(i).cloneRange());
}
const inputSelection =
typeof activeElement?.selectionStart === 'number'
? [
activeElement.selectionStart,
activeElement.selectionEnd,
activeElement.selectionDirection,
]
: null;
let textarea;
try {
textarea = doc.createElement('textarea');
textarea.value = value;
textarea.readOnly = true;
textarea.tabIndex = -1;
Object.assign(textarea.style, {
position: 'fixed',
top: '0',
left: '0',
width: '1px',
height: '1px',
opacity: '0',
fontSize: '16px',
pointerEvents: 'none',
});
// Modal focus traps must allow the temporary input to receive selection.
const container = activeElement?.closest?.('[role="dialog"]') || doc.body;
container.appendChild(textarea);
textarea.focus({ preventScroll: true });
textarea.select();
textarea.setSelectionRange(0, value.length);
return doc.execCommand('copy') === true;
} catch {
return false;
} finally {
textarea?.remove();
try {
activeElement?.focus?.({ preventScroll: true });
if (inputSelection) activeElement.setSelectionRange(...inputSelection);
if (selection && ranges.length) {
selection.removeAllRanges();
ranges.forEach((range) => selection.addRange(range));
}
} catch {
// The original field may have unmounted while Clipboard API was pending.
}
}
}
// Promise-based callers keep their existing success/error callbacks.
export async function writeClipboardText(text) {
if (!(await copyText(text))) throw new Error('Clipboard copy failed');
}
export async function writeClipboardImage(blob) {
const clipboard = globalThis.navigator?.clipboard;
const Item = globalThis.ClipboardItem;
if (!clipboard?.write || !Item)
throw new Error('Image clipboard unavailable');
let png = blob;
if (blob.type !== 'image/png') {
// Clipboard image support is PNG-only in common browsers; relabeling a JPEG
// blob as PNG causes write() to reject it, so convert the bytes as well.
const bitmap = await globalThis.createImageBitmap(blob);
try {
const canvas = document.createElement('canvas');
canvas.width = bitmap.width;
canvas.height = bitmap.height;
canvas.getContext('2d').drawImage(bitmap, 0, 0);
png = await new Promise((resolve, reject) => {
canvas.toBlob(
(result) =>
result
? resolve(result)
: reject(new Error('Image conversion failed')),
'image/png',
);
});
} finally {
bitmap.close();
}
}
await clipboard.write([new Item({ 'image/png': png })]);
}
+3
View File
@@ -28,6 +28,7 @@ import {
timestamp2string1,
copy,
showSuccess,
showError,
} from './utils';
import {
STORAGE_KEYS,
@@ -170,6 +171,8 @@ export const createSectionTitle = (Icon, text) => (
export const handleCopyUrl = async (url, t) => {
if (await copy(url)) {
showSuccess(t('复制成功'));
} else {
showError(t('复制失败,请手动复制'));
}
};
+1
View File
@@ -102,6 +102,7 @@ export function getLucideIcon(key, selected = false) {
case 'chat':
return <MessageSquare {...commonProps} color={iconColor} />;
case 'token':
case 'admin-token':
return <Key {...commonProps} color={iconColor} />;
case 'log':
return <BarChart3 {...commonProps} color={iconColor} />;
+14 -33
View File
@@ -102,35 +102,7 @@ export function getUserIdFromLocalStorage() {
return user.id;
}
export async function copy(text) {
try {
await navigator.clipboard.writeText(text);
return true;
} catch {
let textarea;
const activeElement = document.activeElement;
try {
// 构建 textarea 执行复制命令,保留多行文本格式
textarea = window.document.createElement('textarea');
textarea.value = text;
textarea.setAttribute('readonly', '');
textarea.style.position = 'fixed';
textarea.style.left = '-9999px';
textarea.style.top = '-9999px';
// Keep the selection inside a modal's focus trap when copying credentials.
const container =
activeElement?.closest('[role="dialog"]') || document.body;
container.appendChild(textarea);
textarea.select();
return window.document.execCommand('copy');
} catch {
return false;
} finally {
textarea?.remove();
activeElement?.focus({ preventScroll: true });
}
}
}
export { copyText as copy } from './clipboard';
// isMobile 函数已移除,请改用 useIsMobile Hook
@@ -218,7 +190,10 @@ export function showInfo(message) {
export function showNotice(message, isHTML = false) {
if (isHTML) {
Toast.info({ content: <HTMLToastContent htmlContent={message} />, duration: 0 });
Toast.info({
content: <HTMLToastContent htmlContent={message} />,
duration: 0,
});
} else {
Toast.info(message);
}
@@ -1091,11 +1066,16 @@ export const createCardProPagination = ({
isMobile = false,
pageSizeOpts = [10, 20, 50, 100],
showSizeChanger = true,
showRange = true,
preventPageChangeOnPageSizeChange = false,
t = (key) => key,
}) => {
if (!total || total <= 0) return null;
const unified =
typeof window !== 'undefined' &&
/^\/(console|org)(\/|$)/.test(window.location?.pathname || '');
const start = (currentPage - 1) * pageSize + 1;
const end = Math.min(currentPage * pageSize, total);
const totalText = `${t('显示第')} ${start} ${t('条 - 第')} ${end} ${t('条,共')} ${total} ${t('条')}`;
@@ -1103,7 +1083,7 @@ export const createCardProPagination = ({
return (
<>
{/* 桌面端左侧总数信息 */}
{!isMobile && (
{!unified && !isMobile && showRange && (
<span
className='text-sm select-none'
style={{ color: 'var(--ui-color-text-2)' }}
@@ -1114,6 +1094,7 @@ export const createCardProPagination = ({
{/* 右侧分页控件 */}
<Pagination
className={!isMobile && (unified || !showRange) ? 'ml-auto' : undefined}
currentPage={currentPage}
pageSize={pageSize}
total={total}
@@ -1122,9 +1103,9 @@ export const createCardProPagination = ({
onPageSizeChange={onPageSizeChange}
onPageChange={onPageChange}
preventPageChangeOnPageSizeChange={preventPageChangeOnPageSizeChange}
size={isMobile ? 'small' : 'default'}
size={unified || isMobile ? 'small' : 'default'}
showQuickJumper={isMobile}
showTotal
showTotal={unified ? (total) => t('共 {{total}} 条', { total }) : true}
/>
</>
);