fix(frontend): knowledge document list layout, batch bar, and selection

- Platform route outlet: flex min-height so document area is not collapsed
- Card grid: stable :key=item.id; clamp selection anchor after list reload
- DocumentListView: TDesign checkbox, sticky header, neutral file icons
- DocumentBatchBar: column-footer placement; toned style vs floating pill
- Clear selection i18n: less ambiguous wording (e.g. 取消选择)
- Batch delete: poll list refresh after async queue; getKnowled returns Promise
- files.ts: use file icon for text types; align chat/upload icon usage
This commit is contained in:
wizardchen
2026-04-29 15:15:55 +08:00
committed by lyingbug
parent a40f191430
commit c62ff4c906
12 changed files with 395 additions and 219 deletions
+128 -71
View File
@@ -413,9 +413,9 @@ const getKnowledgeType = (item: any) => {
return '--';
}
const loadKnowledgeFiles = (kbIdValue: string) => {
if (!kbIdValue) return;
getKnowled(
const loadKnowledgeFiles = (kbIdValue: string): Promise<void> => {
if (!kbIdValue) return Promise.resolve();
return getKnowled(
{
page: 1,
page_size: pageSize,
@@ -1632,6 +1632,11 @@ const toggleSelectRow = (id: string, checked: boolean, shiftKey?: boolean) => {
lastSelectedIndex = idx;
};
const onCardGridCheckboxChange = (id: string, checked: boolean, ctx?: { e?: Event }) => {
const me = ctx?.e as MouseEvent | undefined;
toggleSelectRow(id, checked, !!me?.shiftKey);
};
const toggleSelectAll = (checked: boolean) => {
if (checked) {
for (const item of cardList.value || []) selectedIds.value.add(item.id);
@@ -1653,6 +1658,7 @@ const openBatchDeleteDialog = () => {
const confirmBatchDelete = async () => {
if (batchDeleting.value || selectedIds.value.size === 0) return;
const ids = Array.from(selectedIds.value);
const deletedIdSet = new Set(ids);
batchDeleting.value = true;
try {
const res: any = await batchDeleteKnowledge(kbId.value, ids);
@@ -1661,7 +1667,15 @@ const confirmBatchDelete = async () => {
clearSelection();
batchDeleteDialog.value = false;
page = 1;
loadKnowledgeFiles(kbId.value);
// 后端将批量删除放入异步队列,立刻拉列表仍可能包含待删项;短轮询直到列表与后端一致或超时
const maxPolls = 30;
const delayMs = 400;
for (let i = 0; i < maxPolls; i++) {
await loadKnowledgeFiles(kbId.value);
const stillPresent = (cardList.value || []).some((c: KnowledgeCard) => deletedIdSet.has(c.id));
if (!stillPresent) break;
await new Promise<void>((r) => setTimeout(r, delayMs));
}
loadTags(kbId.value);
} else {
MessagePlugin.error(res?.message || t('knowledgeBase.batchDeleteFailed'));
@@ -1690,10 +1704,18 @@ watch([selectedTagId, docSearchKeyword, selectedFileType, kbId], () => {
clearSelection();
});
// After cardList reloads, drop ids that are no longer present.
// After cardList reloads: stable keys rely on correct indices for shift-range; clamp anchor index.
watch(cardList, () => {
const items = cardList.value || [];
const n = items.length;
if (lastSelectedIndex >= n) {
lastSelectedIndex = n > 0 ? n - 1 : -1;
}
if (moreIndex.value >= n) {
moreIndex.value = -1;
}
if (selectedIds.value.size === 0) return;
const visible = new Set((cardList.value || []).map((i: KnowledgeCard) => i.id));
const visible = new Set(items.map((i: KnowledgeCard) => i.id));
for (const id of selectedIds.value) {
if (!visible.has(id)) selectedIds.value.delete(id);
}
@@ -2144,27 +2166,28 @@ async function createNewSession(value: string): Promise<void> {
class="knowledge-card"
:class="{ 'is-selected': selectedIds.has(item.id), 'has-selection': selectedIds.size > 0 }"
v-for="(item, index) in cardList"
:key="index"
:key="item.id"
@click="openCardDetails(item)"
@mouseenter="onCardMouseEnter($event, item)"
@mousemove="onCardMouseMove($event)"
@mouseleave="onCardMouseLeave"
>
<label
v-if="canEdit"
class="card-select-overlay"
:class="{ active: selectedIds.has(item.id) }"
@click.stop
>
<input
type="checkbox"
:checked="selectedIds.has(item.id)"
@click.stop="(e: MouseEvent) => toggleSelectRow(item.id, !selectedIds.has(item.id), e.shiftKey)"
:aria-label="item.file_name"
/>
</label>
<div class="card-content">
<div class="card-content-nav">
<div
v-if="canEdit"
class="card-nav-check"
:class="{ active: selectedIds.has(item.id) }"
@click.stop
>
<t-checkbox
class="card-select-checkbox"
size="small"
:checked="selectedIds.has(item.id)"
:title="item.file_name"
@change="(checked, ctx) => onCardGridCheckboxChange(item.id, checked, ctx)"
/>
</div>
<span class="card-content-title" :title="item.file_name">{{ item.file_name }}</span>
<t-popup
v-if="canEdit"
@@ -2388,6 +2411,8 @@ async function createNewSession(value: string): Promise<void> {
<EmptyKnowledge />
</div>
</template>
</div>
<div class="doc-batch-bar-anchor" v-show="selectedIds.size > 0">
<DocumentBatchBar
:count="selectedIds.size"
:loading="batchDeleting"
@@ -2544,7 +2569,7 @@ async function createNewSession(value: string): Promise<void> {
flex: 1;
width: 100%;
min-width: 0;
padding: 24px 32px 32px;
padding: 24px 32px 0px;
box-sizing: border-box;
}
@@ -3112,6 +3137,12 @@ async function createNewSession(value: string): Promise<void> {
}
}
/* 批量条在滚动区外,始终贴主内容列底部,不随列表高度在列内上下漂移 */
.doc-batch-bar-anchor {
flex-shrink: 0;
padding-top: 4px;
}
// Header 样式(无底部分割线,留更多空间给下方内容区)
.document-header {
display: flex;
@@ -3388,6 +3419,7 @@ async function createNewSession(value: string): Promise<void> {
.faq-manager-wrapper {
flex: 1;
min-height: 0;
padding: 24px 32px;
overflow-y: auto;
margin: 0 16px 0 4px;
@@ -3442,7 +3474,7 @@ async function createNewSession(value: string): Promise<void> {
box-sizing: border-box;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
gap: 14px;
gap: 16px;
align-content: flex-start;
width: 100%;
@@ -3453,14 +3485,24 @@ async function createNewSession(value: string): Promise<void> {
.knowledge-card-skeleton {
cursor: default;
.card-content { padding: 15px 17px 13px; }
.card-content-nav { margin-bottom: 14px; }
.card-content {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
padding: 12px 16px 8px;
}
.card-content-nav {
margin-bottom: 8px;
}
.card-bottom {
position: absolute;
bottom: 0;
left: 0;
flex-shrink: 0;
margin-top: auto;
width: 100%;
padding: 0 17px;
padding: 0 16px;
box-sizing: border-box;
height: 34px;
display: flex;
@@ -3747,6 +3789,7 @@ async function createNewSession(value: string): Promise<void> {
align-items: center;
gap: 8px;
padding: 6px 0;
flex-shrink: 0;
}
.card-draft-tip {
@@ -3756,65 +3799,77 @@ async function createNewSession(value: string): Promise<void> {
.knowledge-card {
min-width: 248px;
border: 1px solid var(--td-component-stroke);
display: flex;
flex-direction: column;
border: 1px solid color-mix(in srgb, var(--td-component-stroke) 82%, var(--td-bg-color-secondarycontainer));
height: 148px;
border-radius: 9px;
overflow: hidden;
box-sizing: border-box;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.035);
background: var(--td-bg-color-container);
position: relative;
cursor: pointer;
transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
&.is-selected {
border-color: var(--td-brand-color, #0052d9);
box-shadow: 0 0 0 1px var(--td-brand-color, #0052d9), 0 4px 12px rgba(0, 82, 217, 0.08);
background: var(--td-brand-color-1, #f0f6ff);
}
.card-select-overlay {
position: absolute;
top: 8px;
left: 8px;
width: 22px;
height: 22px;
/* 初始态略可见,悬停/多选/已选时再强调,避免「凭空多一列」的突兀感 */
.card-nav-check {
flex-shrink: 0;
display: inline-flex;
align-items: center;
justify-content: center;
background: var(--td-bg-color-container, #fff);
border: 1px solid var(--td-component-border, #e0e0e0);
border-radius: 6px;
width: 22px;
height: 29px;
opacity: 0.4;
transition: opacity 0.2s ease;
cursor: pointer;
opacity: 0;
transition: opacity 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
z-index: 1;
input[type='checkbox'] {
width: 14px;
height: 14px;
margin: 0;
cursor: pointer;
accent-color: var(--td-brand-color, #0052d9);
}
&.active,
&:focus-within {
opacity: 1;
border-color: var(--td-brand-color, #0052d9);
}
.card-select-checkbox {
margin: 0;
line-height: 0;
:deep(.t-checkbox) {
align-items: center;
}
:deep(.t-checkbox__label) {
display: none !important;
width: 0 !important;
min-width: 0 !important;
margin: 0 !important;
padding: 0 !important;
}
:deep(.t-checkbox__input) {
margin: 0;
}
:deep(.t-checkbox__input-wrapper) {
margin: 0;
}
}
}
&:hover .card-select-overlay,
&.has-selection .card-select-overlay {
&:hover .card-nav-check,
&.has-selection .card-nav-check {
opacity: 1;
}
.card-content {
padding: 15px 17px 13px;
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
padding: 12px 16px 8px;
}
.card-analyze {
flex-shrink: 0;
height: 52px;
display: flex;
}
@@ -3838,11 +3893,11 @@ async function createNewSession(value: string): Promise<void> {
}
.card-content-nav {
flex-shrink: 0;
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 11px;
gap: 8px;
margin-bottom: 8px;
}
.card-content-title {
@@ -3886,6 +3941,8 @@ async function createNewSession(value: string): Promise<void> {
}
.card-content-txt {
flex: 1;
min-height: 0;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
@@ -3899,9 +3956,9 @@ async function createNewSession(value: string): Promise<void> {
}
.card-bottom {
position: absolute;
bottom: 0;
padding: 0 17px;
flex-shrink: 0;
margin-top: auto;
padding: 0 16px;
box-sizing: border-box;
height: 34px;
width: 100%;
@@ -3920,19 +3977,19 @@ async function createNewSession(value: string): Promise<void> {
}
.card-type {
color: var(--td-text-color-secondary);
color: var(--td-text-color-placeholder);
font-family: "PingFang SC";
font-size: 11px;
font-weight: 500;
padding: 3px 8px;
background: var(--td-bg-color-secondarycontainer);
border-radius: 4px;
padding: 0;
background: transparent;
letter-spacing: 0.02em;
}
}
.knowledge-card:hover {
border-color: var(--td-brand-color);
box-shadow: 0 2px 8px rgba(7, 192, 95, 0.12);
border-color: color-mix(in srgb, var(--td-component-stroke) 55%, var(--td-brand-color));
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.07);
}
/* 悬停知识卡片时跟随鼠标的详情气泡 */