Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/refactor/develop' into adapt-t…
Browse files Browse the repository at this point in the history
…o-unibuy
  • Loading branch information
hexqi committed Sep 5, 2024
2 parents d182071 + 1700d3c commit 3a3029f
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 174 deletions.
15 changes: 10 additions & 5 deletions packages/canvas/container/src/components/CanvasMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
</ul>
</li>
</ul>
<SaveNewBlock v-if="hasBlock" :boxVisibility="boxVisibility" fromCanvas @close="close"></SaveNewBlock>
<component :is="SaveNewBlock" :boxVisibility="boxVisibility" fromCanvas @close="close"></component>
</div>
</template>

<script lang="jsx">
import { ref, reactive, nextTick } from 'vue'
import { canvasState, getConfigure, getController, getCurrent, copyNode, removeNodeById } from '../container'
import { useLayout, useModal, useCanvas, getMetaApi, META_SERVICE } from '@opentiny/tiny-engine-meta-register'
import { useLayout, useModal, useCanvas, getMergeMeta } from '@opentiny/tiny-engine-meta-register'
import { iconRight } from '@opentiny/vue-icon'
const menuState = reactive({
Expand Down Expand Up @@ -112,10 +112,15 @@ export default {
},
{ name: '删除', code: 'del' },
{ name: '复制', code: 'copy' },
{ name: '绑定事件', code: 'bindEvent' },
{ name: '新建区块', code: 'createBlock' }
{ name: '绑定事件', code: 'bindEvent' }
])
// 通过画布右键快捷新建区块
const { SaveNewBlock } = getMergeMeta('engine.plugins.blockmanage')?.components || {}
if (SaveNewBlock) {
menus.value.push({ name: '新建区块', code: 'createBlock' })
}
const boxVisibility = ref(false)
// 计算上下文菜单位置,右键时显示,否则关闭
Expand Down Expand Up @@ -227,7 +232,7 @@ export default {
}
return {
hasBlock: getMetaApi(META_SERVICE.Block),
SaveNewBlock,
menuState,
menus,
doOperation,
Expand Down
4 changes: 1 addition & 3 deletions packages/common/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import ConfigGroup from './ConfigGroup.vue'
import ConfigItem from './ConfigItem.vue'
import SaveNewBlock from './SaveNewBlock.vue'
export { default as PluginSetting } from './PluginSetting.vue'
export { default as PluginPanel } from './PluginPanel.vue'
export { default as SvgButton } from './SvgButton.vue'
Expand Down Expand Up @@ -56,12 +55,11 @@ export { default as I18nInput } from './I18nInput.vue'
export { default as CanvasDragItem } from './CanvasDragItem.vue'
export { default as Modal } from './Modal.jsx'
export { default as Notify } from './Notify.jsx'
export { ConfigGroup, ConfigItem, SaveNewBlock }
export { ConfigGroup, ConfigItem }

export const injectGlobalComponents = {
install: (app) => {
const globalComponents = {
SaveNewBlock,
ConfigGroup,
ConfigItem
}
Expand Down
6 changes: 5 additions & 1 deletion packages/plugins/block/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
import entry, { api } from './src/Main.vue'
import metaData from './meta.js'
import { BlockService } from './src/composable'
import SaveNewBlock from './src/SaveNewBlock.vue'

export default {
...metaData,
apis: api,
entry,
metas: [BlockService]
metas: [BlockService],
components: {
SaveNewBlock
}
}

export { BlockService }
3 changes: 2 additions & 1 deletion packages/plugins/block/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@ import {
Popover as TinyPopover,
Button as TinyButton
} from '@opentiny/vue'
import { PluginPanel, PluginBlockList, SvgButton, SaveNewBlock, LinkButton } from '@opentiny/tiny-engine-common'
import { PluginPanel, PluginBlockList, SvgButton, LinkButton } from '@opentiny/tiny-engine-common'
import { useBlock, useModal, useLayout, useCanvas, useHelp } from '@opentiny/tiny-engine-meta-register'
import { constants } from '@opentiny/tiny-engine-utils'
import BlockSetting, { openPanel, closePanel } from './BlockSetting.vue'
import BlockGroupArrange from './BlockGroupArrange.vue'
import CategoryEdit from './CategoryEdit.vue'
import SaveNewBlock from './SaveNewBlock.vue'
import {
saveBlock,
initEditBlock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import { reactive, computed, ref } from 'vue'
import { Input, Form, FormItem, Button, DialogBox, Select } from '@opentiny/vue'
import { useBlock, useLayout, useCanvas, useModal } from '@opentiny/tiny-engine-meta-register'
import { REGEXP_BLOCK_NAME } from '../js/verification'
import { REGEXP_BLOCK_NAME } from '@opentiny/tiny-engine-common/js/verification'
export default {
components: {
Expand Down
181 changes: 181 additions & 0 deletions packages/plugins/materials/src/meta/block/src/BlockPanel.vue
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>
Loading

0 comments on commit 3a3029f

Please sign in to comment.