From c048c4a1803accd8d354d682aad6fbb8b45f6ba4 Mon Sep 17 00:00:00 2001 From: liuyongkai2 Date: Wed, 27 Aug 2025 20:29:52 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=E4=BC=A0=E9=80=92=E5=A4=8D=E6=9D=82?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuyongkai2 --- .../ui-plugins/interop/initstatevar.ts | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/arkui-plugins/ui-plugins/interop/initstatevar.ts b/arkui-plugins/ui-plugins/interop/initstatevar.ts index 77846dadb..b2ac2cf6d 100644 --- a/arkui-plugins/ui-plugins/interop/initstatevar.ts +++ b/arkui-plugins/ui-plugins/interop/initstatevar.ts @@ -18,7 +18,7 @@ import * as arkts from '@koalaui/libarkts'; import { BuilderMethodNames, InteroperAbilityNames } from './predefines'; import { annotation, backingField, isAnnotation } from '../../common/arkts-utils'; -import { stateProxy, getWrapValue, setPropertyESValue } from './utils'; +import { stateProxy, getWrapValue, setPropertyESValue, createEmptyESValue } from './utils'; import { hasDecorator } from '../property-translators/utils'; import { DecoratorNames } from '../../common/predefines'; @@ -147,6 +147,34 @@ export function processLink(keyName: string, value: arkts.Expression, type: arkt return result; } +function processObjectLiteral(target: arkts.ObjectExpression, curParam: string, result: arkts.Statement[]): void { + if (curParam !== InteroperAbilityNames.PARAM) { + const createParam = createEmptyESValue(curParam); + result.push(createParam); + } + target.properties.forEach((property, index) => { + const paramName = curParam + index; + const key = property.key; + const value = property.value; + if (arkts.isObjectExpression(value)) { + processObjectLiteral(value, paramName, result); + const setProperty = setPropertyESValue( + curParam, + key.name, + arkts.factory.createIdentifier(paramName) + ); + result.push(setProperty); + } else { + const setProperty = setPropertyESValue( + curParam, + key.name, + getWrapValue(value) + ); + result.push(setProperty); + } + }); +} + /** * * @param keyName @@ -155,12 +183,16 @@ export function processLink(keyName: string, value: arkts.Expression, type: arkt */ export function processNormal(keyName: string, value: arkts.AstNode): arkts.Statement[] { const result: arkts.Statement[] = []; - const setProperty = setPropertyESValue( - InteroperAbilityNames.PARAM, - keyName, - getWrapValue(value) - ); - result.push(setProperty); + if (arkts.isObjectExpression(value)) { + processObjectLiteral(value, InteroperAbilityNames.PARAM, result); + } else { + const setProperty = setPropertyESValue( + InteroperAbilityNames.PARAM, + keyName, + getWrapValue(value) + ); + result.push(setProperty); + } return result; } -- Gitee