Skip to content

Commit 3c3bd98

Browse files
Merge branch 'main' of https://github.com/maxkb-dev/maxkb
2 parents f188383 + 0213aff commit 3c3bd98

File tree

6 files changed

+85
-65
lines changed

6 files changed

+85
-65
lines changed

ui/src/components/ai-chat/component/chat-input-operate/index.vue

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ const props = withDefaults(
271271
showUserInput?: boolean
272272
sendMessage: (question: string, other_params_data?: any, chat?: chatType) => void
273273
openChatId: () => Promise<string>
274-
checkInputParam: () => boolean
274+
validate: () => Promise<any>
275275
}>(),
276276
{
277277
applicationDetails: () => ({}),
@@ -649,24 +649,27 @@ const stopTimer = () => {
649649
}
650650
651651
function autoSendMessage() {
652-
props.sendMessage(inputValue.value, {
653-
image_list: uploadImageList.value,
654-
document_list: uploadDocumentList.value,
655-
audio_list: uploadAudioList.value,
656-
video_list: uploadVideoList.value
657-
})
658-
if (!props.checkInputParam()) {
659-
return
660-
} else {
661-
inputValue.value = ''
662-
uploadImageList.value = []
663-
uploadDocumentList.value = []
664-
uploadAudioList.value = []
665-
uploadVideoList.value = []
666-
if (quickInputRef.value) {
667-
quickInputRef.value.textareaStyle.height = '45px'
668-
}
669-
}
652+
props
653+
.validate()
654+
.then(() => {
655+
props.sendMessage(inputValue.value, {
656+
image_list: uploadImageList.value,
657+
document_list: uploadDocumentList.value,
658+
audio_list: uploadAudioList.value,
659+
video_list: uploadVideoList.value
660+
})
661+
inputValue.value = ''
662+
uploadImageList.value = []
663+
uploadDocumentList.value = []
664+
uploadAudioList.value = []
665+
uploadVideoList.value = []
666+
if (quickInputRef.value) {
667+
quickInputRef.value.textareaStyle.height = '45px'
668+
}
669+
})
670+
.catch(() => {
671+
emit('update:showUserInput', true)
672+
})
670673
}
671674
672675
function sendChatHandle(event?: any) {

ui/src/components/ai-chat/component/user-form/index.vue

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -308,38 +308,34 @@ const getRouteQueryValue = (field: string) => {
308308
}
309309
return null
310310
}
311-
/**
312-
* 校验参数
313-
*/
314-
const checkInputParam = () => {
315-
// 检查inputFieldList是否有未填写的字段
316-
for (let i = 0; i < inputFieldList.value.length; i++) {
317-
if (
318-
inputFieldList.value[i].required &&
319-
(form_data_context.value[inputFieldList.value[i].field] === null ||
320-
form_data_context.value[inputFieldList.value[i].field] === undefined ||
321-
form_data_context.value[inputFieldList.value[i].field] === '')
322-
) {
323-
MsgWarning(t('chat.tip.requiredMessage'))
324-
return false
325-
}
311+
const validate = () => {
312+
const promise_list = []
313+
if (dynamicsFormRef.value) {
314+
promise_list.push(dynamicsFormRef.value?.validate())
326315
}
316+
if (dynamicsFormRef2.value) {
317+
promise_list.push(dynamicsFormRef2.value?.validate())
318+
}
319+
promise_list.push(validate_query())
320+
return Promise.all(promise_list)
321+
}
322+
const validate_query = () => {
327323
// 浏览器query参数找到接口传参
328324
let msg = []
329325
for (let f of apiInputFieldList.value) {
330326
if (f.required && !api_form_data_context.value[f.field]) {
331327
msg.push(f.field)
332328
}
333329
}
334-
335330
if (msg.length > 0) {
336331
MsgWarning(
337332
`${t('chat.tip.inputParamMessage1')} ${msg.join('')}${t('chat.tip.inputParamMessage2')}`
338333
)
339-
return false
334+
return Promise.reject(false)
340335
}
341-
return true
336+
return Promise.resolve(false)
342337
}
338+
343339
const initRouteQueryValue = () => {
344340
for (let f of apiInputFieldList.value) {
345341
if (!api_form_data_context.value[f.field]) {
@@ -356,6 +352,7 @@ const initRouteQueryValue = () => {
356352
}
357353
}
358354
}
355+
359356
const decodeQuery = (query: string) => {
360357
try {
361358
return decodeURIComponent(query)
@@ -364,10 +361,10 @@ const decodeQuery = (query: string) => {
364361
}
365362
}
366363
const confirmHandle = () => {
367-
if (checkInputParam()) {
364+
validate().then((ok) => {
368365
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(form_data_context.value))
369366
emit('confirm')
370-
}
367+
})
371368
}
372369
const cancelHandle = () => {
373370
emit('cancel')
@@ -383,7 +380,7 @@ const renderDebugAiChat = (data: any) => {
383380
dynamicsFormRef2.value?.render(apiInputFieldList.value, data)
384381
}
385382
}
386-
defineExpose({ checkInputParam, render, renderDebugAiChat })
383+
defineExpose({ validate, render, renderDebugAiChat })
387384
onMounted(() => {
388385
firstMounted.value = true
389386
handleInputFieldList()

ui/src/components/ai-chat/index.vue

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
:type="type"
6464
:send-message="sendMessage"
6565
:open-chat-id="openChatId"
66-
:check-input-param="checkInputParam"
66+
:validate="validate"
6767
:chat-management="ChatManagement"
6868
v-model:chat-id="chartOpenId"
6969
v-model:loading="loading"
@@ -216,30 +216,39 @@ function UserFormCancel() {
216216
userFormRef.value?.render(form_data.value)
217217
showUserInput.value = false
218218
}
219-
const checkInputParam = () => {
220-
return userFormRef.value?.checkInputParam() || false
219+
220+
const validate = () => {
221+
return userFormRef.value?.validate() || Promise.reject(false)
221222
}
222223
223224
function sendMessage(val: string, other_params_data?: any, chat?: chatType) {
224225
if (isUserInput.value) {
225-
if (!userFormRef.value?.checkInputParam()) {
226-
showUserInput.value = true
227-
return
228-
} else {
229-
let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
230-
const newData = Object.keys(form_data.value).reduce((result: any, key: string) => {
231-
result[key] = Object.prototype.hasOwnProperty.call(userFormData, key)
232-
? userFormData[key]
233-
: form_data.value[key]
234-
return result
235-
}, {})
236-
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData))
237-
showUserInput.value = false
226+
userFormRef.value
227+
?.validate()
228+
.then((ok) => {
229+
let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
230+
const newData = Object.keys(form_data.value).reduce((result: any, key: string) => {
231+
result[key] = Object.prototype.hasOwnProperty.call(userFormData, key)
232+
? userFormData[key]
233+
: form_data.value[key]
234+
return result
235+
}, {})
236+
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData))
237+
showUserInput.value = false
238+
if (!loading.value && props.applicationDetails?.name) {
239+
handleDebounceClick(val, other_params_data, chat)
240+
}
241+
})
242+
.catch((e) => {
243+
showUserInput.value = true
244+
return
245+
})
246+
} else {
247+
showUserInput.value = false
248+
if (!loading.value && props.applicationDetails?.name) {
249+
handleDebounceClick(val, other_params_data, chat)
238250
}
239251
}
240-
if (!loading.value && props.applicationDetails?.name) {
241-
handleDebounceClick(val, other_params_data, chat)
242-
}
243252
}
244253
245254
const handleDebounceClick = debounce((val, other_params_data?: any, chat?: chatType) => {
@@ -268,7 +277,6 @@ const openChatId: () => Promise<string> = () => {
268277
})
269278
} else {
270279
if (isWorkFlow(obj.type)) {
271-
console.log(obj)
272280
const submitObj = {
273281
work_flow: obj.work_flow,
274282
user_id: obj.user

ui/src/stores/modules/application.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ const useApplicationStore = defineStore({
9797
applicationApi
9898
.postAppAuthentication(token, loading, authentication_value)
9999
.then((res) => {
100-
localStorage.setItem(`${token}accessToken`, res.data)
101-
sessionStorage.setItem(`${token}accessToken`, res.data)
100+
localStorage.setItem(`${token}-accessToken`, res.data)
101+
sessionStorage.setItem(`${token}-accessToken`, res.data)
102102
resolve(res)
103103
})
104104
.catch((error) => {

ui/src/stores/modules/user.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@ const useUserStore = defineStore({
6161
return this.userType === 1 ? localStorage.getItem('token') : this.getAccessToken()
6262
},
6363
getAccessToken() {
64-
const token = sessionStorage.getItem(`${this.userAccessToken}accessToken`)
64+
const token = sessionStorage.getItem(`${this.userAccessToken}-accessToken`)
6565
if (token) {
6666
return token
6767
}
68-
return localStorage.getItem(`${this.userAccessToken}accessToken`)
68+
const local_token = localStorage.getItem(`${token}-accessToken`)
69+
if (local_token) {
70+
return local_token
71+
}
72+
return localStorage.getItem(`accessToken`)
6973
},
7074

7175
getPermissions() {

ui/src/views/login/index.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ interface qrOption {
153153
154154
const orgOptions = ref<qrOption[]>([])
155155
156+
function uuidv4() {
157+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
158+
const r = (Math.random() * 16) | 0
159+
const v = c === 'x' ? r : (r & 0x3) | 0x8
160+
return v.toString(16)
161+
})
162+
}
163+
156164
function redirectAuth(authType: string) {
157165
if (authType === 'LDAP' || authType === '') {
158166
return
@@ -191,7 +199,7 @@ function redirectAuth(authType: string) {
191199
if (authType === 'OAuth2') {
192200
url =
193201
`${config.authEndpoint}?client_id=${config.clientId}&response_type=code` +
194-
`&redirect_uri=${redirectUrl}&state=${res.data.id}`
202+
`&redirect_uri=${redirectUrl}&state=${uuidv4()}`
195203
if (config.scope) {
196204
url += `&scope=${config.scope}`
197205
}

0 commit comments

Comments
 (0)