UnisKB/ui/src/views/dataset/UploadDocumentDataset.vue

182 lines
4.7 KiB
Vue
Raw Normal View History

2023-10-26 11:02:16 +00:00
<template>
<LayoutContainer header="上传文档" class="create-dataset">
2023-12-05 11:21:13 +00:00
<template #backButton>
<back-button @click="back"></back-button>
</template>
2023-11-10 09:18:00 +00:00
<div class="create-dataset__main flex" v-loading="loading">
2023-11-10 11:05:52 +00:00
<div class="create-dataset__component main-calc-height">
<el-scrollbar>
<template v-if="active === 0">
<div class="upload-document 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>
2023-10-27 09:49:06 +00:00
</div>
2023-11-08 11:08:54 +00:00
</div>
2023-11-10 11:05:52 +00:00
<div class="create-dataset__footer text-right border-t" v-if="active !== 2">
2024-02-23 08:17:16 +00:00
<el-button @click="router.go(-1)" :disabled="loading">取消</el-button>
2023-11-10 09:18:00 +00:00
<el-button @click="prev" v-if="active === 1" :disabled="loading"></el-button>
<el-button @click="next" type="primary" v-if="active === 0" :disabled="loading">
2024-01-09 07:06:28 +00:00
创建并导入
</el-button>
2023-11-10 09:18:00 +00:00
<el-button @click="submit" type="primary" v-if="active === 1" :disabled="loading">
开始导入
</el-button>
2023-10-27 09:49:06 +00:00
</div>
2023-11-03 09:45:01 +00:00
</LayoutContainer>
2023-10-26 11:02:16 +00:00
</template>
<script setup lang="ts">
2024-01-08 09:53:50 +00:00
import { ref, computed, onUnmounted } from 'vue'
2023-11-10 09:18:00 +00:00
import { useRouter, useRoute } from 'vue-router'
import SetRules from './component/SetRules.vue'
import ResultSuccess from './component/ResultSuccess.vue'
import UploadComponent from './component/UploadComponent.vue'
2023-11-10 09:18:00 +00:00
import datasetApi from '@/api/dataset'
import documentApi from '@/api/document'
2023-11-10 09:18:00 +00:00
import type { datasetData } from '@/api/type/dataset'
2023-12-05 11:21:13 +00:00
import { MsgConfirm, MsgSuccess } from '@/utils/message'
2023-11-10 09:18:00 +00:00
import useStore from '@/stores'
const { dataset, document } = useStore()
const documentsFiles = computed(() => dataset.documentsFiles)
const documentsType = computed(() => dataset.documentsType)
2023-10-26 11:02:16 +00:00
2023-11-08 11:08:54 +00:00
const router = useRouter()
2023-11-10 09:18:00 +00:00
const route = useRoute()
const {
query: { id } // id为datasetID有id的是上传文档
2023-12-05 11:21:13 +00:00
} = route
2023-10-27 09:49:06 +00:00
const SetRulesRef = ref()
const UploadComponentRef = ref()
2023-11-02 01:56:14 +00:00
2023-11-10 09:18:00 +00:00
const loading = ref(false)
2024-02-27 08:20:05 +00:00
const disabled = ref(false)
2023-11-02 01:56:14 +00:00
const active = ref(0)
2023-11-10 11:05:52 +00:00
const successInfo = ref<any>(null)
2023-11-02 01:56:14 +00:00
async function next() {
2024-02-27 08:20:05 +00:00
disabled.value = true
if (await UploadComponentRef.value.validate()) {
if (documentsType.value === 'QA') {
let fd = new FormData()
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('提交成功')
clearStore()
router.push({ path: `/dataset/${id}/document` })
})
}
} else {
if (active.value++ > 2) active.value = 0
}
2024-02-27 08:20:05 +00:00
} else {
disabled.value = false
2023-11-02 01:56:14 +00:00
}
2023-10-26 11:02:16 +00:00
}
2023-11-08 11:08:54 +00:00
const prev = () => {
active.value = 0
}
2023-11-10 09:18:00 +00:00
2023-11-10 11:05:52 +00:00
function clearStore() {
dataset.saveDocumentsFile([])
dataset.saveDocumentsType('')
2023-11-10 11:05:52 +00:00
}
2023-11-10 09:18:00 +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({
2023-11-10 09:18:00 +00:00
name: item.name,
paragraphs: item.content
})
})
2024-07-19 10:51:14 +00:00
2023-11-10 09:18:00 +00:00
if (id) {
// 上传文档
document
.asyncPostDocument(id as string, documents)
.then(() => {
2023-11-10 09:18:00 +00:00
MsgSuccess('提交成功')
2023-11-10 11:05:52 +00:00
clearStore()
2023-11-10 09:18:00 +00:00
router.push({ path: `/dataset/${id}/document` })
})
.catch(() => {
loading.value = false
})
}
}
2023-12-05 11:21:13 +00:00
function back() {
if (documentsFiles.value?.length > 0) {
2023-12-05 11:21:13 +00:00
MsgConfirm(`提示`, `当前的更改尚未保存,确认退出吗?`, {
confirmButtonText: '确认',
type: 'warning'
})
.then(() => {
router.go(-1)
clearStore()
})
.catch(() => {})
} else {
router.go(-1)
}
}
2024-01-08 09:53:50 +00:00
onUnmounted(() => {
clearStore()
})
2023-10-26 11:02:16 +00:00
</script>
2023-10-27 09:49:06 +00:00
<style lang="scss" scoped>
.create-dataset {
2023-11-03 09:45:01 +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;
}
}
2023-10-27 09:49:06 +00:00
&__component {
2023-11-06 11:06:02 +00:00
width: 100%;
2023-10-27 09:49:06 +00:00
margin: 0 auto;
overflow: hidden;
}
&__footer {
2023-11-08 11:08:54 +00:00
padding: 16px 24px;
position: fixed;
bottom: 0;
left: 0;
background: #ffffff;
width: 100%;
box-sizing: border-box;
2023-10-27 09:49:06 +00:00
}
.upload-document {
width: 70%;
margin: 0 auto;
margin-bottom: 20px;
}
2023-10-27 09:49:06 +00:00
}
</style>