feat: add codeChange output event

This commit is contained in:
buqiyuan 2022-07-12 18:46:54 +08:00
parent 51f7201004
commit 230982fb61
2 changed files with 15 additions and 2 deletions

View File

@ -48,7 +48,8 @@
</nz-tree-view>
</div>
<div class="flex-1 ">
<eo-editor [(code)]="model" editorType="javascript" [eventList]="[ 'format', 'copy', 'search', 'replace']">
<eo-editor [(code)]="model" editorType="javascript" [eventList]="[ 'format', 'copy', 'search', 'replace']"
(codeChange)="handleChange($event)">
</eo-editor>
</div>
</div>

View File

@ -1,7 +1,7 @@
import { SelectionModel } from '@angular/cdk/collections';
import { FlatTreeControl } from '@angular/cdk/tree';
// import { FlatTreeControl } from 'ng-zorro-antd/node_modules/@angular/cdk/tree';
import { Component, OnInit, ViewChild } from '@angular/core';
import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core';
import { EoEditorComponent } from 'eo/workbench/browser/src/app/eoui/editor/eo-editor/eo-editor.component';
import { NzTreeFlatDataSource, NzTreeFlattener } from 'ng-zorro-antd/tree-view';
@ -14,8 +14,11 @@ import { TREE_DATA } from './constant';
styleUrls: ['./api-script.component.scss'],
})
export class ApiScriptComponent implements OnInit {
@Output() codeChange = new EventEmitter<string>();
@ViewChild(EoEditorComponent, { static: false }) eoEditor?: EoEditorComponent;
private code = '';
private transformer = (node: TreeNode, level: number): FlatNode => ({
...node,
expandable: !!node.children && node.children.length > 0,
@ -50,7 +53,16 @@ export class ApiScriptComponent implements OnInit {
hasChild = (_: number, node: FlatNode): boolean => node.expandable;
handleChange(code) {
this.code = code;
setTimeout(() => {
this.codeChange.emit(code);
}, 0);
}
insertCode = (node: FlatNode) => {
this.eoEditor.handleInsert(node.value);
};
getCode = () => this.code;
}