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

187 lines
4.8 KiB
Vue
Raw Normal View History

2023-10-26 11:02:16 +00:00
<template>
2023-12-05 11:21:13 +00:00
<LayoutContainer
:header="isCreate ? '创建数据集' : '上传文档'"
back-to="-1"
class="create-dataset"
>
<template #backButton>
<back-button @click="back"></back-button>
</template>
2023-11-03 09:45:01 +00:00
<template #header>
<el-steps :active="active" finish-status="success" align-center class="create-dataset__steps">
<el-step v-for="(item, index) in steps" :key="index">
<template #icon>
2023-11-10 11:05:52 +00:00
<div class="app-step flex align-center">
2023-11-03 09:45:01 +00:00
<div class="el-step__icon is-text">
2023-11-10 11:05:52 +00:00
<div class="el-step__icon-inner">
<el-icon v-if="active == index + 1" style="margin-top: 1px"><Select /></el-icon>
<span v-else> {{ index + 1 }}</span>
</div>
2023-11-03 09:45:01 +00:00
</div>
2023-11-10 11:05:52 +00:00
<span class="ml-4">{{ item.name }}</span>
2023-11-03 09:45:01 +00:00
</div>
</template>
</el-step>
</el-steps>
</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">
<template v-if="steps[active]?.component">
<component :is="steps[active].component" :ref="steps[active]?.ref" />
</template>
<template v-else-if="active === 2">
2023-12-05 11:21:13 +00:00
<ResultSuccess :data="successInfo" />
2023-11-10 11:05:52 +00:00
</template>
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">
2023-11-10 09:18:00 +00:00
<el-button @click="router.go(-1)" :disabled="loading"> </el-button>
<el-button @click="prev" v-if="active === 1" :disabled="loading"></el-button>
<el-button @click="next" type="primary" v-if="active === 0" :disabled="loading"
>下一步</el-button
>
<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">
2023-11-10 09:18:00 +00:00
import { ref, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
2023-11-09 10:52:06 +00:00
import StepFirst from './step/StepFirst.vue'
import StepSecond from './step/StepSecond.vue'
2023-12-05 11:21:13 +00:00
import ResultSuccess from './step/ResultSuccess.vue'
2023-11-10 09:18:00 +00:00
import datasetApi from '@/api/dataset'
import type { datasetData } from '@/api/type/dataset'
2023-11-22 10:37:08 +00:00
import documentApi from '@/api/document'
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 } = useStore()
const baseInfo = computed(() => dataset.baseInfo)
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 {
2023-12-05 11:21:13 +00:00
query: { id, type }
} = route
2023-11-08 11:08:54 +00:00
2023-12-05 11:21:13 +00:00
const isCreate = type === 'create'
2023-10-27 09:49:06 +00:00
const steps = [
2023-11-06 11:06:02 +00:00
{
2023-11-09 10:52:06 +00:00
ref: 'StepFirstRef',
2023-11-06 11:06:02 +00:00
name: '上传文档',
2023-11-09 10:52:06 +00:00
component: StepFirst
2023-11-08 11:08:54 +00:00
},
{
2023-11-10 09:18:00 +00:00
ref: 'StepSecondRef',
2023-11-08 11:08:54 +00:00
name: '设置分段规则',
2023-11-09 10:52:06 +00:00
component: StepSecond
2023-10-27 09:49:06 +00:00
}
]
2023-11-09 10:52:06 +00:00
const StepFirstRef = ref()
2023-11-10 09:18:00 +00:00
const StepSecondRef = ref()
2023-11-02 01:56:14 +00:00
2023-11-10 09:18:00 +00:00
const loading = 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() {
2023-12-12 08:15:37 +00:00
console.log(StepFirstRef.value)
if (await StepFirstRef.value?.onSubmit()) {
2023-11-02 01:56:14 +00:00
if (active.value++ > 2) active.value = 0
}
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.saveBaseInfo(null)
dataset.saveDocumentsFile([])
}
2023-11-10 09:18:00 +00:00
function submit() {
loading.value = true
const documents = [] as any[]
2023-12-12 08:15:37 +00:00
StepSecondRef.value?.paragraphList.map((item: any) => {
2023-11-10 09:18:00 +00:00
documents.push({
name: item.name,
paragraphs: item.content
})
})
const obj = { ...baseInfo.value, documents } as datasetData
if (id) {
2023-11-22 10:37:08 +00:00
documentApi
2023-12-05 11:21:13 +00:00
.postDocument(id as string, documents)
2023-11-10 09:18:00 +00:00
.then((res) => {
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
})
} else {
datasetApi
.postDateset(obj)
.then((res) => {
2023-11-10 11:05:52 +00:00
successInfo.value = res.data
active.value = 2
clearStore()
2023-11-10 09:18:00 +00:00
loading.value = false
})
.catch(() => {
loading.value = false
})
}
}
2023-12-05 11:21:13 +00:00
function back() {
if (baseInfo.value || StepSecondRef.value?.paragraphList?.length > 0) {
MsgConfirm(`提示`, `当前的更改尚未保存,确认退出吗?`, {
confirmButtonText: '确认',
type: 'warning'
})
.then(() => {
router.go(-1)
clearStore()
})
.catch(() => {})
} else {
router.go(-1)
}
}
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
}
}
</style>