mirror of
https://github.com/didi/KnowStreaming.git
synced 2026-01-10 09:04:26 +08:00
kafka-manager 2.0
This commit is contained in:
133
kafka-manager-console/src/store/version.ts
Normal file
133
kafka-manager-console/src/store/version.ts
Normal file
@@ -0,0 +1,133 @@
|
||||
import { observable, action } from 'mobx';
|
||||
import { IUploadFile, IConfigInfo } from 'types/base-type';
|
||||
import { getFileList, addFile, deleteFile, modfiyFile, getFileType, getConfigFiles } from 'lib/api';
|
||||
|
||||
interface IEnum {
|
||||
code: number;
|
||||
message: string;
|
||||
suffix?: string;
|
||||
}
|
||||
interface IUploadFileType {
|
||||
fileEnum: IEnum[] ;
|
||||
storageEnum: IEnum[];
|
||||
}
|
||||
|
||||
export class Version {
|
||||
@observable
|
||||
public loading: boolean = false;
|
||||
|
||||
@observable
|
||||
public fileSuffix: string = '';
|
||||
|
||||
@observable
|
||||
public acceptFileType: string = '';
|
||||
|
||||
@observable
|
||||
public configFiles: string = '';
|
||||
|
||||
@observable
|
||||
public fileList: IUploadFile[] = [];
|
||||
|
||||
@observable
|
||||
public storageTypes: IConfigInfo[] = [];
|
||||
|
||||
@observable
|
||||
public currentFileType: number = 0;
|
||||
|
||||
@observable
|
||||
public fileTypeList: IEnum[] = [];
|
||||
|
||||
@observable
|
||||
public acceptFileMap = {} as {
|
||||
[key: number]: string,
|
||||
};
|
||||
|
||||
@action.bound
|
||||
public setFileList(data: IUploadFile[]) {
|
||||
|
||||
this.fileList = (data || []).map((item, index) => {
|
||||
return {
|
||||
...item,
|
||||
configType: this.acceptFileMap[item.fileType],
|
||||
key: index,
|
||||
};
|
||||
});
|
||||
this.setLoading(false);
|
||||
}
|
||||
|
||||
@action.bound
|
||||
public setConfigFiles(data: string) {
|
||||
this.configFiles = data;
|
||||
}
|
||||
|
||||
@action.bound
|
||||
public setFileTypeList(data: IUploadFileType) {
|
||||
const fileTypeList = data && data.fileEnum || [];
|
||||
const storageEnum = data && data.storageEnum || [];
|
||||
this.fileTypeList = fileTypeList.map((item, index) => {
|
||||
if (item.suffix) {
|
||||
this.acceptFileMap[item.code] = item.message;
|
||||
}
|
||||
|
||||
if (index === 0) { // 初始化文件上传类型
|
||||
this.acceptFileType = item.suffix;
|
||||
}
|
||||
|
||||
return {
|
||||
...item,
|
||||
label: item.message,
|
||||
value: item.code,
|
||||
};
|
||||
});
|
||||
|
||||
this.storageTypes = storageEnum.map(item => {
|
||||
return {
|
||||
...item,
|
||||
label: item.message,
|
||||
value: item.message,
|
||||
};
|
||||
});
|
||||
this.setLoading(false);
|
||||
}
|
||||
|
||||
@action.bound
|
||||
public setLoading(value: boolean) {
|
||||
this.loading = value;
|
||||
}
|
||||
|
||||
@action.bound
|
||||
public setAcceptFileType(type: number) {
|
||||
this.fileSuffix = this.fileTypeList[type].suffix;
|
||||
this.currentFileType = type;
|
||||
this.acceptFileType = this.acceptFileMap[type] || '';
|
||||
}
|
||||
|
||||
public async getFileTypeList() {
|
||||
this.setLoading(true);
|
||||
getFileType().then(this.setFileTypeList);
|
||||
}
|
||||
|
||||
public getFileList() {
|
||||
this.setLoading(true);
|
||||
getFileList().then(this.setFileList);
|
||||
}
|
||||
|
||||
public deleteFile(id: number) {
|
||||
deleteFile(id).then(() => this.getFileList());
|
||||
}
|
||||
|
||||
public modfiyFile(params: IUploadFile) {
|
||||
modfiyFile(params).then(() => this.getFileList());
|
||||
}
|
||||
|
||||
public addFile(params: IUploadFile) {
|
||||
params.clusterId = params.clusterId || -1;
|
||||
addFile(params).then(() => this.getFileList());
|
||||
}
|
||||
|
||||
public getConfigFiles(fileId: number) {
|
||||
getConfigFiles(fileId).then(this.setConfigFiles);
|
||||
}
|
||||
}
|
||||
|
||||
export const version = new Version();
|
||||
Reference in New Issue
Block a user