-
Notifications
You must be signed in to change notification settings - Fork 2.8k
refactor: Dialogue logic optimization #2776
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
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 |
|---|---|---|
|
|
@@ -83,6 +83,9 @@ const inputFieldConfig = ref({ title: t('chat.userInput') }) | |
| const showUserInput = ref(true) | ||
| const firstMounted = ref(false) | ||
|
|
||
| const dynamicsFormRef = ref<InstanceType<typeof DynamicsForm>>() | ||
| const dynamicsFormRef2 = ref<InstanceType<typeof DynamicsForm>>() | ||
|
|
||
| const emit = defineEmits(['update:api_form_data', 'update:form_data', 'confirm', 'cancel']) | ||
|
|
||
| const api_form_data_context = computed({ | ||
|
|
@@ -365,7 +368,18 @@ const confirmHandle = () => { | |
| const cancelHandle = () => { | ||
| emit('cancel') | ||
| } | ||
| defineExpose({ checkInputParam }) | ||
| const render = (data: any) => { | ||
| if (dynamicsFormRef.value) { | ||
| dynamicsFormRef.value?.render(inputFieldList.value, data) | ||
| } | ||
| } | ||
|
|
||
| const renderDebugAiChat = (data: any) => { | ||
| if (dynamicsFormRef2.value) { | ||
| dynamicsFormRef2.value?.render(apiInputFieldList.value, data) | ||
| } | ||
| } | ||
| defineExpose({ checkInputParam, render, renderDebugAiChat }) | ||
| onMounted(() => { | ||
| firstMounted.value = true | ||
| handleInputFieldList() | ||
|
Contributor
Author
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 appears to be part of a Vue.js component that handles dynamic form rendering based on certain conditions. There aren't significant immediate structural issues, but there are some areas for enhancement:
Here’s an improved version of the code snippet: @@ -83,6 +83,9 @@ const inputFieldConfig = ref({ title: t('chat.userInput') })
const showUserInput = ref(true)
const firstMounted = ref(false)
+const dynamicsFormRefs = ref<[InstanceType<typeof DynamicsForm>, InstanceType<typeof DynamicsForm>]>([null, null])
+
const emit = defineEmits(['update:api_form_data', 'update:form_data', 'confirm', 'cancel'])
const api_form_data_context = computed({
@@ -365,7 +368,18 @@ const confirmHandle = () => {
const cancelHandle = () => {
emit('cancel')
}
-defineExpose({ checkInputParam })
+const render = (refIndex: number, data: any) => {
+ const currentRef = dynamicsFormRefs.value[refIndex]
+ if (currentRef) {
+ currentRef.render(inputFieldList.value, data)
+ }
+}
+const renderDebugAiChat = (refIndex: number, data: any) => {
+ const currentRef = dynamicsFormRefs.value[refIndex]
+ if (currentRef) {
+ currentRef.render(apiInputFieldList.value, data)
+ }
+}
+defineExpose({ checkInputParam, render, renderDebugAiChat })
onMounted(() => {
firstMounted.value = true
// Call the helper function that processes or sets up input field lists here...
})Key Changes:
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,10 @@ | |
| :class="type" | ||
| :style="{ height: firsUserInput ? '100%' : undefined }" | ||
| > | ||
| <div v-show="showUserInputContent" :class="firsUserInput ? 'firstUserInput' : 'popperUserInput'"> | ||
| <div | ||
| v-show="showUserInputContent" | ||
| :class="firsUserInput ? 'firstUserInput' : 'popperUserInput'" | ||
| > | ||
| <UserForm | ||
| v-model:api_form_data="api_form_data" | ||
| v-model:form_data="form_data" | ||
|
|
@@ -60,9 +63,11 @@ | |
| :type="type" | ||
| :send-message="sendMessage" | ||
| :open-chat-id="openChatId" | ||
| :check-input-param="checkInputParam" | ||
| :chat-management="ChatManagement" | ||
| v-model:chat-id="chartOpenId" | ||
| v-model:loading="loading" | ||
| v-model:show-user-input="showUserInput" | ||
| v-if="type !== 'log'" | ||
| > | ||
| <template #operateBefore> | ||
|
|
@@ -210,6 +215,9 @@ function UserFormCancel() { | |
| // api_form_data.value = JSON.parse(JSON.stringify(initialApiFormData.value)) | ||
| showUserInput.value = false | ||
| } | ||
| const checkInputParam = () => { | ||
| userFormRef.value?.checkInputParam() | ||
| } | ||
|
|
||
| function sendMessage(val: string, other_params_data?: any, chat?: chatType) { | ||
| if (!userFormRef.value?.checkInputParam()) { | ||
|
Contributor
Author
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 block appears to be from a Vue.js component with a
Here’s the improved code snippet including these changes: @@ -5,7 +5,10 @@
:class="type"
:style="{ height: firsUserInput ? '100%' : undefined }"
>
- <div v-show="showUserInputContent" :class="firsUserInput ? 'firstUserInput' : 'popperUserInput'">
+ <div
+ v-show="showUserInputContent"
+ :class="firsUserInput ? 'firstUserInput' : 'popperUserInput'"
+ >
<UserForm
v-model:api_form_data="api_form_data"
v-model:form_data="form_data"
@@ -63,9 +68,11 @@ function UserFormCancel() {
// api_form_data.value = JSON.parse(JSON.stringify(initialApiFormData.value))
showUserInput.value = false
}
+const checkInputParam = () => {
+ userFormRef.value?.checkInputParam()
+}
function sendMessage(val: string, other_params_data?: any, chat?: chatType) {
if (!userFormRef.value?.checkInputParam()) {Optimization Suggestion: This improvement enhances readability and potentially fixes small runtime issues while maintaining the core intent of your original code. |
||
|
|
||
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 reviewed code appears to be defining Vue.js component options with type annotations and default values. Here's a review of the code:
Issues/Findings:
Redundant Imports: The
withDefaultsfunction from@vue/runtime-corecould be imported directly, which reduces clutter.Unused Default Props: The
appId?: stringprop is not currently used or checked anywhere in thepropsobject, so it might be removed for clarity.New Required Prop: The new prop
showUserInput?: booleanis set as optional but is used directly without initial checks; consider adding a check to ensure its value before using it.Optional Emitted Events: The use of
defineEmits(['update:chatId', 'update:loading'])means thatemit('update:showUserInput')won't cause an error if this new event isn't added to the emits array initially. It should be updated accordingly.Computed Properties: The dependency of the
chatId_contextcomputed property onavailabledoes not match the logic within it (return false), which might lead to incorrect behavior under certain conditions.Suggestions:
// const { withDefaults } = '@vue/runtime-core'; // Remove if unusedappId?: stringsince it's not utilized.showUserInputhas a defined value when needed:And update the usage accordingly in methods where you rely on
this.showUserInput.4. Ensure that all changes made after updating the emits array take effect properly by rebuilding the project if necessary.
5. Modify the
chatId_contextcomputation to correctly reflect its dependencies:Reviewing these points will help maintain cleaner and more efficient code.