Skip to content

Commit e26ea39

Browse files
authored
feat: 物料可以单独设置是否添加基础样式(opentiny#1238)
* feat: 物料可以单独设置是否添加基础样式,可以和物料插件useBaseStyle配置组合使用
1 parent 04d5c04 commit e26ea39

2 files changed

Lines changed: 33 additions & 25 deletions

File tree

packages/plugins/materials/src/composable/useMaterial.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,6 @@ const getSnippet = (component: string) => {
7575
return schema
7676
}
7777

78-
const generateNode = ({ type, component }: { type: string; component: string }) => {
79-
const snippet = getSnippet(component) || {}
80-
81-
const schema: Schema & Required<Pick<Schema, 'props'>> = {
82-
componentName: component,
83-
...snippet,
84-
props: {
85-
...snippet.props,
86-
className: getOptions(meta.id).useBaseStyle ? getOptions(meta.id).componentBaseStyle.className : ''
87-
}
88-
}
89-
90-
if (type === 'block') {
91-
schema.componentType = 'Block'
92-
schema.props.className = getOptions(meta.id).useBaseStyle ? getOptions(meta.id).blockBaseStyle.className : ''
93-
}
94-
95-
return schema
96-
}
97-
9878
/**
9979
* 获取物料组件的配置信息
10080
* @returns
@@ -502,7 +482,29 @@ const initMaterial = ({ isInit = true, appData = {} }: InitMaterialOptions = {})
502482
})
503483
}
504484
}
485+
const generateNode = ({ type, component }) => {
486+
const snippet = getSnippet(component) || {}
487+
const material = getMaterial(component)
488+
// 判断是否要加基础样式
489+
const materialUseBaseStyle = material.configure?.useBaseStyle
490+
const globalUseBaseStyle = getOptions(meta.id).useBaseStyle
491+
const useBaseStyle = globalUseBaseStyle && materialUseBaseStyle !== false
492+
const schema = {
493+
componentName: component,
494+
...snippet,
495+
props: {
496+
...snippet.props,
497+
className: useBaseStyle ? getOptions(meta.id).componentBaseStyle.className : ''
498+
}
499+
}
505500

501+
if (type === 'block') {
502+
schema.componentType = 'Block'
503+
schema.props.className = getOptions(meta.id).useBaseStyle ? getOptions(meta.id).blockBaseStyle.className : ''
504+
}
505+
506+
return schema
507+
}
506508
const refreshMaterial = async () => {
507509
clearMaterials()
508510
initMaterial()

packages/plugins/materials/src/meta/block/src/BlockDetail.vue

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@
1616
<div>{{ detail?.current_history?.message }}</div>
1717
<div class="block-item-history">{{ detail?.current_history?.updated_at }}</div>
1818
</div>
19-
<div v-if="!isSettingPanel && !isShortcutPanel" class="block-detail-item block-detail-show-more"
20-
@click="openHistory">
19+
<div
20+
v-if="!isSettingPanel && !isShortcutPanel"
21+
class="block-detail-item block-detail-show-more"
22+
@click="openHistory"
23+
>
2124
<span>查看历史备份</span>
2225
<icon-double-right></icon-double-right>
2326
</div>
24-
<div v-if="!isDefaultGroupId(selectedGroup.groupId) && !isSettingPanel && !isShortcutPanel"
25-
class="block-delete" @click="deleteBlock(selectedBlock || detail?.id)">
27+
<div
28+
v-if="!isDefaultGroupId(selectedGroup.groupId) && !isSettingPanel && !isShortcutPanel"
29+
class="block-delete"
30+
@click="deleteBlock(selectedBlock || detail?.id)"
31+
>
2632
<tiny-button :icon="IconDel">Delete</tiny-button>
2733
</div>
2834
</div>
@@ -47,7 +53,7 @@ export default {
4753
props: {
4854
detail: {
4955
type: Object,
50-
default: () => { }
56+
default: () => {}
5157
},
5258
isSettingPanel: {
5359
type: Boolean,

0 commit comments

Comments
 (0)