Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/plugins/materials/src/composable/useMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ const addComponentSnippets = (componentSnippets, snippetsData) => {
if (snippetsMap.has(snippetGroup.group)) {
snippetsMap.get(snippetGroup.group).children.push(...snippetGroup.children)
} else {
snippetsData.push(snippetGroup)
const snippetGroupClone = deepClone(snippetGroup)
snippetsData.push(snippetGroupClone)
snippetsMap.set(snippetGroup.group, snippetGroupClone)
}
})

Expand Down Expand Up @@ -486,6 +488,12 @@ const initMaterial = ({ isInit = true, appData = {} } = {}) => {
}
}

const refreshMaterial = async () => {
clearMaterials()
initMaterial()
await fetchMaterial()
}

/**
* 根据组名获取指定分组组件
* @param {Array} components 所有组件
Expand Down Expand Up @@ -526,6 +534,7 @@ export default function () {
getBlockCompileRes,
addBlockResources,
updateBlockCompileCache,
getComponentsByGroup
getComponentsByGroup,
refreshMaterial
}
}
21 changes: 15 additions & 6 deletions packages/plugins/materials/src/meta/component/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</template>

<script lang="ts">
import { inject, onMounted, reactive, ref, watchEffect } from 'vue'
import { inject, onMounted, reactive, ref, watch, watchEffect } from 'vue'
import { Collapse, CollapseItem, Search } from '@opentiny/vue'
import { SearchEmpty, CanvasDragItem } from '@opentiny/tiny-engine-common'
import i18n from '@opentiny/tiny-engine-common/js/i18n'
Expand All @@ -57,7 +57,6 @@ export default {
const { generateNode, materialState, getComponentsByGroup } = useMaterial()
const gridTemplateColumns = ref(COMPONENT_PANEL_COLUMNS)
const panelState = inject('panelState', {})
const { components } = materialState
const { locale } = i18n.global

const fetchComponents = (components, name) => {
Expand Down Expand Up @@ -91,10 +90,10 @@ export default {
const initComponents = () => {
const groupName = panelState.materialGroup
if (groupName) {
return getComponentsByGroup(components, groupName)
return getComponentsByGroup(materialState.components, groupName)
}

return components
return materialState.components
}

const state = reactive({
Expand All @@ -104,13 +103,23 @@ export default {
})

watchEffect(() => {
state.activeName = [...Array(components.length).keys()]
state.activeName = [...Array(materialState.components.length).keys()]
})

const change = (value) => {
state.components = fetchComponents(components, value)
state.components = fetchComponents(materialState.components, value)
}

watch(
() => materialState.components,
(value) => {
state.components = fetchComponents(value, state.searchValue)
},
{
deep: true
}
)

const componentClick = (data) => {
const { isShortcutPanel, emitEvent } = panelState
const { addComponent } = useCanvas().canvasApi.value
Expand Down