GeezerVison is showing github.com — fix: fixed the issue that thisRequiredInJSE did not take effect in so… · zfhstudy/lowcode-engine@7e5a919
File treeExpand file treeCollapse file tree Open diff view settings packages/renderer-core/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/src/hoc/leaf.tsx +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -141,6 +141,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { | 141 | 141 | __debug, | 142 | 142 | __getComponentProps: getProps, | 143 | 143 | __getSchemaChildrenVirtualDom: getChildren, | | 144 | + __parseData, | 144 | 145 | } = baseRenderer; | 145 | 146 | const { engine } = baseRenderer.context; | 146 | 147 | const host = baseRenderer.props?.__host; | @@ -225,7 +226,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { | 225 | 226 | nodeChildren: null, | 226 | 227 | childrenInState: false, | 227 | 228 | visible: !hidden, | 228 | | - condition: parseData(condition, scope), | | 229 | + condition: __parseData(condition, scope), | 229 | 230 | nodeCacheProps: {}, | 230 | 231 | nodeProps: {}, | 231 | 232 | }; | @@ -395,7 +396,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { | 395 | 396 |
| 396 | 397 | if (key === '___condition___') { | 397 | 398 | const { condition = true } = this.leaf?.export(TransformStage.Render) || {}; | 398 | | - const conditionValue = parseData(condition, scope); | | 399 | + const conditionValue = __parseData(condition, scope); | 399 | 400 | __debug(`key is ___condition___, change condition value to [${condition}]`); | 400 | 401 | // 条件表达式改变 | 401 | 402 | this.setState({ | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/src/renderer/base.tsx +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -245,8 +245,8 @@ export default function baseRendererFactory(): IBaseRenderComponent { | 245 | 245 | }; | 246 | 246 |
| 247 | 247 | __parseData = (data: any, ctx?: Record<string, any>) => { | 248 | | - const { __ctx } = this.props; | 249 | | - return parseData(data, ctx || __ctx || this); | | 248 | + const { __ctx, thisRequiredInJSE } = this.props; | | 249 | + return parseData(data, ctx || __ctx || this, { thisRequiredInJSE }); | 250 | 250 | }; | 251 | 251 |
| 252 | 252 | __initDataSource = (props = this.props) => { | @@ -479,7 +479,7 @@ export default function baseRendererFactory(): IBaseRenderComponent { | 479 | 479 | const displayInHook = engine?.props?.designMode === 'design'; | 480 | 480 |
| 481 | 481 | if (schema.loop != null) { | 482 | | - const loop = parseData(schema.loop, scope); | | 482 | + const loop = this.__parseData(schema.loop, scope); | 483 | 483 | const useLoop = isUseLoop(loop, this._designModeIsDesign); | 484 | 484 | if (useLoop) { | 485 | 485 | return this.__createLoopVirtualDom( | @@ -493,7 +493,7 @@ export default function baseRendererFactory(): IBaseRenderComponent { | 493 | 493 | ); | 494 | 494 | } | 495 | 495 | } | 496 | | - const condition = schema.condition == null ? true : parseData(schema.condition, scope); | | 496 | + const condition = schema.condition == null ? true : this.__parseData(schema.condition, scope); | 497 | 497 | if (!condition && !displayInHook) return null; | 498 | 498 |
| 499 | 499 | let scopeKey = ''; | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/src/renderer/page.tsx +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import baseRendererFactory from './base'; | 2 | | -import { parseData } from '../utils'; | 3 | 2 | import { IBaseRendererProps, IBaseRenderComponent } from '../types'; | 4 | 3 |
| 5 | 4 | export default function pageRendererFactory(): IBaseRenderComponent { | @@ -21,8 +20,8 @@ export default function pageRendererFactory(): IBaseRenderComponent { | 21 | 20 |
| 22 | 21 | async componentDidUpdate(prevProps: IBaseRendererProps, _prevState: {}, snapshot: unknown) { | 23 | 22 | const { __ctx } = this.props; | 24 | | - const prevState = parseData(prevProps.__schema.state, __ctx); | 25 | | - const newState = parseData(this.props.__schema.state, __ctx); | | 23 | + const prevState = this.__parseData(prevProps.__schema.state, __ctx); | | 24 | + const newState = this.__parseData(this.props.__schema.state, __ctx); | 26 | 25 | // 当编排的时候修改schema.state值,需要将最新schema.state值setState | 27 | 26 | if (JSON.stringify(newState) != JSON.stringify(prevState)) { | 28 | 27 | this.setState(newState); | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/src/utils/common.ts +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -330,15 +330,15 @@ export function forEach(targetObj: any, fn: any, context?: any) { | 330 | 330 | Object.keys(targetObj).forEach((key) => fn.call(context, targetObj[key], key)); | 331 | 331 | } | 332 | 332 |
| 333 | | -export function parseData(schema: unknown, self: any): any { | | 333 | +export function parseData(schema: unknown, self: any, options: any): any { | 334 | 334 | if (isJSExpression(schema)) { | 335 | | - return parseExpression(schema, self); | | 335 | + return parseExpression(schema, self, options.thisRequiredInJSE); | 336 | 336 | } else if (isI18nData(schema)) { | 337 | 337 | return parseI18n(schema, self); | 338 | 338 | } else if (typeof schema === 'string') { | 339 | 339 | return schema.trim(); | 340 | 340 | } else if (Array.isArray(schema)) { | 341 | | - return schema.map((item) => parseData(item, self)); | | 341 | + return schema.map((item) => parseData(item, self, options)); | 342 | 342 | } else if (typeof schema === 'function') { | 343 | 343 | return schema.bind(self); | 344 | 344 | } else if (typeof schema === 'object') { | @@ -351,7 +351,7 @@ export function parseData(schema: unknown, self: any): any { | 351 | 351 | if (key.startsWith('__')) { | 352 | 352 | return; | 353 | 353 | } | 354 | | - res[key] = parseData(val, self); | | 354 | + res[key] = parseData(val, self, options); | 355 | 355 | }); | 356 | 356 | return res; | 357 | 357 | } | |
|