Skip to content

Commit

Permalink
feat:增加预览、保存apis
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoyun8 committed Sep 14, 2024
1 parent 80a36d6 commit f4ecc76
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 14 deletions.
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
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)

Check failure on line 39 in packages/toolbars/preview/src/Main.vue

View workflow job for this annotation

GitHub Actions / push-check

'afterPreview' is assigned a value but never used. Allowed unused vars must match /^_/u
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 previewed === 'function') {
await previewed()

Check failure on line 83 in packages/toolbars/preview/src/Main.vue

View workflow job for this annotation

GitHub Actions / push-check

'previewed' is not defined
}
}
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()
}
})
}

0 comments on commit f4ecc76

Please sign in to comment.