-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: optimize block and material scalability issue (#788)
当前问题 从用户注册表去掉区块模块后会报错无法启动,解决该报错后,画布中依然存在了新建区块的入口,且物料插件面板报错无法展开 物料模块没有导出加载bundle.json物料的api,不太方便使用 解决方法 从common包中移除SaveNewBlock组件,画布模块从区块注册表获取组件 物料插件根据区块模块存在情况渲染区块面板 物料模块导出增加addMaterials API,传入bundle对象即可加载物料 遗留 物料插件中要隐藏区块依然需要配置注册表,没有实现自动关联
- Loading branch information
Showing
9 changed files
with
212 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
packages/plugins/materials/src/meta/block/src/BlockPanel.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
<template> | ||
<div class="blocks-wrap"> | ||
<block-group v-model="state.groups" @changeGroup="changeGroup"></block-group> | ||
<tiny-search v-model="state.searchValue" clearable placeholder="请输入关键字搜索"> | ||
<template #prefix> <tiny-icon-search /> </template> | ||
</tiny-search> | ||
<block-list v-model:blockList="filterBlocks" :show-add-button="true" :show-block-shot="true"></block-list> | ||
</div> | ||
<teleport to=".material-right-panel" v-if="rightPanelRef"> | ||
<block-group-panel></block-group-panel> | ||
<block-version-select></block-version-select> | ||
</teleport> | ||
</template> | ||
|
||
<script lang="jsx"> | ||
import { onMounted, reactive, watch, provide, computed } from 'vue' | ||
import { Search } from '@opentiny/vue' | ||
import { iconSearch } from '@opentiny/vue-icon' | ||
import { useApp, useBlock, useMaterial, useModal } from '@opentiny/tiny-engine-meta-register' | ||
import BlockGroup from './BlockGroup.vue' | ||
import BlockList from './BlockList.vue' | ||
import BlockGroupPanel from './BlockGroupPanel.vue' | ||
import BlockVersionSelect from './BlockVersionSelect.vue' | ||
import { fetchGroups, fetchGroupBlocksById, fetchGroupBlocksByIds } from './http' | ||
import metaData from '../meta' | ||
import { setBlockPanelVisible, setBlockVersionPanelVisible } from './js/usePanel' | ||
export default { | ||
components: { | ||
TinySearch: Search, | ||
TinyIconSearch: iconSearch(), | ||
BlockGroup, | ||
BlockList, | ||
BlockGroupPanel, | ||
BlockVersionSelect | ||
}, | ||
props: { | ||
activeTabName: String, | ||
rightPanelRef: Object | ||
}, | ||
setup(props) { | ||
const { addDefaultGroup, isDefaultGroupId, isAllGroupId, isRefresh, selectedGroup } = useBlock() | ||
const { materialState } = useMaterial() | ||
const { message } = useModal() | ||
const appId = useApp().appInfoState.selectedId | ||
const state = reactive({ | ||
searchValue: '', | ||
groups: [], | ||
groupData: [] | ||
}) | ||
const filterBlocks = computed(() => { | ||
if (!state.searchValue) { | ||
return state.groupData | ||
} | ||
const lowerCaseSearchValue = state.searchValue.toLowerCase() | ||
return state.groupData.filter((block) => { | ||
const nameCN = block?.name_cn?.toLowerCase?.() ?? '' | ||
const label = block?.label?.toLowerCase?.() ?? '' | ||
const description = block?.description?.toLowerCase?.() ?? '' | ||
return ( | ||
nameCN.includes(lowerCaseSearchValue) || | ||
label.includes(lowerCaseSearchValue) || | ||
description.includes(lowerCaseSearchValue) | ||
) | ||
}) | ||
}) | ||
const changeGroup = () => { | ||
state.searchValue = '' | ||
} | ||
provide('displayType', 'default') | ||
// 读取区块 | ||
const fetchBlocks = async (value) => { | ||
// 设计器默认区块分组的数据从bundle.json取,其他用户自定义分组调接口向数据库查询 | ||
const groupId = selectedGroup.value.groupId | ||
if (isDefaultGroupId(groupId)) { | ||
const blocks = materialState.blocks[0]?.children || [] | ||
state.groupData = value ? blocks.filter((item) => new RegExp(value, 'i').test(item?.label)) : blocks | ||
state.groupData.forEach((block) => { | ||
block.isDefaultGroup = true | ||
}) | ||
} else if (isAllGroupId(groupId)) { | ||
const groupIds = state.groups.map((item) => item.value.groupId).filter((id) => typeof id === 'number') | ||
const innerBlocks = materialState.blocks[0]?.children || [] | ||
innerBlocks.forEach((item) => { | ||
item.isDefaultGroup = true | ||
item.groupName = '设计器默认区块分组' | ||
}) | ||
let blocks = [] | ||
try { | ||
blocks = await fetchGroupBlocksByIds({ groupIds }) | ||
} catch (error) { | ||
message({ message: `获取区块列表失败: ${error.message || error}`, status: 'error' }) | ||
} | ||
state.groupData = [...innerBlocks, ...blocks] | ||
} else { | ||
fetchGroupBlocksById({ groupId, value }) | ||
.then((data) => { | ||
state.groupData = data | ||
}) | ||
.catch((error) => { | ||
state.groupData = [] | ||
message({ message: `获取区块列表失败: ${error.message || error}`, status: 'error' }) | ||
}) | ||
} | ||
} | ||
watch( | ||
() => selectedGroup.value.groupId, | ||
// 避免简写带入watch默认参数 | ||
() => fetchBlocks() | ||
) | ||
watch( | ||
() => isRefresh.value, | ||
(value) => { | ||
if (value) { | ||
fetchBlocks() | ||
isRefresh.value = false | ||
} | ||
} | ||
) | ||
watch( | ||
() => props.activeTabName, | ||
(value) => { | ||
if (value !== metaData.id) { | ||
setBlockPanelVisible(false) | ||
setBlockVersionPanelVisible(false) | ||
} | ||
} | ||
) | ||
onMounted(() => { | ||
fetchGroups(appId) | ||
.then((data) => { | ||
const groups = addDefaultGroup(data) | ||
state.groups.push(...groups) | ||
fetchBlocks() | ||
}) | ||
.catch((error) => { | ||
message({ message: `获取区块列表失败: ${error.message || error}`, status: 'error' }) | ||
}) | ||
}) | ||
return { | ||
state, | ||
filterBlocks, | ||
changeGroup | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="less" scoped> | ||
.blocks-wrap { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
.tiny-search { | ||
padding: 0 8px 12px; | ||
:deep(.tiny-input__inner) { | ||
height: 30px; | ||
} | ||
} | ||
:deep(.block-list) { | ||
.block-item { | ||
color: #ababab; | ||
} | ||
} | ||
} | ||
</style> |
Oops, something went wrong.