Skip to content

Commit

Permalink
fix: JS面板保存后直接上传到服务器,减少一次页面保存的点击操作。和保存页面状态的逻辑保持一致
Browse files Browse the repository at this point in the history
  • Loading branch information
gene9831 committed Feb 20, 2024
1 parent 96def94 commit 02a8ccc
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/plugins/script/src/js/method.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import { ref, reactive, watchEffect, onActivated, nextTick } from 'vue'
import { useCanvas, useModal, useNotify } from '@opentiny/tiny-engine-controller'
import { useCanvas, useLayout, useModal } from '@opentiny/tiny-engine-controller'
import { string2Ast, ast2String, insertName, formatString } from '@opentiny/tiny-engine-common/js/ast'
import { constants } from '@opentiny/tiny-engine-utils'
import { getSchema } from '@opentiny/tiny-engine-canvas'
Expand Down Expand Up @@ -81,12 +81,23 @@ export const saveMethod = ({ name, content }) => {
methods[name].value = content
}

const tryString2Ast = (content) => {
try {
return string2Ast(content)
} catch (error) {
return null
}
}

const saveMethods = () => {
if (!state.isChanged) {
return false
}

if (state.hasError) {
const editorContent = monaco.value.getEditor().getValue()
const ast = tryString2Ast(editorContent)

if (state.hasError || !ast) {
message({
status: 'error',
message: '代码静态检查有错误,请先修改后再保存'
Expand All @@ -95,8 +106,6 @@ const saveMethods = () => {
return false
}

const editorContent = monaco.value.getEditor().getValue()
const ast = string2Ast(editorContent)
getSchema().methods = {}

ast.program.body.forEach((declaration, index) => {
Expand All @@ -116,10 +125,9 @@ const saveMethods = () => {
})
useCanvas().setSaved(false)
state.isChanged = false
useNotify({
type: 'success',
message: '保存成功!'
})

const { PLUGIN_NAME, getPluginApi } = useLayout()
getPluginApi(PLUGIN_NAME.save).openCommon()

return true
}
Expand Down

0 comments on commit 02a8ccc

Please sign in to comment.