From d936d2bdde3cad620ec242d944ea5cc1909ef127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Tue, 18 Aug 2020 21:36:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8C=BA=E5=9D=97=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: 修改 currentPage 逻辑 --- packages/designer/src/component-meta.ts | 6 +++--- .../designer/src/document/document-model.ts | 2 -- packages/editor-preset-vision/src/pages.ts | 15 ++++++++++----- .../editor-preset-vision/src/util/index.ts | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 packages/editor-preset-vision/src/util/index.ts diff --git a/packages/designer/src/component-meta.ts b/packages/designer/src/component-meta.ts index 27b145d68..64c1239d7 100644 --- a/packages/designer/src/component-meta.ts +++ b/packages/designer/src/component-meta.ts @@ -208,13 +208,13 @@ export class ComponentMeta { return result as any; } - isRootComponent() { - return this.componentName === 'Page' || this.componentName === 'Block' || this.componentName === 'Component'; + isRootComponent(includeBlock: boolean = true) { + return this.componentName === 'Page' || this.componentName === 'Component' || (includeBlock && this.componentName === 'Block'); } @computed get availableActions() { let { disableBehaviors, actions } = this._transformedMetadata?.configure.component || {}; - const disabled = ensureAList(disableBehaviors) || (this.isRootComponent() ? ['copy', 'remove'] : null); + const disabled = ensureAList(disableBehaviors) || (this.isRootComponent(false) ? ['copy', 'remove'] : null); actions = builtinComponentActions.concat(this.designer.getGlobalComponentActions() || [], actions || []); if (disabled) { diff --git a/packages/designer/src/document/document-model.ts b/packages/designer/src/document/document-model.ts index dbd9f5713..77f3cee83 100644 --- a/packages/designer/src/document/document-model.ts +++ b/packages/designer/src/document/document-model.ts @@ -105,8 +105,6 @@ export class DocumentModel { if (!schema) { this._blank = true; - } else { - this.id = project.getSchema()?.id || this.id; } this.rootNode = this.createNode( diff --git a/packages/editor-preset-vision/src/pages.ts b/packages/editor-preset-vision/src/pages.ts index 65b2cd05c..c50b95ee0 100644 --- a/packages/editor-preset-vision/src/pages.ts +++ b/packages/editor-preset-vision/src/pages.ts @@ -1,7 +1,8 @@ -import { designer } from './editor'; import { RootSchema } from '@ali/lowcode-types'; import { DocumentModel } from '@ali/lowcode-designer'; +import { designer } from './editor'; import NodeCacheVisitor from './rootNodeVisitor'; +import { getFormUuid } from './util'; const { project } = designer; @@ -51,8 +52,7 @@ const pages = Object.assign(project, { project.load({ version: '1.0.0', componentsMap: [], - componentsTree, - id: pages[0].id, + componentsTree }, true); // FIXME: 根本原因应该是 propStash 导致的,这样可以避免页面加载之后就被标记为 isModified @@ -86,7 +86,12 @@ const pages = Object.assign(project, { page.active(); }, getCurrentPage() { - return project.currentDocument; + if (!project.currentDocument) { + return null; + } + const currentPage = { ...project.currentDocument, id: getFormUuid() }; + Object.setPrototypeOf(currentPage, Object.getPrototypeOf(project.currentDocument || {})); + return currentPage; }, onPagesChange() { // noop @@ -101,7 +106,7 @@ const pages = Object.assign(project, { Object.defineProperty(pages, 'currentPage', { get() { - return project.currentDocument; + return pages.getCurrentPage(); } }) diff --git a/packages/editor-preset-vision/src/util/index.ts b/packages/editor-preset-vision/src/util/index.ts new file mode 100644 index 000000000..b1ad217e9 --- /dev/null +++ b/packages/editor-preset-vision/src/util/index.ts @@ -0,0 +1,18 @@ +function getUrlParameter(sParam: string) { + var sPageURL = window.location.search.substring(1), + sURLVariables = sPageURL.split('&'), + sParameterName, + i; + + for (i = 0; i < sURLVariables.length; i++) { + sParameterName = sURLVariables[i].split('='); + + if (sParameterName[0] === sParam) { + return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); + } + } +}; + +export function getFormUuid() { + return getUrlParameter('formUuid'); +} \ No newline at end of file