Skip to content

Commit

Permalink
refactor(useMaterial): review意见修改
Browse files Browse the repository at this point in the history
  • Loading branch information
wenmine committed Jun 29, 2024
1 parent 8ac2a2b commit 9866981
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/plugins/materials/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default {
layout: MaterialLayout,
options: {
defaultTabId: 'engine.plugins.materials.component',
tabComponentIds: ['engine.plugins.materials.component', 'engine.plugins.materials.block']
displayComponentIds: ['engine.plugins.materials.component', 'engine.plugins.materials.block']
},
components: {
header: MaterialHeader
Expand Down
19 changes: 6 additions & 13 deletions packages/plugins/materials/src/composable/useMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ const setThirdPartyDeps = (components) => {
styles.forEach((item) => materialState.thirdPartyDeps.styles.add(item))
}

/**
* 获取到符合物料协议的bundle.json之后,对其进行处理的函数
* @param {*} materials
*/
const addMaterials = (materials = {}) => {
setThirdPartyDeps(materials.components)
materialState.components.push(...materials.snippets)
Expand Down Expand Up @@ -324,31 +328,20 @@ const initMaterial = ({ isInit = true, appData = {} } = {}) => {
}
}

const getSnippetRelationship = (component) => {
let relationship = {}
materialState.components.forEach(({ children }) => {
const child = children.find(({ snippetName }) => snippetName === component)
child && (relationship = child.relationship)
})

return relationship
}

export default function () {
return {
materialState,
initMaterial,
fetchMaterial,
getMaterialsRes,
generateNode,
addMaterials,
clearMaterials,
clearBlockResources,
getMaterial,
setMaterial,
registerComponentToResource,
registerBlock,
updateCanvasDependencies,
getConfigureMap,
getSnippetRelationship
getConfigureMap
}
}
9 changes: 5 additions & 4 deletions packages/plugins/materials/src/meta/layout/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ export default {
const pluginRegistryData = ref(props.registryData)
const rightPanelRef = ref(null)
const tabComponentIds = pluginRegistryData.value.options.tabComponentIds || []
const displayComponentIds = pluginRegistryData.value.options.displayComponentIds || []
const headerComponent = getMergeMeta(pluginRegistryData.value.components?.header)
const onlyShowDefault = ref(tabComponentIds.length === 1)
const onlyShowDefault = ref(displayComponentIds.length === 1)
const activeTabId =
tabComponentIds.find((item) => item === pluginRegistryData.value.options?.defaultTabId) || tabComponentIds[0]
displayComponentIds.find((item) => item === pluginRegistryData.value.options?.defaultTabId) ||
displayComponentIds[0]
const activeName = ref(activeTabId)
const defaultComponent = getMergeMeta(activeName.value)?.entry
const tabComponents = tabComponentIds.map((id) => {
const tabComponents = displayComponentIds.map((id) => {
const itemMeta = getMergeMeta(id)
return {
id,
Expand Down

0 comments on commit 9866981

Please sign in to comment.