-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Form collection single line tab supports variables #3942
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 |
|---|---|---|
| @@ -1,8 +1,52 @@ | ||
| <template> | ||
| <el-form-item v-if="getModel"> | ||
| <template #label> | ||
| <div class="flex-between"> | ||
| {{ $t('dynamicsForm.AssignmentMethod.label', '赋值方式') }} | ||
| </div> | ||
| </template> | ||
|
|
||
| <el-row style="width: 100%" :gutter="10"> | ||
| <el-radio-group v-model="formValue.default_value_assignment_method"> | ||
| <el-radio :value="item.value" size="large" v-for="item in assignment_method_option_list" | ||
| >{{ item.label }} | ||
| <el-popover | ||
| width="300px" | ||
| v-if="item.value == 'ref_variables'" | ||
| class="box-item" | ||
| placement="top-start" | ||
| > | ||
| {{ $t('dynamicsForm.AssignmentMethod.ref_variables.popover') }}: | ||
| {{ $t('dynamicsForm.AssignmentMethod.ref_variables.json_format') }} | ||
|
|
||
| <template #reference> | ||
| <el-icon><InfoFilled /></el-icon> | ||
| </template> | ||
| </el-popover> | ||
| </el-radio> | ||
| </el-radio-group> | ||
| </el-row> | ||
| </el-form-item> | ||
| <el-form-item | ||
| v-if="formValue.default_value_assignment_method == 'ref_variables'" | ||
| :required="true" | ||
| prop="default_value" | ||
| :rules="[default_ref_variables_value_rule]" | ||
| > | ||
| <NodeCascader | ||
| ref="nodeCascaderRef" | ||
| :nodeModel="model" | ||
| class="w-full" | ||
| :placeholder="$t('views.applicationWorkflow.variable.placeholder')" | ||
| v-model="formValue.default_value" | ||
| /> | ||
| </el-form-item> | ||
|
|
||
| <el-form-item | ||
| class="defaultValueItem" | ||
| :label="$t('dynamicsForm.default.label')" | ||
| :required="formValue.required" | ||
| v-if="formValue.default_value_assignment_method == 'custom'" | ||
| prop="default_value" | ||
| :rules="[default_value_rule]" | ||
| > | ||
|
|
@@ -16,19 +60,46 @@ | |
| </el-form-item> | ||
| </template> | ||
| <script setup lang="ts"> | ||
| import { computed, onMounted, ref } from 'vue' | ||
| import { computed, onMounted, ref, inject, watch } from 'vue' | ||
| import { t } from '@/locales' | ||
| import NodeCascader from '@/workflow/common/NodeCascader.vue' | ||
| import JsonInput from '@/components/dynamics-form/items/JsonInput.vue' | ||
| const props = defineProps<{ | ||
| modelValue: any | ||
| }>() | ||
| const getModel = inject('getModel') as any | ||
|
|
||
| const assignment_method_option_list = computed(() => { | ||
| const option_list = [ | ||
| { | ||
| label: t('dynamicsForm.AssignmentMethod.custom.label', '自定义'), | ||
| value: 'custom', | ||
| }, | ||
| ] | ||
| if (getModel) { | ||
| option_list.push({ | ||
| label: t('dynamicsForm.AssignmentMethod.ref_variables.label', '引用变量'), | ||
| value: 'ref_variables', | ||
| }) | ||
| } | ||
| return option_list | ||
| }) | ||
|
|
||
| const model = computed(() => { | ||
| if (getModel) { | ||
| return getModel() | ||
| } else { | ||
| return null | ||
| } | ||
| }) | ||
| const emit = defineEmits(['update:modelValue']) | ||
| const formValue = computed({ | ||
| set: (item) => { | ||
| emit('update:modelValue', item) | ||
| }, | ||
| get: () => { | ||
| return props.modelValue | ||
| } | ||
| }, | ||
| }) | ||
| const jsonInputRef = ref<InstanceType<typeof JsonInput>>() | ||
| const getData = () => { | ||
|
|
@@ -41,14 +112,15 @@ const getData = () => { | |
| required: formValue.value.required, | ||
| validator: `validator = (rule, value, callback) => { | ||
| return componentFormRef.value?.validate_rules(rule, value, callback); | ||
|
|
||
| }`, | ||
| trigger: 'blur' | ||
| } | ||
| ] | ||
| trigger: 'blur', | ||
| }, | ||
| ], | ||
| }, | ||
| default_value: formValue.value.default_value, | ||
| show_default_value: formValue.value.show_default_value | ||
| show_default_value: formValue.value.show_default_value, | ||
| default_value_assignment_method: formValue.value.default_value_assignment_method || 'custom', | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -58,15 +130,31 @@ const default_value_rule = { | |
| jsonInputRef.value?.validate_rules(rule, value, callback) | ||
| return true | ||
| }, | ||
| trigger: 'blur' | ||
| trigger: 'blur', | ||
| } | ||
| const default_ref_variables_value_rule = { | ||
| required: true, | ||
| validator: (rule: any, value: any, callback: any) => { | ||
| if (!(Array.isArray(value) && value.length > 1)) { | ||
| callback( | ||
| t('dynamicsForm.AssignmentMethod.ref_variables.label', '引用变量') + t('common.required'), | ||
| ) | ||
| } | ||
|
|
||
| return true | ||
| }, | ||
| trigger: 'blur', | ||
| } | ||
|
|
||
| const rander = (form_data: any) => { | ||
| formValue.value.default_value = form_data.default_value | ||
| formValue.value.default_value_assignment_method = | ||
| form_data.default_value_assignment_method || 'custom' | ||
| } | ||
| defineExpose({ getData, rander }) | ||
| onMounted(() => { | ||
| formValue.value.default_value = {} | ||
| formValue.value.default_value_assignment_method = 'custom' | ||
| if (formValue.value.show_default_value === undefined) { | ||
| formValue.value.show_default_value = true | ||
| } | ||
|
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 seems clean and well-structured. However, there are a few points of consideration:
Overall, the current implementation is good but could be improved by considering these guidelines for better future development adaptability and maintainability. |
||
|
|
||
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.
Code Review
Function
get_default_optionisinstance) instead of relying on method existence to ensure robustness when handling different input types.IndexError,ValueError).Function
write_contextFunction
generate_promptClass
BaseFormNodeField Reset with Prompt Generation:
reset_fieldmethod, especially if you want prompt generation only for certain fields (like label), make sure the condition checks these conditions properly. Also, handle cases where_valuemight not be a dictionary before attempting to access keys like'label'.Handling JSON Input Default Value Assignment Method:
json_input_default_value_assignment_methodis handled consistently regardless of its casing (upper vs. lower). Adjust the comparison accordingly.Optimization Recommendations
workflow_manage.get_reference_fieldcan return values that are not lists (perhaps due to incorrect logic or external dependencies), consider adding additional checks within theifstatement to prevent runtime errors.Here’s how you might improve those points:
These improvements address many of the identified potential issues, making your code more robust and maintainable. Always test thoroughly after changes to ensure no unintended behaviors arise.