refactor(shared): 提取公共状态逻辑并修复用户列表分页
统一存储解析、通知已读状态、表格偏好和企业日志筛选参数。修复切换每页条数时沿用旧页码、丢失筛选条件和重复触发分页回调的问题。 同步调整项目检查脚本、格式配置和开发文档。
This commit is contained in:
+11
-28
@@ -19,6 +19,7 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
import { useState, useCallback, useEffect, useRef } from 'react';
|
||||
import { API } from '../../helpers/api';
|
||||
import { showError } from '../../helpers';
|
||||
import { buildOrgLogFilters } from '../../helpers/orgLogFilters.js';
|
||||
|
||||
// 获取企业X-Org-Id header
|
||||
const getOrgHeaders = (orgId) => ({
|
||||
@@ -239,19 +240,15 @@ export function useOrgMemberLogs(orgId) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const fetch = useCallback(
|
||||
async (
|
||||
page = 1,
|
||||
pageSize = 20,
|
||||
{ userId, startTimestamp, endTimestamp, modelName } = {},
|
||||
) => {
|
||||
async (page = 1, pageSize = 20, filters = {}) => {
|
||||
if (!orgId) return;
|
||||
setLoading(true);
|
||||
try {
|
||||
const params = { p: page, page_size: pageSize };
|
||||
if (userId) params.user_id = userId;
|
||||
if (startTimestamp) params.start_timestamp = startTimestamp;
|
||||
if (endTimestamp) params.end_timestamp = endTimestamp;
|
||||
if (modelName) params.model_name = modelName;
|
||||
const params = {
|
||||
p: page,
|
||||
page_size: pageSize,
|
||||
...buildOrgLogFilters(filters),
|
||||
};
|
||||
|
||||
const res = await API.get('/api/org/logs', {
|
||||
headers: getOrgHeaders(orgId),
|
||||
@@ -292,18 +289,11 @@ export function useOrgLogsStat(orgId) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const fetch = useCallback(
|
||||
async (
|
||||
{ userId, startTimestamp, endTimestamp, modelName } = {},
|
||||
noCache = false,
|
||||
) => {
|
||||
async (filters = {}, noCache = false) => {
|
||||
if (!orgId) return;
|
||||
setLoading(true);
|
||||
try {
|
||||
const params = {};
|
||||
if (userId) params.user_id = userId;
|
||||
if (startTimestamp) params.start_timestamp = startTimestamp;
|
||||
if (endTimestamp) params.end_timestamp = endTimestamp;
|
||||
if (modelName) params.model_name = modelName;
|
||||
const params = buildOrgLogFilters(filters);
|
||||
if (noCache) params.nocache = 1;
|
||||
|
||||
const res = await API.get('/api/org/logs/stat', {
|
||||
@@ -346,18 +336,11 @@ export function useOrgMemberRanking(orgId) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const fetch = useCallback(
|
||||
async (
|
||||
{ userId, startTimestamp, endTimestamp, modelName, limit } = {},
|
||||
noCache = false,
|
||||
) => {
|
||||
async ({ limit, ...filters } = {}, noCache = false) => {
|
||||
if (!orgId) return;
|
||||
setLoading(true);
|
||||
try {
|
||||
const params = {};
|
||||
if (userId) params.user_id = userId;
|
||||
if (startTimestamp) params.start_timestamp = startTimestamp;
|
||||
if (endTimestamp) params.end_timestamp = endTimestamp;
|
||||
if (modelName) params.model_name = modelName;
|
||||
const params = buildOrgLogFilters(filters);
|
||||
if (limit) params.limit = limit;
|
||||
if (noCache) params.nocache = 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user