Skip to content

Commit

Permalink
fix(toolbars): disable toolbar btn when page is empty (#70)
Browse files Browse the repository at this point in the history
* fix(toolbars): disable toolbar btn when page is empty

* fix(toolbar): disable preview when page is empty
  • Loading branch information
chilingling authored Nov 8, 2023
1 parent cb8414d commit 213e7d8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 20 deletions.
28 changes: 17 additions & 11 deletions packages/controller/src/useLayout.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/

import { reactive, nextTick } from 'vue'
import { constants } from '@opentiny/tiny-engine-utils'

const { PAGE_STATUS } = constants

const PLUGIN_NAME = {
Materials: 'Materials',
Expand Down Expand Up @@ -111,6 +114,8 @@ const getDimension = () => layoutState.dimension

const getPluginState = () => layoutState.plugins

const isEmptyPage = () => layoutState.pageStatus?.state === PAGE_STATUS.Empty

export default () => {
return {
PLUGIN_NAME,
Expand All @@ -124,6 +129,7 @@ export default () => {
registerPluginApi,
getPluginApi,
getPluginState,
pluginState
pluginState,
isEmptyPage
}
}
10 changes: 9 additions & 1 deletion packages/toolbars/generate-vue/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<script>
import { reactive } from 'vue'
import { Popover } from '@opentiny/vue'
import { getGlobalConfig, useBlock, useCanvas, useNotify } from '@opentiny/tiny-engine-controller'
import { getGlobalConfig, useBlock, useCanvas, useNotify, useLayout } from '@opentiny/tiny-engine-controller'
import { fs } from '@opentiny/tiny-engine-utils'
import { getSchema } from '@opentiny/tiny-engine-canvas'
import { generateVuePage, generateVueBlock } from './generateCode'
Expand Down Expand Up @@ -115,6 +115,14 @@ export default {
}
const generate = async () => {
const { isEmptyPage } = useLayout()
if (isEmptyPage()) {
useNotify({ type: 'warning', message: '请先创建页面' })
return
}
if (state.generating) {
useNotify({ type: 'info', title: '代码生成中, 请稍后...' })
return
Expand Down
15 changes: 11 additions & 4 deletions packages/toolbars/preview/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
<script>
import { Popover } from '@opentiny/vue'
import { previewPage, previewBlock } from '@opentiny/tiny-engine-common/js/preview'
import { getGlobalConfig, useBlock, useCanvas } from '@opentiny/tiny-engine-controller'
import { getGlobalConfig, useBlock, useCanvas, useLayout, useNotify } from '@opentiny/tiny-engine-controller'
import { getSchema } from '@opentiny/tiny-engine-canvas'
import { PublicIcon } from '@opentiny/tiny-engine-common'
export default {
components: {
TinyPopover: Popover,
PublicIcon
TinyPopover: Popover
},
props: {
icon: {
Expand All @@ -37,6 +35,15 @@ export default {
const { getCurrentBlock } = useBlock()
const preview = () => {
if (useLayout().isEmptyPage()) {
useNotify({
type: 'warning',
message: '请先创建页面'
})
return
}
const params = {
framework: getGlobalConfig()?.dslMode,
platform: getGlobalConfig()?.platformId,
Expand Down
6 changes: 5 additions & 1 deletion packages/toolbars/refresh/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default {
setup() {
const { confirm } = useModal()
const { isBlock, isSaved, pageState, initData } = useCanvas()
const { PLUGIN_NAME, activePlugin } = useLayout()
const { PLUGIN_NAME, activePlugin, isEmptyPage } = useLayout()
const { getCurrentBlock, initBlock } = useBlock()
const refreshResouce = () => {
Expand All @@ -52,6 +52,10 @@ export default {
}
const refreshPage = async () => {
if (isEmptyPage()) {
return
}
const { currentPage } = pageState
const api = await activePlugin(PLUGIN_NAME.AppManage, true)
const page = await api.getPageById(currentPage.id)
Expand Down
19 changes: 16 additions & 3 deletions packages/toolbars/setting/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<script lang="jsx">
import { Popover } from '@opentiny/vue'
import { useCanvas, useLayout, useBlock, usePage, useModal } from '@opentiny/tiny-engine-controller'
import { useCanvas, useLayout, useBlock, usePage, useModal, useNotify } from '@opentiny/tiny-engine-controller'
import { constants } from '@opentiny/tiny-engine-utils'
const { PAGE_STATUS } = constants
Expand All @@ -36,7 +36,7 @@ export default {
const { pageState, isBlock } = useCanvas()
const { getCurrentBlock } = useBlock()
const { initCurrentPageData, isChangePageData } = usePage()
const { PLUGIN_NAME, activePlugin, layoutState } = useLayout()
const { PLUGIN_NAME, activePlugin, layoutState, isEmptyPage } = useLayout()
const { confirm, message } = useModal()
const openBlockSetting = () => {
Expand Down Expand Up @@ -79,7 +79,20 @@ export default {
})
}
const openSetting = () => (isBlock() ? openBlockSetting() : openPageSetting())
const openSetting = () => {
if (isEmptyPage()) {
useNotify({ type: 'warning', message: '请先创建页面' })
return
}
if (isBlock()) {
openBlockSetting()
return
}
openPageSetting()
}
return {
openSetting,
Expand Down

0 comments on commit 213e7d8

Please sign in to comment.