Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

material.componentsMap变更问题 #1857

Closed
luoxq1212 opened this issue Apr 10, 2023 · 8 comments
Closed

material.componentsMap变更问题 #1857

luoxq1212 opened this issue Apr 10, 2023 · 8 comments
Assignees

Comments

@luoxq1212
Copy link

Describe the bug (required) / 详细描述 bug(必填)

使用material.setAssets(assets)修改后,其material.componentsMap未发生变更

To Reproduce (required) / 如何复现 bug?(必填,非常重要)

在自定义的一个插件里,通过pluginContext.material.setAssets(assets) 变更了组件库的组件列表,但其material.componentsMap仍然是旧的assets组件

Expected behavior (required) / 预期行为(必填,非常重要)

A clear and concise description of what did you expect to happen. / 请清晰和精确的描述你预期的行为
希望通过pluginContext.material.setAssets(assets)变更能实现组件库物料的变更

Environments (please complete the following information) (required): / 请提供如下信息(必填)

  • AliLowCodeEngine version: [e.g. 1.0.0] / 低代码引擎版本:1.1.3
  • AliLowCodeEngineExt version: [e.g. 1.0.0] / 低代码引擎扩展包版本:1.0.5
  • Browser [e.g. chrome, safari] / 浏览器版本:chrome 最新版
  • materials / plugins / tools / 其他物料 / 插件 / 工具链版本:materials
@JackLian JackLian added the insufficient information Further information is requested / 信息不足,请补充信息 label Apr 11, 2023
@github-actions
Copy link

你好 @luoxq1212,由于缺乏必要的信息(如 bug 重现步骤、引擎版本信息 等),无法定位问题,请按照 issue bug 模板 补全信息,也可以通过阅读 引擎的 issue 说明 了解什么类型的 issue 可以获得更好、更快的支持。

@JackLian
Copy link
Collaborator

给个复现demo,或者通过官方demo提供复现步骤

@luoxq1212
Copy link
Author

luoxq1212 commented Apr 11, 2023

@JackLian 这个是一个自定义的切换物料插件Demo,material.setAssets 切换更新组件库后material.componentsMap仍然是旧的assets组件。我这里期望是material.componentsMap会更新到最新的Assets组件。

`
import { IPublicModelPluginContext } from '@alilc/lowcode-types';
import { Button } from '@alifd/next';
import { material } from '@alilc/lowcode-engine';
import { Message } from '@alifd/next';

const switchingAssets = () => {
material?.onChangeAssets(() => {
Message.success('物料切换成功');
});

material.setAssets({
packages: [
{
title: 'MCBreadcrumb',
package: 'mc-breadcrumb',
version: '1.0.0',
urls: [
'https://unpkg.com/mc-breadcrumb@1.0.0/dist/MCBreadcrumb.js',
'https://unpkg.com/mc-breadcrumb@1.0.0/dist/MCBreadcrumb.css',
],
library: 'MCBreadcrumb',
},
],
components: [
{
componentName: 'MCBreadcrumb',
title: 'MCBreadcrumb',
docUrl: '',
screenshot: '',
npm: {
package: 'mc-breadcrumb',
version: '1.0.0',
exportName: 'MCBreadcrumb',
main: 'lib/index.js',
destructuring: false,
subName: '',
},
props: [
{
name: 'prefix',
propType: 'string',
description: '样式类名的品牌前缀',
defaultValue: 'next-',
},
{
name: 'title',
propType: 'string',
description: '标题',
defaultValue: 'next-',
},
{
name: 'rtl',
propType: 'bool',
},
{
name: 'children',
propType: {
type: 'instanceOf',
value: 'node',
},
description: '面包屑子节点,需传入 Breadcrumb.Item',
},
{
name: 'maxNode',
propType: {
type: 'oneOfType',
value: [
'number',
{
type: 'oneOf',
value: ['auto'],
},
],
},
description:
'面包屑最多显示个数,超出部分会被隐藏, 设置为 auto 会自动根据父元素的宽度适配。',
defaultValue: 100,
},
{
name: 'separator',
propType: {
type: 'instanceOf',
value: 'node',
},
description: '分隔符,可以是文本或 Icon',
},
{
name: 'component',
propType: {
type: 'oneOfType',
value: ['string', 'func'],
},
description: '设置标签类型',
defaultValue: 'nav',
},
{
name: 'className',
propType: 'any',
},
{
name: 'style',
propType: 'object',
},
],
configure: {
component: {
isContainer: true,
isModel: true,
rootSelector: 'div.MCBreadcrumb',
},
},
},
],

componentList: [
  {
    title: '常用',
    icon: '',
    children: [
      {
        componentName: 'MCBreadcrumb',
        title: 'MC面包屑',
        icon: '',
        package: 'mc-breadcrumb',
        library: 'MCBreadcrumb',
        snippets: [
          {
            title: 'MC面包屑',
            screenshot:
              'https://alifd.oss-cn-hangzhou.aliyuncs.com/fusion-cool/icons/icon-light/ic_light_breadcrumb.png',
            schema: {
              componentName: 'MCBreadcrumb',
              props: {
                title: '物料中心',
                prefix: 'next-',
                maxNode: 100,
              },
            },
          },
        ],
      },
    ],
  },
],

});
};
const switchingAssetsWidgetPlugin = (ctx: IPublicModelPluginContext) => {
return {
async init() {
const { skeleton } = ctx;

  skeleton.add({
    name: 'loadAssetsSample',
    area: 'topArea',
    type: 'Widget',
    props: {
      align: 'right',
      width: 80,
    },
    content: (
      <Button onClick={switchingAssets}>
        异步加载资源
      </Button>
    ),
  });
},

};
}
switchingAssetsWidgetPlugin.pluginName = 'LoadIncrementalAssetsWidgetPlugin';
export default switchingAssetsWidgetPlugin;
`

@JackLian JackLian removed the insufficient information Further information is requested / 信息不足,请补充信息 label Apr 11, 2023
@luoxq1212
Copy link
Author

@JackLian 请问如果想要实现这个效果,目前有其他实现方案吗?

@JackLian
Copy link
Collaborator

确实也没见过有需要切换物料的场景,如果物料都换了,那单独做成俩设计器不是更简单....

@liujuping
Copy link
Collaborator

@luoxq1212 可以使用最新 beta 版本的 material.refreshComponentMetasMap API

@luoxq1212
Copy link
Author

@liujuping material.refreshComponentMetasMap API 确实是可以刷新,但AliLowCodeEngine.project.simulator.renderer.components 也还是旧的。
material.setAssets(assets) 好像只有在第一次设置时会初始化物料,后续怎么设置,AliLowCodeEngine.project.simulator.renderer.components 的值好像都不会变。

@chenlei8910
Copy link

@luoxq1212 请问有后续解决方案吗?我也需要实现类似的效果,要是无法支持的话,只能通过重刷页面,设计器重新初始化的这种方式了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants