文章导入知识库
This commit is contained in:
@@ -28,7 +28,14 @@
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="250" fixed="right">
|
||||
<el-table-column prop="isInKnowledge" label="知识库" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.isInKnowledge ? 'success' : 'info'" size="small">
|
||||
{{ row.isInKnowledge ? '已导入' : '未导入' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="320" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button size="small" @click="viewArticle(row)">查看</el-button>
|
||||
<el-button
|
||||
@@ -39,6 +46,15 @@
|
||||
{{ getActionButtonText(row.status) }}
|
||||
</el-button>
|
||||
<el-button size="small" @click="editArticle(row)">编辑</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
type="success"
|
||||
:disabled="row.isInKnowledge || row.status !== 1"
|
||||
:loading="importingIds.has(row.resourceID)"
|
||||
@click="importToKnowledge(row)"
|
||||
>
|
||||
{{ row.isInKnowledge ? '已导入' : '导入知识库' }}
|
||||
</el-button>
|
||||
<el-button size="small" type="danger" @click="deleteArticle(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -99,6 +115,7 @@ const articles = ref<Resource[]>([]);
|
||||
const showViewDialog = ref(false);
|
||||
const currentArticle = ref<any>(null);
|
||||
const categoryList = ref<Tag[]>([]); // 改为使用Tag类型(tagType=1表示文章分类)
|
||||
const importingIds = ref<Set<string>>(new Set()); // 正在导入的文章ID集合
|
||||
|
||||
onMounted(() => {
|
||||
loadArticles();
|
||||
@@ -227,6 +244,50 @@ async function deleteArticle(row: Resource) {
|
||||
}
|
||||
}
|
||||
|
||||
async function importToKnowledge(row: Resource) {
|
||||
if (!row.resourceID) return;
|
||||
|
||||
// 检查文章状态
|
||||
if (row.status !== ResourceStatus.PUBLISHED) {
|
||||
ElMessage.warning('只有已发布的文章才能导入知识库');
|
||||
return;
|
||||
}
|
||||
|
||||
if (row.isInKnowledge) {
|
||||
ElMessage.info('文章已导入知识库');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定要将文章「${row.title}」导入知识库吗?`,
|
||||
'导入确认',
|
||||
{
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'info'
|
||||
}
|
||||
);
|
||||
|
||||
importingIds.value.add(row.resourceID);
|
||||
const res = await resourceApi.importToKnowledge(row.resourceID);
|
||||
|
||||
if (res.success) {
|
||||
ElMessage.success('导入知识库成功');
|
||||
loadArticles();
|
||||
} else {
|
||||
ElMessage.error(res.message || '导入知识库失败');
|
||||
}
|
||||
} catch (error) {
|
||||
if (error !== 'cancel') {
|
||||
console.error('导入知识库失败:', error);
|
||||
ElMessage.error('导入知识库失败');
|
||||
}
|
||||
} finally {
|
||||
importingIds.value.delete(row.resourceID);
|
||||
}
|
||||
}
|
||||
|
||||
function getStatusType(status: number) {
|
||||
const typeMap: Record<number, any> = {
|
||||
[ResourceStatus.DRAFT]: 'info',
|
||||
|
||||
Reference in New Issue
Block a user