mirror of
https://gitee.com/eolink_admin/postcat.git
synced 2024-12-02 11:47:57 +08:00
Merge branch 'main' of github.com:eolinker/eoapi
This commit is contained in:
commit
5cd80ab96a
@ -42,6 +42,8 @@ function createWindow(): BrowserWindow {
|
||||
win = new BrowserWindow({
|
||||
width: Math.round(size.width * 0.85),
|
||||
height: Math.round(size.height * 0.85),
|
||||
minWidth: 1280,
|
||||
minHeight: 720,
|
||||
useContentSize: true, // 这个要设置,不然计算显示区域尺寸不准
|
||||
frame: os.type() === 'Darwin' ? true : false, //mac use default frame
|
||||
webPreferences: {
|
||||
|
@ -160,30 +160,11 @@ export class ApiGroupTreeComponent implements OnInit, OnDestroy {
|
||||
...(getExpandGroupByKey(this.apiGroup, this.route.snapshot.queryParams.uuid) || []),
|
||||
];
|
||||
}
|
||||
// 重新构建整个group
|
||||
async rebuildGroupTree(result) {
|
||||
this.storageInstance.apiData.clear();
|
||||
this.storageInstance.group.clear();
|
||||
async createGroup({ name, projectID, content }) {
|
||||
const groupID = await this.storageInstance.group.add({ name, projectID });
|
||||
const result = content.apiData.map((it, index) => ({ ...it, groupID, uuid: Date.now() + index }));
|
||||
await this.storageInstance.apiData.bulkAdd(result);
|
||||
const apiItems = {};
|
||||
this.treeItems = [];
|
||||
result.forEach((item: ApiData) => {
|
||||
delete item.updatedAt;
|
||||
apiItems[item.uuid] = item;
|
||||
this.treeItems.push({
|
||||
title: item.name,
|
||||
key: item.uuid.toString(),
|
||||
weight: item.weight || 0,
|
||||
parentID: item.groupID ? `group-${item.groupID}` : '0',
|
||||
method: item.method,
|
||||
isLeaf: true,
|
||||
});
|
||||
});
|
||||
this.apiDataItems = apiItems;
|
||||
this.messageService.send({ type: 'loadApi', data: this.apiDataItems });
|
||||
this.setSelectedKeys();
|
||||
this.generateGroupTreeData();
|
||||
this.restoreExpandStatus();
|
||||
this.buildGroupTreeData();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -205,8 +186,7 @@ export class ApiGroupTreeComponent implements OnInit, OnDestroy {
|
||||
break;
|
||||
}
|
||||
case 'importSuccess': {
|
||||
const { apiData } = JSON.parse(inArg.data);
|
||||
this.rebuildGroupTree(apiData);
|
||||
this.createGroup({ projectID: 1, ...inArg.data });
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -349,7 +329,7 @@ export class ApiGroupTreeComponent implements OnInit, OnDestroy {
|
||||
'groupBulkUpdate',
|
||||
[
|
||||
data.group.map((val) => {
|
||||
return { ...val, uuid: val.uuid.replace('group-',''), parentID: val.parentID.replace('group-','') };
|
||||
return { ...val, uuid: val.uuid.replace('group-', ''), parentID: val.parentID.replace('group-', '') };
|
||||
}),
|
||||
],
|
||||
(result: StorageRes) => {}
|
||||
|
@ -35,11 +35,12 @@
|
||||
</div>
|
||||
|
||||
<div class="mt-4" *ngIf="allowDrag">
|
||||
<nz-upload *ngIf="extensionList.length" nzType="drag" [nzBeforeUpload]="parserFile" [nzShowUploadList]="false">
|
||||
<nz-upload *ngIf="extensionList.length" nzType="drag" [nzBeforeUpload]="parserFile">
|
||||
<p class="ant-upload-drag-icon">
|
||||
<i nz-icon nzType="inbox"></i>
|
||||
</p>
|
||||
<p class="ant-upload-text">点击或直接拖拽文件至此区域</p>
|
||||
<p class="ant-upload-hint">仅支持JSON格式的单个文件导入</p>
|
||||
</nz-upload>
|
||||
<div class="text h-4 my-2">{{ filename }}</div>
|
||||
</div>
|
||||
|
@ -20,6 +20,7 @@ export class ExtensionSelectComponent {
|
||||
@Output() extensionChange = new EventEmitter<string>();
|
||||
@Output() currentOptionChange = new EventEmitter<string>();
|
||||
@Output() uploadChange = new EventEmitter<any>();
|
||||
filename = '';
|
||||
|
||||
selectExtension({ key, properties }) {
|
||||
this.extensionChange.emit(key);
|
||||
@ -36,7 +37,8 @@ export class ExtensionSelectComponent {
|
||||
|
||||
parserFile = (file) =>
|
||||
new Observable((observer: Observer<boolean>) => {
|
||||
parserJsonFile(file).then((result) => {
|
||||
parserJsonFile(file).then((result: { name: string }) => {
|
||||
this.filename = result.name;
|
||||
this.uploadChange.emit(result);
|
||||
observer.complete();
|
||||
});
|
||||
|
@ -1,17 +1,42 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { StorageRes, StorageResStatus } from 'eo/workbench/browser/src/app/shared/services/storage/index.model';
|
||||
import { EoMessageService } from 'eo/workbench/browser/src/app/eoui/message/eo-message.service';
|
||||
import { StorageService } from '../../../shared/services/storage';
|
||||
import { FeatureType } from '../../types';
|
||||
import { parserProperties, getDefaultValue } from '../../../utils';
|
||||
import { MessageService } from 'eo/workbench/browser/src/app/shared/services/message/message.service';
|
||||
|
||||
// const optionList = [
|
||||
// {
|
||||
// value: 'import',
|
||||
// type: 'string',
|
||||
// default: '',
|
||||
// label: '直接导入',
|
||||
// description: '直接导入',
|
||||
// },
|
||||
// {
|
||||
// value: 'add',
|
||||
// type: 'string',
|
||||
// default: true,
|
||||
// label: '增量更新[推荐]',
|
||||
// description: '增量更新',
|
||||
// },
|
||||
// {
|
||||
// value: 'all',
|
||||
// type: 'string',
|
||||
// default: '',
|
||||
// label: '全量更新[慎用]',
|
||||
// description: '全量更新',
|
||||
// },
|
||||
// {
|
||||
// value: 'new',
|
||||
// type: 'string',
|
||||
// default: '',
|
||||
// label: '仅添加新 API',
|
||||
// description: '仅添加新 API',
|
||||
// },
|
||||
// ];
|
||||
|
||||
@Component({
|
||||
selector: 'eo-import-api',
|
||||
template: `<extension-select
|
||||
[allowDrag]="true"
|
||||
[optionList]="optionList"
|
||||
[(currentOption)]="currentOption"
|
||||
[(extension)]="currentExtension"
|
||||
[extensionList]="supportList"
|
||||
(uploadChange)="uploadChange($event)"
|
||||
@ -20,15 +45,9 @@ import { MessageService } from 'eo/workbench/browser/src/app/shared/services/mes
|
||||
export class ImportApiComponent implements OnInit {
|
||||
supportList: Array<FeatureType> = [];
|
||||
currentExtension = '';
|
||||
currentOption = '';
|
||||
optionList = [];
|
||||
uploadData = null;
|
||||
featureMap = window.eo.getFeature('apimanage.import');
|
||||
constructor(
|
||||
private storage: StorageService,
|
||||
private message: EoMessageService,
|
||||
private messageService: MessageService
|
||||
) {}
|
||||
constructor(private messageService: MessageService) {}
|
||||
ngOnInit(): void {
|
||||
this.featureMap?.forEach((data: FeatureType, key: string) => {
|
||||
this.supportList.push({
|
||||
@ -37,39 +56,25 @@ export class ImportApiComponent implements OnInit {
|
||||
});
|
||||
});
|
||||
{
|
||||
const { key, properties } = this.supportList.at(0);
|
||||
const { key } = this.supportList.at(0);
|
||||
this.currentExtension = key || '';
|
||||
this.optionList = parserProperties(properties || '');
|
||||
this.currentOption = getDefaultValue(this.optionList, 'value');
|
||||
}
|
||||
}
|
||||
getEoapiData() {
|
||||
return new Promise((resolve) => {
|
||||
this.storage.run('projectExport', [], (result: StorageRes) => {
|
||||
const isOk = result.status === StorageResStatus.success;
|
||||
resolve(isOk ? [result.data, null] : [null, true]);
|
||||
});
|
||||
});
|
||||
}
|
||||
uploadChange(data) {
|
||||
this.uploadData = data;
|
||||
}
|
||||
async submit(callback) {
|
||||
const [eoapiData, err]: any = await this.getEoapiData();
|
||||
if (err) {
|
||||
this.message.error('获取本地数据失败');
|
||||
return;
|
||||
}
|
||||
// * this.currentExtension is extension's key, like 'eoapi-import-openapi'
|
||||
const feature = this.featureMap.get(this.currentExtension);
|
||||
const action = feature.action || null;
|
||||
const module = window.eo.loadFeatureModule(this.currentExtension);
|
||||
const data = module[action](eoapiData, this.uploadData, this.currentOption);
|
||||
const { name, content } = this.uploadData;
|
||||
const data = module[action](content);
|
||||
// console.log(JSON.stringify(data, null, 2));
|
||||
this.messageService.send({
|
||||
type: 'importSuccess',
|
||||
data: JSON.stringify(data),
|
||||
data: { name, content: data },
|
||||
});
|
||||
// console.log(JSON.stringify(data));
|
||||
callback(true);
|
||||
}
|
||||
}
|
||||
|
@ -322,11 +322,11 @@ export class IndexedDBStorage extends Dexie implements StorageInterface {
|
||||
}
|
||||
|
||||
apiDataLoadAllByGroupID(groupID: number | string): Observable<object> {
|
||||
return this.loadAllByConditions(this.apiData, { groupID: groupID });
|
||||
return this.loadAllByConditions(this.apiData, { groupID });
|
||||
}
|
||||
|
||||
apiDataLoadAllByProjectID(projectID: number | string): Observable<object> {
|
||||
return this.loadAllByConditions(this.apiData, { projectID: projectID });
|
||||
return this.loadAllByConditions(this.apiData, { projectID });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -335,7 +335,7 @@ export class IndexedDBStorage extends Dexie implements StorageInterface {
|
||||
* @param groupID
|
||||
*/
|
||||
apiDataLoadAllByProjectIDAndGroupID(projectID: number | string, groupID: number | string): Observable<object> {
|
||||
return this.loadAllByConditions(this.apiData, { projectID: projectID, groupID: groupID });
|
||||
return this.loadAllByConditions(this.apiData, { projectID, groupID });
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,6 +54,7 @@ export class HttpStorage implements StorageInterface {
|
||||
projectLoad: (uuid: number | string) => Observable<object>;
|
||||
projectBulkLoad: (uuids: Array<number | string>) => Observable<object>;
|
||||
projectExport() {
|
||||
console.log('lo', new Error());
|
||||
return this.http.get(`/project/export`) as Observable<object>;
|
||||
}
|
||||
// Environment
|
||||
|
@ -26,7 +26,8 @@ export class StorageService {
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
run = (action: string, params: Array<any>, callback) => {
|
||||
run(action: string, params: Array<any>, callback): void {
|
||||
console.log('koko');
|
||||
const handleResult = {
|
||||
status: StorageResStatus.invalid,
|
||||
data: undefined,
|
||||
@ -47,7 +48,7 @@ export class StorageService {
|
||||
callback(handleResult);
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
setStorage = (type: DataSourceType = 'local', options = {}) => {
|
||||
switch (type) {
|
||||
case 'local': {
|
||||
|
@ -82,7 +82,7 @@ export const parserJsonFile = (file, type = 'UTF-8') =>
|
||||
reader.onload = (ev) => {
|
||||
const fileString: string = ev.target.result as string;
|
||||
const json = JSON.parse(fileString);
|
||||
resolve(json);
|
||||
resolve({ name: file.name, content: json });
|
||||
};
|
||||
});
|
||||
|
||||
@ -93,5 +93,3 @@ export const getDefaultValue = (list: any[], key) => {
|
||||
const [target] = list.filter((it) => it.default);
|
||||
return target[key] || '';
|
||||
};
|
||||
|
||||
export const parserProperties = (properties) => Object.keys(properties).map((it) => ({ value: it, ...properties[it] }));
|
||||
|
Loading…
Reference in New Issue
Block a user