2023-10-26 11:02:16 +00:00
|
|
|
|
<template>
|
2024-07-17 10:22:56 +00:00
|
|
|
|
<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">
|
2024-07-30 04:48:12 +00:00
|
|
|
|
<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>
|
2024-07-17 10:22:56 +00:00
|
|
|
|
<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'
|
2024-07-17 10:22:56 +00:00
|
|
|
|
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'
|
2024-05-23 10:57:49 +00:00
|
|
|
|
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'
|
2024-04-09 03:33:28 +00:00
|
|
|
|
const { dataset, document } = useStore()
|
2024-04-09 07:56:01 +00:00
|
|
|
|
const documentsFiles = computed(() => dataset.documentsFiles)
|
2024-05-23 10:57:49 +00:00
|
|
|
|
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 {
|
2024-04-09 03:33:28 +00:00
|
|
|
|
query: { id } // id为datasetID,有id的是上传文档
|
2023-12-05 11:21:13 +00:00
|
|
|
|
} = route
|
2023-10-27 09:49:06 +00:00
|
|
|
|
|
2024-07-17 10:22:56 +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
|
2024-07-17 10:22:56 +00:00
|
|
|
|
if (await UploadComponentRef.value.validate()) {
|
2024-05-23 10:57:49 +00:00
|
|
|
|
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([])
|
2024-05-23 10:57:49 +00:00
|
|
|
|
dataset.saveDocumentsType('')
|
2023-11-10 11:05:52 +00:00
|
|
|
|
}
|
2023-11-10 09:18:00 +00:00
|
|
|
|
function submit() {
|
|
|
|
|
|
loading.value = true
|
2024-04-10 06:16:56 +00:00
|
|
|
|
const documents = [] as any
|
2024-07-17 10:22:56 +00:00
|
|
|
|
SetRulesRef.value?.paragraphList.map((item: any) => {
|
|
|
|
|
|
if (!SetRulesRef.value?.checkedConnect) {
|
2024-05-08 09:40:01 +00:00
|
|
|
|
item.content.map((v: any) => {
|
|
|
|
|
|
delete v['problem_list']
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2024-04-10 06:16:56 +00:00
|
|
|
|
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) {
|
2024-04-09 03:33:28 +00:00
|
|
|
|
// 上传文档
|
|
|
|
|
|
document
|
2024-04-10 06:16:56 +00:00
|
|
|
|
.asyncPostDocument(id as string, documents)
|
2024-04-09 03:33:28 +00:00
|
|
|
|
.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() {
|
2024-07-17 10:22:56 +00:00
|
|
|
|
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
|
|
|
|
}
|
2024-07-17 10:22:56 +00:00
|
|
|
|
.upload-document {
|
|
|
|
|
|
width: 70%;
|
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
|
}
|
2023-10-27 09:49:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|