From 11552e57eeb853dcd6310bfc9d650ac4a0997be2 Mon Sep 17 00:00:00 2001 From: gene9831 Date: Fri, 15 Nov 2024 17:08:06 +0800 Subject: [PATCH 1/4] feat: support merge categories and groups in blocks --- designer-demo/registry.js | 15 +++++++- packages/plugins/block/index.js | 3 ++ packages/plugins/block/src/BlockConfig.vue | 19 +++++++--- packages/plugins/block/src/CategoryEdit.vue | 36 +++++++++++++++---- packages/plugins/block/src/Main.vue | 23 +++++++++--- packages/plugins/block/src/SaveNewBlock.vue | 7 ++-- .../plugins/block/src/composable/useBlock.js | 10 +++++- .../plugins/block/src/js/blockSetting.jsx | 34 +++++++++++++----- packages/plugins/block/src/js/http.js | 19 ++++++++++ 9 files changed, 138 insertions(+), 28 deletions(-) diff --git a/designer-demo/registry.js b/designer-demo/registry.js index 45d09f154..20f4bc029 100644 --- a/designer-demo/registry.js +++ b/designer-demo/registry.js @@ -98,7 +98,20 @@ export default { Fullscreen, Lang ], - plugins: [Materials, Tree, Page, Block, Datasource, Bridge, I18n, Script, State, Schema, Help, Robot], + plugins: [ + Materials, + Tree, + Page, + [Block, { options: { ...Block.options, mergeCategoriesAndGroups: true } }], + Datasource, + Bridge, + I18n, + Script, + State, + Schema, + Help, + Robot + ], dsls: [{ id: 'engine.dsls.dslvue' }], settings: [Props, Styles, Events], canvas: Canvas diff --git a/packages/plugins/block/index.js b/packages/plugins/block/index.js index df70726dd..66e6967a0 100644 --- a/packages/plugins/block/index.js +++ b/packages/plugins/block/index.js @@ -20,6 +20,9 @@ export default { apis: api, entry, metas: [BlockService], + options: { + mergeCategoriesAndGroups: false + }, components: { SaveNewBlock } diff --git a/packages/plugins/block/src/BlockConfig.vue b/packages/plugins/block/src/BlockConfig.vue index a5d36ba2b..7f7f8c172 100644 --- a/packages/plugins/block/src/BlockConfig.vue +++ b/packages/plugins/block/src/BlockConfig.vue @@ -24,12 +24,12 @@ > - + - - + + - + + @@ -46,7 +51,7 @@ import { REGEXP_GROUP_NAME } from '@opentiny/tiny-engine-common/js/verification' import { extend } from '@opentiny/vue-renderless/common/object' import { createOrUpdateCategory } from './js/blockSetting' -const { getGroupList } = useBlock() +const { getGroupList, shouldReplaceCategoryWithGroup } = useBlock() const props = defineProps({ modelValue: Boolean, @@ -55,6 +60,20 @@ const props = defineProps({ const emit = defineEmits(['update:modelValue']) +const groupLabels = shouldReplaceCategoryWithGroup() + ? { + text: '分组', + nameInput: '分组名称', + nameInputPlaceholder: '请输入分组名称', + validateErrMsg: '分组名称不能重复!' + } + : { + text: '分类', + nameInput: '分类名称', + nameInputPlaceholder: '请输入分类名称', + validateErrMsg: '分类名称不能重复!' + } + const state = reactive({ visible: false }) @@ -69,7 +88,7 @@ const formData = reactive({ name: '', categoryId: '' }) const validateGroup = (rule, value, callback) => { const isRepeat = props.initialValue?.name !== value && groupList.value.some((group) => group.name === value) if (isRepeat) { - callback(new Error('分类名称不能重复!')) + callback(new Error(groupLabels.validateErrMsg)) return } callback() @@ -86,6 +105,11 @@ const rules = reactive({ categoryId: [{ required: true, message: '必填', trigger: 'blur' }] }) +// 分组不需要填写表单id字段 +if (shouldReplaceCategoryWithGroup()) { + rules.categoryId = [] +} + const handleChangeName = (value) => { if (isEdit.value) { // 编辑时不允许修改id @@ -103,7 +127,7 @@ const handleChangeName = (value) => { formData.categoryId = id } -const title = computed(() => `${isEdit.value ? '编辑' : '新增'}分类`) +const title = computed(() => `${isEdit.value ? '编辑' : '新增'}${groupLabels.text}`) const closeDialog = () => { emit('update:modelValue', false) diff --git a/packages/plugins/block/src/Main.vue b/packages/plugins/block/src/Main.vue index 7000b3f84..aa4a2d5c5 100644 --- a/packages/plugins/block/src/Main.vue +++ b/packages/plugins/block/src/Main.vue @@ -16,7 +16,7 @@ ref="groupSelect" v-model="state.categoryId" popper-class="block-popper" - placeholder="默认展示全部分类" + :placeholder="groupLabels.selectPlaceholder" filterable :filter-method="categoryFilter" clearable @@ -48,7 +48,7 @@
- 您确定删除该区块分类吗? + {{ groupLabels.deletePrompt }}