feat(phase7): add batch asset classification
This commit is contained in:
@@ -57,6 +57,7 @@ const ProjectAssets: React.FC = () => {
|
||||
const [classificationJobId, setClassificationJobId] = useState<string>('');
|
||||
const [classifyingAssetId, setClassifyingAssetId] = useState<string>('');
|
||||
const [classificationFilter, setClassificationFilter] = useState<string>('all');
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
|
||||
const [form] = Form.useForm();
|
||||
|
||||
const librariesQuery = useQuery({
|
||||
@@ -166,6 +167,40 @@ const ProjectAssets: React.FC = () => {
|
||||
return items.filter((item) => item.metadata?.classification === classificationFilter);
|
||||
}, [assetsQuery.data, classificationFilter]);
|
||||
|
||||
const selectedAssets = useMemo(
|
||||
() => filteredAssets.filter((item) => selectedRowKeys.includes(item.id)),
|
||||
[filteredAssets, selectedRowKeys]
|
||||
);
|
||||
|
||||
const selectableAssets = useMemo(
|
||||
() =>
|
||||
selectedAssets.filter(
|
||||
(item) => item.metadata?.auto_classification !== 'queued' && classifyingAssetId !== item.id
|
||||
),
|
||||
[selectedAssets, classifyingAssetId]
|
||||
);
|
||||
|
||||
const handleBatchClassification = async () => {
|
||||
if (!selectableAssets.length) {
|
||||
message.warning('没有可批量分类的素材');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
for (const asset of selectableAssets) {
|
||||
await submitClassificationJob({
|
||||
workspace_id: asset.workspace_id,
|
||||
project_id: asset.project_id,
|
||||
asset_id: asset.id,
|
||||
});
|
||||
}
|
||||
message.success(`已发起 ${selectableAssets.length} 个分类任务`);
|
||||
setSelectedRowKeys([]);
|
||||
assetsQuery.refetch();
|
||||
} catch {
|
||||
message.error('批量发起分类失败');
|
||||
}
|
||||
};
|
||||
|
||||
const renderClassification = (asset: AssetItem) => {
|
||||
const autoClassification = String(asset.metadata?.auto_classification || '');
|
||||
if (classifyingAssetId === asset.id || autoClassification === 'queued') {
|
||||
@@ -225,7 +260,13 @@ const ProjectAssets: React.FC = () => {
|
||||
});
|
||||
}}
|
||||
>
|
||||
{isAutoClassifying ? '自动分类中...' : isCurrentClassifying ? '分类中...' : hasClassification ? '重新分类' : '发起分类'}
|
||||
{isAutoClassifying
|
||||
? '自动分类中...'
|
||||
: isCurrentClassifying
|
||||
? '分类中...'
|
||||
: hasClassification
|
||||
? '重新分类'
|
||||
: '发起分类'}
|
||||
</Button>
|
||||
);
|
||||
},
|
||||
@@ -278,6 +319,9 @@ const ProjectAssets: React.FC = () => {
|
||||
onChange={setLibraryId}
|
||||
loading={librariesQuery.isLoading}
|
||||
/>
|
||||
<Button icon={<TagsOutlined />} disabled={!selectedRowKeys.length} onClick={handleBatchClassification}>
|
||||
批量分类 ({selectedRowKeys.length})
|
||||
</Button>
|
||||
<Button icon={<PlusOutlined />} onClick={() => setCreateLibraryOpen(true)}>
|
||||
新建素材库
|
||||
</Button>
|
||||
@@ -330,7 +374,16 @@ const ProjectAssets: React.FC = () => {
|
||||
</Dragger>
|
||||
|
||||
{filteredAssets.length ? (
|
||||
<Table rowKey="id" columns={columns} dataSource={filteredAssets} pagination={false} />
|
||||
<Table
|
||||
rowKey="id"
|
||||
rowSelection={{
|
||||
selectedRowKeys,
|
||||
onChange: setSelectedRowKeys,
|
||||
}}
|
||||
columns={columns}
|
||||
dataSource={filteredAssets}
|
||||
pagination={false}
|
||||
/>
|
||||
) : (
|
||||
<Empty description="当前筛选条件下没有素材" />
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user