alibaba / lowcode-engine

An enterprise-class low-code technology stack with scale-out design / 一套面向扩展设计的企业级低代码技术体系
https://lowcode-engine.cn
MIT License
14.68k stars 2.55k forks source link

workspace 模式下 注册plugin ,options 参数不能传入下一步 #1922

Closed qq29800623 closed 1 year ago

qq29800623 commented 1 year ago

V1.1.6 release 版本下的 用workspace 模式注册plugin,options参数有问题 具体代码如下

await workspace.plugins.register(WindowsTabPlugin,{ pro1: '111', tabs: [ { key: 'page', name: '表单设计' }, { key: 'home', name: '流程设计' } ],
}); 用上述代码注册plugin,在plugin内部 const WindowsTabPlugin = (ctx: IPublicModelPluginContext,options:any) => { return { async init() { console.log('WindowsTabPlugin options',options); //此处获取的options 为 {} const { workspace,skeleton, hotkey, config } = ctx;

  skeleton.add({
    name: 'windowsTab',
    area: 'subTopArea',
    type: 'Widget',
    props: {
      align: 'left',
    },
    content: <WindowTab></WindowTab>,
  });

},

}; } 以上是问题现象描述。 通过查看源码,发现注册的时候,调用了以下代码,\lowcode-engine\packages\designer\src\plugin\plugin-utils.ts 文件中 export function filterValidOptions( opts: any, preferenceDeclaration: IPublicTypePluginDeclaration, ) { if (!opts || !isPlainObject(opts)) return opts; //此处不返回,继续往下走 const filteredOpts = {} as any; Object.keys(opts).forEach((key) => { if (isValidPreferenceKey(key, preferenceDeclaration)) { //校验是否为有效的key,导致返回为{} const v = opts[key]; if (v !== undefined && v !== null) { filteredOpts[key] = v; } } }); return filteredOpts; }

qq29800623 commented 1 year ago

已看懂怎么回事,需要在插件代码中加入preferenceDeclaration定义,这是为了安全吗?