fix:loading can't be closed when state is saved (#87)

* fix:loading can't be closed when state is saved

* fix: remove global loading
This commit is contained in:
yaoyun8 2023-11-16 03:01:33 -08:00 committed by GitHub
parent 9911abe6de
commit ac4b52ce13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 28 deletions

View File

@ -395,8 +395,9 @@ export default {
//
if (oldValue !== variableContent) {
const { pageState } = useCanvas()
pageState.isSaved = false
const { setSaved } = useCanvas()
setSaved(false)
variableContent = formatString(variableContent, 'javascript')
}

View File

@ -20,7 +20,7 @@ import { getGlobalConfig } from './globalConfig'
const bridge = window.vscodeBridge
const confirmSaveLocal = async () => {
const { pageState } = useCanvas()
const { pageState, setSaved } = useCanvas()
const currentPageId = pageState.currentPageId || pageState.currentPage.id
const currentPageName = pageState.currentPageName || pageState.currentPage.name
@ -42,7 +42,7 @@ const confirmSaveLocal = async () => {
const message = savePage.data.isSuccess ? '保存文件到本地成功' : errorMsg
savePage.data.isSuccess && (pageState.isSaved = true)
savePage.data.isSuccess && setSaved(true)
Modal.message({ message, status: 'error', duration: '5000', top: 60 })
}

View File

@ -189,7 +189,7 @@ export default {
//
add(name, variable)
isPanelShow.value = false
useCanvas().pageState.isSaved = false
setSaved(false)
//
setState({ [name]: variable })

View File

@ -113,7 +113,7 @@ const saveMethods = () => {
saveMethod({ name, content })
})
useCanvas().pageState.isSaved = false
useCanvas().setSaved(false)
state.isChanged = false
useNotify({
type: 'success',

View File

@ -10,13 +10,13 @@
*
*/
import { reactive, ref } from 'vue'
import { useBlock, useCanvas, useLayout, useNotify, usePage } from '@opentiny/tiny-engine-controller'
import { getSchema, setSchema } from '@opentiny/tiny-engine-canvas'
import { constants } from '@opentiny/tiny-engine-utils'
import { reactive, ref, watch } from 'vue'
import { Loading } from '@opentiny/vue'
const { pageState, isSaved, isBlock } = useCanvas()
import { handlePageUpdate } from '@opentiny/tiny-engine-common/js/http'
const { pageState, isSaved, isBlock } = useCanvas()
const { PLUGIN_NAME, getPluginApi } = useLayout()
const { getCurrentBlock } = useBlock()
const { PAGE_STATUS } = constants
@ -27,7 +27,9 @@ const state = reactive({
originalCode: '',
disabled: false
})
export const isLoading = ref(false)
// 保存或新建区块
const saveBlock = async (pageSchema) => {
const api = getPluginApi(PLUGIN_NAME.BlockManage)
@ -48,6 +50,7 @@ const savePage = async (pageSchema) => {
const params = {
page_content: pageSchema
}
isLoading.value = true
await handlePageUpdate(currentPage.id, { ...currentPage, ...params })
isLoading.value = false
@ -55,29 +58,35 @@ const savePage = async (pageSchema) => {
export const saveCommon = (value) => {
const pageSchema = JSON.parse(value)
pageState.pageSchema = pageSchema
// setSchema 是异步,保存直接传递当前 schema
setSchema(pageSchema)
if (pageSettingState?.isAIPage) {
if (isTemporaryPage.saved) {
isTemporaryPage.saved = false
}
// 如果当前页面没有ID为临时生成的页面则打开新建页面面板
isTemporaryPage.saved = true
const pageContent = 'page_content'
pageSettingState.currentPageData[pageContent] = pageSchema
return
}
isBlock() ? saveBlock(pageSchema) : savePage(pageSchema)
return isBlock() ? saveBlock(pageSchema) : savePage(pageSchema)
}
export const openCommon = async () => {
if (isSaved() || state.disabled) {
return
}
const pageStatus = useLayout().layoutState?.pageStatus
const curPageState = pageStatus?.state
const pageInfo = pageStatus?.data
const ERR_MSG = {
[PAGE_STATUS.Release]: '当前页面未锁定,请先锁定再保存',
[PAGE_STATUS.Empty]: '当前应用无页面,请先新建页面再保存',
@ -96,13 +105,9 @@ export const openCommon = async () => {
}
state.disabled = true
let loadingInstance = Loading.service({
lock: true,
text: '保存中',
background: 'rgba(0, 0, 0, 0.5)'
})
const pageSchema = getSchema()
state.code = JSON.stringify(pageSchema || {}, null, 2)
// 获取请求前schema代码暂时先屏蔽
@ -119,17 +124,7 @@ export const openCommon = async () => {
}
*/
saveCommon(state.code)
if (isLoading.value) {
saveCommon(state.code).finally(() => {
state.disabled = false
}
watch(
() => pageState.isSaved,
(value) => {
if (value) {
loadingInstance.close()
}
}
)
})
}