GeezerVison is showing github.com — feat: add setConfig method for project · EasterGit/lowcode-engine@3d51fe0
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docs/docs/api/project.md +29Lines changed: 29 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -252,6 +252,35 @@ setI18n(value: object): void; | 252 | 252 |
| 253 | 253 | **@since v1.0.17** | 254 | 254 |
| | 255 | +### setConfig | | 256 | +设置当前项目配置 | | 257 | + | | 258 | +```typescript | | 259 | +/** | | 260 | + * 设置当前项目配置 | | 261 | + * set config for this project | | 262 | + * @param value object | | 263 | + * @since v1.1.4 | | 264 | + */ | | 265 | + setConfig(value: IPublicTypeAppConfig): void; | | 266 | + setConfig<T extends keyof IPublicTypeAppConfig>(key: T, value: IPublicTypeAppConfig[T]): void; | | 267 | +``` | | 268 | +
| | 269 | +**@since v1.1.4** | | 270 | +
| | 271 | +#### 如何扩展项目配置 | | 272 | +
| | 273 | +```typescript | | 274 | +// shims.d.ts | | 275 | +declare module '@alilc/lowcode-types' { | | 276 | + export interface IPublicTypeAppConfig { | | 277 | + customProp: CustomPropType | | 278 | + } | | 279 | +} | | 280 | + | | 281 | +export {}; | | 282 | +``` | | 283 | + | 255 | 284 |
| 256 | 285 | ## 事件 | 257 | 286 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/project/project.ts +17-44Lines changed: 17 additions & 44 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,6 +29,7 @@ export interface IProject extends Omit<IBaseApiProject< | 29 | 29 | 'onSimulatorHostReady' | | 30 | 30 | 'onSimulatorRendererReady' | | 31 | 31 | 'setI18n' | | | 32 | + 'setConfig' | | 32 | 33 | 'currentDocument' | | 33 | 34 | 'selection' | | 34 | 35 | 'documents' | | @@ -75,21 +76,15 @@ export interface IProject extends Omit<IBaseApiProject< | 75 | 76 | /** | 76 | 77 | * 分字段设置储存数据,不记录操作记录 | 77 | 78 | */ | 78 | | - set( | 79 | | - // eslint-disable-next-line @typescript-eslint/no-unused-vars | 80 | | - key: | 81 | | - | 'version' | 82 | | - | 'componentsTree' | 83 | | - | 'componentsMap' | 84 | | - | 'utils' | 85 | | - | 'constants' | 86 | | - | 'i18n' | 87 | | - | 'css' | 88 | | - | 'dataSource' | 89 | | - | string, | 90 | | - // eslint-disable-next-line @typescript-eslint/no-unused-vars | 91 | | - value: any, | 92 | | - ): void; | | 79 | + set<T extends keyof IPublicTypeProjectSchema>(key: T, value: IPublicTypeProjectSchema[T]): void; | | 80 | + set(key: string, value: unknown): void; | | 81 | + | | 82 | + /** | | 83 | + * 分字段获取储存数据 | | 84 | + */ | | 85 | + get<T extends keyof IPublicTypeProjectSchema>(key: T): IPublicTypeProjectSchema[T]; | | 86 | + get<T>(key: string): T; | | 87 | + get(key: string): unknown; | 93 | 88 |
| 94 | 89 | checkExclusive(activeDoc: DocumentModel): void; | 95 | 90 | } | @@ -268,21 +263,9 @@ export class Project implements IProject { | 268 | 263 | /** | 269 | 264 | * 分字段设置储存数据,不记录操作记录 | 270 | 265 | */ | 271 | | - set( | 272 | | - // eslint-disable-next-line @typescript-eslint/no-unused-vars | 273 | | - key: | 274 | | - | 'version' | 275 | | - | 'componentsTree' | 276 | | - | 'componentsMap' | 277 | | - | 'utils' | 278 | | - | 'constants' | 279 | | - | 'i18n' | 280 | | - | 'css' | 281 | | - | 'dataSource' | 282 | | - | string, | 283 | | - // eslint-disable-next-line @typescript-eslint/no-unused-vars | 284 | | - value: any, | 285 | | - ): void { | | 266 | + set<T extends keyof IPublicTypeProjectSchema>(key: T, value: IPublicTypeProjectSchema[T]): void; | | 267 | + set(key: string, value: unknown): void; | | 268 | + set(key: string, value: unknown): void { | 286 | 269 | if (key === 'config') { | 287 | 270 | this.config = value; | 288 | 271 | } | @@ -295,20 +278,10 @@ export class Project implements IProject { | 295 | 278 | /** | 296 | 279 | * 分字段设置储存数据 | 297 | 280 | */ | 298 | | - get( | 299 | | - // eslint-disable-next-line @typescript-eslint/no-unused-vars | 300 | | - key: | 301 | | - | 'version' | 302 | | - | 'componentsTree' | 303 | | - | 'componentsMap' | 304 | | - | 'utils' | 305 | | - | 'constants' | 306 | | - | 'i18n' | 307 | | - | 'css' | 308 | | - | 'dataSource' | 309 | | - | 'config' | 310 | | - | string, | 311 | | - ): any { | | 281 | + get<T extends keyof IPublicTypeRootSchema>(key: T): IPublicTypeRootSchema[T]; | | 282 | + get<T>(key: string): T; | | 283 | + get(key: string): unknown; | | 284 | + get(key: string): any { | 312 | 285 | if (key === 'config') { | 313 | 286 | return this.config; | 314 | 287 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/shell/src/api/project.ts +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,7 @@ import { | 13 | 13 | IPublicTypePropsTransducer, | 14 | 14 | IPublicEnumTransformStage, | 15 | 15 | IPublicTypeDisposable, | | 16 | + IPublicTypeAppConfig, | 16 | 17 | } from '@alilc/lowcode-types'; | 17 | 18 | import { DocumentModel as ShellDocumentModel } from '../model'; | 18 | 19 | import { SimulatorHost } from './simulator-host'; | @@ -216,4 +217,23 @@ export class Project implements IPublicApiProject { | 216 | 217 | setI18n(value: object): void { | 217 | 218 | this[projectSymbol].set('i18n', value); | 218 | 219 | } | | 220 | + | | 221 | + /** | | 222 | + * 设置项目配置 | | 223 | + * @param value object | | 224 | + * @returns | | 225 | + */ | | 226 | + setConfig<T extends keyof IPublicTypeAppConfig>(key: T, value: IPublicTypeAppConfig[T]): void; | | 227 | + setConfig(value: IPublicTypeAppConfig): void; | | 228 | + setConfig(...params: any[]): void{ | | 229 | + if(params.length === 2) { | | 230 | + const oldConfig = this[projectSymbol].get('config'); | | 231 | + this[projectSymbol].set('config', { | | 232 | + ...oldConfig, | | 233 | + [params[0]]: params[1], | | 234 | + }) | | 235 | + } else { | | 236 | + this[projectSymbol].set('config', params[0]) | | 237 | + } | | 238 | + } | 219 | 239 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/types/src/shell/api/project.ts +12-2Lines changed: 12 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { IPublicTypeProjectSchema, IPublicTypeDisposable, IPublicTypeRootSchema, IPublicTypePropsTransducer } from '../type'; | | 1 | +import { IPublicTypeProjectSchema, IPublicTypeDisposable, IPublicTypeRootSchema, IPublicTypePropsTransducer, IPublicTypeAppConfig } from '../type'; | 2 | 2 | import { IPublicEnumTransformStage } from '../enum'; | 3 | 3 | import { IPublicApiSimulatorHost } from './'; | 4 | 4 | import { IPublicModelDocumentModel } from '../model'; | @@ -132,6 +132,16 @@ export interface IBaseApiProject< | 132 | 132 | * @since v1.0.17 | 133 | 133 | */ | 134 | 134 | setI18n(value: object): void; | | 135 | + | | 136 | + /** | | 137 | + * 设置当前项目配置 | | 138 | + * | | 139 | + * set config data for this project | | 140 | + * @param value object | | 141 | + * @since v1.1.4 | | 142 | + */ | | 143 | + setConfig<T extends keyof IPublicTypeAppConfig>(key: T, value: IPublicTypeAppConfig[T]): void; | | 144 | + setConfig(value: IPublicTypeAppConfig): void; | 135 | 145 | } | 136 | 146 |
| 137 | | -export interface IPublicApiProject extends IBaseApiProject<IPublicModelDocumentModel> {} | | 147 | +export interface IPublicApiProject extends IBaseApiProject<IPublicModelDocumentModel> {} |
Collapse file Copy file name to clipboardExpand all lines: packages/types/src/shell/type/app-config.ts -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,7 +4,6 @@ export interface IPublicTypeAppConfig { | 4 | 4 | targetRootID?: string; | 5 | 5 | layout?: IPublicTypeLayout; | 6 | 6 | theme?: IPublicTypeTheme; | 7 | | - [key: string]: any; | 8 | 7 | } | 9 | 8 |
| 10 | 9 | interface IPublicTypeTheme { | |
Collapse file Copy file name to clipboardExpand all lines: packages/types/src/shell/type/project-schema.ts +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -57,8 +57,10 @@ export interface IPublicTypeProjectSchema<T = IPublicTypeRootSchema> { | 57 | 57 | dataSource?: DataSource; | 58 | 58 | /** | 59 | 59 | * 当前应用配置信息 | | 60 | + * | | 61 | + * TODO: 需要在后续版本中移除 `Record<string, unknown>` 类型签名 | 60 | 62 | */ | 61 | | - config?: IPublicTypeAppConfig | Record<string, any>; | | 63 | + config?: IPublicTypeAppConfig & Record<string, unknown>; | 62 | 64 | /** | 63 | 65 | * 当前应用元数据信息 | 64 | 66 | */ | |
|