Skip to content

Commit

Permalink
fix: breadcrumb publish block cannot get correct version
Browse files Browse the repository at this point in the history
  • Loading branch information
chilingling committed Dec 27, 2024
1 parent 7f05029 commit 1517440
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 65 deletions.
73 changes: 50 additions & 23 deletions packages/common/component/BlockDeployDialog.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<tiny-dialog-box
:visible="$attrs.visible"
:visible="visible"
title="发布区块"
width="550px"
append-to-body
Expand Down Expand Up @@ -80,7 +80,7 @@ import {
Popover as TinyPopover,
FormItem as TinyFormItem
} from '@opentiny/vue'
import { useNotify, useCanvas, getMetaApi, META_APP, useBlock } from '@opentiny/tiny-engine-meta-register'
import { useNotify, getMetaApi, META_APP } from '@opentiny/tiny-engine-meta-register'
import { constants } from '@opentiny/tiny-engine-utils'
import VueMonaco from './VueMonaco.vue'
Expand All @@ -96,13 +96,17 @@ export default {
VueMonaco
},
props: {
nextVersion: {
type: String,
default: ''
block: {
type: Object,
default: () => ({})
},
visible: {
type: Boolean,
default: false
}
},
emits: ['update:visible'],
setup(props, { emit, attrs }) {
emits: ['update:visible', 'changeSchema'],
setup(props, { emit }) {
const { COMPONENT_NAME } = constants
const formState = reactive({
deployInfo: '',
Expand Down Expand Up @@ -137,23 +141,43 @@ export default {
}
}
const getNextVersion = (block) => {
const backupList = block.backupList || []
let latestVersion = '1.0.0'
let latestTime = 0
backupList.forEach((v) => {
const vTime = new Date(v.created_at).getTime()
if (vTime > latestTime) {
latestTime = vTime
latestVersion = v.version
}
})
// version 符合X.Y.Z的字符结构
return latestVersion.replace(/\d+$/, (match) => Number(match) + 1)
}
watch(
() => attrs.visible,
() => props.visible,
(visible) => {
if (visible && !formState.version) {
formState.version = props.nextVersion
if (!visible) {
return
}
formState.version = getNextVersion(props.block)
}
)
const setVisible = (visible) => emit('update:visible', visible)
const deployBlock = async () => {
deployBlockRef.value.validate((valid) => {
const { getEditBlock, publishBlock } = getMetaApi(META_APP.BlockManage)
const { publishBlock } = getMetaApi(META_APP.BlockManage)
if (valid) {
const params = {
block: getEditBlock() || useBlock().getCurrentBlock(),
block: props.block,
is_compile: true,
deploy_info: formState.deployInfo,
version: formState.version,
Expand All @@ -170,21 +194,23 @@ export default {
const changeCompare = async (value) => {
const api = getMetaApi(META_APP.BlockManage)
if (value) {
const block = api.getEditBlock()
const block = props.block
const remote = await api.getBlockById(block?.id)
const originalObj = remote?.content || {}
state.originalCode = JSON.stringify(originalObj, null, 2)
const getSchema = useCanvas().getSchema
// const getSchema = useCanvas().getSchema
// 转为普通对象,和线上代码顺序保持一致
const pageSchema = getSchema?.() || {}
if (pageSchema.componentName === 'Block') {
state.code = JSON.stringify(pageSchema, null, 2)
} else {
// 非区块编辑
state.code = state.originalCode
}
// const pageSchema = getSchema?.() || {}
// if (pageSchema.componentName === 'Block') {
// state.code = JSON.stringify(pageSchema, null, 2)
// } else {
// // 非区块编辑
// }
state.code = block?.content || {}
state.compareVisible = true
}
}
Expand All @@ -207,8 +233,9 @@ export default {
return
}
try {
const pageSchema = JSON.parse(state.newCode)
useCanvas().importSchema({ ...pageSchema, componentName: COMPONENT_NAME.Block })
const newSchema = JSON.parse(state.newCode)
// useCanvas().importSchema({ ...pageSchema, componentName: COMPONENT_NAME.Block })
emit('changeSchema', { ...newSchema, componentName: COMPONENT_NAME.Block })
close()
} catch (err) {
useNotify({
Expand Down
53 changes: 32 additions & 21 deletions packages/plugins/block/src/BlockSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,17 @@
</tiny-collapse>
</template>
</plugin-setting>
<block-deploy-dialog v-model:visible="state.showDeployBlock" :nextVersion="nextVersion"></block-deploy-dialog>
<block-deploy-dialog
v-model:visible="state.showDeployBlock"
:block="editBlock"
@changeSchema="handleChangeSchema"
></block-deploy-dialog>
</template>

<script lang="jsx">
import { reactive, ref, watch, watchEffect, computed } from 'vue'
import { Button as TinyButton, Collapse as TinyCollapse, CollapseItem as TinyCollapseItem } from '@opentiny/vue'
import { useModal } from '@opentiny/tiny-engine-meta-register'
import { getMergeMeta, useBlock } from '@opentiny/tiny-engine-meta-register'
import { useModal, getMergeMeta, useBlock, useCanvas } from '@opentiny/tiny-engine-meta-register'
import { BlockHistoryList, PluginSetting, CloseIcon, SvgButton, ButtonGroup } from '@opentiny/tiny-engine-common'
import { previewBlock } from '@opentiny/tiny-engine-common/js/preview'
import { LifeCycles } from '@opentiny/tiny-engine-common'
Expand Down Expand Up @@ -152,22 +155,22 @@ export default {
})
// 按时间最新提交的版本的修订版本号+1, 提示输入的下一个版本
const nextVersion = computed(() => {
const backupList = state.backupList || []
let latestVersion = '1.0.0'
let latestTime = 0
backupList.forEach((v) => {
const vTime = new Date(v.created_at).getTime()
if (vTime > latestTime) {
latestTime = vTime
latestVersion = v.version
}
})
// version 符合X.Y.Z的字符结构
return latestVersion.replace(/\d+$/, (match) => Number(match) + 1)
})
// const nextVersion = computed(() => {
// const backupList = state.backupList || []
// let latestVersion = '1.0.0'
// let latestTime = 0
// backupList.forEach((v) => {
// const vTime = new Date(v.created_at).getTime()
// if (vTime > latestTime) {
// latestTime = vTime
// latestVersion = v.version
// }
// })
// // version 符合X.Y.Z的字符结构
// return latestVersion.replace(/\d+$/, (match) => Number(match) + 1)
// })
watch(
() => {
Expand Down Expand Up @@ -264,10 +267,17 @@ export default {
setConfigItemVisible(false)
}
const handleChangeSchema = (newSchema) => {
// 如果是当前正在画布编辑的区块,需要重新 importSchema
if (getEditBlock()?.id === useBlock().getCurrentBlock()?.id) {
useCanvas().importSchema(newSchema)
}
}
return {
state,
isOpen,
nextVersion,
// nextVersion,
showDeployBlockDialog,
closePanel,
deleteBlock,
Expand All @@ -279,7 +289,8 @@ export default {
globalConfig: getMergeMeta('engine.config'),
onMouseLeave,
handleClick,
handleShowGuide
handleShowGuide,
handleChangeSchema
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/block/src/composable/useBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ const initBlock = async (block = {}, _langs = {}, isEdit) => {
block.content = getSchema()

setCurrentBlock(block)
setBreadcrumbBlock([block[nameCn] || block.label], block.histories)
setBreadcrumbBlock([block[nameCn] || block.label])

// 如果是点击区块管理列表进来的则不需要执行以下操作
if (!isEdit) {
Expand Down
48 changes: 30 additions & 18 deletions packages/toolbars/breadcrumb/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@
>发布区块
</tiny-button>
</div>
<block-deploy-dialog v-model:visible="state.showDeployBlock" :nextVersion="nextVersion"></block-deploy-dialog>
<block-deploy-dialog
v-model:visible="state.showDeployBlock"
:block="currentBlock"
@changeSchema="handleChangeSchema"
></block-deploy-dialog>
</template>
</toolbar-base>
</template>

<script>
import { reactive, computed } from 'vue'
import { Breadcrumb, BreadcrumbItem, Button } from '@opentiny/vue'
import { useBreadcrumb, useLayout } from '@opentiny/tiny-engine-meta-register'
import { useBreadcrumb, useLayout, useBlock, useCanvas } from '@opentiny/tiny-engine-meta-register'
import { ToolbarBase } from '@opentiny/tiny-engine-common'
import { BlockDeployDialog } from '@opentiny/tiny-engine-common'
Expand Down Expand Up @@ -68,36 +72,44 @@ export default {
state.showDeployBlock = true
}
const nextVersion = computed(() => {
const backupList = getBreadcrumbData().value[2] || []
// const nextVersion = computed(() => {
// const backupList = getBreadcrumbData().value[2] || []
let latestVersion = '1.0.0'
let latestTime = 0
backupList.forEach((v) => {
const vTime = new Date(v.created_at).getTime()
// let latestVersion = '1.0.0'
// let latestTime = 0
// backupList.forEach((v) => {
// const vTime = new Date(v.created_at).getTime()
if (vTime > latestTime) {
latestTime = vTime
latestVersion = v.version
}
})
// if (vTime > latestTime) {
// latestTime = vTime
// latestVersion = v.version
// }
// })
// version 符合X.Y.Z的字符结构
return latestVersion.replace(/\d+$/, (match) => Number(match) + 1)
})
// // version 符合X.Y.Z的字符结构
// return latestVersion.replace(/\d+$/, (match) => Number(match) + 1)
// })
const open = () => {
if (!plugins) return
plugins.render = breadcrumbData.value[0] === CONSTANTS.PAGETEXT ? PLUGINS_ID.PAGEID : PLUGINS_ID.BLOCKID
}
const currentBlock = computed(useBlock().getCurrentBlock())
const handleChangeSchema = (newSchema) => {
useCanvas().importSchema(newSchema)
}
return {
breadcrumbData,
publishBlock,
state,
nextVersion,
// nextVersion,
CONSTANTS,
open
open,
currentBlock,
handleChangeSchema
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/toolbars/breadcrumb/src/composable/useBreadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const setBreadcrumbPage = (value) => {
sessionStorage.setItem('pageInfo', value)
}

const setBreadcrumbBlock = (value, histories = []) => {
breadcrumbData.value = [CONSTANTS.BLOCKTEXT, ...value, histories]
const setBreadcrumbBlock = (value) => {
breadcrumbData.value = [CONSTANTS.BLOCKTEXT, ...value]
}

const getBreadcrumbData = () => breadcrumbData
Expand Down

0 comments on commit 1517440

Please sign in to comment.