feat: add organization management features
- Introduced a new API for organization management, including creation, updating, and deletion of organizations. - Implemented organization sharing functionality for knowledge bases, allowing users to share knowledge bases with specific organizations and set permissions. - Added UI components for organization selection and sharing dialogs. - Enhanced existing components to support organization-related features, including shared knowledge base handling and organization role management. This update enhances collaboration capabilities within the application by allowing users to manage and share knowledge bases across different organizations.
This commit is contained in:
@@ -8,9 +8,13 @@ import EmptyKnowledge from '@/components/empty-knowledge.vue';
|
||||
import { getSessionsList, createSessions, generateSessionsTitle } from "@/api/chat/index";
|
||||
import { useMenuStore } from '@/stores/menu';
|
||||
import { useUIStore } from '@/stores/ui';
|
||||
import { useOrganizationStore } from '@/stores/organization';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import KnowledgeBaseEditorModal from './KnowledgeBaseEditorModal.vue';
|
||||
const usemenuStore = useMenuStore();
|
||||
const uiStore = useUIStore();
|
||||
const orgStore = useOrganizationStore();
|
||||
const authStore = useAuthStore();
|
||||
const router = useRouter();
|
||||
import {
|
||||
batchQueryKnowledge,
|
||||
@@ -32,9 +36,59 @@ const { t } = useI18n();
|
||||
const kbId = computed(() => (route.params as any).kbId as string || '');
|
||||
const kbInfo = ref<any>(null);
|
||||
const uploadInputRef = ref<HTMLInputElement | null>(null);
|
||||
const folderUploadInputRef = ref<HTMLInputElement | null>(null);
|
||||
const uploading = ref(false);
|
||||
const kbLoading = ref(false);
|
||||
const isFAQ = computed(() => (kbInfo.value?.type || '') === 'faq');
|
||||
|
||||
// Permission control: check if current user owns this KB or has edit/manage permission
|
||||
const isOwner = computed(() => {
|
||||
if (!kbInfo.value) return false;
|
||||
// Check if the current user's tenant ID matches the KB's tenant ID
|
||||
const userTenantId = authStore.effectiveTenantId;
|
||||
return kbInfo.value.tenant_id === userTenantId;
|
||||
});
|
||||
|
||||
// Can edit: owner, admin, or editor
|
||||
const canEdit = computed(() => {
|
||||
return orgStore.canEditKB(kbId.value, isOwner.value);
|
||||
});
|
||||
|
||||
// Can manage (delete, settings, etc.): owner or admin
|
||||
const canManage = computed(() => {
|
||||
return orgStore.canManageKB(kbId.value, isOwner.value);
|
||||
});
|
||||
|
||||
// Current KB's shared record (when accessed via organization share)
|
||||
const currentSharedKb = computed(() =>
|
||||
orgStore.sharedKnowledgeBases.find((s) => s.knowledge_base?.id === kbId.value) ?? null,
|
||||
);
|
||||
|
||||
// Display role label: owner or org role (admin/editor/viewer)
|
||||
const accessRoleLabel = computed(() => {
|
||||
if (isOwner.value) return t('knowledgeBase.accessInfo.roleOwner');
|
||||
const perm = orgStore.getKBPermission(kbId.value);
|
||||
if (perm) return t(`organization.role.${perm}`);
|
||||
return '--';
|
||||
});
|
||||
|
||||
// Permission summary text for current role
|
||||
const accessPermissionSummary = computed(() => {
|
||||
if (isOwner.value) return t('knowledgeBase.accessInfo.permissionOwner');
|
||||
const perm = orgStore.getKBPermission(kbId.value);
|
||||
if (perm === 'admin') return t('knowledgeBase.accessInfo.permissionAdmin');
|
||||
if (perm === 'editor') return t('knowledgeBase.accessInfo.permissionEditor');
|
||||
if (perm === 'viewer') return t('knowledgeBase.accessInfo.permissionViewer');
|
||||
return '--';
|
||||
});
|
||||
|
||||
// Last updated time from kbInfo
|
||||
const kbLastUpdated = computed(() => {
|
||||
const raw = kbInfo.value?.updated_at;
|
||||
if (!raw) return null;
|
||||
return formatStringDate(new Date(raw));
|
||||
});
|
||||
|
||||
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);
|
||||
@@ -397,11 +451,26 @@ const loadKnowledgeBaseInfo = async (targetKbId: string) => {
|
||||
const loadKnowledgeList = async () => {
|
||||
try {
|
||||
const res: any = await listKnowledgeBases();
|
||||
knowledgeList.value = (res?.data || []).map((item: any) => ({
|
||||
const myKbs = (res?.data || []).map((item: any) => ({
|
||||
id: String(item.id),
|
||||
name: item.name,
|
||||
type: item.type || 'document',
|
||||
}));
|
||||
|
||||
// Also include shared knowledge bases from orgStore
|
||||
const sharedKbs = (orgStore.sharedKnowledgeBases || [])
|
||||
.filter(s => s.knowledge_base != null)
|
||||
.map(s => ({
|
||||
id: String(s.knowledge_base.id),
|
||||
name: s.knowledge_base.name,
|
||||
type: s.knowledge_base.type || 'document',
|
||||
}));
|
||||
|
||||
// Merge and deduplicate by id (my KBs take precedence)
|
||||
const myKbIds = new Set(myKbs.map(kb => kb.id));
|
||||
const uniqueSharedKbs = sharedKbs.filter(kb => !myKbIds.has(kb.id));
|
||||
|
||||
knowledgeList.value = [...myKbs, ...uniqueSharedKbs];
|
||||
} catch (error) {
|
||||
console.error('Failed to load knowledge list:', error);
|
||||
}
|
||||
@@ -485,7 +554,9 @@ const handleOpenURLImportDialog = (event: CustomEvent) => {
|
||||
onMounted(() => {
|
||||
loadKnowledgeBaseInfo(kbId.value);
|
||||
loadKnowledgeList();
|
||||
|
||||
// Load shared knowledge bases to get permission info
|
||||
orgStore.fetchSharedKnowledgeBases();
|
||||
|
||||
// 监听文件上传事件
|
||||
window.addEventListener('knowledgeFileUploaded', handleFileUploaded as EventListener);
|
||||
// 监听URL导入对话框打开事件
|
||||
@@ -587,6 +658,32 @@ const documentTitle = computed(() => {
|
||||
return t('knowledgeEditor.document.title');
|
||||
});
|
||||
|
||||
// 文档操作下拉菜单选项
|
||||
const documentActionOptions = computed(() => [
|
||||
{ content: t('upload.uploadDocument'), value: 'upload', prefixIcon: () => h(TIcon, { name: 'upload', size: '16px' }) },
|
||||
{ content: t('upload.uploadFolder'), value: 'uploadFolder', prefixIcon: () => h(TIcon, { name: 'folder-add', size: '16px' }) },
|
||||
{ content: t('knowledgeBase.importURL'), value: 'importURL', prefixIcon: () => h(TIcon, { name: 'link', size: '16px' }) },
|
||||
{ content: t('upload.onlineEdit'), value: 'manualCreate', prefixIcon: () => h(TIcon, { name: 'edit', size: '16px' }) },
|
||||
]);
|
||||
|
||||
// 处理文档操作下拉菜单选择
|
||||
const handleDocumentActionSelect = (data: { value: string }) => {
|
||||
switch (data.value) {
|
||||
case 'upload':
|
||||
handleDocumentUploadClick();
|
||||
break;
|
||||
case 'uploadFolder':
|
||||
handleFolderUploadClick();
|
||||
break;
|
||||
case 'importURL':
|
||||
handleURLImportClick();
|
||||
break;
|
||||
case 'manualCreate':
|
||||
handleManualCreate();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const ensureDocumentKbReady = () => {
|
||||
if (isFAQ.value) {
|
||||
MessagePlugin.warning('当前知识库类型不支持该操作');
|
||||
@@ -609,6 +706,11 @@ const handleDocumentUploadClick = () => {
|
||||
uploadInputRef.value?.click();
|
||||
};
|
||||
|
||||
const handleFolderUploadClick = () => {
|
||||
if (!ensureDocumentKbReady()) return;
|
||||
folderUploadInputRef.value?.click();
|
||||
};
|
||||
|
||||
const resetUploadInput = () => {
|
||||
if (uploadInputRef.value) {
|
||||
uploadInputRef.value.value = '';
|
||||
@@ -705,6 +807,102 @@ const handleDocumentUpload = async (event: Event) => {
|
||||
resetUploadInput();
|
||||
};
|
||||
|
||||
// 处理文件夹上传
|
||||
const handleFolderUpload = async (event: Event) => {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const files = input?.files;
|
||||
if (!files || files.length === 0) return;
|
||||
|
||||
if (!kbId.value) {
|
||||
MessagePlugin.error("缺少知识库ID");
|
||||
if (input) input.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否启用了VLM
|
||||
const vlmEnabled = kbInfo.value?.vlm_config?.enabled || false;
|
||||
|
||||
// 过滤有效文件
|
||||
const validFiles: File[] = [];
|
||||
let hiddenFileCount = 0;
|
||||
let imageFilteredCount = 0;
|
||||
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = files[i];
|
||||
const relativePath = (file as any).webkitRelativePath || file.name;
|
||||
|
||||
// 1. 过滤隐藏文件和隐藏文件夹
|
||||
const pathParts = relativePath.split('/');
|
||||
const hasHiddenComponent = pathParts.some((part: string) => part.startsWith('.'));
|
||||
if (hasHiddenComponent) {
|
||||
hiddenFileCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 2. 如果未启用VLM,过滤图片文件
|
||||
if (!vlmEnabled) {
|
||||
const fileExt = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase();
|
||||
const imageTypes = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
|
||||
if (imageTypes.includes(fileExt)) {
|
||||
imageFilteredCount++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 文件类型验证
|
||||
if (!kbFileTypeVerification(file, true)) {
|
||||
validFiles.push(file);
|
||||
}
|
||||
}
|
||||
|
||||
if (validFiles.length === 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.noValidFilesInFolder', { total: files.length }));
|
||||
if (input) input.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
MessagePlugin.info(t('knowledgeBase.uploadingFolder', { total: validFiles.length }));
|
||||
|
||||
// 批量上传
|
||||
let successCount = 0;
|
||||
let failCount = 0;
|
||||
const tagIdToUpload = selectedTagId.value !== '__untagged__' ? selectedTagId.value : undefined;
|
||||
|
||||
for (const file of validFiles) {
|
||||
const relativePath = (file as any).webkitRelativePath;
|
||||
let fileName = file.name;
|
||||
if (relativePath) {
|
||||
const pathParts = relativePath.split('/');
|
||||
if (pathParts.length > 2) {
|
||||
const subPath = pathParts.slice(1, -1).join('/');
|
||||
fileName = `${subPath}/${file.name}`;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await uploadKnowledgeFile(kbId.value, { file, fileName, tag_id: tagIdToUpload });
|
||||
successCount++;
|
||||
} catch (error: any) {
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (successCount > 0) {
|
||||
window.dispatchEvent(new CustomEvent('knowledgeFileUploaded', {
|
||||
detail: { kbId: kbId.value }
|
||||
}));
|
||||
}
|
||||
|
||||
if (failCount === 0) {
|
||||
MessagePlugin.success(t('knowledgeBase.uploadAllSuccess', { count: successCount }));
|
||||
} else if (successCount > 0) {
|
||||
MessagePlugin.warning(t('knowledgeBase.uploadPartialSuccess', { success: successCount, fail: failCount }));
|
||||
} else {
|
||||
MessagePlugin.error(t('knowledgeBase.uploadAllFailed'));
|
||||
}
|
||||
|
||||
if (input) input.value = '';
|
||||
};
|
||||
|
||||
const handleManualCreate = () => {
|
||||
if (!ensureDocumentKbReady()) return;
|
||||
@@ -939,7 +1137,7 @@ async function createNewSession(value: string): Promise<void> {
|
||||
<t-icon name="chevron-right" class="breadcrumb-separator" />
|
||||
<span class="breadcrumb-current">{{ $t('knowledgeEditor.document.title') }}</span>
|
||||
</h2>
|
||||
<t-tooltip :content="$t('knowledgeBase.settings')" placement="top">
|
||||
<t-tooltip v-if="canManage" :content="$t('knowledgeBase.settings')" placement="top">
|
||||
<button
|
||||
type="button"
|
||||
class="kb-settings-button"
|
||||
@@ -951,6 +1149,41 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</t-tooltip>
|
||||
</div>
|
||||
<p class="document-subtitle">{{ $t('knowledgeEditor.document.subtitle') }}</p>
|
||||
<!-- 当前知识库权限与来源信息 -->
|
||||
<div v-if="kbInfo" class="kb-access-info">
|
||||
<span class="kb-access-role">
|
||||
<span class="kb-access-label">{{ $t('knowledgeBase.accessInfo.myRole') }}:</span>
|
||||
<t-tag size="small" :theme="isOwner ? 'success' : (currentSharedKb?.permission === 'admin' ? 'primary' : currentSharedKb?.permission === 'editor' ? 'warning' : 'default')">
|
||||
{{ accessRoleLabel }}
|
||||
</t-tag>
|
||||
</span>
|
||||
<span class="kb-access-summary">{{ accessPermissionSummary }}</span>
|
||||
<template v-if="currentSharedKb">
|
||||
<span class="kb-access-sep">·</span>
|
||||
<span class="kb-access-source">
|
||||
{{ $t('knowledgeBase.accessInfo.fromOrg') }}「{{ currentSharedKb.org_name }}」
|
||||
{{ $t('knowledgeBase.accessInfo.sharedAt') }} {{ formatStringDate(new Date(currentSharedKb.shared_at)) }}
|
||||
</span>
|
||||
</template>
|
||||
<template v-else-if="kbLastUpdated">
|
||||
<span class="kb-access-sep">·</span>
|
||||
<span class="kb-access-updated">{{ $t('knowledgeBase.accessInfo.lastUpdated') }} {{ kbLastUpdated }}</span>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="canEdit" class="document-header-actions">
|
||||
<t-dropdown
|
||||
:options="documentActionOptions"
|
||||
trigger="click"
|
||||
placement="bottom-right"
|
||||
@click="handleDocumentActionSelect"
|
||||
>
|
||||
<t-button class="doc-action-btn dropdown-action-btn">
|
||||
<template #icon><t-icon name="file-add" /></template>
|
||||
<span>{{ $t('knowledgeBase.addDocument') }}</span>
|
||||
<t-icon name="chevron-down" size="14px" class="dropdown-arrow" />
|
||||
</t-button>
|
||||
</t-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -962,6 +1195,13 @@ async function createNewSession(value: string): Promise<void> {
|
||||
multiple
|
||||
@change="handleDocumentUpload"
|
||||
/>
|
||||
<input
|
||||
ref="folderUploadInputRef"
|
||||
type="file"
|
||||
class="document-upload-input"
|
||||
webkitdirectory
|
||||
@change="handleFolderUpload"
|
||||
/>
|
||||
<div class="knowledge-main">
|
||||
<aside class="tag-sidebar">
|
||||
<div class="sidebar-header">
|
||||
@@ -969,7 +1209,7 @@ async function createNewSession(value: string): Promise<void> {
|
||||
<span>{{ $t('knowledgeBase.documentCategoryTitle') }}</span>
|
||||
<span class="sidebar-count">({{ sidebarCategoryCount }})</span>
|
||||
</div>
|
||||
<div class="sidebar-actions">
|
||||
<div v-if="canEdit" class="sidebar-actions">
|
||||
<t-button
|
||||
size="small"
|
||||
variant="text"
|
||||
@@ -1086,7 +1326,7 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="tag-more" @click.stop>
|
||||
<div v-if="canEdit" class="tag-more" @click.stop>
|
||||
<t-popup trigger="click" placement="top-right" overlayClassName="tag-more-popup">
|
||||
<div class="tag-more-btn">
|
||||
<t-icon name="more" size="14px" />
|
||||
@@ -1168,6 +1408,7 @@ async function createNewSession(value: string): Promise<void> {
|
||||
<div class="card-content-nav">
|
||||
<span class="card-content-title">{{ item.file_name }}</span>
|
||||
<t-popup
|
||||
v-if="canEdit"
|
||||
v-model="item.isMore"
|
||||
overlayClassName="card-more"
|
||||
:on-visible-change="onVisibleChange"
|
||||
@@ -1232,6 +1473,7 @@ async function createNewSession(value: string): Promise<void> {
|
||||
<div class="card-bottom-right">
|
||||
<div v-if="tagList.length" class="card-tag-selector" @click.stop>
|
||||
<t-dropdown
|
||||
v-if="canEdit"
|
||||
:options="tagDropdownOptions"
|
||||
trigger="click"
|
||||
@click="(data: any) => handleKnowledgeTagChange(item.id, data.value as string)"
|
||||
@@ -1240,6 +1482,9 @@ async function createNewSession(value: string): Promise<void> {
|
||||
<span class="tag-text">{{ getTagName(item.tag_id) }}</span>
|
||||
</t-tag>
|
||||
</t-dropdown>
|
||||
<t-tag v-else size="small" variant="light-outline">
|
||||
<span class="tag-text">{{ getTagName(item.tag_id) }}</span>
|
||||
</t-tag>
|
||||
</div>
|
||||
<div class="card-type">
|
||||
<span>{{ getKnowledgeType(item) }}</span>
|
||||
@@ -1869,6 +2114,34 @@ async function createNewSession(value: string): Promise<void> {
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.document-header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-shrink: 0;
|
||||
|
||||
.doc-action-btn {
|
||||
background: linear-gradient(135deg, #07c05f 0%, #00a67e 100%);
|
||||
border: none;
|
||||
color: #fff;
|
||||
|
||||
&:hover {
|
||||
background: linear-gradient(135deg, #05a04f 0%, #008a6a 100%);
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.dropdown-action-btn) {
|
||||
.t-button__text {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.dropdown-arrow {
|
||||
margin-left: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.document-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -1954,8 +2227,43 @@ async function createNewSession(value: string): Promise<void> {
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.kb-access-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px 12px;
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
color: #86909c;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.kb-access-label {
|
||||
color: #4e5969;
|
||||
}
|
||||
|
||||
.kb-access-role {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.kb-access-summary {
|
||||
color: #86909c;
|
||||
}
|
||||
|
||||
.kb-access-sep {
|
||||
color: #c9ced6;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.kb-access-source,
|
||||
.kb-access-updated {
|
||||
color: #86909c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.document-upload-input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@@ -150,6 +150,11 @@
|
||||
@update:question-generation="handleQuestionGenerationUpdate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 共享设置(仅编辑模式) -->
|
||||
<div v-if="mode === 'edit' && kbId" v-show="currentSection === 'share'" class="section">
|
||||
<KBShareSettings :kb-id="kbId" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 保存按钮 -->
|
||||
@@ -180,6 +185,7 @@ import KBModelConfig from './settings/KBModelConfig.vue'
|
||||
import KBChunkingSettings from './settings/KBChunkingSettings.vue'
|
||||
import KBAdvancedSettings from './settings/KBAdvancedSettings.vue'
|
||||
import GraphSettings from './settings/GraphSettings.vue'
|
||||
import KBShareSettings from './settings/KBShareSettings.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const uiStore = useUIStore()
|
||||
@@ -219,6 +225,10 @@ const navItems = computed(() => {
|
||||
{ key: 'advanced', icon: 'setting', label: t('knowledgeEditor.sidebar.advanced') }
|
||||
)
|
||||
}
|
||||
// 只在编辑模式下显示共享标签页
|
||||
if (props.mode === 'edit' && props.kbId) {
|
||||
items.push({ key: 'share', icon: 'share', label: t('knowledgeEditor.sidebar.share') })
|
||||
}
|
||||
return items
|
||||
})
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -39,11 +39,10 @@
|
||||
<t-icon name="chevron-right" class="breadcrumb-separator" />
|
||||
<span class="breadcrumb-current">{{ $t('knowledgeEditor.faq.title') }}</span>
|
||||
</h2>
|
||||
<t-tooltip :content="$t('knowledgeBase.settings')" placement="top">
|
||||
<t-tooltip v-if="canManage" :content="$t('knowledgeBase.settings')" placement="top">
|
||||
<button
|
||||
type="button"
|
||||
class="kb-settings-button"
|
||||
:disabled="!props.kbId"
|
||||
@click="handleOpenKBSettings"
|
||||
>
|
||||
<t-icon name="setting" size="16px" />
|
||||
@@ -51,6 +50,41 @@
|
||||
</t-tooltip>
|
||||
</div>
|
||||
<p class="faq-subtitle">{{ $t('knowledgeEditor.faq.subtitle') }}</p>
|
||||
<!-- 当前知识库权限与来源信息 -->
|
||||
<div v-if="kbInfo" class="faq-access-info">
|
||||
<span class="faq-access-role">
|
||||
<span class="faq-access-label">{{ $t('knowledgeBase.accessInfo.myRole') }}:</span>
|
||||
<t-tag size="small" :theme="isOwner ? 'success' : (currentSharedKb?.permission === 'admin' ? 'primary' : currentSharedKb?.permission === 'editor' ? 'warning' : 'default')">
|
||||
{{ accessRoleLabel }}
|
||||
</t-tag>
|
||||
</span>
|
||||
<span class="faq-access-summary">{{ accessPermissionSummary }}</span>
|
||||
<template v-if="currentSharedKb">
|
||||
<span class="faq-access-sep">·</span>
|
||||
<span class="faq-access-source">
|
||||
{{ $t('knowledgeBase.accessInfo.fromOrg') }}「{{ currentSharedKb.org_name }}」
|
||||
{{ $t('knowledgeBase.accessInfo.sharedAt') }} {{ formatImportTime(currentSharedKb.shared_at) }}
|
||||
</span>
|
||||
</template>
|
||||
<template v-else-if="kbLastUpdated">
|
||||
<span class="faq-access-sep">·</span>
|
||||
<span class="faq-access-updated">{{ $t('knowledgeBase.accessInfo.lastUpdated') }} {{ kbLastUpdated }}</span>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<div class="faq-header-actions">
|
||||
<t-dropdown
|
||||
:options="faqActionOptions"
|
||||
trigger="click"
|
||||
placement="bottom-right"
|
||||
@click="handleFaqAction"
|
||||
>
|
||||
<t-button class="faq-action-btn dropdown-action-btn">
|
||||
<template #icon><t-icon name="help-circle" /></template>
|
||||
<span>{{ $t('knowledgeEditor.faq.manageFaq') }}</span>
|
||||
<t-icon name="chevron-down" size="14px" class="dropdown-arrow" />
|
||||
</t-button>
|
||||
</t-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -173,7 +207,7 @@
|
||||
<span>{{ $t('knowledgeBase.faqCategoryTitle') }}</span>
|
||||
<span class="sidebar-count">({{ sidebarCategoryCount }})</span>
|
||||
</div>
|
||||
<div class="sidebar-actions">
|
||||
<div v-if="canEdit" class="sidebar-actions">
|
||||
<t-button
|
||||
size="small"
|
||||
variant="text"
|
||||
@@ -290,7 +324,7 @@
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="tag-more" @click.stop>
|
||||
<div v-if="canEdit" class="tag-more" @click.stop>
|
||||
<t-popup trigger="click" placement="top-right" overlayClassName="tag-more-popup">
|
||||
<div class="tag-more-btn">
|
||||
<t-icon name="more" size="14px" />
|
||||
@@ -359,6 +393,7 @@
|
||||
</div>
|
||||
<div class="faq-card-actions">
|
||||
<t-popup
|
||||
v-if="canManage"
|
||||
v-model="entry.showMore"
|
||||
overlayClassName="faq-card-popup"
|
||||
trigger="click"
|
||||
@@ -502,7 +537,7 @@
|
||||
<!-- Card Footer -->
|
||||
<div class="faq-card-footer">
|
||||
<div class="faq-card-tag" @click.stop>
|
||||
<template v-if="tagList.length">
|
||||
<template v-if="canEdit && tagList.length">
|
||||
<t-dropdown
|
||||
:options="tagDropdownOptions"
|
||||
trigger="click"
|
||||
@@ -539,22 +574,21 @@
|
||||
</div>
|
||||
</t-tooltip>
|
||||
-->
|
||||
<t-tooltip
|
||||
:content="entry.is_enabled ? $t('knowledgeEditor.faq.statusEnabled') : $t('knowledgeEditor.faq.statusDisabled')"
|
||||
placement="top"
|
||||
>
|
||||
<div class="status-item-compact">
|
||||
<t-switch
|
||||
:key="`${entry.id}-${entry.is_enabled}`"
|
||||
size="small"
|
||||
:value="entry.is_enabled"
|
||||
:loading="!!entryStatusLoading[entry.id]"
|
||||
:disabled="!!entryStatusLoading[entry.id]"
|
||||
@click.stop
|
||||
@change="(value: boolean) => handleEntryStatusChange(entry, value)"
|
||||
/>
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip
|
||||
:content="entry.is_enabled ? $t('knowledgeEditor.faq.statusEnabled') : $t('knowledgeEditor.faq.statusDisabled')"
|
||||
placement="top"
|
||||
>
|
||||
<div class="status-item-compact">
|
||||
<t-switch
|
||||
:key="`${entry.id}-${entry.is_enabled}`"
|
||||
size="small"
|
||||
:value="entry.is_enabled"
|
||||
:loading="!!entryStatusLoading[entry.id]"
|
||||
:disabled="!!entryStatusLoading[entry.id] || !canEdit"
|
||||
@click.stop @change="(value: boolean) => handleEntryStatusChange(entry, value)"
|
||||
/>
|
||||
</div>
|
||||
</t-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1161,6 +1195,8 @@ 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'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useOrganizationStore } from '@/stores/organization'
|
||||
import {
|
||||
listFAQEntries,
|
||||
upsertFAQEntries,
|
||||
@@ -1226,6 +1262,95 @@ const props = defineProps<{
|
||||
const { t } = useI18n()
|
||||
const router = useRouter()
|
||||
const uiStore = useUIStore()
|
||||
const authStore = useAuthStore()
|
||||
const orgStore = useOrganizationStore()
|
||||
|
||||
// Permission control: check if current user owns this KB or has edit/manage permission
|
||||
const isOwner = computed(() => {
|
||||
if (!kbInfo.value) return false
|
||||
// Check if the current user's tenant ID matches the KB's tenant ID
|
||||
const userTenantId = authStore.effectiveTenantId
|
||||
return kbInfo.value.tenant_id === userTenantId
|
||||
})
|
||||
|
||||
// Can edit: owner, admin, or editor
|
||||
const canEdit = computed(() => {
|
||||
return orgStore.canEditKB(props.kbId, isOwner.value)
|
||||
})
|
||||
|
||||
// Can manage (delete, settings, etc.): owner or admin
|
||||
const canManage = computed(() => {
|
||||
return orgStore.canManageKB(props.kbId, isOwner.value)
|
||||
})
|
||||
|
||||
// Current KB's shared record (when accessed via organization share)
|
||||
const currentSharedKb = computed(() =>
|
||||
orgStore.sharedKnowledgeBases.find((s) => s.knowledge_base?.id === props.kbId) ?? null,
|
||||
)
|
||||
|
||||
// Display role label: owner or org role (admin/editor/viewer)
|
||||
const accessRoleLabel = computed(() => {
|
||||
if (isOwner.value) return t('knowledgeBase.accessInfo.roleOwner')
|
||||
const perm = orgStore.getKBPermission(props.kbId)
|
||||
if (perm) return t(`organization.role.${perm}`)
|
||||
return '--'
|
||||
})
|
||||
|
||||
// Permission summary text for current role
|
||||
const accessPermissionSummary = computed(() => {
|
||||
if (isOwner.value) return t('knowledgeBase.accessInfo.permissionOwner')
|
||||
const perm = orgStore.getKBPermission(props.kbId)
|
||||
if (perm === 'admin') return t('knowledgeBase.accessInfo.permissionAdmin')
|
||||
if (perm === 'editor') return t('knowledgeBase.accessInfo.permissionEditor')
|
||||
if (perm === 'viewer') return t('knowledgeBase.accessInfo.permissionViewer')
|
||||
return '--'
|
||||
})
|
||||
|
||||
// Last updated time from kbInfo
|
||||
const kbLastUpdated = computed(() => {
|
||||
const raw = kbInfo.value?.updated_at
|
||||
if (!raw) return null
|
||||
return formatImportTime(raw)
|
||||
})
|
||||
|
||||
// FAQ 操作下拉选项
|
||||
const faqActionOptions = computed(() => {
|
||||
const options = []
|
||||
|
||||
// 编辑权限相关操作
|
||||
if (canEdit.value) {
|
||||
options.push(
|
||||
{ content: t('knowledgeEditor.faq.editorCreate'), value: 'create', prefixIcon: () => h(TIcon, { name: 'add', size: '16px' }) },
|
||||
{ content: t('knowledgeEditor.faqImport.importButton'), value: 'import', prefixIcon: () => h(TIcon, { name: 'upload', size: '16px' }) },
|
||||
)
|
||||
}
|
||||
|
||||
// 通用操作
|
||||
options.push(
|
||||
{ content: t('knowledgeEditor.faq.searchTest'), value: 'search', prefixIcon: () => h(TIcon, { name: 'search', size: '16px' }) },
|
||||
{ content: t('knowledgeEditor.faqExport.exportButton'), value: 'export', prefixIcon: () => h(TIcon, { name: 'download', size: '16px' }) },
|
||||
)
|
||||
|
||||
return options
|
||||
})
|
||||
|
||||
// 处理 FAQ 操作
|
||||
const handleFaqAction = (data: { value: string }) => {
|
||||
switch (data.value) {
|
||||
case 'create':
|
||||
openEditor()
|
||||
break
|
||||
case 'import':
|
||||
openImportDialog()
|
||||
break
|
||||
case 'search':
|
||||
searchDrawerVisible.value = true
|
||||
break
|
||||
case 'export':
|
||||
handleExportCSV()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
const loadingMore = ref(false)
|
||||
@@ -1336,11 +1461,26 @@ const loadKnowledgeInfo = async (kbId: string) => {
|
||||
const loadKnowledgeList = async () => {
|
||||
try {
|
||||
const res: any = await listKnowledgeBases()
|
||||
knowledgeList.value = (res?.data || []).map((item: any) => ({
|
||||
const myKbs = (res?.data || []).map((item: any) => ({
|
||||
id: String(item.id),
|
||||
name: item.name,
|
||||
type: item.type,
|
||||
}))
|
||||
|
||||
// Also include shared knowledge bases from orgStore
|
||||
const sharedKbs = (orgStore.sharedKnowledgeBases || [])
|
||||
.filter(s => s.knowledge_base != null)
|
||||
.map(s => ({
|
||||
id: String(s.knowledge_base.id),
|
||||
name: s.knowledge_base.name,
|
||||
type: s.knowledge_base.type,
|
||||
}))
|
||||
|
||||
// Merge and deduplicate by id (my KBs take precedence)
|
||||
const myKbIds = new Set(myKbs.map(kb => kb.id))
|
||||
const uniqueSharedKbs = sharedKbs.filter(kb => !myKbIds.has(kb.id))
|
||||
|
||||
knowledgeList.value = [...myKbs, ...uniqueSharedKbs]
|
||||
} catch (error) {
|
||||
console.error('Failed to load knowledge bases:', error)
|
||||
}
|
||||
@@ -1671,13 +1811,15 @@ const handleKnowledgeDropdownSelect = (data: { value: string }) => {
|
||||
const handleFaqMenuAction = (event: Event) => {
|
||||
const detail = (event as CustomEvent<{ action: string; kbId: string }>).detail
|
||||
if (!detail || detail.kbId !== props.kbId) return
|
||||
|
||||
if (detail.action === 'create') {
|
||||
openEditor()
|
||||
if (canEdit.value) openEditor()
|
||||
} else if (detail.action === 'import') {
|
||||
openImportDialog()
|
||||
if (canEdit.value) openImportDialog()
|
||||
} else if (detail.action === 'search') {
|
||||
searchDrawerVisible.value = true
|
||||
} else if (detail.action === 'export') {
|
||||
// Export is usually allowed for viewers as well
|
||||
handleExportCSV()
|
||||
} else if (detail.action === 'batch') {
|
||||
// 批量操作通过左侧菜单的下拉菜单处理
|
||||
@@ -1685,19 +1827,19 @@ const handleFaqMenuAction = (event: Event) => {
|
||||
MessagePlugin.warning(t('knowledgeEditor.faq.selectEntriesFirst') || '请先选中要操作的FAQ条目')
|
||||
}
|
||||
} else if (detail.action === 'batchTag') {
|
||||
if (selectedRowKeys.value.length > 0) {
|
||||
if (canEdit.value && selectedRowKeys.value.length > 0) {
|
||||
openBatchTagDialog()
|
||||
}
|
||||
} else if (detail.action === 'batchEnable') {
|
||||
if (selectedRowKeys.value.length > 0) {
|
||||
if (canEdit.value && selectedRowKeys.value.length > 0) {
|
||||
handleBatchStatusChange(true)
|
||||
}
|
||||
} else if (detail.action === 'batchDisable') {
|
||||
if (selectedRowKeys.value.length > 0) {
|
||||
if (canEdit.value && selectedRowKeys.value.length > 0) {
|
||||
handleBatchStatusChange(false)
|
||||
}
|
||||
} else if (detail.action === 'batchDelete') {
|
||||
if (selectedRowKeys.value.length > 0) {
|
||||
if (canManage.value && selectedRowKeys.value.length > 0) {
|
||||
handleBatchDelete()
|
||||
}
|
||||
}
|
||||
@@ -3021,6 +3163,8 @@ const handleResize = () => {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
// Ensure shared knowledge bases are loaded before loading the knowledge list
|
||||
orgStore.fetchSharedKnowledgeBases()
|
||||
loadKnowledgeList()
|
||||
window.addEventListener('resize', handleResize)
|
||||
window.addEventListener('faqMenuAction', handleFaqMenuAction as EventListener)
|
||||
@@ -3603,6 +3747,160 @@ watch(() => entries.value.map(e => ({
|
||||
margin-bottom: 20px;
|
||||
border-bottom: 1px solid #e7ebf0;
|
||||
flex-shrink: 0;
|
||||
|
||||
.faq-header-title {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.faq-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.faq-breadcrumb {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #1d2129;
|
||||
}
|
||||
|
||||
.breadcrumb-link {
|
||||
border: none;
|
||||
background: transparent;
|
||||
padding: 4px 8px;
|
||||
margin: -4px -8px;
|
||||
font: inherit;
|
||||
color: #4e5969;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
border-radius: 6px;
|
||||
transition: all 0.12s ease;
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
color: #10b981;
|
||||
background: #f6f8f7;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
cursor: not-allowed;
|
||||
color: #c9ced6;
|
||||
}
|
||||
|
||||
&.dropdown {
|
||||
padding-right: 6px;
|
||||
|
||||
:deep(.t-icon) {
|
||||
font-size: 14px;
|
||||
transition: transform 0.12s ease;
|
||||
}
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
:deep(.t-icon) {
|
||||
transform: translateY(1px);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.breadcrumb-separator {
|
||||
font-size: 14px;
|
||||
color: #c9ced6;
|
||||
}
|
||||
|
||||
.breadcrumb-current {
|
||||
color: #1d2129;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 0;
|
||||
color: #1d2129;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
line-height: 32px;
|
||||
}
|
||||
|
||||
.faq-subtitle {
|
||||
margin: 0;
|
||||
color: #00000099;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.faq-access-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px 12px;
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
color: #86909c;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.faq-access-label {
|
||||
color: #4e5969;
|
||||
}
|
||||
|
||||
.faq-access-role {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.faq-access-summary {
|
||||
color: #86909c;
|
||||
}
|
||||
|
||||
.faq-access-sep {
|
||||
color: #c9ced6;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.faq-access-source,
|
||||
.faq-access-updated {
|
||||
color: #86909c;
|
||||
}
|
||||
}
|
||||
|
||||
.faq-header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-shrink: 0;
|
||||
|
||||
.faq-action-btn {
|
||||
background: linear-gradient(135deg, #26a69a 0%, #00897b 100%);
|
||||
border: none;
|
||||
color: #fff;
|
||||
|
||||
&:hover {
|
||||
background: linear-gradient(135deg, #00897b 0%, #00796b 100%);
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.dropdown-action-btn) {
|
||||
.t-button__text {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.dropdown-arrow {
|
||||
margin-left: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 导入进度条样式(显示在列表页面顶部)
|
||||
@@ -3850,97 +4148,6 @@ watch(() => entries.value.map(e => ({
|
||||
}
|
||||
}
|
||||
|
||||
.faq-header-title {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.faq-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.faq-breadcrumb {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #1d2129;
|
||||
}
|
||||
|
||||
.breadcrumb-link {
|
||||
border: none;
|
||||
background: transparent;
|
||||
padding: 4px 8px;
|
||||
margin: -4px -8px;
|
||||
font: inherit;
|
||||
color: #4e5969;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
border-radius: 6px;
|
||||
transition: all 0.12s ease;
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
color: #10b981;
|
||||
background: #f6f8f7;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
cursor: not-allowed;
|
||||
color: #c9ced6;
|
||||
}
|
||||
|
||||
&.dropdown {
|
||||
padding-right: 6px;
|
||||
|
||||
:deep(.t-icon) {
|
||||
font-size: 14px;
|
||||
transition: transform 0.12s ease;
|
||||
}
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
:deep(.t-icon) {
|
||||
transform: translateY(1px);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.breadcrumb-separator {
|
||||
font-size: 14px;
|
||||
color: #c9ced6;
|
||||
}
|
||||
|
||||
.breadcrumb-current {
|
||||
color: #1d2129;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 0;
|
||||
color: #1d2129;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
line-height: 32px;
|
||||
}
|
||||
|
||||
.faq-subtitle {
|
||||
margin: 0;
|
||||
color: #00000099;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
|
||||
.tag-filter-bar {
|
||||
display: flex;
|
||||
|
||||
@@ -0,0 +1,550 @@
|
||||
<template>
|
||||
<div class="section-content">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">{{ $t('organization.share.title') }}</h3>
|
||||
<p class="section-desc">{{ $t('knowledgeEditor.share.description') }}</p>
|
||||
</div>
|
||||
<div class="section-body">
|
||||
<!-- 共享表单 -->
|
||||
<div class="share-form">
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ $t('organization.share.selectOrg') }}</label>
|
||||
<div class="share-input-row">
|
||||
<t-select
|
||||
v-model="selectedOrgId"
|
||||
:placeholder="$t('organization.share.selectOrgPlaceholder')"
|
||||
:loading="loadingOrgs"
|
||||
class="org-select"
|
||||
>
|
||||
<t-option
|
||||
v-for="org in availableOrganizations"
|
||||
:key="org.id"
|
||||
:value="org.id"
|
||||
:label="org.name"
|
||||
>
|
||||
<div class="org-option-content">
|
||||
<div class="org-option-header">
|
||||
<span class="org-option-name">{{ org.name }}</span>
|
||||
<t-tag v-if="org.is_owner" theme="primary" size="small" variant="light">
|
||||
{{ $t('organization.owner') }}
|
||||
</t-tag>
|
||||
<t-tag v-else-if="org.my_role" :theme="org.my_role === 'admin' ? 'warning' : 'default'" size="small" variant="light">
|
||||
{{ $t(`organization.role.${org.my_role}`) }}
|
||||
</t-tag>
|
||||
</div>
|
||||
<div v-if="org.description" class="org-option-desc">{{ org.description }}</div>
|
||||
<div class="org-option-meta">
|
||||
<span class="org-meta-item">
|
||||
<t-icon name="usergroup" size="14px" />
|
||||
{{ org.member_count || 0 }} {{ $t('organization.members') }}
|
||||
</span>
|
||||
<span v-if="org.share_count !== undefined" class="org-meta-item">
|
||||
<t-icon name="share" size="14px" />
|
||||
{{ org.share_count }} {{ $t('organization.share.sharedKBs') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</t-option>
|
||||
</t-select>
|
||||
<t-select
|
||||
v-model="selectedPermission"
|
||||
class="permission-select"
|
||||
>
|
||||
<t-option value="viewer" :label="$t('organization.share.permissionReadonly')" />
|
||||
<t-option value="editor" :label="$t('organization.share.permissionEditable')" />
|
||||
</t-select>
|
||||
<t-button
|
||||
theme="primary"
|
||||
:loading="submitting"
|
||||
:disabled="!selectedOrgId"
|
||||
@click="handleShare"
|
||||
>
|
||||
{{ $t('knowledgeEditor.share.addShare') }}
|
||||
</t-button>
|
||||
</div>
|
||||
<p class="form-tip">{{ $t('organization.share.permissionTip') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 已共享列表 -->
|
||||
<div class="shares-section">
|
||||
<div class="shares-header">
|
||||
<span class="shares-title">{{ $t('organization.share.sharedTo') }}</span>
|
||||
<span class="shares-count">{{ shares.length }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="loadingShares" class="shares-loading">
|
||||
<t-loading size="small" />
|
||||
<span>{{ $t('common.loading') }}</span>
|
||||
</div>
|
||||
|
||||
<div v-else-if="shares.length === 0" class="shares-empty">
|
||||
<t-icon name="share" class="empty-icon" />
|
||||
<span>{{ $t('organization.share.noShares') }}</span>
|
||||
</div>
|
||||
|
||||
<div v-else class="shares-list">
|
||||
<div v-for="share in shares" :key="share.id" class="share-item">
|
||||
<div class="share-info">
|
||||
<div class="share-org">
|
||||
<t-icon name="usergroup" class="org-icon" />
|
||||
<span class="org-name">{{ share.organization_name }}</span>
|
||||
</div>
|
||||
<t-tag
|
||||
:theme="share.permission === 'editor' ? 'warning' : 'default'"
|
||||
size="small"
|
||||
variant="light"
|
||||
>
|
||||
{{ share.permission === 'editor' ? $t('organization.share.permissionEditable') : $t('organization.share.permissionReadonly') }}
|
||||
</t-tag>
|
||||
</div>
|
||||
<div class="share-actions">
|
||||
<t-select
|
||||
:value="share.permission"
|
||||
size="small"
|
||||
class="permission-change-select"
|
||||
@change="(val: string) => handleUpdatePermission(share, val)"
|
||||
>
|
||||
<t-option value="viewer" :label="$t('organization.share.permissionReadonly')" />
|
||||
<t-option value="editor" :label="$t('organization.share.permissionEditable')" />
|
||||
</t-select>
|
||||
<t-popconfirm
|
||||
:content="$t('knowledgeEditor.share.unshareConfirm', { name: share.organization_name })"
|
||||
@confirm="handleUnshare(share)"
|
||||
>
|
||||
<t-button variant="text" theme="danger" size="small">
|
||||
<t-icon name="delete" />
|
||||
</t-button>
|
||||
</t-popconfirm>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 提示信息 -->
|
||||
<div class="share-tips">
|
||||
<t-icon name="info-circle" class="tip-icon" />
|
||||
<div class="tip-content">
|
||||
<p>{{ $t('knowledgeEditor.share.tip1') }}</p>
|
||||
<p>{{ $t('knowledgeEditor.share.tip2') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, onMounted } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useOrganizationStore } from '@/stores/organization'
|
||||
import { shareKnowledgeBase, listKBShares, removeShare, updateSharePermission } from '@/api/organization'
|
||||
import type { KnowledgeBaseShare } from '@/api/organization'
|
||||
|
||||
const { t } = useI18n()
|
||||
const orgStore = useOrganizationStore()
|
||||
|
||||
interface Props {
|
||||
kbId: string
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const loadingOrgs = ref(false)
|
||||
const loadingShares = ref(false)
|
||||
const submitting = ref(false)
|
||||
const selectedOrgId = ref('')
|
||||
const selectedPermission = ref<'viewer' | 'editor'>('viewer')
|
||||
const shares = ref<(KnowledgeBaseShare & { organization_name?: string })[]>([])
|
||||
|
||||
// Only show organizations where user can share (editor or admin); exclude viewer-only orgs and already shared
|
||||
const availableOrganizations = computed(() => {
|
||||
const sharedOrgIds = new Set(shares.value.map(s => s.organization_id))
|
||||
return orgStore.organizations.filter(
|
||||
(org) =>
|
||||
!sharedOrgIds.has(org.id) &&
|
||||
(org.is_owner === true || org.my_role === 'admin' || org.my_role === 'editor')
|
||||
)
|
||||
})
|
||||
|
||||
// Load organizations
|
||||
async function loadOrganizations() {
|
||||
loadingOrgs.value = true
|
||||
try {
|
||||
await orgStore.fetchOrganizations()
|
||||
} finally {
|
||||
loadingOrgs.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Load shares
|
||||
async function loadShares() {
|
||||
if (!props.kbId) return
|
||||
loadingShares.value = true
|
||||
try {
|
||||
const result = await listKBShares(props.kbId)
|
||||
if (result.success && result.data) {
|
||||
// result.data is ListSharesResponse with shares array
|
||||
const sharesData = (result.data as any).shares || result.data
|
||||
const sharesList = Array.isArray(sharesData) ? sharesData : []
|
||||
shares.value = sharesList.map((share: KnowledgeBaseShare) => ({
|
||||
...share,
|
||||
organization_name: share.organization_name || orgStore.organizations.find(o => o.id === share.organization_id)?.name || share.organization_id
|
||||
}))
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load shares:', e)
|
||||
} finally {
|
||||
loadingShares.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Handle share
|
||||
async function handleShare() {
|
||||
if (!selectedOrgId.value) return
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
const result = await shareKnowledgeBase(props.kbId, {
|
||||
organization_id: selectedOrgId.value,
|
||||
permission: selectedPermission.value
|
||||
})
|
||||
if (result.success) {
|
||||
MessagePlugin.success(t('organization.share.shareSuccess'))
|
||||
selectedOrgId.value = ''
|
||||
selectedPermission.value = 'viewer'
|
||||
await loadShares()
|
||||
} else {
|
||||
MessagePlugin.error(result.message || t('organization.share.shareFailed'))
|
||||
}
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('organization.share.shareFailed'))
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Handle update permission
|
||||
async function handleUpdatePermission(share: KnowledgeBaseShare, newPermission: string) {
|
||||
if (share.permission === newPermission) return
|
||||
|
||||
try {
|
||||
const result = await updateSharePermission(props.kbId, share.id, {
|
||||
permission: newPermission as 'viewer' | 'editor'
|
||||
})
|
||||
if (result.success) {
|
||||
MessagePlugin.success(t('organization.roleUpdated'))
|
||||
await loadShares()
|
||||
} else {
|
||||
MessagePlugin.error(result.message || t('organization.roleUpdateFailed'))
|
||||
}
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('organization.roleUpdateFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
// Handle unshare
|
||||
async function handleUnshare(share: KnowledgeBaseShare) {
|
||||
try {
|
||||
const result = await removeShare(props.kbId, share.id)
|
||||
if (result.success) {
|
||||
MessagePlugin.success(t('organization.share.unshareSuccess'))
|
||||
await loadShares()
|
||||
} else {
|
||||
MessagePlugin.error(result.message || t('organization.share.unshareFailed'))
|
||||
}
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('organization.share.unshareFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
// Watch for kbId changes
|
||||
watch(() => props.kbId, async (newKbId) => {
|
||||
if (newKbId) {
|
||||
await Promise.all([loadOrganizations(), loadShares()])
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
onMounted(async () => {
|
||||
if (props.kbId) {
|
||||
await Promise.all([loadOrganizations(), loadShares()])
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.section-content {
|
||||
.section-header {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
margin: 0 0 8px 0;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #000000e6;
|
||||
}
|
||||
|
||||
.section-desc {
|
||||
margin: 0;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
color: #00000066;
|
||||
line-height: 22px;
|
||||
}
|
||||
}
|
||||
|
||||
.share-form {
|
||||
margin-bottom: 24px;
|
||||
padding-bottom: 24px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
.form-label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #000000e6;
|
||||
}
|
||||
|
||||
.form-tip {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
color: #00000066;
|
||||
line-height: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
.share-input-row {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
|
||||
.org-select {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
.permission-select {
|
||||
width: 120px;
|
||||
}
|
||||
}
|
||||
|
||||
.shares-section {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.shares-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
|
||||
.shares-title {
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #000000e6;
|
||||
}
|
||||
|
||||
.shares-count {
|
||||
padding: 2px 8px;
|
||||
background: #f5f5f5;
|
||||
border-radius: 10px;
|
||||
font-size: 12px;
|
||||
color: #00000066;
|
||||
}
|
||||
}
|
||||
|
||||
.shares-loading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
padding: 32px;
|
||||
color: #00000066;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.shares-empty {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
padding: 40px 20px;
|
||||
background: #fafafa;
|
||||
border-radius: 8px;
|
||||
color: #00000066;
|
||||
|
||||
.empty-icon {
|
||||
font-size: 32px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
.shares-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.share-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 12px 16px;
|
||||
background: #fafafa;
|
||||
border-radius: 8px;
|
||||
transition: background 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: #f5f5f5;
|
||||
}
|
||||
}
|
||||
|
||||
.share-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.share-org {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
.org-icon {
|
||||
font-size: 16px;
|
||||
color: #0052d9;
|
||||
}
|
||||
|
||||
.org-name {
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #000000e6;
|
||||
}
|
||||
}
|
||||
|
||||
.share-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
.permission-change-select {
|
||||
width: 100px;
|
||||
}
|
||||
}
|
||||
|
||||
.share-tips {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
padding: 16px;
|
||||
background: #f0f7ff;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e6f0ff;
|
||||
|
||||
.tip-icon {
|
||||
flex-shrink: 0;
|
||||
font-size: 16px;
|
||||
color: #0052d9;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.tip-content {
|
||||
flex: 1;
|
||||
|
||||
p {
|
||||
margin: 0 0 4px 0;
|
||||
font-size: 13px;
|
||||
color: #00000099;
|
||||
line-height: 20px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Custom option styles for organization select
|
||||
:deep(.t-select-option) {
|
||||
height: auto;
|
||||
align-items: flex-start;
|
||||
padding-top: 8px;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
:deep(.t-select-option__content) {
|
||||
white-space: normal;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.org-option-content {
|
||||
padding: 2px 0;
|
||||
min-width: 280px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.org-option-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 4px;
|
||||
|
||||
.org-option-name {
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #000000e6;
|
||||
}
|
||||
}
|
||||
|
||||
.org-option-desc {
|
||||
font-family: "PingFang SC";
|
||||
font-size: 12px;
|
||||
color: #00000066;
|
||||
line-height: 18px;
|
||||
margin-bottom: 6px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.org-option-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 12px;
|
||||
color: #00000066;
|
||||
|
||||
.org-meta-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="less">
|
||||
// Global styles for select dropdown (outside scoped)
|
||||
.t-select__dropdown .t-select-option {
|
||||
height: auto;
|
||||
align-items: flex-start;
|
||||
padding-top: 8px;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
.t-select__dropdown .t-select-option__content {
|
||||
white-space: normal;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user