+
+
+
+
+
+ {{ node.name }}
+
+
+
+
+
+
+
+
+ {{ node.name }}
+
+
+
+
+
+
+
+
+
diff --git a/src/workbench/browser/src/app/shared/components/api-script/api-script.component.scss b/src/workbench/browser/src/app/shared/components/api-script/api-script.component.scss
new file mode 100644
index 00000000..e69de29b
diff --git a/src/workbench/browser/src/app/shared/components/api-script/api-script.component.spec.ts b/src/workbench/browser/src/app/shared/components/api-script/api-script.component.spec.ts
new file mode 100644
index 00000000..47238854
--- /dev/null
+++ b/src/workbench/browser/src/app/shared/components/api-script/api-script.component.spec.ts
@@ -0,0 +1,23 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { ApiScriptComponent } from './api-script.component';
+
+describe('ApiScriptComponent', () => {
+ let component: ApiScriptComponent;
+ let fixture: ComponentFixture;
+
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ declarations: [ ApiScriptComponent ]
+ })
+ .compileComponents();
+
+ fixture = TestBed.createComponent(ApiScriptComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/src/workbench/browser/src/app/shared/components/api-script/api-script.component.ts b/src/workbench/browser/src/app/shared/components/api-script/api-script.component.ts
new file mode 100644
index 00000000..2d7e41a3
--- /dev/null
+++ b/src/workbench/browser/src/app/shared/components/api-script/api-script.component.ts
@@ -0,0 +1,83 @@
+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 { EoEditorComponent } from 'eo/workbench/browser/src/app/eoui/editor/eo-editor/eo-editor.component';
+
+import { NzTreeFlatDataSource, NzTreeFlattener } from 'ng-zorro-antd/tree-view';
+
+interface TreeNode {
+ name: string;
+ code?: string;
+ children?: TreeNode[];
+}
+
+const TREE_DATA: TreeNode[] = [
+ {
+ name: 'HTTP API 请求',
+ children: [
+ {
+ name: '获取响应结果',
+ code: 'eo.http.response.get();',
+ },
+ {
+ name: '设置响应结果',
+ code: 'eo.http.response.set("response_value");',
+ },
+ ],
+ },
+];
+
+interface FlatNode extends TreeNode {
+ expandable: boolean;
+ name: string;
+ level: number;
+ disabled: boolean;
+}
+
+@Component({
+ selector: 'eo-api-script',
+ templateUrl: './api-script.component.html',
+ styleUrls: ['./api-script.component.scss'],
+})
+export class ApiScriptComponent implements OnInit {
+ @ViewChild(EoEditorComponent, { static: false }) eoEditor?: EoEditorComponent;
+
+ private transformer = (node: TreeNode, level: number): FlatNode => ({
+ ...node,
+ expandable: !!node.children && node.children.length > 0,
+ name: node.name,
+ level,
+ disabled: false,
+ });
+ selectListSelection = new SelectionModel(true);
+
+ treeControl = new FlatTreeControl(
+ (node) => node.level,
+ (node) => node.expandable
+ );
+
+ treeFlattener = new NzTreeFlattener(
+ this.transformer,
+ (node) => node.level,
+ (node) => node.expandable,
+ (node) => node.children
+ );
+
+ // @ts-ignore
+ dataSource = new NzTreeFlatDataSource(this.treeControl, this.treeFlattener);
+
+ model = '';
+ constructor() {
+ this.dataSource.setData(TREE_DATA);
+ this.treeControl.expandAll();
+ }
+
+ ngOnInit(): void {}
+
+ hasChild = (_: number, node: FlatNode): boolean => node.expandable;
+
+ insertCode = (node: FlatNode) => {
+ this.eoEditor.handleInsert(node.code);
+ };
+}
diff --git a/src/workbench/browser/src/app/shared/shared.module.ts b/src/workbench/browser/src/app/shared/shared.module.ts
index dd610291..49c4e267 100644
--- a/src/workbench/browser/src/app/shared/shared.module.ts
+++ b/src/workbench/browser/src/app/shared/shared.module.ts
@@ -22,8 +22,17 @@ import { PageBlankComponent } from './components/page-blank/page-blank.component
import { RouterModule } from '@angular/router';
import { ShadowDomEncapsulationComponent } from 'eo/workbench/browser/src/app/shared/components/shadow/shadow-dom-encapsulation.component';
import { EoIconparkIconModule } from 'eo/workbench/browser/src/app/eoui/iconpark-icon/eo-iconpark-icon.module';
+import { ApiScriptComponent } from './components/api-script/api-script.component';
+import { EouiModule } from 'eo/workbench/browser/src/app/eoui/eoui.module';
+import { NzTreeViewModule } from 'ng-zorro-antd/tree-view';
-const COMPONENTS = [ToolbarComponent, ShadowDomEncapsulationComponent, SidebarComponent, PageNotFoundComponent];
+const COMPONENTS = [
+ ToolbarComponent,
+ ShadowDomEncapsulationComponent,
+ SidebarComponent,
+ PageNotFoundComponent,
+ ApiScriptComponent,
+];
@NgModule({
imports: [
CommonModule,
@@ -42,6 +51,8 @@ const COMPONENTS = [ToolbarComponent, ShadowDomEncapsulationComponent, SidebarCo
NzMessageModule,
NzDescriptionsModule,
EoIconparkIconModule,
+ EouiModule,
+ NzTreeViewModule,
],
declarations: [WebviewDirective, ...COMPONENTS, ApiParamsNumPipe, PageBlankComponent],
providers: [ModalService],
diff --git a/yarn.lock b/yarn.lock
index e19f28c3..478498b6 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -205,16 +205,7 @@
dependencies:
tslib "^2.3.0"
-"@angular/cdk@14.0.3":
- version "14.0.3"
- resolved "https://registry.yarnpkg.com/@angular/cdk/-/cdk-14.0.3.tgz#eaa0b0736481bc9c1d24ad88e19dd20874506032"
- integrity sha512-XN5+WVUFx13lW2x9gnzJprHGqcvSpKQaoXxFvlcn16i0P6Iy1jldVZm6q6chEhgX9rEi7P31nfE88OJzHmkEyw==
- dependencies:
- tslib "^2.3.0"
- optionalDependencies:
- parse5 "^5.0.0"
-
-"@angular/cdk@^13.0.1":
+"@angular/cdk@13.3.9", "@angular/cdk@^13.0.1":
version "13.3.9"
resolved "https://registry.npmmirror.com/@angular/cdk/-/cdk-13.3.9.tgz#a177196e872e29be3f84d3a50f778d361c689ff7"
integrity sha512-XCuCbeuxWFyo3EYrgEYx7eHzwl76vaWcxtWXl00ka8d+WAOtMQ6Tf1D98ybYT5uwF9889fFpXAPw98mVnlo3MA==