|
|
@ -6,8 +6,8 @@ |
|
|
|
<div class="setting-dialog"> |
|
|
|
<el-form ref="form" :model="form" size="small" inline label-width="80px" :rules="rules"> |
|
|
|
<el-row> |
|
|
|
<el-form-item label="专题名称" prop="title"> |
|
|
|
<el-input v-model="form.title" style="width: 520px;" /> |
|
|
|
<el-form-item label="专题名称" prop="researchTitle"> |
|
|
|
<el-input v-model="form.researchTitle" style="width: 520px;" /> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="编研类型" prop="researchType"> |
|
|
|
<el-select v-model="form.researchType" placeholder="请选择" style="width: 225px;"> |
|
|
@ -75,10 +75,13 @@ |
|
|
|
</div> |
|
|
|
<div class="file-right-info"> |
|
|
|
<p>{{ fileName }}</p> |
|
|
|
<span v-if="isUploading">解析中...</span> |
|
|
|
<div v-else class="file-info"> |
|
|
|
<span>600KB</span> |
|
|
|
<span>约2.9万字</span> |
|
|
|
<span v-if="isAssisting">{{ fileLoadingText }}</span> |
|
|
|
<div v-else> |
|
|
|
<div v-if="context !== ''" class="file-info"> |
|
|
|
<span>{{ fileType }}</span> |
|
|
|
<span>约{{ contextSize }}字</span> |
|
|
|
</div> |
|
|
|
<span v-else>{{ fileLoadingText }}</span> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
@ -106,11 +109,12 @@ |
|
|
|
</div> |
|
|
|
<div class="right-panel"> |
|
|
|
<mavon-editor |
|
|
|
:value="editorContent" |
|
|
|
:value="researchContext" |
|
|
|
:subfield="true" |
|
|
|
:default-open="'edit,preview'" |
|
|
|
:editable="true" |
|
|
|
:ishljs="true" |
|
|
|
@change="handleEditorChange" |
|
|
|
/> |
|
|
|
</div> |
|
|
|
</div> |
|
|
@ -124,8 +128,10 @@ import { form } from '@crud/crud' |
|
|
|
import { mapGetters } from 'vuex' |
|
|
|
import { FetchDictionaryTree } from '@/api/system/dict' |
|
|
|
import { aiEditUpload } from '@/utils/upload' |
|
|
|
import { FetchEditResearchAI } from '@/api/ai/ai' |
|
|
|
// import json from './str.json' |
|
|
|
|
|
|
|
const defaultForm = { id: null, title: null, researchType: null } |
|
|
|
const defaultForm = { id: null, researchTitle: null, researchType: null } |
|
|
|
export default { |
|
|
|
name: 'Form', |
|
|
|
components: { }, |
|
|
@ -140,15 +146,16 @@ export default { |
|
|
|
formType: 1, |
|
|
|
formVisible: false, |
|
|
|
editorRef: 'test', |
|
|
|
editorContent: '', |
|
|
|
researchContext: '', |
|
|
|
|
|
|
|
options: [], |
|
|
|
rules: { |
|
|
|
title: [{ required: true, trigger: 'blur', message: '专题名称不可为空' }], |
|
|
|
researchTitle: [{ required: true, trigger: 'blur', message: '专题名称不可为空' }], |
|
|
|
researchType: [{ required: true, trigger: 'change', message: '请选择' }] |
|
|
|
}, |
|
|
|
isCollapsed: false, |
|
|
|
inputValue: '', |
|
|
|
file: null, |
|
|
|
fileName: '', |
|
|
|
fileType: '', |
|
|
|
message: [], |
|
|
@ -157,10 +164,13 @@ export default { |
|
|
|
model: 'deepseek-r1:14b', |
|
|
|
messages: [] |
|
|
|
}, |
|
|
|
fileLoadingText: '上传中...', |
|
|
|
isUploading: false, |
|
|
|
isAssisting: false, |
|
|
|
progress: 0, |
|
|
|
animationDuration: 0, |
|
|
|
context: '' |
|
|
|
context: '', |
|
|
|
contextSize: 0 |
|
|
|
} |
|
|
|
}, |
|
|
|
computed: { |
|
|
@ -201,51 +211,100 @@ export default { |
|
|
|
this.$message.error('文件大小不能超过 10MB!') |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
this.fileType = file.type |
|
|
|
this.isAssisting = true |
|
|
|
this.fileLoadingText = '上传中...' |
|
|
|
this.file = file |
|
|
|
this.fileName = file.name |
|
|
|
this.isUploading = true |
|
|
|
this.progress = 0 |
|
|
|
|
|
|
|
// 这种情况前端就给个提示:您上传的文件不是纯文本格式,暂不支持解析 |
|
|
|
this.fileType = this.fileName.substring( |
|
|
|
this.fileName.lastIndexOf('.') + 1, |
|
|
|
this.fileName.length |
|
|
|
) |
|
|
|
|
|
|
|
// const startTime = Date.now() |
|
|
|
// const formData = new FormData() |
|
|
|
// formData.append('file', file) |
|
|
|
|
|
|
|
try { |
|
|
|
// setTimeout(() => { |
|
|
|
// const data = json |
|
|
|
// const resultOcr = data.results[0] |
|
|
|
// const endTime = Date.now() |
|
|
|
// const uploadTime = Math.round((endTime - startTime) / 1000) |
|
|
|
// this.animationDuration = uploadTime |
|
|
|
// this.isUploading = true |
|
|
|
// this.fileLoadingText = '解析中...' |
|
|
|
// setTimeout(() => { |
|
|
|
// if (resultOcr.status === 'success') { |
|
|
|
// this.isUploading = false |
|
|
|
// this.isAssisting = false |
|
|
|
// // 处理上传成功的逻辑 |
|
|
|
// this.$message({ message: '上传的文件已解析完成', type: 'success', offset: 8 }) |
|
|
|
// this.context = resultOcr.content |
|
|
|
// const length = this.context.length |
|
|
|
// if (length >= 10000) { |
|
|
|
// this.contextSize = (length / 10000).toFixed(1) + '万' |
|
|
|
// } else if (length >= 1000) { |
|
|
|
// this.contextSize = (length / 1000).toFixed(1) + '千' |
|
|
|
// } else { |
|
|
|
// this.contextSize = length |
|
|
|
// } |
|
|
|
// } else { |
|
|
|
// this.context = '' |
|
|
|
// this.$message({ message: ' 您上传的文件不是纯文本格式,暂不支持解析', type: 'error', offset: 8 }) |
|
|
|
// this.isUploading = false |
|
|
|
// this.isAssisting = false |
|
|
|
// this.fileLoadingText = '解析失败' |
|
|
|
// } |
|
|
|
// }, uploadTime * 1000) |
|
|
|
// }, 4000) |
|
|
|
|
|
|
|
aiEditUpload(this.baseApi + '/api/ai/uploadAIResearchFiles', |
|
|
|
file, |
|
|
|
).then(res => { |
|
|
|
console.log('res.data.data', res.data.data) |
|
|
|
if (res.data.data !== null) { |
|
|
|
this.context = res.data.data.results[0].content |
|
|
|
this.$message({ message: '编研附件传输成功', type: 'success', offset: 8 }) |
|
|
|
} else { |
|
|
|
this.$message({ message: '编研附件传输失败', type: 'error', offset: 8 }) |
|
|
|
} |
|
|
|
}).catch(() => { |
|
|
|
// this.$message({ message: '编研附件传输失败', type: 'error', offset: 8 }) |
|
|
|
}) |
|
|
|
|
|
|
|
const resultOcr = res.data.data.results[0] |
|
|
|
// const endTime = Date.now() |
|
|
|
// const uploadTime = (endTime - startTime) / 1000 |
|
|
|
// const uploadTime = Math.round((endTime - startTime) / 1000) |
|
|
|
// this.animationDuration = uploadTime |
|
|
|
|
|
|
|
// // 处理上传成功的逻辑 |
|
|
|
// this.$message.success('文件上传成功') |
|
|
|
} catch (error) { |
|
|
|
// 处理上传失败的逻辑 |
|
|
|
// this.$message.error('文件上传失败') |
|
|
|
} finally { |
|
|
|
this.animationDuration = 2 |
|
|
|
this.isUploading = true |
|
|
|
this.fileLoadingText = '解析中...' |
|
|
|
setTimeout(() => { |
|
|
|
if (resultOcr.status === 'success') { |
|
|
|
this.isUploading = false |
|
|
|
this.isAssisting = false |
|
|
|
// 处理上传成功的逻辑 |
|
|
|
this.$message({ message: '上传的文件已解析完成', type: 'success', offset: 8 }) |
|
|
|
this.context = resultOcr.content |
|
|
|
const length = this.context.length |
|
|
|
if (length >= 10000) { |
|
|
|
this.contextSize = (length / 10000).toFixed(1) + '万' |
|
|
|
} else if (length >= 1000) { |
|
|
|
this.contextSize = (length / 1000).toFixed(1) + '千' |
|
|
|
} else { |
|
|
|
this.contextSize = length |
|
|
|
} |
|
|
|
|
|
|
|
const uploadTime = 2 |
|
|
|
this.animationDuration = uploadTime |
|
|
|
setTimeout(() => { |
|
|
|
} else { |
|
|
|
this.context = '' |
|
|
|
this.$message({ message: ' 您上传的文件不是纯文本格式,暂不支持解析', type: 'error', offset: 8 }) |
|
|
|
this.isUploading = false |
|
|
|
this.isAssisting = false |
|
|
|
this.fileLoadingText = '解析失败' |
|
|
|
} |
|
|
|
}, this.animationDuration * 1000) |
|
|
|
} else { |
|
|
|
this.context = '' |
|
|
|
this.isUploading = false |
|
|
|
this.isAssisting = false |
|
|
|
this.fileLoadingText = '上传失败' |
|
|
|
this.$message({ message: '编研附件传输失败', type: 'error', offset: 8 }) |
|
|
|
} |
|
|
|
}).catch(() => { |
|
|
|
this.context = '' |
|
|
|
this.isUploading = false |
|
|
|
}, uploadTime * 1000) |
|
|
|
this.isAssisting = false |
|
|
|
this.fileLoadingText = '上传失败' |
|
|
|
this.$message({ message: '编研附件传输失败', type: 'error', offset: 8 }) |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
async handleMessage(e) { |
|
|
@ -264,11 +323,22 @@ export default { |
|
|
|
} |
|
|
|
}, |
|
|
|
async sendMessage(e) { |
|
|
|
if (!this.inputValue) { |
|
|
|
this.$message.error('请输入问题') |
|
|
|
if (this.file) { |
|
|
|
if (!this.context) { |
|
|
|
if (this.fileLoadingText === '解析失败') { |
|
|
|
this.$message({ message: '您上传的文件不是纯文本格式,暂不支持解析,请重新选择合适文件!', type: 'error', offset: 8 }) |
|
|
|
return |
|
|
|
} else { |
|
|
|
this.$message({ message: '您上传的文件正在解析中,请耐心等待!', type: 'error', offset: 8 }) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!this.inputValue) { |
|
|
|
this.$message({ message: '请输入问题', type: 'error', offset: 8 }) |
|
|
|
return |
|
|
|
} |
|
|
|
// 如果已经有一个正在进行的流式请求,则中止它 |
|
|
|
if (this.controller) { |
|
|
|
this.controller.abort() |
|
|
@ -375,12 +445,16 @@ export default { |
|
|
|
} |
|
|
|
}, |
|
|
|
onClickContent(talkContent) { |
|
|
|
this.editorContent = '' |
|
|
|
this.editorContent = talkContent |
|
|
|
this.researchContext = '' |
|
|
|
this.researchContext = talkContent |
|
|
|
}, |
|
|
|
deleteFile() { |
|
|
|
this.fileName = '' |
|
|
|
this.fileType = '' |
|
|
|
this.context = '' |
|
|
|
this.file = null |
|
|
|
this.isUploading = false |
|
|
|
this.isAssisting = false |
|
|
|
// 清空 input type="file" 的数据 |
|
|
|
if (this.$refs.fileInput) { |
|
|
|
this.$refs.fileInput.value = '' |
|
|
@ -388,41 +462,52 @@ export default { |
|
|
|
}, |
|
|
|
handleCloseForm() { |
|
|
|
this.inputValue = '' |
|
|
|
this.editorContent = '' |
|
|
|
this.researchContext = '' |
|
|
|
this.message = [] |
|
|
|
this.formVisible = false |
|
|
|
this.deleteFile() |
|
|
|
}, |
|
|
|
handleEditorChange(value) { |
|
|
|
this.researchContext = value |
|
|
|
}, |
|
|
|
handleComfiredEditing() { |
|
|
|
this.$refs.form.validate(valid => { |
|
|
|
if (valid) { |
|
|
|
console.log('保存数据', this.form) |
|
|
|
|
|
|
|
console.log('this.researchContext', this.researchContext) |
|
|
|
if (this.researchContext === '') { |
|
|
|
this.$message({ message: '编研内容不可为空!', type: 'error', offset: 8 }) |
|
|
|
return |
|
|
|
} else { |
|
|
|
this.$confirm('此操作将发布当前编研主题' + '<span>你是否还要继续?</span>', '提示', { |
|
|
|
confirmButtonText: '继续', |
|
|
|
cancelButtonText: '取消', |
|
|
|
type: 'warning', |
|
|
|
dangerouslyUseHTMLString: true |
|
|
|
}).then(() => { |
|
|
|
// const ids = data.map(item => item.id) |
|
|
|
// const params = { |
|
|
|
// 'ids': ids, |
|
|
|
// 'operator': this.user.username |
|
|
|
// } |
|
|
|
// crudEditing.del(params).then((res) => { |
|
|
|
// console.log(res) |
|
|
|
// if (res.code !== 500) { |
|
|
|
// this.$message({ message: '删除成功', type: 'success', offset: 8 }) |
|
|
|
// } else { |
|
|
|
// this.$message({ message: res.message, type: 'error', offset: 8 }) |
|
|
|
// } |
|
|
|
// this.initData() |
|
|
|
// }).catch(err => { |
|
|
|
// console.log(err) |
|
|
|
// }) |
|
|
|
const params = { |
|
|
|
'id': this.form.id, |
|
|
|
'researchContext': this.researchContext, |
|
|
|
'researchTitle': this.form.researchTitle, |
|
|
|
'researchType': this.form.researchType |
|
|
|
} |
|
|
|
console.log('params', params) |
|
|
|
FetchEditResearchAI(params).then((res) => { |
|
|
|
console.log(res) |
|
|
|
if (res) { |
|
|
|
this.$message({ message: '编研操作成功', type: 'success', offset: 8 }) |
|
|
|
this.$emit('initData') |
|
|
|
} else { |
|
|
|
this.$message({ message: '编研操作失败', type: 'error', offset: 8 }) |
|
|
|
} |
|
|
|
}).catch(err => { |
|
|
|
console.log(err) |
|
|
|
}) |
|
|
|
this.handleCloseForm() |
|
|
|
}).catch(() => { |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
toggleCollapse() { |
|
|
|