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
+48 -24
View File
@@ -26,9 +26,7 @@ import {
showSuccess,
loadChannelModels,
} from '../../helpers';
import {
ITEMS_PER_PAGE,
} from '../../constants';
import { ITEMS_PER_PAGE } from '../../constants';
import { useIsMobile } from '../common/useIsMobile';
import { useTableCompactMode } from '../common/useTableCompactMode';
@@ -100,6 +98,9 @@ export const useChannelsData = () => {
// Refs
const requestCounter = useRef(0);
const pendingBalanceUpdatesRef = useRef(new Set());
const lastBalanceUpdateAtRef = useRef(new Map());
const pendingChannelTestsRef = useRef(new Set());
const allSelectingRef = useRef(false);
const [formApi, setFormApi] = useState(null);
@@ -796,18 +797,32 @@ export const useChannelsData = () => {
};
const updateChannelBalance = async (record) => {
const res = await API.get(`/api/channel/update_balance/${record.id}/`);
const { success, message, balance } = res.data;
if (success) {
updateChannelProperty(record.id, (channel) => {
channel.balance = balance;
channel.balance_updated_time = Date.now() / 1000;
});
showInfo(
t('通道 ${name} 余额更新成功!').replace('${name}', record.name),
);
} else {
showError(message);
const requestKey = String(record.id);
if (pendingBalanceUpdatesRef.current.has(requestKey)) return;
const now = Date.now();
const lastUpdateAt = lastBalanceUpdateAtRef.current.get(requestKey);
// Keep fast responses from allowing another request within the same 200ms window.
if (lastUpdateAt !== undefined && now - lastUpdateAt < 200) return;
lastBalanceUpdateAtRef.current.set(requestKey, now);
pendingBalanceUpdatesRef.current.add(requestKey);
try {
const res = await API.get(`/api/channel/update_balance/${record.id}/`);
const { success, message, balance } = res.data;
if (success) {
updateChannelProperty(record.id, (channel) => {
channel.balance = balance;
channel.balance_updated_time = Date.now() / 1000;
});
showInfo(
t('通道 ${name} 余额更新成功!').replace('${name}', record.name),
);
} else {
showError(message);
}
} catch (error) {
showError(error.message || t('网络错误'));
} finally {
pendingBalanceUpdatesRef.current.delete(requestKey);
}
};
@@ -835,10 +850,13 @@ export const useChannelsData = () => {
return Promise.resolve();
}
// 添加到正在测试的模型集合
setTestingModels((prev) => new Set([...prev, model]));
// Ref locks take effect immediately, including repeated clicks before a render.
const requestKey = JSON.stringify([String(record.id), model, endpointType]);
if (pendingChannelTestsRef.current.has(requestKey)) return;
pendingChannelTestsRef.current.add(requestKey);
try {
setTestingModels((prev) => new Set([...prev, model]));
let url = `/api/channel/test/${record.id}?model=${model}`;
if (endpointType) {
url += `&endpoint_type=${endpointType}`;
@@ -903,6 +921,7 @@ export const useChannelsData = () => {
}));
showError(`${t('模型')} ${model}: ${error.message || t('测试失败')}`);
} finally {
pendingChannelTestsRef.current.delete(requestKey);
// 从正在测试的模型集合中移除
setTestingModels((prev) => {
const newSet = new Set(prev);
@@ -912,21 +931,25 @@ export const useChannelsData = () => {
}
};
// 批量测试单个渠道的所有模型,参考旧版实现
// 批量测试当前渠道已勾选的模型。
const batchTestModels = async () => {
if (isBatchTesting) return;
if (!currentTestChannel || !currentTestChannel.models) {
showError(t('渠道模型信息不完整'));
return;
}
const models = currentTestChannel.models
.split(',')
.filter((model) =>
model.toLowerCase().includes(modelSearchKeyword.toLowerCase()),
);
// Snapshot selections across pages; search only controls the visible list.
const models = [
...new Set(
currentTestChannel.models
.split(',')
.filter((model) => model && selectedModelKeys.includes(model)),
),
];
if (models.length === 0) {
showError(t('没有找到匹配的模型'));
showError(t('请先选择模型!'));
return;
}
@@ -1112,6 +1135,7 @@ export const useChannelsData = () => {
// Column states
visibleColumns,
setVisibleColumns,
showColumnSelector,
setShowColumnSelector,
COLUMN_KEYS,