Skip to content

Commit

Permalink
feat: export eoapi file
Browse files Browse the repository at this point in the history
  • Loading branch information
scarqin committed Apr 27, 2022
1 parent 2f4d1b9 commit 85c1875
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"scripts": {
"postinstall": "npm-run-all --serial install:*",
"start": "npm-run-all -p startall electron:serve",
"serve:web": "cd src/workbench/browser && npm run ng:serve",
"startall": "npm-run-all -p start:*",
"install:workbench": "cd src/workbench/browser&&npm install",
"start:workbench": "cd src/workbench/browser&&npm start",
Expand Down
1 change: 0 additions & 1 deletion src/platform/browser/IndexedDB/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ class Storage extends Dexie implements StorageInterface {
for (var i = 0; i < tables.length; i++) {
let tableName = tables[i];
result[tableName] = await this[tableName].toArray();
console.log(result)
}
obs.next(result);
obs.complete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class ElectronService {
webFrame: typeof webFrame;
childProcess: typeof childProcess;
fs: typeof fs;

constructor() {
// Conditional imports
if (this.isElectron) {
Expand All @@ -32,7 +31,7 @@ export class ElectronService {
// If you want to use a NodeJS 3rd party deps in Renderer process,
// ipcRenderer.invoke can serve many common use cases.
// https://www.electronjs.org/docs/latest/api/ipc-renderer#ipcrendererinvokechannel-args
}
}
}

get isElectron(): boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { ExportApiComponent } from '../../../shared/components/export-api/export-api.component';
import { SyncApiComponent } from '../../../shared/components/sync-api/sync-api.component';
Expand All @@ -10,17 +11,25 @@ import { ModalService } from '../../../shared/services/modal.service';
styleUrls: ['./api-overview.component.scss'],
})
export class ApiOverviewComponent implements OnInit {
constructor(private modalService: ModalService) {}
constructor(private modalService: ModalService,private message: NzMessageService) {}

ngOnInit(): void {}
export() {
let that=this;
const modal: NzModalRef = this.modalService.create({
nzTitle: '导出 API',
nzContent: ExportApiComponent,
nzClosable: false,
nzComponentParams: {},
nzOnOk() {
modal.componentInstance.submit();
modal.componentInstance.submit((isSuccess) => {
if (isSuccess) {
that.message.success('导出成功');
modal.destroy();
} else {
that.message.error('导出失败');
}
});
},
});
}
Expand All @@ -31,7 +40,14 @@ export class ApiOverviewComponent implements OnInit {
nzClosable: false,
nzComponentParams: {},
nzOnOk() {
modal.componentInstance.submit();
modal.componentInstance.submit((isSuccess) => {
if (isSuccess) {
this.message.success('同步成功');
modal.destroy();
} else {
this.message.error('同步失败');
}
});
},
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, Input, OnInit } from '@angular/core';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { StorageService } from '../../../shared/services/storage';
import { StorageHandleResult, StorageHandleStatus } from '../../../../../../../platform/browser/IndexedDB';
import packageJson from '../../../../../../../../package.json';
@Component({
selector: 'eo-export-api',
templateUrl: './export-api.component.html',
Expand All @@ -12,29 +12,45 @@ export class ExportApiComponent implements OnInit {
supportList: any[] = [
{
key: 'eoapi',
image:'',
image: '',
title: 'Eoapi(.json)',
},
{
key: 'openapi3',
image:'',
image: '',
title: 'Swagger V3.0',
},
];
constructor(private modalRef: NzModalRef, private storage: StorageService) {}
constructor(private storage: StorageService) {}
ngOnInit(): void {}
exportEoapi() {
private transferTextToFile(fileName: string, exportData: any) {
let file = new Blob([JSON.stringify(exportData)], { type: 'data:text/plain;charset=utf-8' });
let element = document.createElement('a'),
url = URL.createObjectURL(file);
element.href = url;
element.download = fileName;
document.body.appendChild(element);
element.click();
setTimeout(function () {
document.body.removeChild(element);
window.URL.revokeObjectURL(url);
}, 0);
}
private exportEoapi(callback) {
this.storage.run('projectExport', [], (result: StorageHandleResult) => {
console.log(result)
if (result.status === StorageHandleStatus.success) {
result.data.version = packageJson.version;
this.transferTextToFile('Eoapi-export.json', result.data);
callback(true);
} else {
callback(false);
}
});
}
submit() {
submit(callback: () => boolean) {
switch (this.exportType) {
case 'eoapi': {
this.exportEoapi();
this.exportEoapi(callback);
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/workbench/browser/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"resolveJsonModule":true,
"allowSyntheticDefaultImports":true,
"module": "es2020",
"sourceMap": true,
"declaration": false,
Expand Down

0 comments on commit 85c1875

Please sign in to comment.