2026-07-22 15:39:57 +08:00
|
|
|
|
import { useEffect, useMemo, useState } from 'react'
|
|
|
|
|
|
import type { ReactNode } from 'react'
|
2026-07-23 22:25:12 +08:00
|
|
|
|
import { Alert, Button, Card, Empty, Grid, Input, Message, Modal, Space, Spin, Switch, Typography } from '@arco-design/web-react'
|
2026-07-22 15:39:57 +08:00
|
|
|
|
import {
|
|
|
|
|
|
IconBook,
|
|
|
|
|
|
IconCheckCircle,
|
|
|
|
|
|
IconCompass,
|
|
|
|
|
|
IconDelete,
|
|
|
|
|
|
IconEdit,
|
2026-07-23 15:07:35 +08:00
|
|
|
|
IconLaunch,
|
2026-07-22 15:39:57 +08:00
|
|
|
|
IconLink,
|
|
|
|
|
|
IconRefresh,
|
|
|
|
|
|
IconStar,
|
|
|
|
|
|
IconStorage,
|
|
|
|
|
|
} from '@arco-design/web-react/icon'
|
2026-07-23 15:07:35 +08:00
|
|
|
|
import type {
|
|
|
|
|
|
DatasetCronDTO,
|
2026-07-23 22:25:12 +08:00
|
|
|
|
DatasetDepositDTO,
|
2026-07-23 15:07:35 +08:00
|
|
|
|
DatasetItemDTO,
|
2026-07-23 22:25:12 +08:00
|
|
|
|
DatasetItemPageDTO,
|
2026-07-23 15:07:35 +08:00
|
|
|
|
DatasetItemUpdate,
|
|
|
|
|
|
DatasetSourceDTO,
|
|
|
|
|
|
DatasetSourceInput,
|
|
|
|
|
|
DatasetSourceKind,
|
|
|
|
|
|
} from '../api/dataset'
|
2026-07-21 00:46:09 +08:00
|
|
|
|
|
2026-07-22 15:39:57 +08:00
|
|
|
|
const { Row, Col } = Grid
|
|
|
|
|
|
const { Title, Text, Paragraph } = Typography
|
2026-07-22 15:56:04 +08:00
|
|
|
|
const { TextArea } = Input
|
2026-07-23 22:25:12 +08:00
|
|
|
|
const ITEM_PAGE_SIZE = 50
|
2026-07-22 15:39:57 +08:00
|
|
|
|
|
2026-07-23 15:07:35 +08:00
|
|
|
|
type DataSourceCard = DatasetSourceDTO & {
|
2026-07-22 15:39:57 +08:00
|
|
|
|
icon: ReactNode
|
|
|
|
|
|
color: string
|
2026-07-22 15:56:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type SourceDraft = {
|
|
|
|
|
|
name: string
|
2026-07-23 15:07:35 +08:00
|
|
|
|
kind: DatasetSourceKind
|
2026-07-22 15:56:04 +08:00
|
|
|
|
url: string
|
2026-07-23 15:14:31 +08:00
|
|
|
|
iconUrl: string
|
2026-07-22 15:56:04 +08:00
|
|
|
|
description: string
|
2026-07-23 15:07:35 +08:00
|
|
|
|
enabled: boolean
|
2026-07-22 15:39:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-22 15:56:04 +08:00
|
|
|
|
const EMPTY_SOURCE_DRAFT: SourceDraft = {
|
|
|
|
|
|
name: '',
|
2026-07-23 22:25:12 +08:00
|
|
|
|
kind: 'rss',
|
2026-07-22 15:56:04 +08:00
|
|
|
|
url: '',
|
2026-07-23 15:14:31 +08:00
|
|
|
|
iconUrl: '',
|
2026-07-22 15:56:04 +08:00
|
|
|
|
description: '',
|
2026-07-23 15:07:35 +08:00
|
|
|
|
enabled: true,
|
2026-07-22 15:39:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function WorkspaceExplorePage({
|
2026-07-23 22:25:12 +08:00
|
|
|
|
activeProjectID,
|
|
|
|
|
|
activeProjectName,
|
2026-07-23 15:07:35 +08:00
|
|
|
|
onListSources,
|
|
|
|
|
|
onListItems,
|
|
|
|
|
|
onCreateSource,
|
|
|
|
|
|
onUpdateSource,
|
|
|
|
|
|
onDeleteSource,
|
|
|
|
|
|
onUpdateItem,
|
|
|
|
|
|
onQueueSync,
|
2026-07-23 22:25:12 +08:00
|
|
|
|
onListCrons,
|
|
|
|
|
|
onDepositItem,
|
2026-07-22 15:39:57 +08:00
|
|
|
|
}: {
|
2026-07-23 22:25:12 +08:00
|
|
|
|
activeProjectID: string
|
|
|
|
|
|
activeProjectName: string
|
2026-07-23 15:07:35 +08:00
|
|
|
|
onListSources: (signal?: AbortSignal) => Promise<DatasetSourceDTO[]>
|
2026-07-23 22:25:12 +08:00
|
|
|
|
onListItems: (sourceId?: string, offset?: number, limit?: number, signal?: AbortSignal) => Promise<DatasetItemPageDTO>
|
2026-07-23 15:07:35 +08:00
|
|
|
|
onCreateSource: (input: DatasetSourceInput) => Promise<DatasetSourceDTO>
|
|
|
|
|
|
onUpdateSource: (sourceId: string, input: DatasetSourceInput) => Promise<DatasetSourceDTO>
|
|
|
|
|
|
onDeleteSource: (sourceId: string) => Promise<void>
|
|
|
|
|
|
onUpdateItem: (itemId: string, input: DatasetItemUpdate) => Promise<DatasetItemDTO>
|
|
|
|
|
|
onQueueSync: () => Promise<DatasetCronDTO[]>
|
2026-07-23 22:25:12 +08:00
|
|
|
|
onListCrons: (signal?: AbortSignal) => Promise<DatasetCronDTO[]>
|
|
|
|
|
|
onDepositItem: (itemId: string, projectId: string) => Promise<DatasetDepositDTO & { refreshFailed?: boolean }>
|
2026-07-22 15:39:57 +08:00
|
|
|
|
}) {
|
2026-07-23 15:07:35 +08:00
|
|
|
|
const [sourceRecords, setSourceRecords] = useState<DatasetSourceDTO[]>([])
|
|
|
|
|
|
const [items, setItems] = useState<DatasetItemDTO[]>([])
|
2026-07-23 22:25:12 +08:00
|
|
|
|
const [itemTotal, setItemTotal] = useState(0)
|
2026-07-23 15:07:35 +08:00
|
|
|
|
const [activeSourceID, setActiveSourceID] = useState('all')
|
|
|
|
|
|
const [activeItemID, setActiveItemID] = useState<string | null>(null)
|
2026-07-22 15:56:04 +08:00
|
|
|
|
const [sourceModalMode, setSourceModalMode] = useState<'add' | 'edit' | null>(null)
|
2026-07-23 15:07:35 +08:00
|
|
|
|
const [editingSourceID, setEditingSourceID] = useState<string | null>(null)
|
2026-07-22 15:56:04 +08:00
|
|
|
|
const [sourceDraft, setSourceDraft] = useState<SourceDraft>(EMPTY_SOURCE_DRAFT)
|
|
|
|
|
|
const [sourceError, setSourceError] = useState('')
|
2026-07-23 15:07:35 +08:00
|
|
|
|
const [loadError, setLoadError] = useState('')
|
|
|
|
|
|
const [loading, setLoading] = useState(true)
|
2026-07-23 22:25:12 +08:00
|
|
|
|
const [itemsLoading, setItemsLoading] = useState(true)
|
2026-07-23 15:07:35 +08:00
|
|
|
|
const [saving, setSaving] = useState(false)
|
|
|
|
|
|
const [syncing, setSyncing] = useState(false)
|
2026-07-23 22:25:12 +08:00
|
|
|
|
const [depositingItemID, setDepositingItemID] = useState<string | null>(null)
|
2026-07-23 15:07:35 +08:00
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
const controller = new AbortController()
|
|
|
|
|
|
setLoading(true)
|
|
|
|
|
|
setLoadError('')
|
2026-07-23 22:25:12 +08:00
|
|
|
|
onListSources(controller.signal)
|
|
|
|
|
|
.then((nextSources) => {
|
2026-07-23 15:07:35 +08:00
|
|
|
|
setSourceRecords(nextSources)
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((error: unknown) => {
|
|
|
|
|
|
if (!controller.signal.aborted) {
|
|
|
|
|
|
setLoadError(error instanceof Error ? error.message : '探索数据加载失败')
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.finally(() => {
|
|
|
|
|
|
if (!controller.signal.aborted) setLoading(false)
|
|
|
|
|
|
})
|
|
|
|
|
|
return () => controller.abort()
|
2026-07-23 22:25:12 +08:00
|
|
|
|
}, [onListSources])
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
const controller = new AbortController()
|
|
|
|
|
|
setItemsLoading(true)
|
|
|
|
|
|
setLoadError('')
|
|
|
|
|
|
setItems([])
|
|
|
|
|
|
setItemTotal(0)
|
|
|
|
|
|
setActiveItemID(null)
|
|
|
|
|
|
const sourceID = activeSourceID === 'all' ? undefined : activeSourceID
|
|
|
|
|
|
onListItems(sourceID, 0, ITEM_PAGE_SIZE, controller.signal)
|
|
|
|
|
|
.then((page) => {
|
|
|
|
|
|
setItems(page.items)
|
|
|
|
|
|
setItemTotal(page.total)
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((error: unknown) => {
|
|
|
|
|
|
if (!controller.signal.aborted) {
|
|
|
|
|
|
setLoadError(error instanceof Error ? error.message : '探索内容加载失败')
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.finally(() => {
|
|
|
|
|
|
if (!controller.signal.aborted) setItemsLoading(false)
|
|
|
|
|
|
})
|
|
|
|
|
|
return () => controller.abort()
|
|
|
|
|
|
}, [activeSourceID, onListItems])
|
2026-07-23 15:07:35 +08:00
|
|
|
|
|
|
|
|
|
|
const sources = useMemo<DataSourceCard[]>(() => {
|
|
|
|
|
|
const allSource: DataSourceCard = {
|
|
|
|
|
|
id: 'all',
|
|
|
|
|
|
name: '全部',
|
|
|
|
|
|
kind: 'manual',
|
|
|
|
|
|
url: '',
|
2026-07-23 15:14:31 +08:00
|
|
|
|
iconUrl: '',
|
2026-07-23 15:07:35 +08:00
|
|
|
|
description: '全部探索内容',
|
|
|
|
|
|
enabled: true,
|
2026-07-23 22:25:12 +08:00
|
|
|
|
builtIn: true,
|
2026-07-23 15:07:35 +08:00
|
|
|
|
lastSyncedAt: null,
|
2026-07-23 22:25:12 +08:00
|
|
|
|
itemCount: sourceRecords.reduce((total, source) => total + source.itemCount, 0),
|
2026-07-23 15:07:35 +08:00
|
|
|
|
createdAt: '',
|
|
|
|
|
|
updatedAt: '',
|
|
|
|
|
|
icon: <IconStorage />,
|
|
|
|
|
|
color: 'blue',
|
|
|
|
|
|
}
|
|
|
|
|
|
return [
|
|
|
|
|
|
allSource,
|
|
|
|
|
|
...sourceRecords.map((source) => ({
|
|
|
|
|
|
...source,
|
2026-07-23 15:14:31 +08:00
|
|
|
|
icon: source.iconUrl
|
|
|
|
|
|
? <img className="explore-source-image" src={source.iconUrl} alt="" />
|
|
|
|
|
|
: sourceIcon(source.kind),
|
2026-07-23 15:07:35 +08:00
|
|
|
|
color: sourceColor(source.kind),
|
|
|
|
|
|
})),
|
|
|
|
|
|
]
|
2026-07-23 22:25:12 +08:00
|
|
|
|
}, [sourceRecords])
|
2026-07-23 15:07:35 +08:00
|
|
|
|
|
2026-07-23 22:25:12 +08:00
|
|
|
|
const filteredItems = items
|
2026-07-22 15:39:57 +08:00
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-07-23 15:07:35 +08:00
|
|
|
|
if (filteredItems.length === 0) {
|
|
|
|
|
|
setActiveItemID(null)
|
2026-07-22 15:39:57 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2026-07-23 15:07:35 +08:00
|
|
|
|
if (!activeItemID || !filteredItems.some((item) => item.id === activeItemID)) {
|
|
|
|
|
|
setActiveItemID(filteredItems[0].id)
|
2026-07-22 15:39:57 +08:00
|
|
|
|
}
|
2026-07-23 15:07:35 +08:00
|
|
|
|
}, [activeItemID, filteredItems])
|
2026-07-22 15:39:57 +08:00
|
|
|
|
|
2026-07-23 15:07:35 +08:00
|
|
|
|
const selected = filteredItems.find((item) => item.id === activeItemID) ?? filteredItems[0]
|
2026-07-22 15:56:04 +08:00
|
|
|
|
const activeSource = sourceByID(sources, activeSourceID)
|
2026-07-23 15:07:35 +08:00
|
|
|
|
const selectedSource = selected ? sourceByID(sources, selected.sourceId) : activeSource
|
2026-07-23 22:25:12 +08:00
|
|
|
|
const editingSource = editingSourceID
|
|
|
|
|
|
? sourceRecords.find((source) => source.id === editingSourceID)
|
|
|
|
|
|
: undefined
|
2026-07-22 15:56:04 +08:00
|
|
|
|
|
|
|
|
|
|
function openAddSource() {
|
|
|
|
|
|
setEditingSourceID(null)
|
|
|
|
|
|
setSourceDraft(EMPTY_SOURCE_DRAFT)
|
|
|
|
|
|
setSourceError('')
|
|
|
|
|
|
setSourceModalMode('add')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function openEditSource(source: DataSourceCard) {
|
|
|
|
|
|
setEditingSourceID(source.id)
|
|
|
|
|
|
setSourceDraft({
|
|
|
|
|
|
name: source.name,
|
|
|
|
|
|
kind: source.kind,
|
|
|
|
|
|
url: source.url,
|
2026-07-23 15:14:31 +08:00
|
|
|
|
iconUrl: source.iconUrl,
|
2026-07-22 15:56:04 +08:00
|
|
|
|
description: source.description,
|
2026-07-23 15:07:35 +08:00
|
|
|
|
enabled: source.enabled,
|
2026-07-22 15:56:04 +08:00
|
|
|
|
})
|
|
|
|
|
|
setSourceError('')
|
|
|
|
|
|
setSourceModalMode('edit')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-23 15:07:35 +08:00
|
|
|
|
async function saveSource() {
|
|
|
|
|
|
const input: DatasetSourceInput = {
|
|
|
|
|
|
name: sourceDraft.name.trim(),
|
|
|
|
|
|
kind: sourceDraft.kind,
|
|
|
|
|
|
url: sourceDraft.url.trim(),
|
2026-07-23 22:25:12 +08:00
|
|
|
|
iconUrl: sourceDraft.iconUrl.trim(),
|
2026-07-23 15:07:35 +08:00
|
|
|
|
description: sourceDraft.description.trim(),
|
|
|
|
|
|
enabled: sourceDraft.enabled,
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!input.name) {
|
2026-07-22 15:56:04 +08:00
|
|
|
|
setSourceError('请输入数据源名称')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2026-07-23 22:25:12 +08:00
|
|
|
|
if (input.kind === 'rss' && !input.url) {
|
|
|
|
|
|
setSourceError('RSS 数据源必须填写地址')
|
2026-07-23 15:07:35 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
setSaving(true)
|
|
|
|
|
|
setSourceError('')
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (sourceModalMode === 'edit' && editingSourceID) {
|
|
|
|
|
|
const updated = await onUpdateSource(editingSourceID, input)
|
|
|
|
|
|
setSourceRecords((current) => current.map((source) => source.id === updated.id ? updated : source))
|
|
|
|
|
|
Message.success('数据源已更新')
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const created = await onCreateSource(input)
|
|
|
|
|
|
setSourceRecords((current) => [...current, created])
|
|
|
|
|
|
Message.success('数据源已添加')
|
|
|
|
|
|
}
|
|
|
|
|
|
setSourceModalMode(null)
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
setSourceError(error instanceof Error ? error.message : '数据源保存失败')
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setSaving(false)
|
2026-07-22 15:56:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function deleteSource(source: DataSourceCard) {
|
|
|
|
|
|
Modal.confirm({
|
|
|
|
|
|
title: `删除“${source.name}”数据源?`,
|
2026-07-23 15:07:35 +08:00
|
|
|
|
content: '删除后,该数据源及其采集条目和待执行任务都会移除。',
|
2026-07-22 15:56:04 +08:00
|
|
|
|
okButtonProps: { status: 'danger' },
|
2026-07-23 15:07:35 +08:00
|
|
|
|
onOk: async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await onDeleteSource(source.id)
|
|
|
|
|
|
setSourceRecords((current) => current.filter((item) => item.id !== source.id))
|
|
|
|
|
|
setItems((current) => current.filter((item) => item.sourceId !== source.id))
|
|
|
|
|
|
if (activeSourceID === source.id) setActiveSourceID('all')
|
|
|
|
|
|
Message.success('数据源已删除')
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
Message.error(error instanceof Error ? error.message : '数据源删除失败')
|
|
|
|
|
|
throw error
|
|
|
|
|
|
}
|
2026-07-22 15:56:04 +08:00
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2026-07-21 00:46:09 +08:00
|
|
|
|
|
2026-07-23 15:07:35 +08:00
|
|
|
|
async function syncSources() {
|
|
|
|
|
|
setSyncing(true)
|
|
|
|
|
|
try {
|
2026-07-23 22:25:12 +08:00
|
|
|
|
const queued = await onQueueSync()
|
|
|
|
|
|
if (queued.length === 0) {
|
2026-07-23 20:47:54 +08:00
|
|
|
|
Message.info('暂无已启用的 RSS 数据源')
|
2026-07-23 15:07:35 +08:00
|
|
|
|
} else {
|
2026-07-23 22:25:12 +08:00
|
|
|
|
Message.info(`已提交 ${queued.length} 个采集任务`)
|
|
|
|
|
|
const crons = await waitForDatasetRuns(queued, onListCrons)
|
|
|
|
|
|
const sourceID = activeSourceID === 'all' ? undefined : activeSourceID
|
|
|
|
|
|
const [nextSources, nextPage] = await Promise.all([
|
|
|
|
|
|
onListSources(),
|
|
|
|
|
|
onListItems(sourceID, 0, ITEM_PAGE_SIZE),
|
|
|
|
|
|
])
|
2026-07-23 20:47:54 +08:00
|
|
|
|
setSourceRecords(nextSources)
|
2026-07-23 22:25:12 +08:00
|
|
|
|
setItems(nextPage.items)
|
|
|
|
|
|
setItemTotal(nextPage.total)
|
|
|
|
|
|
const failed = crons.filter((cron) => cron.status === 'failed').length
|
2026-07-23 20:47:54 +08:00
|
|
|
|
if (failed > 0) {
|
|
|
|
|
|
Message.warning(`${crons.length - failed} 个数据源采集完成,${failed} 个失败`)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Message.success(`已完成 ${crons.length} 个数据源采集任务`)
|
|
|
|
|
|
}
|
2026-07-23 15:07:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
2026-07-23 20:47:54 +08:00
|
|
|
|
Message.error(error instanceof Error ? error.message : '数据源采集失败')
|
2026-07-23 15:07:35 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
setSyncing(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-23 22:25:12 +08:00
|
|
|
|
async function loadMoreItems() {
|
|
|
|
|
|
if (itemsLoading || items.length >= itemTotal) return
|
|
|
|
|
|
setItemsLoading(true)
|
|
|
|
|
|
try {
|
|
|
|
|
|
const sourceID = activeSourceID === 'all' ? undefined : activeSourceID
|
|
|
|
|
|
const page = await onListItems(sourceID, items.length, ITEM_PAGE_SIZE)
|
|
|
|
|
|
setItems((current) => [...current, ...page.items])
|
|
|
|
|
|
setItemTotal(page.total)
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
Message.error(error instanceof Error ? error.message : '更多探索内容加载失败')
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setItemsLoading(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-23 15:07:35 +08:00
|
|
|
|
async function updateSelected(input: DatasetItemUpdate) {
|
|
|
|
|
|
if (!selected) return
|
|
|
|
|
|
try {
|
|
|
|
|
|
const updated = await onUpdateItem(selected.id, input)
|
|
|
|
|
|
setItems((current) => current.map((item) => item.id === updated.id ? updated : item))
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
Message.error(error instanceof Error ? error.message : '数据条目更新失败')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-23 22:25:12 +08:00
|
|
|
|
async function depositSelected() {
|
|
|
|
|
|
if (!selected || !activeProjectID) return
|
|
|
|
|
|
setDepositingItemID(selected.id)
|
|
|
|
|
|
try {
|
|
|
|
|
|
const result = await onDepositItem(selected.id, activeProjectID)
|
|
|
|
|
|
if (result.refreshFailed) {
|
|
|
|
|
|
Message.warning(`笔记已沉淀到项目“${activeProjectName}”,但项目数据刷新失败`)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Message.success(`已沉淀到项目“${activeProjectName}”的笔记资料`)
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
Message.error(error instanceof Error ? error.message : '沉淀到项目失败')
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setDepositingItemID(null)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-21 00:46:09 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<div className="workspace-explore-page overview-page">
|
|
|
|
|
|
<div className="overview-head">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<Title heading={4}>探索</Title>
|
2026-07-22 15:39:57 +08:00
|
|
|
|
<Text type="secondary">多个外部数据源的集中阅读页,采集文章并沉淀到项目。</Text>
|
2026-07-21 00:46:09 +08:00
|
|
|
|
</div>
|
2026-07-22 15:39:57 +08:00
|
|
|
|
<Space>
|
2026-07-23 15:07:35 +08:00
|
|
|
|
<Button icon={<IconRefresh />} loading={syncing} onClick={() => void syncSources()}>同步数据源</Button>
|
|
|
|
|
|
<Button type="primary" icon={<IconLink />} onClick={openAddSource}>添加数据源</Button>
|
2026-07-22 15:39:57 +08:00
|
|
|
|
</Space>
|
2026-07-21 00:46:09 +08:00
|
|
|
|
</div>
|
2026-07-22 15:39:57 +08:00
|
|
|
|
|
2026-07-23 15:07:35 +08:00
|
|
|
|
{loadError ? <Alert type="error" content={loadError} /> : null}
|
|
|
|
|
|
|
2026-07-23 22:25:12 +08:00
|
|
|
|
<Spin loading={loading || (itemsLoading && items.length === 0)} style={{ width: '100%' }}>
|
2026-07-23 15:07:35 +08:00
|
|
|
|
<Row gutter={10} className="explore-source-row">
|
|
|
|
|
|
{sources.map((source) => (
|
|
|
|
|
|
<Col span={6} key={source.id}>
|
|
|
|
|
|
<Card
|
|
|
|
|
|
className={activeSourceID === source.id ? 'compact-card explore-source-card active' : 'compact-card explore-source-card'}
|
|
|
|
|
|
bordered
|
|
|
|
|
|
onClick={() => setActiveSourceID(source.id)}
|
|
|
|
|
|
>
|
|
|
|
|
|
<span className={`explore-source-icon ${source.color}`}>{source.icon}</span>
|
|
|
|
|
|
<span className="explore-source-copy">
|
|
|
|
|
|
<Text className="explore-source-name">{source.name}</Text>
|
2026-07-23 22:25:12 +08:00
|
|
|
|
<Text type="secondary">{sourceSubtitle(source)}</Text>
|
2026-07-22 15:39:57 +08:00
|
|
|
|
</span>
|
2026-07-23 15:07:35 +08:00
|
|
|
|
{source.id !== 'all' ? (
|
|
|
|
|
|
<span className="explore-source-actions" onClick={(event) => event.stopPropagation()}>
|
|
|
|
|
|
<Button aria-label={`编辑${source.name}`} type="text" size="mini" icon={<IconEdit />} onClick={() => openEditSource(source)} />
|
2026-07-23 22:25:12 +08:00
|
|
|
|
{!source.builtIn ? (
|
|
|
|
|
|
<Button aria-label={`删除${source.name}`} type="text" size="mini" status="danger" icon={<IconDelete />} onClick={() => deleteSource(source)} />
|
|
|
|
|
|
) : null}
|
2026-07-23 15:07:35 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</Row>
|
|
|
|
|
|
|
|
|
|
|
|
{selected ? (
|
|
|
|
|
|
<section className="explore-reader-layout">
|
|
|
|
|
|
<Card className="explore-article-list queue-section" bordered>
|
|
|
|
|
|
<div className="explore-list-header">
|
|
|
|
|
|
<Title heading={5}>
|
|
|
|
|
|
<Space size={6}>
|
|
|
|
|
|
<span className={`explore-source-icon mini ${activeSource.color}`}>{activeSource.icon}</span>
|
|
|
|
|
|
<span>{activeSource.name}</span>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
</Title>
|
|
|
|
|
|
<Button type="text" icon={<IconRefresh />} loading={syncing} onClick={() => void syncSources()} />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="explore-list-body">
|
|
|
|
|
|
{filteredItems.map((item) => {
|
|
|
|
|
|
const itemSource = sourceByID(sources, item.sourceId)
|
|
|
|
|
|
return (
|
|
|
|
|
|
<button
|
|
|
|
|
|
key={item.id}
|
|
|
|
|
|
className={item.id === selected.id ? 'explore-article-item active' : 'explore-article-item'}
|
2026-07-23 22:25:12 +08:00
|
|
|
|
onClick={() => setActiveItemID(item.id)}
|
2026-07-23 15:07:35 +08:00
|
|
|
|
>
|
|
|
|
|
|
<span className={`explore-source-logo ${itemSource.color}`}>{sourceInitial(itemSource.name)}</span>
|
|
|
|
|
|
<span className="explore-article-copy">
|
|
|
|
|
|
<Text type="secondary">{itemSource.name} · {itemTime(item)}</Text>
|
|
|
|
|
|
<Text className="explore-article-title">{item.title}</Text>
|
|
|
|
|
|
<Text className="explore-article-summary" type="secondary" ellipsis={{ showTooltip: true }}>
|
|
|
|
|
|
{item.summary || '暂无摘要'}
|
|
|
|
|
|
</Text>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
)
|
|
|
|
|
|
})}
|
2026-07-23 22:25:12 +08:00
|
|
|
|
{items.length < itemTotal ? (
|
|
|
|
|
|
<Button long type="text" loading={itemsLoading} onClick={() => void loadMoreItems()}>
|
|
|
|
|
|
加载更多({items.length}/{itemTotal})
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
) : null}
|
2026-07-23 15:07:35 +08:00
|
|
|
|
</div>
|
2026-07-22 15:39:57 +08:00
|
|
|
|
</Card>
|
|
|
|
|
|
|
2026-07-23 15:07:35 +08:00
|
|
|
|
<Card className="explore-article-detail queue-section" bordered>
|
|
|
|
|
|
<div className="explore-detail-toolbar">
|
|
|
|
|
|
<Title heading={5}>{selected.title}</Title>
|
|
|
|
|
|
<Space>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
aria-label={selected.status === 'read' ? '标记未读' : '标记已读'}
|
|
|
|
|
|
type={selected.status === 'read' ? 'primary' : 'text'}
|
|
|
|
|
|
icon={<IconCheckCircle />}
|
|
|
|
|
|
onClick={() => void updateSelected({ status: selected.status === 'read' ? 'unread' : 'read', starred: selected.starred })}
|
|
|
|
|
|
/>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
aria-label={selected.starred ? '取消收藏' : '收藏'}
|
|
|
|
|
|
type={selected.starred ? 'primary' : 'text'}
|
|
|
|
|
|
icon={<IconStar />}
|
|
|
|
|
|
onClick={() => void updateSelected({ status: selected.status, starred: !selected.starred })}
|
|
|
|
|
|
/>
|
2026-07-23 22:25:12 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
aria-label={`沉淀到项目${activeProjectName}`}
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
icon={<IconBook />}
|
|
|
|
|
|
loading={depositingItemID === selected.id}
|
|
|
|
|
|
onClick={() => void depositSelected()}
|
|
|
|
|
|
/>
|
2026-07-23 15:07:35 +08:00
|
|
|
|
{selected.url ? <Button type="text" icon={<IconLaunch />} href={selected.url} target="_blank" /> : null}
|
2026-07-22 15:39:57 +08:00
|
|
|
|
</Space>
|
2026-07-23 15:07:35 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<article className="explore-article-body">
|
|
|
|
|
|
<Space className="explore-article-meta" wrap>
|
|
|
|
|
|
<span className={`explore-source-logo small ${selectedSource.color}`}>{sourceInitial(selectedSource.name)}</span>
|
|
|
|
|
|
<Text type="secondary">{selectedSource.name}</Text>
|
|
|
|
|
|
<Text type="secondary">{itemTime(selected)}</Text>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
<Paragraph className="explore-article-content">{selected.content || selected.summary || '暂无正文'}</Paragraph>
|
|
|
|
|
|
</article>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Card className="queue-section" bordered>
|
|
|
|
|
|
<Empty description={sourceRecords.length === 0 ? '暂无数据源,请先添加数据源' : '暂无数据源文章'} />
|
2026-07-22 15:39:57 +08:00
|
|
|
|
</Card>
|
2026-07-23 15:07:35 +08:00
|
|
|
|
)}
|
|
|
|
|
|
</Spin>
|
2026-07-22 15:56:04 +08:00
|
|
|
|
|
|
|
|
|
|
<Modal
|
|
|
|
|
|
className="explore-source-modal"
|
|
|
|
|
|
title={sourceModalMode === 'edit' ? '编辑数据源' : '添加数据源'}
|
|
|
|
|
|
visible={sourceModalMode !== null}
|
|
|
|
|
|
okText="保存"
|
|
|
|
|
|
cancelText="取消"
|
2026-07-23 15:07:35 +08:00
|
|
|
|
confirmLoading={saving}
|
2026-07-22 15:56:04 +08:00
|
|
|
|
onCancel={() => setSourceModalMode(null)}
|
2026-07-23 15:07:35 +08:00
|
|
|
|
onOk={() => void saveSource()}
|
2026-07-22 15:56:04 +08:00
|
|
|
|
>
|
|
|
|
|
|
<Space direction="vertical" size={12} className="action-form">
|
2026-07-23 15:07:35 +08:00
|
|
|
|
{sourceError ? <Alert type="error" content={sourceError} /> : null}
|
2026-07-22 15:56:04 +08:00
|
|
|
|
<label>
|
|
|
|
|
|
<Text>数据源名称</Text>
|
|
|
|
|
|
<Input value={sourceDraft.name} placeholder="例如:行业资讯" onChange={(name) => setSourceDraft((current) => ({ ...current, name }))} />
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<label>
|
|
|
|
|
|
<Text>数据源类型</Text>
|
2026-07-23 22:25:12 +08:00
|
|
|
|
<Input value={sourceDraft.kind === 'rss' ? 'RSS 订阅' : '历史数据源(仅维护)'} disabled />
|
2026-07-22 15:56:04 +08:00
|
|
|
|
</label>
|
|
|
|
|
|
<label>
|
|
|
|
|
|
<Text>链接地址</Text>
|
2026-07-23 22:25:12 +08:00
|
|
|
|
<Input
|
|
|
|
|
|
value={sourceDraft.url}
|
|
|
|
|
|
disabled={Boolean(editingSource?.builtIn || (editingSource && editingSource.kind !== 'rss'))}
|
|
|
|
|
|
placeholder="https://example.com/feed"
|
|
|
|
|
|
onChange={(url) => setSourceDraft((current) => ({ ...current, url }))}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<label>
|
|
|
|
|
|
<Text>图标地址</Text>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
value={sourceDraft.iconUrl}
|
|
|
|
|
|
disabled={Boolean(editingSource?.builtIn || (editingSource && editingSource.kind !== 'rss'))}
|
|
|
|
|
|
placeholder="https://example.com/icon.png"
|
|
|
|
|
|
onChange={(iconUrl) => setSourceDraft((current) => ({ ...current, iconUrl }))}
|
|
|
|
|
|
/>
|
2026-07-22 15:56:04 +08:00
|
|
|
|
</label>
|
|
|
|
|
|
<label>
|
|
|
|
|
|
<Text>说明</Text>
|
|
|
|
|
|
<TextArea rows={4} value={sourceDraft.description} placeholder="数据源用途或内容范围" onChange={(description) => setSourceDraft((current) => ({ ...current, description }))} />
|
|
|
|
|
|
</label>
|
2026-07-23 15:07:35 +08:00
|
|
|
|
<label>
|
|
|
|
|
|
<Space>
|
|
|
|
|
|
<Switch checked={sourceDraft.enabled} onChange={(enabled) => setSourceDraft((current) => ({ ...current, enabled }))} />
|
|
|
|
|
|
<Text>启用采集</Text>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
</label>
|
2026-07-22 15:56:04 +08:00
|
|
|
|
</Space>
|
|
|
|
|
|
</Modal>
|
2026-07-21 00:46:09 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
2026-07-22 15:39:57 +08:00
|
|
|
|
|
2026-07-23 15:07:35 +08:00
|
|
|
|
function sourceByID(sources: DataSourceCard[], id: string): DataSourceCard {
|
2026-07-22 15:56:04 +08:00
|
|
|
|
return sources.find((source) => source.id === id) ?? sources[0]
|
2026-07-22 15:39:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-23 15:07:35 +08:00
|
|
|
|
function sourceIcon(kind: DatasetSourceKind) {
|
2026-07-22 15:56:04 +08:00
|
|
|
|
if (kind === 'rss') return <IconStorage />
|
|
|
|
|
|
if (kind === 'manual') return <IconCompass />
|
|
|
|
|
|
return <IconLink />
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-23 15:07:35 +08:00
|
|
|
|
function sourceColor(kind: DatasetSourceKind) {
|
2026-07-22 15:56:04 +08:00
|
|
|
|
if (kind === 'rss') return 'orange'
|
|
|
|
|
|
if (kind === 'manual') return 'green'
|
|
|
|
|
|
return 'blue'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-22 15:39:57 +08:00
|
|
|
|
function sourceInitial(name: string) {
|
2026-07-23 15:07:35 +08:00
|
|
|
|
return Array.from(name.trim())[0] || '源'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function itemTime(item: DatasetItemDTO) {
|
|
|
|
|
|
const value = item.publishedAt ?? item.createdAt
|
|
|
|
|
|
const parsed = new Date(value)
|
|
|
|
|
|
if (Number.isNaN(parsed.getTime())) return ''
|
|
|
|
|
|
return new Intl.DateTimeFormat('zh-CN', { dateStyle: 'medium' }).format(parsed)
|
2026-07-22 15:39:57 +08:00
|
|
|
|
}
|
2026-07-23 22:25:12 +08:00
|
|
|
|
|
|
|
|
|
|
function sourceSubtitle(source: DatasetSourceDTO) {
|
|
|
|
|
|
if (!source.lastSyncedAt) return `${source.itemCount} 条`
|
|
|
|
|
|
const parsed = new Date(source.lastSyncedAt)
|
|
|
|
|
|
if (Number.isNaN(parsed.getTime())) return `${source.itemCount} 条`
|
|
|
|
|
|
return `${source.itemCount} 条 · ${new Intl.DateTimeFormat('zh-CN', { dateStyle: 'short', timeStyle: 'short' }).format(parsed)}`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function waitForDatasetRuns(
|
|
|
|
|
|
queued: DatasetCronDTO[],
|
|
|
|
|
|
listRuns: (signal?: AbortSignal) => Promise<DatasetCronDTO[]>,
|
|
|
|
|
|
) {
|
|
|
|
|
|
const queuedIDs = new Set(queued.map((run) => run.id))
|
|
|
|
|
|
const deadline = Date.now() + 10 * 60 * 1000
|
|
|
|
|
|
while (Date.now() < deadline) {
|
|
|
|
|
|
const runs = (await listRuns()).filter((run) => queuedIDs.has(run.id))
|
|
|
|
|
|
if (runs.length === queuedIDs.size && runs.every((run) => run.status === 'completed' || run.status === 'failed')) {
|
|
|
|
|
|
return runs
|
|
|
|
|
|
}
|
|
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 1500))
|
|
|
|
|
|
}
|
|
|
|
|
|
throw new Error('采集任务仍在后台运行,请稍后刷新')
|
|
|
|
|
|
}
|