mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 01:21:58 +00:00
fix: 修复 setDevice 里获取 currentDocument 的逻辑
This commit is contained in:
parent
447ed9b8f9
commit
275b7aaef9
@ -1308,26 +1308,6 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
|
||||
return nearBy;
|
||||
}
|
||||
|
||||
_innerWaitForCurrentDocument(): Promise<any> {
|
||||
const timeGap = 200;
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
if (this.project.currentDocument) {
|
||||
resolve();
|
||||
}
|
||||
}, timeGap);
|
||||
}).catch(() => {
|
||||
return this.waitForCurrentDocument();
|
||||
});
|
||||
}
|
||||
|
||||
waitForCurrentDocument(): Promise<any> {
|
||||
if (this.project.currentDocument) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return this._innerWaitForCurrentDocument();
|
||||
}
|
||||
// #endregion
|
||||
}
|
||||
|
||||
|
||||
@ -36,6 +36,7 @@ editor.set('designer', designer);
|
||||
|
||||
designer.project.onCurrentDocumentChange((doc) => {
|
||||
bus.emit(VE_EVENTS.VE_PAGE_PAGE_READY);
|
||||
editor.set('currentDocuemnt', doc);
|
||||
});
|
||||
|
||||
// 升级 Props
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import Flags from './flags';
|
||||
import { designer } from './editor';
|
||||
import { editor } from './editor';
|
||||
|
||||
const domReady = require('domready');
|
||||
|
||||
@ -192,10 +192,11 @@ export class Viewport {
|
||||
return this.preview;
|
||||
}
|
||||
|
||||
setDevice(device = 'pc') {
|
||||
async setDevice(device = 'pc') {
|
||||
if (this.getDevice() !== device) {
|
||||
this.device = device;
|
||||
designer.currentDocument?.simulator?.set('device', device === 'mobile' ? 'mobile' : 'default');
|
||||
const currentDocument = await editor.onceGot('currentDocuemnt');
|
||||
currentDocument?.simulator?.set('device', device === 'mobile' ? 'mobile' : 'default');
|
||||
// Flags.setSimulator(device);
|
||||
// this.applyMediaCSS();
|
||||
this.emitter.emit('devicechange', device);
|
||||
|
||||
@ -2,6 +2,7 @@ import React, { Component, PureComponent, createElement as reactCreateElement }
|
||||
import ReactDOM from 'react-dom';
|
||||
import PropTypes from 'prop-types';
|
||||
import Debug from 'debug';
|
||||
import { ConfigProvider } from '@alifd/next';
|
||||
import { isEmpty } from '@ali/b3-one/lib/obj';
|
||||
import AppContext from './context/appContext';
|
||||
import { isFileSchema, goldlog } from './utils';
|
||||
@ -196,15 +197,17 @@ export default class Renderer extends Component {
|
||||
engine: this,
|
||||
}}
|
||||
>
|
||||
<Comp
|
||||
key={schema.__ctx && `${schema.__ctx.lunaKey}_${schema.__ctx.idx || '0'}`}
|
||||
ref={this.__getRef}
|
||||
__appHelper={appHelper}
|
||||
__components={allComponents}
|
||||
__schema={schema}
|
||||
__designMode={designMode}
|
||||
{...this.props}
|
||||
/>
|
||||
<ConfigProvider device={this.props.device}>
|
||||
<Comp
|
||||
key={schema.__ctx && `${schema.__ctx.lunaKey}_${schema.__ctx.idx || '0'}`}
|
||||
ref={this.__getRef}
|
||||
__appHelper={appHelper}
|
||||
__components={allComponents}
|
||||
__schema={schema}
|
||||
__designMode={designMode}
|
||||
{...this.props}
|
||||
/>
|
||||
</ConfigProvider>
|
||||
</AppContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
@ -177,7 +177,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.dispose = host.connect(this, async () => {
|
||||
this.dispose = host.connect(this, () => {
|
||||
// sync layout config
|
||||
this._layout = host.project.get('config').layout;
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
"dependencies": {
|
||||
"@ali/lowcode-types": "^0.13.1-15",
|
||||
"@alifd/next": "^1.19.16",
|
||||
"lodash.get": "^4.4.2",
|
||||
"react": "^16"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
|
||||
import { isI18NObject } from './is-object';
|
||||
import get from 'lodash.get';
|
||||
|
||||
export function isUseI18NSetter(prototype: any, propName: string) {
|
||||
const configure = prototype?.options?.configure;
|
||||
@ -18,4 +19,27 @@ export function convertToI18NObject(v: string | object, locale: string = 'zh_CN'
|
||||
|
||||
export function isString(v: any): v is string {
|
||||
return typeof v === 'string';
|
||||
}
|
||||
}
|
||||
|
||||
function _innerWaitForThing(obj: any, path: string): Promise<any> {
|
||||
const timeGap = 200;
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
const thing = get(obj, path);
|
||||
if (thing) {
|
||||
return resolve(thing);
|
||||
}
|
||||
reject();
|
||||
}, timeGap);
|
||||
}).catch(() => {
|
||||
return _innerWaitForThing(obj, path);
|
||||
});
|
||||
}
|
||||
|
||||
export function waitForThing(obj: any, path: string): Promise<any> {
|
||||
const thing = get(obj, path);
|
||||
if (thing) {
|
||||
return Promise.resolve(thing);
|
||||
}
|
||||
return _innerWaitForThing(obj, path);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user