Moonofweisheng / wot-design-uni

一个基于Vue3+TS开发的uni-app组件库,提供70+高质量组件,支持暗黑模式、国际化和自定义主题。
https://wot-design-uni.pages.dev
MIT License
626 stars 90 forks source link

[新功能需求] 表单可以根据schema进行自定义展示吗 #328

Open KaneOne opened 1 month ago

KaneOne commented 1 month ago

这个功能解决了什么问题?

之前一直使用vben作为PC端的前端框架,vben对表单有个很好的功能就是可以定义schema来展示表单内容,同时提供对schema的操作api,比如增加字段定义,更新字段定义等。这对由于不同分类的提交对象有细微变化的页面很有用,比如一个产品需要多提交一个是否使用优惠的字段,而不用重写一个页面。

你期望的 API 是什么样子的?

vben的schema是这样定义的:

{
  // 简单例子,值改变的时候操作表格或者修改表单内其他元素的值
  component:'Input',
  componentProps: ({ schema, tableAction, formActionType, formModel }) => {
    return {
      // xxxx props
      onChange:e=>{
        const {reload}=tableAction
        reload()
        // or
        formModel.xxx='123'
      }
    };
  };
}

包含了组件名,组件属性等,同时提供了以下对schema操作的API

removeSchemaByField

类型: (field: string | string[]) => Promise<void>

说明: 根据 field 删除 Schema

appendSchemaByField

类型: ( schema: FormSchema, prefixField: string | undefined, first?: boolean | undefined ) => Promise<void>

说明: 插入到指定 filed 后面,如果没传指定 field,则插入到最后,当 first = true 时插入到第一个位置

updateSchema

类型: (data: Partial<FormSchema> | Partial<FormSchema>[]) => Promise<void>

说明: 更新表单的 schema, 只更新函数所传的参数

以上供参考,或者有没有类似的方法可以解决表单自定义的问题,感谢。

Moonofweisheng commented 1 month ago

很好的提议,不过目前没太多精力,暂时不列入计划,不过欢迎PR。