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

useVbenTable 可编辑表格,使用ElCascader时,如果配置了editRules表格校验,ElCascader的面板选项就会点不动 #5541

Open
763124572 opened this issue Feb 15, 2025 · 0 comments

Comments

@763124572
Copy link

列配置:

{
      title: '品类范围',
      field: props.editable ? 'sortRange' : 'sortRangeName',
      width: 160,
      editRender: { enabled: props.editable },
      slots: props.editable
        ? {
            edit: ({ row, rowIndex }) => {
              return (
                <FormField
                  commonComponentProps={{}}
                  component="Cascader"
                  componentProps={{
                    ref: 'sortRangeRef',
                    placeholder: '请选择',
                    options: sortList.value,
                    filterable: true,
                    showAllLevels: false,
                    popperClass: 'vxe-table--ignore-clear',
                    props: {
                      value: 'categoryId',
                      label: 'categoryName',
                      children: 'children',
                      checkStrictly: true,
                    },
                    onChange(value: any) {
                      const findCategoryName = (
                        id: string,
                        list: any[],
                      ): string => {
                        for (const item of list) {
                          if (item.categoryId === id) {
                            return item.categoryName;
                          }
                          if (item.children) {
                            const found = findCategoryName(id, item.children);
                            if (found) return found;
                          }
                        }
                        return '';
                      };
                      // 获取数组的最后一个值作为实际选中值
                      const selectedId = Array.isArray(value)
                        ? value[value.length - 1]
                        : value;
                      row.sortRangeName = findCategoryName(
                        selectedId,
                        sortList.value,
                      );
                    },
                  }}
                  fieldName={`${props.prefixName}[${rowIndex}].sortRange`}
                  hideLabel={true}
                  inline={true}
                />
              );
            },
            default: ({ row }) => {
              return row.sortRangeName;
            },
          }
        : undefined,
    },

表格配置:

editRules: {
    xxxx: [{ required: true, message: '必须填写' }]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant