feat(datasource): implement data source management functionality
- Added a new API for managing data sources, including CRUD operations and connection validation. - Introduced UI components for data source settings, sync logs, and editor dialog, enhancing user experience in managing external data sources. - Updated localization files to support new data source features in multiple languages. - Implemented cron expression humanization for better scheduling visibility. - Enhanced knowledge base editor to include data source management options.
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
import { get, post, put, del } from '../../utils/request'
|
||||
|
||||
// --- Types ---
|
||||
|
||||
export interface DataSource {
|
||||
id: string
|
||||
tenant_id: number
|
||||
knowledge_base_id: string
|
||||
name: string
|
||||
type: string
|
||||
config: any
|
||||
sync_schedule: string
|
||||
sync_mode: 'incremental' | 'full'
|
||||
status: 'active' | 'paused' | 'error'
|
||||
conflict_strategy: 'overwrite' | 'skip'
|
||||
sync_deletions: boolean
|
||||
last_sync_at: string | null
|
||||
last_sync_result: any
|
||||
error_message: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
latest_sync_log?: SyncLog
|
||||
}
|
||||
|
||||
export interface SyncLog {
|
||||
id: string
|
||||
data_source_id: string
|
||||
status: 'running' | 'success' | 'partial' | 'failed' | 'canceled'
|
||||
started_at: string
|
||||
finished_at: string | null
|
||||
items_total: number
|
||||
items_created: number
|
||||
items_updated: number
|
||||
items_deleted: number
|
||||
items_skipped: number
|
||||
items_failed: number
|
||||
error_message: string
|
||||
}
|
||||
|
||||
export interface ConnectorMeta {
|
||||
type: string
|
||||
name: string
|
||||
description: string
|
||||
icon: string
|
||||
priority: number
|
||||
auth_type: string
|
||||
capabilities: string[]
|
||||
}
|
||||
|
||||
export interface Resource {
|
||||
external_id: string
|
||||
name: string
|
||||
type: string
|
||||
description: string
|
||||
url: string
|
||||
parent_id?: string
|
||||
}
|
||||
|
||||
// --- API calls ---
|
||||
|
||||
export function getConnectorTypes() {
|
||||
return get('/api/v1/datasource/types')
|
||||
}
|
||||
|
||||
export function listDataSources(kbId: string) {
|
||||
return get(`/api/v1/datasource?kb_id=${encodeURIComponent(kbId)}`)
|
||||
}
|
||||
|
||||
export function getDataSource(id: string) {
|
||||
return get(`/api/v1/datasource/${id}`)
|
||||
}
|
||||
|
||||
export function createDataSource(data: Partial<DataSource>) {
|
||||
return post('/api/v1/datasource', data)
|
||||
}
|
||||
|
||||
export function updateDataSource(id: string, data: Partial<DataSource>) {
|
||||
return put(`/api/v1/datasource/${id}`, data)
|
||||
}
|
||||
|
||||
export function deleteDataSource(id: string) {
|
||||
return del(`/api/v1/datasource/${id}`)
|
||||
}
|
||||
|
||||
export function validateConnection(id: string) {
|
||||
return post(`/api/v1/datasource/${id}/validate`, {})
|
||||
}
|
||||
|
||||
// Validate credentials without persisting (for "Test Connection" during creation)
|
||||
export function validateCredentials(type: string, credentials: Record<string, any>) {
|
||||
return post('/api/v1/datasource/validate-credentials', { type, credentials })
|
||||
}
|
||||
|
||||
export function listResources(id: string) {
|
||||
return get(`/api/v1/datasource/${id}/resources`)
|
||||
}
|
||||
|
||||
export function triggerSync(id: string) {
|
||||
return post(`/api/v1/datasource/${id}/sync`, {})
|
||||
}
|
||||
|
||||
export function pauseDataSource(id: string) {
|
||||
return post(`/api/v1/datasource/${id}/pause`, {})
|
||||
}
|
||||
|
||||
export function resumeDataSource(id: string) {
|
||||
return post(`/api/v1/datasource/${id}/resume`, {})
|
||||
}
|
||||
|
||||
export function getSyncLogs(id: string, limit = 20, offset = 0) {
|
||||
return get(`/api/v1/datasource/${id}/logs?limit=${limit}&offset=${offset}`)
|
||||
}
|
||||
@@ -272,7 +272,7 @@ defineExpose({ loadShares })
|
||||
margin-bottom: 16px;
|
||||
.shares-title {
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
@@ -1432,6 +1432,7 @@ export default {
|
||||
faq: 'FAQ Settings',
|
||||
graph: 'Knowledge Graph',
|
||||
multimodal: 'Multimodal',
|
||||
datasource: 'Data Sources',
|
||||
share: 'Sharing'
|
||||
},
|
||||
basic: {
|
||||
@@ -3344,4 +3345,166 @@ export default {
|
||||
yesterday: 'Yesterday',
|
||||
daysAgo: '{days} days ago',
|
||||
},
|
||||
datasource: {
|
||||
title: 'Data Sources',
|
||||
description: 'Configure external data sources to sync content into this knowledge base',
|
||||
add: 'Add Data Source',
|
||||
addFirst: 'Add your first data source',
|
||||
empty: 'No data sources configured',
|
||||
edit: 'Edit',
|
||||
delete: 'Delete',
|
||||
deleteConfirm: 'Delete this data source? Synced knowledge will not be removed.',
|
||||
deleteSuccess: 'Data source deleted',
|
||||
deleteFailed: 'Failed to delete',
|
||||
syncNow: 'Sync Now',
|
||||
syncTriggered: 'Sync task submitted',
|
||||
syncFailed: 'Failed to trigger sync',
|
||||
pause: 'Pause',
|
||||
resume: 'Resume',
|
||||
paused: 'Paused',
|
||||
resumed: 'Resumed',
|
||||
pauseFailed: 'Failed to pause',
|
||||
logs: 'Logs',
|
||||
lastSync: 'Last sync',
|
||||
lastStatus: 'Result',
|
||||
schedule: 'Schedule',
|
||||
syncModeLabel: 'Sync mode',
|
||||
syncMode: {
|
||||
incremental: 'Incremental',
|
||||
full: 'Full',
|
||||
},
|
||||
status: {
|
||||
active: 'Connected',
|
||||
paused: 'Paused',
|
||||
error: 'Error',
|
||||
},
|
||||
createTitle: 'Add Data Source',
|
||||
editTitle: 'Edit Data Source',
|
||||
nameLabel: 'Name',
|
||||
namePlaceholder: 'Enter data source name',
|
||||
testConnection: 'Test Connection',
|
||||
testSuccess: 'Connection successful',
|
||||
testFailed: 'Connection failed',
|
||||
connected: 'Connected',
|
||||
connectionFailed: 'Connection failed',
|
||||
isRequired: 'is required',
|
||||
resourceHint: 'Select the spaces or folders to sync',
|
||||
resourceLoadFailed: 'Failed to load resources',
|
||||
noResources: 'No wiki spaces found',
|
||||
noResourcesDesc: 'The app needs wiki access via a group chat to fetch content',
|
||||
retryLoadResources: 'Retry',
|
||||
guideStep1: 'Create a group chat in Feishu, then add your app as a bot in the group settings',
|
||||
guideStep2: 'Open wiki "Settings" > "Member Settings" > "Add Member", search for the group chat and add it',
|
||||
guideStep3: 'Ensure the group chat role is at least "Can Read", then come back and click Retry',
|
||||
permissionDocLink: 'View Feishu wiki permission docs',
|
||||
syncScheduleLabel: 'Sync schedule',
|
||||
conflictLabel: 'Conflict strategy',
|
||||
conflict: {
|
||||
overwrite: 'Overwrite',
|
||||
skip: 'Skip existing',
|
||||
},
|
||||
syncDeletions: 'Sync deletions (remove knowledge when deleted at source)',
|
||||
createAndSync: 'Create & Sync Now',
|
||||
createSuccess: 'Data source created',
|
||||
updateSuccess: 'Data source updated',
|
||||
saveFailed: 'Failed to save',
|
||||
step: {
|
||||
selectType: 'Select Type',
|
||||
credentials: 'Credentials',
|
||||
resources: 'Resources',
|
||||
strategy: 'Strategy',
|
||||
},
|
||||
syncHistory: 'Sync History',
|
||||
noLogs: 'No sync records yet',
|
||||
logStatus: {
|
||||
running: 'Syncing',
|
||||
success: 'Success',
|
||||
partial: 'Partial',
|
||||
failed: 'Failed',
|
||||
canceled: 'Canceled',
|
||||
},
|
||||
logMetric: {
|
||||
total: 'Total',
|
||||
created: 'created',
|
||||
updated: 'updated',
|
||||
deleted: 'deleted',
|
||||
skipped: 'skipped',
|
||||
failed: 'failed',
|
||||
},
|
||||
logSummary: {
|
||||
total: 'Runs',
|
||||
success: 'Success',
|
||||
failed: 'Failed',
|
||||
items: 'Items',
|
||||
},
|
||||
logLatest: 'Latest',
|
||||
logDetail: {
|
||||
startTime: 'Started',
|
||||
endTime: 'Finished',
|
||||
duration: 'Duration',
|
||||
},
|
||||
connector: {
|
||||
feishu: 'Feishu',
|
||||
notion: 'Notion',
|
||||
yuque: 'Yuque',
|
||||
wecom_doc: 'WeCom Docs',
|
||||
},
|
||||
connectorDesc: {
|
||||
feishu: 'Sync documents, spreadsheets and files from Feishu Wiki',
|
||||
notion: 'Sync pages and databases from Notion',
|
||||
yuque: 'Sync documents from Yuque knowledge bases',
|
||||
wecom_doc: 'Sync documents from WeCom Docs',
|
||||
},
|
||||
field: {
|
||||
appId: 'App ID',
|
||||
appSecret: 'App Secret',
|
||||
integrationToken: 'Integration Token',
|
||||
apiToken: 'API Token',
|
||||
corpId: 'Corp ID',
|
||||
corpSecret: 'Corp Secret',
|
||||
},
|
||||
comingSoon: 'Coming soon',
|
||||
docHint: 'Get credentials at:',
|
||||
pleaseTestFirst: 'Please test connection first',
|
||||
prereqTitle: 'Complete these steps before connecting (all required)',
|
||||
prereqBarText: 'First time? Click to see Feishu app setup guide',
|
||||
prereqBotBrief: 'Add "Bot" capability to your app',
|
||||
prereqBotDesc: 'Open Platform > Add App Capability > Bot > create version and publish',
|
||||
prereqBotLabel: '1. Add "Bot" capability to your app (otherwise the app won\'t appear in wiki member search):',
|
||||
prereqBotStep1: 'Open your app in Feishu Open Platform, click "Add App Capability" in the left menu',
|
||||
prereqBotStep2: 'Select "Bot" and confirm',
|
||||
prereqBotStep3: 'Create a new version and publish (or test in your test organization)',
|
||||
prereqPermBrief: 'Grant API permissions',
|
||||
prereqPermLabel: '2. Grant these API permissions:',
|
||||
prereqOpenConsole: 'Open Feishu Developer Console',
|
||||
prereqMemberBrief: 'Add app to wiki via group chat',
|
||||
prereqMemberDesc: 'Create group chat > add app as bot > add group chat as wiki member',
|
||||
prereqMemberLabel: '3. Add the app to a wiki space via group chat (wiki cannot search for apps directly):',
|
||||
back: 'Back',
|
||||
next: 'Next',
|
||||
save: 'Save',
|
||||
schedule30min: 'Every 30 min',
|
||||
schedule1h: 'Every hour',
|
||||
schedule6h: 'Every 6 hours',
|
||||
schedule12h: 'Every 12 hours',
|
||||
schedule24h: 'Daily',
|
||||
scheduleHuman: {
|
||||
'30min': 'Every 30 min',
|
||||
'1h': 'Hourly',
|
||||
'6h': 'Every 6 hours',
|
||||
'12h': 'Every 12 hours',
|
||||
'24h': 'Daily',
|
||||
},
|
||||
addCard: 'Add Data Source',
|
||||
wikiSpace: 'Wiki Space',
|
||||
neverSynced: 'Never synced',
|
||||
justNow: 'Just now',
|
||||
minutesAgo: '{n}m ago',
|
||||
hoursAgo: '{n}h ago',
|
||||
daysAgo: '{n}d ago',
|
||||
syncResultCreated: '+{n}',
|
||||
syncResultUpdated: '~{n}',
|
||||
syncResultDeleted: '-{n}',
|
||||
moreActions: 'More',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1915,6 +1915,7 @@ export default {
|
||||
graph: "지식 그래프",
|
||||
share: "공유관리",
|
||||
storage: "스토리지 엔진",
|
||||
datasource: "데이터 소스",
|
||||
},
|
||||
basic: {
|
||||
title: "기본 정보",
|
||||
@@ -3390,4 +3391,124 @@ export default {
|
||||
yesterday: "어제",
|
||||
daysAgo: "{days}일 전",
|
||||
},
|
||||
datasource: {
|
||||
title: "데이터 소스 관리",
|
||||
description: "외부 데이터 소스를 구성하여 콘텐츠를 지식베이스에 자동 동기화",
|
||||
add: "데이터 소스 추가",
|
||||
addFirst: "첫 번째 데이터 소스 추가",
|
||||
empty: "구성된 데이터 소스가 없습니다",
|
||||
edit: "편집",
|
||||
delete: "삭제",
|
||||
deleteConfirm: "이 데이터 소스를 삭제하시겠습니까? 동기화된 지식은 삭제되지 않습니다.",
|
||||
deleteSuccess: "데이터 소스가 삭제되었습니다",
|
||||
deleteFailed: "삭제 실패",
|
||||
syncNow: "지금 동기화",
|
||||
syncTriggered: "동기화 작업이 제출되었습니다",
|
||||
syncFailed: "동기화 트리거 실패",
|
||||
pause: "일시정지",
|
||||
resume: "재개",
|
||||
paused: "일시정지됨",
|
||||
resumed: "재개됨",
|
||||
pauseFailed: "일시정지 실패",
|
||||
logs: "로그",
|
||||
lastSync: "마지막 동기화",
|
||||
lastStatus: "결과",
|
||||
schedule: "동기화 주기",
|
||||
syncModeLabel: "동기화 모드",
|
||||
syncMode: {
|
||||
incremental: "증분 동기화",
|
||||
full: "전체 동기화",
|
||||
},
|
||||
status: {
|
||||
active: "연결됨",
|
||||
paused: "일시정지",
|
||||
error: "오류",
|
||||
},
|
||||
createTitle: "데이터 소스 추가",
|
||||
editTitle: "데이터 소스 편집",
|
||||
nameLabel: "이름",
|
||||
namePlaceholder: "데이터 소스 이름 입력",
|
||||
testConnection: "연결 테스트",
|
||||
testSuccess: "연결 성공",
|
||||
testFailed: "연결 실패",
|
||||
connected: "연결됨",
|
||||
connectionFailed: "연결 실패",
|
||||
isRequired: "은(는) 필수입니다",
|
||||
resourceHint: "동기화할 공간/폴더를 선택하세요",
|
||||
resourceLoadFailed: "리소스 목록 로드 실패",
|
||||
noResources: "동기화 가능한 위키 공간을 찾을 수 없습니다",
|
||||
noResourcesHint: "먼저 데이터 소스를 저장하고 권한 설정을 확인하세요",
|
||||
permissionHint: "앱이 위키 공간의 멤버로 추가되어야 콘텐츠에 접근할 수 있습니다:",
|
||||
permissionStep1: "페이슈를 열고 동기화할 위키 공간으로 이동",
|
||||
permissionStep2: "오른쪽 상단 '...' > '설정' > '멤버 관리' 클릭",
|
||||
permissionStep3: "페이슈 앱을 검색하여 위키 공간 멤버로 추가",
|
||||
permissionDocLink: "페이슈 위키 권한 설정 문서 보기",
|
||||
syncScheduleLabel: "동기화 주기",
|
||||
conflictLabel: "충돌 전략",
|
||||
conflict: {
|
||||
overwrite: "덮어쓰기",
|
||||
skip: "기존 항목 건너뛰기",
|
||||
},
|
||||
syncDeletions: "삭제 동기화 (소스에서 삭제 시 지식베이스에서도 삭제)",
|
||||
createAndSync: "생성 후 즉시 동기화",
|
||||
createSuccess: "데이터 소스가 생성되었습니다",
|
||||
updateSuccess: "데이터 소스가 업데이트되었습니다",
|
||||
saveFailed: "저장 실패",
|
||||
step: {
|
||||
selectType: "유형 선택",
|
||||
credentials: "인증 정보",
|
||||
resources: "리소스 선택",
|
||||
strategy: "동기화 전략",
|
||||
},
|
||||
syncHistory: "동기화 이력",
|
||||
noLogs: "동기화 기록이 없습니다",
|
||||
logStatus: {
|
||||
running: "동기화 중",
|
||||
success: "성공",
|
||||
partial: "부분 성공",
|
||||
failed: "실패",
|
||||
canceled: "취소됨",
|
||||
},
|
||||
logMetric: {
|
||||
total: "총계",
|
||||
failed: "실패",
|
||||
},
|
||||
connector: {
|
||||
feishu: "페이슈 (Feishu)",
|
||||
notion: "Notion",
|
||||
confluence: "Confluence",
|
||||
yuque: "위큐 (Yuque)",
|
||||
github: "GitHub",
|
||||
web_crawler: "웹 크롤러",
|
||||
},
|
||||
connectorDesc: {
|
||||
feishu: "페이슈 위키에서 문서, 스프레드시트, 파일 동기화",
|
||||
notion: "Notion에서 페이지 및 데이터베이스 동기화",
|
||||
confluence: "Confluence에서 스페이스 및 페이지 동기화",
|
||||
yuque: "위큐 지식베이스에서 문서 동기화",
|
||||
github: "GitHub 리포지토리에서 문서 및 위키 동기화",
|
||||
web_crawler: "사이트맵을 통해 웹사이트 크롤링",
|
||||
},
|
||||
field: {
|
||||
appId: "App ID",
|
||||
appSecret: "App Secret",
|
||||
integrationToken: "Integration Token",
|
||||
baseUrl: "Base URL",
|
||||
email: "이메일",
|
||||
apiToken: "API Token",
|
||||
personalToken: "Personal Access Token",
|
||||
sitemapUrl: "사이트맵 URL",
|
||||
},
|
||||
comingSoon: "곧 지원 예정",
|
||||
docHint: "다음에서 인증 정보를 받으세요:",
|
||||
pleaseTestFirst: "먼저 연결을 테스트하세요",
|
||||
back: "이전",
|
||||
next: "다음",
|
||||
save: "저장",
|
||||
schedule30min: "30분마다",
|
||||
schedule1h: "매시간",
|
||||
schedule6h: "6시간마다",
|
||||
schedule12h: "12시간마다",
|
||||
schedule24h: "매일",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1600,6 +1600,7 @@ export default {
|
||||
faq: 'FAQ настройки',
|
||||
graph: 'Граф знаний',
|
||||
storage: 'Storage Engine',
|
||||
datasource: 'Источники данных',
|
||||
share: 'Sharing'
|
||||
},
|
||||
basic: {
|
||||
@@ -3296,5 +3297,125 @@ export default {
|
||||
sharedKBs: ' knowledge bases',
|
||||
sharedAgents: ' agents'
|
||||
}
|
||||
}
|
||||
},
|
||||
datasource: {
|
||||
title: 'Источники данных',
|
||||
description: 'Настройте внешние источники данных для автоматической синхронизации контента',
|
||||
add: 'Добавить источник',
|
||||
addFirst: 'Добавить первый источник данных',
|
||||
empty: 'Источники данных не настроены',
|
||||
edit: 'Редактировать',
|
||||
delete: 'Удалить',
|
||||
deleteConfirm: 'Удалить этот источник данных? Синхронизированные знания не будут удалены.',
|
||||
deleteSuccess: 'Источник данных удалён',
|
||||
deleteFailed: 'Не удалось удалить',
|
||||
syncNow: 'Синхронизировать',
|
||||
syncTriggered: 'Задача синхронизации отправлена',
|
||||
syncFailed: 'Не удалось запустить синхронизацию',
|
||||
pause: 'Пауза',
|
||||
resume: 'Возобновить',
|
||||
paused: 'Приостановлено',
|
||||
resumed: 'Возобновлено',
|
||||
pauseFailed: 'Не удалось приостановить',
|
||||
logs: 'Журнал',
|
||||
lastSync: 'Последняя синхронизация',
|
||||
lastStatus: 'Результат',
|
||||
schedule: 'Расписание',
|
||||
syncModeLabel: 'Режим синхронизации',
|
||||
syncMode: {
|
||||
incremental: 'Инкрементная',
|
||||
full: 'Полная',
|
||||
},
|
||||
status: {
|
||||
active: 'Подключено',
|
||||
paused: 'Приостановлено',
|
||||
error: 'Ошибка',
|
||||
},
|
||||
createTitle: 'Добавить источник данных',
|
||||
editTitle: 'Редактировать источник данных',
|
||||
nameLabel: 'Название',
|
||||
namePlaceholder: 'Введите название источника данных',
|
||||
testConnection: 'Проверить подключение',
|
||||
testSuccess: 'Подключение успешно',
|
||||
testFailed: 'Подключение не удалось',
|
||||
connected: 'Подключено',
|
||||
connectionFailed: 'Подключение не удалось',
|
||||
isRequired: 'обязательно для заполнения',
|
||||
resourceHint: 'Выберите пространства или папки для синхронизации',
|
||||
resourceLoadFailed: 'Не удалось загрузить список ресурсов',
|
||||
noResources: 'Пространства вики не найдены',
|
||||
noResourcesHint: 'Сначала сохраните источник данных и проверьте права доступа',
|
||||
permissionHint: 'Приложение должно быть добавлено как участник пространства вики для доступа к контенту:',
|
||||
permissionStep1: 'Откройте Feishu и перейдите в пространство вики для синхронизации',
|
||||
permissionStep2: 'Нажмите "..." > "Настройки" > "Управление участниками"',
|
||||
permissionStep3: 'Найдите и добавьте приложение Feishu как участника пространства',
|
||||
permissionDocLink: 'Документация по настройке прав доступа',
|
||||
syncScheduleLabel: 'Расписание синхронизации',
|
||||
conflictLabel: 'Стратегия конфликтов',
|
||||
conflict: {
|
||||
overwrite: 'Перезаписать',
|
||||
skip: 'Пропустить существующие',
|
||||
},
|
||||
syncDeletions: 'Синхронизировать удаления (удалять знания при удалении в источнике)',
|
||||
createAndSync: 'Создать и синхронизировать',
|
||||
createSuccess: 'Источник данных создан',
|
||||
updateSuccess: 'Источник данных обновлён',
|
||||
saveFailed: 'Не удалось сохранить',
|
||||
step: {
|
||||
selectType: 'Выберите тип',
|
||||
credentials: 'Учётные данные',
|
||||
resources: 'Ресурсы',
|
||||
strategy: 'Стратегия',
|
||||
},
|
||||
syncHistory: 'История синхронизации',
|
||||
noLogs: 'Нет записей синхронизации',
|
||||
logStatus: {
|
||||
running: 'Синхронизация',
|
||||
success: 'Успешно',
|
||||
partial: 'Частично',
|
||||
failed: 'Ошибка',
|
||||
canceled: 'Отменено',
|
||||
},
|
||||
logMetric: {
|
||||
total: 'Всего',
|
||||
failed: 'ошибок',
|
||||
},
|
||||
connector: {
|
||||
feishu: 'Feishu (Фэйшу)',
|
||||
notion: 'Notion',
|
||||
confluence: 'Confluence',
|
||||
yuque: 'Yuque (Юйцюэ)',
|
||||
github: 'GitHub',
|
||||
web_crawler: 'Веб-краулер',
|
||||
},
|
||||
connectorDesc: {
|
||||
feishu: 'Синхронизация документов, таблиц и файлов из Feishu Wiki',
|
||||
notion: 'Синхронизация страниц и баз данных из Notion',
|
||||
confluence: 'Синхронизация пространств и страниц из Confluence',
|
||||
yuque: 'Синхронизация документов из баз знаний Yuque',
|
||||
github: 'Синхронизация документов и вики из репозиториев GitHub',
|
||||
web_crawler: 'Сканирование веб-сайтов через Sitemap',
|
||||
},
|
||||
field: {
|
||||
appId: 'App ID',
|
||||
appSecret: 'App Secret',
|
||||
integrationToken: 'Integration Token',
|
||||
baseUrl: 'Base URL',
|
||||
email: 'Email',
|
||||
apiToken: 'API Token',
|
||||
personalToken: 'Personal Access Token',
|
||||
sitemapUrl: 'Sitemap URL',
|
||||
},
|
||||
comingSoon: 'Скоро',
|
||||
docHint: 'Получить учётные данные можно здесь:',
|
||||
pleaseTestFirst: 'Сначала проверьте подключение',
|
||||
back: 'Назад',
|
||||
next: 'Далее',
|
||||
save: 'Сохранить',
|
||||
schedule30min: 'Каждые 30 мин',
|
||||
schedule1h: 'Каждый час',
|
||||
schedule6h: 'Каждые 6 часов',
|
||||
schedule12h: 'Каждые 12 часов',
|
||||
schedule24h: 'Ежедневно',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1904,6 +1904,7 @@ export default {
|
||||
faq: "FAQ 设置",
|
||||
graph: "知识图谱",
|
||||
multimodal: "多模态",
|
||||
datasource: "数据源",
|
||||
share: "共享管理",
|
||||
},
|
||||
basic: {
|
||||
@@ -3342,4 +3343,166 @@ export default {
|
||||
yesterday: "昨天",
|
||||
daysAgo: "{days} 天前",
|
||||
},
|
||||
datasource: {
|
||||
title: "数据源管理",
|
||||
description: "配置外部数据源,自动同步内容到知识库",
|
||||
add: "添加数据源",
|
||||
addFirst: "添加第一个数据源",
|
||||
empty: "暂无数据源",
|
||||
edit: "编辑",
|
||||
delete: "删除",
|
||||
deleteConfirm: "确定删除该数据源?同步的知识不会被删除。",
|
||||
deleteSuccess: "数据源已删除",
|
||||
deleteFailed: "删除失败",
|
||||
syncNow: "立即同步",
|
||||
syncTriggered: "同步任务已提交",
|
||||
syncFailed: "同步触发失败",
|
||||
pause: "暂停",
|
||||
resume: "恢复",
|
||||
paused: "已暂停",
|
||||
resumed: "已恢复",
|
||||
pauseFailed: "暂停失败",
|
||||
logs: "日志",
|
||||
lastSync: "上次同步",
|
||||
lastStatus: "同步结果",
|
||||
schedule: "同步频率",
|
||||
syncModeLabel: "同步模式",
|
||||
syncMode: {
|
||||
incremental: "增量同步",
|
||||
full: "全量同步",
|
||||
},
|
||||
status: {
|
||||
active: "已连接",
|
||||
paused: "已暂停",
|
||||
error: "异常",
|
||||
},
|
||||
createTitle: "添加数据源",
|
||||
editTitle: "编辑数据源",
|
||||
nameLabel: "名称",
|
||||
namePlaceholder: "输入数据源名称",
|
||||
testConnection: "测试连接",
|
||||
testSuccess: "连接成功",
|
||||
testFailed: "连接失败",
|
||||
connected: "已连接",
|
||||
connectionFailed: "连接失败",
|
||||
isRequired: "为必填项",
|
||||
resourceHint: "选择要同步的内容空间/文件夹",
|
||||
resourceLoadFailed: "加载资源列表失败",
|
||||
noResources: "未找到可同步的知识库空间",
|
||||
noResourcesDesc: "应用需要通过群聊获得知识库访问权限才能拉取内容",
|
||||
retryLoadResources: "重新加载",
|
||||
guideStep1: "在飞书中创建一个群聊,在群设置「群机器人」中添加你的应用",
|
||||
guideStep2: "打开知识库「设置」→「成员设置」→ 添加成员,搜索该群聊名称并添加",
|
||||
guideStep3: "确保群聊角色至少为「可阅读」,然后回到这里点重新加载",
|
||||
permissionDocLink: "查看飞书知识库权限配置文档",
|
||||
syncScheduleLabel: "同步频率",
|
||||
conflictLabel: "冲突策略",
|
||||
conflict: {
|
||||
overwrite: "覆盖更新",
|
||||
skip: "跳过已存在",
|
||||
},
|
||||
syncDeletions: "同步删除(源端删除时同步删除知识库中的条目)",
|
||||
createAndSync: "创建并立即同步",
|
||||
createSuccess: "数据源创建成功",
|
||||
updateSuccess: "数据源更新成功",
|
||||
saveFailed: "保存失败",
|
||||
step: {
|
||||
selectType: "选择类型",
|
||||
credentials: "配置凭证",
|
||||
resources: "选择范围",
|
||||
strategy: "同步策略",
|
||||
},
|
||||
syncHistory: "同步历史",
|
||||
noLogs: "暂无同步记录",
|
||||
logStatus: {
|
||||
running: "同步中",
|
||||
success: "成功",
|
||||
partial: "部分成功",
|
||||
failed: "失败",
|
||||
canceled: "已取消",
|
||||
},
|
||||
logMetric: {
|
||||
total: "总计",
|
||||
created: "新增",
|
||||
updated: "更新",
|
||||
deleted: "删除",
|
||||
skipped: "跳过",
|
||||
failed: "失败",
|
||||
},
|
||||
logSummary: {
|
||||
total: "总次数",
|
||||
success: "成功",
|
||||
failed: "失败",
|
||||
items: "同步条目",
|
||||
},
|
||||
logLatest: "最新",
|
||||
logDetail: {
|
||||
startTime: "开始时间",
|
||||
endTime: "结束时间",
|
||||
duration: "耗时",
|
||||
},
|
||||
connector: {
|
||||
feishu: "飞书",
|
||||
notion: "Notion",
|
||||
yuque: "语雀",
|
||||
wecom_doc: "企微文档",
|
||||
},
|
||||
connectorDesc: {
|
||||
feishu: "同步飞书知识库中的文档、表格、文件",
|
||||
notion: "同步 Notion 中的页面和数据库",
|
||||
yuque: "同步语雀知识库中的文档",
|
||||
wecom_doc: "同步企业微信文档中的内容",
|
||||
},
|
||||
field: {
|
||||
appId: "App ID",
|
||||
appSecret: "App Secret",
|
||||
integrationToken: "Integration Token",
|
||||
apiToken: "API Token",
|
||||
corpId: "Corp ID",
|
||||
corpSecret: "Corp Secret",
|
||||
},
|
||||
comingSoon: "即将支持",
|
||||
docHint: "在以下地址获取凭证:",
|
||||
pleaseTestFirst: "请先测试连接",
|
||||
prereqTitle: "使用前请先完成以下配置(缺一不可)",
|
||||
prereqBarText: "首次使用?点击查看飞书应用配置指引",
|
||||
prereqBotBrief: "为应用添加「机器人」能力",
|
||||
prereqBotDesc: "开放平台 → 添加应用能力 → 机器人 → 创建版本并发布",
|
||||
prereqBotLabel: "1. 为应用添加「机器人」能力(否则知识库中搜不到该应用):",
|
||||
prereqBotStep1: "在飞书开放平台打开你的应用,点击左侧「添加应用能力」",
|
||||
prereqBotStep2: "选择「机器人」并确认添加",
|
||||
prereqBotStep3: "创建新版本并发布(或在测试企业中调试)",
|
||||
prereqPermBrief: "开通 API 权限",
|
||||
prereqPermLabel: "2. 为应用开通以下 API 权限:",
|
||||
prereqOpenConsole: "前往飞书开放平台配置",
|
||||
prereqMemberBrief: "通过群聊添加为知识库成员",
|
||||
prereqMemberDesc: "创建群聊 → 添加应用为群机器人 → 将群聊添加为知识库成员",
|
||||
prereqMemberLabel: "3. 通过群聊将应用添加为知识库成员(知识库无法直接搜到应用):",
|
||||
back: "上一步",
|
||||
next: "下一步",
|
||||
save: "保存",
|
||||
schedule30min: "每 30 分钟",
|
||||
schedule1h: "每小时",
|
||||
schedule6h: "每 6 小时",
|
||||
schedule12h: "每 12 小时",
|
||||
schedule24h: "每天",
|
||||
scheduleHuman: {
|
||||
'30min': "每 30 分钟",
|
||||
'1h': "每小时",
|
||||
'6h': "每 6 小时",
|
||||
'12h': "每 12 小时",
|
||||
'24h': "每天",
|
||||
},
|
||||
addCard: "添加数据源",
|
||||
wikiSpace: "知识库空间",
|
||||
neverSynced: "未同步",
|
||||
justNow: "刚刚",
|
||||
minutesAgo: "{n} 分钟前",
|
||||
hoursAgo: "{n} 小时前",
|
||||
daysAgo: "{n} 天前",
|
||||
syncResultCreated: "+{n}",
|
||||
syncResultUpdated: "~{n}",
|
||||
syncResultDeleted: "-{n}",
|
||||
moreActions: "更多",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
// cronHumanize maps known cron schedule presets to human-readable i18n keys.
|
||||
// Falls back to the raw cron expression for unknown patterns.
|
||||
|
||||
const CRON_PRESET_MAP: Record<string, string> = {
|
||||
'0 */30 * * * *': 'datasource.scheduleHuman.30min',
|
||||
'0 0 * * * *': 'datasource.scheduleHuman.1h',
|
||||
'0 0 */6 * * *': 'datasource.scheduleHuman.6h',
|
||||
'0 0 */12 * * *': 'datasource.scheduleHuman.12h',
|
||||
'0 0 2 * * *': 'datasource.scheduleHuman.24h',
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a cron expression to a human-readable string.
|
||||
* Uses i18n translate function for known presets, raw expression otherwise.
|
||||
*/
|
||||
export function humanizeCron(cron: string, t: (key: string) => string): string {
|
||||
const key = CRON_PRESET_MAP[cron]
|
||||
if (key) return t(key)
|
||||
return cron || '--'
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a timestamp as relative time (e.g. "3小时前", "2天前").
|
||||
* Falls back to locale date string for timestamps older than 30 days.
|
||||
*/
|
||||
export function relativeTime(ts: string | null, t: (key: string, params?: Record<string, string | number>) => string): string {
|
||||
if (!ts) return t('datasource.neverSynced')
|
||||
const then = new Date(ts).getTime()
|
||||
if (isNaN(then)) return t('datasource.neverSynced')
|
||||
const now = Date.now()
|
||||
const diffMs = now - then
|
||||
|
||||
// Future time or just happened (within 60s)
|
||||
if (diffMs < 60000) return t('datasource.justNow')
|
||||
|
||||
const minutes = Math.floor(diffMs / 60000)
|
||||
if (minutes < 60) return t('datasource.minutesAgo', { n: minutes })
|
||||
|
||||
const hours = Math.floor(diffMs / 3600000)
|
||||
if (hours < 24) return t('datasource.hoursAgo', { n: hours })
|
||||
|
||||
const days = Math.floor(diffMs / 86400000)
|
||||
if (days < 30) return t('datasource.daysAgo', { n: days })
|
||||
|
||||
return new Date(ts).toLocaleDateString()
|
||||
}
|
||||
@@ -212,6 +212,11 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 数据源管理(仅编辑模式) -->
|
||||
<div v-if="mode === 'edit' && kbId" v-show="currentSection === 'datasource'" class="section">
|
||||
<DataSourceSettings :kb-id="kbId" />
|
||||
</div>
|
||||
|
||||
<!-- 共享设置(仅编辑模式) -->
|
||||
<div v-if="mode === 'edit' && kbId" v-show="currentSection === 'share'" class="section">
|
||||
<KBShareSettings :kb-id="kbId" />
|
||||
@@ -250,6 +255,7 @@ import KBAdvancedSettings from './settings/KBAdvancedSettings.vue'
|
||||
import ModelSelector from '@/components/ModelSelector.vue'
|
||||
import GraphSettings from './settings/GraphSettings.vue'
|
||||
import KBShareSettings from './settings/KBShareSettings.vue'
|
||||
import DataSourceSettings from './settings/DataSourceSettings.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const uiStore = useUIStore()
|
||||
@@ -292,8 +298,12 @@ const navItems = computed(() => {
|
||||
{ key: 'multimodal', icon: 'image', label: t('knowledgeEditor.sidebar.multimodal') },
|
||||
{ key: 'advanced', icon: 'setting', label: t('knowledgeEditor.sidebar.advanced') }
|
||||
)
|
||||
// 数据源管理:仅文档类型知识库 + 编辑模式
|
||||
if (props.mode === 'edit' && props.kbId) {
|
||||
items.push({ key: 'datasource', icon: 'cloud-download', label: t('knowledgeEditor.sidebar.datasource') })
|
||||
}
|
||||
}
|
||||
// 只在编辑模式下显示共享标签页
|
||||
// 共享设置:编辑模式下所有类型都可用
|
||||
if (props.mode === 'edit' && props.kbId) {
|
||||
items.push({ key: 'share', icon: 'share', label: t('knowledgeEditor.sidebar.share') })
|
||||
}
|
||||
@@ -810,7 +820,7 @@ watch(
|
||||
.settings-modal {
|
||||
position: relative;
|
||||
width: 90vw;
|
||||
max-width: 1100px;
|
||||
max-width: 1000px;
|
||||
height: 85vh;
|
||||
max-height: 750px;
|
||||
background: var(--td-bg-color-container);
|
||||
@@ -944,7 +954,7 @@ watch(
|
||||
.section-title {
|
||||
margin: 0 0 8px 0;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 16px;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
@@ -974,7 +984,7 @@ watch(
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
|
||||
|
||||
@@ -0,0 +1,834 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import {
|
||||
createDataSource,
|
||||
updateDataSource,
|
||||
validateConnection,
|
||||
validateCredentials,
|
||||
listResources,
|
||||
deleteDataSource,
|
||||
type DataSource,
|
||||
type Resource,
|
||||
} from '@/api/datasource'
|
||||
|
||||
const props = defineProps<{
|
||||
kbId: string
|
||||
dataSource: DataSource | null
|
||||
}>()
|
||||
|
||||
const visible = defineModel<boolean>('visible', { default: false })
|
||||
const emit = defineEmits<{ saved: [] }>()
|
||||
const { t } = useI18n()
|
||||
|
||||
const isEdit = computed(() => !!props.dataSource)
|
||||
const step = ref(0)
|
||||
const submitting = ref(false)
|
||||
|
||||
// Form data
|
||||
const form = ref({
|
||||
name: '',
|
||||
type: '',
|
||||
config: {
|
||||
credentials: {} as Record<string, any>,
|
||||
resource_ids: [] as string[],
|
||||
settings: {} as Record<string, any>,
|
||||
},
|
||||
sync_schedule: '0 0 */6 * * *',
|
||||
sync_mode: 'incremental' as 'incremental' | 'full',
|
||||
conflict_strategy: 'overwrite' as 'overwrite' | 'skip',
|
||||
sync_deletions: true,
|
||||
})
|
||||
|
||||
// Step 2: Resources
|
||||
const resources = ref<Resource[]>([])
|
||||
const loadingResources = ref(false)
|
||||
const selectedResourceIds = ref<string[]>([])
|
||||
|
||||
// Connection test
|
||||
const testing = ref(false)
|
||||
const testResult = ref<'success' | 'error' | ''>('')
|
||||
const testErrorMsg = ref('')
|
||||
|
||||
// Collapsible prereq in Step 1
|
||||
const prereqExpanded = ref(false)
|
||||
|
||||
// Temp data source for resource listing
|
||||
const tempDsId = ref('')
|
||||
|
||||
// Schedule presets
|
||||
const schedulePresets = computed(() => [
|
||||
{ label: t('datasource.schedule30min'), value: '0 */30 * * * *' },
|
||||
{ label: t('datasource.schedule1h'), value: '0 0 * * * *' },
|
||||
{ label: t('datasource.schedule6h'), value: '0 0 */6 * * *' },
|
||||
{ label: t('datasource.schedule12h'), value: '0 0 */12 * * *' },
|
||||
{ label: t('datasource.schedule24h'), value: '0 0 2 * * *' },
|
||||
])
|
||||
|
||||
// --- Connector definitions ---
|
||||
interface ConnectorDef {
|
||||
type: string
|
||||
available: boolean
|
||||
docUrl: string
|
||||
permissionDocUrl: string
|
||||
permissionPageUrl: string
|
||||
requiredPermissions: string[]
|
||||
fields: { key: string; labelKey: string; placeholder: string; secret?: boolean }[]
|
||||
}
|
||||
|
||||
const connectorDefs = computed<ConnectorDef[]>(() => [
|
||||
{
|
||||
type: 'feishu',
|
||||
available: true,
|
||||
docUrl: 'https://open.feishu.cn/app',
|
||||
permissionDocUrl: 'https://open.feishu.cn/document/server-docs/docs/wiki-v2/wiki-overview',
|
||||
permissionPageUrl: 'https://open.feishu.cn/app',
|
||||
requiredPermissions: [
|
||||
'wiki:wiki:readonly',
|
||||
'drive:drive:readonly',
|
||||
'drive:export:readonly',
|
||||
'docx:document:readonly',
|
||||
],
|
||||
fields: [
|
||||
{ key: 'app_id', labelKey: 'datasource.field.appId', placeholder: 'cli_xxxx' },
|
||||
{ key: 'app_secret', labelKey: 'datasource.field.appSecret', placeholder: '', secret: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'notion',
|
||||
available: false,
|
||||
docUrl: 'https://www.notion.so/my-integrations',
|
||||
permissionDocUrl: '',
|
||||
permissionPageUrl: '',
|
||||
requiredPermissions: [],
|
||||
fields: [
|
||||
{ key: 'api_key', labelKey: 'datasource.field.integrationToken', placeholder: 'ntn_xxxx', secret: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'yuque',
|
||||
available: false,
|
||||
docUrl: 'https://www.yuque.com/settings/tokens',
|
||||
permissionDocUrl: '',
|
||||
permissionPageUrl: '',
|
||||
requiredPermissions: [],
|
||||
fields: [
|
||||
{ key: 'api_token', labelKey: 'datasource.field.apiToken', placeholder: '', secret: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'wecom_doc',
|
||||
available: false,
|
||||
docUrl: 'https://developer.work.weixin.qq.com/',
|
||||
permissionDocUrl: '',
|
||||
permissionPageUrl: '',
|
||||
requiredPermissions: [],
|
||||
fields: [
|
||||
{ key: 'corp_id', labelKey: 'datasource.field.corpId', placeholder: '' },
|
||||
{ key: 'corp_secret', labelKey: 'datasource.field.corpSecret', placeholder: '', secret: true },
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
|
||||
const currentDef = computed(() => connectorDefs.value.find(d => d.type === form.value.type))
|
||||
|
||||
// --- Dialog lifecycle ---
|
||||
watch(visible, (v) => {
|
||||
if (!v) return
|
||||
step.value = isEdit.value ? 1 : 0
|
||||
testResult.value = ''
|
||||
testErrorMsg.value = ''
|
||||
tempDsId.value = ''
|
||||
prereqExpanded.value = false
|
||||
resources.value = []
|
||||
selectedResourceIds.value = []
|
||||
|
||||
if (isEdit.value && props.dataSource) {
|
||||
form.value = {
|
||||
name: props.dataSource.name,
|
||||
type: props.dataSource.type,
|
||||
config: props.dataSource.config || { credentials: {}, resource_ids: [], settings: {} },
|
||||
sync_schedule: props.dataSource.sync_schedule,
|
||||
sync_mode: props.dataSource.sync_mode,
|
||||
conflict_strategy: props.dataSource.conflict_strategy,
|
||||
sync_deletions: props.dataSource.sync_deletions,
|
||||
}
|
||||
selectedResourceIds.value = form.value.config?.resource_ids || []
|
||||
tempDsId.value = props.dataSource.id
|
||||
} else {
|
||||
form.value = {
|
||||
name: '',
|
||||
type: '',
|
||||
config: { credentials: {}, resource_ids: [], settings: {} },
|
||||
sync_schedule: '0 0 */6 * * *',
|
||||
sync_mode: 'incremental',
|
||||
conflict_strategy: 'overwrite',
|
||||
sync_deletions: true,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function selectType(def: ConnectorDef) {
|
||||
if (!def.available) return
|
||||
form.value.type = def.type
|
||||
form.value.name = t(`datasource.connector.${def.type}`)
|
||||
step.value = 1
|
||||
}
|
||||
|
||||
// --- Test connection (stateless, no DB write) ---
|
||||
async function testConnection() {
|
||||
const fields = currentDef.value?.fields || []
|
||||
for (const f of fields) {
|
||||
if (!form.value.config.credentials[f.key]) {
|
||||
MessagePlugin.warning(`${t(f.labelKey)} ${t('datasource.isRequired')}`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
testing.value = true
|
||||
testResult.value = ''
|
||||
testErrorMsg.value = ''
|
||||
try {
|
||||
if (isEdit.value && tempDsId.value) {
|
||||
await updateDataSource(tempDsId.value, {
|
||||
...form.value,
|
||||
knowledge_base_id: props.kbId,
|
||||
} as any)
|
||||
await validateConnection(tempDsId.value)
|
||||
} else {
|
||||
await validateCredentials(form.value.type, form.value.config.credentials)
|
||||
}
|
||||
testResult.value = 'success'
|
||||
MessagePlugin.success(t('datasource.testSuccess'))
|
||||
} catch (e: any) {
|
||||
testResult.value = 'error'
|
||||
testErrorMsg.value = e?.response?.data?.error || e?.message || ''
|
||||
MessagePlugin.error(t('datasource.testFailed'))
|
||||
}
|
||||
testing.value = false
|
||||
}
|
||||
|
||||
// --- Load resources ---
|
||||
async function loadResources() {
|
||||
loadingResources.value = true
|
||||
try {
|
||||
if (!tempDsId.value) {
|
||||
const res = await createDataSource({
|
||||
...form.value,
|
||||
knowledge_base_id: props.kbId,
|
||||
status: 'paused',
|
||||
} as any)
|
||||
const created = res?.data || res
|
||||
tempDsId.value = created.id
|
||||
} else if (!isEdit.value) {
|
||||
await updateDataSource(tempDsId.value, {
|
||||
...form.value,
|
||||
knowledge_base_id: props.kbId,
|
||||
} as any)
|
||||
}
|
||||
|
||||
const res = await listResources(tempDsId.value)
|
||||
resources.value = res?.data || res || []
|
||||
} catch {
|
||||
MessagePlugin.error(t('datasource.resourceLoadFailed'))
|
||||
}
|
||||
loadingResources.value = false
|
||||
}
|
||||
|
||||
function toggleResource(id: string) {
|
||||
const idx = selectedResourceIds.value.indexOf(id)
|
||||
if (idx >= 0) {
|
||||
selectedResourceIds.value.splice(idx, 1)
|
||||
} else {
|
||||
selectedResourceIds.value.push(id)
|
||||
}
|
||||
}
|
||||
|
||||
function validateStep1Fields(): boolean {
|
||||
const fields = currentDef.value?.fields || []
|
||||
for (const f of fields) {
|
||||
if (!form.value.config.credentials[f.key]) {
|
||||
MessagePlugin.warning(`${t(f.labelKey)} ${t('datasource.isRequired')}`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function nextStep() {
|
||||
if (step.value === 1) {
|
||||
if (!validateStep1Fields()) return
|
||||
if (testResult.value !== 'success') {
|
||||
MessagePlugin.warning(t('datasource.pleaseTestFirst'))
|
||||
return
|
||||
}
|
||||
}
|
||||
step.value++
|
||||
if (step.value === 2) {
|
||||
loadResources()
|
||||
}
|
||||
}
|
||||
|
||||
function prevStep() {
|
||||
step.value--
|
||||
}
|
||||
|
||||
// --- Final submit ---
|
||||
async function handleSubmit() {
|
||||
form.value.config.resource_ids = selectedResourceIds.value
|
||||
submitting.value = true
|
||||
try {
|
||||
if (tempDsId.value) {
|
||||
await updateDataSource(tempDsId.value, {
|
||||
...form.value,
|
||||
knowledge_base_id: props.kbId,
|
||||
status: 'active',
|
||||
} as any)
|
||||
} else {
|
||||
await createDataSource({
|
||||
...form.value,
|
||||
knowledge_base_id: props.kbId,
|
||||
status: 'active',
|
||||
} as any)
|
||||
}
|
||||
MessagePlugin.success(isEdit.value ? t('datasource.updateSuccess') : t('datasource.createSuccess'))
|
||||
emit('saved')
|
||||
visible.value = false
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('datasource.saveFailed'))
|
||||
}
|
||||
submitting.value = false
|
||||
}
|
||||
|
||||
// --- Cleanup on dialog close ---
|
||||
async function handleClose() {
|
||||
if (!isEdit.value && tempDsId.value) {
|
||||
try {
|
||||
await deleteDataSource(tempDsId.value)
|
||||
} catch {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
tempDsId.value = ''
|
||||
}
|
||||
visible.value = false
|
||||
}
|
||||
|
||||
const stepTitles = computed(() => [
|
||||
t('datasource.step.selectType'),
|
||||
t('datasource.step.credentials'),
|
||||
t('datasource.step.resources'),
|
||||
t('datasource.step.strategy'),
|
||||
])
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<t-dialog
|
||||
v-model:visible="visible"
|
||||
:header="isEdit ? t('datasource.editTitle') : t('datasource.createTitle')"
|
||||
:footer="false"
|
||||
width="640px"
|
||||
destroy-on-close
|
||||
:on-close="handleClose"
|
||||
>
|
||||
<!-- Step indicator -->
|
||||
<div class="ds-steps">
|
||||
<div
|
||||
v-for="(title, i) in stepTitles"
|
||||
:key="i"
|
||||
:class="['ds-step', { active: step === i, done: step > i }]"
|
||||
>
|
||||
<span class="ds-step-num">{{ step > i ? '✓' : i + 1 }}</span>
|
||||
<span class="ds-step-title">{{ title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Step 0: Select connector type -->
|
||||
<div v-if="step === 0" class="ds-step-content">
|
||||
<div class="ds-type-grid">
|
||||
<div
|
||||
v-for="def in connectorDefs"
|
||||
:key="def.type"
|
||||
:class="['ds-type-card', { disabled: !def.available }]"
|
||||
@click="selectType(def)"
|
||||
>
|
||||
<div class="ds-type-header">
|
||||
<span class="ds-type-name">{{ t(`datasource.connector.${def.type}`) }}</span>
|
||||
<span v-if="!def.available" class="ds-type-soon">{{ t('datasource.comingSoon') }}</span>
|
||||
</div>
|
||||
<div class="ds-type-desc">{{ t(`datasource.connectorDesc.${def.type}`) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Step 1: Credentials -->
|
||||
<div v-if="step === 1" class="ds-step-content">
|
||||
<!-- Compact collapsible prereq hint -->
|
||||
<div v-if="currentDef && currentDef.requiredPermissions.length > 0" class="ds-prereq-bar" @click="prereqExpanded = !prereqExpanded">
|
||||
<t-icon name="help-circle" size="14px" />
|
||||
<span>{{ t('datasource.prereqBarText') }}</span>
|
||||
<t-icon :name="prereqExpanded ? 'chevron-up' : 'chevron-down'" size="14px" class="ds-prereq-arrow" />
|
||||
</div>
|
||||
<div v-if="prereqExpanded && currentDef" class="ds-prereq-detail">
|
||||
<div class="ds-prereq-item">
|
||||
<span class="ds-prereq-num">1</span>
|
||||
<div>
|
||||
<div class="ds-prereq-item-title">{{ t('datasource.prereqBotBrief') }}</div>
|
||||
<div class="ds-prereq-item-desc">{{ t('datasource.prereqBotDesc') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ds-prereq-item">
|
||||
<span class="ds-prereq-num">2</span>
|
||||
<div>
|
||||
<div class="ds-prereq-item-title">{{ t('datasource.prereqPermBrief') }}</div>
|
||||
<div class="ds-prereq-item-desc">
|
||||
<code v-for="perm in currentDef.requiredPermissions" :key="perm" class="ds-perm-tag">{{ perm }}</code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ds-prereq-item">
|
||||
<span class="ds-prereq-num">3</span>
|
||||
<div>
|
||||
<div class="ds-prereq-item-title">{{ t('datasource.prereqMemberBrief') }}</div>
|
||||
<div class="ds-prereq-item-desc">{{ t('datasource.prereqMemberDesc') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<a :href="currentDef.permissionPageUrl" target="_blank" rel="noopener" class="ds-prereq-link">
|
||||
{{ t('datasource.prereqOpenConsole') }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ t('datasource.nameLabel') }}</label>
|
||||
<t-input v-model="form.name" :placeholder="t('datasource.namePlaceholder')" />
|
||||
</div>
|
||||
|
||||
<div v-if="currentDef?.docUrl" class="ds-doc-link">
|
||||
<t-icon name="info-circle" size="14px" />
|
||||
<span>{{ t('datasource.docHint') }}</span>
|
||||
<a :href="currentDef.docUrl" target="_blank" rel="noopener">{{ currentDef.docUrl }}</a>
|
||||
</div>
|
||||
|
||||
<div v-for="field in currentDef?.fields || []" :key="field.key" class="form-item">
|
||||
<label class="form-label">{{ t(field.labelKey) }}</label>
|
||||
<t-input
|
||||
v-model="form.config.credentials[field.key]"
|
||||
:placeholder="field.placeholder"
|
||||
:type="field.secret ? 'password' : 'text'"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<t-button variant="outline" :loading="testing" @click="testConnection">
|
||||
{{ t('datasource.testConnection') }}
|
||||
</t-button>
|
||||
<span v-if="testResult === 'success'" class="test-ok">{{ t('datasource.connected') }}</span>
|
||||
<span v-if="testResult === 'error'" class="test-fail">
|
||||
{{ t('datasource.connectionFailed') }}
|
||||
<span v-if="testErrorMsg" class="test-error-detail">- {{ testErrorMsg }}</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="ds-dialog-footer">
|
||||
<t-button variant="outline" @click="step = 0" v-if="!isEdit">{{ t('datasource.back') }}</t-button>
|
||||
<t-button theme="primary" @click="nextStep">{{ t('datasource.next') }}</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Step 2: Select resources -->
|
||||
<div v-if="step === 2" class="ds-step-content">
|
||||
<p class="form-tip">{{ t('datasource.resourceHint') }}</p>
|
||||
<div v-if="loadingResources" style="text-align:center;padding:20px"><t-loading /></div>
|
||||
<div v-else-if="resources.length > 0" class="ds-resource-list">
|
||||
<div
|
||||
v-for="r in resources"
|
||||
:key="r.external_id"
|
||||
:class="['ds-resource-row', { selected: selectedResourceIds.includes(r.external_id) }]"
|
||||
@click="toggleResource(r.external_id)"
|
||||
>
|
||||
<t-checkbox
|
||||
:checked="selectedResourceIds.includes(r.external_id)"
|
||||
@click.stop
|
||||
@change="toggleResource(r.external_id)"
|
||||
/>
|
||||
<div class="ds-resource-info">
|
||||
<div class="ds-resource-name">{{ r.name }}</div>
|
||||
<div class="ds-resource-meta">
|
||||
<span class="ds-resource-type">{{ r.type === 'wiki_space' ? t('datasource.wikiSpace') : r.type }}</span>
|
||||
<span v-if="r.description" class="ds-resource-desc">{{ r.description }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Empty state: concise guide -->
|
||||
<div v-else class="ds-resource-empty">
|
||||
<t-icon name="info-circle" size="32px" style="color: var(--td-warning-color); margin-bottom: 8px;" />
|
||||
<p class="ds-empty-title">{{ t('datasource.noResources') }}</p>
|
||||
<p class="ds-empty-desc">{{ t('datasource.noResourcesDesc') }}</p>
|
||||
<div class="ds-guide-steps">
|
||||
<div class="ds-guide-step">
|
||||
<span class="ds-guide-num">1</span>
|
||||
<span>{{ t('datasource.guideStep1') }}</span>
|
||||
</div>
|
||||
<div class="ds-guide-step">
|
||||
<span class="ds-guide-num">2</span>
|
||||
<span>{{ t('datasource.guideStep2') }}</span>
|
||||
</div>
|
||||
<div class="ds-guide-step">
|
||||
<span class="ds-guide-num">3</span>
|
||||
<span>{{ t('datasource.guideStep3') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ds-empty-actions">
|
||||
<t-button variant="outline" size="small" @click="loadResources">
|
||||
{{ t('datasource.retryLoadResources') }}
|
||||
</t-button>
|
||||
<a v-if="currentDef?.permissionDocUrl" :href="currentDef.permissionDocUrl" target="_blank" rel="noopener" class="ds-doc-link-inline">
|
||||
{{ t('datasource.permissionDocLink') }}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ds-dialog-footer">
|
||||
<t-button variant="outline" @click="prevStep">{{ t('datasource.back') }}</t-button>
|
||||
<t-button theme="primary" @click="nextStep">{{ t('datasource.next') }}</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Step 3: Sync strategy -->
|
||||
<div v-if="step === 3" class="ds-step-content">
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ t('datasource.syncScheduleLabel') }}</label>
|
||||
<t-select v-model="form.sync_schedule">
|
||||
<t-option v-for="p in schedulePresets" :key="p.value" :value="p.value" :label="p.label" />
|
||||
</t-select>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ t('datasource.syncModeLabel') }}</label>
|
||||
<t-radio-group v-model="form.sync_mode">
|
||||
<t-radio value="incremental">{{ t('datasource.syncMode.incremental') }}</t-radio>
|
||||
<t-radio value="full">{{ t('datasource.syncMode.full') }}</t-radio>
|
||||
</t-radio-group>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ t('datasource.conflictLabel') }}</label>
|
||||
<t-radio-group v-model="form.conflict_strategy">
|
||||
<t-radio value="overwrite">{{ t('datasource.conflict.overwrite') }}</t-radio>
|
||||
<t-radio value="skip">{{ t('datasource.conflict.skip') }}</t-radio>
|
||||
</t-radio-group>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<t-checkbox v-model="form.sync_deletions">{{ t('datasource.syncDeletions') }}</t-checkbox>
|
||||
</div>
|
||||
|
||||
<div class="ds-dialog-footer">
|
||||
<t-button variant="outline" @click="prevStep">{{ t('datasource.back') }}</t-button>
|
||||
<t-button theme="primary" :loading="submitting" @click="handleSubmit">
|
||||
{{ isEdit ? t('datasource.save') : t('datasource.createAndSync') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</t-dialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.ds-steps {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
margin-bottom: 24px;
|
||||
border-bottom: 1px solid var(--td-border-level-2-color);
|
||||
padding-bottom: 16px;
|
||||
}
|
||||
|
||||
.ds-step {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex: 1;
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.ds-step.active { color: var(--td-brand-color); font-weight: 600; }
|
||||
.ds-step.done { color: var(--td-success-color); }
|
||||
|
||||
.ds-step-num {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 12px;
|
||||
border: 1px solid currentColor;
|
||||
}
|
||||
|
||||
.ds-step.active .ds-step-num { background: var(--td-brand-color); color: #fff; border-color: var(--td-brand-color); }
|
||||
.ds-step.done .ds-step-num { background: var(--td-success-color); color: #fff; border-color: var(--td-success-color); }
|
||||
|
||||
.ds-step-content { min-height: 200px; }
|
||||
|
||||
/* --- Step 0: type cards --- */
|
||||
.ds-type-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.ds-type-card {
|
||||
border: 1px solid var(--td-border-level-2-color);
|
||||
border-radius: 8px;
|
||||
padding: 14px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.ds-type-card:hover:not(.disabled) { border-color: var(--td-brand-color); background: var(--td-brand-color-light); }
|
||||
.ds-type-card.disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
|
||||
.ds-type-header { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
|
||||
.ds-type-name { font-size: 13px; font-weight: 600; }
|
||||
.ds-type-soon { font-size: 10px; color: var(--td-text-color-placeholder); background: var(--td-bg-color-component); padding: 1px 6px; border-radius: 3px; }
|
||||
.ds-type-desc { font-size: 11px; color: var(--td-text-color-secondary); }
|
||||
|
||||
/* --- Step 1: collapsible prereq --- */
|
||||
.ds-prereq-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 8px 12px;
|
||||
margin-bottom: 16px;
|
||||
border-radius: 6px;
|
||||
background: var(--td-warning-color-1);
|
||||
color: var(--td-warning-color);
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
transition: background 0.15s;
|
||||
}
|
||||
|
||||
.ds-prereq-bar:hover {
|
||||
background: var(--td-warning-color-2);
|
||||
}
|
||||
|
||||
.ds-prereq-arrow {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.ds-prereq-detail {
|
||||
border: 1px solid var(--td-border-level-2-color);
|
||||
border-radius: 8px;
|
||||
padding: 14px;
|
||||
margin-bottom: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.ds-prereq-item {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.ds-prereq-num {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 50%;
|
||||
background: var(--td-brand-color);
|
||||
color: #fff;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
.ds-prereq-item-title {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.ds-prereq-item-desc {
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin-top: 2px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.ds-perm-tag {
|
||||
font-size: 11px;
|
||||
padding: 1px 5px;
|
||||
border-radius: 3px;
|
||||
background: var(--td-bg-color-component);
|
||||
color: var(--td-text-color-secondary);
|
||||
font-family: monospace;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.ds-prereq-link {
|
||||
font-size: 12px;
|
||||
color: var(--td-brand-color);
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
/* --- Step 1: doc link & form --- */
|
||||
.ds-doc-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-secondary);
|
||||
background: var(--td-bg-color-component);
|
||||
padding: 8px 12px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.ds-doc-link a {
|
||||
color: var(--td-brand-color);
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.form-item { margin-bottom: 16px; }
|
||||
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--td-text-color-primary); }
|
||||
.form-tip { font-size: 12px; color: var(--td-text-color-placeholder); margin: 4px 0 12px; }
|
||||
.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
|
||||
.test-ok { color: #00a870; font-size: 13px; }
|
||||
.test-fail { color: #e34d59; font-size: 13px; }
|
||||
.test-error-detail { font-size: 11px; color: var(--td-text-color-placeholder); }
|
||||
|
||||
.ds-dialog-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--td-border-level-2-color); }
|
||||
|
||||
/* --- Step 2: resource list --- */
|
||||
.ds-resource-list { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
|
||||
|
||||
.ds-resource-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
|
||||
.ds-resource-row:hover {
|
||||
background: var(--td-bg-color-container-hover);
|
||||
}
|
||||
|
||||
.ds-resource-row.selected {
|
||||
border-color: var(--td-brand-color);
|
||||
background: none;
|
||||
}
|
||||
|
||||
.ds-resource-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.ds-resource-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.ds-resource-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.ds-resource-type {
|
||||
font-size: 11px;
|
||||
padding: 0 5px;
|
||||
border-radius: 3px;
|
||||
background: var(--td-bg-color-component);
|
||||
color: var(--td-text-color-placeholder);
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
.ds-resource-desc {
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-secondary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* --- Step 2: empty state --- */
|
||||
.ds-resource-empty {
|
||||
text-align: center;
|
||||
padding: 24px 0;
|
||||
}
|
||||
|
||||
.ds-empty-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
margin: 0 0 4px;
|
||||
}
|
||||
|
||||
.ds-empty-desc {
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin: 0 0 16px;
|
||||
}
|
||||
|
||||
.ds-guide-steps {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
text-align: left;
|
||||
max-width: 440px;
|
||||
margin: 0 auto 16px;
|
||||
}
|
||||
|
||||
.ds-guide-step {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-primary);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.ds-guide-num {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 50%;
|
||||
background: var(--td-brand-color-light);
|
||||
color: var(--td-brand-color);
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
.ds-empty-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.ds-doc-link-inline {
|
||||
color: var(--td-brand-color);
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,489 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import {
|
||||
listDataSources,
|
||||
deleteDataSource,
|
||||
triggerSync,
|
||||
pauseDataSource,
|
||||
resumeDataSource,
|
||||
type DataSource,
|
||||
} from '@/api/datasource'
|
||||
import { humanizeCron, relativeTime } from '@/utils/cronHumanize'
|
||||
import DataSourceEditorDialog from './DataSourceEditorDialog.vue'
|
||||
import DataSourceSyncLogs from './DataSourceSyncLogs.vue'
|
||||
|
||||
const props = defineProps<{ kbId: string }>()
|
||||
const { t } = useI18n()
|
||||
|
||||
const dataSources = ref<DataSource[]>([])
|
||||
const loading = ref(false)
|
||||
const editorVisible = ref(false)
|
||||
const editingDs = ref<DataSource | null>(null)
|
||||
const logsVisible = ref(false)
|
||||
const logsDsId = ref('')
|
||||
const logsDsName = ref('')
|
||||
|
||||
async function loadList() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await listDataSources(props.kbId)
|
||||
dataSources.value = res?.data || res || []
|
||||
} catch (e: any) {
|
||||
console.error(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
editingDs.value = null
|
||||
editorVisible.value = true
|
||||
}
|
||||
|
||||
function openEdit(ds: DataSource) {
|
||||
editingDs.value = ds
|
||||
editorVisible.value = true
|
||||
}
|
||||
|
||||
function openLogs(ds: DataSource) {
|
||||
logsDsId.value = ds.id
|
||||
logsDsName.value = ds.name
|
||||
logsVisible.value = true
|
||||
}
|
||||
|
||||
async function handleDelete(ds: DataSource) {
|
||||
try {
|
||||
await deleteDataSource(ds.id)
|
||||
MessagePlugin.success(t('datasource.deleteSuccess'))
|
||||
loadList()
|
||||
} catch {
|
||||
MessagePlugin.error(t('datasource.deleteFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSync(ds: DataSource) {
|
||||
try {
|
||||
await triggerSync(ds.id)
|
||||
MessagePlugin.success(t('datasource.syncTriggered'))
|
||||
loadList()
|
||||
} catch {
|
||||
MessagePlugin.error(t('datasource.syncFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePause(ds: DataSource) {
|
||||
try {
|
||||
await pauseDataSource(ds.id)
|
||||
MessagePlugin.success(t('datasource.paused'))
|
||||
loadList()
|
||||
} catch {
|
||||
MessagePlugin.error(t('datasource.pauseFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
async function handleResume(ds: DataSource) {
|
||||
try {
|
||||
await resumeDataSource(ds.id)
|
||||
MessagePlugin.success(t('datasource.resumed'))
|
||||
loadList()
|
||||
} catch {
|
||||
MessagePlugin.error(t('datasource.resumeFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
function statusColor(status: string) {
|
||||
if (status === 'active') return 'var(--td-success-color)'
|
||||
if (status === 'error') return 'var(--td-error-color)'
|
||||
return 'var(--td-text-color-placeholder)'
|
||||
}
|
||||
|
||||
function statusLabel(status: string) {
|
||||
return t(`datasource.status.${status}`)
|
||||
}
|
||||
|
||||
function syncModeLabel(mode: string) {
|
||||
return t(`datasource.syncMode.${mode}`)
|
||||
}
|
||||
|
||||
function connectorLabel(type: string) {
|
||||
return t(`datasource.connector.${type}`) || type
|
||||
}
|
||||
|
||||
function scheduleLabel(cron: string) {
|
||||
return humanizeCron(cron, t)
|
||||
}
|
||||
|
||||
function lastSyncTime(ds: DataSource) {
|
||||
return relativeTime(ds.last_sync_at, t)
|
||||
}
|
||||
|
||||
function lastSyncFullTime(ds: DataSource) {
|
||||
if (!ds.last_sync_at) return ''
|
||||
return new Date(ds.last_sync_at).toLocaleString()
|
||||
}
|
||||
|
||||
// Build sync result pills from latest_sync_log
|
||||
function syncResultPills(ds: DataSource) {
|
||||
const log = ds.latest_sync_log
|
||||
if (!log) return []
|
||||
const pills: { text: string; cls: string }[] = []
|
||||
if (log.items_created > 0) pills.push({ text: `+${log.items_created}`, cls: 'created' })
|
||||
if (log.items_updated > 0) pills.push({ text: `~${log.items_updated}`, cls: 'updated' })
|
||||
if (log.items_deleted > 0) pills.push({ text: `-${log.items_deleted}`, cls: 'deleted' })
|
||||
if (log.items_failed > 0) pills.push({ text: `${log.items_failed} ${t('datasource.logMetric.failed')}`, cls: 'failed' })
|
||||
if (log.items_skipped > 0) pills.push({ text: `${log.items_skipped} ${t('datasource.logMetric.skipped')}`, cls: 'skipped' })
|
||||
return pills
|
||||
}
|
||||
|
||||
function lastSyncStatusLabel(ds: DataSource) {
|
||||
const log = ds.latest_sync_log
|
||||
if (!log) return '--'
|
||||
return t(`datasource.logStatus.${log.status}`)
|
||||
}
|
||||
|
||||
function lastSyncStatusColor(ds: DataSource) {
|
||||
const log = ds.latest_sync_log
|
||||
if (!log) return ''
|
||||
switch (log.status) {
|
||||
case 'success': return 'var(--td-success-color)'
|
||||
case 'failed': return 'var(--td-error-color)'
|
||||
case 'running': return 'var(--td-brand-color)'
|
||||
case 'partial': return 'var(--td-warning-color)'
|
||||
default: return ''
|
||||
}
|
||||
}
|
||||
|
||||
function onEditorSaved() {
|
||||
editorVisible.value = false
|
||||
loadList()
|
||||
}
|
||||
|
||||
onMounted(loadList)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="ds-settings">
|
||||
<!-- Section header: title only, no button here -->
|
||||
<div class="section-header">
|
||||
<h2 class="section-title">{{ t('datasource.title') }}</h2>
|
||||
<p class="section-desc">{{ t('datasource.description') }}</p>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="ds-loading">
|
||||
<t-loading />
|
||||
</div>
|
||||
|
||||
<div v-else-if="dataSources.length === 0" class="ds-empty">
|
||||
<t-icon name="cloud-download" size="48px" style="color: var(--td-text-color-placeholder)" />
|
||||
<p>{{ t('datasource.empty') }}</p>
|
||||
<t-button variant="outline" @click="openCreate">{{ t('datasource.addFirst') }}</t-button>
|
||||
</div>
|
||||
|
||||
<div v-else class="ds-list">
|
||||
<!-- Data source cards -->
|
||||
<div v-for="ds in dataSources" :key="ds.id" class="ds-card">
|
||||
<div class="ds-card-header">
|
||||
<div class="ds-card-title">
|
||||
<span class="ds-type-badge">{{ connectorLabel(ds.type) }}</span>
|
||||
<span class="ds-name">{{ ds.name }}</span>
|
||||
</div>
|
||||
<div class="ds-card-header-right">
|
||||
<div class="ds-status">
|
||||
<span class="ds-status-dot" :style="{ background: statusColor(ds.status) }"></span>
|
||||
{{ statusLabel(ds.status) }}
|
||||
</div>
|
||||
<t-dropdown trigger="click" :min-column-width="100">
|
||||
<t-button size="small" variant="text" shape="square">
|
||||
<template #icon><t-icon name="more" /></template>
|
||||
</t-button>
|
||||
<template #dropdown>
|
||||
<t-dropdown-menu>
|
||||
<t-dropdown-item @click="openEdit(ds)">
|
||||
<t-icon name="edit" /> {{ t('datasource.edit') }}
|
||||
</t-dropdown-item>
|
||||
<t-dropdown-item @click="openLogs(ds)">
|
||||
<t-icon name="history" /> {{ t('datasource.logs') }}
|
||||
</t-dropdown-item>
|
||||
<t-dropdown-item
|
||||
v-if="ds.status === 'active'"
|
||||
@click="handlePause(ds)"
|
||||
>
|
||||
<t-icon name="pause-circle" /> {{ t('datasource.pause') }}
|
||||
</t-dropdown-item>
|
||||
<t-dropdown-item
|
||||
v-else-if="ds.status === 'paused'"
|
||||
@click="handleResume(ds)"
|
||||
>
|
||||
<t-icon name="play-circle" /> {{ t('datasource.resume') }}
|
||||
</t-dropdown-item>
|
||||
<t-dropdown-item theme="error" @click="handleDelete(ds)">
|
||||
<t-icon name="delete" /> {{ t('datasource.delete') }}
|
||||
</t-dropdown-item>
|
||||
</t-dropdown-menu>
|
||||
</template>
|
||||
</t-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Info grid -->
|
||||
<div class="ds-card-body">
|
||||
<div class="ds-info-cell">
|
||||
<span class="ds-info-label">{{ t('datasource.syncModeLabel') }}</span>
|
||||
<span class="ds-info-value">{{ syncModeLabel(ds.sync_mode) }}</span>
|
||||
</div>
|
||||
<div class="ds-info-cell">
|
||||
<span class="ds-info-label">{{ t('datasource.schedule') }}</span>
|
||||
<span class="ds-info-value">{{ scheduleLabel(ds.sync_schedule) }}</span>
|
||||
</div>
|
||||
<div class="ds-info-cell">
|
||||
<span class="ds-info-label">{{ t('datasource.lastSync') }}</span>
|
||||
<span class="ds-info-value" :title="lastSyncFullTime(ds)">{{ lastSyncTime(ds) }}</span>
|
||||
</div>
|
||||
<div class="ds-info-cell">
|
||||
<span class="ds-info-label">{{ t('datasource.lastStatus') }}</span>
|
||||
<span class="ds-info-value">
|
||||
<span v-if="ds.latest_sync_log" :style="{ color: lastSyncStatusColor(ds) }">{{ lastSyncStatusLabel(ds) }}</span>
|
||||
<span v-else>--</span>
|
||||
<span v-for="pill in syncResultPills(ds)" :key="pill.cls" :class="['ds-pill', pill.cls]">{{ pill.text }}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="ds.error_message" class="ds-error">
|
||||
<t-icon name="error-circle" size="14px" />
|
||||
{{ ds.error_message }}
|
||||
</div>
|
||||
|
||||
<!-- Quick action -->
|
||||
<div class="ds-card-footer">
|
||||
<t-button size="small" variant="outline" theme="primary" @click="handleSync(ds)">
|
||||
<template #icon><t-icon name="refresh" /></template>
|
||||
{{ t('datasource.syncNow') }}
|
||||
</t-button>
|
||||
<t-button size="small" variant="text" @click="openLogs(ds)">
|
||||
{{ t('datasource.logs') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add card at the end -->
|
||||
<div class="ds-card-add" @click="openCreate">
|
||||
<t-icon name="add" size="20px" />
|
||||
<span>{{ t('datasource.addCard') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Editor dialog -->
|
||||
<DataSourceEditorDialog
|
||||
v-model:visible="editorVisible"
|
||||
:kb-id="kbId"
|
||||
:data-source="editingDs"
|
||||
@saved="onEditorSaved"
|
||||
/>
|
||||
|
||||
<!-- Sync logs drawer -->
|
||||
<DataSourceSyncLogs
|
||||
v-model:visible="logsVisible"
|
||||
:data-source-id="logsDsId"
|
||||
:data-source-name="logsDsName"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.ds-settings {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* --- Section header: matches KBModelConfig / KBStorageSettings pattern --- */
|
||||
.section-header {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
margin: 0 0 8px 0;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.section-desc {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
line-height: 22px;
|
||||
}
|
||||
|
||||
/* --- Loading / Empty --- */
|
||||
.ds-loading, .ds-empty {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 60px 0;
|
||||
gap: 12px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
/* --- List --- */
|
||||
.ds-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
/* --- Card --- */
|
||||
.ds-card {
|
||||
border: 1px solid var(--td-border-level-2-color);
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.ds-card:hover {
|
||||
border-color: var(--td-brand-color-hover);
|
||||
}
|
||||
|
||||
.ds-card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.ds-card-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.ds-type-badge {
|
||||
font-size: 11px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
background: var(--td-brand-color-light);
|
||||
color: var(--td-brand-color);
|
||||
font-weight: 500;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.ds-name {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.ds-card-header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.ds-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
.ds-status-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
/* --- Info grid --- */
|
||||
.ds-card-body {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 8px 24px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.ds-info-cell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.ds-info-label {
|
||||
font-size: 11px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.ds-info-value {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-primary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
/* --- Sync result pills --- */
|
||||
.ds-pill {
|
||||
font-size: 11px;
|
||||
padding: 0 5px;
|
||||
border-radius: 3px;
|
||||
font-weight: 500;
|
||||
font-variant-numeric: tabular-nums;
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
.ds-pill.created { background: var(--td-success-color-1); color: var(--td-success-color); }
|
||||
.ds-pill.updated { background: var(--td-brand-color-light); color: var(--td-brand-color); }
|
||||
.ds-pill.deleted { background: var(--td-warning-color-1); color: var(--td-warning-color); }
|
||||
.ds-pill.skipped { background: var(--td-bg-color-component); color: var(--td-text-color-placeholder); }
|
||||
.ds-pill.failed { background: var(--td-error-color-1); color: var(--td-error-color); }
|
||||
|
||||
/* --- Error --- */
|
||||
.ds-error {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 6px;
|
||||
color: var(--td-error-color);
|
||||
font-size: 12px;
|
||||
background: var(--td-error-color-1);
|
||||
padding: 6px 10px;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
/* --- Footer actions --- */
|
||||
.ds-card-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
border-top: 1px solid var(--td-border-level-2-color);
|
||||
padding-top: 12px;
|
||||
}
|
||||
|
||||
/* --- Add card --- */
|
||||
.ds-card-add {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
padding: 12px;
|
||||
border: 1px dashed var(--td-border-level-2-color);
|
||||
border-radius: 8px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.ds-card-add:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
color: var(--td-brand-color);
|
||||
background: var(--td-brand-color-light);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,446 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { getSyncLogs, type SyncLog } from '@/api/datasource'
|
||||
|
||||
const props = defineProps<{
|
||||
dataSourceId: string
|
||||
dataSourceName?: string
|
||||
}>()
|
||||
const visible = defineModel<boolean>('visible', { default: false })
|
||||
const { t } = useI18n()
|
||||
|
||||
const logs = ref<SyncLog[]>([])
|
||||
const loading = ref(false)
|
||||
const expandedId = ref('')
|
||||
|
||||
watch(visible, async (v) => {
|
||||
if (!v || !props.dataSourceId) return
|
||||
expandedId.value = ''
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await getSyncLogs(props.dataSourceId, 50, 0)
|
||||
logs.value = res?.data || res || []
|
||||
} catch { /* ignore */ }
|
||||
loading.value = false
|
||||
})
|
||||
|
||||
function toggleExpand(id: string) {
|
||||
expandedId.value = expandedId.value === id ? '' : id
|
||||
}
|
||||
|
||||
// --- Stats ---
|
||||
const stats = computed(() => {
|
||||
const total = logs.value.length
|
||||
const success = logs.value.filter(l => l.status === 'success').length
|
||||
const failed = logs.value.filter(l => l.status === 'failed').length
|
||||
const totalItems = logs.value.reduce((acc, l) => acc + (l.items_created || 0) + (l.items_updated || 0), 0)
|
||||
return { total, success, failed, totalItems }
|
||||
})
|
||||
|
||||
// --- Helpers ---
|
||||
function statusIcon(status: string) {
|
||||
switch (status) {
|
||||
case 'success': return 'check-circle-filled'
|
||||
case 'running': return 'loading'
|
||||
case 'failed': return 'close-circle-filled'
|
||||
case 'partial': return 'error-circle-filled'
|
||||
case 'canceled': return 'minus-circle-filled'
|
||||
default: return 'info-circle-filled'
|
||||
}
|
||||
}
|
||||
|
||||
function statusColor(status: string) {
|
||||
switch (status) {
|
||||
case 'success': return 'var(--td-success-color)'
|
||||
case 'running': return 'var(--td-brand-color)'
|
||||
case 'failed': return 'var(--td-error-color)'
|
||||
case 'partial': return 'var(--td-warning-color)'
|
||||
default: return 'var(--td-text-color-placeholder)'
|
||||
}
|
||||
}
|
||||
|
||||
function formatTime(ts: string | null) {
|
||||
if (!ts) return '--'
|
||||
const d = new Date(ts)
|
||||
if (isNaN(d.getTime())) return '--'
|
||||
return d.toLocaleString(undefined, {
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
hour12: false,
|
||||
})
|
||||
}
|
||||
|
||||
function formatDate(ts: string | null) {
|
||||
if (!ts) return ''
|
||||
const d = new Date(ts)
|
||||
if (isNaN(d.getTime())) return ''
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
return `${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
|
||||
}
|
||||
|
||||
function formatHourMin(ts: string | null) {
|
||||
if (!ts) return ''
|
||||
const d = new Date(ts)
|
||||
if (isNaN(d.getTime())) return ''
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
return `${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||||
}
|
||||
|
||||
function duration(log: SyncLog) {
|
||||
if (!log.started_at || !log.finished_at) return '--'
|
||||
const ms = new Date(log.finished_at).getTime() - new Date(log.started_at).getTime()
|
||||
if (ms < 1000) return `<1s`
|
||||
const sec = Math.round(ms / 1000)
|
||||
if (sec < 60) return `${sec}s`
|
||||
return `${Math.floor(sec / 60)}m${sec % 60}s`
|
||||
}
|
||||
|
||||
function hasPills(log: SyncLog) {
|
||||
return log.items_created > 0 || log.items_updated > 0 || log.items_deleted > 0 || log.items_skipped > 0 || log.items_failed > 0
|
||||
}
|
||||
|
||||
// Group logs by date
|
||||
const groupedLogs = computed(() => {
|
||||
const groups: { date: string; logs: SyncLog[] }[] = []
|
||||
let currentDate = ''
|
||||
for (const log of logs.value) {
|
||||
const d = formatDate(log.started_at)
|
||||
if (d !== currentDate) {
|
||||
currentDate = d
|
||||
groups.push({ date: d, logs: [] })
|
||||
}
|
||||
groups[groups.length - 1].logs.push(log)
|
||||
}
|
||||
return groups
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<t-drawer
|
||||
v-model:visible="visible"
|
||||
:header="props.dataSourceName ? `${t('datasource.syncHistory')} · ${props.dataSourceName}` : t('datasource.syncHistory')"
|
||||
size="480px"
|
||||
destroy-on-close
|
||||
class="ds-logs-drawer"
|
||||
>
|
||||
<div v-if="loading" style="text-align:center;padding:60px"><t-loading /></div>
|
||||
|
||||
<div v-else-if="logs.length === 0" class="logs-empty">
|
||||
<t-icon name="history" size="40px" />
|
||||
<p>{{ t('datasource.noLogs') }}</p>
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<!-- Summary -->
|
||||
<div class="logs-summary">
|
||||
<div class="summary-stat">
|
||||
<span class="stat-num">{{ stats.total }}</span>
|
||||
<span class="stat-label">{{ t('datasource.logSummary.total') }}</span>
|
||||
</div>
|
||||
<div class="summary-stat">
|
||||
<span class="stat-num success">{{ stats.success }}</span>
|
||||
<span class="stat-label">{{ t('datasource.logSummary.success') }}</span>
|
||||
</div>
|
||||
<div class="summary-stat">
|
||||
<span class="stat-num error">{{ stats.failed }}</span>
|
||||
<span class="stat-label">{{ t('datasource.logSummary.failed') }}</span>
|
||||
</div>
|
||||
<div class="summary-stat">
|
||||
<span class="stat-num">{{ stats.totalItems }}</span>
|
||||
<span class="stat-label">{{ t('datasource.logSummary.items') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Timeline grouped by date -->
|
||||
<div class="timeline">
|
||||
<div v-for="group in groupedLogs" :key="group.date" class="timeline-group">
|
||||
<div class="timeline-date">{{ group.date }}</div>
|
||||
|
||||
<div
|
||||
v-for="log in group.logs"
|
||||
:key="log.id"
|
||||
class="timeline-item"
|
||||
@click="toggleExpand(log.id)"
|
||||
>
|
||||
<!-- Dot -->
|
||||
<div class="tl-dot-col">
|
||||
<span class="tl-dot" :style="{ background: statusColor(log.status) }">
|
||||
<t-icon v-if="log.status === 'running'" name="loading" size="10px" class="tl-spin" />
|
||||
</span>
|
||||
<span class="tl-line"></span>
|
||||
</div>
|
||||
|
||||
<!-- Content -->
|
||||
<div class="tl-content">
|
||||
<div class="tl-header">
|
||||
<span class="tl-status" :style="{ color: statusColor(log.status) }">
|
||||
{{ t(`datasource.logStatus.${log.status}`) }}
|
||||
</span>
|
||||
<span class="tl-time">{{ formatHourMin(log.started_at) }}</span>
|
||||
<span v-if="log.finished_at" class="tl-duration">{{ duration(log) }}</span>
|
||||
</div>
|
||||
|
||||
<!-- Pills -->
|
||||
<div v-if="hasPills(log)" class="tl-pills">
|
||||
<span v-if="log.items_created > 0" class="pill created">+{{ log.items_created }}</span>
|
||||
<span v-if="log.items_updated > 0" class="pill updated">~{{ log.items_updated }}</span>
|
||||
<span v-if="log.items_deleted > 0" class="pill deleted">-{{ log.items_deleted }}</span>
|
||||
<span v-if="log.items_skipped > 0" class="pill skipped">{{ log.items_skipped }} {{ t('datasource.logMetric.skipped') }}</span>
|
||||
<span v-if="log.items_failed > 0" class="pill failed">{{ log.items_failed }} {{ t('datasource.logMetric.failed') }}</span>
|
||||
</div>
|
||||
|
||||
<!-- Expanded -->
|
||||
<div v-if="expandedId === log.id" class="tl-detail" @click.stop>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">{{ t('datasource.logDetail.startTime') }}</span>
|
||||
<span>{{ formatTime(log.started_at) }}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">{{ t('datasource.logDetail.endTime') }}</span>
|
||||
<span>{{ formatTime(log.finished_at) }}</span>
|
||||
</div>
|
||||
<div v-if="log.items_total > 0" class="detail-row">
|
||||
<span class="detail-label">{{ t('datasource.logMetric.total') }}</span>
|
||||
<span>{{ log.items_total }}</span>
|
||||
</div>
|
||||
<div v-if="log.error_message" class="tl-error">
|
||||
{{ log.error_message }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</t-drawer>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.logs-empty {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 80px 0;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: 13px;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* --- Summary --- */
|
||||
.logs-summary {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
padding-bottom: 16px;
|
||||
margin-bottom: 8px;
|
||||
border-bottom: 1px solid var(--td-border-level-2-color);
|
||||
}
|
||||
|
||||
.summary-stat {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 8px 0;
|
||||
border-radius: 6px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
}
|
||||
|
||||
.stat-num {
|
||||
display: block;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
color: var(--td-text-color-primary);
|
||||
line-height: 1.3;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.stat-num.success { color: var(--td-success-color); }
|
||||
.stat-num.error { color: var(--td-error-color); }
|
||||
|
||||
.stat-label {
|
||||
font-size: 11px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
/* --- Timeline --- */
|
||||
.timeline {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.timeline-group {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.timeline-date {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-placeholder);
|
||||
padding: 10px 0 6px 24px;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
background: var(--td-bg-color-container);
|
||||
z-index: 1;
|
||||
letter-spacing: 0.5px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.timeline-item {
|
||||
display: flex;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* --- Dot column: continuous line --- */
|
||||
.tl-dot-col {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 24px;
|
||||
flex-shrink: 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* Continuous vertical line behind dots */
|
||||
.tl-dot-col::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
width: 1.5px;
|
||||
background: var(--td-border-level-2-color);
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.timeline-group:last-child .timeline-item:last-child .tl-dot-col::before {
|
||||
bottom: 50%;
|
||||
}
|
||||
|
||||
.tl-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
margin-top: 15px;
|
||||
box-shadow: 0 0 0 3px var(--td-bg-color-container);
|
||||
}
|
||||
|
||||
.tl-dot .tl-spin {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tl-line {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* --- Content --- */
|
||||
.tl-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
padding: 6px 10px;
|
||||
margin: 2px 0;
|
||||
border-radius: 6px;
|
||||
transition: background 0.15s;
|
||||
}
|
||||
|
||||
.timeline-item:hover .tl-content {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
}
|
||||
|
||||
.tl-header {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.tl-status {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.tl-time {
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.tl-duration {
|
||||
margin-left: auto;
|
||||
font-size: 11px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
/* --- Pills --- */
|
||||
.tl-pills {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.pill {
|
||||
font-size: 11px;
|
||||
padding: 0 5px;
|
||||
border-radius: 3px;
|
||||
font-weight: 500;
|
||||
line-height: 18px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.pill.created { background: var(--td-success-color-1); color: var(--td-success-color); }
|
||||
.pill.updated { background: var(--td-brand-color-light); color: var(--td-brand-color); }
|
||||
.pill.deleted { background: var(--td-warning-color-1); color: var(--td-warning-color); }
|
||||
.pill.skipped { background: var(--td-bg-color-component); color: var(--td-text-color-placeholder); }
|
||||
.pill.failed { background: var(--td-error-color-1); color: var(--td-error-color); }
|
||||
|
||||
/* --- Expanded detail --- */
|
||||
.tl-detail {
|
||||
margin-top: 8px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px dashed var(--td-border-level-2-color);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.detail-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.detail-label {
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.tl-error {
|
||||
margin-top: 6px;
|
||||
padding: 6px 8px;
|
||||
border-radius: 4px;
|
||||
background: var(--td-error-color-1);
|
||||
color: var(--td-error-color);
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
/* --- Drawer overrides --- */
|
||||
.ds-logs-drawer :deep(.t-drawer__header) {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
padding: 16px 24px;
|
||||
border-bottom: 1px solid var(--td-border-level-2-color);
|
||||
}
|
||||
|
||||
.ds-logs-drawer :deep(.t-drawer__body) {
|
||||
padding: 16px 20px;
|
||||
}
|
||||
</style>
|
||||
@@ -611,8 +611,8 @@ onMounted(async () => {
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
flex: 0 0 40%;
|
||||
max-width: 40%;
|
||||
padding-right: 24px;
|
||||
|
||||
label {
|
||||
@@ -632,8 +632,8 @@ onMounted(async () => {
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 280px;
|
||||
flex: 0 0 55%;
|
||||
max-width: 55%;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
|
||||
@@ -129,8 +129,8 @@ const handleQuestionGenerationChange = () => {
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
flex: 0 0 40%;
|
||||
max-width: 40%;
|
||||
padding-right: 24px;
|
||||
|
||||
label {
|
||||
@@ -157,8 +157,8 @@ const handleQuestionGenerationChange = () => {
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 280px;
|
||||
flex: 0 0 55%;
|
||||
max-width: 55%;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
|
||||
@@ -250,8 +250,8 @@ const emitUpdate = () => {
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
flex: 0 0 40%;
|
||||
max-width: 40%;
|
||||
padding-right: 24px;
|
||||
|
||||
label {
|
||||
@@ -271,8 +271,8 @@ const emitUpdate = () => {
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 280px;
|
||||
flex: 0 0 55%;
|
||||
max-width: 55%;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
|
||||
@@ -153,8 +153,8 @@ const handleAddModel = (subSection: string) => {
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
flex: 0 0 40%;
|
||||
max-width: 40%;
|
||||
padding-right: 24px;
|
||||
|
||||
label {
|
||||
@@ -179,8 +179,8 @@ const handleAddModel = (subSection: string) => {
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 280px;
|
||||
flex: 0 0 55%;
|
||||
max-width: 55%;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: flex-start;
|
||||
|
||||
@@ -335,8 +335,8 @@ watch(() => props.parserEngineRules, (v) => {
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
flex: 0 0 40%;
|
||||
max-width: 40%;
|
||||
padding-right: 24px;
|
||||
|
||||
.group-label {
|
||||
@@ -386,8 +386,8 @@ watch(() => props.parserEngineRules, (v) => {
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 280px;
|
||||
flex: 0 0 55%;
|
||||
max-width: 55%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
|
||||
@@ -315,7 +315,7 @@ onMounted(async () => {
|
||||
.section-title {
|
||||
margin: 0 0 8px 0;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 16px;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
@@ -340,7 +340,7 @@ onMounted(async () => {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
@@ -382,7 +382,7 @@ onMounted(async () => {
|
||||
|
||||
.shares-title {
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
@@ -208,8 +208,8 @@ onMounted(load)
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
flex: 0 0 40%;
|
||||
max-width: 40%;
|
||||
padding-right: 24px;
|
||||
|
||||
label {
|
||||
@@ -229,8 +229,8 @@ onMounted(load)
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 280px;
|
||||
flex: 0 0 55%;
|
||||
max-width: 55%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
|
||||
Reference in New Issue
Block a user