roymondchen b1193b909e feat(editor): 样式设置器 StyleSetter 支持表单对比模式
- Index.vue 透传 lastValues/isCompare 给各分类子组件,并冒泡 addDiffCount

- pro 下 6 个分类组件接受新 props 并向 MContainer 传递

- Layout/Border 同时将新 props 传递给内部 Box/Border 组件

- components/Border.vue 接受新 props 并冒泡 MContainer 的 addDiffCount

- components/Box.vue 接受 props 以保持接口一致

- 补充单元测试覆盖透传与事件冒泡
2026-05-26 20:59:43 +08:00

118 lines
2.6 KiB
Vue

<template>
<MContainer
:config="config"
:model="values"
:last-values="lastValues"
:is-compare="isCompare"
:size="size"
:disabled="disabled"
@change="change"
@add-diff-count="onAddDiffCount"
></MContainer>
</template>
<script lang="ts" setup>
import { type ContainerChangeEventData, defineFormItem, MContainer } from '@tmagic/form';
import type { StyleSchema } from '@tmagic/schema';
const props = defineProps<{
values: Partial<StyleSchema>;
lastValues?: Partial<StyleSchema>;
isCompare?: boolean;
disabled?: boolean;
size?: 'large' | 'default' | 'small';
}>();
const emit = defineEmits<{
change: [v: string | StyleSchema, eventData: ContainerChangeEventData];
addDiffCount: [];
}>();
const positionText: Record<string, string> = {
static: '不定位',
relative: '相对定位',
absolute: '绝对定位',
fixed: '固定定位',
sticky: '粘性定位',
};
const config = defineFormItem({
items: [
{
name: 'position',
text: '定位',
labelWidth: '68px',
type: 'data-source-field-select',
fieldConfig: {
type: 'select',
options: Object.keys(positionText).map((item) => ({
value: item,
text: `${item}(${positionText[item]})`,
})),
},
},
{
type: 'row',
labelWidth: '68px',
display: () => props.values.position !== 'static',
items: [
{
name: 'left',
type: 'data-source-field-select',
text: 'left',
fieldConfig: {
type: 'text',
},
},
{
name: 'top',
type: 'data-source-field-select',
text: 'top',
fieldConfig: {
type: 'text',
},
},
],
},
{
type: 'row',
labelWidth: '68px',
display: () => props.values.position !== 'static',
items: [
{
name: 'right',
type: 'data-source-field-select',
text: 'right',
fieldConfig: {
type: 'text',
},
},
{
name: 'bottom',
type: 'data-source-field-select',
text: 'bottom',
fieldConfig: {
type: 'text',
},
},
],
},
{
labelWidth: '68px',
name: 'zIndex',
text: 'zIndex',
type: 'data-source-field-select',
fieldConfig: {
type: 'text',
},
},
],
});
const change = (value: string | StyleSchema, eventData: ContainerChangeEventData) => {
emit('change', value, eventData);
};
const onAddDiffCount = () => emit('addDiffCount');
</script>