2025-06-05 12:15:55 +00:00
|
|
|
|
<template>
|
2025-06-09 11:47:23 +00:00
|
|
|
|
<div class="upload-document p-12-24">
|
|
|
|
|
|
<div class="flex align-center mb-16">
|
|
|
|
|
|
<back-button to="-1" style="margin-left: -4px"></back-button>
|
|
|
|
|
|
<h3 style="display: inline-block">{{ $t('views.document.uploadDocument') }}</h3>
|
2025-06-05 12:15:55 +00:00
|
|
|
|
</div>
|
2025-06-09 11:47:23 +00:00
|
|
|
|
<el-card style="--el-card-padding: 0">
|
|
|
|
|
|
<div class="upload-document__main flex" v-loading="loading">
|
|
|
|
|
|
<div class="upload-document__component main-calc-height">
|
|
|
|
|
|
<el-scrollbar>
|
|
|
|
|
|
<template v-if="active === 0">
|
|
|
|
|
|
<div class="upload-component p-24">
|
|
|
|
|
|
<!-- 上传文档 -->
|
|
|
|
|
|
<UploadComponent ref="UploadComponentRef" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-else-if="active === 1">
|
|
|
|
|
|
<SetRules ref="SetRulesRef" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-else-if="active === 2">
|
|
|
|
|
|
<ResultSuccess :data="successInfo" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-scrollbar>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
<div class="upload-document__footer text-right border-t" v-if="active !== 2">
|
2025-06-05 12:15:55 +00:00
|
|
|
|
<el-button @click="router.go(-1)" :disabled="SetRulesRef?.loading || loading">{{
|
|
|
|
|
|
$t('common.cancel')
|
|
|
|
|
|
}}</el-button>
|
|
|
|
|
|
<el-button @click="prev" v-if="active === 1" :disabled="SetRulesRef?.loading || loading">{{
|
|
|
|
|
|
$t('views.document.buttons.prev')
|
|
|
|
|
|
}}</el-button>
|
|
|
|
|
|
<el-button
|
|
|
|
|
|
@click="next"
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
v-if="active === 0"
|
|
|
|
|
|
:disabled="SetRulesRef?.loading || loading"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{
|
|
|
|
|
|
documentsType === 'txt'
|
|
|
|
|
|
? $t('views.document.buttons.next')
|
|
|
|
|
|
: $t('views.document.buttons.import')
|
|
|
|
|
|
}}
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
<el-button
|
|
|
|
|
|
@click="submit"
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
v-if="active === 1"
|
|
|
|
|
|
:disabled="SetRulesRef?.loading || loading"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ $t('views.document.buttons.import') }}
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
</div>
|
2025-06-09 11:47:23 +00:00
|
|
|
|
</div>
|
2025-06-05 12:15:55 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import { ref, computed, onUnmounted } from 'vue'
|
|
|
|
|
|
import { useRouter, useRoute } from 'vue-router'
|
2025-06-09 11:47:23 +00:00
|
|
|
|
import SetRules from './upload/SetRules.vue'
|
|
|
|
|
|
import ResultSuccess from './upload/ResultSuccess.vue'
|
|
|
|
|
|
import UploadComponent from './upload/UploadComponent.vue'
|
|
|
|
|
|
import documentApi from '@/api/knowledge/document'
|
2025-06-05 12:15:55 +00:00
|
|
|
|
import { MsgConfirm, MsgSuccess } from '@/utils/message'
|
|
|
|
|
|
import { t } from '@/locales'
|
|
|
|
|
|
import useStore from '@/stores'
|
2025-06-09 10:54:13 +00:00
|
|
|
|
const { knowledge, document } = useStore()
|
|
|
|
|
|
const documentsFiles = computed(() => knowledge.documentsFiles)
|
|
|
|
|
|
const documentsType = computed(() => knowledge.documentsType)
|
2025-06-05 12:15:55 +00:00
|
|
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
const route = useRoute()
|
|
|
|
|
|
const {
|
2025-06-09 11:47:23 +00:00
|
|
|
|
query: { id }, // id为knowledgeID,有id的是上传文档
|
2025-06-05 12:15:55 +00:00
|
|
|
|
} = route
|
|
|
|
|
|
|
|
|
|
|
|
const SetRulesRef = ref()
|
|
|
|
|
|
const UploadComponentRef = ref()
|
|
|
|
|
|
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const disabled = ref(false)
|
|
|
|
|
|
const active = ref(0)
|
|
|
|
|
|
const successInfo = ref<any>(null)
|
|
|
|
|
|
async function next() {
|
|
|
|
|
|
disabled.value = true
|
|
|
|
|
|
if (await UploadComponentRef.value.validate()) {
|
|
|
|
|
|
if (documentsType.value === 'QA') {
|
2025-06-06 04:31:30 +00:00
|
|
|
|
const fd = new FormData()
|
2025-06-05 12:15:55 +00:00
|
|
|
|
documentsFiles.value.forEach((item: any) => {
|
|
|
|
|
|
if (item?.raw) {
|
|
|
|
|
|
fd.append('file', item?.raw)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
if (id) {
|
|
|
|
|
|
// QA文档上传
|
|
|
|
|
|
documentApi.postQADocument(id as string, fd, loading).then((res) => {
|
|
|
|
|
|
MsgSuccess(t('common.submitSuccess'))
|
|
|
|
|
|
clearStore()
|
2025-06-09 10:54:13 +00:00
|
|
|
|
router.push({ path: `/knowledge/${id}/document` })
|
2025-06-05 12:15:55 +00:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (documentsType.value === 'table') {
|
2025-06-06 04:31:30 +00:00
|
|
|
|
const fd = new FormData()
|
2025-06-05 12:15:55 +00:00
|
|
|
|
documentsFiles.value.forEach((item: any) => {
|
|
|
|
|
|
if (item?.raw) {
|
|
|
|
|
|
fd.append('file', item?.raw)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
if (id) {
|
|
|
|
|
|
// table文档上传
|
|
|
|
|
|
documentApi.postTableDocument(id as string, fd, loading).then((res) => {
|
|
|
|
|
|
MsgSuccess(t('common.submitSuccess'))
|
|
|
|
|
|
clearStore()
|
2025-06-09 10:54:13 +00:00
|
|
|
|
router.push({ path: `/knowledge/${id}/document` })
|
2025-06-05 12:15:55 +00:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (active.value++ > 2) active.value = 0
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
disabled.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
const prev = () => {
|
|
|
|
|
|
active.value = 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function clearStore() {
|
2025-06-09 10:54:13 +00:00
|
|
|
|
knowledge.saveDocumentsFile([])
|
|
|
|
|
|
knowledge.saveDocumentsType('')
|
2025-06-05 12:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
function submit() {
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
const documents = [] as any
|
|
|
|
|
|
SetRulesRef.value?.paragraphList.map((item: any) => {
|
|
|
|
|
|
if (!SetRulesRef.value?.checkedConnect) {
|
|
|
|
|
|
item.content.map((v: any) => {
|
|
|
|
|
|
delete v['problem_list']
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
documents.push({
|
|
|
|
|
|
name: item.name,
|
2025-06-09 11:47:23 +00:00
|
|
|
|
paragraphs: item.content,
|
2025-06-05 12:15:55 +00:00
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if (id) {
|
|
|
|
|
|
// 上传文档
|
|
|
|
|
|
document
|
2025-06-16 12:18:01 +00:00
|
|
|
|
.asyncPutDocument(id as string, documents)
|
2025-06-05 12:15:55 +00:00
|
|
|
|
.then(() => {
|
|
|
|
|
|
MsgSuccess(t('common.submitSuccess'))
|
|
|
|
|
|
clearStore()
|
2025-06-09 10:54:13 +00:00
|
|
|
|
router.push({ path: `/knowledge/${id}/document` })
|
2025-06-05 12:15:55 +00:00
|
|
|
|
})
|
|
|
|
|
|
.catch(() => {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
function back() {
|
|
|
|
|
|
if (documentsFiles.value?.length > 0) {
|
|
|
|
|
|
MsgConfirm(t('common.tip'), t('views.document.tip.saveMessage'), {
|
|
|
|
|
|
confirmButtonText: t('common.confirm'),
|
2025-06-09 11:47:23 +00:00
|
|
|
|
type: 'warning',
|
2025-06-05 12:15:55 +00:00
|
|
|
|
})
|
|
|
|
|
|
.then(() => {
|
|
|
|
|
|
router.go(-1)
|
|
|
|
|
|
clearStore()
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch(() => {})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
router.go(-1)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
|
clearStore()
|
|
|
|
|
|
})
|
|
|
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
2025-06-09 11:47:23 +00:00
|
|
|
|
.upload-document {
|
2025-06-05 12:15:55 +00:00
|
|
|
|
&__steps {
|
|
|
|
|
|
min-width: 450px;
|
|
|
|
|
|
max-width: 800px;
|
|
|
|
|
|
width: 80%;
|
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
|
padding-right: 60px;
|
|
|
|
|
|
|
|
|
|
|
|
:deep(.el-step__line) {
|
|
|
|
|
|
left: 64% !important;
|
|
|
|
|
|
right: -33% !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
&__component {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
}
|
|
|
|
|
|
&__footer {
|
|
|
|
|
|
padding: 16px 24px;
|
|
|
|
|
|
position: fixed;
|
|
|
|
|
|
bottom: 0;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
background: #ffffff;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
}
|
2025-06-09 11:47:23 +00:00
|
|
|
|
.upload-component {
|
2025-06-05 12:15:55 +00:00
|
|
|
|
width: 70%;
|
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|