merge: 同步 origin/ui-optimization(d224d5b6),保留 weiyuan 功能与 Semi 迁移
- 冲突以 weiyuan 功能(小程序登录、i18n 文案)为准,并保留远端 lint 重构与依赖收敛 - 删除 weiyuan 已移除、远端仅做 lint 修正的 3 个图片相关文件 - 适配远端零警告 ESLint:Monitoring/Subscription 改用 useEffectEvent,EditChannelModal 注明 t 依赖 - effect-events 单测补充 react-i18next mock - 对合并后仍不符合 Prettier 的文件做纯格式化
This commit is contained in:
@@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useEffectEvent } from '../common/useEffectEvent';
|
||||
import { useState, useEffect, useRef, useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
@@ -127,7 +128,7 @@ export const useChannelsData = () => {
|
||||
};
|
||||
|
||||
// Initialize from localStorage
|
||||
useEffect(() => {
|
||||
const onMount = useEffectEvent(() => {
|
||||
const localIdSort = localStorage.getItem('id-sort') === 'true';
|
||||
const localPageSize =
|
||||
parseInt(localStorage.getItem('page-size')) || ITEMS_PER_PAGE;
|
||||
@@ -149,7 +150,8 @@ export const useChannelsData = () => {
|
||||
fetchGroups().then();
|
||||
fetchExcludedChannels().then();
|
||||
loadChannelModels().then();
|
||||
}, []);
|
||||
});
|
||||
useEffect(() => onMount(), [onMount]);
|
||||
|
||||
// Column visibility management
|
||||
const getDefaultColumnVisibility = () => {
|
||||
@@ -175,7 +177,7 @@ export const useChannelsData = () => {
|
||||
};
|
||||
|
||||
// Load saved column preferences
|
||||
useEffect(() => {
|
||||
const onMount2 = useEffectEvent(() => {
|
||||
const savedColumns = localStorage.getItem('channels-table-columns');
|
||||
if (savedColumns) {
|
||||
try {
|
||||
@@ -190,7 +192,8 @@ export const useChannelsData = () => {
|
||||
} else {
|
||||
initDefaultColumns();
|
||||
}
|
||||
}, []);
|
||||
});
|
||||
useEffect(() => onMount2(), [onMount2]);
|
||||
|
||||
// Save column preferences
|
||||
useEffect(() => {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
import { useCallback, useEffect, useLayoutEffect, useRef } from 'react';
|
||||
|
||||
const useCommitEffect =
|
||||
typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
||||
|
||||
// React 18 equivalent for effect events: read the latest committed values without
|
||||
// making callback identity or draft state restart requests, timers, or form resets.
|
||||
// Call from effects or their handlers; keep reactive triggers in useEffect's deps.
|
||||
export function useEffectEvent(callback) {
|
||||
const callbackRef = useRef(callback);
|
||||
useCommitEffect(() => {
|
||||
callbackRef.current = callback;
|
||||
});
|
||||
return useCallback((...args) => callbackRef.current(...args), []);
|
||||
}
|
||||
@@ -121,9 +121,10 @@ export const useSecureVerification = ({
|
||||
);
|
||||
|
||||
// 执行验证
|
||||
const apiCall = verificationState.apiCall;
|
||||
const executeVerification = useCallback(
|
||||
async (method, code = '') => {
|
||||
if (!verificationState.apiCall) {
|
||||
if (!apiCall) {
|
||||
showError(t('验证配置错误'));
|
||||
return;
|
||||
}
|
||||
@@ -135,7 +136,7 @@ export const useSecureVerification = ({
|
||||
await SecureVerificationService.verify(method, code);
|
||||
|
||||
// 验证成功,调用业务 API(此时中间件会通过)
|
||||
const result = await verificationState.apiCall();
|
||||
const result = await apiCall();
|
||||
|
||||
// 显示成功消息
|
||||
if (successMessage) {
|
||||
@@ -159,15 +160,7 @@ export const useSecureVerification = ({
|
||||
setVerificationState((prev) => ({ ...prev, loading: false }));
|
||||
}
|
||||
},
|
||||
[
|
||||
verificationState.apiCall,
|
||||
successMessage,
|
||||
onSuccess,
|
||||
onError,
|
||||
autoReset,
|
||||
resetState,
|
||||
t,
|
||||
],
|
||||
[apiCall, successMessage, onSuccess, onError, autoReset, resetState, t],
|
||||
);
|
||||
|
||||
// 设置验证码
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useEffectEvent } from './useEffectEvent';
|
||||
import { useState, useEffect, useMemo, useContext, useRef } from 'react';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
import { API } from '../../helpers';
|
||||
@@ -148,13 +149,14 @@ export const useSidebar = () => {
|
||||
);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const onScopeChange = useEffectEvent(() => {
|
||||
if (Object.keys(adminConfig).length > 0) {
|
||||
loadUserConfig();
|
||||
}
|
||||
}, [adminConfig]);
|
||||
});
|
||||
useEffect(() => onScopeChange(), [onScopeChange, adminConfig]);
|
||||
|
||||
useEffect(() => {
|
||||
const onScopeChange2 = useEffectEvent(() => {
|
||||
const handleRefresh = (event) => {
|
||||
if (event?.detail?.sourceId === instanceIdRef.current) {
|
||||
return;
|
||||
@@ -175,7 +177,8 @@ export const useSidebar = () => {
|
||||
handleRefresh,
|
||||
);
|
||||
};
|
||||
}, [adminConfig]);
|
||||
});
|
||||
useEffect(() => onScopeChange2(), [onScopeChange2, adminConfig]);
|
||||
|
||||
const finalConfig = useMemo(() => {
|
||||
const result = {};
|
||||
|
||||
@@ -92,7 +92,6 @@ export const useDashboardData = (userState, userDispatch, statusState) => {
|
||||
const [activeUptimeTab, setActiveUptimeTab] = useState('');
|
||||
|
||||
// ========== 常量 ==========
|
||||
const now = new Date();
|
||||
const isAdminUser = isAdmin();
|
||||
|
||||
// ========== Panel enable flags ==========
|
||||
@@ -116,7 +115,8 @@ export const useDashboardData = (userState, userDispatch, statusState) => {
|
||||
);
|
||||
|
||||
const performanceMetrics = useMemo(() => {
|
||||
const { start_timestamp, end_timestamp } = inputs;
|
||||
const start_timestamp = inputs.start_timestamp;
|
||||
const end_timestamp = inputs.end_timestamp;
|
||||
const timeDiff =
|
||||
(Date.parse(end_timestamp) - Date.parse(start_timestamp)) / 60000;
|
||||
const avgRPM = isNaN(times / timeDiff)
|
||||
@@ -189,7 +189,7 @@ export const useDashboardData = (userState, userDispatch, statusState) => {
|
||||
count: 0,
|
||||
model_name: t('无数据'),
|
||||
quota: 0,
|
||||
created_at: now.getTime() / 1000,
|
||||
created_at: Date.now() / 1000,
|
||||
});
|
||||
}
|
||||
data.sort((a, b) => a.created_at - b.created_at);
|
||||
@@ -201,7 +201,7 @@ export const useDashboardData = (userState, userDispatch, statusState) => {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [inputs, dataExportDefaultTime, isAdminUser, now, t]);
|
||||
}, [inputs, dataExportDefaultTime, isAdminUser, t]);
|
||||
|
||||
const loadTokenUsageData = useCallback(async () => {
|
||||
setTokenUsageLoading(true);
|
||||
|
||||
@@ -35,7 +35,6 @@ export const useDashboardStats = (
|
||||
consumeQuota,
|
||||
consumeTokens,
|
||||
times,
|
||||
trendData,
|
||||
performanceMetrics,
|
||||
navigate,
|
||||
t,
|
||||
@@ -138,7 +137,6 @@ export const useDashboardStats = (
|
||||
userState?.user?.used_quota,
|
||||
userState?.user?.request_count,
|
||||
times,
|
||||
trendData,
|
||||
performanceMetrics,
|
||||
tokenUsage,
|
||||
t,
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useEffectEvent } from '../common/useEffectEvent';
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Modal } from '@/components/ui';
|
||||
@@ -87,7 +88,7 @@ export const useMjLogsData = () => {
|
||||
const [showColumnSelector, setShowColumnSelector] = useState(false);
|
||||
|
||||
// Load saved column preferences from localStorage
|
||||
useEffect(() => {
|
||||
const onMount = useEffectEvent(() => {
|
||||
const savedColumns = localStorage.getItem(STORAGE_KEY);
|
||||
if (savedColumns) {
|
||||
try {
|
||||
@@ -108,7 +109,8 @@ export const useMjLogsData = () => {
|
||||
} else {
|
||||
initDefaultColumns();
|
||||
}
|
||||
}, []);
|
||||
});
|
||||
useEffect(() => onMount(), [onMount]);
|
||||
|
||||
// Check banner notification
|
||||
useEffect(() => {
|
||||
@@ -173,7 +175,7 @@ export const useMjLogsData = () => {
|
||||
if (Object.keys(visibleColumns).length > 0) {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(visibleColumns));
|
||||
}
|
||||
}, [visibleColumns]);
|
||||
}, [visibleColumns, STORAGE_KEY]);
|
||||
|
||||
// Get form values helper function
|
||||
const getFormValues = () => {
|
||||
@@ -283,12 +285,13 @@ export const useMjLogsData = () => {
|
||||
};
|
||||
|
||||
// Initialize data
|
||||
useEffect(() => {
|
||||
const onMount2 = useEffectEvent(() => {
|
||||
const localPageSize =
|
||||
parseInt(localStorage.getItem('mj-page-size')) || ITEMS_PER_PAGE;
|
||||
setPageSize(localPageSize);
|
||||
loadLogs(1, localPageSize).then();
|
||||
}, []);
|
||||
});
|
||||
useEffect(() => onMount2(), [onMount2]);
|
||||
|
||||
return {
|
||||
// Basic state
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useEffectEvent } from '../common/useEffectEvent';
|
||||
import { useState, useEffect, useContext, useRef, useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
@@ -351,9 +352,10 @@ export const useModelPricingData = () => {
|
||||
}, 300);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const onMount = useEffectEvent(() => {
|
||||
refresh().then();
|
||||
}, []);
|
||||
});
|
||||
useEffect(() => onMount(), [onMount]);
|
||||
|
||||
// 当筛选条件变化时重置到第一页
|
||||
useEffect(() => {
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useMemo } from 'react';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
// 工具函数:将 tags 字符串转为小写去重数组
|
||||
const normalizeTags = (tags = '') =>
|
||||
@@ -48,120 +48,93 @@ export const usePricingFilterCounts = ({
|
||||
* @param {Array<string>} ignore 需要忽略的过滤条件 key
|
||||
* @returns {boolean}
|
||||
*/
|
||||
const matchesFilters = (model, ignore = []) => {
|
||||
// 分组
|
||||
if (!ignore.includes('group') && filterGroup !== 'all') {
|
||||
if (!model.enable_groups || !model.enable_groups.includes(filterGroup))
|
||||
return false;
|
||||
}
|
||||
|
||||
// 计费类型
|
||||
if (!ignore.includes('quota') && filterQuotaType !== 'all') {
|
||||
if (model.quota_type !== filterQuotaType) return false;
|
||||
}
|
||||
|
||||
// 端点类型
|
||||
if (!ignore.includes('endpoint') && filterEndpointType !== 'all') {
|
||||
if (
|
||||
!model.supported_endpoint_types ||
|
||||
!model.supported_endpoint_types.includes(filterEndpointType)
|
||||
)
|
||||
return false;
|
||||
}
|
||||
|
||||
// 供应商
|
||||
if (!ignore.includes('vendor') && filterVendor !== 'all') {
|
||||
if (filterVendor === 'unknown') {
|
||||
if (model.vendor_name) return false;
|
||||
} else if (model.vendor_name !== filterVendor) {
|
||||
return false;
|
||||
const matchesFilters = useCallback(
|
||||
(model, ignore = []) => {
|
||||
// 分组
|
||||
if (!ignore.includes('group') && filterGroup !== 'all') {
|
||||
if (!model.enable_groups || !model.enable_groups.includes(filterGroup))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 标签
|
||||
if (!ignore.includes('tag') && filterTag !== 'all') {
|
||||
const tagsArr = normalizeTags(model.tags);
|
||||
if (!tagsArr.includes(filterTag.toLowerCase())) return false;
|
||||
}
|
||||
// 计费类型
|
||||
if (!ignore.includes('quota') && filterQuotaType !== 'all') {
|
||||
if (model.quota_type !== filterQuotaType) return false;
|
||||
}
|
||||
|
||||
// 搜索
|
||||
if (!ignore.includes('search') && searchValue) {
|
||||
const term = searchValue.toLowerCase();
|
||||
const tags = model.tags ? model.tags.toLowerCase() : '';
|
||||
if (
|
||||
!(
|
||||
// 端点类型
|
||||
if (!ignore.includes('endpoint') && filterEndpointType !== 'all') {
|
||||
if (
|
||||
!model.supported_endpoint_types ||
|
||||
!model.supported_endpoint_types.includes(filterEndpointType)
|
||||
)
|
||||
return false;
|
||||
}
|
||||
|
||||
// 供应商
|
||||
if (!ignore.includes('vendor') && filterVendor !== 'all') {
|
||||
if (filterVendor === 'unknown') {
|
||||
if (model.vendor_name) return false;
|
||||
} else if (model.vendor_name !== filterVendor) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 标签
|
||||
if (!ignore.includes('tag') && filterTag !== 'all') {
|
||||
const tagsArr = normalizeTags(model.tags);
|
||||
if (!tagsArr.includes(filterTag.toLowerCase())) return false;
|
||||
}
|
||||
|
||||
// 搜索
|
||||
if (!ignore.includes('search') && searchValue) {
|
||||
const term = searchValue.toLowerCase();
|
||||
const tags = model.tags ? model.tags.toLowerCase() : '';
|
||||
if (!(
|
||||
model.model_name.toLowerCase().includes(term) ||
|
||||
(model.description &&
|
||||
model.description.toLowerCase().includes(term)) ||
|
||||
tags.includes(term) ||
|
||||
(model.vendor_name && model.vendor_name.toLowerCase().includes(term))
|
||||
)
|
||||
)
|
||||
return false;
|
||||
}
|
||||
))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
return true;
|
||||
},
|
||||
[
|
||||
filterGroup,
|
||||
filterQuotaType,
|
||||
filterEndpointType,
|
||||
filterVendor,
|
||||
filterTag,
|
||||
searchValue,
|
||||
],
|
||||
);
|
||||
|
||||
// 生成不同视图所需的模型集合
|
||||
const quotaTypeModels = useMemo(
|
||||
() => allModels.filter((m) => matchesFilters(m, ['quota'])),
|
||||
[
|
||||
allModels,
|
||||
filterGroup,
|
||||
filterEndpointType,
|
||||
filterVendor,
|
||||
filterTag,
|
||||
searchValue,
|
||||
],
|
||||
[allModels, matchesFilters],
|
||||
);
|
||||
|
||||
const endpointTypeModels = useMemo(
|
||||
() => allModels.filter((m) => matchesFilters(m, ['endpoint'])),
|
||||
[
|
||||
allModels,
|
||||
filterGroup,
|
||||
filterQuotaType,
|
||||
filterVendor,
|
||||
filterTag,
|
||||
searchValue,
|
||||
],
|
||||
[allModels, matchesFilters],
|
||||
);
|
||||
|
||||
const vendorModels = useMemo(
|
||||
() => allModels.filter((m) => matchesFilters(m, ['vendor'])),
|
||||
[
|
||||
allModels,
|
||||
filterGroup,
|
||||
filterQuotaType,
|
||||
filterEndpointType,
|
||||
filterTag,
|
||||
searchValue,
|
||||
],
|
||||
[allModels, matchesFilters],
|
||||
);
|
||||
|
||||
const tagModels = useMemo(
|
||||
() => allModels.filter((m) => matchesFilters(m, ['tag'])),
|
||||
[
|
||||
allModels,
|
||||
filterGroup,
|
||||
filterQuotaType,
|
||||
filterEndpointType,
|
||||
filterVendor,
|
||||
searchValue,
|
||||
],
|
||||
[allModels, matchesFilters],
|
||||
);
|
||||
|
||||
const groupCountModels = useMemo(
|
||||
() => allModels.filter((m) => matchesFilters(m, ['group'])),
|
||||
[
|
||||
allModels,
|
||||
filterQuotaType,
|
||||
filterEndpointType,
|
||||
filterVendor,
|
||||
filterTag,
|
||||
searchValue,
|
||||
],
|
||||
[allModels, matchesFilters],
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useEffectEvent } from '../common/useEffectEvent';
|
||||
import { writeClipboardText } from '../../helpers/clipboard';
|
||||
import { useState, useEffect, useMemo, useRef } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -355,9 +356,10 @@ export const useModelsData = () => {
|
||||
};
|
||||
|
||||
// Reload models when activeVendorKey changes
|
||||
useEffect(() => {
|
||||
const onScopeChange = useEffectEvent(() => {
|
||||
loadModels(1, pageSize, activeVendorKey);
|
||||
}, [activeVendorKey]);
|
||||
});
|
||||
useEffect(() => onScopeChange(), [onScopeChange, activeVendorKey]);
|
||||
|
||||
// Handle page size change
|
||||
const handlePageSizeChange = async (size) => {
|
||||
|
||||
@@ -969,9 +969,10 @@ export const useApiRequest = (
|
||||
streamMessageUpdate,
|
||||
completeMessage,
|
||||
t,
|
||||
applyAutoCollapseLogic,
|
||||
onConversationIdReceived,
|
||||
onUserMessageIdReceived,
|
||||
sseSourceRef,
|
||||
setMessage,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1022,7 +1023,7 @@ export const useApiRequest = (
|
||||
setTimeout(() => {
|
||||
if (capturedUpdated) saveMessages(capturedUpdated);
|
||||
}, 0);
|
||||
}, [setMessage, applyAutoCollapseLogic, saveMessages]);
|
||||
}, [setMessage, applyAutoCollapseLogic, saveMessages, sseSourceRef]);
|
||||
|
||||
// 发送请求
|
||||
const sendRequest = useCallback(
|
||||
|
||||
@@ -343,8 +343,7 @@ export const useFileUpload = ({ maxSizeMB, maxCount = 10, onSuccess } = {}) => {
|
||||
// SVG 虽然 MIME 是 image/*,但本质是 XML 文本,多数大模型不接受 SVG 作为
|
||||
// input_image(OpenAI vision 会返 "invalid image"),所以当 file 处理走文件分支。
|
||||
fileType:
|
||||
file.type?.startsWith('image/') &&
|
||||
file.type !== 'image/svg+xml'
|
||||
file.type?.startsWith('image/') && file.type !== 'image/svg+xml'
|
||||
? 'image'
|
||||
: 'file',
|
||||
status: 'uploading',
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useEffectEvent } from '../common/useEffectEvent';
|
||||
import { useState, useCallback, useRef, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Toast } from '@/components/ui';
|
||||
@@ -238,22 +239,25 @@ export const usePlaygroundState = (options = {}) => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleConfigReset = useCallback((options = {}) => {
|
||||
const { resetMessages = false } = options;
|
||||
const handleConfigReset = useCallback(
|
||||
(options = {}) => {
|
||||
const { resetMessages = false } = options;
|
||||
|
||||
setInputs(DEFAULT_CONFIG.inputs);
|
||||
setParameterEnabled(DEFAULT_CONFIG.parameterEnabled);
|
||||
setShowDebugPanel(DEFAULT_CONFIG.showDebugPanel);
|
||||
setCustomRequestMode(DEFAULT_CONFIG.customRequestMode);
|
||||
setCustomRequestBody(DEFAULT_CONFIG.customRequestBody);
|
||||
setInputs(DEFAULT_CONFIG.inputs);
|
||||
setParameterEnabled(DEFAULT_CONFIG.parameterEnabled);
|
||||
setShowDebugPanel(DEFAULT_CONFIG.showDebugPanel);
|
||||
setCustomRequestMode(DEFAULT_CONFIG.customRequestMode);
|
||||
setCustomRequestBody(DEFAULT_CONFIG.customRequestBody);
|
||||
|
||||
if (resetMessages) {
|
||||
setMessage([]);
|
||||
setTimeout(() => {
|
||||
setMessage(getDefaultMessages(t));
|
||||
}, 0);
|
||||
}
|
||||
}, []);
|
||||
if (resetMessages) {
|
||||
setMessage([]);
|
||||
setTimeout(() => {
|
||||
setMessage(getDefaultMessages(t));
|
||||
}, 0);
|
||||
}
|
||||
},
|
||||
[t],
|
||||
);
|
||||
|
||||
const SESSIONS_PAGE_SIZE = 30;
|
||||
|
||||
@@ -552,7 +556,7 @@ export const usePlaygroundState = (options = {}) => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const onMount = useEffectEvent(() => {
|
||||
if (!Array.isArray(message) || message.length === 0) return;
|
||||
|
||||
const lastMsg = message[message.length - 1];
|
||||
@@ -578,7 +582,8 @@ export const usePlaygroundState = (options = {}) => {
|
||||
|
||||
setTimeout(() => saveMessagesImmediately(updatedMessages), 0);
|
||||
}
|
||||
}, []);
|
||||
});
|
||||
useEffect(() => onMount(), [onMount]);
|
||||
|
||||
return {
|
||||
inputs,
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useEffectEvent } from '../common/useEffectEvent';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { API, showError, showSuccess, copy } from '../../helpers';
|
||||
import { ITEMS_PER_PAGE } from '../../constants';
|
||||
@@ -295,13 +296,14 @@ export const useRedemptionsData = () => {
|
||||
};
|
||||
|
||||
// Initialize data loading
|
||||
useEffect(() => {
|
||||
const onScopeChange = useEffectEvent(() => {
|
||||
loadRedemptions(1, pageSize)
|
||||
.then()
|
||||
.catch((reason) => {
|
||||
showError(reason);
|
||||
});
|
||||
}, [pageSize]);
|
||||
});
|
||||
useEffect(() => onScopeChange(), [onScopeChange, pageSize]);
|
||||
|
||||
return {
|
||||
// Data state
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useEffectEvent } from '../common/useEffectEvent';
|
||||
import { useState, useEffect, useRef, useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Modal } from '@/components/ui';
|
||||
@@ -162,7 +163,7 @@ export const useTaskLogsData = ({
|
||||
const [compactMode, setCompactMode] = useTableCompactMode('taskLogs');
|
||||
|
||||
// Load saved column preferences from localStorage
|
||||
useEffect(() => {
|
||||
const onMount = useEffectEvent(() => {
|
||||
const savedColumns = localStorage.getItem(STORAGE_KEY);
|
||||
setVisibleColumns(
|
||||
resolveColumnVisibility(
|
||||
@@ -171,7 +172,8 @@ export const useTaskLogsData = ({
|
||||
isAdminUser ? [] : [COLUMN_KEYS.CHANNEL],
|
||||
),
|
||||
);
|
||||
}, []);
|
||||
});
|
||||
useEffect(() => onMount(), [onMount]);
|
||||
|
||||
// Get default column visibility based on user role
|
||||
const getDefaultColumnVisibility = () => {
|
||||
@@ -224,7 +226,7 @@ export const useTaskLogsData = ({
|
||||
if (Object.keys(visibleColumns).length > 0) {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(visibleColumns));
|
||||
}
|
||||
}, [visibleColumns]);
|
||||
}, [visibleColumns, STORAGE_KEY]);
|
||||
|
||||
// Get form values helper function
|
||||
const getFormValues = () => {
|
||||
@@ -439,17 +441,22 @@ export const useTaskLogsData = ({
|
||||
};
|
||||
|
||||
// Initialize data
|
||||
useEffect(() => {
|
||||
const onScopeChange2 = useEffectEvent(() => {
|
||||
const localPageSize =
|
||||
parseInt(localStorage.getItem('task-page-size')) || ITEMS_PER_PAGE;
|
||||
setPageSize(localPageSize);
|
||||
loadLogs(1, localPageSize).then();
|
||||
}, [
|
||||
organizationMode,
|
||||
sharedStartTimestamp,
|
||||
sharedEndTimestamp,
|
||||
sharedFilterRevision,
|
||||
]);
|
||||
});
|
||||
useEffect(
|
||||
() => onScopeChange2(),
|
||||
[
|
||||
onScopeChange2,
|
||||
organizationMode,
|
||||
sharedStartTimestamp,
|
||||
sharedEndTimestamp,
|
||||
sharedFilterRevision,
|
||||
],
|
||||
);
|
||||
|
||||
// 存在进行中的任务时,自动轮询刷新(10s 间隔),无 pending 则停止,避免无谓请求
|
||||
const loadLogsRef = useRef(loadLogs);
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useEffectEvent } from '../common/useEffectEvent';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Modal } from '@/components/ui';
|
||||
@@ -330,13 +331,14 @@ export const useTokensData = (openFluentNotification) => {
|
||||
};
|
||||
|
||||
// Initialize data
|
||||
useEffect(() => {
|
||||
const onScopeChange = useEffectEvent(() => {
|
||||
loadTokens(1)
|
||||
.then()
|
||||
.catch((reason) => {
|
||||
showError(reason);
|
||||
});
|
||||
}, [pageSize]);
|
||||
});
|
||||
useEffect(() => onScopeChange(), [onScopeChange, pageSize]);
|
||||
|
||||
return {
|
||||
// Basic state
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useEffectEvent } from '../common/useEffectEvent';
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Modal } from '@/components/ui';
|
||||
@@ -190,7 +191,7 @@ export const useLogsData = () => {
|
||||
};
|
||||
|
||||
// Load saved column preferences from localStorage
|
||||
useEffect(() => {
|
||||
const onMount = useEffectEvent(() => {
|
||||
const savedColumns = localStorage.getItem(STORAGE_KEY);
|
||||
setVisibleColumns(
|
||||
resolveColumnVisibility(
|
||||
@@ -201,7 +202,8 @@ export const useLogsData = () => {
|
||||
: [COLUMN_KEYS.CHANNEL, COLUMN_KEYS.USERNAME, COLUMN_KEYS.RETRY],
|
||||
),
|
||||
);
|
||||
}, []);
|
||||
});
|
||||
useEffect(() => onMount(), [onMount]);
|
||||
|
||||
// Get default column visibility based on user role
|
||||
const getDefaultColumnVisibility = () => {
|
||||
@@ -262,7 +264,7 @@ export const useLogsData = () => {
|
||||
if (Object.keys(visibleColumns).length > 0) {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(visibleColumns));
|
||||
}
|
||||
}, [visibleColumns]);
|
||||
}, [visibleColumns, STORAGE_KEY]);
|
||||
|
||||
// 获取表单值的辅助函数,确保所有值都是字符串
|
||||
const getFormValues = () => {
|
||||
@@ -659,7 +661,7 @@ export const useLogsData = () => {
|
||||
};
|
||||
|
||||
// Initialize data
|
||||
useEffect(() => {
|
||||
const onMount2 = useEffectEvent(() => {
|
||||
const localPageSize =
|
||||
parseInt(localStorage.getItem('page-size')) || ITEMS_PER_PAGE;
|
||||
setPageSize(localPageSize);
|
||||
@@ -668,14 +670,16 @@ export const useLogsData = () => {
|
||||
.catch((reason) => {
|
||||
showError(reason);
|
||||
});
|
||||
}, []);
|
||||
});
|
||||
useEffect(() => onMount2(), [onMount2]);
|
||||
|
||||
// Initialize statistics when formApi is available
|
||||
useEffect(() => {
|
||||
const onScopeChange3 = useEffectEvent(() => {
|
||||
if (formApi) {
|
||||
handleEyeClick();
|
||||
}
|
||||
}, [formApi]);
|
||||
});
|
||||
useEffect(() => onScopeChange3(), [onScopeChange3, formApi]);
|
||||
|
||||
// 订阅"任务完成"事件:任务转终态时后端会产生消费日志,这里跟随刷新
|
||||
// 用 ref 保存最新的加载函数,避免依赖数组里塞太多 state 导致频繁重订阅
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useEffectEvent } from '../common/useEffectEvent';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { API, showError, showSuccess } from '../../helpers';
|
||||
@@ -271,14 +272,15 @@ export const useUsersData = () => {
|
||||
};
|
||||
|
||||
// Initialize data on component mount
|
||||
useEffect(() => {
|
||||
const onMount = useEffectEvent(() => {
|
||||
loadUsers(0, pageSize)
|
||||
.then()
|
||||
.catch((reason) => {
|
||||
showError(reason);
|
||||
});
|
||||
fetchGroups().then();
|
||||
}, []);
|
||||
});
|
||||
useEffect(() => onMount(), [onMount]);
|
||||
|
||||
return {
|
||||
// Data state
|
||||
|
||||
@@ -102,6 +102,7 @@ async function createHarness() {
|
||||
'../common/useTableCompactMode': {
|
||||
useTableCompactMode: () => [false, () => {}],
|
||||
},
|
||||
'../common/useEffectEvent': { useEffectEvent: (callback) => callback },
|
||||
};
|
||||
const module = { exports: {} };
|
||||
runInNewContext(code, {
|
||||
|
||||
Reference in New Issue
Block a user