Skip to content

Commit 69447ef

Browse files
authored
feat: Custom prompt words support filtering prompt words based on data sources. (#518)
1 parent c4b4ad1 commit 69447ef

File tree

2 files changed

+91
-15
lines changed

2 files changed

+91
-15
lines changed

frontend/src/api/prompt.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { request } from '@/utils/request'
22

33
export const promptApi = {
44
getList: (pageNum: any, pageSize: any, type: any, params: any) =>
5-
request.get(`/system/custom_prompt/${type}/page/${pageNum}/${pageSize}`, {
6-
params,
7-
}),
5+
request.get(`/system/custom_prompt/${type}/page/${pageNum}/${pageSize}${params}`),
86
updateEmbedded: (data: any) => request.put(`/system/custom_prompt`, data),
97
deleteEmbedded: (params: any) => request.delete('/system/custom_prompt', { data: params }),
108
getOne: (id: any) => request.get(`/system/custom_prompt/${id}`),

frontend/src/views/system/prompt/index.vue

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import { cloneDeep, endsWith, startsWith } from 'lodash-es'
1717
import { genFileId, type UploadInstance, type UploadProps, type UploadRawFile } from 'element-plus'
1818
import { settingsApi } from '@/api/setting.ts'
1919
import { useCache } from '@/utils/useCache.ts'
20-
20+
import { convertFilterText, FilterText } from '@/components/filter-text'
21+
import { DrawerMain } from '@/components/drawer-main'
22+
import iconFilter from '@/assets/svg/icon-filter_outlined.svg'
2123
interface Form {
2224
id?: string | null
2325
type: string | null
@@ -27,7 +29,7 @@ interface Form {
2729
datasource_names: string[]
2830
name: string | null
2931
}
30-
32+
const drawerMainRef = ref()
3133
const { t } = useI18n()
3234
const { copy } = useClipboard({ legacy: true })
3335
const multipleSelectionAll = ref<any[]>([])
@@ -40,7 +42,16 @@ const options = ref<any[]>([])
4042
const selectable = () => {
4143
return true
4244
}
45+
46+
const state = reactive<any>({
47+
conditions: [],
48+
filterTexts: [],
49+
})
50+
4351
onMounted(() => {
52+
datasourceApi.list().then((res) => {
53+
filterOption.value[0].option = [...res]
54+
})
4455
search()
4556
})
4657
@@ -325,16 +336,7 @@ const search = () => {
325336
searchLoading.value = true
326337
oldKeywords.value = keywords.value
327338
promptApi
328-
.getList(
329-
pageInfo.currentPage,
330-
pageInfo.pageSize,
331-
currentType.value,
332-
keywords.value
333-
? {
334-
name: keywords.value,
335-
}
336-
: {}
337-
)
339+
.getList(pageInfo.currentPage, pageInfo.pageSize, currentType.value, configParams())
338340
.then((res: any) => {
339341
toggleRowLoading.value = true
340342
fieldList.value = res.data
@@ -456,6 +458,66 @@ const typeChange = (val: any) => {
456458
pageInfo.currentPage = 0
457459
search()
458460
}
461+
462+
const configParams = () => {
463+
let str = ''
464+
if (keywords.value) {
465+
str += `name=${keywords.value}`
466+
}
467+
468+
state.conditions.forEach((ele: any) => {
469+
ele.value.forEach((itx: any) => {
470+
str += str ? `&${ele.field}=${itx}` : `${ele.field}=${itx}`
471+
})
472+
})
473+
474+
if (str.length) {
475+
str = `?${str}`
476+
}
477+
return str
478+
}
479+
const filterOption = ref<any[]>([
480+
{
481+
type: 'select',
482+
option: [],
483+
field: 'dslist',
484+
title: t('ds.title'),
485+
operate: 'in',
486+
property: { placeholder: t('common.empty') + t('ds.title') },
487+
},
488+
])
489+
490+
const fillFilterText = () => {
491+
const textArray = state.conditions?.length
492+
? convertFilterText(state.conditions, filterOption.value)
493+
: []
494+
state.filterTexts = [...textArray]
495+
Object.assign(state.filterTexts, textArray)
496+
}
497+
const searchCondition = (conditions: any) => {
498+
state.conditions = conditions
499+
fillFilterText()
500+
search()
501+
drawerMainClose()
502+
}
503+
504+
const clearFilter = (params?: number) => {
505+
let index = params ? params : 0
506+
if (isNaN(index)) {
507+
state.filterTexts = []
508+
} else {
509+
state.filterTexts.splice(index, 1)
510+
}
511+
drawerMainRef.value.clearFilter(index)
512+
}
513+
514+
const drawerMainOpen = async () => {
515+
drawerMainRef.value.init()
516+
}
517+
518+
const drawerMainClose = () => {
519+
drawerMainRef.value.close()
520+
}
459521
</script>
460522

461523
<template>
@@ -524,6 +586,12 @@ const typeChange = (val: any) => {
524586
{{ $t('user.batch_import') }}
525587
</el-button>
526588
</el-upload>
589+
<el-button secondary @click="drawerMainOpen">
590+
<template #icon>
591+
<iconFilter></iconFilter>
592+
</template>
593+
{{ $t('user.filter') }}
594+
</el-button>
527595
<el-button type="primary" @click="editHandler(null)">
528596
<template #icon>
529597
<icon_add_outlined></icon_add_outlined>
@@ -537,6 +605,11 @@ const typeChange = (val: any) => {
537605
class="table-content"
538606
:class="multipleSelectionAll?.length && 'show-pagination_height'"
539607
>
608+
<filter-text
609+
:total="pageInfo.total"
610+
:filter-texts="state.filterTexts"
611+
@clear-filter="clearFilter"
612+
/>
540613
<div class="preview-or-schema">
541614
<el-table
542615
ref="multipleTableRef"
@@ -770,6 +843,11 @@ const typeChange = (val: any) => {
770843
</el-form-item>
771844
</el-form>
772845
</el-drawer>
846+
<drawer-main
847+
ref="drawerMainRef"
848+
:filter-options="filterOption"
849+
@trigger-filter="searchCondition"
850+
/>
773851
</template>
774852

775853
<style lang="less" scoped>

0 commit comments

Comments
 (0)