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
5 changes: 5 additions & 0 deletions packages/canvas/DesignCanvas/src/api/useCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ const initData = (schema = { ...defaultSchema }, currentPage) => {
})
}

publish({
topic: 'pageOrBlockInit',
data: schema
})

useHistory().addHistory(schema)
}

Expand Down
6 changes: 6 additions & 0 deletions packages/plugins/block/src/composable/useBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
useTranslate,
useBreadcrumb,
useLayout,
useMessage,
getMetaApi,
META_APP,
getMergeMeta,
Expand Down Expand Up @@ -297,6 +298,11 @@ const initBlock = async (block = {}, _langs = {}, isEdit) => {
addBlock(block)
setSaved(false)
}

useMessage().publish({
topic: 'pageOrBlockInit',
data: block.content
})
}

const createBlock = ({ name_cn, label, path, categories }) => {
Expand Down
3 changes: 0 additions & 3 deletions packages/toolbars/redoundo/src/composable/useHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,12 @@ const go = (addend, valid) => {
const back = () => {
if (historyState.back) {
go(-1)
useCanvas().setSaved(false)
}
}

const forward = () => {
if (historyState.forward) {
go(1)
useCanvas().setSaved(historyState.index === list.length - 1)
}
}

Expand All @@ -95,7 +93,6 @@ const clear = () => {

const addHistory = (schema) => {
if (!schema) {
useCanvas().setSaved(false)
push(useCanvas().getSchema())
} else {
clear()
Expand Down
56 changes: 51 additions & 5 deletions packages/toolbars/save/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import { reactive, ref, onUnmounted, onMounted } from 'vue'
import { VueMonaco } from '@opentiny/tiny-engine-common'
import { Button, Popover, DialogBox, Checkbox, Select } from '@opentiny/vue'
import { useCanvas } from '@opentiny/tiny-engine-meta-register'
import { useCanvas, useMessage } from '@opentiny/tiny-engine-meta-register'
import { ToolbarBase } from '@opentiny/tiny-engine-common'
import { openCommon, saveCommon } from './js/index'
import { isLoading, setAutoSaveStatus, getAutoSaveStatus } from './js/index'
Expand Down Expand Up @@ -90,8 +90,6 @@ export default {
}
},
setup() {
const { isSaved } = useCanvas()

const delayOptions = [
{ value: 5, label: '5分钟' },
{ value: 10, label: '10分钟' },
Expand All @@ -101,14 +99,62 @@ export default {
visible: false,
code: '',
originalCode: '',
disabled: false,
timeValue: 5,
checked: false,
timeValue: 5,
preservationTime: null
})

const editor = ref(null)

const { isSaved, setSaved, getSchema } = useCanvas()

const { subscribe, unsubscribe } = useMessage()
const subscriber = 'toolbar-save'

const originSchema = ref(null)

onMounted(() => {
// 订阅页面/区块初始化事件
subscribe({
topic: 'pageOrBlockInit',
subscriber,
callback: (schema) => {
originSchema.value = JSON.stringify(schema)
setSaved(true) // 初始化时标记为已保存
}
})

// 订阅 schema 变更事件
subscribe({
topic: 'schemaChange',
subscriber,
callback: () => {
if (originSchema.value) {
const hasChange = JSON.stringify(getSchema()) === originSchema.value
setSaved(hasChange)
}
}
})

// 订阅 schema 导入事件
subscribe({
topic: 'schemaImport',
subscriber,
callback: () => {
if (originSchema.value) {
const hasChange = JSON.stringify(getSchema()) === originSchema.value
setSaved(hasChange)
}
}
})
})

onUnmounted(() => {
unsubscribe({ topic: 'pageOrBlockInit', subscriber })
unsubscribe({ topic: 'schemaChange', subscriber })
unsubscribe({ topic: 'schemaImport', subscriber })
})

const close = () => {
state.visible = false
state.originalCode = ''
Expand Down