Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

rangepicker 添加defaultValue: [] 数组 会出现报错 #6407

Closed
benben120 opened this issue Mar 12, 2024 · 4 comments
Closed

rangepicker 添加defaultValue: [] 数组 会出现报错 #6407

benben120 opened this issue Mar 12, 2024 · 4 comments

Comments

@benben120
Copy link

版本号:

3.6.3

问题描述:

rangepicker 添加defaultValue: [] 数组 会出现报错

截图&代码:

BE)`YNX_SAG8S3BXZ81YKUN

IUMQ4IKU~QA%Y04 D1EZJ92

LFPWCNN06@37%EQFQ75W$A0

友情提示(为了提高issue处理效率):

  • 未按格式要求发帖,会被直接删掉;
  • 请自己初判问题描述是否清楚,是否方便我们调查处理;
  • 描述过于简单或模糊,导致无法处理的,会被直接删掉;
@benben120
Copy link
Author

defaultValue 只要是数组 就会出现这个报错 空数组也会 空字符串不会报错 或者不添加defaultValue 也不会报错

@benben120
Copy link
Author

注释schema.defaultValue = def;该段逻辑也能赋值默认值 不会触发报错 暂时性解决 希望官方有个解决方案
image

@zhangdaiscott
Copy link
Member

zy

@liaozhiyang
Copy link

已修复,下一版本发布。(以此版本为主)

在 src/components/Form/src/BasicForm.vue 文件
你本地可按如下替换 getSchema 函数。

const getSchema = computed((): FormSchema[] => {
        const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any);
        for (const schema of schemas) {
          const { defaultValue, component, componentProps } = schema;
          // handle date type
          if (defaultValue && dateItemType.includes(component)) {
            //update-begin---author:wangshuai ---date:20230410  for:【issues/435】代码生成的日期控件赋默认值报错------------
            let valueFormat:string = "";
            if(componentProps){
              valueFormat = componentProps?.valueFormat;
            }
            if(!valueFormat){
              console.warn("未配置valueFormat,可能导致格式化错误!");
            }
            //update-end---author:wangshuai ---date:20230410  for:【issues/435】代码生成的日期控件赋默认值报错------------
            if (!Array.isArray(defaultValue)) {
              //update-begin---author:wangshuai ---date:20221124  for:[issues/215]列表页查询框(日期选择框)设置初始时间,一进入页面时,后台报日期转换类型错误的------------
              if(valueFormat){
                schema.defaultValue = dateUtil(defaultValue).format(valueFormat);
              }else{
                schema.defaultValue = dateUtil(defaultValue);
              }
              //update-end---author:wangshuai ---date:20221124  for:[issues/215]列表页查询框(日期选择框)设置初始时间,一进入页面时,后台报日期转换类型错误的------------
            } else {
              const def: dayjs.Dayjs[] = [];
              defaultValue.forEach((item) => {
                //update-begin---author:wangshuai ---date:20221124  for:[issues/215]列表页查询框(日期选择框)设置初始时间,一进入页面时,后台报日期转换类型错误的------------
                if(valueFormat){
                  def.push(dateUtil(item).format(valueFormat));
                }else{
                  def.push(dateUtil(item));
                }
                //update-end---author:wangshuai ---date:20221124  for:[issues/215]列表页查询框(日期选择框)设置初始时间,一进入页面时,后台报日期转换类型错误的------------
              });
              // update-begin--author:liaozhiyang---date:20240328---for:【issues/1114】rangepicker等时间控件报错(vue3.4以上版本有问题)
              def.forEach((item, index) => {
                defaultValue[index] = item;
              });
              // update-end--author:liaozhiyang---date:20240328---for:【issues/1114】rangepicker等时间控件报错(vue3.4以上版本有问题)
            }
          }
        }
        if (unref(getProps).showAdvancedButton) {
          return schemas.filter((schema) => schema.component !== 'Divider') as FormSchema[];
        } else {
          return schemas as FormSchema[];
        }
      });
image

@zhangdaiscott zhangdaiscott transferred this issue from jeecgboot/JeecgBoot-vue3 Jun 21, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants