fix(editor): make the created module's name is different

This commit is contained in:
MrWindlike 2022-01-30 15:48:12 +08:00
parent f5aa1460ba
commit 02d1a407dd

View File

@ -1,5 +1,5 @@
import { observable, makeObservable, action, toJS } from 'mobx';
import { Application, ComponentSchema, Module } from '@sunmao-ui/core';
import { Application, ComponentSchema, Module, RuntimeModule } from '@sunmao-ui/core';
import { cloneDeep } from 'lodash-es';
import { produce } from 'immer';
import { DefaultNewModule, EmptyAppSchema } from '../constants';
@ -29,7 +29,28 @@ export class AppStorage {
}
createModule() {
this.setModules([...this.modules, DefaultNewModule]);
let index = this.modules.length;
this.modules.forEach((module) => {
if (module.metadata.name === `myModule${index}`) {
index++;
}
});
const name = `myModule${index}`;
const newModule: RuntimeModule = {
...DefaultNewModule,
parsedVersion: {
...DefaultNewModule.parsedVersion,
value: name,
},
metadata: {
...DefaultNewModule.metadata,
name,
}
};
this.setModules([...this.modules, newModule]);
this.saveModules();
}