fix(knowledge-base): 优化知识库页面,重构后端job队列
This commit is contained in:
1 parent
7e4a2037d8
commit
b476b58a91
38 files changed
+992
-428
No files matched your search
@@ -77,9 +77,9 @@ export function createKbWorkspaceState(options: CreateKbWorkspaceStateOptions =
|
||||
const failureModalPage = ref(1);
|
||||
const retryingFailureKey = ref('');
|
||||
|
||||
const documentStageFilter = ref<'all' | 'upload' | 'clean' | 'sync'>('all');
|
||||
const documentStageFilter = ref<'all' | 'pending_clean' | 'cleaning' | 'pending_sync' | 'failed'>('all');
|
||||
const documentListPage = ref(1);
|
||||
const documentListPageSize = ref(20);
|
||||
const documentListPageSize = ref(10);
|
||||
const documentKeyword = ref('');
|
||||
const batchSubmitting = ref(false);
|
||||
const selectedDocumentIds = ref<number[]>([]);
|
||||
|
||||
@@ -98,17 +98,20 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
|
||||
const matchesDocumentStageFilter = (
|
||||
doc: KbDocumentItem,
|
||||
filter: 'all' | 'upload' | 'clean' | 'sync',
|
||||
filter: 'all' | 'pending_clean' | 'cleaning' | 'pending_sync' | 'failed',
|
||||
) => {
|
||||
const workflow = resolveWorkflowState(doc);
|
||||
if (filter === 'all') return true;
|
||||
if (filter === 'upload') {
|
||||
return workflow.upload.code !== 'success';
|
||||
if (filter === 'pending_clean') {
|
||||
return workflow.clean.code === 'pending';
|
||||
}
|
||||
if (filter === 'clean') {
|
||||
return ['pending', 'queued', 'running', 'failed'].includes(workflow.clean.code);
|
||||
if (filter === 'cleaning') {
|
||||
return ['queued', 'running'].includes(workflow.clean.code);
|
||||
}
|
||||
return ['pending', 'running', 'failed'].includes(workflow.sync.code);
|
||||
if (filter === 'pending_sync') {
|
||||
return workflow.sync.code === 'pending';
|
||||
}
|
||||
return [workflow.upload.code, workflow.clean.code, workflow.sync.code].includes('failed');
|
||||
};
|
||||
|
||||
const matchesDocumentKeyword = (doc: KbDocumentItem, keyword: string) => {
|
||||
@@ -125,11 +128,12 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
};
|
||||
|
||||
const stageFilterTabs = computed(() => {
|
||||
const filters: Array<{ key: 'all' | 'upload' | 'clean' | 'sync'; label: string }> = [
|
||||
const filters: Array<{ key: 'all' | 'pending_clean' | 'cleaning' | 'pending_sync' | 'failed'; label: string }> = [
|
||||
{ key: 'all', label: t('kbWorkspace.filters.all') },
|
||||
{ key: 'upload', label: t('kbWorkspace.filters.upload') },
|
||||
{ key: 'clean', label: t('kbWorkspace.filters.clean') },
|
||||
{ key: 'sync', label: t('kbWorkspace.filters.sync') },
|
||||
{ key: 'pending_clean', label: t('kbWorkspace.filters.pendingClean') },
|
||||
{ key: 'cleaning', label: t('kbWorkspace.filters.cleaning') },
|
||||
{ key: 'pending_sync', label: t('kbWorkspace.filters.pendingSync') },
|
||||
{ key: 'failed', label: t('kbWorkspace.filters.failed') },
|
||||
];
|
||||
return filters.map((item) => ({
|
||||
...item,
|
||||
|
||||
@@ -46,6 +46,7 @@ export function useKbWorkspaceData(
|
||||
selectedDocumentIds,
|
||||
showPathUploadDetails,
|
||||
selectedPathUploadHistoryJobId,
|
||||
router,
|
||||
} = state;
|
||||
|
||||
const { t } = state;
|
||||
@@ -189,6 +190,9 @@ export function useKbWorkspaceData(
|
||||
};
|
||||
|
||||
const openGroupDetail = async (groupId: number) => {
|
||||
if (viewMode.value === 'group_overview') {
|
||||
await router.push({ name: 'workspace-knowledge-base-group', params: { groupId } });
|
||||
}
|
||||
selectedGroupId.value = groupId;
|
||||
viewMode.value = 'group_detail';
|
||||
feedback.value = '';
|
||||
@@ -197,6 +201,9 @@ export function useKbWorkspaceData(
|
||||
};
|
||||
|
||||
const backToGroupOverview = () => {
|
||||
if (viewMode.value === 'group_detail') {
|
||||
void router.push({ name: 'workspace-knowledge-base' });
|
||||
}
|
||||
viewMode.value = 'group_overview';
|
||||
selectedGroupId.value = null;
|
||||
documents.value = [];
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* features/kb/composables/useKbWorkspace.ts
|
||||
* 知识库作业面编排入口:组合 state / computed / data / pathUpload / documents / modals。
|
||||
*/
|
||||
import { onMounted, onUnmounted, reactive, watch } from 'vue';
|
||||
import { computed as vueComputed, onMounted, onUnmounted, reactive, watch } from 'vue';
|
||||
import {
|
||||
DOCUMENT_PAGE_SIZE_OPTIONS,
|
||||
FAILURE_PAGE_SIZE,
|
||||
@@ -76,6 +76,29 @@ export function useKbWorkspace(options: UseKbWorkspaceOptions = {}) {
|
||||
} = computed;
|
||||
|
||||
const { applyPathUploadJob } = pathUpload;
|
||||
const routeGroupId = vueComputed(() => {
|
||||
const raw = state.router.currentRoute.value.params.groupId;
|
||||
const value = Array.isArray(raw) ? raw[0] : raw;
|
||||
const parsed = Number(value);
|
||||
return Number.isInteger(parsed) && parsed > 0 ? parsed : null;
|
||||
});
|
||||
|
||||
const syncViewModeFromRoute = () => {
|
||||
const groupId = routeGroupId.value;
|
||||
if (groupId) {
|
||||
state.viewMode.value = 'group_detail';
|
||||
if (selectedGroupId.value !== groupId) {
|
||||
selectedGroupId.value = groupId;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (state.embedded) {
|
||||
state.viewMode.value = 'group_overview';
|
||||
if (selectedGroupId.value !== null) {
|
||||
selectedGroupId.value = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// --- 筛选/分页/路径上传历史联动 ---
|
||||
watch(selectedGroupId, (groupId) => {
|
||||
@@ -90,6 +113,10 @@ export function useKbWorkspace(options: UseKbWorkspaceOptions = {}) {
|
||||
applyPathUploadJob(latestPathUploadJob.value);
|
||||
});
|
||||
|
||||
watch(routeGroupId, () => {
|
||||
syncViewModeFromRoute();
|
||||
});
|
||||
|
||||
watch(documentStageFilter, () => {
|
||||
documentListPage.value = 1;
|
||||
});
|
||||
@@ -117,6 +144,7 @@ export function useKbWorkspace(options: UseKbWorkspaceOptions = {}) {
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
syncViewModeFromRoute();
|
||||
await Promise.all([data.loadGroups(), data.loadJobs()]);
|
||||
if (state.viewMode.value === 'group_detail') {
|
||||
await data.loadDocuments(selectedGroupId.value);
|
||||
|
||||
@@ -52,7 +52,7 @@ export const FAILURE_PAGE_SIZE = 15;
|
||||
export const PATH_UPLOAD_BATCH_SIZE = 30;
|
||||
export const PATH_UPLOAD_BATCH_INTERVAL_MS = 500;
|
||||
export const PATH_UPLOAD_CONCURRENCY = 3;
|
||||
export const DOCUMENT_PAGE_SIZE_OPTIONS = [20, 50, 100, 200] as const;
|
||||
export const DOCUMENT_PAGE_SIZE_OPTIONS = [10, 20, 50, 100] as const;
|
||||
|
||||
/** 未开始阶段的徽标样式,与 getStatusBadgeClass 默认一致 */
|
||||
export const IDLE_BADGE_CLASS = 'border-default bg-surface-soft text-muted';
|
||||
@@ -46,11 +46,12 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<button
|
||||
v-if="kb.viewMode !== 'group_overview'"
|
||||
@click="kb.refreshCurrentView"
|
||||
class="btn-secondary"
|
||||
>
|
||||
<RefreshCw class="h-4 w-4" />
|
||||
{{ kb.viewMode === 'group_overview' ? kb.t('kbWorkspace.actions.refreshGroups') : kb.t('kbWorkspace.actions.refreshDocuments') }}
|
||||
{{ kb.t('kbWorkspace.actions.refreshDocuments') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.viewMode === 'group_overview'"
|
||||
@@ -66,9 +67,8 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
|
||||
<template v-if="kb.viewMode === 'group_overview'">
|
||||
<section class="kb-ws-section">
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<div class="mb-4 flex items-center">
|
||||
<h2 class="text-lg font-semibold text-primary">{{ kb.t('kbWorkspace.overview.title') }}</h2>
|
||||
<span class="text-xs text-muted">`/api/kb/groups`</span>
|
||||
</div>
|
||||
<div v-if="kb.isLoading" class="py-10 text-center text-sm text-muted">{{ kb.t('kbWorkspace.overview.loadingGroups') }}</div>
|
||||
<div v-else-if="kb.groups.length === 0" class="kb-ws-empty py-10 text-center text-sm text-muted">
|
||||
@@ -101,29 +101,6 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="kb-ws-stat-grid">
|
||||
<div
|
||||
v-for="item in kb.groupSummaryItems"
|
||||
:key="item.label"
|
||||
class="kb-ws-stat-tile "
|
||||
:class="[
|
||||
item.wide ? 'col-span-2 xl:col-span-2' : '',
|
||||
item.clickable
|
||||
? 'cursor-pointer hover:bg-rose-50 hover:bg-rose-50'
|
||||
: '',
|
||||
]"
|
||||
@click="item.clickable && item.failureType ? kb.openFailureModal(item.failureType) : undefined"
|
||||
>
|
||||
<div
|
||||
class="text-base font-semibold text-primary break-words"
|
||||
:style="item.wide ? '-webkit-line-clamp: 2; -webkit-box-orient: vertical; display: -webkit-box; overflow: hidden;' : undefined"
|
||||
>
|
||||
{{ item.value }}
|
||||
</div>
|
||||
<div class="mt-1 text-xs text-muted">{{ item.label }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 gap-6 lg:grid-cols-[320px_minmax(0,1fr)]">
|
||||
<input
|
||||
:ref="(el) => { kb.fileInputRef = el as HTMLInputElement | null }"
|
||||
type="file"
|
||||
@@ -140,54 +117,49 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
class="hidden"
|
||||
@change="kb.handlePathFilesSelected"
|
||||
/>
|
||||
<section class="kb-ws-section">
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<h2 class="text-lg font-semibold text-primary">{{ kb.t('kbWorkspace.sidebar.groupsTitle') }}</h2>
|
||||
</div>
|
||||
|
||||
<div v-if="kb.isLoading" class="py-10 text-center text-sm text-muted">{{ kb.t('kbWorkspace.sidebar.loadingGroups') }}</div>
|
||||
<div v-else-if="kb.groups.length === 0" class="rounded-2xl border border-dashed border-default px-4 py-8 text-center text-sm text-muted ">
|
||||
{{ kb.t('kbWorkspace.sidebar.emptyGroups') }}
|
||||
</div>
|
||||
<div v-else class="space-y-3">
|
||||
<button
|
||||
v-for="group in kb.groups"
|
||||
:key="group.id"
|
||||
@click="kb.selectedGroupId = group.id"
|
||||
class="kb-ws-group-list-btn"
|
||||
:class="{ 'kb-ws-group-list-btn--active': kb.selectedGroupId === group.id }"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="truncate font-semibold">{{ group.name }}</div>
|
||||
<div class="mt-1 text-sm opacity-80">{{ group.description || kb.t('kbWorkspace.sidebar.noDescription') }}</div>
|
||||
</div>
|
||||
<span class="rounded-full bg-surface/70 px-2 py-1 text-xs ">
|
||||
{{ group.document_count ?? 0 }}
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="space-y-6">
|
||||
<div class="kb-ws-section">
|
||||
<div class="flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between">
|
||||
<div class="min-w-0">
|
||||
<div class="text-xs font-medium text-muted">{{ kb.t('kbWorkspace.summary.currentGroup') }}</div>
|
||||
<h2 class="mt-1 text-2xl font-bold text-primary break-words">{{ kb.selectedGroup?.name || '--' }}</h2>
|
||||
<p class="mt-2 max-w-3xl text-sm text-muted">
|
||||
{{ kb.selectedGroup?.description || kb.t('kbWorkspace.overview.noDescription') }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="grid min-w-full grid-cols-2 gap-2 sm:grid-cols-5 lg:min-w-[520px]">
|
||||
<button
|
||||
v-for="item in kb.groupSummaryItems.filter((summary) => !summary.wide)"
|
||||
:key="item.label"
|
||||
type="button"
|
||||
class="rounded-2xl border border-default bg-surface-soft px-3 py-3 text-left transition-colors"
|
||||
:class="item.clickable ? 'hover:border-rose-200 hover:bg-rose-50' : ''"
|
||||
@click="item.clickable && item.failureType ? kb.openFailureModal(item.failureType) : undefined"
|
||||
>
|
||||
<div class="text-lg font-semibold text-primary">{{ item.value }}</div>
|
||||
<div class="mt-1 text-xs text-muted">{{ item.label }}</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="kb-ws-section">
|
||||
<div class="mb-4 space-y-3">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div class="flex items-center gap-2">
|
||||
<h2 class="text-lg font-semibold text-primary">{{ kb.t('kbWorkspace.documents.title') }}</h2>
|
||||
<div class="group relative">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex h-6 w-6 items-center justify-center rounded-full border border-default text-muted transition-colors hover:border-brand-300 hover:text-brand-500 hover:border-brand-300 hover:text-brand-600"
|
||||
>
|
||||
<Info class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
<div class="pointer-events-none absolute left-0 top-8 z-10 hidden w-80 rounded-2xl border border-default bg-surface px-4 py-3 text-sm text-muted shadow-xl group-hover:block">
|
||||
{{ kb.t('kbWorkspace.documents.infoTip') }}
|
||||
<h2 class="text-lg font-semibold text-primary">{{ kb.t('kbWorkspace.documents.title') }}</h2>
|
||||
<div class="group relative">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex h-6 w-6 items-center justify-center rounded-full border border-default text-muted transition-colors hover:border-brand-300 hover:text-brand-600"
|
||||
>
|
||||
<Info class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
<div class="pointer-events-none absolute left-0 top-8 z-10 hidden w-80 rounded-2xl border border-default bg-surface px-4 py-3 text-sm text-muted shadow-xl group-hover:block">
|
||||
{{ kb.t('kbWorkspace.documents.infoTip') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<button
|
||||
v-if="kb.selectedGroupId"
|
||||
@@ -209,62 +181,6 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<button
|
||||
v-if="kb.isKbAdmin && kb.selectedGroupId"
|
||||
@click="kb.handleBatchClean"
|
||||
:disabled="kb.batchSubmitting || kb.selectedDocuments.length === 0"
|
||||
class="inline-flex items-center gap-2 rounded-2xl border border-amber-200 px-4 py-2.5 text-sm font-medium text-amber-700 transition-colors hover:bg-amber-50 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
<RefreshCw class="h-4 w-4" />
|
||||
{{ kb.batchActionLabel('clean', kb.batchSubmitting, kb.selectedDocuments.length) }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.isKbAdmin && kb.selectedGroupId"
|
||||
@click="kb.handleBatchSync"
|
||||
:disabled="kb.batchSubmitting || kb.selectedDocuments.length === 0"
|
||||
class="inline-flex items-center gap-2 rounded-2xl border border-emerald-200 px-4 py-2.5 text-sm font-medium text-emerald-700 transition-colors hover:bg-emerald-50 disabled:cursor-not-allowed disabled:opacity-60 border-emerald-200"
|
||||
>
|
||||
<RefreshCw class="h-4 w-4" />
|
||||
{{ kb.batchActionLabel('sync', kb.batchSubmitting, kb.selectedDocuments.length) }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.selectedGroupId"
|
||||
@click="kb.handleBatchDelete"
|
||||
:disabled="kb.batchSubmitting || kb.selectedDocuments.length === 0"
|
||||
class="inline-flex items-center gap-2 rounded-2xl border border-rose-200 px-4 py-2.5 text-sm font-medium text-rose-600 transition-colors hover:bg-rose-50 disabled:cursor-not-allowed disabled:opacity-60 border-rose-200 hover:bg-rose-50"
|
||||
>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
{{ kb.batchActionLabel('delete', kb.batchSubmitting, kb.selectedDocuments.length) }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.selectedGroupId"
|
||||
@click="kb.openPathUploadHistoryModal()"
|
||||
class="btn-secondary"
|
||||
>
|
||||
<FileText class="h-4 w-4" />
|
||||
{{ kb.t('kbWorkspace.documents.historyBatches') }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="kb.selectedGroupId" class="flex flex-wrap items-center gap-3">
|
||||
<label class="relative w-full max-w-md">
|
||||
<Search class="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted" />
|
||||
<input
|
||||
v-model.trim="kb.documentKeyword"
|
||||
type="text"
|
||||
class="w-full rounded-2xl border border-default bg-surface py-2.5 pl-10 pr-4 text-sm text-primary outline-none transition-colors focus:border-brand-300"
|
||||
:placeholder="kb.t('kbWorkspace.documents.searchPlaceholder')"
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
v-if="kb.documentKeyword"
|
||||
type="button"
|
||||
@click="kb.documentKeyword = ''"
|
||||
class="inline-flex items-center rounded-xl border border-default px-3 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
>
|
||||
{{ kb.t('kbWorkspace.documents.clearSearch') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p
|
||||
@@ -373,41 +289,99 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
</div>
|
||||
<div
|
||||
v-if="kb.selectedGroupId"
|
||||
class="mb-4 flex flex-wrap items-center justify-between gap-3 rounded-2xl bg-surface-soft px-4 py-3 "
|
||||
>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
@click="kb.toggleSelectAllFiltered"
|
||||
class="inline-flex items-center gap-2 rounded-full border border-default bg-surface px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
{{ kb.isAllFilteredSelected ? kb.t('kbWorkspace.pathUpload.deselectAllFiltered') : kb.t('kbWorkspace.pathUpload.selectAllFiltered') }}
|
||||
</button>
|
||||
<button
|
||||
v-for="tab in kb.stageFilterTabs"
|
||||
:key="tab.key"
|
||||
@click="kb.documentStageFilter = tab.key"
|
||||
class="inline-flex items-center gap-2 rounded-full border px-4 py-2 text-sm font-medium transition-colors"
|
||||
:class="kb.documentStageFilter === tab.key
|
||||
? 'border-brand-200 bg-brand-50 text-brand-700 border-brand-200 '
|
||||
: 'border-default bg-surface text-secondary hover:bg-surface-soft hover-surface-soft'"
|
||||
>
|
||||
<span>{{ tab.label }}</span>
|
||||
<span class="rounded-full bg-surface-soft px-2 py-0.5 text-xs ">{{ tab.count }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3 text-sm text-muted">
|
||||
<label class="inline-flex items-center gap-2">
|
||||
<span>{{ kb.t('kbWorkspace.common.perPage') }}</span>
|
||||
<select
|
||||
v-model.number="kb.documentListPageSize"
|
||||
class="rounded-xl border border-default bg-surface px-3 py-1.5 text-sm text-secondary outline-none transition-colors focus:border-brand-300"
|
||||
class="mb-4 space-y-3 rounded-2xl bg-surface-soft px-4 py-3"
|
||||
>
|
||||
<div class="flex flex-col gap-3 xl:flex-row xl:items-center xl:justify-between">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
v-for="tab in kb.stageFilterTabs"
|
||||
:key="tab.key"
|
||||
@click="kb.documentStageFilter = tab.key"
|
||||
class="inline-flex items-center gap-2 rounded-full border px-4 py-2 text-sm font-medium transition-colors"
|
||||
:class="kb.documentStageFilter === tab.key
|
||||
? 'border-brand-200 bg-brand-50 text-brand-700'
|
||||
: 'border-default bg-surface text-secondary hover:bg-surface-soft'"
|
||||
>
|
||||
<option v-for="size in kb.DOCUMENT_PAGE_SIZE_OPTIONS" :key="size" :value="size">{{ size }}</option>
|
||||
</select>
|
||||
<span>{{ kb.t('kbWorkspace.common.countUnit') }}</span>
|
||||
</label>
|
||||
<span>{{ kb.t('kbWorkspace.documents.selectedCount', { selected: kb.selectedDocuments.length, total: kb.filteredDocuments.length }) }}</span>
|
||||
<span v-if="kb.filteredDocuments.length > 0">{{ kb.t('kbWorkspace.documents.showingRange', { start: kb.pagedDocumentRange.start, end: kb.pagedDocumentRange.end }) }}</span>
|
||||
<span>{{ tab.label }}</span>
|
||||
<span class="rounded-full bg-surface-soft px-2 py-0.5 text-xs">{{ tab.count }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3 text-sm text-muted">
|
||||
<label class="relative min-w-[260px] flex-1 xl:w-80 xl:flex-none">
|
||||
<Search class="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted" />
|
||||
<input
|
||||
v-model.trim="kb.documentKeyword"
|
||||
type="text"
|
||||
class="w-full rounded-2xl border border-default bg-surface py-2.5 pl-10 pr-4 text-sm text-primary outline-none transition-colors focus:border-brand-300"
|
||||
:placeholder="kb.t('kbWorkspace.documents.searchPlaceholder')"
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
v-if="kb.documentKeyword"
|
||||
type="button"
|
||||
@click="kb.documentKeyword = ''"
|
||||
class="inline-flex items-center rounded-xl border border-default bg-surface px-3 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
>
|
||||
{{ kb.t('kbWorkspace.documents.clearSearch') }}
|
||||
</button>
|
||||
<label class="inline-flex items-center gap-2">
|
||||
<span>{{ kb.t('kbWorkspace.common.perPage') }}</span>
|
||||
<select
|
||||
v-model.number="kb.documentListPageSize"
|
||||
class="rounded-xl border border-default bg-surface px-3 py-1.5 text-sm text-secondary outline-none transition-colors focus:border-brand-300"
|
||||
>
|
||||
<option v-for="size in kb.DOCUMENT_PAGE_SIZE_OPTIONS" :key="size" :value="size">{{ size }}</option>
|
||||
</select>
|
||||
<span>{{ kb.t('kbWorkspace.common.countUnit') }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-3 border-t border-default pt-3 lg:flex-row lg:items-center lg:justify-between">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
@click="kb.toggleSelectAllFiltered"
|
||||
class="inline-flex items-center gap-2 rounded-full border border-default bg-surface px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
>
|
||||
{{ kb.isAllFilteredSelected ? kb.t('kbWorkspace.pathUpload.deselectAllFiltered') : kb.t('kbWorkspace.pathUpload.selectAllFiltered') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.isKbAdmin"
|
||||
@click="kb.handleBatchClean"
|
||||
:disabled="kb.batchSubmitting || kb.selectedDocuments.length === 0"
|
||||
class="inline-flex items-center gap-2 rounded-full border border-amber-200 bg-surface px-4 py-2 text-sm font-medium text-amber-700 transition-colors hover:bg-amber-50 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
<RefreshCw class="h-4 w-4" />
|
||||
{{ kb.batchActionLabel('clean', kb.batchSubmitting, kb.selectedDocuments.length) }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.isKbAdmin"
|
||||
@click="kb.handleBatchSync"
|
||||
:disabled="kb.batchSubmitting || kb.selectedDocuments.length === 0"
|
||||
class="inline-flex items-center gap-2 rounded-full border border-emerald-200 bg-surface px-4 py-2 text-sm font-medium text-emerald-700 transition-colors hover:bg-emerald-50 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
<RefreshCw class="h-4 w-4" />
|
||||
{{ kb.batchActionLabel('sync', kb.batchSubmitting, kb.selectedDocuments.length) }}
|
||||
</button>
|
||||
<button
|
||||
@click="kb.handleBatchDelete"
|
||||
:disabled="kb.batchSubmitting || kb.selectedDocuments.length === 0"
|
||||
class="inline-flex items-center gap-2 rounded-full border border-rose-200 bg-surface px-4 py-2 text-sm font-medium text-rose-600 transition-colors hover:bg-rose-50 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
{{ kb.batchActionLabel('delete', kb.batchSubmitting, kb.selectedDocuments.length) }}
|
||||
</button>
|
||||
<button
|
||||
@click="kb.openPathUploadHistoryModal()"
|
||||
class="inline-flex items-center gap-2 rounded-full border border-default bg-surface px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
>
|
||||
<FileText class="h-4 w-4" />
|
||||
{{ kb.t('kbWorkspace.documents.historyBatches') }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3 text-sm text-muted">
|
||||
<span>{{ kb.t('kbWorkspace.documents.selectedCount', { selected: kb.selectedDocuments.length, total: kb.filteredDocuments.length }) }}</span>
|
||||
<span v-if="kb.filteredDocuments.length > 0">{{ kb.t('kbWorkspace.documents.showingRange', { start: kb.pagedDocumentRange.start, end: kb.pagedDocumentRange.end }) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -424,13 +398,13 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
<div
|
||||
v-for="doc in kb.pagedFilteredDocuments"
|
||||
:key="doc.id"
|
||||
class="rounded-2xl border px-4 py-4 transition-colors"
|
||||
class="rounded-2xl border px-4 py-3 transition-colors"
|
||||
:class="kb.selectedDocumentId === doc.id
|
||||
? 'border-brand-200 bg-brand-50/50 border-brand-200'
|
||||
: 'border-default'"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="flex min-w-0 flex-1 gap-3">
|
||||
<div class="grid gap-3 xl:grid-cols-[minmax(0,1.3fr)_minmax(360px,0.9fr)_auto] xl:items-center">
|
||||
<div class="flex min-w-0 gap-3">
|
||||
<label class="mt-1 inline-flex shrink-0 cursor-pointer items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
@@ -440,35 +414,53 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
/>
|
||||
</label>
|
||||
<div class="min-w-0 flex-1">
|
||||
<button
|
||||
@click="kb.openMarkdownEditor(doc)"
|
||||
class="block max-w-full truncate text-left font-semibold text-primary transition-colors hover:text-brand-600 hover:text-brand-600"
|
||||
>
|
||||
{{ kb.getDocumentDisplayTitle(doc) }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
@click="kb.openSourceInfo(doc)"
|
||||
class="mt-1 block max-w-full text-left text-sm text-muted transition-colors hover:text-brand-600 hover:text-brand-600"
|
||||
>
|
||||
{{ kb.getDocumentDisplayDescription(doc) }}
|
||||
</button>
|
||||
<div class="mt-2 text-xs text-muted">
|
||||
<span>{{ kb.t('kbWorkspace.documents.versionCount', { count: doc.version_count ?? 0 }) }}</span>
|
||||
<span v-if="doc.latest_version">
|
||||
<span>{{ kb.t('kbWorkspace.documents.currentVersion', { version: doc.latest_version.version_no }) }}</span>
|
||||
<button
|
||||
@click="kb.openMarkdownEditor(doc)"
|
||||
class="block max-w-full truncate text-left font-semibold text-primary transition-colors hover:text-brand-600 hover:text-brand-600"
|
||||
>
|
||||
{{ kb.getDocumentDisplayTitle(doc) }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
@click="kb.openSourceInfo(doc)"
|
||||
class="mt-1 block max-w-full truncate text-left text-sm text-muted transition-colors hover:text-brand-600 hover:text-brand-600"
|
||||
>
|
||||
{{ kb.getDocumentDisplayDescription(doc) }}
|
||||
</button>
|
||||
<div class="mt-2 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted">
|
||||
<span>{{ kb.t('kbWorkspace.documents.versionCount', { count: doc.version_count ?? 0 }) }}</span>
|
||||
<span v-if="doc.latest_version">{{ kb.t('kbWorkspace.documents.currentVersion', { version: doc.latest_version.version_no }) }}</span>
|
||||
<button
|
||||
v-if="doc.latest_version"
|
||||
type="button"
|
||||
@click="kb.openSourceInfo(doc)"
|
||||
class="inline text-xs text-muted underline-offset-2 transition-colors hover:text-brand-600 hover:underline hover:text-brand-600"
|
||||
>
|
||||
class="max-w-full truncate text-xs text-muted underline-offset-2 transition-colors hover:text-brand-600 hover:underline hover:text-brand-600"
|
||||
>
|
||||
{{ doc.latest_version.source_file_name }}
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
<span>{{ kb.t('kbWorkspace.documents.updatedAt', { time: kb.formatDateTime(doc.updated_at) }) }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="kb.getDocumentWorkflowState(doc).primaryError"
|
||||
class="mt-1 max-w-xl text-xs text-rose-500"
|
||||
>
|
||||
{{ kb.t('kbWorkspace.common.failureReason', { reason: kb.getDocumentWorkflowState(doc).primaryError }) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2 xl:justify-end">
|
||||
<div
|
||||
v-for="badge in kb.getWorkflowBadges(doc)"
|
||||
:key="`${doc.id}-${badge.label}`"
|
||||
class="inline-flex items-center rounded-full border px-3 py-1 text-xs font-semibold"
|
||||
:class="badge.className"
|
||||
>
|
||||
{{ badge.label }}:{{ badge.value }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2 xl:justify-end">
|
||||
<button
|
||||
@click="kb.openDocumentDetail(doc.id)"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-violet-200 px-3 py-2 text-xs font-medium text-violet-700 transition-colors hover:bg-violet-50"
|
||||
@@ -501,32 +493,9 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 flex items-end justify-between gap-3 border-t border-default pt-3 ">
|
||||
<div class="space-y-1">
|
||||
<div class="text-xs text-muted">
|
||||
{{ kb.t('kbWorkspace.documents.updatedAt', { time: kb.formatDateTime(doc.updated_at) }) }}
|
||||
</div>
|
||||
<div
|
||||
v-if="kb.getDocumentWorkflowState(doc).primaryError"
|
||||
class="max-w-xl text-xs text-rose-500"
|
||||
>
|
||||
{{ kb.t('kbWorkspace.common.failureReason', { reason: kb.getDocumentWorkflowState(doc).primaryError }) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center justify-end gap-2">
|
||||
<div
|
||||
v-for="badge in kb.getWorkflowBadges(doc)"
|
||||
:key="`${doc.id}-${badge.label}`"
|
||||
class="inline-flex items-center rounded-full border px-3 py-1 text-sm font-semibold"
|
||||
:class="badge.className"
|
||||
>
|
||||
{{ badge.label }}:{{ badge.value }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="kb.filteredDocuments.length > kb.documentListPageSize"
|
||||
v-if="kb.filteredDocuments.length > 0"
|
||||
class="flex flex-wrap items-center justify-between gap-3 rounded-2xl border border-default px-4 py-3 "
|
||||
>
|
||||
<div class="text-sm text-muted">
|
||||
@@ -552,7 +521,6 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -6,11 +6,15 @@
|
||||
import { inject } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import {
|
||||
LayoutGrid, Bot, FileText, User, LogOut, Edit, Megaphone, Clock, Package,
|
||||
LayoutGrid, Bot, FileText, User, LogOut, Edit, Megaphone, Clock, Package, PanelLeftClose, PanelLeftOpen,
|
||||
} from 'lucide-vue-next';
|
||||
import { WORKSPACE_PATHS } from '../constants/routes';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
|
||||
defineProps<{
|
||||
collapsed?: boolean;
|
||||
}>();
|
||||
|
||||
const ws = inject(WORKSPACE_KEY)! as any;
|
||||
const route = useRoute();
|
||||
|
||||
@@ -30,54 +34,97 @@ function isActive(match: readonly string[]) {
|
||||
|
||||
<template>
|
||||
<aside class="lg:sticky lg:top-0 lg:h-screen">
|
||||
<div class="flex h-full flex-col border-r border-default bg-surface px-5 py-6 shadow-sm">
|
||||
<div class="border-b border-subtle pb-6">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="flex h-12 w-12 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-purple-600 text-white shadow-lg shadow-brand-500/25">
|
||||
<Bot class="h-6 w-6" />
|
||||
<div
|
||||
class="flex h-full flex-col border-r border-default bg-surface shadow-sm transition-all duration-200"
|
||||
:class="collapsed ? 'px-3 py-4' : 'px-4 py-4'"
|
||||
>
|
||||
<template v-if="collapsed">
|
||||
<button
|
||||
type="button"
|
||||
class="mb-6 inline-flex h-10 w-full items-center justify-center rounded-xl text-muted transition-colors hover:bg-surface-soft hover:text-secondary"
|
||||
:title="$t('workspace.expandSidebar')"
|
||||
@click="ws.toggleSidebarCollapsed"
|
||||
>
|
||||
<PanelLeftOpen class="h-5 w-5" />
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<div class="border-b border-subtle pb-4">
|
||||
<div class="flex items-center gap-3" :class="collapsed ? 'justify-center' : ''">
|
||||
<div class="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-sm font-bold text-white shadow-sm shadow-brand-500/25">
|
||||
AI
|
||||
</div>
|
||||
<div class="min-w-0">
|
||||
<div class="text-2xl font-extrabold tracking-tight text-primary">{{ $t('workspace.brandTitle') }}</div>
|
||||
<div class="truncate text-xs font-medium text-muted">
|
||||
<div v-if="!collapsed" class="min-w-0 flex-1">
|
||||
<div class="truncate text-lg font-bold text-primary">{{ $t('workspace.brandTitle') }}</div>
|
||||
<div class="mt-1 truncate text-[11px] text-muted">
|
||||
{{ ws.currentUser?.username }} / {{ ws.currentUser?.role }}
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
v-if="!collapsed"
|
||||
type="button"
|
||||
class="ml-2 inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-xl text-muted transition-colors hover:bg-surface-soft hover:text-secondary"
|
||||
:title="$t('workspace.collapseSidebar')"
|
||||
@click="ws.toggleSidebarCollapsed"
|
||||
>
|
||||
<PanelLeftClose class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 py-6">
|
||||
<div class="flex-1 py-4">
|
||||
<nav class="space-y-2">
|
||||
<RouterLink
|
||||
v-for="item in linkItems"
|
||||
:key="item.path"
|
||||
:to="item.path"
|
||||
class="ws-nav-btn"
|
||||
:class="{ 'ws-nav-btn--active': isActive(item.match) }"
|
||||
:class="[
|
||||
{ 'ws-nav-btn--active': isActive(item.match) },
|
||||
collapsed ? 'justify-center px-0' : '',
|
||||
]"
|
||||
:title="$t(item.labelKey)"
|
||||
>
|
||||
<component :is="item.icon" class="h-4 w-4" />
|
||||
<span>{{ $t(item.labelKey) }}</span>
|
||||
<component :is="item.icon" class="h-[18px] w-[18px]" />
|
||||
<span v-if="!collapsed">{{ $t(item.labelKey) }}</span>
|
||||
</RouterLink>
|
||||
<button
|
||||
type="button"
|
||||
class="ws-nav-btn w-full"
|
||||
:class="{ 'ws-nav-btn--active': isActive(['workspace-knowledge-base']) }"
|
||||
:class="[
|
||||
{ 'ws-nav-btn--active': isActive(['workspace-knowledge-base', 'workspace-knowledge-base-group']) },
|
||||
collapsed ? 'justify-center px-0' : '',
|
||||
]"
|
||||
:title="$t('workspace.nav.knowledgeBase')"
|
||||
@click="ws.navigateToKnowledgeBase"
|
||||
>
|
||||
<FileText class="h-4 w-4" />
|
||||
<span>{{ $t('workspace.nav.knowledgeBase') }}</span>
|
||||
<FileText class="h-[18px] w-[18px]" />
|
||||
<span v-if="!collapsed">{{ $t('workspace.nav.knowledgeBase') }}</span>
|
||||
</button>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="border-t border-subtle pt-6">
|
||||
<div class="border-t border-subtle pt-4">
|
||||
<div class="space-y-2">
|
||||
<button type="button" @click="ws.navigateToGeneralChat" class="ws-nav-btn">
|
||||
<Bot class="h-4 w-4" />
|
||||
<span>{{ $t('workspace.nav.backToChat') }}</span>
|
||||
<button
|
||||
type="button"
|
||||
@click="ws.navigateToGeneralChat"
|
||||
class="ws-nav-btn"
|
||||
:class="collapsed ? 'justify-center px-0' : ''"
|
||||
:title="$t('workspace.nav.backToChat')"
|
||||
>
|
||||
<Bot class="h-[18px] w-[18px]" />
|
||||
<span v-if="!collapsed">{{ $t('workspace.nav.backToChat') }}</span>
|
||||
</button>
|
||||
<button type="button" @click="ws.handleLogout" class="ws-nav-btn ws-nav-btn--danger">
|
||||
<LogOut class="h-4 w-4" />
|
||||
<span>{{ $t('workspace.nav.logout') }}</span>
|
||||
<button
|
||||
type="button"
|
||||
@click="ws.handleLogout"
|
||||
class="ws-nav-btn ws-nav-btn--danger"
|
||||
:class="collapsed ? 'justify-center px-0' : ''"
|
||||
:title="$t('workspace.nav.logout')"
|
||||
>
|
||||
<LogOut class="h-[18px] w-[18px]" />
|
||||
<span v-if="!collapsed">{{ $t('workspace.nav.logout') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -30,6 +30,7 @@ export function useWorkspace() {
|
||||
const deps = { t, locale, msg, router, route, setThemePreference, appliedTheme };
|
||||
const isLoading = ref(true);
|
||||
const currentUser = ref<WorkspaceUser | null>(null);
|
||||
const isSidebarCollapsed = ref(false);
|
||||
|
||||
const sessionRef: { handleLogout?: () => void } = {};
|
||||
const home = useWorkspaceHome(deps, {
|
||||
@@ -65,6 +66,7 @@ export function useWorkspace() {
|
||||
onMounted(async () => {
|
||||
window.addEventListener('hxops:logout', session.onAuthLogout);
|
||||
localeApi.loadLanguagePreference();
|
||||
isSidebarCollapsed.value = localStorage.getItem('hxops.workspace.sidebarCollapsed') === 'true';
|
||||
|
||||
session.loadAuthUser();
|
||||
if (!session.isLoggedIn.value) {
|
||||
@@ -88,6 +90,11 @@ export function useWorkspace() {
|
||||
window.removeEventListener('hxops:logout', session.onAuthLogout);
|
||||
});
|
||||
|
||||
const toggleSidebarCollapsed = () => {
|
||||
isSidebarCollapsed.value = !isSidebarCollapsed.value;
|
||||
localStorage.setItem('hxops.workspace.sidebarCollapsed', String(isSidebarCollapsed.value));
|
||||
};
|
||||
|
||||
return reactive({
|
||||
config,
|
||||
msg,
|
||||
@@ -95,6 +102,8 @@ export function useWorkspace() {
|
||||
route,
|
||||
isMobile,
|
||||
isLoading,
|
||||
isSidebarCollapsed,
|
||||
toggleSidebarCollapsed,
|
||||
...localeApi,
|
||||
...session,
|
||||
...home,
|
||||
|
||||
@@ -17,6 +17,7 @@ const ROUTE_NAME_TO_SIDEBAR: Record<string, WorkspaceSidebarItem> = {
|
||||
'workspace-applications': 'applications',
|
||||
'workspace-updates': 'updates',
|
||||
'workspace-knowledge-base': 'knowledge_base',
|
||||
'workspace-knowledge-base-group': 'knowledge_base',
|
||||
'workspace-schedule-runs': 'schedule_runs',
|
||||
'workspace-shipping-notice': 'shipping_notice',
|
||||
'workspace-feedback': 'feedback',
|
||||
@@ -173,7 +174,7 @@ export function useWorkspaceNavigation(deps: WorkspaceDeps, options: NavigationO
|
||||
if (name === 'workspace-schedule-runs') {
|
||||
await loadWorkspaceScheduleRuns();
|
||||
}
|
||||
if (name === 'workspace-knowledge-base' && !hasKnowledgeBaseAccess.value) {
|
||||
if (['workspace-knowledge-base', 'workspace-knowledge-base-group'].includes(name) && !hasKnowledgeBaseAccess.value) {
|
||||
showKnowledgeBaseAccessDenied();
|
||||
await router.replace(WORKSPACE_PATHS.applications);
|
||||
}
|
||||
|
||||
@@ -42,8 +42,11 @@ const mobileTabs = [
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="grid min-h-screen gap-0 lg:grid-cols-[232px_minmax(0,1fr)]">
|
||||
<WorkspaceSidebar v-if="!ws.isMobile" />
|
||||
<div
|
||||
class="grid min-h-screen gap-0 transition-[grid-template-columns] duration-200"
|
||||
:class="ws.isMobile ? '' : (ws.isSidebarCollapsed ? 'lg:grid-cols-[72px_minmax(0,1fr)]' : 'lg:grid-cols-[320px_minmax(0,1fr)]')"
|
||||
>
|
||||
<WorkspaceSidebar v-if="!ws.isMobile" :collapsed="ws.isSidebarCollapsed" />
|
||||
|
||||
<section class="ws-main" :class="ws.isMobile ? 'pb-20' : ''">
|
||||
<RouterView />
|
||||
|
||||
Reference in new issue
Block a user