feat: Enhance knowledge base management with new create action and improved UI
- Added a new "Create Knowledge Base" action in the menu for easier knowledge base creation. - Updated localization strings in English, Russian, and Chinese to include a subtitle for knowledge base management. - Improved UI components to better display knowledge base options and actions, including a new header subtitle in the KnowledgeBaseList view. - Refactored related components to streamline the knowledge base list and FAQ entry management.
This commit is contained in:
@@ -9,7 +9,17 @@
|
||||
<div v-if="showKbActions" class="kb-action-wrapper">
|
||||
<div class="kb-action-label">{{ t('knowledgeBase.quickActions') }}</div>
|
||||
<div class="kb-action-menu">
|
||||
<template v-if="showDocActions">
|
||||
<template v-if="showCreateKbAction">
|
||||
<div class="menu_item kb-action-item" @click.stop="handleCreateKnowledgeBase">
|
||||
<div class="menu_item-box">
|
||||
<div class="menu_icon">
|
||||
<t-icon name="add" />
|
||||
</div>
|
||||
<span class="menu_title">{{ t('knowledgeList.create') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="showDocActions">
|
||||
<div class="menu_item kb-action-item" @click.stop="handleDocUploadClick">
|
||||
<div class="menu_item-box">
|
||||
<div class="menu_icon">
|
||||
@@ -56,6 +66,7 @@
|
||||
<img class="icon" :src="getImgSrc(item.icon == 'zhishiku' ? knowledgeIcon : item.icon == 'logout' ? logoutIcon : item.icon == 'setting' ? settingIcon : prefixIcon)" alt="">
|
||||
</div>
|
||||
<span class="menu_title" :title="item.title">{{ item.title }}</span>
|
||||
<t-icon v-if="item.path === 'creatChat'" name="add" class="menu-create-hint" />
|
||||
</div>
|
||||
</div>
|
||||
<div ref="submenuscrollContainer" @scroll="handleScroll" class="submenu" v-if="item.children">
|
||||
@@ -142,6 +153,11 @@ const isInKnowledgeBase = computed<boolean>(() => {
|
||||
route.name === 'knowledgeBaseSettings';
|
||||
});
|
||||
|
||||
// 是否在知识库列表页面
|
||||
const isInKnowledgeBaseList = computed<boolean>(() => {
|
||||
return route.name === 'knowledgeBaseList';
|
||||
});
|
||||
|
||||
// 统一的菜单项激活状态判断
|
||||
const isMenuItemActive = (itemPath: string): boolean => {
|
||||
const currentRoute = route.name;
|
||||
@@ -198,10 +214,11 @@ const currentKbInfo = ref<any>(null)
|
||||
const docUploadInput = ref<HTMLInputElement | null>(null)
|
||||
const pendingUploadKbId = ref<string | null>(null)
|
||||
|
||||
const showKbActions = computed(() => isInKnowledgeBase.value && !!currentKbInfo.value)
|
||||
const showKbActions = computed(() => (isInKnowledgeBase.value && !!currentKbInfo.value) || isInKnowledgeBaseList.value)
|
||||
const currentKbType = computed(() => currentKbInfo.value?.type || 'document')
|
||||
const showDocActions = computed(() => showKbActions.value && currentKbType.value !== 'faq')
|
||||
const showFaqActions = computed(() => showKbActions.value && currentKbType.value === 'faq')
|
||||
const showDocActions = computed(() => showKbActions.value && isInKnowledgeBase.value && currentKbType.value !== 'faq')
|
||||
const showFaqActions = computed(() => showKbActions.value && isInKnowledgeBase.value && currentKbType.value === 'faq')
|
||||
const showCreateKbAction = computed(() => showKbActions.value && isInKnowledgeBaseList.value)
|
||||
|
||||
// 时间分组函数
|
||||
const getTimeCategory = (dateStr: string): string => {
|
||||
@@ -633,6 +650,10 @@ const handleFaqImportFromMenu = async () => {
|
||||
dispatchFaqMenuAction('import', kbId)
|
||||
}
|
||||
|
||||
const handleCreateKnowledgeBase = () => {
|
||||
uiStore.openCreateKB()
|
||||
}
|
||||
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
.aside_box {
|
||||
@@ -775,6 +796,11 @@ const handleFaqImportFromMenu = async () => {
|
||||
.menu_title {
|
||||
color: #07c05f !important;
|
||||
}
|
||||
|
||||
.menu-create-hint {
|
||||
color: #07c05f !important;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.menu_item_c_active {
|
||||
@@ -1033,6 +1059,20 @@ const handleFaqImportFromMenu = async () => {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.menu-create-hint {
|
||||
margin-left: auto;
|
||||
margin-right: 8px;
|
||||
font-size: 16px;
|
||||
color: #07c05f;
|
||||
opacity: 0.7;
|
||||
transition: opacity 0.2s ease;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.menu_item:hover .menu-create-hint {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.menu_box {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
@@ -687,6 +687,7 @@ export default {
|
||||
knowledgeList: {
|
||||
create: 'Create Knowledge Base',
|
||||
createFAQ: 'Create FAQ Knowledge Base',
|
||||
subtitle: 'Manage and organize your knowledge bases, supporting document-based and FAQ-based knowledge bases',
|
||||
uninitializedBanner: 'Some knowledge bases are not initialized. Configure model information in settings before adding documents.',
|
||||
empty: {
|
||||
title: 'No knowledge bases yet',
|
||||
|
||||
@@ -781,6 +781,7 @@ export default {
|
||||
knowledgeList: {
|
||||
create: 'Создать базу знаний',
|
||||
createFAQ: 'Создать FAQ-базу',
|
||||
subtitle: 'Управляйте и организуйте свои базы знаний, поддерживаются документные и FAQ-базы знаний',
|
||||
uninitializedBanner: 'Некоторые базы знаний не инициализированы. Сначала настройте модели в разделе настроек, чтобы добавлять документы.',
|
||||
empty: {
|
||||
title: 'Базы знаний отсутствуют',
|
||||
|
||||
@@ -1004,6 +1004,7 @@ export default {
|
||||
knowledgeList: {
|
||||
create: "新建知识库",
|
||||
createFAQ: "新建 FAQ 知识库",
|
||||
subtitle: "管理和组织您的知识库,支持文档型和问答型知识库",
|
||||
uninitializedBanner:
|
||||
"部分知识库尚未初始化,需要先在设置中配置模型信息才能添加知识文档",
|
||||
empty: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, onUnmounted, watch, reactive, computed, nextTick, type ComponentPublicInstance } from "vue";
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
import { ref, onMounted, onUnmounted, watch, reactive, computed, nextTick, h, type ComponentPublicInstance } from "vue";
|
||||
import { MessagePlugin, Icon as TIcon } from "tdesign-vue-next";
|
||||
import DocContent from "@/components/doc-content.vue";
|
||||
import useKnowledgeBase from '@/hooks/useKnowledgeBase';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
@@ -34,7 +34,7 @@ const uploadInputRef = ref<HTMLInputElement | null>(null);
|
||||
const uploading = ref(false);
|
||||
const kbLoading = ref(false);
|
||||
const isFAQ = computed(() => (kbInfo.value?.type || '') === 'faq');
|
||||
const knowledgeList = ref<Array<{ id: string; name: string }>>([]);
|
||||
const knowledgeList = ref<Array<{ id: string; name: string; type?: string }>>([]);
|
||||
let { cardList, total, moreIndex, details, getKnowled, delKnowledge, openMore, onVisibleChange, getCardDetails, getfDetails } = useKnowledgeBase(kbId.value)
|
||||
let isCardDetails = ref(false);
|
||||
let timeout: ReturnType<typeof setInterval> | null = null;
|
||||
@@ -345,6 +345,7 @@ const loadKnowledgeList = async () => {
|
||||
knowledgeList.value = (res?.data || []).map((item: any) => ({
|
||||
id: String(item.id),
|
||||
name: item.name,
|
||||
type: item.type || 'document',
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('Failed to load knowledge list:', error);
|
||||
@@ -580,6 +581,7 @@ const knowledgeDropdownOptions = computed(() =>
|
||||
knowledgeList.value.map((item) => ({
|
||||
content: item.name,
|
||||
value: item.id,
|
||||
prefixIcon: () => h(TIcon, { name: item.type === 'faq' ? 'help-circle' : 'folder', size: '16px' }),
|
||||
}))
|
||||
);
|
||||
|
||||
@@ -718,30 +720,6 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</div>
|
||||
<p class="document-subtitle">{{ $t('knowledgeEditor.document.subtitle') }}</p>
|
||||
</div>
|
||||
<div class="document-header-actions">
|
||||
<t-button
|
||||
class="document-action-btn primary"
|
||||
size="medium"
|
||||
:loading="uploading"
|
||||
:disabled="uploading"
|
||||
@click="handleDocumentUploadClick"
|
||||
>
|
||||
<template #icon>
|
||||
<t-icon name="upload" />
|
||||
</template>
|
||||
{{ $t('upload.uploadDocument') }}
|
||||
</t-button>
|
||||
<t-button
|
||||
class="document-action-btn secondary"
|
||||
size="medium"
|
||||
@click="handleManualCreate"
|
||||
>
|
||||
<template #icon>
|
||||
<t-icon name="edit" />
|
||||
</template>
|
||||
{{ $t('upload.onlineEdit') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
<input
|
||||
ref="uploadInputRef"
|
||||
@@ -1544,64 +1522,6 @@ async function createNewSession(value: string): Promise<void> {
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.document-header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
|
||||
.document-action-btn {
|
||||
min-width: 148px;
|
||||
height: 38px;
|
||||
border-radius: 8px;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
padding: 0 18px;
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
:deep(.t-icon) {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
&.primary {
|
||||
background: linear-gradient(90deg, #07c05f, #05a04f);
|
||||
border-color: transparent;
|
||||
color: #fff;
|
||||
box-shadow: 0 6px 14px rgba(7, 192, 95, 0.2);
|
||||
|
||||
&:hover {
|
||||
background: linear-gradient(90deg, #08d067, #05a04f);
|
||||
box-shadow: 0 8px 16px rgba(7, 192, 95, 0.25);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.7;
|
||||
box-shadow: none;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
&.secondary {
|
||||
background: #ffffff;
|
||||
border-color: #07c05f;
|
||||
color: #07c05f;
|
||||
|
||||
&:hover {
|
||||
background: #f3fdf7;
|
||||
border-color: #05a04f;
|
||||
color: #059669;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.document-upload-input {
|
||||
|
||||
@@ -2,14 +2,12 @@
|
||||
<div class="kb-list-container">
|
||||
<!-- 头部 -->
|
||||
<div class="header">
|
||||
<h2>{{ $t('knowledgeBase.title') }}</h2>
|
||||
<div class="action-buttons">
|
||||
<button class="create-btn ghost" @click="openCreateModal">
|
||||
<t-icon name="add" size="16px" class="btn-icon" />
|
||||
<span>{{ $t('knowledgeList.create') }}</span>
|
||||
</button>
|
||||
<div class="header-title">
|
||||
<h2>{{ $t('knowledgeBase.title') }}</h2>
|
||||
<p class="header-subtitle">{{ $t('knowledgeList.subtitle') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="header-divider"></div>
|
||||
|
||||
<!-- 未初始化知识库提示 -->
|
||||
<div v-if="hasUninitializedKbs" class="warning-banner">
|
||||
@@ -177,11 +175,6 @@ onMounted(() => {
|
||||
fetchList()
|
||||
})
|
||||
|
||||
// 打开创建知识库弹窗
|
||||
const openCreateModal = () => {
|
||||
uiStore.openCreateKB()
|
||||
}
|
||||
|
||||
const openMore = (index: number) => {
|
||||
// 只记录当前打开的索引,用于显示激活样式
|
||||
// 弹窗的开关由 v-model 自动管理
|
||||
@@ -274,7 +267,13 @@ const handleKBEditorSuccess = (kbId: string) => {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 20px;
|
||||
margin-bottom: 16px;
|
||||
|
||||
.header-title {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 0;
|
||||
@@ -286,72 +285,19 @@ const handleKBEditorSuccess = (kbId: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.create-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 24px;
|
||||
height: 40px;
|
||||
border-radius: 8px;
|
||||
.header-subtitle {
|
||||
margin: 0;
|
||||
color: #00000099;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
.btn-icon {
|
||||
flex-shrink: 0;
|
||||
font-size: 16px;
|
||||
}
|
||||
font-weight: 400;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.create-btn.primary {
|
||||
background: #07c05f;
|
||||
color: #fff;
|
||||
border: none;
|
||||
box-shadow: 0 2px 6px 0 rgba(7, 192, 95, 0.2);
|
||||
|
||||
&:hover {
|
||||
background: #05a855;
|
||||
box-shadow: 0 3px 8px 0 rgba(7, 192, 95, 0.28);
|
||||
}
|
||||
|
||||
&:active {
|
||||
background: #048f45;
|
||||
}
|
||||
}
|
||||
|
||||
.create-btn.ghost {
|
||||
background: #ffffff;
|
||||
color: #07c05f;
|
||||
border: 1.5px solid #d4edde;
|
||||
box-shadow: none;
|
||||
|
||||
.btn-icon {
|
||||
color: #07c05f;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: #f6fdf9;
|
||||
border-color: #07c05f;
|
||||
color: #059669;
|
||||
|
||||
.btn-icon {
|
||||
color: #059669;
|
||||
}
|
||||
}
|
||||
|
||||
&:active {
|
||||
background: #ecfdf5;
|
||||
border-color: #05a855;
|
||||
}
|
||||
.header-divider {
|
||||
height: 1px;
|
||||
background: #e7ebf0;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.warning-banner {
|
||||
|
||||
@@ -52,28 +52,6 @@
|
||||
</div>
|
||||
<p class="faq-subtitle">{{ $t('knowledgeEditor.faq.subtitle') }}</p>
|
||||
</div>
|
||||
<div class="faq-header-actions">
|
||||
<t-button
|
||||
class="faq-action-btn primary"
|
||||
size="medium"
|
||||
@click="openEditor()"
|
||||
>
|
||||
<template #icon>
|
||||
<t-icon name="add" />
|
||||
</template>
|
||||
{{ $t('knowledgeEditor.faq.editorCreate') }}
|
||||
</t-button>
|
||||
<t-dropdown
|
||||
:options="toolbarActionOptions"
|
||||
placement="bottom-left"
|
||||
trigger="click"
|
||||
@click="handleToolbarAction"
|
||||
>
|
||||
<t-button class="faq-action-btn secondary icon-only" size="medium">
|
||||
<t-icon name="more" />
|
||||
</t-button>
|
||||
</t-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="faq-main">
|
||||
@@ -988,9 +966,9 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, watch, onMounted, computed, nextTick, onUnmounted } from 'vue'
|
||||
import { ref, reactive, watch, onMounted, computed, nextTick, onUnmounted, h } from 'vue'
|
||||
import type { ComponentPublicInstance } from 'vue'
|
||||
import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
|
||||
import { MessagePlugin, DialogPlugin, Icon as TIcon } from 'tdesign-vue-next'
|
||||
import type { FormRules, FormInstanceFunctions } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useRouter } from 'vue-router'
|
||||
@@ -1122,6 +1100,7 @@ const knowledgeDropdownOptions = computed(() =>
|
||||
.map((item) => ({
|
||||
content: item.name,
|
||||
value: item.id,
|
||||
prefixIcon: () => h(TIcon, { name: item.type === 'faq' ? 'help-circle' : 'file', size: '16px' }),
|
||||
})),
|
||||
)
|
||||
|
||||
@@ -2781,13 +2760,6 @@ watch(() => entries.value.map(e => ({
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.faq-header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
|
||||
.tag-filter-bar {
|
||||
@@ -2802,56 +2774,6 @@ watch(() => entries.value.map(e => ({
|
||||
}
|
||||
}
|
||||
|
||||
.faq-action-btn {
|
||||
min-width: 148px;
|
||||
height: 38px;
|
||||
border-radius: 8px;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
padding: 0 18px;
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
:deep(.t-icon) {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
&.primary {
|
||||
background: linear-gradient(90deg, #07c05f, #05a04f);
|
||||
border-color: transparent;
|
||||
color: #fff;
|
||||
box-shadow: 0 6px 14px rgba(7, 192, 95, 0.2);
|
||||
|
||||
&:hover {
|
||||
background: linear-gradient(90deg, #08d067, #05a04f);
|
||||
box-shadow: 0 8px 16px rgba(7, 192, 95, 0.25);
|
||||
}
|
||||
}
|
||||
|
||||
&.secondary {
|
||||
background: #ffffff;
|
||||
border-color: #07c05f;
|
||||
color: #07c05f;
|
||||
|
||||
&:hover {
|
||||
background: #f3fdf7;
|
||||
border-color: #05a04f;
|
||||
color: #059669;
|
||||
}
|
||||
}
|
||||
|
||||
&.icon-only {
|
||||
min-width: auto;
|
||||
width: 38px;
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.kb-settings-button {
|
||||
width: 30px;
|
||||
|
||||
Reference in New Issue
Block a user