Skip to content
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

fix: 修复单选框多选框 选择器未使用label作为选项 #1719

Merged
merged 1 commit into from
Nov 30, 2024

Conversation

shaohuzhang1
Copy link
Contributor

fix: 修复单选框多选框 选择器未使用label作为选项

Copy link

f2c-ci-robot bot commented Nov 30, 2024

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

f2c-ci-robot bot commented Nov 30, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

}
)
form_data.value.form_field_list = _value
sync_form_field_list()
}
const addFormField = (form_field_data: any) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该部分有轻微逻辑问题:

  1. useSync 方法名称应更改为 sync_form_field_list
  2. 处理新增字段的操作可以合并为以下代码:
// 在这里添加 new field data 到数组里,并通过 sync 函数同步到表单结构中

export function syncFieldLists(fieldTypeList: Array<any>, formData: any) {
  // 先将新的字段列表复制一份以防止原数据被修改影响到新数据 
  const newFieldTypeList = cloneSpreadDeep(formData.form_field_list);
  
  for (let i = 0; i < fieldTypeList.length; i++) {
    const itemToAdd = fieldTypeList[i];
    
    // 同步已存在的字段到新创建的字段对象上,但需要确保不会替换掉原来的值
    try {
      newFieldTypeList.find((f: any) => f.fieldValue === itemToAdd.addValue)
      .setFieldValue(itemToAdd.getValue())
    } catch(e: any) {

注意:这段代码中的处理方法没有考虑到类型匹配的情况。如果在传递给 addFormField 的参数和之前已经有的属性冲突,则可能不会正确处理。

其他地方整体来看语法无误。

textField: 'label',
valueField: 'value',
text_field: 'label',
value_field: 'value',
option_list: formValue.value.option_list
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该段代码没有明显问题,逻辑清晰且语法正确。

textField: 'label',
valueField: 'value',
text_field: 'label',
value_field: 'value',
option_list: formValue.value.option_list
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该段代码没有明显的差错或优化机会,只是简单的 HTML + Vue 实现了一个单选框表单组件,它包含一个 select 和两个输入字段 textFieldvalueField 。Vue 的 data 属性和方法也已正确设置。

在这个版本中:

  1. 标签选择 (input-type为singleselect),默认绑定到 "label" 字段,并可将值指定为"value".
  2. 使用 options 列出不同的选项。

尽管如此,如果你希望使用更现代的元素,请尝试移除 <el-form> 元素以及替换相应的数据属性。这可能包括将其更改为更具表现力的方式(例如通过 React 进行封装):

// 导入必要的库
import { ElForm } from 'element-plus';

const FormElementProps = {
  inputType: 'SingleSelect',
  defaultValues: null,
};

class SingleSelect extends HTMLElement {
  constructor() {
    super();
    // 在这里添加额外的信息和逻辑处理
  }

  connectedCallback(event) {
    this.$parent.addEventListeners(this);
  }

  handleInputChange = event => {
    console.log("Input changed:", event.detail.value); // 示例:在控制台打印获取的用户输入值
  };
}

请注意,在实际项目中可能需要对上述部分进行适当的修改以适应具体的业务需求。

@shaohuzhang1 shaohuzhang1 merged commit 46c3725 into main Nov 30, 2024
4 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_form_node_select branch November 30, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants