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

182 lines
5.2 KiB
Vue
Raw Normal View History

2023-10-26 11:02:16 +00:00
<template>
2023-11-03 09:45:01 +00:00
<LayoutContainer header="创建数据集" back-to="-1" class="create-dataset">
<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">
<el-result icon="success" title="🎉 数据集创建成功 🎉">
<template #sub-title>
<div class="mt-8">
<span class="bold">{{ successInfo?.document_count || 0 }}</span>
<el-text type="info" class="ml-4">文档</el-text>
<el-divider direction="vertical" />
<span class="bold">{{ successInfo?.document_list.length || 0 }}</span>
<el-text type="info" class="ml-4">分段</el-text>
<el-divider direction="vertical" />
<span class="bold">{{ toThousands(successInfo?.char_length) || 0 }}</span>
<el-text type="info" class="ml-4">字符</el-text>
</div>
</template>
<template #extra>
<el-button @click="router.push({ path: `/dataset` })">返回数据集列表</el-button>
<el-button
type="primary"
@click="router.push({ path: `/dataset/${successInfo?.id}/document` })"
>前往文档</el-button
>
</template>
</el-result>
</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-11-10 09:18:00 +00:00
import datasetApi from '@/api/dataset'
import type { datasetData } from '@/api/type/dataset'
import { MsgSuccess } from '@/utils/message'
2023-11-10 11:05:52 +00:00
import { toThousands } from '@/utils/utils'
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 {
query: { id }
} = route as any
2023-11-08 11:08:54 +00:00
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-11-09 10:52:06 +00:00
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[]
StepSecondRef.value.segmentList.map((item: any) => {
documents.push({
name: item.name,
paragraphs: item.content
})
})
const obj = { ...baseInfo.value, documents } as datasetData
if (id) {
datasetApi
.postDocument(id, documents)
.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-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>