fix: compatible with SlotSchema which doesn't have title / name / params

This commit is contained in:
LeoYuan 袁力皓 2022-12-21 09:52:55 +08:00 committed by 刘菊萍(絮黎)
parent 064e842382
commit 3fe9882f9d
2 changed files with 17 additions and 2 deletions

View File

@ -315,9 +315,17 @@ export class Prop implements IPropParent {
setAsSlot(data: JSSlot) {
this._type = 'slot';
let slotSchema: SlotSchema;
// 当 data.value 的结构为 { componentName: 'Slot' } 时,直接当成 slotSchema 使用
// 当 data.value 的结构为 { componentName: 'Slot' } 时,复用部分 slotSchema 数据
if ((isPlainObject(data.value) && data.value?.componentName === 'Slot')) {
slotSchema = data.value as SlotSchema;
const value = data.value as SlotSchema;
slotSchema = {
componentName: 'Slot',
title: value.title || value.props?.slotTitle,
id: data.id,
name: value.name || value.props?.slotName,
params: value.params || value.props?.slotParams,
children: data.value,
} as SlotSchema;
} else {
slotSchema = {
componentName: 'Slot',

View File

@ -162,7 +162,14 @@ export type RootSchema = PageSchema | ComponentSchema | BlockSchema;
export interface SlotSchema extends NodeSchema {
componentName: 'Slot';
name?: string;
title?: string;
params?: string[];
props?: {
slotTitle?: string;
slotName?: string;
slotParams?: string[];
};
children?: NodeSchema[];
}
/**