-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Pr@main/user input #2706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pr@main/user input #2706
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -780,6 +780,4 @@ onMounted(() => { | |
| } | ||
| } | ||
| } | ||
| .chat-pc { | ||
| } | ||
| </style> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,13 +196,27 @@ const toggleUserInput = () => { | |
| } | ||
|
|
||
| function UserFormConfirm() { | ||
| firsUserInput.value = false | ||
| showUserInput.value = false | ||
| if (userFormRef.value?.checkInputParam()) { | ||
| firsUserInput.value = false | ||
| showUserInput.value = false | ||
| } | ||
| } | ||
|
|
||
| function sendMessage(val: string, other_params_data?: any, chat?: chatType) { | ||
| if (!userFormRef.value?.checkInputParam()) { | ||
| if (isUserInput.value) { | ||
| showUserInput.value = true | ||
| } | ||
| return | ||
| } else { | ||
| let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}') | ||
| const newData = Object.keys(form_data.value).reduce((result: any, key: string) => { | ||
| result[key] = Object.prototype.hasOwnProperty.call(userFormData, key) | ||
| ? userFormData[key] | ||
| : form_data.value[key] | ||
| return result | ||
| }, {}) | ||
| localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData)) | ||
| } | ||
| if (!loading.value && props.applicationDetails?.name) { | ||
| handleDebounceClick(val, other_params_data, chat) | ||
|
|
@@ -505,6 +519,10 @@ const handleScroll = () => { | |
| } | ||
|
|
||
| onMounted(() => { | ||
| if (isUserInput.value && localStorage.getItem(`${accessToken}userForm`)) { | ||
| let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}') | ||
| form_data.value = userFormData | ||
| } | ||
| window.speechSynthesis.cancel() | ||
| window.sendMessage = sendMessage | ||
| bus.on('on:transcribing', (status: boolean) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a few potential areas of improvement and corrections in the given code:
Here’s an updated version of the relevant parts of the code with some improvements: function toggleUserInput() {
if (userFormRef.value?.checkInputParam()) {
firsUserInput.value ??= false;
showUserInput.value ??= false;
}
}
function sendMessage(val: string, other_params_data?: any, chat?: chatType) {
const shouldProcessInput = !!userFormRef.value?.checkInputParam();
// Show input if needed after processing
if (!shouldProcessInput && isUserInput.value) {
showUserInput.value = true;
}
if (!loading.value && props.applicationDetails?.name) {
if (shouldProcessInput) {
let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}') ?? {};
const newData = Object.fromEntries(
Object.entries<Object>(form_data.value).filter(([key]) =>
Object.prototype.hasOwnProperty.call(userFormData, key)
)
);
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData));
}
handleDebounceClick(val, other_params_data, chat);
}
}
These changes aim to improve the robustness and readability of the代码 while maintaining its functionality. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,12 @@ | ||
| <template> | ||
| <div class="function-lib-list-container p-24" style="padding-top: 16px"> | ||
| <el-tabs v-model="functionType" @tab-change="selectUserId = ''"> | ||
| <el-tabs | ||
| v-model="functionType" | ||
| @tab-change=" | ||
| tabChangeHandle | ||
|
|
||
| " | ||
| > | ||
| <el-tab-pane :label="$t('views.functionLib.title')" name="PUBLIC"></el-tab-pane> | ||
| <el-tab-pane :label="$t('views.functionLib.internalTitle')" name="INTERNAL"></el-tab-pane> | ||
| </el-tabs> | ||
|
|
@@ -280,11 +286,6 @@ import { isAppIcon } from '@/utils/application' | |
| import InfiniteScroll from '@/components/infinite-scroll/index.vue' | ||
| import CardBox from '@/components/card-box/index.vue' | ||
| import AddInternalFunctionDialog from '@/views/function-lib/component/AddInternalFunctionDialog.vue' | ||
| // const internalDesc: Record<string, any> = import.meta.glob('/fx/*/detail.md', { | ||
| // eager: true, | ||
| // as: 'raw' | ||
| // }) | ||
| // console.log(internalDesc) | ||
|
|
||
| const { user } = useStore() | ||
|
|
||
|
|
@@ -331,6 +332,11 @@ watch( | |
| { immediate: true } | ||
| ) | ||
|
|
||
| function tabChangeHandle() { | ||
| selectUserId.value = 'all' | ||
| searchValue.value = '' | ||
| } | ||
|
|
||
| const canEdit = (row: any) => { | ||
| return user.userInfo?.id === row?.user_id | ||
| } | ||
|
|
@@ -404,10 +410,12 @@ async function changeState(bool: Boolean, row: any) { | |
| }) | ||
| } else { | ||
| const res = await functionLibApi.getFunctionLibById(row.id, changeStateloading) | ||
| if (!res.data.init_params && | ||
| if ( | ||
| !res.data.init_params && | ||
| res.data.init_field_list && | ||
| res.data.init_field_list.length > 0 && | ||
| res.data.init_field_list.filter((item: any) => item.default_value).length !== res.data.init_field_list.length | ||
| res.data.init_field_list.filter((item: any) => item.default_value).length !== | ||
| res.data.init_field_list.length | ||
| ) { | ||
| InitParamDrawerRef.value.open(res.data, bool) | ||
| row.is_active = false | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code has several issues and optimizations that can be addressed:
Here's the optimized version of the key segments affected by these issues: <template>
<!-- Template remains unchanged -->
</template>
<script setup lang='ts'>
import { ref, watch } from 'vue';
import type { Ref } from 'vue';
const functionName = ref('');
const selectUserId: Ref<string> = ref('') as Ref<string>;
const searchValue: Ref<string> = ref('');
// No need for const internalDesc
const { user } = useStore();
watch(
() => selectUserId.value,
newVal => {
if (newVal !== 'all') {
searchValue.value = ''; // Reset searchValue on userId change
}
},
{ immediate: true }
);
async function tabChangeHandle() {
selectUserId.value = 'all'; // Always set selectUserId to 'all' when changing tabs
searchValue.value = '';
}
// Rest of the script...Optimized Code Summary:
These optimizations should improve both performance and usability. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code is generally well-written with proper imports, data declarations, watcher functions, and event emitters. However, there are a few minor improvements and optimizations that can be made:
Avoid using
useReffor strings: Sinceparams.accessTokenwill always return a string, you don't need to wrap it inref. Use let or const directly.Simplify
watch, handle default values properly forshowUderInput.Remove redundant check in
handleConfirmHandle:If
checkInputParam()already checks if the user has filled out the necessary fields and emits an error message if not, this can be removed since the logic might have been intended to prevent confirm action in such cases, but removing it doesn't alter the functionality significantly unless needed otherwise.By making these small adjustments, you could make the code cleaner and slightly more efficient. Keep up the good practices!