Skip to content

Commit 154cc72

Browse files
perf: Optimize duplicate files and style
1 parent c785dfa commit 154cc72

File tree

5 files changed

+68
-321
lines changed

5 files changed

+68
-321
lines changed

ui/src/views/document/component/GenerateRelatedDialog.vue renamed to ui/src/components/generate-related-dialog/index.vue

Lines changed: 40 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
</div>
2121
<div class="ml-12 lighter">
2222
<p>提示词中的 {data} 为分段内容的占位符,执行时替换为分段内容发送给 AI 模型;</p>
23-
<p>AI 模型根据分段内容生成相关问题,请将生成的问题放至&lt;question&gt;&lt;/question&gt;标签中,系统会自动关联标签中的问题;</p>
23+
<p>
24+
AI
25+
模型根据分段内容生成相关问题,请将生成的问题放至&lt;question&gt;&lt;/question&gt;标签中,系统会自动关联标签中的问题;
26+
</p>
2427
<p>生成效果依赖于所选模型和提示词,用户可自行调整至最佳效果。</p>
2528
</div>
2629
</div>
@@ -45,16 +48,13 @@
4548
class="flex-between"
4649
>
4750
<div class="flex align-center">
48-
<span
49-
v-html="relatedObject(providerOptions, label, 'provider')?.icon"
50-
class="model-icon mr-8"
51-
></span>
51+
<span
52+
v-html="relatedObject(providerOptions, label, 'provider')?.icon"
53+
class="model-icon mr-8"
54+
></span>
5255
<span>{{ item.name }}</span>
53-
<el-tag
54-
v-if="item.permission_type === 'PUBLIC'"
55-
type="info"
56-
class="info-tag ml-8"
57-
>公用
56+
<el-tag v-if="item.permission_type === 'PUBLIC'" type="info" class="info-tag ml-8"
57+
>公用
5858
</el-tag>
5959
</div>
6060
<el-icon class="check-icon" v-if="item.id === form.model_id">
@@ -71,14 +71,14 @@
7171
disabled
7272
>
7373
<div class="flex">
74-
<span
75-
v-html="relatedObject(providerOptions, label, 'provider')?.icon"
76-
class="model-icon mr-8"
77-
></span>
74+
<span
75+
v-html="relatedObject(providerOptions, label, 'provider')?.icon"
76+
class="model-icon mr-8"
77+
></span>
7878
<span>{{ item.name }}</span>
7979
<span class="danger">{{
80-
$t('views.application.applicationForm.form.aiModel.unavailable')
81-
}}</span>
80+
$t('views.application.applicationForm.form.aiModel.unavailable')
81+
}}</span>
8282
</div>
8383
<el-icon class="check-icon" v-if="item.id === form.model_id">
8484
<Check />
@@ -88,16 +88,9 @@
8888
</el-select>
8989
</el-form-item>
9090
<el-form-item label="提示词" prop="prompt">
91-
<el-input
92-
v-model="form.prompt"
93-
placeholder="请输入提示词"
94-
:rows="7"
95-
type="textarea"
96-
/>
91+
<el-input v-model="form.prompt" placeholder="请输入提示词" :rows="7" type="textarea" />
9792
</el-form-item>
9893
</el-form>
99-
100-
10194
</div>
10295
<template #footer>
10396
<span class="dialog-footer">
@@ -113,48 +106,47 @@
113106
import { reactive, ref, watch } from 'vue'
114107
import { useRoute } from 'vue-router'
115108
import documentApi from '@/api/document'
116-
109+
import paragraphApi from '@/api/paragraph'
110+
import datasetApi from '@/api/dataset'
117111
import useStore from '@/stores'
118112
import { relatedObject } from '@/utils/utils'
119113
import type { Provider } from '@/api/type/model'
120-
import datasetApi from '@/api/dataset'
121114
import { groupBy } from 'lodash'
122115
import { MsgSuccess } from '@/utils/message'
123116
import { t } from '@/locales'
124117
import type { FormInstance } from 'element-plus'
125118
126119
const route = useRoute()
127120
const {
128-
params: { id } // id为datasetID
121+
params: { id, documentId } // id为datasetID
129122
} = route as any
130123
131124
const { model, prompt, user } = useStore()
132125
133-
134126
const emit = defineEmits(['refresh'])
135127
136128
const loading = ref<boolean>(false)
137129
138130
const dialogVisible = ref<boolean>(false)
139131
const modelOptions = ref<any>(null)
140132
const providerOptions = ref<Array<Provider>>([])
141-
const documentIdList = ref<string[]>([])
133+
const idList = ref<string[]>([])
134+
const apiType = ref('') // 文档document或段落paragraph
142135
143136
const FormRef = ref()
144137
const userId = user.userInfo?.id as string
145138
const form = ref(prompt.get(userId))
146139
147-
148140
const rules = reactive({
149141
model_id: [{ required: true, message: '请选择AI 模型', trigger: 'blur' }],
150142
prompt: [{ required: true, message: '请输入提示词', trigger: 'blur' }]
151143
})
152144
153-
154-
const open = (document_ids: string[]) => {
145+
const open = (ids: string[], type: string) => {
155146
getProvider()
156147
getModel()
157-
documentIdList.value = document_ids
148+
idList.value = ids
149+
apiType.value = type
158150
dialogVisible.value = true
159151
}
160152
@@ -166,17 +158,25 @@ const submitHandle = async (formEl: FormInstance) => {
166158
if (valid) {
167159
// 保存提示词
168160
prompt.save(user.userInfo?.id as string, form.value)
169-
const data = { ...form.value, document_id_list: documentIdList.value }
170-
documentApi.batchGenerateRelated(id, data).then(() => {
171-
MsgSuccess('生成问题成功')
172-
emit('refresh')
173-
dialogVisible.value = false
174-
})
161+
if (apiType.value === 'paragraph') {
162+
const data = { ...form.value, paragraph_id_list: idList.value }
163+
paragraphApi.batchGenerateRelated(id, documentId, data).then(() => {
164+
MsgSuccess('生成问题成功')
165+
emit('refresh')
166+
dialogVisible.value = false
167+
})
168+
} else if (apiType.value === 'document') {
169+
const data = { ...form.value, document_id_list: idList.value }
170+
documentApi.batchGenerateRelated(id, data).then(() => {
171+
MsgSuccess('生成问题成功')
172+
emit('refresh')
173+
dialogVisible.value = false
174+
})
175+
}
175176
}
176177
})
177178
}
178179
179-
180180
function getModel() {
181181
loading.value = true
182182
datasetApi
@@ -203,26 +203,9 @@ function getProvider() {
203203
})
204204
}
205205
206-
207206
defineExpose({ open })
208207
</script>
209208
<style lang="scss" scope>
210-
.select-dataset-dialog {
211-
padding: 10px;
212-
213-
.el-dialog__header {
214-
padding: 24px 24px 0 8px;
215-
}
216-
217-
.el-dialog__body {
218-
padding: 8px !important;
219-
}
220-
221-
.el-dialog__footer {
222-
padding: 0 24px 24px;
223-
}
224-
}
225-
226209
.update-info {
227210
background: #d6e2ff;
228211
line-height: 25px;

ui/src/views/application-workflow/component/DropdownMenu.vue

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<component :is="iconComponent(`function-lib-node-icon`)" class="mr-8 mt-4" :size="32" />
4242
<div class="pre-wrap">
4343
<div class="lighter">{{ functionNode.label }}</div>
44-
<el-text type="info" size="small" >{{ functionNode.text }}</el-text>
44+
<el-text type="info" size="small">{{ functionNode.text }}</el-text>
4545
</div>
4646
</div>
4747

@@ -51,14 +51,19 @@
5151
@click.stop="clickNodes(functionLibNode, item, 'function')"
5252
@mousedown.stop="onmousedown(functionLibNode, item, 'function')"
5353
>
54-
<component
55-
:is="iconComponent(`function-lib-node-icon`)"
56-
class="mr-8"
57-
:size="32"
58-
/>
54+
<component :is="iconComponent(`function-lib-node-icon`)" class="mr-8" :size="32" />
5955
<div class="pre-wrap">
60-
<div class="lighter">{{ item.name }}</div>
61-
<el-text type="info" size="small" v-if="item.desc">{{ item.desc }}</el-text>
56+
<div class="lighter ellipsis-1" :title="item.name">{{ item.name }}</div>
57+
<p>
58+
<el-text
59+
class="ellipsis-1"
60+
type="info"
61+
size="small"
62+
:title="item.desc"
63+
v-if="item.desc"
64+
>{{ item.desc }}</el-text
65+
>
66+
</p>
6267
</div>
6368
</div>
6469
</template>
@@ -83,7 +88,16 @@
8388
<div class="lighter ellipsis" :title="item.name">
8489
{{ item.name }}
8590
</div>
86-
<el-text type="info" size="small" style="width: 80%" v-if="item.desc">{{ item.desc }}</el-text>
91+
<p>
92+
<el-text
93+
class="ellipsis"
94+
type="info"
95+
size="small"
96+
:title="item.desc"
97+
v-if="item.desc"
98+
>{{ item.desc }}</el-text
99+
>
100+
</p>
87101
</div>
88102
<div class="status-tag" style="margin-left: auto">
89103
<el-tag type="warning" v-if="isWorkFlow(item.type)" style="height: 22px"

ui/src/views/document/index.vue

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ import { hitHandlingMethod } from '@/enums/document'
438438
import { MsgSuccess, MsgConfirm, MsgError } from '@/utils/message'
439439
import useStore from '@/stores'
440440
import StatusVlue from '@/views/document/component/Status.vue'
441-
import GenerateRelatedDialog from '@/views/document/component/GenerateRelatedDialog.vue'
441+
import GenerateRelatedDialog from '@/components/generate-related-dialog/index.vue'
442442
import { TaskType, State } from '@/utils/status'
443443
const router = useRouter()
444444
const route = useRoute()
@@ -562,9 +562,6 @@ const cancelTask = (row: any, task_type: number) => {
562562
MsgSuccess('发送成功')
563563
})
564564
}
565-
function syncDataset() {
566-
SyncWebDialogRef.value.open(id)
567-
}
568565
569566
function importDoc() {
570567
title.value = '导入文档'
@@ -706,18 +703,6 @@ function batchRefresh() {
706703
})
707704
}
708705
709-
function batchGenerateRelated() {
710-
const arr: string[] = []
711-
multipleSelection.value.map((v) => {
712-
if (v) {
713-
arr.push(v.id)
714-
}
715-
})
716-
documentApi.batchGenerateRelated(id, arr, loading).then(() => {
717-
MsgSuccess('批量生成问题成功')
718-
multipleTableRef.value?.clearSelection()
719-
})
720-
}
721706
722707
function deleteDocument(row: any) {
723708
MsgConfirm(
@@ -827,7 +812,7 @@ function openGenerateDialog(row?: any) {
827812
})
828813
}
829814
830-
GenerateRelatedDialogRef.value.open(arr)
815+
GenerateRelatedDialogRef.value.open(arr, 'document')
831816
}
832817
833818
onMounted(() => {

0 commit comments

Comments
 (0)