feat(designer): add blank page logic

This commit is contained in:
kangwei 2020-03-31 01:54:29 +08:00
parent 968febe6c9
commit aeeb9baf05
7 changed files with 81 additions and 30 deletions

View File

@ -59,6 +59,7 @@ export class DocumentModel {
} }
private _modalNode?: NodeParent; private _modalNode?: NodeParent;
private _blank?: boolean;
get modalNode() { get modalNode() {
return this._modalNode; return this._modalNode;
} }
@ -67,7 +68,7 @@ export class DocumentModel {
return this.modalNode || this.rootNode; return this.modalNode || this.rootNode;
} }
constructor(readonly project: Project, schema: RootSchema) { constructor(readonly project: Project, schema?: RootSchema) {
autorun(() => { autorun(() => {
this.nodes.forEach((item) => { this.nodes.forEach((item) => {
if (item.parent == null && item !== this.rootNode) { if (item.parent == null && item !== this.rootNode) {
@ -75,7 +76,16 @@ export class DocumentModel {
} }
}); });
}, true); }, true);
this.rootNode = this.createRootNode(schema);
if (!schema) {
this._blank = true;
}
this.rootNode = this.createRootNode(schema || {
componentName: 'Page',
fileName: ''
});
this.history = new History( this.history = new History(
() => this.schema, () => this.schema,
(schema) => this.import(schema as RootSchema, true), (schema) => this.import(schema as RootSchema, true),
@ -83,6 +93,10 @@ export class DocumentModel {
this.setupListenActiveNodes(); this.setupListenActiveNodes();
} }
@computed isBlank() {
return this._blank && !this.isModified();
}
readonly designer = this.project.designer; readonly designer = this.project.designer;
/** /**
@ -295,6 +309,7 @@ export class DocumentModel {
} }
private mountSimulator(simulator: ISimulatorHost) { private mountSimulator(simulator: ISimulatorHost) {
// TODO: 多设备 simulator 支持
this._simulator = simulator; this._simulator = simulator;
// TODO: emit simulator mounted // TODO: emit simulator mounted
} }
@ -386,7 +401,8 @@ export class DocumentModel {
* *
*/ */
remove() { remove() {
// todo: // this.project.removeDocument(this);
// todo: ...
} }
purge() { purge() {

View File

@ -1,5 +1,6 @@
{ {
"copy": "Copy", "copy": "Copy",
"remove": "Remove", "remove": "Remove",
"Condition Group": "Condition Group" "Condition Group": "Condition Group",
"No opened document": "No opened document, open some document to editing"
} }

View File

@ -1,5 +1,6 @@
{ {
"copy": "复制", "copy": "复制",
"remove": "删除", "remove": "删除",
"Condition Group": "条件组" "Condition Group": "条件组",
"No opened document": "没有打开的页面,请选择页面打开编辑"
} }

View File

@ -2,6 +2,7 @@ import { Component } from 'react';
import { observer } from '@ali/lowcode-globals'; import { observer } from '@ali/lowcode-globals';
import { Designer } from '../designer'; import { Designer } from '../designer';
import { DocumentView } from '../document'; import { DocumentView } from '../document';
import { intl } from '../locale';
import './project.less'; import './project.less';
@observer @observer
@ -9,14 +10,14 @@ export class ProjectView extends Component<{ designer: Designer }> {
render() { render() {
const { designer } = this.props; const { designer } = this.props;
// TODO: support splitview // TODO: support splitview
const opens = designer.project.documents.filter((doc) => doc.opened);
return ( return (
<div className="lc-project"> <div className="lc-project">
{designer.project.documents.map(doc => { {opens.length > 0 ? (
if (!doc.opened) { opens.map((doc) => <DocumentView key={doc.id} document={doc} />)
return null; ) : (
} <div className="lc-project-empty">{intl('No opened document')}</div>
return <DocumentView key={doc.id} document={doc} />; )}
})}
</div> </div>
); );
} }

View File

@ -4,6 +4,14 @@
right: 0; right: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
.lc-project-empty {
width: 100%;
height: 100%;
font-size: 16px;
text-align: center;
background: transparent url(//img.alicdn.com/tfs/TB1xLKQAbj1gK0jSZFuXXcrHpXa-90-90.png) center 30% no-repeat;
padding-top: 50%;
}
.lc-document { .lc-document {
width: 100%; width: 100%;
height: 100%; height: 100%;

View File

@ -14,11 +14,11 @@ export class Project {
// TODO: 考虑项目级别 History // TODO: 考虑项目级别 History
constructor(readonly designer: Designer, schema?: ProjectSchema) { constructor(readonly designer: Designer, schema?: ProjectSchema) {
this.setSchema(schema); this.load(schema);
} }
@computed get currentDocument() { @computed get currentDocument() {
return this.documents.find(doc => doc.actived); return this.documents.find((doc) => doc.actived);
} }
/** /**
@ -27,30 +27,45 @@ export class Project {
getSchema(): ProjectSchema { getSchema(): ProjectSchema {
return { return {
...this.data, ...this.data,
componentsTree: this.documents.map(doc => doc.schema), // todo: future change this filter
componentsTree: this.documents.filter((doc) => !doc.isBlank()).map((doc) => doc.schema),
}; };
} }
/** /**
* schema * schema
*
* @param autoOpen true string
*/ */
setSchema(schema?: ProjectSchema) { load(schema?: ProjectSchema, autoOpen?: boolean | string) {
this.unload();
// load new document
this.data = { this.data = {
version: '1.0.0', version: '1.0.0',
componentsMap: [], componentsMap: [],
componentsTree: [], componentsTree: [],
...schema, ...schema,
}; };
if (this.documents.length > 0) {
this.documents.forEach(doc => doc.purge()); if (autoOpen) {
this.documents.length = 0; if (autoOpen === true) {
// auto open first document or open a blank page
this.open(this.data.componentsTree[0]);
} else {
// auto open should be string of fileName
this.open(autoOpen);
}
} }
this.open( }
this.data.componentsTree[0] || {
componentName: 'Page', /**
fileName: '', *
}, */
); unload() {
if (this.documents.length < 1) {
return;
}
this.documents.forEach((doc) => doc.remove());
} }
/** /**
@ -86,14 +101,23 @@ export class Project {
| string, | string,
): any {} ): any {}
open(doc: string | DocumentModel | RootSchema): void { open(doc?: string | DocumentModel | RootSchema): void {
if (!doc) {
const got = this.documents.find((item) => item.isBlank());
if (got) {
return got.open();
}
doc = new DocumentModel(this);
this.documents.push(doc);
return doc.open();
}
if (typeof doc === 'string') { if (typeof doc === 'string') {
const got = this.documents.find(item => item.fileName === doc); const got = this.documents.find((item) => item.fileName === doc);
if (got) { if (got) {
return got.open(); return got.open();
} }
const data = this.data.componentsTree.find(data => data.fileName === doc); const data = this.data.componentsTree.find((data) => data.fileName === doc);
if (data) { if (data) {
doc = new DocumentModel(this, data); doc = new DocumentModel(this, data);
this.documents.push(doc); this.documents.push(doc);
@ -113,7 +137,7 @@ export class Project {
} }
checkExclusive(actived: DocumentModel) { checkExclusive(actived: DocumentModel) {
this.documents.forEach(doc => { this.documents.forEach((doc) => {
if (doc !== actived) { if (doc !== actived) {
doc.suspense(); doc.suspense();
} }
@ -122,7 +146,7 @@ export class Project {
} }
closeOthers(opened: DocumentModel) { closeOthers(opened: DocumentModel) {
this.documents.forEach(doc => { this.documents.forEach((doc) => {
if (doc !== opened) { if (doc !== opened) {
doc.close(); doc.close();
} }

View File

@ -214,7 +214,7 @@ export default class DesignerPlugin extends PureComponent<PluginProps, DesignerP
if (!library || !componentMetadatas) { if (!library || !componentMetadatas) {
// TODO: use a Loading // TODO: use a Loading
return 'assets loading'; return null;
} }
return ( return (