mirror of
http://112.124.100.131/ebiz-ai/ebiz-ai-knowledge-manage.git
synced 2025-12-09 10:56:50 +08:00
feat(knowledge): 实现题词功能并优化知识库创建流程- 新增题词预览组件和相关 API 接口
- 重构知识库创建流程,支持自动和自定义题词 - 优化题词结果展示和保存逻辑 - 调整知识库详情页面布局
This commit is contained in:
@@ -160,6 +160,24 @@ export function execExtract(data) {
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 题词-查询题词结果详情
|
||||
export function getExtractResultList(data) {
|
||||
return request({
|
||||
url: getUrl(`/document/attribute/extract/result/list`),
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 题词-保存
|
||||
export function saveContentToDocument(data) {
|
||||
return request({
|
||||
url: getUrl(`/datasetDocumentEx/saveContentToDocument`),
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
//知识库文件上传-自定义
|
||||
export function uploadFileByCustom(data) {
|
||||
return request({
|
||||
|
||||
@@ -218,10 +218,6 @@ export default {
|
||||
|
||||
// 4. 显示预览组件
|
||||
this.showPreview(previewData)
|
||||
|
||||
// 5. 处理成功响应
|
||||
// const result = this.handleSuccessResponse(execSplitData, previewData)
|
||||
// resolve(result)
|
||||
} catch (error) {
|
||||
// 6. 处理错误
|
||||
const errorResult = this.handleOperationError(error)
|
||||
|
||||
@@ -43,7 +43,8 @@ export default {
|
||||
{ id: 2, name: 'Item 2', selected: false },
|
||||
{ id: 3, name: 'Item 3', selected: false }
|
||||
],
|
||||
addRuleVisible: false // 控制 AddRule 组件的显示状态
|
||||
addRuleVisible: false, // 控制 AddRule 组件的显示状态
|
||||
selectData: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -53,6 +54,7 @@ export default {
|
||||
},
|
||||
getCheckData(value) {
|
||||
console.log(value)
|
||||
this.selectData = value
|
||||
this.ruleId = value[0].id
|
||||
},
|
||||
getDataList() {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<!-- src/views/knowledge/detail/components/words/ExtractPreview.vue -->
|
||||
<template>
|
||||
<div class="extract-preview">
|
||||
<el-dialog title="题词结果预览" :visible.sync="visible" width="700px" :close-on-click-modal="false">
|
||||
<div class="preview-content">
|
||||
<template v-if="extractResults && extractResults.length > 0">
|
||||
<el-table :data="extractResults" border style="width: 100%">
|
||||
<el-table-column prop="attribute" label="属性" align="center" width="180"></el-table-column>
|
||||
<el-table-column prop="attributeContent" label="题词内容" align="center"></el-table-column>
|
||||
</el-table>
|
||||
</template>
|
||||
<el-empty v-else-if="!extractResults || extractResults.length === 0" description="暂无题词结果"></el-empty>
|
||||
</div>
|
||||
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="handleConfirm">完成</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'ExtractPreview',
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
extractResults: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
},
|
||||
loading: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleClose() {
|
||||
this.$emit('update:visible', false)
|
||||
},
|
||||
handleConfirm() {
|
||||
this.$emit('confirm', this.extractResults)
|
||||
this.handleClose()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.extract-preview {
|
||||
.preview-content {
|
||||
min-height: 300px;
|
||||
padding: 10px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -56,22 +56,36 @@
|
||||
</ul>
|
||||
<!-- 弹窗组件 -->
|
||||
<custom-split-dialog class="active" ref="customTable"> </custom-split-dialog>
|
||||
|
||||
<!-- 添加题词预览组件 -->
|
||||
<extract-preview
|
||||
:visible.sync="previewVisible"
|
||||
:extract-results="extractResults"
|
||||
:is-auto-extract="activeIndex === 0"
|
||||
:loading="previewLoading"
|
||||
@confirm="handlePreviewConfirm"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import CustomSplitDialog from './CustomWords.vue'
|
||||
import { execExtract, execSplit } from '@/api/generatedApi'
|
||||
import ExtractPreview from './ExtractPreview.vue'
|
||||
import { execExtract, getExtractResultList, saveContentToDocument } from '@/api/generatedApi'
|
||||
|
||||
export default {
|
||||
name: 'splitConfig',
|
||||
components: {
|
||||
CustomSplitDialog
|
||||
CustomSplitDialog,
|
||||
ExtractPreview
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
dialogVisible: false,
|
||||
activeIndex: 0,
|
||||
previewVisible: false,
|
||||
extractResults: [],
|
||||
previewLoading: false,
|
||||
splitOptions: [
|
||||
{
|
||||
icon: 'el-icon-setting',
|
||||
@@ -85,7 +99,8 @@ export default {
|
||||
description: '使用自定义题词方式可以根据具体需求灵活调整文本分割逻辑,但需要权衡灵活性与复杂度,需要用户具备一定的题词经验。',
|
||||
tip: ''
|
||||
}
|
||||
]
|
||||
],
|
||||
documentId: ''
|
||||
}
|
||||
},
|
||||
props: {},
|
||||
@@ -100,21 +115,103 @@ export default {
|
||||
this.$refs.customTable.close()
|
||||
}
|
||||
},
|
||||
|
||||
// 构建执行题词的参数
|
||||
buildExecExtractParams(documentId) {
|
||||
const params = {
|
||||
documentId: documentId,
|
||||
beAuto: this.activeIndex === 0
|
||||
}
|
||||
|
||||
if (!params.beAuto && this.$refs.customTable.ruleId) {
|
||||
params.rulesId = this.$refs.customTable.ruleId
|
||||
}
|
||||
|
||||
return params
|
||||
},
|
||||
|
||||
// 执行题词操作
|
||||
async execExtractOperation(params) {
|
||||
const res = await execExtract(params)
|
||||
console.log('execExtract result:', res.content)
|
||||
|
||||
if (res.content.result !== '0') {
|
||||
throw new Error(res.content.resultMessage || '执行题词失败')
|
||||
}
|
||||
|
||||
return res.content.content
|
||||
},
|
||||
|
||||
// 显示预览
|
||||
showExtractPreview(results) {
|
||||
this.extractResults = results || []
|
||||
this.previewVisible = true
|
||||
},
|
||||
|
||||
// 获取题词结果列表 - 修改后的方法
|
||||
async getExtractResultOperation(documentId) {
|
||||
this.previewLoading = true
|
||||
const params = { documentId }
|
||||
const res = await getExtractResultList(params)
|
||||
console.log('getExtractResultList result:', res.content)
|
||||
|
||||
if (res.content.result !== '0') {
|
||||
throw new Error(res.content.resultMessage || '获取题词结果失败')
|
||||
}
|
||||
|
||||
const results = res.content.content || []
|
||||
|
||||
// 显示预览弹窗
|
||||
this.showExtractPreview(results)
|
||||
},
|
||||
// 处理预览确认
|
||||
handlePreviewConfirm(extractResults) {
|
||||
console.log('selectData')
|
||||
console.log(this.$refs.customTable.selectData)
|
||||
this.saveContentToDocumentOperation(this.documentId, extractResults)
|
||||
},
|
||||
// 保存题词内容到文档
|
||||
async saveContentToDocumentOperation(documentId, resultList) {
|
||||
try {
|
||||
const params = {
|
||||
documentId,
|
||||
resultDTOList: resultList.map(item => ({
|
||||
attribute: item.attribute,
|
||||
attributeContent: item.attributeContent
|
||||
}))
|
||||
}
|
||||
|
||||
const res = await saveContentToDocument(params)
|
||||
console.log('saveContentToDocument result:', res.content)
|
||||
|
||||
if (res.content.result !== '0') {
|
||||
throw new Error(res.content.resultMessage || '保存题词内容失败')
|
||||
}
|
||||
|
||||
this.$router.go(-1)
|
||||
} catch (error) {
|
||||
this.$message.error('保存题词内容失败: ' + error.message)
|
||||
throw error
|
||||
}
|
||||
},
|
||||
|
||||
// 主方法
|
||||
nextStep(documentId) {
|
||||
this.documentId = documentId
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = {
|
||||
documentId: documentId,
|
||||
beAuto: this.activeIndex === 0
|
||||
try {
|
||||
// 1. 执行题词
|
||||
const params = this.buildExecExtractParams(documentId)
|
||||
await this.execExtractOperation(params)
|
||||
// 2.
|
||||
await this.getExtractResultOperation(documentId)
|
||||
} catch (error) {
|
||||
console.error('题词操作失败:', error)
|
||||
reject({
|
||||
success: false,
|
||||
message: error.message || '题词操作失败'
|
||||
})
|
||||
}
|
||||
if (params.beAuto === false) {
|
||||
params.rulesId = this.$refs.customTable.ruleId
|
||||
}
|
||||
let res = await execExtract(params)
|
||||
console.log(res.content)
|
||||
resolve({
|
||||
result: res.content.result,
|
||||
data: res.content
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
@@ -88,19 +88,9 @@ export default {
|
||||
if (this.active === 0) {
|
||||
this.$refs.stepPreProcessing.uploadFiled()
|
||||
} else if (this.active === 1) {
|
||||
const res = await this.$refs.splitConfig.nextStep(this.documentId)
|
||||
if (res.result === '0') {
|
||||
// 处理成功的情况
|
||||
console.log('拆分成功', res.content)
|
||||
this.active++
|
||||
}
|
||||
await this.$refs.splitConfig.nextStep(this.documentId)
|
||||
} else if (this.active === 2) {
|
||||
const res = await this.$refs.words.nextStep(this.documentId)
|
||||
if (res.result === '0') {
|
||||
// 处理成功的情况
|
||||
console.log('拆分成功', res.content)
|
||||
this.$message.success('创建成功')
|
||||
}
|
||||
await this.$refs.words.nextStep(this.documentId)
|
||||
}
|
||||
},
|
||||
// 预览完成
|
||||
|
||||
@@ -192,7 +192,7 @@ export default {
|
||||
.then(() => {
|
||||
// 删除当前行
|
||||
this.tableData.splice(index, 1)
|
||||
this.getTableData();
|
||||
this.getTableData()
|
||||
})
|
||||
.catch(err => {
|
||||
this.$notify.error({
|
||||
|
||||
@@ -23,8 +23,7 @@ export default {
|
||||
})
|
||||
}
|
||||
},
|
||||
created() {
|
||||
},
|
||||
created() {},
|
||||
methods: {}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user