Merge branch 'fix/component-not-found' into 'release/0.9.3'

fix组件缺失占位



See merge request !927746
This commit is contained in:
高凯 2020-08-10 19:45:35 +08:00
commit 270e27cc38
3 changed files with 28 additions and 2 deletions

View File

@ -302,6 +302,11 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
const nodeInst = this.getNodeInstanceFromElement(downEvent.target as Element);
const node = nodeInst?.node || this.document.rootNode;
if (!node?.isValidComponent()) {
// 对于未注册组件直接返回
return;
}
const isMulti = downEvent.metaKey || downEvent.ctrlKey;
const isLeftButton = downEvent.which === 1 || downEvent.button === 0;
const checkSelect = (e: MouseEvent) => {

View File

@ -653,6 +653,16 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
slotNode.internalSetParent(this as ParentalNode, true);
this._slots.push(slotNode);
}
/**
* node对应组件是否已注册可用
*/
isValidComponent() {
const allComponents = this.document?.designer?.componentsMap;
if (allComponents && allComponents[this.componentName]) {
return true;
}
return false;
}
/**
*
@ -702,6 +712,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
getComponentName() {
return this.componentName;
}
insertBefore(node: Node, ref?: Node, useMutator = true) {
this.children?.insert(node, ref ? ref.index : null, useMutator);
}

View File

@ -36,8 +36,18 @@ class FaultComponent extends PureComponent {
class NotFoundComponent extends PureComponent {
render() {
console.error('component not found', this.props);
return <Div {...this.props} />;
console.error('component not found:', this.props);
const { _componentName: componentName } = this.props;
return <Div
{...this.props}
style={{
backgroundColor: '#3E91C9',
padding: '15px',
fontSize: '18px',
textAlign: 'center',
color: 'white',
}}
>组件 {componentName} 无视图请打开控制台排查</Div>;
}
}