Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:增加预览、保存apis #800

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions packages/canvas/render/src/RenderMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
setContext,
getContext,
setCondition,
getCondition,
context,
setNode
} from './context'
Expand Down Expand Up @@ -440,6 +441,7 @@ export const api = {
getRoot,
setPagecss,
setCondition,
getCondition,
getGlobalState,
getDataSourceMap,
setDataSourceMap,
Expand Down
2 changes: 2 additions & 0 deletions packages/canvas/render/src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ export const getContext = () => context
export const setCondition = (id, visible = false) => {
conditions[id] = visible
}

export const getCondition = () => conditions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以加末尾换行

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

26 changes: 17 additions & 9 deletions packages/settings/events/src/components/BindEventsDialog.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<template>
<tiny-dialog-box
v-show="dialogVisible"
:visible="dialogVisible"
title="事件绑定"
width="50%"
:append-to-body="true"
@close="closeDialog"
@opened="openedDialog"
>
<div class="bind-event-dialog-content">
<component :is="BindEventsDialogSidebar" :eventBinding="eventBinding"></component>
<component :is="BindEventsDialogSidebar" :dialogVisible="dialogVisible" :eventBinding="eventBinding"></component>
<component :is="BindEventsDialogContent" :dialogVisible="dialogVisible"></component>
</div>
<template #footer>
Expand All @@ -27,6 +27,7 @@ import {
useCanvas,
useHistory,
useLayout,
getOptions,
getMetaApi,
META_APP
} from '@opentiny/tiny-engine-meta-register'
Expand Down Expand Up @@ -167,7 +168,7 @@ export default {
})
}

const confirm = () => {
const confirm = async () => {
if (state.tipError) {
return
}
Expand All @@ -189,13 +190,20 @@ export default {

// 需要在bindMethod之后
const functionBody = getFunctionBody()

saveMethod?.({
name: state.bindMethodInfo.name,
const { name } = state.bindMethodInfo
const method = {
name,
content: state.enableExtraParams
? `function ${state.bindMethodInfo.name}(eventArgs,${formatParams}) ${functionBody}`
: `function ${state.bindMethodInfo.name}(${formatParams}) ${functionBody}`
})
? `function ${name}(eventArgs,${formatParams}) ${functionBody}`
: `function ${name}(${formatParams}) ${functionBody}`
}
const { beforeSaveMethod } = getOptions(meta.id)

if (typeof beforeSaveMethod === 'function') {
await beforeSaveMethod(method, state.bindMethodInfo)
}

saveMethod?.(method)

activePagePlugin()
close()
Expand Down
23 changes: 21 additions & 2 deletions packages/toolbars/preview/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import { Popover } from '@opentiny/vue'
import { previewPage, previewBlock } from '@opentiny/tiny-engine-common/js/preview'
import { useBlock, useCanvas, useLayout, useNotify } from '@opentiny/tiny-engine-meta-register'
import { getMergeMeta } from '@opentiny/tiny-engine-meta-register'
import { getMergeMeta, getOptions } from '@opentiny/tiny-engine-meta-register'
import meta from '../meta'

export default {
components: {
Expand All @@ -34,7 +35,21 @@ export default {
const { isBlock, getCurrentPage, canvasApi } = useCanvas()
const { getCurrentBlock } = useBlock()

const preview = () => {
const preview = async () => {
const { beforePreview, previewMethod, afterPreview } = getOptions(meta.id)

if (typeof beforePreview === 'function') {
await beforePreview()
}

if (typeof previewMethod === 'function') {
const stop = await previewMethod()

if(stop) {
return
}
}

if (useLayout().isEmptyPage()) {
useNotify({
type: 'warning',
Expand Down Expand Up @@ -63,6 +78,10 @@ export default {
params.pageInfo.name = page?.name
previewPage(params)
}

if (typeof afterPreview === 'function') {
await afterPreview()
}
}

return {
Expand Down
28 changes: 25 additions & 3 deletions packages/toolbars/save/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@
import { reactive, ref, onUnmounted } from 'vue'
import { VueMonaco } from '@opentiny/tiny-engine-common'
import { Button, Popover, DialogBox, Checkbox, Select } from '@opentiny/vue'
import { getOptions } from '@opentiny/tiny-engine-meta-register'
import { openCommon, saveCommon } from './js/index'
import { isLoading } from './js/index'
import meta from '../meta'
export const api = {
saveCommon,
openCommon
Expand Down Expand Up @@ -102,9 +104,29 @@ export default {
state.visible = false
state.originalCode = ''
}
const openApi = () => {
if (!isLoading.value) {
openCommon()
const openApi = async () => {
if (isLoading.value) {
return
}

const { beforeSave, saveMethod, saved } = getOptions(meta.id)

if (typeof beforeSave === 'function') {
await beforeSave()
}

let stop = false

if (typeof saveMethod === 'function') {
stop = await saveMethod()
}

if (!stop) {
await openCommon()
}

if (typeof saved === 'function') {
await saved()
}
}
const saveApi = () => {
Expand Down
22 changes: 22 additions & 0 deletions packages/toolbars/save/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import {
useLayout,
useNotify,
usePage,
getOptions,
getMetaApi,
META_APP
} from '@opentiny/tiny-engine-meta-register'
import { constants } from '@opentiny/tiny-engine-utils'
import { handlePageUpdate } from '@opentiny/tiny-engine-common/js/http'
import meta from '../../meta'

const { PAGE_STATUS } = constants
const state = reactive({
Expand Down Expand Up @@ -95,6 +97,22 @@ export const openCommon = async () => {
return
}

const { beforeSave, saveMethod, saved } = getOptions(meta.id)

if (typeof beforeSave === 'function') {
await beforeSave()
}

let stop = false

if (typeof saveMethod === 'function') {
stop = await saveMethod()
}

if (!stop) {
await openCommon()
}

const pageStatus = useLayout().layoutState?.pageStatus
const curPageState = pageStatus?.state
const pageInfo = pageStatus?.data
Expand Down Expand Up @@ -138,5 +156,9 @@ export const openCommon = async () => {

saveCommon(state.code).finally(() => {
state.disabled = false

if (typeof saved === 'function') {
saved()
}
})
}