2626 <el-input v-model =" form.title" placeholder =" 请给当前内容设置一个标题,以便管理查看" >
2727 </el-input >
2828 </el-form-item >
29- <el-form-item label =" 保存至文档" prop =" document" >
30- <el-cascader
31- v-model =" form.document"
32- :props =" LoadDocument"
33- placeholder =" 请选择文档"
34- class =" w-full"
29+ <el-form-item label =" 选择知识库" prop =" dataset_id" >
30+ <el-select
31+ v-model =" form.dataset_id"
32+ filterable
33+ placeholder =" 请选择知识库"
34+ :loading =" optionLoading"
35+ @change =" changeDataset"
3536 >
36- <template # default = " { node , data } " >
37+ <el-option v-for = " item in datasetList " :key = " item.id " :label = " item.name " :value = " item.id " >
3738 <span class =" flex align-center" >
3839 <AppAvatar
39- v-if =" !data .dataset_id && data .type === '1'"
40+ v-if =" !item .dataset_id && item .type === '1'"
4041 class =" mr-12 avatar-purple"
4142 shape =" square"
4243 :size =" 24"
4344 >
4445 <img src =" @/assets/icon_web.svg" style =" width : 58% " alt =" " />
4546 </AppAvatar >
4647 <AppAvatar
47- v-else-if =" !data .dataset_id && data .type === '0'"
48+ v-else-if =" !item .dataset_id && item .type === '0'"
4849 class =" mr-12"
4950 shape =" square"
5051 :size =" 24"
5152 >
5253 <img src =" @/assets/icon_document.svg" style =" width : 58% " alt =" " />
5354 </AppAvatar >
54- < span class = " ellipsis " > {{ data .name }}</ span >
55+ {{ item .name }}
5556 </span >
56- </template >
57- </el-cascader >
57+ </el-option >
58+ </el-select >
59+ </el-form-item >
60+ <el-form-item label =" 保存至文档" prop =" document_id" >
61+ <el-select
62+ v-model =" form.document_id"
63+ filterable
64+ placeholder =" 请选择文档"
65+ :loading =" optionLoading"
66+ >
67+ <el-option
68+ v-for =" item in documentList"
69+ :key =" item.id"
70+ :label =" item.name"
71+ :value =" item.id"
72+ >
73+ {{ item.name }}
74+ </el-option >
75+ </el-select >
5876 </el-form-item >
5977 </el-form >
6078 <template #footer >
@@ -70,7 +88,6 @@ import { ref, watch, reactive } from 'vue'
7088import { useRoute } from ' vue-router'
7189import type { FormInstance , FormRules } from ' element-plus'
7290import logApi from ' @/api/log'
73- import type { CascaderProps } from ' element-plus'
7491import useStore from ' @/stores'
7592
7693const { application, document } = useStore ()
@@ -99,15 +116,19 @@ const form = ref<any>({
99116 problem_text: ' ' ,
100117 title: ' ' ,
101118 content: ' ' ,
102- document: []
119+ dataset_id: ' ' ,
120+ document_id: ' '
103121})
104122
105123const rules = reactive <FormRules >({
106124 content: [{ required: true , message: ' 请输入内容' , trigger: ' blur' }],
107- document: [{ type: ' array' , required: true , message: ' 请选择文档' , trigger: ' change' }]
125+ dataset_id: [{ required: true , message: ' 请选择知识库' , trigger: ' change' }],
126+ document_id: [{ required: true , message: ' 请选择文档' , trigger: ' change' }]
108127})
109128
110- const datasetList = ref ([])
129+ const datasetList = ref <any []>([])
130+ const documentList = ref <any []>([])
131+ const optionLoading = ref (false )
111132
112133watch (dialogVisible , (bool ) => {
113134 if (! bool ) {
@@ -117,45 +138,40 @@ watch(dialogVisible, (bool) => {
117138 problem_text: ' ' ,
118139 title: ' ' ,
119140 content: ' ' ,
120- document: []
141+ dataset_id: ' ' ,
142+ document_id: ' '
121143 }
144+ datasetList .value = []
145+ documentList .value = []
146+ formRef .value ?.clearValidate ()
122147 }
123148})
124149
125- const LoadDocument: CascaderProps = {
126- lazy: true ,
127- value: ' id' ,
128- label: ' name' ,
129- leaf: ' dataset_id' ,
130- lazyLoad(node , resolve : any ) {
131- const { level, data } = node
132- if (data ?.id ) {
133- getDocument (data ?.id as string , resolve )
134- } else {
135- getDataset (resolve )
136- }
137- }
150+
151+ function changeDataset(id : string ) {
152+ form .value .document_id = ' '
153+ getDocument (id )
138154}
139155
140- function getDocument(id : string , resolve : any ) {
156+ function getDocument(id : string ) {
141157 document .asyncGetAllDocument (id , loading ).then ((res : any ) => {
142- datasetList .value = res .data
143- resolve (datasetList .value )
158+ documentList .value = res .data
144159 })
145160}
146161
147- function getDataset(resolve : any ) {
162+ function getDataset() {
148163 application .asyncGetApplicationDataset (id , loading ).then ((res : any ) => {
149164 datasetList .value = res .data
150- resolve (datasetList .value )
151165 })
152166}
153167
154168const open = (data : any ) => {
169+ getDataset ()
155170 form .value .chat_id = data .chat_id
156171 form .value .record_id = data .id
157172 form .value .problem_text = data .problem_text
158173 form .value .content = data .answer_text
174+ formRef .value ?.clearValidate ()
159175 dialogVisible .value = true
160176}
161177const submitForm = async (formEl : FormInstance | undefined ) => {
@@ -171,8 +187,8 @@ const submitForm = async (formEl: FormInstance | undefined) => {
171187 id ,
172188 form .value .chat_id ,
173189 form .value .record_id ,
174- form .value .document [ 0 ] ,
175- form .value .document [ 1 ] ,
190+ form .value .dataset_id ,
191+ form .value .document_id ,
176192 obj ,
177193 loading
178194 )
0 commit comments