refactor(web): consume api v1 contracts

This commit is contained in:
2026-07-21 16:29:42 +08:00
parent 80bec26839
commit c56ada3708
8 changed files with 311 additions and 149 deletions

View File

@@ -1,20 +1,20 @@
import { IconClockCircle, IconEmail, IconFile, IconHome, IconLink, IconList, IconRobot, IconUserGroup } from '@arco-design/web-react/icon'
import type {
BackendAISession,
BackendChannel,
BackendCronPlan,
BackendInboxMessage,
BackendNoteSource,
BackendProjectWorkspace,
BackendTask,
ProjectWorkspaceDTO,
WorkspaceAISessionDTO,
WorkspaceChannelDTO,
WorkspaceCronPlanDTO,
WorkspaceInboxDTO,
WorkspaceNoteSourceDTO,
WorkspaceTaskDTO,
} from './projects'
import type { AISession, ChannelKey, CronJob, InboxItem, NoteSource, Project, ProjectChannel, ProjectWorkspace, TaskItem } from '../pages/projects/project-types'
const projectColors = ['#165DFF', '#00B42A', '#722ED1', '#FF7D00', '#14C9C9', '#F53F3F']
export function mapWorkspace(payload: BackendProjectWorkspace, index = 0): ProjectWorkspace {
export function mapWorkspace(payload: ProjectWorkspaceDTO, index = 0): ProjectWorkspace {
const project: Project = {
id: String(payload.project.id),
id: payload.project.id,
name: payload.project.name,
identifier: payload.project.identifier ?? '',
icon: payload.project.icon ?? '',
@@ -29,7 +29,7 @@ export function mapWorkspace(payload: BackendProjectWorkspace, index = 0): Proje
return {
project,
channels: payload.channels.filter((channel) => channel.type !== 'inbox').map(mapChannel),
tags: payload.tags.map((tag) => (tag === 'all' ? '全部' : tag)),
tags: payload.tags.map((tag) => tag.name),
recentSessions: payload.recentSessions.map(mapAISession),
inbox: payload.inbox.map(mapInbox),
tasks: payload.tasks.map(mapTask),
@@ -55,7 +55,7 @@ function projectColor(background: string, index: number) {
return projectColors[index % projectColors.length]
}
function mapChannel(channel: BackendChannel): ProjectChannel {
function mapChannel(channel: WorkspaceChannelDTO): ProjectChannel {
return {
id: channel.id,
key: mapChannelKey(channel.type, channel.id),
@@ -86,7 +86,7 @@ function mapChannelKey(type: string, id = ''): ChannelKey {
}
}
function channelLabel(channel: BackendChannel) {
function channelLabel(channel: WorkspaceChannelDTO) {
switch (channel.type) {
case 'overview':
return '概况'
@@ -105,7 +105,7 @@ function channelLabel(channel: BackendChannel) {
}
}
function channelIcon(channel: BackendChannel) {
function channelIcon(channel: WorkspaceChannelDTO) {
switch (channel.type) {
case 'overview':
return <IconHome />
@@ -124,36 +124,36 @@ function channelIcon(channel: BackendChannel) {
}
}
function mapInbox(item: BackendInboxMessage): InboxItem {
function mapInbox(item: WorkspaceInboxDTO): InboxItem {
return {
id: item.id,
title: item.title,
meta: `来源:${item.source}`,
owner: '系统',
time: item.time,
time: formatBackendDate(item.time),
tag: item.tag || item.status,
summary: item.summary,
status: item.status,
}
}
function mapTask(task: BackendTask): TaskItem {
function mapTask(task: WorkspaceTaskDTO): TaskItem {
return {
id: task.id,
title: task.title,
owner: task.owner,
progress: task.completed ? '100%' : '60%',
due: task.due || '未设置',
createdAt: formatCreatedAt(task.createdAt),
completedAt: task.completedAt ? formatCreatedAt(task.completedAt) : '',
duration: task.duration || '',
progress: task.completed ? '100%' : '',
due: task.due ? formatBackendDate(task.due) : '未设置',
createdAt: formatBackendDate(task.createdAt),
completedAt: task.completedAt ? formatBackendDate(task.completedAt) : '',
duration: '',
tag: task.tag || '',
summary: task.summary,
completed: task.completed,
}
}
function formatCreatedAt(value: string) {
function formatBackendDate(value: string) {
const date = parseBackendDate(value)
if (!date) return '未知时间'
@@ -184,35 +184,35 @@ function pad(value: number) {
return String(value).padStart(2, '0')
}
function mapAISession(session: BackendAISession): AISession {
function mapAISession(session: WorkspaceAISessionDTO): AISession {
return {
id: session.id,
title: session.title,
summary: session.summary,
owner: 'AI',
time: session.updatedAt,
time: formatBackendDate(session.updatedAt),
}
}
function mapNoteSource(note: BackendNoteSource): NoteSource {
function mapNoteSource(note: WorkspaceNoteSourceDTO): NoteSource {
return {
id: note.id,
title: note.title,
type: note.kind === 'note' ? '笔记' : note.source,
updated: note.updatedAt,
updated: formatBackendDate(note.updatedAt),
owner: note.source,
source: note.source,
}
}
function mapCronPlan(plan: BackendCronPlan): CronJob {
function mapCronPlan(plan: WorkspaceCronPlanDTO): CronJob {
return {
id: plan.id,
name: plan.title,
expr: plan.schedule,
status: plan.enabled ? '运行中' : '暂停',
lastRun: plan.lastResult,
nextRun: plan.nextRun || '暂停中',
nextRun: plan.nextRun ? formatBackendDate(plan.nextRun) : '暂停中',
owner: plan.owner,
enabled: plan.enabled,
}