mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 11:20:11 +00:00
feat: add setConfig method for project
This commit is contained in:
parent
298ab0f62f
commit
3d51fe00bf
@ -252,6 +252,35 @@ setI18n(value: object): void;
|
|||||||
|
|
||||||
**@since v1.0.17**
|
**@since v1.0.17**
|
||||||
|
|
||||||
|
### setConfig
|
||||||
|
设置当前项目配置
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
/**
|
||||||
|
* 设置当前项目配置
|
||||||
|
* set config for this project
|
||||||
|
* @param value object
|
||||||
|
* @since v1.1.4
|
||||||
|
*/
|
||||||
|
setConfig(value: IPublicTypeAppConfig): void;
|
||||||
|
setConfig<T extends keyof IPublicTypeAppConfig>(key: T, value: IPublicTypeAppConfig[T]): void;
|
||||||
|
```
|
||||||
|
|
||||||
|
**@since v1.1.4**
|
||||||
|
|
||||||
|
#### 如何扩展项目配置
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// shims.d.ts
|
||||||
|
declare module '@alilc/lowcode-types' {
|
||||||
|
export interface IPublicTypeAppConfig {
|
||||||
|
customProp: CustomPropType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## 事件
|
## 事件
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,7 @@ export interface IProject extends Omit<IBaseApiProject<
|
|||||||
'onSimulatorHostReady' |
|
'onSimulatorHostReady' |
|
||||||
'onSimulatorRendererReady' |
|
'onSimulatorRendererReady' |
|
||||||
'setI18n' |
|
'setI18n' |
|
||||||
|
'setConfig' |
|
||||||
'currentDocument' |
|
'currentDocument' |
|
||||||
'selection' |
|
'selection' |
|
||||||
'documents' |
|
'documents' |
|
||||||
@ -75,21 +76,15 @@ export interface IProject extends Omit<IBaseApiProject<
|
|||||||
/**
|
/**
|
||||||
* 分字段设置储存数据,不记录操作记录
|
* 分字段设置储存数据,不记录操作记录
|
||||||
*/
|
*/
|
||||||
set(
|
set<T extends keyof IPublicTypeProjectSchema>(key: T, value: IPublicTypeProjectSchema[T]): void;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
set(key: string, value: unknown): void;
|
||||||
key:
|
|
||||||
| 'version'
|
/**
|
||||||
| 'componentsTree'
|
* 分字段获取储存数据
|
||||||
| 'componentsMap'
|
*/
|
||||||
| 'utils'
|
get<T extends keyof IPublicTypeProjectSchema>(key: T): IPublicTypeProjectSchema[T];
|
||||||
| 'constants'
|
get<T>(key: string): T;
|
||||||
| 'i18n'
|
get(key: string): unknown;
|
||||||
| 'css'
|
|
||||||
| 'dataSource'
|
|
||||||
| string,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
value: any,
|
|
||||||
): void;
|
|
||||||
|
|
||||||
checkExclusive(activeDoc: DocumentModel): void;
|
checkExclusive(activeDoc: DocumentModel): void;
|
||||||
}
|
}
|
||||||
@ -268,21 +263,9 @@ export class Project implements IProject {
|
|||||||
/**
|
/**
|
||||||
* 分字段设置储存数据,不记录操作记录
|
* 分字段设置储存数据,不记录操作记录
|
||||||
*/
|
*/
|
||||||
set(
|
set<T extends keyof IPublicTypeProjectSchema>(key: T, value: IPublicTypeProjectSchema[T]): void;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
set(key: string, value: unknown): void;
|
||||||
key:
|
set(key: string, value: unknown): void {
|
||||||
| 'version'
|
|
||||||
| 'componentsTree'
|
|
||||||
| 'componentsMap'
|
|
||||||
| 'utils'
|
|
||||||
| 'constants'
|
|
||||||
| 'i18n'
|
|
||||||
| 'css'
|
|
||||||
| 'dataSource'
|
|
||||||
| string,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
value: any,
|
|
||||||
): void {
|
|
||||||
if (key === 'config') {
|
if (key === 'config') {
|
||||||
this.config = value;
|
this.config = value;
|
||||||
}
|
}
|
||||||
@ -295,20 +278,10 @@ export class Project implements IProject {
|
|||||||
/**
|
/**
|
||||||
* 分字段设置储存数据
|
* 分字段设置储存数据
|
||||||
*/
|
*/
|
||||||
get(
|
get<T extends keyof IPublicTypeRootSchema>(key: T): IPublicTypeRootSchema[T];
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
get<T>(key: string): T;
|
||||||
key:
|
get(key: string): unknown;
|
||||||
| 'version'
|
get(key: string): any {
|
||||||
| 'componentsTree'
|
|
||||||
| 'componentsMap'
|
|
||||||
| 'utils'
|
|
||||||
| 'constants'
|
|
||||||
| 'i18n'
|
|
||||||
| 'css'
|
|
||||||
| 'dataSource'
|
|
||||||
| 'config'
|
|
||||||
| string,
|
|
||||||
): any {
|
|
||||||
if (key === 'config') {
|
if (key === 'config') {
|
||||||
return this.config;
|
return this.config;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import {
|
|||||||
IPublicTypePropsTransducer,
|
IPublicTypePropsTransducer,
|
||||||
IPublicEnumTransformStage,
|
IPublicEnumTransformStage,
|
||||||
IPublicTypeDisposable,
|
IPublicTypeDisposable,
|
||||||
|
IPublicTypeAppConfig,
|
||||||
} from '@alilc/lowcode-types';
|
} from '@alilc/lowcode-types';
|
||||||
import { DocumentModel as ShellDocumentModel } from '../model';
|
import { DocumentModel as ShellDocumentModel } from '../model';
|
||||||
import { SimulatorHost } from './simulator-host';
|
import { SimulatorHost } from './simulator-host';
|
||||||
@ -216,4 +217,23 @@ export class Project implements IPublicApiProject {
|
|||||||
setI18n(value: object): void {
|
setI18n(value: object): void {
|
||||||
this[projectSymbol].set('i18n', value);
|
this[projectSymbol].set('i18n', value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置项目配置
|
||||||
|
* @param value object
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
setConfig<T extends keyof IPublicTypeAppConfig>(key: T, value: IPublicTypeAppConfig[T]): void;
|
||||||
|
setConfig(value: IPublicTypeAppConfig): void;
|
||||||
|
setConfig(...params: any[]): void{
|
||||||
|
if(params.length === 2) {
|
||||||
|
const oldConfig = this[projectSymbol].get('config');
|
||||||
|
this[projectSymbol].set('config', {
|
||||||
|
...oldConfig,
|
||||||
|
[params[0]]: params[1],
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this[projectSymbol].set('config', params[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { IPublicTypeProjectSchema, IPublicTypeDisposable, IPublicTypeRootSchema, IPublicTypePropsTransducer } from '../type';
|
import { IPublicTypeProjectSchema, IPublicTypeDisposable, IPublicTypeRootSchema, IPublicTypePropsTransducer, IPublicTypeAppConfig } from '../type';
|
||||||
import { IPublicEnumTransformStage } from '../enum';
|
import { IPublicEnumTransformStage } from '../enum';
|
||||||
import { IPublicApiSimulatorHost } from './';
|
import { IPublicApiSimulatorHost } from './';
|
||||||
import { IPublicModelDocumentModel } from '../model';
|
import { IPublicModelDocumentModel } from '../model';
|
||||||
@ -132,6 +132,16 @@ export interface IBaseApiProject<
|
|||||||
* @since v1.0.17
|
* @since v1.0.17
|
||||||
*/
|
*/
|
||||||
setI18n(value: object): void;
|
setI18n(value: object): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置当前项目配置
|
||||||
|
*
|
||||||
|
* set config data for this project
|
||||||
|
* @param value object
|
||||||
|
* @since v1.1.4
|
||||||
|
*/
|
||||||
|
setConfig<T extends keyof IPublicTypeAppConfig>(key: T, value: IPublicTypeAppConfig[T]): void;
|
||||||
|
setConfig(value: IPublicTypeAppConfig): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPublicApiProject extends IBaseApiProject<IPublicModelDocumentModel> {}
|
export interface IPublicApiProject extends IBaseApiProject<IPublicModelDocumentModel> {}
|
||||||
|
|||||||
@ -4,7 +4,6 @@ export interface IPublicTypeAppConfig {
|
|||||||
targetRootID?: string;
|
targetRootID?: string;
|
||||||
layout?: IPublicTypeLayout;
|
layout?: IPublicTypeLayout;
|
||||||
theme?: IPublicTypeTheme;
|
theme?: IPublicTypeTheme;
|
||||||
[key: string]: any;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IPublicTypeTheme {
|
interface IPublicTypeTheme {
|
||||||
|
|||||||
@ -57,8 +57,10 @@ export interface IPublicTypeProjectSchema<T = IPublicTypeRootSchema> {
|
|||||||
dataSource?: DataSource;
|
dataSource?: DataSource;
|
||||||
/**
|
/**
|
||||||
* 当前应用配置信息
|
* 当前应用配置信息
|
||||||
|
*
|
||||||
|
* TODO: 需要在后续版本中移除 `Record<string, unknown>` 类型签名
|
||||||
*/
|
*/
|
||||||
config?: IPublicTypeAppConfig | Record<string, any>;
|
config?: IPublicTypeAppConfig & Record<string, unknown>;
|
||||||
/**
|
/**
|
||||||
* 当前应用元数据信息
|
* 当前应用元数据信息
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user