feat: 段落模块
This commit is contained in:
parent
48257eacff
commit
8b23ce18d0
2
ui/env.d.ts
vendored
2
ui/env.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
/// <reference types="vite/client" />
|
/// <reference types="vite/client" />
|
||||||
interface ImportMeta {
|
interface ImportMeta {
|
||||||
readonly env: ImportMetaEnv;
|
readonly env: ImportMetaEnv
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ const getParagraph: (dataset_id: string, document_id: string) => Promise<Result<
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除段落
|
* 删除段落
|
||||||
* @param 参数 dataset_id, document_id, document_id
|
* @param 参数 dataset_id, document_id, paragraph_id
|
||||||
*/
|
*/
|
||||||
const delParagraph: (
|
const delParagraph: (
|
||||||
dataset_id: string,
|
dataset_id: string,
|
||||||
@ -245,6 +245,51 @@ const putParagraph: (
|
|||||||
return put(`${prefix}/${dataset_id}/document/${document_id}/paragraph/${paragraph_id}`, data)
|
return put(`${prefix}/${dataset_id}/document/${document_id}/paragraph/${paragraph_id}`, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 问题列表
|
||||||
|
* @param 参数 dataset_id,document_id,paragraph_id
|
||||||
|
*/
|
||||||
|
const getProblem: (dataset_id: string, document_id: string, paragraph_id: string) => Promise<Result<any>> = (
|
||||||
|
dataset_id,
|
||||||
|
document_id,
|
||||||
|
paragraph_id: string,
|
||||||
|
) => {
|
||||||
|
return get(`${prefix}/${dataset_id}/document/${document_id}/paragraph/${paragraph_id}/problem`)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建问题
|
||||||
|
* @param 参数
|
||||||
|
* dataset_id, document_id, paragraph_id
|
||||||
|
* {
|
||||||
|
"id": "string",
|
||||||
|
content": "string"
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
const postProblem: (
|
||||||
|
dataset_id: string,
|
||||||
|
document_id: string,
|
||||||
|
paragraph_id: string,
|
||||||
|
data: any
|
||||||
|
) => Promise<Result<any>> = (dataset_id, document_id, paragraph_id, data: any) => {
|
||||||
|
return post(
|
||||||
|
`${prefix}/${dataset_id}/document/${document_id}/paragraph/${paragraph_id}/problem`,
|
||||||
|
data
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 删除问题
|
||||||
|
* @param 参数 dataset_id, document_id, paragraph_id,problem_id
|
||||||
|
*/
|
||||||
|
const delProblem: (
|
||||||
|
dataset_id: string,
|
||||||
|
document_id: string,
|
||||||
|
paragraph_id: string,
|
||||||
|
problem_id: string,
|
||||||
|
) => Promise<Result<boolean>> = (dataset_id, document_id, paragraph_id,problem_id) => {
|
||||||
|
return del(`${prefix}/${dataset_id}/document/${document_id}/paragraph/${paragraph_id}/problem/${problem_id}`)
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getDateset,
|
getDateset,
|
||||||
getAllDateset,
|
getAllDateset,
|
||||||
@ -261,5 +306,8 @@ export default {
|
|||||||
getParagraph,
|
getParagraph,
|
||||||
delParagraph,
|
delParagraph,
|
||||||
putParagraph,
|
putParagraph,
|
||||||
postParagraph
|
postParagraph,
|
||||||
|
getProblem,
|
||||||
|
postProblem,
|
||||||
|
delProblem
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,48 +6,45 @@
|
|||||||
class="paragraph-dialog"
|
class="paragraph-dialog"
|
||||||
destroy-on-close
|
destroy-on-close
|
||||||
>
|
>
|
||||||
<el-row>
|
<el-row v-loading="loading">
|
||||||
<el-col :span="16" class="p-24">
|
<el-col :span="16" class="p-24">
|
||||||
<div class="flex-between mb-16">
|
<el-scrollbar>
|
||||||
<div class="bold title align-center">分段内容</div>
|
<div style="height: 350px">
|
||||||
<el-button text v-if="pId">
|
<div class="flex-between mb-16">
|
||||||
<el-icon><EditPen /></el-icon>
|
<div class="bold title align-center">分段内容</div>
|
||||||
</el-button>
|
<el-button text @click="isEdit = true" v-if="problemId && !isEdit">
|
||||||
</div>
|
<el-icon><EditPen /></el-icon>
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<ParagraphForm ref="paragraphFormRef" :data="detail" />
|
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="isEdit" />
|
||||||
<div class="text-right">
|
</div>
|
||||||
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button>
|
|
||||||
<el-button type="primary" :disabled="loading" @click="submitHandle"> 保存 </el-button>
|
<div class="text-right" v-if="problemId && isEdit">
|
||||||
</div>
|
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button>
|
||||||
|
<el-button type="primary" :disabled="loading" @click="submitHandle"> 保存 </el-button>
|
||||||
|
</div>
|
||||||
|
</el-scrollbar>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="8" class="border-l p-24">
|
<el-col :span="8" class="border-l p-24">
|
||||||
<p class="bold title mb-16">
|
<!-- 关联问题 -->
|
||||||
关联问题 <el-divider direction="vertical" />
|
<ProblemComponent :problemId="problemId" ref="ProblemRef" />
|
||||||
<el-button text>
|
|
||||||
<el-icon><Plus /></el-icon>
|
|
||||||
</el-button>
|
|
||||||
</p>
|
|
||||||
<el-input
|
|
||||||
v-model="questionValue"
|
|
||||||
@change="addQuestion"
|
|
||||||
placeholder="请输入问题,回车保存"
|
|
||||||
class="mb-8"
|
|
||||||
/>
|
|
||||||
<template v-for="(item, index) in questionList" :key="index">
|
|
||||||
<TagEllipsis class="question-tag" type="info" effect="plain" closable>
|
|
||||||
{{ item.content }}
|
|
||||||
</TagEllipsis>
|
|
||||||
</template>
|
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
<template #footer v-if="!problemId">
|
||||||
|
<span class="dialog-footer">
|
||||||
|
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button>
|
||||||
|
<el-button type="primary" @click="submitHandle"> 提交 </el-button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch } from 'vue'
|
import { ref, watch, nextTick } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import type { FormInstance, FormRules } from 'element-plus'
|
import type { FormInstance, FormRules } from 'element-plus'
|
||||||
import ParagraphForm from '@/views/paragraph/component/ParagraphForm.vue'
|
import ParagraphForm from '@/views/paragraph/component/ParagraphForm.vue'
|
||||||
|
import ProblemComponent from '@/views/paragraph/component/ProblemComponent.vue'
|
||||||
import datasetApi from '@/api/dataset'
|
import datasetApi from '@/api/dataset'
|
||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
|
|
||||||
@ -64,33 +61,30 @@ const {
|
|||||||
|
|
||||||
const emit = defineEmits(['refresh'])
|
const emit = defineEmits(['refresh'])
|
||||||
|
|
||||||
|
const ProblemRef = ref()
|
||||||
const paragraphFormRef = ref<FormInstance>()
|
const paragraphFormRef = ref<FormInstance>()
|
||||||
|
|
||||||
const dialogVisible = ref<boolean>(false)
|
const dialogVisible = ref<boolean>(false)
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const pId = ref('')
|
const problemId = ref('')
|
||||||
const detail = ref<any>({})
|
const detail = ref<any>({})
|
||||||
const isEdit = ref(false)
|
const isEdit = ref(false)
|
||||||
|
|
||||||
const questionValue = ref('')
|
|
||||||
const questionList = ref<any[]>([])
|
|
||||||
|
|
||||||
watch(dialogVisible, (bool) => {
|
watch(dialogVisible, (bool) => {
|
||||||
if (!bool) {
|
if (!bool) {
|
||||||
pId.value = ''
|
problemId.value = ''
|
||||||
detail.value = {}
|
detail.value = {}
|
||||||
isEdit.value = false
|
isEdit.value = false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function addQuestion() {}
|
|
||||||
|
|
||||||
const open = (data: any) => {
|
const open = (data: any) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
detail.value.title = data.title
|
detail.value.title = data.title
|
||||||
detail.value.content = data.content
|
detail.value.content = data.content
|
||||||
pId.value = data.id
|
problemId.value = data.id
|
||||||
|
} else {
|
||||||
isEdit.value = true
|
isEdit.value = true
|
||||||
}
|
}
|
||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
@ -98,10 +92,10 @@ const open = (data: any) => {
|
|||||||
const submitHandle = async () => {
|
const submitHandle = async () => {
|
||||||
if (await paragraphFormRef.value?.validate()) {
|
if (await paragraphFormRef.value?.validate()) {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
if (id) {
|
if (problemId.value) {
|
||||||
paragraph
|
paragraph
|
||||||
.asyncPutParagraph(datasetId, documentId, pId, paragraphFormRef.value?.form)
|
.asyncPutParagraph(datasetId, documentId, problemId.value, paragraphFormRef.value?.form)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
emit('refresh')
|
emit('refresh')
|
||||||
loading.value = false
|
loading.value = false
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
@ -110,8 +104,15 @@ const submitHandle = async () => {
|
|||||||
loading.value = false
|
loading.value = false
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
const obj =
|
||||||
|
ProblemRef.value.problemList.length > 0
|
||||||
|
? {
|
||||||
|
problem_list: ProblemRef.value.problemList,
|
||||||
|
...paragraphFormRef.value?.form
|
||||||
|
}
|
||||||
|
: paragraphFormRef.value?.form
|
||||||
datasetApi
|
datasetApi
|
||||||
.postParagraph(datasetId, documentId, paragraphFormRef.value?.form)
|
.postParagraph(datasetId, documentId, obj)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
emit('refresh')
|
emit('refresh')
|
||||||
loading.value = false
|
loading.value = false
|
||||||
@ -135,11 +136,12 @@ defineExpose({ open })
|
|||||||
border-top: 1px solid var(--el-border-color);
|
border-top: 1px solid var(--el-border-color);
|
||||||
padding: 0 !important;
|
padding: 0 !important;
|
||||||
}
|
}
|
||||||
|
.el-dialog__footer {
|
||||||
|
padding-top: 16px;
|
||||||
|
border-top: 1px solid var(--el-border-color);
|
||||||
|
}
|
||||||
.title {
|
.title {
|
||||||
color: var(--app-text-color);
|
color: var(--app-text-color);
|
||||||
}
|
}
|
||||||
.question-tag {
|
|
||||||
width: 217px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-form ref="paragraphFormRef" :model="form" label-position="top" :rules="rules" @submit.prevent>
|
<el-form ref="paragraphFormRef" :model="form" label-position="top" :rules="rules" @submit.prevent>
|
||||||
<el-form-item label="分段标题">
|
<el-form-item label="分段标题">
|
||||||
<el-input v-model="form.title" placeholder="请输入分段标题"> </el-input>
|
<el-input v-if="isEdit" v-model="form.title" placeholder="请输入分段标题"> </el-input>
|
||||||
|
<span v-else>{{ form.title }}</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="分段内容" prop="content">
|
<el-form-item label="分段内容" prop="content">
|
||||||
<el-input
|
<el-input
|
||||||
|
v-if="isEdit"
|
||||||
v-model="form.content"
|
v-model="form.content"
|
||||||
placeholder="请输入分段内容"
|
placeholder="请输入分段内容"
|
||||||
maxlength="1024"
|
maxlength="1024"
|
||||||
@ -13,6 +15,7 @@
|
|||||||
type="textarea"
|
type="textarea"
|
||||||
>
|
>
|
||||||
</el-input>
|
</el-input>
|
||||||
|
<span v-else>{{ form.content }}</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</template>
|
</template>
|
||||||
@ -24,7 +27,8 @@ const props = defineProps({
|
|||||||
data: {
|
data: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => {}
|
default: () => {}
|
||||||
}
|
},
|
||||||
|
isEdit: Boolean
|
||||||
})
|
})
|
||||||
|
|
||||||
const form = ref<any>({
|
const form = ref<any>({
|
||||||
|
|||||||
145
ui/src/views/paragraph/component/ProblemComponent.vue
Normal file
145
ui/src/views/paragraph/component/ProblemComponent.vue
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
<template>
|
||||||
|
<p class="bold title mb-16">
|
||||||
|
关联问题 <el-divider direction="vertical" />
|
||||||
|
<el-button text @click="addProblem">
|
||||||
|
<el-icon><Plus /></el-icon>
|
||||||
|
</el-button>
|
||||||
|
</p>
|
||||||
|
<div v-loading="loading" style="height: 350px">
|
||||||
|
<el-scrollbar>
|
||||||
|
<el-input
|
||||||
|
ref="inputRef"
|
||||||
|
v-if="isAddProblem"
|
||||||
|
v-model="problemValue"
|
||||||
|
@change="addProblemHandle"
|
||||||
|
placeholder="请输入问题,回车保存"
|
||||||
|
class="mb-8"
|
||||||
|
autofocus
|
||||||
|
/>
|
||||||
|
|
||||||
|
<template v-for="(item, index) in problemList" :key="index">
|
||||||
|
<TagEllipsis
|
||||||
|
@close="delProblemHandle(item, index)"
|
||||||
|
class="question-tag"
|
||||||
|
type="info"
|
||||||
|
effect="plain"
|
||||||
|
closable
|
||||||
|
>
|
||||||
|
{{ item.content }}
|
||||||
|
</TagEllipsis>
|
||||||
|
</template>
|
||||||
|
</el-scrollbar>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, nextTick, onMounted, onUnmounted, watch } from 'vue'
|
||||||
|
import { useRoute } from 'vue-router'
|
||||||
|
import datasetApi from '@/api/dataset'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
problemId: String
|
||||||
|
})
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
const {
|
||||||
|
params: { datasetId, documentId }
|
||||||
|
} = route as any
|
||||||
|
|
||||||
|
const inputRef = ref()
|
||||||
|
const loading = ref(false)
|
||||||
|
const isAddProblem = ref(false)
|
||||||
|
|
||||||
|
const problemValue = ref('')
|
||||||
|
const problemList = ref<any[]>([])
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.problemId,
|
||||||
|
(value) => {
|
||||||
|
if (value) {
|
||||||
|
getProblemList()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 初始化立即执行
|
||||||
|
immediate: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
function delProblemHandle(item: any, index: number) {
|
||||||
|
loading.value = true
|
||||||
|
if (item.id) {
|
||||||
|
datasetApi
|
||||||
|
.delProblem(datasetId, documentId, props.problemId || '', item.id)
|
||||||
|
.then((res) => {
|
||||||
|
getProblemList()
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
loading.value = false
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
problemList.value.splice(index, 1)
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getProblemList() {
|
||||||
|
loading.value = true
|
||||||
|
datasetApi
|
||||||
|
.getProblem(datasetId, documentId, props.problemId || '')
|
||||||
|
.then((res) => {
|
||||||
|
problemList.value = res.data
|
||||||
|
loading.value = false
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
loading.value = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function addProblem() {
|
||||||
|
isAddProblem.value = true
|
||||||
|
nextTick(() => {
|
||||||
|
inputRef.value?.focus()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
function addProblemHandle(val: string) {
|
||||||
|
if (val) {
|
||||||
|
const obj = {
|
||||||
|
content: val
|
||||||
|
}
|
||||||
|
loading.value = true
|
||||||
|
if (props.problemId) {
|
||||||
|
datasetApi
|
||||||
|
.postProblem(datasetId, documentId, props.problemId, obj)
|
||||||
|
.then((res) => {
|
||||||
|
getProblemList()
|
||||||
|
problemValue.value = ''
|
||||||
|
isAddProblem.value = false
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
loading.value = false
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
problemList.value.unshift(obj)
|
||||||
|
problemValue.value = ''
|
||||||
|
isAddProblem.value = false
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {})
|
||||||
|
onUnmounted(() => {
|
||||||
|
problemList.value = []
|
||||||
|
problemValue.value = ''
|
||||||
|
isAddProblem.value = false
|
||||||
|
})
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
problemList
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.question-tag {
|
||||||
|
width: 217px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -5,7 +5,7 @@
|
|||||||
<el-button @click="addParagraph" type="primary" :disabled="loading"> 添加分段 </el-button>
|
<el-button @click="addParagraph" type="primary" :disabled="loading"> 添加分段 </el-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<div class="document-detail__main p-16">
|
<div class="document-detail__main p-16" v-loading="loading">
|
||||||
<div class="flex-between p-8">
|
<div class="flex-between p-8">
|
||||||
<span>{{ paragraphDetail.length }} 段落</span>
|
<span>{{ paragraphDetail.length }} 段落</span>
|
||||||
<el-input
|
<el-input
|
||||||
@ -23,7 +23,7 @@
|
|||||||
</el-input>
|
</el-input>
|
||||||
</div>
|
</div>
|
||||||
<el-scrollbar>
|
<el-scrollbar>
|
||||||
<div class="document-detail-height" v-loading="loading">
|
<div class="document-detail-height">
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col
|
<el-col
|
||||||
:xs="24"
|
:xs="24"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user