Skip to content

Commit aa368b2

Browse files
feat: User input optimization
1 parent e4de3f4 commit aa368b2

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,4 @@ onMounted(() => {
780780
}
781781
}
782782
}
783-
.chat-pc {
784-
}
785783
</style>

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ import { useRoute } from 'vue-router'
6565
import { MsgWarning } from '@/utils/message'
6666
import { t } from '@/locales'
6767
const route = useRoute()
68+
const {
69+
params: { accessToken }
70+
} = route
6871
const props = defineProps<{
6972
application: any
7073
type: 'log' | 'ai-chat' | 'debug-ai-chat'
@@ -78,6 +81,8 @@ const inputFieldList = ref<FormField[]>([])
7881
const apiInputFieldList = ref<FormField[]>([])
7982
const inputFieldConfig = ref({ title: t('chat.userInput') })
8083
const showUserInput = ref(true)
84+
const firstMounted = ref(false)
85+
8186
const emit = defineEmits(['update:api_form_data', 'update:form_data', 'confirm', 'cancel'])
8287
8388
const api_form_data_context = computed({
@@ -100,7 +105,7 @@ const form_data_context = computed({
100105
101106
watch(
102107
() => props.application,
103-
() => {
108+
(data) => {
104109
handleInputFieldList()
105110
}
106111
)
@@ -352,15 +357,15 @@ const decodeQuery = (query: string) => {
352357
}
353358
}
354359
const confirmHandle = () => {
355-
if (checkInputParam()) {
356-
emit('confirm')
357-
}
360+
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(form_data_context.value))
361+
emit('confirm')
358362
}
359363
const cancelHandle = () => {
360364
emit('cancel')
361365
}
362366
defineExpose({ checkInputParam })
363367
onMounted(() => {
368+
firstMounted.value = true
364369
handleInputFieldList()
365370
})
366371
</script>

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,27 @@ const toggleUserInput = () => {
196196
}
197197
198198
function UserFormConfirm() {
199-
firsUserInput.value = false
200-
showUserInput.value = false
199+
if (userFormRef.value?.checkInputParam()) {
200+
firsUserInput.value = false
201+
showUserInput.value = false
202+
}
201203
}
202204
203205
function sendMessage(val: string, other_params_data?: any, chat?: chatType) {
204206
if (!userFormRef.value?.checkInputParam()) {
207+
if (isUserInput.value) {
208+
showUserInput.value = true
209+
}
205210
return
211+
} else {
212+
let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
213+
const newData = Object.keys(form_data.value).reduce((result: any, key: string) => {
214+
result[key] = Object.prototype.hasOwnProperty.call(userFormData, key)
215+
? userFormData[key]
216+
: form_data.value[key]
217+
return result
218+
}, {})
219+
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData))
206220
}
207221
if (!loading.value && props.applicationDetails?.name) {
208222
handleDebounceClick(val, other_params_data, chat)
@@ -505,6 +519,10 @@ const handleScroll = () => {
505519
}
506520
507521
onMounted(() => {
522+
if (isUserInput.value && localStorage.getItem(`${accessToken}userForm`)) {
523+
let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
524+
form_data.value = userFormData
525+
}
508526
window.speechSynthesis.cancel()
509527
window.sendMessage = sendMessage
510528
bus.on('on:transcribing', (status: boolean) => {

ui/src/views/function-lib/index.vue

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<template>
22
<div class="function-lib-list-container p-24" style="padding-top: 16px">
3-
<el-tabs v-model="functionType" @tab-change="selectUserId = ''">
3+
<el-tabs
4+
v-model="functionType"
5+
@tab-change="
6+
tabChangeHandle
7+
8+
"
9+
>
410
<el-tab-pane :label="$t('views.functionLib.title')" name="PUBLIC"></el-tab-pane>
511
<el-tab-pane :label="$t('views.functionLib.internalTitle')" name="INTERNAL"></el-tab-pane>
612
</el-tabs>
@@ -280,11 +286,6 @@ import { isAppIcon } from '@/utils/application'
280286
import InfiniteScroll from '@/components/infinite-scroll/index.vue'
281287
import CardBox from '@/components/card-box/index.vue'
282288
import AddInternalFunctionDialog from '@/views/function-lib/component/AddInternalFunctionDialog.vue'
283-
// const internalDesc: Record<string, any> = import.meta.glob('/fx/*/detail.md', {
284-
// eager: true,
285-
// as: 'raw'
286-
// })
287-
// console.log(internalDesc)
288289
289290
const { user } = useStore()
290291
@@ -331,6 +332,11 @@ watch(
331332
{ immediate: true }
332333
)
333334
335+
function tabChangeHandle() {
336+
selectUserId.value = 'all'
337+
searchValue.value = ''
338+
}
339+
334340
const canEdit = (row: any) => {
335341
return user.userInfo?.id === row?.user_id
336342
}
@@ -404,10 +410,12 @@ async function changeState(bool: Boolean, row: any) {
404410
})
405411
} else {
406412
const res = await functionLibApi.getFunctionLibById(row.id, changeStateloading)
407-
if (!res.data.init_params &&
413+
if (
414+
!res.data.init_params &&
408415
res.data.init_field_list &&
409416
res.data.init_field_list.length > 0 &&
410-
res.data.init_field_list.filter((item: any) => item.default_value).length !== res.data.init_field_list.length
417+
res.data.init_field_list.filter((item: any) => item.default_value).length !==
418+
res.data.init_field_list.length
411419
) {
412420
InitParamDrawerRef.value.open(res.data, bool)
413421
row.is_active = false

0 commit comments

Comments
 (0)