antvis / G6VP

G6VP is an online visual analysis tool for graphs and a low-code platform for building graph applications.
https://insight.antv.antgroup.com
Apache License 2.0
797 stars 109 forks source link

perf(GISDK): SDK 支持传入额外的 props #591

Closed echoOikawa closed 1 month ago

echoOikawa commented 1 month ago

🎨 Enhance

📝 Description

支持 GISDK 传入额外的 props 额外props 格式约定为:

interface GISDKProps {
 / ** 全局额外参数 */
  GISDKExtraParams?: Record<string, any>;
  /** 资产额外参数,以资产ID为 key, value 为传入对应资产的 props */
  componentExtraParams?: Record<string, any>;
}

比如:

const GISDKExtraParams = {
     GI_AKG_AGENT_CONTEXT: {
         id: 7,
         agentCode: 'e690b81f43'
      }
};

const componentExtraParams = {
// 传给 ToolBar 组件的 props
    Toolbar: {
      test: 123,
      test2: 'abc'
    }
}

使用在对应的资产中进行读取:

 const context = useContext();
 const { direction, components, assets, placement, offset, ...extraProps ...extraProps } = props;

  console.log({
   // 从 context 中读取存入全局的 extraParams
    contextExtraProps: context.extraParams,
   // 读取传给对应资产的 额外 props
    componentExtraProps: extraProps
  });

验证 image

🔍 Self-Check before the merge