@@ -4,7 +4,7 @@ import icon_expand_down_filled from '@/assets/embedded/icon_expand-down_filled.s
44import rename from ' @/assets/svg/icon_rename_outlined.svg'
55import delIcon from ' @/assets/svg/icon_delete.svg'
66import { type Chat , chatApi } from ' @/api/chat.ts'
7- import { computed , ref } from ' vue'
7+ import { computed , nextTick , reactive , ref } from ' vue'
88import dayjs from ' dayjs'
99import { getDate } from ' @/utils/utils.ts'
1010import { groupBy } from ' lodash-es'
@@ -107,39 +107,9 @@ function handleCommand(command: string | number | object, chat: Chat) {
107107 if (chat && chat .id !== undefined ) {
108108 switch (command ) {
109109 case ' rename' :
110- ElMessageBox .prompt (' Please enter new brief' , ' Rename' , {
111- confirmButtonText: ' OK' ,
112- cancelButtonText: ' Cancel' ,
113- customStyle: { ' padding-left' : ' unset' , padding: ' var(--ed-messagebox-padding-primary)' },
114- inputValue: chat .brief ,
115- inputValidator : (value : string ) => {
116- if (! value ) return false
117- if (value .trim ().length == 0 ) return false
118- return true
119- },
120- }).then (({ value }) => {
121- _loading .value = true
122- chatApi
123- .renameChat (chat .id , value )
124- .then ((res ) => {
125- ElMessage ({
126- type: ' success' ,
127- message: ' Successfully renamed chat' ,
128- })
129- emits (' chatRenamed' , { id: chat .id , brief: res })
130- })
131- .catch ((err ) => {
132- ElMessage ({
133- type: ' error' ,
134- message: err .message ,
135- })
136- console .error (err )
137- })
138- .finally (() => {
139- _loading .value = false
140- })
141- })
142-
110+ password .id = chat .id
111+ password .name = chat .brief as string
112+ dialogVisiblePassword .value = true
143113 break
144114 case ' delete' :
145115 ElMessageBox .confirm (' This action will permanently delete the chat. Continue?' , ' Warning' , {
@@ -173,6 +143,56 @@ function handleCommand(command: string | number | object, chat: Chat) {
173143 }
174144 }
175145}
146+
147+ const passwordRef = ref ()
148+ const dialogVisiblePassword = ref (false )
149+ const password = reactive ({
150+ name: ' ' ,
151+ id: 0 ,
152+ })
153+
154+ const passwordRules = {
155+ name: [
156+ {
157+ required: true ,
158+ message: t (' datasource.please_enter' ) + t (' common.empty' ) + t (' qa.conversation_title' ),
159+ trigger: ' blur' ,
160+ },
161+ ],
162+ }
163+
164+ const handleClosePassword = () => {
165+ passwordRef .value .clearValidate ()
166+ dialogVisiblePassword .value = false
167+ password .id = 0
168+ password .name = ' '
169+ }
170+ const handleConfirmPassword = () => {
171+ passwordRef .value .validate ((res : any ) => {
172+ if (res ) {
173+ chatApi
174+ .renameChat (password .id , password .name )
175+ .then ((res ) => {
176+ ElMessage ({
177+ type: ' success' ,
178+ message: t (' common.save_success' ),
179+ })
180+ emits (' chatRenamed' , { id: password .id , brief: res })
181+ handleClosePassword ()
182+ })
183+ .catch ((err ) => {
184+ ElMessage ({
185+ type: ' error' ,
186+ message: err .message ,
187+ })
188+ console .error (err )
189+ })
190+ .finally (() => {
191+ _loading .value = false
192+ })
193+ }
194+ })
195+ }
176196 </script >
177197
178198<template >
@@ -222,6 +242,41 @@ function handleCommand(command: string | number | object, chat: Chat) {
222242 </div >
223243 </div >
224244 </el-scrollbar >
245+ <el-dialog
246+ v-model =" dialogVisiblePassword"
247+ :title =" $t('qa.rename_conversation_title')"
248+ width =" 420"
249+ :before-close =" handleClosePassword"
250+ >
251+ <el-form
252+ ref =" passwordRef"
253+ :model =" password"
254+ label-width =" 180px"
255+ label-position =" top"
256+ :rules =" passwordRules"
257+ class =" form-content_error"
258+ @submit.prevent
259+ >
260+ <el-form-item prop =" name" :label =" t('qa.conversation_title')" >
261+ <el-input
262+ v-model =" password.name"
263+ maxlength =" 20"
264+ :placeholder ="
265+ $t('datasource.please_enter') + $t('common.empty') + $t('qa.conversation_title')
266+ "
267+ autocomplete =" off"
268+ />
269+ </el-form-item >
270+ </el-form >
271+ <template #footer >
272+ <div class =" dialog-footer" >
273+ <el-button secondary @click =" handleClosePassword" >{{ $t('common.cancel') }}</el-button >
274+ <el-button type =" primary" @click =" handleConfirmPassword" >
275+ {{ $t('common.save') }}
276+ </el-button >
277+ </div >
278+ </template >
279+ </el-dialog >
225280</template >
226281
227282<style scoped lang="less">
0 commit comments