roymondchen 2ad5101471 fix(editor): 修复 StyleSetter 嵌套场景下 propPath 丢失上下文路径的问题
当 prop 与 name 不一致(如 data.items.0.style)时,原实现固定使用 name 会丢失上下文路径,
改为优先使用 prop,回退到 name,确保 changeRecords 携带完整路径。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-14 19:17:48 +08:00

86 lines
2.0 KiB
Vue

<template>
<TMagicCollapse class="m-fields-style-setter" v-model="collapseValue">
<template v-for="(item, index) in list" :key="index">
<TMagicCollapseItem :name="`${index}`">
<template #title><MIcon :icon="Grid"></MIcon>{{ item.title }}</template>
<component
v-if="item.component"
:is="item.component"
:values="model[name]"
:size="size"
:disabled="disabled"
@change="change"
></component>
</TMagicCollapseItem>
</template>
</TMagicCollapse>
</template>
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Grid } from '@element-plus/icons-vue';
import { TMagicCollapse, TMagicCollapseItem } from '@tmagic/design';
import type { ContainerChangeEventData, FieldProps } from '@tmagic/form';
import type { StyleSchema } from '@tmagic/schema';
import MIcon from '@editor/components/Icon.vue';
import { Background, Border, Font, Layout, Position, Transform } from './pro/';
defineOptions({
name: 'MFieldsStyleSetter',
});
const props = defineProps<FieldProps<StyleSchema>>();
const emit = defineEmits<{
change: [v: any, eventData: ContainerChangeEventData];
}>();
const list = [
{
name: 'font',
title: '布局',
component: Layout,
},
{
title: '位置',
component: Position,
},
{
title: '背景',
component: Background,
},
{
title: '文字',
component: Font,
},
{
title: '边框与圆角',
component: Border,
},
{
title: '变形',
component: Transform,
},
];
const collapseValue = shallowRef(
Array(list.length)
.fill(1)
.map((x, i) => `${i}`),
);
const change = (v: any, eventData: ContainerChangeEventData) => {
eventData.changeRecords?.forEach((record) => {
if (props.prop) {
record.propPath = `${props.prop}.${record.propPath}`;
} else if (props.name) {
record.propPath = `${props.name}.${record.propPath}`;
}
});
emit('change', v, eventData);
};
</script>