Skip to content

componentProps -》 formContext.formModel的问题

  1. componentProps 人事pc端可抽出外面,但taro不能
  2. values: { ...formContext.formModel } 人事pc端能这样写,但taro 不能 需求:为什么要克隆,克隆能防止外部修改表单的值。 场景:比如input输入,更新会晚一步得到值,比如输入两次2(22),但得到2,延迟了,未解决
ts
const comAttrs = computed(() => {
      // componentProps抽取required是否表单必填
      let { componentProps } = props.schema
      // // 组件的属性是否为外部回调函数
      if (isFunction(componentProps)) {
        componentProps = componentProps({
          schema: props.schema,
          // values: { ...formContext.formModel }, // todo:更新会晚一步得到值,比如输入22,但得到2,克隆能防止外部修改表单的值,待解决
          values: formContext.formModel,
          field: props.schema.field,
          actions: formContext,
          index: props.multipleIndex,
          parentField: props.parentSchemaField,
        })
      }


      const attrs = { // 核心
        placeholder: createDefaultMsg(props.schema),
        ...componentProps,
        textAlign: textAlign(props.schema.textAlign)
      } as any

      // 数组处理
      if (props.parentSchemaField) {
        attrs.modelValue = formContext.formModel[props.parentSchemaField][props.multipleIndex][props.schema.field!]
        attrs['onUpdate:modelValue'] = value => handleUpdateValue(value, props.multipleIndex, props.parentSchemaField)
      } else {
        attrs.modelValue = formContext.formModel[props.schema.field!]
        attrs['onUpdate:modelValue'] = handleUpdateValue
      }
      if (unref(isInputComponent)) {
        // 让小程序在键盘弹起时自动调整页面内容的位置
        attrs.adjustPosition = true
        attrs.cursorSpacing = 50
        attrs.inputAlign = textAlign(props.schema.textAlign)
        attrs.onBlur = () => formItemValidate()
      }


      return attrs
    })
  1. Api-picker

    想得不够完全

    容器使用overflow-y:auto,导致里面内容是过长,使用absolute定位,只是定位在过长内容头部,还是能滚动。

Lucking