Revert "feat(org): expose enterprise drawing and task logs"
This reverts commit 72bec4f8f1.
This commit is contained in:
@@ -55,6 +55,7 @@ export const exportTaskLogsPageCsv = (logs, isAdminUser, t) => {
|
|||||||
{ key: 'channel_name', title: t('渠道名称') },
|
{ key: 'channel_name', title: t('渠道名称') },
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
|
{ key: 'platform', title: t('平台') },
|
||||||
{ key: 'action', title: t('类型') },
|
{ key: 'action', title: t('类型') },
|
||||||
{
|
{
|
||||||
key: 'model',
|
key: 'model',
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import {
|
|||||||
Video,
|
Video,
|
||||||
Sparkles,
|
Sparkles,
|
||||||
Timer,
|
Timer,
|
||||||
|
Image as ImageIcon,
|
||||||
ImagePlus,
|
ImagePlus,
|
||||||
Coins,
|
Coins,
|
||||||
Cpu,
|
Cpu,
|
||||||
@@ -47,6 +48,7 @@ import {
|
|||||||
IMAGE_ACTION_GENERATE,
|
IMAGE_ACTION_GENERATE,
|
||||||
IMAGE_ACTION_EDIT,
|
IMAGE_ACTION_EDIT,
|
||||||
} from '../../../constants/common.constant';
|
} from '../../../constants/common.constant';
|
||||||
|
import { CHANNEL_OPTIONS } from '../../../constants/channel.constants';
|
||||||
import { renderQuota } from '../../../helpers';
|
import { renderQuota } from '../../../helpers';
|
||||||
|
|
||||||
// 仅保留与下方 COLOR_CONFIG 一一对应的色值,避免 amber/lime/violet/teal/indigo/light-blue
|
// 仅保留与下方 COLOR_CONFIG 一一对应的色值,避免 amber/lime/violet/teal/indigo/light-blue
|
||||||
@@ -229,6 +231,34 @@ const renderType = (type, t) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderPlatform = (platform, t) => {
|
||||||
|
let option = CHANNEL_OPTIONS.find(
|
||||||
|
(opt) => String(opt.value) === String(platform),
|
||||||
|
);
|
||||||
|
if (option) {
|
||||||
|
return (
|
||||||
|
<CustomTag
|
||||||
|
icon={Video}
|
||||||
|
label={option.label}
|
||||||
|
colorKey={option.color || 'cyan'}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (platform === 'suno') {
|
||||||
|
return <CustomTag icon={Music} label='Suno' colorKey='green' />;
|
||||||
|
}
|
||||||
|
if (platform === 'image') {
|
||||||
|
return <CustomTag icon={ImageIcon} label={t('图片')} colorKey='cyan' />;
|
||||||
|
}
|
||||||
|
if (platform === 'video') {
|
||||||
|
return <CustomTag icon={Video} label={t('视频')} colorKey='blue' />;
|
||||||
|
}
|
||||||
|
if (platform === 'mj') {
|
||||||
|
return <CustomTag icon={Sparkles} label='Midjourney' colorKey='purple' />;
|
||||||
|
}
|
||||||
|
return <CustomTag icon={HelpCircle} label={t('未知')} colorKey='grey' />;
|
||||||
|
};
|
||||||
|
|
||||||
const renderStatus = (type, t) => {
|
const renderStatus = (type, t) => {
|
||||||
const statusConfig = {
|
const statusConfig = {
|
||||||
SUCCESS: { icon: CheckCircle, label: t('成功'), color: 'green' },
|
SUCCESS: { icon: CheckCircle, label: t('成功'), color: 'green' },
|
||||||
@@ -326,6 +356,12 @@ const applyTaskRecordPresentation = (columns, { COLUMN_KEYS }) =>
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
case COLUMN_KEYS.PLATFORM:
|
||||||
|
return {
|
||||||
|
...column,
|
||||||
|
render: (text, record, index) =>
|
||||||
|
unwrap(text, record, index)?.props?.label ?? '-',
|
||||||
|
};
|
||||||
case COLUMN_KEYS.TYPE:
|
case COLUMN_KEYS.TYPE:
|
||||||
return {
|
return {
|
||||||
...column,
|
...column,
|
||||||
@@ -393,7 +429,6 @@ export const getTaskLogsColumns = ({
|
|||||||
copyText,
|
copyText,
|
||||||
openContentModal,
|
openContentModal,
|
||||||
isAdminUser,
|
isAdminUser,
|
||||||
isRootUser = false,
|
|
||||||
openVideoModal,
|
openVideoModal,
|
||||||
usageRecordMode = false,
|
usageRecordMode = false,
|
||||||
}) => {
|
}) => {
|
||||||
@@ -447,6 +482,14 @@ export const getTaskLogsColumns = ({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: COLUMN_KEYS.PLATFORM,
|
||||||
|
title: t('平台'),
|
||||||
|
dataIndex: 'platform',
|
||||||
|
render: (text, record, index) => {
|
||||||
|
return <div>{renderPlatform(text, t)}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: COLUMN_KEYS.TYPE,
|
key: COLUMN_KEYS.TYPE,
|
||||||
title: t('类型'),
|
title: t('类型'),
|
||||||
@@ -489,16 +532,10 @@ export const getTaskLogsColumns = ({
|
|||||||
return (
|
return (
|
||||||
<Typography.Text
|
<Typography.Text
|
||||||
ellipsis={{ showTooltip: true }}
|
ellipsis={{ showTooltip: true }}
|
||||||
onClick={
|
onClick={() => {
|
||||||
isRootUser
|
openContentModal(JSON.stringify(record, null, 2));
|
||||||
? () => openContentModal(JSON.stringify(record, null, 2))
|
}}
|
||||||
: undefined
|
className='cursor-pointer hover:text-blue-500 dark:hover:text-blue-400 transition-colors font-mono text-xs'
|
||||||
}
|
|
||||||
className={
|
|
||||||
isRootUser
|
|
||||||
? 'cursor-pointer hover:text-blue-500 dark:hover:text-blue-400 transition-colors font-mono text-xs'
|
|
||||||
: 'font-mono text-xs'
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{text}
|
{text}
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ const TaskLogsFilters = ({
|
|||||||
isAdminUser,
|
isAdminUser,
|
||||||
getFreshInitValues,
|
getFreshInitValues,
|
||||||
usageRecordMode = false,
|
usageRecordMode = false,
|
||||||
hideDateRange = false,
|
|
||||||
t,
|
t,
|
||||||
}) => {
|
}) => {
|
||||||
const SearchIcon = Search;
|
const SearchIcon = Search;
|
||||||
@@ -269,27 +268,25 @@ const TaskLogsFilters = ({
|
|||||||
|
|
||||||
{/* 搜索字段网格 */}
|
{/* 搜索字段网格 */}
|
||||||
<div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3'>
|
<div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3'>
|
||||||
{/* 时间选择器:企业页复用上方消费记录的已提交时间范围 */}
|
{/* 时间选择器 */}
|
||||||
{!hideDateRange && (
|
<div className='col-span-1 lg:col-span-2'>
|
||||||
<div className='col-span-1 lg:col-span-2'>
|
<div className='relative group'>
|
||||||
<div className='relative group'>
|
<div className='absolute -inset-0.5 bg-gradient-to-r from-cyan-500/20 to-blue-500/20 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity duration-300 blur-sm' />
|
||||||
<div className='absolute -inset-0.5 bg-gradient-to-r from-cyan-500/20 to-blue-500/20 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity duration-300 blur-sm' />
|
<div className='relative'>
|
||||||
<div className='relative'>
|
<Form.DatePicker
|
||||||
<Form.DatePicker
|
field='dateRange'
|
||||||
field='dateRange'
|
className='w-full'
|
||||||
className='w-full'
|
type='dateTimeRange'
|
||||||
type='dateTimeRange'
|
placeholder={[t('开始时间'), t('结束时间')]}
|
||||||
placeholder={[t('开始时间'), t('结束时间')]}
|
showClear
|
||||||
showClear
|
pure
|
||||||
pure
|
size='small'
|
||||||
size='small'
|
prefix={<InputPrefix icon={Calendar} />}
|
||||||
prefix={<InputPrefix icon={Calendar} />}
|
presets={datePresets}
|
||||||
presets={datePresets}
|
/>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
|
|
||||||
{/* 任务 ID */}
|
{/* 任务 ID */}
|
||||||
<div className='relative group'>
|
<div className='relative group'>
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ const TaskLogsTable = (taskLogsData) => {
|
|||||||
openContentModal,
|
openContentModal,
|
||||||
openVideoModal,
|
openVideoModal,
|
||||||
isAdminUser,
|
isAdminUser,
|
||||||
isRootUser,
|
|
||||||
t,
|
t,
|
||||||
COLUMN_KEYS,
|
COLUMN_KEYS,
|
||||||
usageRecordMode = false,
|
usageRecordMode = false,
|
||||||
@@ -58,7 +57,6 @@ const TaskLogsTable = (taskLogsData) => {
|
|||||||
openVideoModal,
|
openVideoModal,
|
||||||
isAdminUser,
|
isAdminUser,
|
||||||
usageRecordMode,
|
usageRecordMode,
|
||||||
isRootUser,
|
|
||||||
});
|
});
|
||||||
}, [
|
}, [
|
||||||
t,
|
t,
|
||||||
@@ -68,7 +66,6 @@ const TaskLogsTable = (taskLogsData) => {
|
|||||||
openVideoModal,
|
openVideoModal,
|
||||||
isAdminUser,
|
isAdminUser,
|
||||||
usageRecordMode,
|
usageRecordMode,
|
||||||
isRootUser,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Filter columns based on visibility settings
|
// Filter columns based on visibility settings
|
||||||
|
|||||||
@@ -34,19 +34,8 @@ import { useTaskLogsData } from '../../../hooks/task-logs/useTaskLogsData';
|
|||||||
import { useIsMobile } from '../../../hooks/common/useIsMobile';
|
import { useIsMobile } from '../../../hooks/common/useIsMobile';
|
||||||
import { createCardProPagination } from '../../../helpers/utils';
|
import { createCardProPagination } from '../../../helpers/utils';
|
||||||
|
|
||||||
const TaskLogsPage = ({
|
const TaskLogsPage = ({ usageRecordMode = false }) => {
|
||||||
usageRecordMode = false,
|
const taskLogsData = useTaskLogsData();
|
||||||
organizationMode = false,
|
|
||||||
sharedStartTimestamp,
|
|
||||||
sharedEndTimestamp,
|
|
||||||
sharedFilterRevision = 0,
|
|
||||||
}) => {
|
|
||||||
const taskLogsData = useTaskLogsData({
|
|
||||||
organizationMode,
|
|
||||||
sharedStartTimestamp,
|
|
||||||
sharedEndTimestamp,
|
|
||||||
sharedFilterRevision,
|
|
||||||
});
|
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
// 与 CardPro 一致:移动端默认收起筛选区,仅视图状态
|
// 与 CardPro 一致:移动端默认收起筛选区,仅视图状态
|
||||||
const [showMobileFilters, setShowMobileFilters] = useState(false);
|
const [showMobileFilters, setShowMobileFilters] = useState(false);
|
||||||
@@ -178,12 +167,7 @@ const TaskLogsPage = ({
|
|||||||
statsArea={
|
statsArea={
|
||||||
<TaskLogsActions {...taskLogsData} logs={taskLogsData.logs} />
|
<TaskLogsActions {...taskLogsData} logs={taskLogsData.logs} />
|
||||||
}
|
}
|
||||||
searchArea={
|
searchArea={<TaskLogsFilters {...taskLogsData} />}
|
||||||
<TaskLogsFilters
|
|
||||||
{...taskLogsData}
|
|
||||||
hideDateRange={taskLogsData.usesSharedDateRange}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
paginationArea={createCardProPagination({
|
paginationArea={createCardProPagination({
|
||||||
currentPage: taskLogsData.activePage,
|
currentPage: taskLogsData.activePage,
|
||||||
pageSize: taskLogsData.pageSize,
|
pageSize: taskLogsData.pageSize,
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ const ColumnSelectorModal = ({
|
|||||||
initDefaultColumns,
|
initDefaultColumns,
|
||||||
COLUMN_KEYS,
|
COLUMN_KEYS,
|
||||||
isAdminUser,
|
isAdminUser,
|
||||||
isRootUser,
|
|
||||||
copyText,
|
copyText,
|
||||||
openContentModal,
|
openContentModal,
|
||||||
t,
|
t,
|
||||||
@@ -42,7 +41,6 @@ const ColumnSelectorModal = ({
|
|||||||
copyText,
|
copyText,
|
||||||
openContentModal,
|
openContentModal,
|
||||||
isAdminUser,
|
isAdminUser,
|
||||||
isRootUser,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 计算"全选"状态时应忽略的 key:当前角色下不可见的管理员专属列
|
// 计算"全选"状态时应忽略的 key:当前角色下不可见的管理员专属列
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import {
|
|||||||
API,
|
API,
|
||||||
copy,
|
copy,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
isRoot,
|
|
||||||
showError,
|
showError,
|
||||||
showSuccess,
|
showSuccess,
|
||||||
timestamp2string,
|
timestamp2string,
|
||||||
@@ -34,25 +33,7 @@ import { resolveColumnVisibility } from '../../helpers/columnVisibility';
|
|||||||
import { ITEMS_PER_PAGE } from '../../constants';
|
import { ITEMS_PER_PAGE } from '../../constants';
|
||||||
import { useTableCompactMode } from '../common/useTableCompactMode';
|
import { useTableCompactMode } from '../common/useTableCompactMode';
|
||||||
|
|
||||||
const DEFAULT_TASK_RANGE_DAYS = 7;
|
export const useTaskLogsData = () => {
|
||||||
|
|
||||||
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,
|
|
||||||
} = {}) => {
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
// Define column keys for selection
|
// Define column keys for selection
|
||||||
@@ -63,6 +44,7 @@ export const useTaskLogsData = ({
|
|||||||
FINISH_TIME: 'finish_time',
|
FINISH_TIME: 'finish_time',
|
||||||
DURATION: 'duration',
|
DURATION: 'duration',
|
||||||
CHANNEL: 'channel',
|
CHANNEL: 'channel',
|
||||||
|
PLATFORM: 'platform',
|
||||||
TYPE: 'type',
|
TYPE: 'type',
|
||||||
MODEL: 'model',
|
MODEL: 'model',
|
||||||
TASK_ID: 'task_id',
|
TASK_ID: 'task_id',
|
||||||
@@ -80,15 +62,11 @@ export const useTaskLogsData = ({
|
|||||||
const [pageSize, setPageSize] = useState(ITEMS_PER_PAGE);
|
const [pageSize, setPageSize] = useState(ITEMS_PER_PAGE);
|
||||||
|
|
||||||
// User and admin
|
// User and admin
|
||||||
const isAdminUser = !organizationMode && isAdmin();
|
const isAdminUser = isAdmin();
|
||||||
// 任务 ID 详情包含完整任务记录,仅系统超级管理员可查看;企业用户始终不可打开
|
|
||||||
const isRootUser = !organizationMode && isRoot();
|
|
||||||
// Role-specific storage key to prevent different roles from overwriting each other
|
// Role-specific storage key to prevent different roles from overwriting each other
|
||||||
const STORAGE_KEY = organizationMode
|
const STORAGE_KEY = isAdminUser
|
||||||
? 'task-logs-table-columns-organization'
|
? 'task-logs-table-columns-admin'
|
||||||
: isAdminUser
|
: 'task-logs-table-columns-user';
|
||||||
? 'task-logs-table-columns-admin'
|
|
||||||
: 'task-logs-table-columns-user';
|
|
||||||
|
|
||||||
// Modal state
|
// Modal state
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
@@ -104,20 +82,15 @@ export const useTaskLogsData = ({
|
|||||||
// Form state
|
// Form state
|
||||||
const [formApi, setFormApi] = useState(null);
|
const [formApi, setFormApi] = useState(null);
|
||||||
|
|
||||||
const usesSharedDateRange =
|
// 每次调用都返回"此刻"的默认时间范围,避免长时间驻留页面后
|
||||||
organizationMode &&
|
// 点击"重置"仍得到页面加载时的"今日"(跨日 bug)
|
||||||
Number.isFinite(Number(sharedStartTimestamp)) &&
|
|
||||||
Number.isFinite(Number(sharedEndTimestamp));
|
|
||||||
|
|
||||||
// 每次调用都返回"此刻"的默认时间范围,默认最近 7 天,避免任务页首屏
|
|
||||||
// 只查当天而遗漏历史任务;返回 Date 对象以便日期控件正确显示。
|
|
||||||
const getFreshDateRange = () => {
|
const getFreshDateRange = () => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
now.setSeconds(0, 0);
|
const zeroNow = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||||
const start = new Date(
|
return [
|
||||||
now.getTime() - DEFAULT_TASK_RANGE_DAYS * 24 * 60 * 60 * 1000,
|
timestamp2string(zeroNow.getTime() / 1000),
|
||||||
);
|
timestamp2string(now.getTime() / 1000 + 3600),
|
||||||
return [start, now];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
const getFreshInitValues = () => ({
|
const getFreshInitValues = () => ({
|
||||||
@@ -180,6 +153,7 @@ export const useTaskLogsData = ({
|
|||||||
[COLUMN_KEYS.FINISH_TIME]: true,
|
[COLUMN_KEYS.FINISH_TIME]: true,
|
||||||
[COLUMN_KEYS.DURATION]: true,
|
[COLUMN_KEYS.DURATION]: true,
|
||||||
[COLUMN_KEYS.CHANNEL]: isAdminUser,
|
[COLUMN_KEYS.CHANNEL]: isAdminUser,
|
||||||
|
[COLUMN_KEYS.PLATFORM]: true,
|
||||||
[COLUMN_KEYS.TYPE]: true,
|
[COLUMN_KEYS.TYPE]: true,
|
||||||
[COLUMN_KEYS.MODEL]: true,
|
[COLUMN_KEYS.MODEL]: true,
|
||||||
[COLUMN_KEYS.TASK_ID]: true,
|
[COLUMN_KEYS.TASK_ID]: true,
|
||||||
@@ -232,17 +206,12 @@ export const useTaskLogsData = ({
|
|||||||
// 否则 URL 带的 ?task_id=xxx 在第一次 loadLogs 时会被当成空字符串,导致初始列表不过滤
|
// 否则 URL 带的 ?task_id=xxx 在第一次 loadLogs 时会被当成空字符串,导致初始列表不过滤
|
||||||
const formValues = formApi ? formApi.getValues() : formInitValues;
|
const formValues = formApi ? formApi.getValues() : formInitValues;
|
||||||
|
|
||||||
// 企业页复用上方已经提交的时间范围;个人/平台任务页使用自己的日期控件。
|
// 处理时间范围:每次调用时取"此刻"的默认值,避免闭包陈旧
|
||||||
const [freshStart, freshEnd] = getFreshDateRange();
|
const [freshStart, freshEnd] = getFreshDateRange();
|
||||||
let start_timestamp = usesSharedDateRange
|
let start_timestamp = freshStart;
|
||||||
? Number(sharedStartTimestamp)
|
let end_timestamp = freshEnd;
|
||||||
: freshStart;
|
|
||||||
let end_timestamp = usesSharedDateRange
|
|
||||||
? Number(sharedEndTimestamp)
|
|
||||||
: freshEnd;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!usesSharedDateRange &&
|
|
||||||
formValues.dateRange &&
|
formValues.dateRange &&
|
||||||
Array.isArray(formValues.dateRange) &&
|
Array.isArray(formValues.dateRange) &&
|
||||||
formValues.dateRange.length === 2
|
formValues.dateRange.length === 2
|
||||||
@@ -326,8 +295,8 @@ export const useTaskLogsData = ({
|
|||||||
start_timestamp,
|
start_timestamp,
|
||||||
end_timestamp,
|
end_timestamp,
|
||||||
} = getFormValues();
|
} = getFormValues();
|
||||||
let localStartTimestamp = toUnixTimestamp(start_timestamp);
|
let localStartTimestamp = parseInt(Date.parse(start_timestamp) / 1000);
|
||||||
let localEndTimestamp = toUnixTimestamp(end_timestamp);
|
let localEndTimestamp = parseInt(Date.parse(end_timestamp) / 1000);
|
||||||
// 时间范围校验:起始晚于结束视为非法,避免白发一轮请求并给出提示
|
// 时间范围校验:起始晚于结束视为非法,避免白发一轮请求并给出提示
|
||||||
if (
|
if (
|
||||||
Number.isFinite(localStartTimestamp) &&
|
Number.isFinite(localStartTimestamp) &&
|
||||||
@@ -355,11 +324,9 @@ export const useTaskLogsData = ({
|
|||||||
// 与使用日志对齐:管理员可按 user_id 过滤任务日志
|
// 与使用日志对齐:管理员可按 user_id 过滤任务日志
|
||||||
if (user_id) params.set('user_id', user_id);
|
if (user_id) params.set('user_id', user_id);
|
||||||
}
|
}
|
||||||
const url = organizationMode
|
const url = isAdminUser
|
||||||
? `/api/org/tasks?${params.toString()}`
|
? `/api/task/?${params.toString()}`
|
||||||
: isAdminUser
|
: `/api/task/self?${params.toString()}`;
|
||||||
? `/api/task/?${params.toString()}`
|
|
||||||
: `/api/task/self?${params.toString()}`;
|
|
||||||
try {
|
try {
|
||||||
const res = await API.get(url);
|
const res = await API.get(url);
|
||||||
// 过时响应直接丢弃:reqId 小于最新值说明更新的请求已经发出
|
// 过时响应直接丢弃:reqId 小于最新值说明更新的请求已经发出
|
||||||
@@ -444,12 +411,7 @@ export const useTaskLogsData = ({
|
|||||||
parseInt(localStorage.getItem('task-page-size')) || ITEMS_PER_PAGE;
|
parseInt(localStorage.getItem('task-page-size')) || ITEMS_PER_PAGE;
|
||||||
setPageSize(localPageSize);
|
setPageSize(localPageSize);
|
||||||
loadLogs(1, localPageSize).then();
|
loadLogs(1, localPageSize).then();
|
||||||
}, [
|
}, []);
|
||||||
organizationMode,
|
|
||||||
sharedStartTimestamp,
|
|
||||||
sharedEndTimestamp,
|
|
||||||
sharedFilterRevision,
|
|
||||||
]);
|
|
||||||
|
|
||||||
// 存在进行中的任务时,自动轮询刷新(10s 间隔),无 pending 则停止,避免无谓请求
|
// 存在进行中的任务时,自动轮询刷新(10s 间隔),无 pending 则停止,避免无谓请求
|
||||||
const loadLogsRef = useRef(loadLogs);
|
const loadLogsRef = useRef(loadLogs);
|
||||||
@@ -501,8 +463,6 @@ export const useTaskLogsData = ({
|
|||||||
logCount,
|
logCount,
|
||||||
pageSize,
|
pageSize,
|
||||||
isAdminUser,
|
isAdminUser,
|
||||||
isRootUser,
|
|
||||||
usesSharedDateRange,
|
|
||||||
|
|
||||||
// Modal state
|
// Modal state
|
||||||
isModalOpen,
|
isModalOpen,
|
||||||
|
|||||||
+129
-146
@@ -47,7 +47,6 @@ import {
|
|||||||
import OrgPageHeader from './components/OrgPageHeader';
|
import OrgPageHeader from './components/OrgPageHeader';
|
||||||
import { OrgFilterCard, OrgListCard } from './components/OrgListCard';
|
import { OrgFilterCard, OrgListCard } from './components/OrgListCard';
|
||||||
import OrgModal from './components/OrgModal';
|
import OrgModal from './components/OrgModal';
|
||||||
import TaskLogsTable from '../../components/table/task-logs';
|
|
||||||
import {
|
import {
|
||||||
API,
|
API,
|
||||||
showError,
|
showError,
|
||||||
@@ -234,7 +233,6 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
|
|||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
const pageSize = 20;
|
const pageSize = 20;
|
||||||
const [activeTab, setActiveTab] = useState('logs');
|
const [activeTab, setActiveTab] = useState('logs');
|
||||||
const [taskFilterRevision, setTaskFilterRevision] = useState(0);
|
|
||||||
const isAdmin =
|
const isAdmin =
|
||||||
orgRole === 'owner' || orgRole === 'admin' || orgRole === 'super_admin';
|
orgRole === 'owner' || orgRole === 'admin' || orgRole === 'super_admin';
|
||||||
const canViewTeamUsage = isAdmin || isDeptManager;
|
const canViewTeamUsage = isAdmin || isDeptManager;
|
||||||
@@ -346,7 +344,6 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
setPage(1);
|
setPage(1);
|
||||||
setTaskFilterRevision((revision) => revision + 1);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 重置:回到默认状态(滚动最近 7 天、不限成员/模型)
|
// 重置:回到默认状态(滚动最近 7 天、不限成员/模型)
|
||||||
@@ -367,7 +364,6 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
setPage(1);
|
setPage(1);
|
||||||
setTaskFilterRevision((revision) => revision + 1);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 导出弹窗状态(导出方式 + 字段勾选从 localStorage 恢复)
|
// 导出弹窗状态(导出方式 + 字段勾选从 localStorage 恢复)
|
||||||
@@ -782,157 +778,144 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
|
|||||||
onChange={setActiveTab}
|
onChange={setActiveTab}
|
||||||
items={[
|
items={[
|
||||||
{ key: 'logs', label: t('明细日志') },
|
{ key: 'logs', label: t('明细日志') },
|
||||||
{ key: 'tasks', label: t('绘图与视频') },
|
|
||||||
...(canViewTeamUsage
|
...(canViewTeamUsage
|
||||||
? [{ key: 'ranking', label: t('成员排行') }]
|
? [{ key: 'ranking', label: t('成员排行') }]
|
||||||
: []),
|
: []),
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{activeTab === 'tasks' ? (
|
{/* 筛选栏(原型 .ee-filter-card / .eex-filter-grid) */}
|
||||||
<TaskLogsTable
|
<OrgFilterCard
|
||||||
usageRecordMode
|
className='oc-exp-filter'
|
||||||
organizationMode
|
actions={
|
||||||
sharedStartTimestamp={appliedFilters.startTimestamp}
|
<>
|
||||||
sharedEndTimestamp={appliedFilters.endTimestamp}
|
<Button onClick={handleReset}>{t('重置')}</Button>
|
||||||
sharedFilterRevision={taskFilterRevision}
|
<Button
|
||||||
/>
|
type='primary'
|
||||||
) : (
|
icon={<Search size={16} />}
|
||||||
<>
|
onClick={() => handleSearch(false)}
|
||||||
{/* 筛选栏(原型 .ee-filter-card / .eex-filter-grid) */}
|
loading={loading}
|
||||||
<OrgFilterCard
|
>
|
||||||
className='oc-exp-filter'
|
{t('搜索')}
|
||||||
actions={
|
</Button>
|
||||||
<>
|
</>
|
||||||
<Button onClick={handleReset}>{t('重置')}</Button>
|
}
|
||||||
<Button
|
>
|
||||||
type='primary'
|
<AntForm layout='vertical' requiredMark={false} component='div'>
|
||||||
icon={<Search size={16} />}
|
<AntForm.Item label={t('成员')}>
|
||||||
onClick={() => handleSearch(false)}
|
{canViewTeamUsage ? (
|
||||||
loading={loading}
|
<Select
|
||||||
>
|
value={selectedUserId}
|
||||||
{t('搜索')}
|
onChange={setSelectedUserId}
|
||||||
</Button>
|
optionList={memberOptions}
|
||||||
</>
|
style={{ width: '100%' }}
|
||||||
}
|
placeholder={isAdmin ? t('全部成员') : t('全部部门成员')}
|
||||||
>
|
filter
|
||||||
<AntForm layout='vertical' requiredMark={false} component='div'>
|
|
||||||
<AntForm.Item label={t('成员')}>
|
|
||||||
{canViewTeamUsage ? (
|
|
||||||
<Select
|
|
||||||
value={selectedUserId}
|
|
||||||
onChange={setSelectedUserId}
|
|
||||||
optionList={memberOptions}
|
|
||||||
style={{ width: '100%' }}
|
|
||||||
placeholder={isAdmin ? t('全部成员') : t('全部部门成员')}
|
|
||||||
filter
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<div className='oc-exp-self'>{t('仅本人')}</div>
|
|
||||||
)}
|
|
||||||
</AntForm.Item>
|
|
||||||
</AntForm>
|
|
||||||
<AntForm layout='vertical' requiredMark={false} component='div'>
|
|
||||||
<AntForm.Item label={t('时间范围')}>
|
|
||||||
<DatePicker
|
|
||||||
type='dateTimeRange'
|
|
||||||
value={dateRange}
|
|
||||||
onChange={(v) => {
|
|
||||||
setDateRange(v);
|
|
||||||
setIsDefaultRange(false);
|
|
||||||
}}
|
|
||||||
placeholder={[t('开始时间'), t('结束时间')]}
|
|
||||||
style={{ width: '100%' }}
|
|
||||||
/>
|
|
||||||
</AntForm.Item>
|
|
||||||
</AntForm>
|
|
||||||
<AntForm layout='vertical' requiredMark={false} component='div'>
|
|
||||||
<AntForm.Item label={t('模型名称')}>
|
|
||||||
<Input
|
|
||||||
placeholder={t('请输入模型名称')}
|
|
||||||
value={modelName}
|
|
||||||
onChange={setModelName}
|
|
||||||
onEnterPress={() => handleSearch(false)}
|
|
||||||
/>
|
|
||||||
</AntForm.Item>
|
|
||||||
</AntForm>
|
|
||||||
</OrgFilterCard>
|
|
||||||
|
|
||||||
<OrgListCard
|
|
||||||
title={activeTab === 'ranking' ? t('成员排行') : t('明细日志')}
|
|
||||||
tools={
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
icon={<Download size={16} />}
|
|
||||||
onClick={() => setExportModalVisible(true)}
|
|
||||||
>
|
|
||||||
{t('导出')}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
icon={<RefreshCw size={16} />}
|
|
||||||
onClick={() => handleSearch(true)}
|
|
||||||
loading={loading}
|
|
||||||
>
|
|
||||||
{t('刷新')}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{activeTab === 'ranking' && canViewTeamUsage ? (
|
|
||||||
<Table
|
|
||||||
columns={rankingColumns}
|
|
||||||
dataSource={ranking}
|
|
||||||
loading={rankingLoading}
|
|
||||||
rowKey='user_id'
|
|
||||||
pagination={false}
|
|
||||||
scroll={{ x: 790 }}
|
|
||||||
empty={
|
|
||||||
<div className='py-10 text-center'>
|
|
||||||
<div className='inline-flex p-3 rounded-full bg-gray-100 dark:bg-neutral-800 mb-3'>
|
|
||||||
<Trophy
|
|
||||||
size={24}
|
|
||||||
className='text-gray-400 dark:text-gray-500'
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<p className='text-gray-400 dark:text-gray-500 text-sm'>
|
|
||||||
{t('暂无排行数据')}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Table
|
<div className='oc-exp-self'>{t('仅本人')}</div>
|
||||||
columns={logColumns}
|
|
||||||
dataSource={logs}
|
|
||||||
loading={loading}
|
|
||||||
rowKey='id'
|
|
||||||
scroll={{ x: 1285 }}
|
|
||||||
pagination={{
|
|
||||||
currentPage: page,
|
|
||||||
pageSize,
|
|
||||||
total,
|
|
||||||
showSizeChanger: false,
|
|
||||||
onPageChange: (p) => doPageFetch(p),
|
|
||||||
showTotal: (n) => t('共 {{total}} 条', { total: n }),
|
|
||||||
}}
|
|
||||||
empty={
|
|
||||||
<div className='py-10 text-center'>
|
|
||||||
<div className='inline-flex p-3 rounded-full bg-gray-100 dark:bg-neutral-800 mb-3'>
|
|
||||||
<Receipt
|
|
||||||
size={24}
|
|
||||||
className='text-gray-400 dark:text-gray-500'
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<p className='text-gray-400 dark:text-gray-500 text-sm'>
|
|
||||||
{t('暂无消耗记录')}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</OrgListCard>
|
</AntForm.Item>
|
||||||
</>
|
</AntForm>
|
||||||
)}
|
<AntForm layout='vertical' requiredMark={false} component='div'>
|
||||||
|
<AntForm.Item label={t('时间范围')}>
|
||||||
|
<DatePicker
|
||||||
|
type='dateTimeRange'
|
||||||
|
value={dateRange}
|
||||||
|
onChange={(v) => {
|
||||||
|
setDateRange(v);
|
||||||
|
setIsDefaultRange(false);
|
||||||
|
}}
|
||||||
|
placeholder={[t('开始时间'), t('结束时间')]}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
/>
|
||||||
|
</AntForm.Item>
|
||||||
|
</AntForm>
|
||||||
|
<AntForm layout='vertical' requiredMark={false} component='div'>
|
||||||
|
<AntForm.Item label={t('模型名称')}>
|
||||||
|
<Input
|
||||||
|
placeholder={t('请输入模型名称')}
|
||||||
|
value={modelName}
|
||||||
|
onChange={setModelName}
|
||||||
|
onEnterPress={() => handleSearch(false)}
|
||||||
|
/>
|
||||||
|
</AntForm.Item>
|
||||||
|
</AntForm>
|
||||||
|
</OrgFilterCard>
|
||||||
|
|
||||||
|
<OrgListCard
|
||||||
|
title={activeTab === 'ranking' ? t('成员排行') : t('明细日志')}
|
||||||
|
tools={
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
icon={<Download size={16} />}
|
||||||
|
onClick={() => setExportModalVisible(true)}
|
||||||
|
>
|
||||||
|
{t('导出')}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
icon={<RefreshCw size={16} />}
|
||||||
|
onClick={() => handleSearch(true)}
|
||||||
|
loading={loading}
|
||||||
|
>
|
||||||
|
{t('刷新')}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{activeTab === 'ranking' && canViewTeamUsage ? (
|
||||||
|
<Table
|
||||||
|
columns={rankingColumns}
|
||||||
|
dataSource={ranking}
|
||||||
|
loading={rankingLoading}
|
||||||
|
rowKey='user_id'
|
||||||
|
pagination={false}
|
||||||
|
scroll={{ x: 790 }}
|
||||||
|
empty={
|
||||||
|
<div className='py-10 text-center'>
|
||||||
|
<div className='inline-flex p-3 rounded-full bg-gray-100 dark:bg-neutral-800 mb-3'>
|
||||||
|
<Trophy
|
||||||
|
size={24}
|
||||||
|
className='text-gray-400 dark:text-gray-500'
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<p className='text-gray-400 dark:text-gray-500 text-sm'>
|
||||||
|
{t('暂无排行数据')}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Table
|
||||||
|
columns={logColumns}
|
||||||
|
dataSource={logs}
|
||||||
|
loading={loading}
|
||||||
|
rowKey='id'
|
||||||
|
scroll={{ x: 1285 }}
|
||||||
|
pagination={{
|
||||||
|
currentPage: page,
|
||||||
|
pageSize,
|
||||||
|
total,
|
||||||
|
showSizeChanger: false,
|
||||||
|
onPageChange: (p) => doPageFetch(p),
|
||||||
|
showTotal: (n) => t('共 {{total}} 条', { total: n }),
|
||||||
|
}}
|
||||||
|
empty={
|
||||||
|
<div className='py-10 text-center'>
|
||||||
|
<div className='inline-flex p-3 rounded-full bg-gray-100 dark:bg-neutral-800 mb-3'>
|
||||||
|
<Receipt
|
||||||
|
size={24}
|
||||||
|
className='text-gray-400 dark:text-gray-500'
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<p className='text-gray-400 dark:text-gray-500 text-sm'>
|
||||||
|
{t('暂无消耗记录')}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</OrgListCard>
|
||||||
|
|
||||||
{/* 导出弹窗:汇总 / 按用户 + 字段选择 */}
|
{/* 导出弹窗:汇总 / 按用户 + 字段选择 */}
|
||||||
<OrgModal
|
<OrgModal
|
||||||
|
|||||||
@@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
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 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, /<TaskLogsTable usageRecordMode \/>/);
|
|
||||||
assert.doesNotMatch(actions, /key: 'platform'/);
|
|
||||||
assert.match(columns, /isRootUser\s*\?\s*\(\) => openContentModal/);
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user