diff --git a/src/components/table/task-logs/TaskLogsTable.jsx b/src/components/table/task-logs/TaskLogsTable.jsx
index 084feb8d..44af3e71 100644
--- a/src/components/table/task-logs/TaskLogsTable.jsx
+++ b/src/components/table/task-logs/TaskLogsTable.jsx
@@ -42,7 +42,6 @@ const TaskLogsTable = (taskLogsData) => {
openContentModal,
openVideoModal,
isAdminUser,
- isRootUser,
t,
COLUMN_KEYS,
usageRecordMode = false,
@@ -58,7 +57,6 @@ const TaskLogsTable = (taskLogsData) => {
openVideoModal,
isAdminUser,
usageRecordMode,
- isRootUser,
});
}, [
t,
@@ -68,7 +66,6 @@ const TaskLogsTable = (taskLogsData) => {
openVideoModal,
isAdminUser,
usageRecordMode,
- isRootUser,
]);
// Filter columns based on visibility settings
diff --git a/src/components/table/task-logs/index.jsx b/src/components/table/task-logs/index.jsx
index 11a4819b..79c5ed50 100644
--- a/src/components/table/task-logs/index.jsx
+++ b/src/components/table/task-logs/index.jsx
@@ -34,19 +34,8 @@ import { useTaskLogsData } from '../../../hooks/task-logs/useTaskLogsData';
import { useIsMobile } from '../../../hooks/common/useIsMobile';
import { createCardProPagination } from '../../../helpers/utils';
-const TaskLogsPage = ({
- usageRecordMode = false,
- organizationMode = false,
- sharedStartTimestamp,
- sharedEndTimestamp,
- sharedFilterRevision = 0,
-}) => {
- const taskLogsData = useTaskLogsData({
- organizationMode,
- sharedStartTimestamp,
- sharedEndTimestamp,
- sharedFilterRevision,
- });
+const TaskLogsPage = ({ usageRecordMode = false }) => {
+ const taskLogsData = useTaskLogsData();
const isMobile = useIsMobile();
// 与 CardPro 一致:移动端默认收起筛选区,仅视图状态
const [showMobileFilters, setShowMobileFilters] = useState(false);
@@ -178,12 +167,7 @@ const TaskLogsPage = ({
statsArea={
}
- searchArea={
-
- }
+ searchArea={
}
paginationArea={createCardProPagination({
currentPage: taskLogsData.activePage,
pageSize: taskLogsData.pageSize,
diff --git a/src/components/table/task-logs/modals/ColumnSelectorModal.jsx b/src/components/table/task-logs/modals/ColumnSelectorModal.jsx
index 1c59c5da..b5123891 100644
--- a/src/components/table/task-logs/modals/ColumnSelectorModal.jsx
+++ b/src/components/table/task-logs/modals/ColumnSelectorModal.jsx
@@ -30,7 +30,6 @@ const ColumnSelectorModal = ({
initDefaultColumns,
COLUMN_KEYS,
isAdminUser,
- isRootUser,
copyText,
openContentModal,
t,
@@ -42,7 +41,6 @@ const ColumnSelectorModal = ({
copyText,
openContentModal,
isAdminUser,
- isRootUser,
});
// 计算"全选"状态时应忽略的 key:当前角色下不可见的管理员专属列
diff --git a/src/hooks/task-logs/useTaskLogsData.js b/src/hooks/task-logs/useTaskLogsData.js
index cfb371d6..30fbf971 100644
--- a/src/hooks/task-logs/useTaskLogsData.js
+++ b/src/hooks/task-logs/useTaskLogsData.js
@@ -24,7 +24,6 @@ import {
API,
copy,
isAdmin,
- isRoot,
showError,
showSuccess,
timestamp2string,
@@ -34,25 +33,7 @@ import { resolveColumnVisibility } from '../../helpers/columnVisibility';
import { ITEMS_PER_PAGE } from '../../constants';
import { useTableCompactMode } from '../common/useTableCompactMode';
-const DEFAULT_TASK_RANGE_DAYS = 7;
-
-const toUnixTimestamp = (value) => {
- if (typeof value === 'number' && Number.isFinite(value)) {
- return Math.floor(value);
- }
- if (value instanceof Date) {
- return Math.floor(value.getTime() / 1000);
- }
- const parsed = Date.parse(value);
- return Number.isFinite(parsed) ? Math.floor(parsed / 1000) : NaN;
-};
-
-export const useTaskLogsData = ({
- organizationMode = false,
- sharedStartTimestamp,
- sharedEndTimestamp,
- sharedFilterRevision = 0,
-} = {}) => {
+export const useTaskLogsData = () => {
const { t } = useTranslation();
// Define column keys for selection
@@ -63,6 +44,7 @@ export const useTaskLogsData = ({
FINISH_TIME: 'finish_time',
DURATION: 'duration',
CHANNEL: 'channel',
+ PLATFORM: 'platform',
TYPE: 'type',
MODEL: 'model',
TASK_ID: 'task_id',
@@ -80,15 +62,11 @@ export const useTaskLogsData = ({
const [pageSize, setPageSize] = useState(ITEMS_PER_PAGE);
// User and admin
- const isAdminUser = !organizationMode && isAdmin();
- // 任务 ID 详情包含完整任务记录,仅系统超级管理员可查看;企业用户始终不可打开
- const isRootUser = !organizationMode && isRoot();
+ const isAdminUser = isAdmin();
// Role-specific storage key to prevent different roles from overwriting each other
- const STORAGE_KEY = organizationMode
- ? 'task-logs-table-columns-organization'
- : isAdminUser
- ? 'task-logs-table-columns-admin'
- : 'task-logs-table-columns-user';
+ const STORAGE_KEY = isAdminUser
+ ? 'task-logs-table-columns-admin'
+ : 'task-logs-table-columns-user';
// Modal state
const [isModalOpen, setIsModalOpen] = useState(false);
@@ -104,20 +82,15 @@ export const useTaskLogsData = ({
// Form state
const [formApi, setFormApi] = useState(null);
- const usesSharedDateRange =
- organizationMode &&
- Number.isFinite(Number(sharedStartTimestamp)) &&
- Number.isFinite(Number(sharedEndTimestamp));
-
- // 每次调用都返回"此刻"的默认时间范围,默认最近 7 天,避免任务页首屏
- // 只查当天而遗漏历史任务;返回 Date 对象以便日期控件正确显示。
+ // 每次调用都返回"此刻"的默认时间范围,避免长时间驻留页面后
+ // 点击"重置"仍得到页面加载时的"今日"(跨日 bug)
const getFreshDateRange = () => {
const now = new Date();
- now.setSeconds(0, 0);
- const start = new Date(
- now.getTime() - DEFAULT_TASK_RANGE_DAYS * 24 * 60 * 60 * 1000,
- );
- return [start, now];
+ const zeroNow = new Date(now.getFullYear(), now.getMonth(), now.getDate());
+ return [
+ timestamp2string(zeroNow.getTime() / 1000),
+ timestamp2string(now.getTime() / 1000 + 3600),
+ ];
};
const getFreshInitValues = () => ({
@@ -180,6 +153,7 @@ export const useTaskLogsData = ({
[COLUMN_KEYS.FINISH_TIME]: true,
[COLUMN_KEYS.DURATION]: true,
[COLUMN_KEYS.CHANNEL]: isAdminUser,
+ [COLUMN_KEYS.PLATFORM]: true,
[COLUMN_KEYS.TYPE]: true,
[COLUMN_KEYS.MODEL]: true,
[COLUMN_KEYS.TASK_ID]: true,
@@ -232,17 +206,12 @@ export const useTaskLogsData = ({
// 否则 URL 带的 ?task_id=xxx 在第一次 loadLogs 时会被当成空字符串,导致初始列表不过滤
const formValues = formApi ? formApi.getValues() : formInitValues;
- // 企业页复用上方已经提交的时间范围;个人/平台任务页使用自己的日期控件。
+ // 处理时间范围:每次调用时取"此刻"的默认值,避免闭包陈旧
const [freshStart, freshEnd] = getFreshDateRange();
- let start_timestamp = usesSharedDateRange
- ? Number(sharedStartTimestamp)
- : freshStart;
- let end_timestamp = usesSharedDateRange
- ? Number(sharedEndTimestamp)
- : freshEnd;
+ let start_timestamp = freshStart;
+ let end_timestamp = freshEnd;
if (
- !usesSharedDateRange &&
formValues.dateRange &&
Array.isArray(formValues.dateRange) &&
formValues.dateRange.length === 2
@@ -326,8 +295,8 @@ export const useTaskLogsData = ({
start_timestamp,
end_timestamp,
} = getFormValues();
- let localStartTimestamp = toUnixTimestamp(start_timestamp);
- let localEndTimestamp = toUnixTimestamp(end_timestamp);
+ let localStartTimestamp = parseInt(Date.parse(start_timestamp) / 1000);
+ let localEndTimestamp = parseInt(Date.parse(end_timestamp) / 1000);
// 时间范围校验:起始晚于结束视为非法,避免白发一轮请求并给出提示
if (
Number.isFinite(localStartTimestamp) &&
@@ -355,11 +324,9 @@ export const useTaskLogsData = ({
// 与使用日志对齐:管理员可按 user_id 过滤任务日志
if (user_id) params.set('user_id', user_id);
}
- const url = organizationMode
- ? `/api/org/tasks?${params.toString()}`
- : isAdminUser
- ? `/api/task/?${params.toString()}`
- : `/api/task/self?${params.toString()}`;
+ const url = isAdminUser
+ ? `/api/task/?${params.toString()}`
+ : `/api/task/self?${params.toString()}`;
try {
const res = await API.get(url);
// 过时响应直接丢弃:reqId 小于最新值说明更新的请求已经发出
@@ -444,12 +411,7 @@ export const useTaskLogsData = ({
parseInt(localStorage.getItem('task-page-size')) || ITEMS_PER_PAGE;
setPageSize(localPageSize);
loadLogs(1, localPageSize).then();
- }, [
- organizationMode,
- sharedStartTimestamp,
- sharedEndTimestamp,
- sharedFilterRevision,
- ]);
+ }, []);
// 存在进行中的任务时,自动轮询刷新(10s 间隔),无 pending 则停止,避免无谓请求
const loadLogsRef = useRef(loadLogs);
@@ -501,8 +463,6 @@ export const useTaskLogsData = ({
logCount,
pageSize,
isAdminUser,
- isRootUser,
- usesSharedDateRange,
// Modal state
isModalOpen,
diff --git a/src/pages/Organization/OrgLogs.jsx b/src/pages/Organization/OrgLogs.jsx
index ab9ef418..d7c2a8fc 100644
--- a/src/pages/Organization/OrgLogs.jsx
+++ b/src/pages/Organization/OrgLogs.jsx
@@ -47,7 +47,6 @@ import {
import OrgPageHeader from './components/OrgPageHeader';
import { OrgFilterCard, OrgListCard } from './components/OrgListCard';
import OrgModal from './components/OrgModal';
-import TaskLogsTable from '../../components/table/task-logs';
import {
API,
showError,
@@ -234,7 +233,6 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
const [page, setPage] = useState(1);
const pageSize = 20;
const [activeTab, setActiveTab] = useState('logs');
- const [taskFilterRevision, setTaskFilterRevision] = useState(0);
const isAdmin =
orgRole === 'owner' || orgRole === 'admin' || orgRole === 'super_admin';
const canViewTeamUsage = isAdmin || isDeptManager;
@@ -346,7 +344,6 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
);
}
setPage(1);
- setTaskFilterRevision((revision) => revision + 1);
};
// 重置:回到默认状态(滚动最近 7 天、不限成员/模型)
@@ -367,7 +364,6 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
});
}
setPage(1);
- setTaskFilterRevision((revision) => revision + 1);
};
// 导出弹窗状态(导出方式 + 字段勾选从 localStorage 恢复)
@@ -782,157 +778,144 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
onChange={setActiveTab}
items={[
{ key: 'logs', label: t('明细日志') },
- { key: 'tasks', label: t('绘图与视频') },
...(canViewTeamUsage
? [{ key: 'ranking', label: t('成员排行') }]
: []),
]}
/>
- {activeTab === 'tasks' ? (
-
- ) : (
- <>
- {/* 筛选栏(原型 .ee-filter-card / .eex-filter-grid) */}
-
-
- }
- onClick={() => handleSearch(false)}
- loading={loading}
- >
- {t('搜索')}
-
- >
- }
- >
-
-
- {canViewTeamUsage ? (
-
- ) : (
- {t('仅本人')}
- )}
-
-
-
-
- {
- setDateRange(v);
- setIsDefaultRange(false);
- }}
- placeholder={[t('开始时间'), t('结束时间')]}
- style={{ width: '100%' }}
- />
-
-
-
-
- handleSearch(false)}
- />
-
-
-
-
-
- }
- onClick={() => setExportModalVisible(true)}
- >
- {t('导出')}
-
- }
- onClick={() => handleSearch(true)}
- loading={loading}
- >
- {t('刷新')}
-
- >
- }
- >
- {activeTab === 'ranking' && canViewTeamUsage ? (
-
-
-
-
-
- {t('暂无排行数据')}
-
-
- }
+ {/* 筛选栏(原型 .ee-filter-card / .eex-filter-grid) */}
+
+
+ }
+ onClick={() => handleSearch(false)}
+ loading={loading}
+ >
+ {t('搜索')}
+
+ >
+ }
+ >
+
+
+ {canViewTeamUsage ? (
+
) : (
- doPageFetch(p),
- showTotal: (n) => t('共 {{total}} 条', { total: n }),
- }}
- empty={
-
-
-
-
-
- {t('暂无消耗记录')}
-
-
- }
- />
+ {t('仅本人')}
)}
-
- >
- )}
+
+
+
+
+ {
+ setDateRange(v);
+ setIsDefaultRange(false);
+ }}
+ placeholder={[t('开始时间'), t('结束时间')]}
+ style={{ width: '100%' }}
+ />
+
+
+
+
+ handleSearch(false)}
+ />
+
+
+
+
+
+ }
+ onClick={() => setExportModalVisible(true)}
+ >
+ {t('导出')}
+
+ }
+ onClick={() => handleSearch(true)}
+ loading={loading}
+ >
+ {t('刷新')}
+
+ >
+ }
+ >
+ {activeTab === 'ranking' && canViewTeamUsage ? (
+
+
+
+
+
+ {t('暂无排行数据')}
+
+
+ }
+ />
+ ) : (
+ doPageFetch(p),
+ showTotal: (n) => t('共 {{total}} 条', { total: n }),
+ }}
+ empty={
+
+
+
+
+
+ {t('暂无消耗记录')}
+
+
+ }
+ />
+ )}
+
{/* 导出弹窗:汇总 / 按用户 + 字段选择 */}
.
-
-For commercial licensing, please contact support@quantumnous.com
-*/
-
-import assert from 'node:assert/strict';
-import { readFileSync } from 'node:fs';
-import test from 'node:test';
-
-const hook = readFileSync(
- new URL('../src/hooks/task-logs/useTaskLogsData.js', import.meta.url),
- 'utf8',
-);
-const columns = readFileSync(
- new URL(
- '../src/components/table/task-logs/TaskLogsColumnDefs.jsx',
- import.meta.url,
- ),
- 'utf8',
-);
-const actions = readFileSync(
- new URL(
- '../src/components/table/task-logs/TaskLogsActions.jsx',
- import.meta.url,
- ),
- 'utf8',
-);
-const filters = readFileSync(
- new URL(
- '../src/components/table/task-logs/TaskLogsFilters.jsx',
- import.meta.url,
- ),
- 'utf8',
-);
-const orgLogs = readFileSync(
- new URL('../src/pages/Organization/OrgLogs.jsx', import.meta.url),
- 'utf8',
-);
-const usageRecord = readFileSync(
- new URL('../src/pages/UserCenter/UsageRecord.jsx', import.meta.url),
- 'utf8',
-);
-
-test('enterprise task records use the organization-scoped endpoint', () => {
- assert.match(hook, /organizationMode/);
- assert.match(hook, /`\/api\/org\/tasks\?\$\{params\.toString\(\)\}`/);
- assert.match(
- orgLogs,
- /sharedStartTimestamp=\{appliedFilters\.startTimestamp\}/,
- );
- assert.match(orgLogs, /sharedEndTimestamp=\{appliedFilters\.endTimestamp\}/);
- assert.match(orgLogs, /sharedFilterRevision=\{taskFilterRevision\}/);
- assert.match(hook, /DEFAULT_TASK_RANGE_DAYS = 7/);
- assert.match(hook, /const usesSharedDateRange/);
- assert.match(filters, /hideDateRange = false/);
- assert.match(filters, /!hideDateRange/);
-});
-
-test('platform is not exposed as a task-log presentation field', () => {
- assert.doesNotMatch(columns, /COLUMN_KEYS\.PLATFORM/);
- assert.doesNotMatch(columns, /title: t\('平台'\)/);
- assert.doesNotMatch(actions, /key: 'platform'/);
- assert.doesNotMatch(actions, /title: t\('平台'\)/);
-});
-
-test('task details can only be opened by the system root user', () => {
- assert.match(
- hook,
- /import \{[\s\S]*isRoot[\s\S]*\} from '\.\.\/\.\.\/helpers';/,
- );
- assert.match(hook, /const isRootUser = !organizationMode && isRoot\(\);/);
- assert.match(columns, /isRootUser = false/);
- assert.match(columns, /isRootUser\s*\?\s*\(\) => openContentModal/);
- assert.match(columns, /isRootUser\s*\?\s*'cursor-pointer/);
-});
-
-test('personal usage records reuse the same platform-free task view', () => {
- assert.match(usageRecord, //);
- assert.doesNotMatch(actions, /key: 'platform'/);
- assert.match(columns, /isRootUser\s*\?\s*\(\) => openContentModal/);
-});