@@ -224,33 +224,41 @@ const validate = () => {
224224 return userFormRef .value ?.validate () || Promise .reject (false )
225225}
226226
227- function sendMessage(val : string , other_params_data ? : any , chat ? : chatType ) {
227+ function sendMessage(val : string , other_params_data ? : any , chat ? : chatType ): Promise < boolean > {
228228 if (isUserInput .value ) {
229- userFormRef .value
230- ?.validate ()
231- .then ((ok ) => {
232- let userFormData = JSON .parse (localStorage .getItem (` ${accessToken }userForm ` ) || ' {}' )
233- const newData = Object .keys (form_data .value ).reduce ((result : any , key : string ) => {
234- result [key ] = Object .prototype .hasOwnProperty .call (userFormData , key )
235- ? userFormData [key ]
236- : form_data .value [key ]
237- return result
238- }, {})
239- localStorage .setItem (` ${accessToken }userForm ` , JSON .stringify (newData ))
240- showUserInput .value = false
241- if (! loading .value && props .applicationDetails ?.name ) {
242- handleDebounceClick (val , other_params_data , chat )
243- }
244- })
245- .catch ((e ) => {
246- showUserInput .value = true
247- return
248- })
229+ if (userFormRef .value ) {
230+ return userFormRef .value
231+ ?.validate ()
232+ .then ((ok ) => {
233+ let userFormData = JSON .parse (localStorage .getItem (` ${accessToken }userForm ` ) || ' {}' )
234+ const newData = Object .keys (form_data .value ).reduce ((result : any , key : string ) => {
235+ result [key ] = Object .prototype .hasOwnProperty .call (userFormData , key )
236+ ? userFormData [key ]
237+ : form_data .value [key ]
238+ return result
239+ }, {})
240+ localStorage .setItem (` ${accessToken }userForm ` , JSON .stringify (newData ))
241+ showUserInput .value = false
242+ if (! loading .value && props .applicationDetails ?.name ) {
243+ handleDebounceClick (val , other_params_data , chat )
244+ return true
245+ }
246+ throw ' err: no send'
247+ })
248+ .catch ((e ) => {
249+ showUserInput .value = true
250+ return false
251+ })
252+ } else {
253+ return Promise .reject (false )
254+ }
249255 } else {
250256 showUserInput .value = false
251257 if (! loading .value && props .applicationDetails ?.name ) {
252258 handleDebounceClick (val , other_params_data , chat )
259+ return Promise .resolve (true )
253260 }
261+ return Promise .reject (false )
254262 }
255263}
256264
0 commit comments