fix(admin): 重构知识库配置布局

This commit is contained in:
sophie committed 2026-06-26 16:37:27 +08:00
1 parent 70d7435b5f
commit 25876f94bd
18 files changed
+556 -229

No files matched your search

@@ -41,6 +41,7 @@ const {
chatLogsColumns,
chatLogsSortRules,
isChatLogsTable,
showReportTable,
visibleReportKeys,
allReportRowsSelected,
paginatedSortedTableData,
@@ -240,10 +241,10 @@ onMounted(() => {
</div>
</div>
<div v-if="tableData.length === 0" class="text-center text-muted py-20 bg-surface-soft rounded-2xl border border-dashed border-default">
<div v-if="!showReportTable" class="text-center text-muted py-20 bg-surface-soft rounded-2xl border border-dashed border-default">
<p>{{ t('admin.report.noData', { table: getReportTableLabel(currentTable) }) }}</p>
</div>
<div v-else class="admin-report-table-wrap">
<table class="admin-report-table w-full border-collapse">
<thead>
@@ -289,6 +290,14 @@ onMounted(() => {
</tr>
</thead>
<tbody>
<tr v-if="paginatedSortedTableData.length === 0">
<td
:colspan="visibleReportKeys.length + (isChatLogsTable && showChatLogsSelection ? 1 : 0)"
class="text-center text-muted py-12"
>
{{ t('admin.report.noFilterResults') }}
</td>
</tr>
<tr v-for="(row, idx) in paginatedSortedTableData" :key="idx">
<td v-if="isChatLogsTable && showChatLogsSelection" class="px-4 py-3">
<input
@@ -314,7 +323,7 @@ onMounted(() => {
</table>
</div>
<div v-if="tableData.length > 0" class="flex flex-col gap-3 rounded-2xl border border-default bg-surface px-4 py-3 md:flex-row md:items-center md:justify-between">
<div v-if="showReportTable" class="flex flex-col gap-3 rounded-2xl border border-default bg-surface px-4 py-3 md:flex-row md:items-center md:justify-between">
<div class="text-sm text-secondary">
{{ t('admin.report.paginationSummary', { total: reportTotalRows, page: reportCurrentPage, pages: reportTotalPages }) }}
</div>
@@ -344,6 +344,10 @@ const handleFilterChange = () => {
};
const isChatLogsTable = computed(() => currentTable.value === 'chat_logs');
/** 列已初始化后(含筛选无结果)仍展示表头与筛选框,避免用户无法修改条件 */
const showReportTable = computed(
() => tableData.value.length > 0 || chatLogsColumns.value.length > 0,
);
const visibleReportKeys = computed(() => {
let keys: string[];
if (chatLogsColumns.value.length === 0) {
@@ -782,6 +786,7 @@ const batchDeleteChatLogs = async () => {
watch(currentTable, async () => {
columnFilters.value = {}; // Reset filters on table change
chatLogsColumns.value = [];
selectedReportRowIds.value = [];
showChatLogsColumnPanel.value = false;
showChatLogsSelection.value = false;
@@ -880,6 +885,7 @@ watch([reportPageSize, sortedTableData], () => {
reportHeaderSort,
draggingColumnKey,
isChatLogsTable,
showReportTable,
visibleReportKeys,
allReportRowsSelected,
sortedTableData,
@@ -2,15 +2,29 @@
/**
* features/kb/components/KbAdminPanel.vue
* 知识库配置面板(治理面:分组、Dify、任务队列)。
* 依赖:kb.api、DifySettingsDialog、DifyHealthDialog、DeleteConfirmDialog、Vue I18n。
* 逻辑:管理控制台加载知识库分组与任务队列;分组列表在主表格过滤排序,新增/编辑通过右侧抽屉提交。
*/
import { computed, onMounted, ref } from 'vue';
import { computed, onMounted, ref, watch } from 'vue';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { Activity, FolderPlus, Pencil, Play, Settings, Trash2, Wrench, X } from 'lucide-vue-next';
import {
Activity,
Pencil,
Plus,
RefreshCw,
Search,
Settings,
Trash2,
Wrench,
} from 'lucide-vue-next';
import KbGroupDrawer, { type KbGroupFormValue } from './KbGroupDrawer.vue';
import KbJobQueuePanel from './KbJobQueuePanel.vue';
import DifyHealthDialog from './DifyHealthDialog.vue';
import DifySettingsDialog from './DifySettingsDialog.vue';
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
import PaginationBar from '@/shared/components/PaginationBar.vue';
import { WORKSPACE_PATHS } from '@/features/workspace/constants/routes';
import {
createKbGroup,
@@ -23,72 +37,124 @@ import {
type KbJob,
} from '../api/kb.api';
type GroupFilterMode = 'all' | 'withDocs' | 'empty';
type GroupSortMode = 'updatedDesc' | 'updatedAsc' | 'docsDesc' | 'docsAsc' | 'nameAsc';
const router = useRouter();
const { t } = useI18n();
const groups = ref<KbGroup[]>([]);
const jobs = ref<KbJob[]>([]);
const isSubmitting = ref(false);
const isDeleting = ref(false);
const isRefreshing = ref(false);
const editingGroupId = ref<number | null>(null);
const form = ref({
name: '',
description: '',
});
const form = ref<KbGroupFormValue>({ name: '', description: '' });
const feedback = ref('');
const feedbackType = ref<'success' | 'error' | ''>('');
const runningJobId = ref<number | string | null>(null);
const settingsDialogOpen = ref(false);
const healthDialogOpen = ref(false);
const deleteDialogOpen = ref(false);
const drawerOpen = ref(false);
const deletingGroup = ref<KbGroup | null>(null);
const searchKeyword = ref('');
const filterMode = ref<GroupFilterMode>('all');
const sortMode = ref<GroupSortMode>('updatedDesc');
const currentPage = ref(1);
const pageSize = ref(20);
const formTitle = computed(() => editingGroupId.value ? t('kbAdmin.form.editTitle') : t('kbAdmin.form.createTitle'));
const formDescription = computed(() => editingGroupId.value
? t('kbAdmin.form.editDesc')
: t('kbAdmin.form.createDesc'));
const submitText = computed(() => {
if (isSubmitting.value) return editingGroupId.value ? t('kbAdmin.form.saving') : t('kbAdmin.form.submitting');
return editingGroupId.value ? t('kbAdmin.form.saveChanges') : t('kbAdmin.form.create');
const filterOptions: GroupFilterMode[] = ['all', 'withDocs', 'empty'];
const sortOptions: GroupSortMode[] = ['updatedDesc', 'updatedAsc', 'docsDesc', 'docsAsc', 'nameAsc'];
const pageSizeOptions = [10, 20, 50, 100];
const totalDocuments = computed(() => groups.value.reduce((total, group) => total + (group.document_count ?? 0), 0));
const filteredGroups = computed(() => {
const keyword = searchKeyword.value.trim().toLowerCase();
const matched = groups.value.filter((group) => {
const documentCount = group.document_count ?? 0;
const matchesKeyword = !keyword
|| group.name.toLowerCase().includes(keyword)
|| (group.description || '').toLowerCase().includes(keyword);
const matchesFilter = filterMode.value === 'all'
|| (filterMode.value === 'withDocs' && documentCount > 0)
|| (filterMode.value === 'empty' && documentCount === 0);
return matchesKeyword && matchesFilter;
});
return [...matched].sort((a, b) => {
const docsA = a.document_count ?? 0;
const docsB = b.document_count ?? 0;
const updatedA = Date.parse(a.updated_at || '') || 0;
const updatedB = Date.parse(b.updated_at || '') || 0;
if (sortMode.value === 'updatedAsc') return updatedA - updatedB;
if (sortMode.value === 'docsDesc') return docsB - docsA;
if (sortMode.value === 'docsAsc') return docsA - docsB;
if (sortMode.value === 'nameAsc') return a.name.localeCompare(b.name, undefined, { numeric: true });
return updatedB - updatedA;
});
});
const pagedGroups = computed(() => {
const start = (currentPage.value - 1) * pageSize.value;
return filteredGroups.value.slice(start, start + pageSize.value);
});
/** 加载知识库治理页的分组与任务队列,供页面初始渲染和操作后刷新复用。 */
const loadData = async () => {
isRefreshing.value = true;
const [groupsResult, jobsResult] = await Promise.all([getKbGroupsSafe(), getKbJobsSafe()]);
if (groupsResult.ok) {
groups.value = groupsResult.data;
} else {
if (groupsResult.ok) groups.value = groupsResult.data;
else {
feedback.value = groupsResult.error || t('kbAdmin.msg.loadGroupsFailed');
feedbackType.value = 'error';
}
if (jobsResult.ok) {
jobs.value = jobsResult.data;
} else {
if (jobsResult.ok) jobs.value = jobsResult.data;
else {
feedback.value = jobsResult.error || t('kbAdmin.msg.loadJobsFailed');
feedbackType.value = 'error';
}
isRefreshing.value = false;
};
/** 重置分组表单到新建状态,关闭抽屉或切换新建时清空当前编辑对象。 */
const resetForm = () => {
editingGroupId.value = null;
form.value = { name: '', description: '' };
};
const handleCreateGroup = async () => {
/** 打开新建抽屉,保持主列表当前位置和筛选条件不变。 */
const openCreateDrawer = () => {
resetForm();
feedback.value = '';
feedbackType.value = '';
drawerOpen.value = true;
};
/** 将列表中的分组带入右侧抽屉,避免大列表编辑时跳转到页面顶部。 */
const openEditDrawer = (group: KbGroup) => {
editingGroupId.value = group.id;
form.value = { name: group.name, description: group.description || '' };
feedback.value = '';
feedbackType.value = '';
drawerOpen.value = true;
};
/** 关闭分组抽屉并恢复表单,列表筛选和分页状态保留。 */
const closeDrawer = () => {
drawerOpen.value = false;
resetForm();
};
/** 提交分组新建或编辑;根据 editingGroupId 自动选择创建或更新接口。 */
const handleSubmitGroup = async () => {
if (!form.value.name.trim()) {
feedback.value = t('kbAdmin.msg.nameRequired');
feedbackType.value = 'error';
return;
}
isSubmitting.value = true;
const payload = {
name: form.value.name.trim(),
description: form.value.description.trim(),
};
const result = editingGroupId.value
? await updateKbGroup(editingGroupId.value, payload)
: await createKbGroup(payload);
const payload = { name: form.value.name.trim(), description: form.value.description.trim() };
const result = editingGroupId.value ? await updateKbGroup(editingGroupId.value, payload) : await createKbGroup(payload);
isSubmitting.value = false;
if (!result.ok) {
@@ -99,37 +165,29 @@ const handleCreateGroup = async () => {
feedback.value = editingGroupId.value ? t('kbAdmin.msg.updated') : t('kbAdmin.msg.created');
feedbackType.value = 'success';
resetForm();
closeDrawer();
await loadData();
};
const handleEditGroup = (group: KbGroup) => {
editingGroupId.value = group.id;
form.value = {
name: group.name,
description: group.description || '',
};
feedback.value = '';
feedbackType.value = '';
};
const handleDeleteGroup = async (group: KbGroup) => {
/** 打开分组删除确认弹窗,确认前不直接调用删除接口。 */
const handleDeleteGroup = (group: KbGroup) => {
deletingGroup.value = group;
deleteDialogOpen.value = true;
};
/** 确认删除当前选中的分组,并在成功后同步刷新列表与编辑表单状态。 */
const handleDeleteGroupConfirm = async () => {
if (!deletingGroup.value) return;
isDeleting.value = true;
const result = await deleteKbGroup(deletingGroup.value.id);
isDeleting.value = false;
if (!result.ok) {
feedback.value = result.error || t('kbAdmin.msg.deleteFailed');
feedbackType.value = 'error';
return;
}
if (editingGroupId.value === deletingGroup.value.id) {
resetForm();
}
if (editingGroupId.value === deletingGroup.value.id) closeDrawer();
feedback.value = t('kbAdmin.msg.deleted');
feedbackType.value = 'success';
deleteDialogOpen.value = false;
@@ -137,6 +195,7 @@ const handleDeleteGroupConfirm = async () => {
await loadData();
};
/** 手动执行可重试的知识库任务,并将后端执行结果反馈到页面提示区。 */
const handleRunJob = async (job: KbJob) => {
runningJobId.value = job.id;
const result = await runKbJob(job.id);
@@ -153,6 +212,10 @@ const handleRunJob = async (job: KbJob) => {
await loadData();
};
watch([searchKeyword, filterMode, sortMode, pageSize], () => {
currentPage.value = 1;
});
onMounted(async () => {
await loadData();
});
@@ -164,217 +227,155 @@ defineExpose({ loadData });
<div class="animate-fade-in-up">
<div class="kb-admin-header">
<div class="min-w-0 flex-1">
<h2 class="text-xl font-bold text-primary">{{ t('kbAdmin.title') }}</h2>
<p class="section-desc mt-1">
{{ t('kbAdmin.subtitle') }}
</p>
<h2 class="text-xl font-bold text-primary">{{ t('kbAdmin.groupsTitle') }}</h2>
<p class="section-desc mt-1">{{ t('kbAdmin.groupManageSubtitle') }}</p>
</div>
<div class="flex w-full shrink-0 flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:justify-end">
<div
class="kb-admin-toolbar"
role="toolbar"
:aria-label="t('kbAdmin.toolbar')"
>
<button
type="button"
class="kb-admin-toolbar-btn"
@click="settingsDialogOpen = true"
:title="t('kbAdmin.difySettings')"
>
<div class="kb-admin-toolbar" role="toolbar" :aria-label="t('kbAdmin.toolbar')">
<button type="button" class="kb-admin-toolbar-btn" @click="settingsDialogOpen = true" :title="t('kbAdmin.difySettings')">
<Settings class="h-4 w-4 shrink-0" />
<span class="whitespace-nowrap">{{ t('kbAdmin.difySettings') }}</span>
</button>
<button
type="button"
class="kb-admin-toolbar-btn"
@click="healthDialogOpen = true"
:title="t('kbAdmin.healthCheck')"
>
<button type="button" class="kb-admin-toolbar-btn" @click="healthDialogOpen = true" :title="t('kbAdmin.healthCheck')">
<Activity class="h-4 w-4 shrink-0" />
<span class="whitespace-nowrap">{{ t('kbAdmin.healthCheck') }}</span>
</button>
<button type="button" class="kb-admin-toolbar-btn" @click="loadData" :title="t('common.refresh')">
<RefreshCw class="h-4 w-4 shrink-0" :class="{ 'animate-spin': isRefreshing }" />
<span class="whitespace-nowrap">{{ t('common.refresh') }}</span>
</button>
</div>
<button
type="button"
class="btn-primary inline-flex w-full items-center justify-center gap-2 px-5 py-2.5 text-sm sm:w-auto"
@click="router.push(WORKSPACE_PATHS.knowledgeBase)"
>
<button type="button" class="btn-secondary inline-flex w-full items-center justify-center gap-2 px-4 py-2.5 text-sm sm:w-auto" @click="router.push(WORKSPACE_PATHS.knowledgeBase)">
<Wrench class="h-4 w-4 shrink-0" />
<span class="whitespace-nowrap">{{ t('kbAdmin.goWorkspace') }}</span>
</button>
<button type="button" class="btn-primary inline-flex w-full items-center justify-center gap-2 px-4 py-2.5 text-sm sm:w-auto" @click="openCreateDrawer">
<Plus class="h-4 w-4 shrink-0" />
<span class="whitespace-nowrap">{{ t('kbAdmin.form.create') }}</span>
</button>
</div>
</div>
<div class="kb-admin-body">
<section class="kb-admin-section">
<div class="mb-5 flex items-center gap-3">
<div class="flex h-10 w-10 items-center justify-center rounded-2xl bg-brand-50 text-brand-600">
<FolderPlus class="h-5 w-5" />
<section class="admin-table-section">
<div class="admin-table-filters flex flex-col gap-4">
<div class="grid grid-cols-1 gap-3 lg:grid-cols-[minmax(16rem,1fr)_auto_minmax(11rem,14rem)] lg:items-center">
<label class="relative min-w-0">
<Search class="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted" />
<input v-model="searchKeyword" class="input-field w-full pl-9" :placeholder="t('kbAdmin.filters.searchPlaceholder')" />
</label>
<div class="inline-flex w-full overflow-hidden rounded-xl border border-default bg-surface lg:w-auto">
<button
v-for="option in filterOptions"
:key="option"
type="button"
class="min-w-0 flex-1 whitespace-nowrap px-4 py-2.5 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft hover:text-primary lg:flex-none"
:class="{ 'bg-brand-50 text-brand-700': filterMode === option }"
@click="filterMode = option"
>
{{ t(`kbAdmin.filters.${option}`) }}
</button>
</div>
<select v-model="sortMode" class="select-field w-full">
<option v-for="option in sortOptions" :key="option" :value="option">
{{ t(`kbAdmin.sort.${option}`) }}
</option>
</select>
</div>
<div>
<h3 class="section-title">{{ formTitle }}</h3>
<p class="section-desc">{{ formDescription }}</p>
<div class="flex flex-wrap items-center gap-3 text-xs text-muted">
<span>{{ t('kbAdmin.stats.groups', { count: groups.length }) }}</span>
<span>{{ t('kbAdmin.stats.documents', { count: totalDocuments }) }}</span>
<span>{{ t('kbAdmin.stats.visible', { count: filteredGroups.length }) }}</span>
</div>
</div>
<div class="space-y-4">
<div>
<label class="label-field mb-2 block">{{ t('kbAdmin.form.groupName') }}</label>
<input v-model="form.name" class="input-field" :placeholder="t('kbAdmin.form.groupNamePlaceholder')" />
<p v-if="feedback" class="mx-6 mt-4 rounded-xl border px-4 py-3 text-sm" :class="feedbackType === 'error' ? 'border-rose-200 bg-rose-50 text-rose-600' : 'border-emerald-200 bg-emerald-50 text-emerald-700'">
{{ feedback }}
</p>
<div v-if="groups.length === 0" class="admin-table-empty">{{ t('kbAdmin.groupsEmpty') }}</div>
<div v-else-if="filteredGroups.length === 0" class="admin-table-empty">{{ t('kbAdmin.filters.emptyResult') }}</div>
<div v-else>
<div class="admin-table-wrap hidden md:block">
<table class="admin-table table-fixed">
<thead>
<tr>
<th class="w-[20%] px-6 py-3 text-xs">{{ t('kbAdmin.table.name') }}</th>
<th class="w-[30%] px-6 py-3 text-xs">{{ t('kbAdmin.table.description') }}</th>
<th class="w-[12%] px-6 py-3 text-xs">{{ t('kbAdmin.table.documents') }}</th>
<th class="w-[26%] px-6 py-3 text-xs">{{ t('kbAdmin.table.updatedAt') }}</th>
<th class="w-[12%] px-6 py-3 text-right text-xs">{{ t('kbAdmin.table.actions') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="group in pagedGroups" :key="group.id">
<td class="px-6 py-4 align-middle"><div class="truncate font-semibold text-primary" :title="group.name">{{ group.name }}</div></td>
<td class="px-6 py-4 align-middle text-sm text-muted">
<div class="truncate" :title="group.description || t('kbAdmin.noDescription')">
{{ group.description || t('kbAdmin.noDescription') }}
</div>
</td>
<td class="px-6 py-4 align-middle"><span class="kb-admin-badge whitespace-nowrap">{{ t('kbAdmin.documentCount', { count: group.document_count ?? 0 }) }}</span></td>
<td class="px-6 py-4 align-middle text-sm text-muted"><div class="truncate" :title="group.updated_at || '--'">{{ group.updated_at || '--' }}</div></td>
<td class="px-6 py-4 align-middle">
<div class="flex justify-end gap-1.5">
<button type="button" class="btn-icon-ds border border-default" @click="openEditDrawer(group)" :title="t('common.edit')"><Pencil class="h-4 w-4" /></button>
<button type="button" class="btn-icon-ds border border-rose-200 text-rose-600 hover:bg-rose-50" @click="handleDeleteGroup(group)" :disabled="isDeleting" :title="t('common.delete')"><Trash2 class="h-4 w-4" /></button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<label class="label-field mb-2 block">{{ t('kbAdmin.form.groupDesc') }}</label>
<textarea
v-model="form.description"
rows="4"
class="input-field"
:placeholder="t('kbAdmin.form.groupDescPlaceholder')"
<div class="space-y-3 p-4 md:hidden">
<article v-for="group in pagedGroups" :key="group.id" class="kb-admin-card">
<div class="flex items-start justify-between gap-3">
<div class="min-w-0">
<h3 class="font-semibold text-primary">{{ group.name }}</h3>
<p class="mt-1 line-clamp-2 text-sm text-muted" :title="group.description || t('kbAdmin.noDescription')">{{ group.description || t('kbAdmin.noDescription') }}</p>
</div>
<span class="kb-admin-badge">{{ t('kbAdmin.documentCount', { count: group.document_count ?? 0 }) }}</span>
</div>
<div class="mt-3 flex items-center justify-between gap-3">
<span class="text-xs text-muted">{{ group.updated_at || '--' }}</span>
<div class="flex gap-1.5">
<button type="button" class="btn-icon-ds border border-default" @click="openEditDrawer(group)" :title="t('common.edit')"><Pencil class="h-4 w-4" /></button>
<button type="button" class="btn-icon-ds border border-rose-200 text-rose-600" @click="handleDeleteGroup(group)" :title="t('common.delete')"><Trash2 class="h-4 w-4" /></button>
</div>
</div>
</article>
</div>
<div class="border-t border-default px-6 py-4">
<PaginationBar
v-model:page="currentPage"
v-model:page-size="pageSize"
:total="filteredGroups.length"
:page-size-options="pageSizeOptions"
/>
</div>
<div class="flex flex-wrap items-center justify-end gap-2 border-t border-subtle pt-4">
<button
type="button"
class="btn-primary inline-flex items-center gap-1.5 px-5 py-2 text-sm disabled:cursor-not-allowed disabled:opacity-60"
@click="handleCreateGroup"
:disabled="isSubmitting"
>
<FolderPlus v-if="!isSubmitting" class="h-4 w-4 shrink-0" />
{{ submitText }}
</button>
<button
v-if="editingGroupId"
type="button"
class="btn-secondary inline-flex items-center gap-1.5 px-4 py-2 text-sm"
@click="resetForm"
>
<X class="h-4 w-4 shrink-0" />
{{ t('kbAdmin.form.cancelEdit') }}
</button>
</div>
<p
v-if="feedback"
class="text-sm"
:class="feedbackType === 'error' ? 'text-rose-500' : 'text-emerald-600'"
>
{{ feedback }}
</p>
</div>
</section>
<div class="space-y-6">
<section class="kb-admin-section">
<div class="mb-4 flex items-center justify-between">
<h3 class="section-title">{{ t('kbAdmin.groupsTitle') }}</h3>
<span class="text-xs text-muted">{{ isRefreshing ? t('common.loading') : '/api/kb/groups' }}</span>
</div>
<div v-if="groups.length === 0" class="kb-admin-empty">
{{ t('kbAdmin.groupsEmpty') }}
</div>
<div v-else class="grid grid-cols-1 gap-3 md:grid-cols-2">
<div
v-for="group in groups"
:key="group.id"
class="kb-admin-card"
>
<div class="flex items-start justify-between gap-3">
<div class="min-w-0">
<div class="font-semibold text-primary">{{ group.name }}</div>
<div class="mt-1 text-sm text-muted">{{ group.description || t('kbAdmin.noDescription') }}</div>
</div>
<div class="kb-admin-badge">
{{ t('kbAdmin.documentCount', { count: group.document_count ?? 0 }) }}
</div>
</div>
<div class="mt-4 flex flex-wrap items-center justify-between gap-3">
<div class="text-xs text-muted">
{{ t('kbAdmin.updatedAt') }}{{ group.updated_at || '--' }}
</div>
<div class="flex items-center gap-2">
<button
type="button"
class="btn-secondary inline-flex items-center gap-1 px-3 py-2 text-xs"
@click="handleEditGroup(group)"
>
<Pencil class="h-3.5 w-3.5" />
{{ t('common.edit') }}
</button>
<button
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-rose-200 px-3 py-2 text-xs font-medium text-rose-600 transition-colors hover:bg-rose-50"
@click="handleDeleteGroup(group)"
>
<Trash2 class="h-3.5 w-3.5" />
{{ t('common.delete') }}
</button>
</div>
</div>
</div>
</div>
</section>
<section class="kb-admin-section">
<div class="mb-4 flex items-center justify-between">
<h3 class="section-title">{{ t('kbAdmin.jobsTitle') }}</h3>
<span class="text-xs text-muted">/api/kb/jobs</span>
</div>
<div v-if="jobs.length === 0" class="kb-admin-empty">
{{ t('kbAdmin.jobsEmpty') }}
</div>
<div v-else class="space-y-3">
<div
v-for="job in jobs"
:key="job.id"
class="kb-admin-card"
>
<div class="flex items-start justify-between gap-3">
<div class="min-w-0">
<div class="font-semibold text-primary">{{ job.job_type }}</div>
<div class="mt-1 text-sm text-muted">{{ job.created_at || '--' }}</div>
<div class="mt-2 text-sm text-muted">
{{ job.message || t('kbAdmin.noJobMessage') }}
</div>
<div class="mt-2 text-xs text-muted">
{{ t('kbAdmin.jobMeta', { docId: job.document_id ?? '--', versionId: job.document_version_id ?? '--', progress: job.progress ?? 0 }) }}
</div>
</div>
<span class="kb-admin-badge">
{{ job.status }}
</span>
</div>
<div v-if="['clean', 'sync_dify'].includes(job.job_type) && job.status !== 'success'" class="mt-3 flex justify-end">
<button
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-brand-200 px-3 py-2 text-xs font-medium text-brand-700 transition-colors hover:bg-brand-50 disabled:cursor-not-allowed disabled:opacity-60"
@click="handleRunJob(job)"
:disabled="runningJobId === job.id"
>
<Play class="h-3.5 w-3.5" />
{{ runningJobId === job.id ? t('kbAdmin.running') : t('kbAdmin.runJob') }}
</button>
</div>
</div>
</div>
</section>
</div>
<KbJobQueuePanel
:jobs="jobs"
:running-job-id="runningJobId"
@run-job="handleRunJob"
/>
</div>
</div>
<DifySettingsDialog
:open="settingsDialogOpen"
@close="settingsDialogOpen = false"
@saved="(message) => { feedback = message; feedbackType = 'success'; void loadData(); }"
@error="(message) => { feedback = message; feedbackType = 'error'; }"
/>
<DifyHealthDialog
:open="healthDialogOpen"
@close="healthDialogOpen = false"
@error="(message) => { feedback = message; feedbackType = 'error'; }"
/>
<DeleteConfirmDialog
v-model="deleteDialogOpen"
:title="t('kbAdmin.deleteDialog.title')"
:message="t('kbAdmin.deleteDialog.message', { name: deletingGroup?.name || '' })"
@confirm="handleDeleteGroupConfirm"
@cancel="() => { deleteDialogOpen = false; deletingGroup = null; }"
<KbGroupDrawer
v-model:form="form"
:open="drawerOpen"
:mode="editingGroupId ? 'edit' : 'create'"
:submitting="isSubmitting"
@submit="handleSubmitGroup"
@close="closeDrawer"
/>
<DifySettingsDialog :open="settingsDialogOpen" @close="settingsDialogOpen = false" @saved="(message) => { feedback = message; feedbackType = 'success'; void loadData(); }" @error="(message) => { feedback = message; feedbackType = 'error'; }" />
<DifyHealthDialog :open="healthDialogOpen" @close="healthDialogOpen = false" @error="(message) => { feedback = message; feedbackType = 'error'; }" />
<DeleteConfirmDialog v-model="deleteDialogOpen" :title="t('kbAdmin.deleteDialog.title')" :message="t('kbAdmin.deleteDialog.message', { name: deletingGroup?.name || '' })" :confirm-loading="isDeleting" @confirm="handleDeleteGroupConfirm" @cancel="() => { deleteDialogOpen = false; deletingGroup = null; }" />
</template>
@@ -0,0 +1,127 @@
<script setup lang="ts">
/**
* features/kb/components/KbGroupDrawer.vue
* 知识库分组新建/编辑抽屉表单。
* 依赖:Vue I18n、lucide-vue-next、父级 KbAdminPanel 传入的表单状态。
* 逻辑:只负责抽屉展示、表单双向同步和提交/关闭事件;接口调用与列表刷新由父组件处理。
*/
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { FolderPlus, X } from 'lucide-vue-next';
export interface KbGroupFormValue {
name: string;
description: string;
}
const props = defineProps<{
open: boolean;
mode: 'create' | 'edit';
form: KbGroupFormValue;
submitting: boolean;
}>();
const emit = defineEmits<{
(e: 'update:form', value: KbGroupFormValue): void;
(e: 'submit'): void;
(e: 'close'): void;
}>();
const { t } = useI18n();
const formTitle = computed(() => props.mode === 'edit' ? t('kbAdmin.form.editTitle') : t('kbAdmin.form.createTitle'));
const formDescription = computed(() => props.mode === 'edit' ? t('kbAdmin.form.editDesc') : t('kbAdmin.form.createDesc'));
const submitText = computed(() => {
if (props.submitting) return props.mode === 'edit' ? t('kbAdmin.form.saving') : t('kbAdmin.form.submitting');
return props.mode === 'edit' ? t('kbAdmin.form.saveChanges') : t('kbAdmin.form.create');
});
/** 更新指定表单字段,并将完整表单值同步回父组件。 */
const updateField = (field: keyof KbGroupFormValue, value: string) => {
emit('update:form', {
...props.form,
[field]: value,
});
};
</script>
<template>
<Teleport to="body">
<Transition name="kb-admin-drawer">
<div v-if="open" class="fixed inset-0 z-[100] bg-overlay backdrop-blur-sm" @click.self="emit('close')">
<aside class="ml-auto flex h-full w-full max-w-[440px] flex-col border-l border-default bg-surface shadow-elevated">
<header class="flex items-start justify-between gap-4 border-b border-default px-6 py-5">
<div class="min-w-0">
<h3 class="text-lg font-semibold text-primary">{{ formTitle }}</h3>
<p class="section-desc mt-1">{{ formDescription }}</p>
</div>
<button type="button" class="btn-icon-ds shrink-0" @click="emit('close')" :title="t('common.close')">
<X class="h-5 w-5" />
</button>
</header>
<div class="flex-1 space-y-5 overflow-y-auto px-6 py-5">
<div>
<label class="label-field mb-2 block">{{ t('kbAdmin.form.groupName') }}</label>
<input
:value="form.name"
class="input-field"
:placeholder="t('kbAdmin.form.groupNamePlaceholder')"
@input="updateField('name', ($event.target as HTMLInputElement).value)"
/>
</div>
<div>
<label class="label-field mb-2 block">{{ t('kbAdmin.form.groupDesc') }}</label>
<textarea
:value="form.description"
rows="8"
class="input-field"
:placeholder="t('kbAdmin.form.groupDescPlaceholder')"
@input="updateField('description', ($event.target as HTMLTextAreaElement).value)"
/>
</div>
</div>
<footer class="flex justify-end gap-2 border-t border-default px-6 py-4">
<button type="button" class="btn-secondary inline-flex items-center gap-1.5 px-4 py-2 text-sm" @click="emit('close')">
<X class="h-4 w-4 shrink-0" />
{{ t('common.cancel') }}
</button>
<button
type="button"
class="btn-primary inline-flex items-center gap-1.5 px-5 py-2 text-sm disabled:cursor-not-allowed disabled:opacity-60"
:disabled="submitting"
@click="emit('submit')"
>
<FolderPlus v-if="!submitting" class="h-4 w-4 shrink-0" />
{{ submitText }}
</button>
</footer>
</aside>
</div>
</Transition>
</Teleport>
</template>
<style scoped>
.kb-admin-drawer-enter-active,
.kb-admin-drawer-leave-active {
transition: opacity 0.18s ease;
}
.kb-admin-drawer-enter-active aside,
.kb-admin-drawer-leave-active aside {
transition: transform 0.18s ease;
}
.kb-admin-drawer-enter-from,
.kb-admin-drawer-leave-to {
opacity: 0;
}
.kb-admin-drawer-enter-from aside,
.kb-admin-drawer-leave-to aside {
transform: translateX(100%);
}
</style>
@@ -0,0 +1,64 @@
<script setup lang="ts">
/**
* features/kb/components/KbJobQueuePanel.vue
* 知识库任务队列展示面板。
* 依赖:kb.api 的 KbJob 类型、Vue I18n、lucide-vue-next 图标。
* 逻辑:只负责渲染任务列表和触发执行事件;任务执行、反馈和刷新由父级 KbAdminPanel 处理。
*/
import { Play } from 'lucide-vue-next';
import { useI18n } from 'vue-i18n';
import type { KbJob } from '../api/kb.api';
defineProps<{
jobs: KbJob[];
runningJobId: number | string | null;
}>();
const emit = defineEmits<{
(e: 'run-job', job: KbJob): void;
}>();
const { t } = useI18n();
/** 判断任务是否允许手动执行,避免模板里重复硬编码任务类型条件。 */
const canRunJob = (job: KbJob): boolean => ['clean', 'sync_dify'].includes(job.job_type) && job.status !== 'success';
</script>
<template>
<section class="kb-admin-section">
<div class="mb-4 flex items-center justify-between">
<h3 class="section-title">{{ t('kbAdmin.jobsTitle') }}</h3>
<span class="text-xs text-muted">/api/kb/jobs</span>
</div>
<div v-if="jobs.length === 0" class="kb-admin-empty">
{{ t('kbAdmin.jobsEmpty') }}
</div>
<div v-else class="grid grid-cols-1 gap-3 lg:grid-cols-2">
<div v-for="job in jobs" :key="job.id" class="kb-admin-card">
<div class="flex items-start justify-between gap-3">
<div class="min-w-0">
<div class="font-semibold text-primary">{{ job.job_type }}</div>
<div class="mt-1 text-sm text-muted">{{ job.created_at || '--' }}</div>
<div class="mt-2 text-sm text-muted">{{ job.message || t('kbAdmin.noJobMessage') }}</div>
<div class="mt-2 text-xs text-muted">
{{ t('kbAdmin.jobMeta', { docId: job.document_id ?? '--', versionId: job.document_version_id ?? '--', progress: job.progress ?? 0 }) }}
</div>
</div>
<span class="kb-admin-badge">{{ job.status }}</span>
</div>
<div v-if="canRunJob(job)" class="mt-3 flex justify-end">
<button
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-brand-200 px-3 py-2 text-xs font-medium text-brand-700 transition-colors hover:bg-brand-50 disabled:cursor-not-allowed disabled:opacity-60"
:disabled="runningJobId === job.id"
@click="emit('run-job', job)"
>
<Play class="h-3.5 w-3.5" />
{{ runningJobId === job.id ? t('kbAdmin.running') : t('kbAdmin.runJob') }}
</button>
</div>
</div>
</div>
</section>
</template>
+1
View File
@@ -645,6 +645,7 @@
"enterFullscreen": "Enter Fullscreen",
"exitFullscreen": "Exit Fullscreen",
"noData": "No data available for {table}",
"noFilterResults": "No matching rows. Adjust your filters.",
"usage": "Usage Analytics",
"byUser": "Requests by User",
"byAgent": "Requests by Agent",
+2
View File
@@ -2,6 +2,8 @@
"errorOccurred": "An error occurred",
"close": "Close",
"cancel": "Cancel",
"edit": "Edit",
"delete": "Delete",
"loading": "Loading...",
"refresh": "Refresh",
"yes": "Yes",
+27
View File
@@ -77,6 +77,33 @@
"deleted": "Group deleted",
"runFailed": "Job run failed",
"runDone": "Job executed"
},
"groupManageSubtitle": "Manage Dify binding, group structure, and document statistics. Daily content work is in Workspace > Knowledge Base.",
"filters": {
"emptyResult": "No knowledge base groups match the current filters.",
"withDocs": "With docs",
"all": "All",
"searchPlaceholder": "Search group name or description",
"empty": "Empty"
},
"sort": {
"docsAsc": "Documents low to high",
"updatedDesc": "Updated newest first",
"docsDesc": "Documents high to low",
"nameAsc": "Name A-Z",
"updatedAsc": "Updated oldest first"
},
"stats": {
"documents": "{count} docs",
"groups": "{count} groups",
"visible": "{count} shown"
},
"table": {
"updatedAt": "Updated At",
"documents": "Documents",
"description": "Description",
"name": "Group Name",
"actions": "Actions"
}
},
"kbWorkspace": {
+1
View File
@@ -650,6 +650,7 @@
"enterFullscreen": "เต็มหน้าจอ",
"exitFullscreen": "ออกจากเต็มหน้าจอ",
"noData": "ไม่มีข้อมูลสำหรับ {table}",
"noFilterResults": "ไม่พบข้อมูลที่ตรงกับเงื่อนไข โปรดปรับตัวกรอง",
"usage": "การวิเคราะห์การใช้งาน",
"byUser": "ตามผู้ใช้",
"byAgent": "ตามตัวแทน",
+2
View File
@@ -2,6 +2,8 @@
"errorOccurred": "เกิดข้อผิดพลาด",
"close": "ปิด",
"cancel": "ยกเลิก",
"edit": "แก้ไข",
"delete": "ลบ",
"loading": "กำลังโหลด...",
"refresh": "รีเฟรช",
"yes": "ใช่",
+27
View File
@@ -77,6 +77,33 @@
"deleted": "ลบกลุ่มคลังความรู้แล้ว",
"runFailed": "รันงานล้มเหลว",
"runDone": "รันงานแล้ว"
},
"groupManageSubtitle": "จัดการการผูก Dify โครงสร้างกลุ่ม และสถิติเอกสาร งานเอกสารประจำวันให้ทำที่พื้นที่ทำงานฐานความรู้",
"filters": {
"emptyResult": "ไม่พบกลุ่มฐานความรู้ที่ตรงกับตัวกรองปัจจุบัน",
"withDocs": "มีเอกสาร",
"all": "ทั้งหมด",
"searchPlaceholder": "ค้นหาชื่อกลุ่มหรือคำอธิบาย",
"empty": "กลุ่มว่าง"
},
"sort": {
"docsAsc": "เอกสารน้อยไปมาก",
"updatedDesc": "อัปเดตล่าสุดก่อน",
"docsDesc": "เอกสารมากไปน้อย",
"nameAsc": "เรียงตามชื่อ",
"updatedAsc": "อัปเดตเก่าสุดก่อน"
},
"stats": {
"documents": "{count} เอกสาร",
"groups": "ทั้งหมด {count} กลุ่ม",
"visible": "แสดง {count} รายการ"
},
"table": {
"updatedAt": "เวลาอัปเดต",
"documents": "เอกสาร",
"description": "คำอธิบาย",
"name": "ชื่อกลุ่ม",
"actions": "การดำเนินการ"
}
},
"kbWorkspace": {
+1
View File
@@ -646,6 +646,7 @@
"enterFullscreen": "进入全屏",
"exitFullscreen": "退出全屏",
"noData": "暂无数据: {table}",
"noFilterResults": "没有匹配的数据,请调整筛选条件",
"usage": "使用分析",
"byUser": "按用户统计",
"byAgent": "按应用统计",
+2
View File
@@ -2,6 +2,8 @@
"errorOccurred": "发生错误",
"close": "关闭",
"cancel": "取消",
"edit": "编辑",
"delete": "删除",
"loading": "加载中...",
"refresh": "刷新",
"yes": "是",
+27
View File
@@ -77,6 +77,33 @@
"deleted": "知识库分组已删除",
"runFailed": "任务执行失败",
"runDone": "任务已执行"
},
"groupManageSubtitle": "管理 Dify 绑定、分组结构与文档统计。日常文档维护请在工作台「知识库」操作。",
"filters": {
"emptyResult": "当前筛选条件下暂无匹配的知识库分组。",
"withDocs": "有文档",
"all": "全部",
"searchPlaceholder": "搜索分组名称或描述",
"empty": "空分组"
},
"sort": {
"docsAsc": "按文档数正序",
"updatedDesc": "按更新时间倒序",
"docsDesc": "按文档数倒序",
"nameAsc": "按名称排序",
"updatedAsc": "按更新时间正序"
},
"stats": {
"documents": "{count} 个文档",
"groups": "共 {count} 个分组",
"visible": "当前显示 {count} 个"
},
"table": {
"updatedAt": "更新时间",
"documents": "文档数",
"description": "描述",
"name": "分组名称",
"actions": "操作"
}
},
"kbWorkspace": {
+1
View File
@@ -650,6 +650,7 @@
"enterFullscreen": "進入全屏",
"exitFullscreen": "退出全屏",
"noData": "暫無數據: {table}",
"noFilterResults": "沒有匹配的數據,請調整篩選條件",
"usage": "使用分析",
"byUser": "按用戶統計",
"byAgent": "按應用統計",
+2
View File
@@ -2,6 +2,8 @@
"errorOccurred": "發生錯誤",
"close": "關閉",
"cancel": "取消",
"edit": "編輯",
"delete": "刪除",
"loading": "載入中...",
"refresh": "刷新",
"yes": "是",
+27
View File
@@ -77,6 +77,33 @@
"deleted": "知識庫分組已刪除",
"runFailed": "任務執行失敗",
"runDone": "任務已執行"
},
"groupManageSubtitle": "管理 Dify 綁定、分組結構與文件統計。日常文件維護請在工作台「知識庫」操作。",
"filters": {
"emptyResult": "目前篩選條件下沒有符合的知識庫分組。",
"withDocs": "有文件",
"all": "全部",
"searchPlaceholder": "搜尋分組名稱或描述",
"empty": "空分組"
},
"sort": {
"docsAsc": "依文件數正序",
"updatedDesc": "依更新時間倒序",
"docsDesc": "依文件數倒序",
"nameAsc": "依名稱排序",
"updatedAsc": "依更新時間正序"
},
"stats": {
"documents": "{count} 份文件",
"groups": "共 {count} 個分組",
"visible": "目前顯示 {count} 個"
},
"table": {
"updatedAt": "更新時間",
"documents": "文件數",
"description": "描述",
"name": "分組名稱",
"actions": "操作"
}
},
"kbWorkspace": {
+1 -1
View File
@@ -688,7 +688,7 @@
}
.kb-admin-body {
@apply grid grid-cols-1 gap-6 bg-surface p-8 xl:grid-cols-[420px_minmax(0,1fr)];
@apply space-y-6 bg-surface p-6 md:p-8;
}
.kb-admin-section {