fix: fixed the issue that thisRequiredInJSE did not take effect in some scenarios

This commit is contained in:
liujuping 2022-06-24 15:10:28 +08:00 committed by 刘菊萍(絮黎)
parent b216aa5d2b
commit 7e5a919f93
4 changed files with 13 additions and 13 deletions

View File

@ -141,6 +141,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
__debug,
__getComponentProps: getProps,
__getSchemaChildrenVirtualDom: getChildren,
__parseData,
} = baseRenderer;
const { engine } = baseRenderer.context;
const host = baseRenderer.props?.__host;
@ -225,7 +226,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
nodeChildren: null,
childrenInState: false,
visible: !hidden,
condition: parseData(condition, scope),
condition: __parseData(condition, scope),
nodeCacheProps: {},
nodeProps: {},
};
@ -395,7 +396,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
if (key === '___condition___') {
const { condition = true } = this.leaf?.export(TransformStage.Render) || {};
const conditionValue = parseData(condition, scope);
const conditionValue = __parseData(condition, scope);
__debug(`key is ___condition___, change condition value to [${condition}]`);
// 条件表达式改变
this.setState({

View File

@ -245,8 +245,8 @@ export default function baseRendererFactory(): IBaseRenderComponent {
};
__parseData = (data: any, ctx?: Record<string, any>) => {
const { __ctx } = this.props;
return parseData(data, ctx || __ctx || this);
const { __ctx, thisRequiredInJSE } = this.props;
return parseData(data, ctx || __ctx || this, { thisRequiredInJSE });
};
__initDataSource = (props = this.props) => {
@ -479,7 +479,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
const displayInHook = engine?.props?.designMode === 'design';
if (schema.loop != null) {
const loop = parseData(schema.loop, scope);
const loop = this.__parseData(schema.loop, scope);
const useLoop = isUseLoop(loop, this._designModeIsDesign);
if (useLoop) {
return this.__createLoopVirtualDom(
@ -493,7 +493,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
);
}
}
const condition = schema.condition == null ? true : parseData(schema.condition, scope);
const condition = schema.condition == null ? true : this.__parseData(schema.condition, scope);
if (!condition && !displayInHook) return null;
let scopeKey = '';

View File

@ -1,5 +1,4 @@
import baseRendererFactory from './base';
import { parseData } from '../utils';
import { IBaseRendererProps, IBaseRenderComponent } from '../types';
export default function pageRendererFactory(): IBaseRenderComponent {
@ -21,8 +20,8 @@ export default function pageRendererFactory(): IBaseRenderComponent {
async componentDidUpdate(prevProps: IBaseRendererProps, _prevState: {}, snapshot: unknown) {
const { __ctx } = this.props;
const prevState = parseData(prevProps.__schema.state, __ctx);
const newState = parseData(this.props.__schema.state, __ctx);
const prevState = this.__parseData(prevProps.__schema.state, __ctx);
const newState = this.__parseData(this.props.__schema.state, __ctx);
// 当编排的时候修改schema.state值需要将最新schema.state值setState
if (JSON.stringify(newState) != JSON.stringify(prevState)) {
this.setState(newState);

View File

@ -330,15 +330,15 @@ export function forEach(targetObj: any, fn: any, context?: any) {
Object.keys(targetObj).forEach((key) => fn.call(context, targetObj[key], key));
}
export function parseData(schema: unknown, self: any): any {
export function parseData(schema: unknown, self: any, options: any): any {
if (isJSExpression(schema)) {
return parseExpression(schema, self);
return parseExpression(schema, self, options.thisRequiredInJSE);
} else if (isI18nData(schema)) {
return parseI18n(schema, self);
} else if (typeof schema === 'string') {
return schema.trim();
} else if (Array.isArray(schema)) {
return schema.map((item) => parseData(item, self));
return schema.map((item) => parseData(item, self, options));
} else if (typeof schema === 'function') {
return schema.bind(self);
} else if (typeof schema === 'object') {
@ -351,7 +351,7 @@ export function parseData(schema: unknown, self: any): any {
if (key.startsWith('__')) {
return;
}
res[key] = parseData(val, self);
res[key] = parseData(val, self, options);
});
return res;
}