Skip to content

Commit 69e39f5

Browse files
authored
feat: 导入时支持设置分段标题为关联问题(#177) (#392)
1 parent 4da8b1b commit 69e39f5

File tree

4 files changed

+142
-10
lines changed

4 files changed

+142
-10
lines changed

ui/src/views/dataset/CreateDataset.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ function submit() {
9898
loading.value = true
9999
const documents = [] as any
100100
StepSecondRef.value?.paragraphList.map((item: any) => {
101+
if (!StepSecondRef.value?.checkedConnect) {
102+
item.content.map((v: any) => {
103+
delete v['problem_list']
104+
})
105+
}
101106
documents.push({
102107
name: item.name,
103108
paragraphs: item.content

ui/src/views/dataset/component/EditParagraphDialog.vue

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,55 @@
11
<template>
2-
<el-dialog title="编辑分段" v-model="dialogVisible" width="80%" destroy-on-close>
3-
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="true" />
2+
<el-dialog
3+
title="编辑分段"
4+
v-model="dialogVisible"
5+
width="80%"
6+
destroy-on-close
7+
class="paragraph-dialog"
8+
>
9+
<el-row v-if="isConnect">
10+
<el-col :span="18" class="p-24">
11+
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="true" />
12+
</el-col>
13+
<el-col :span="6" class="border-l" style="width: 300px">
14+
<p class="bold title p-24" style="padding-bottom: 0">
15+
<span class="flex align-center">
16+
<span>关联问题</span>
17+
<el-divider direction="vertical" class="mr-4" />
18+
<el-button text @click="addProblem">
19+
<el-icon><Plus /></el-icon>
20+
</el-button>
21+
</span>
22+
</p>
23+
<el-scrollbar height="345px">
24+
<div class="p-24" style="padding-top: 16px">
25+
<el-input
26+
v-if="isAddProblem"
27+
v-model="problemValue"
28+
placeholder="请选择问题"
29+
@change="addProblemHandle"
30+
@blur="isAddProblem = false"
31+
ref="inputRef"
32+
/>
33+
34+
<template v-for="(item, index) in detail.problem_list" :key="index">
35+
<TagEllipsis
36+
@close="delProblemHandle(item, index)"
37+
class="question-tag"
38+
type="info"
39+
effect="plain"
40+
closable
41+
>
42+
{{ item.content }}
43+
</TagEllipsis>
44+
</template>
45+
</div>
46+
</el-scrollbar>
47+
</el-col>
48+
</el-row>
49+
<div v-else class="p-24">
50+
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="true" />
51+
</div>
52+
453
<template #footer>
554
<span class="dialog-footer">
655
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button>
@@ -10,17 +59,26 @@
1059
</el-dialog>
1160
</template>
1261
<script setup lang="ts">
13-
import { ref, watch } from 'vue'
62+
import { ref, watch, nextTick } from 'vue'
1463
import { cloneDeep } from 'lodash'
1564
import ParagraphForm from '@/views/paragraph/component/ParagraphForm.vue'
1665
66+
const props = defineProps({
67+
isConnect: Boolean
68+
})
69+
1770
const emit = defineEmits(['updateContent'])
1871
1972
const dialogVisible = ref<boolean>(false)
2073
21-
const detail = ref({})
74+
const detail = ref<any>({})
2275
2376
const paragraphFormRef = ref()
77+
const inputRef = ref()
78+
79+
const isAddProblem = ref(false)
80+
81+
const problemValue = ref('')
2482
2583
watch(dialogVisible, (bool) => {
2684
if (!bool) {
@@ -32,9 +90,32 @@ const open = (data: any) => {
3290
detail.value = cloneDeep(data)
3391
dialogVisible.value = true
3492
}
93+
94+
function delProblemHandle(item: any, index: number) {
95+
detail.value.problem_list.splice(index, 1)
96+
}
97+
function addProblemHandle() {
98+
if (problemValue.value) {
99+
detail.value?.problem_list?.push({
100+
content: problemValue.value
101+
})
102+
problemValue.value = ''
103+
isAddProblem.value = false
104+
}
105+
}
106+
function addProblem() {
107+
isAddProblem.value = true
108+
nextTick(() => {
109+
inputRef.value?.focus()
110+
})
111+
}
112+
35113
const submitHandle = async () => {
36114
if (await paragraphFormRef.value?.validate()) {
37-
emit('updateContent', paragraphFormRef.value?.form)
115+
emit('updateContent', {
116+
problem_list: detail.value.problem_list,
117+
...paragraphFormRef.value?.form
118+
})
38119
dialogVisible.value = false
39120
}
40121
}

ui/src/views/dataset/component/ParagraphPreview.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@
4545
</el-tab-pane>
4646
</template>
4747
</el-tabs>
48-
<EditParagraphDialog ref="EditParagraphDialogRef" @updateContent="updateContent" />
48+
<EditParagraphDialog
49+
ref="EditParagraphDialogRef"
50+
@updateContent="updateContent"
51+
:isConnect="isConnect"
52+
/>
4953
</template>
5054
<script setup lang="ts">
5155
import { ref, reactive, onMounted, watch } from 'vue'
@@ -59,7 +63,8 @@ const props = defineProps({
5963
data: {
6064
type: Array<any>,
6165
default: () => []
62-
}
66+
},
67+
isConnect: Boolean
6368
})
6469
6570
const emit = defineEmits(['update:data'])

ui/src/views/dataset/step/StepSecond.vue

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@
8181
</el-radio-group>
8282
</div>
8383
</el-scrollbar>
84-
<div class="text-right">
84+
<div>
85+
<el-checkbox v-model="checkedConnect" @change="changeHandle">
86+
导入时添加分段标题为关联问题(适用于标题为问题的问答对)
87+
</el-checkbox>
88+
</div>
89+
<div class="text-right mt-8">
8590
<el-button @click="splitDocument">生成预览</el-button>
8691
</div>
8792
</div>
@@ -90,7 +95,7 @@
9095
<el-col :span="14" class="p-24 border-l">
9196
<div v-loading="loading">
9297
<h4 class="title-decoration-1 mb-8">分段预览</h4>
93-
<ParagraphPreview v-model:data="paragraphList" />
98+
<ParagraphPreview v-model:data="paragraphList" :isConnect="checkedConnect" />
9499
</div>
95100
</el-col>
96101
</el-row>
@@ -110,6 +115,9 @@ const radio = ref('1')
110115
const loading = ref(false)
111116
const paragraphList = ref<any[]>([])
112117
const patternLoading = ref<boolean>(false)
118+
const checkedConnect = ref<boolean>(false)
119+
120+
const firstChecked = ref(true)
113121
114122
const form = reactive<{
115123
patterns: Array<string>
@@ -122,6 +130,24 @@ const form = reactive<{
122130
with_filter: true
123131
})
124132
133+
function changeHandle(val: boolean) {
134+
if (val && firstChecked.value) {
135+
const list = paragraphList.value
136+
list.map((item: any) => {
137+
item.content.map((v: any) => {
138+
v['problem_list'] = v.title
139+
? [
140+
{
141+
content: v.title
142+
}
143+
]
144+
: []
145+
})
146+
})
147+
paragraphList.value = list
148+
firstChecked.value = false
149+
}
150+
}
125151
function splitDocument() {
126152
loading.value = true
127153
let fd = new FormData()
@@ -142,6 +168,20 @@ function splitDocument() {
142168
documentApi
143169
.postSplitDocument(fd)
144170
.then((res: any) => {
171+
const list = res.data
172+
if (checkedConnect.value) {
173+
list.map((item: any) => {
174+
item.content.map((v: any) => {
175+
v['problem_list'] = v.title
176+
? [
177+
{
178+
content: v.title
179+
}
180+
]
181+
: []
182+
})
183+
})
184+
}
145185
paragraphList.value = res.data
146186
loading.value = false
147187
})
@@ -167,7 +207,8 @@ onMounted(() => {
167207
})
168208
169209
defineExpose({
170-
paragraphList
210+
paragraphList,
211+
checkedConnect
171212
})
172213
</script>
173214
<style scoped lang="scss">

0 commit comments

Comments
 (0)