调整界面
调整脚本 增加功能:备份、恢复、清空
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
import {activateRecordService} from "../service/database/activateRecord";
|
||||
import path from 'path';
|
||||
import { app as electronApp, dialog } from 'electron';
|
||||
import { activateRecordService } from "../service/database/activateRecord";
|
||||
|
||||
class ActivateRecordController {
|
||||
|
||||
async list(args: { macAddress: string, modules: string[] }): Promise<any> {
|
||||
const {macAddress, modules} = args
|
||||
return activateRecordService.list(macAddress, modules)
|
||||
const { macAddress, modules } = args;
|
||||
return activateRecordService.list(macAddress, modules);
|
||||
}
|
||||
|
||||
async save(args: {
|
||||
applicant: string,
|
||||
macAddress: string,
|
||||
applicationCode: string,
|
||||
modules: string[],
|
||||
@@ -15,8 +18,76 @@ class ActivateRecordController {
|
||||
createTime: string,
|
||||
remark: string
|
||||
}): Promise<any> {
|
||||
const { modules} = args
|
||||
return activateRecordService.save({...args, module : modules.join(',')})
|
||||
const { modules } = args;
|
||||
return activateRecordService.save({ ...args, module: modules.join(',') });
|
||||
}
|
||||
|
||||
async removeById(args: { id: number }): Promise<any> {
|
||||
const { id } = args;
|
||||
return activateRecordService.removeById(id);
|
||||
}
|
||||
|
||||
async clear(): Promise<any> {
|
||||
return activateRecordService.clear();
|
||||
}
|
||||
|
||||
async backup(): Promise<any> {
|
||||
const defaultFileName = `activate-record-backup-${this.getTimestamp()}.json`;
|
||||
const filePath = dialog.showSaveDialogSync({
|
||||
title: '导出备份',
|
||||
defaultPath: path.join(electronApp.getPath('documents'), defaultFileName),
|
||||
filters: [
|
||||
{ name: 'JSON', extensions: ['json'] }
|
||||
]
|
||||
});
|
||||
|
||||
if (!filePath) {
|
||||
return {
|
||||
canceled: true
|
||||
};
|
||||
}
|
||||
|
||||
const count = await activateRecordService.backup(filePath);
|
||||
return {
|
||||
canceled: false,
|
||||
count,
|
||||
filePath
|
||||
};
|
||||
}
|
||||
|
||||
async importBackup(): Promise<any> {
|
||||
const filePaths = dialog.showOpenDialogSync({
|
||||
title: '导入备份',
|
||||
properties: ['openFile'],
|
||||
filters: [
|
||||
{ name: 'JSON', extensions: ['json'] }
|
||||
]
|
||||
});
|
||||
|
||||
if (!filePaths || filePaths.length === 0) {
|
||||
return {
|
||||
canceled: true
|
||||
};
|
||||
}
|
||||
|
||||
const filePath = filePaths[0];
|
||||
const count = await activateRecordService.importBackup(filePath);
|
||||
return {
|
||||
canceled: false,
|
||||
count,
|
||||
filePath
|
||||
};
|
||||
}
|
||||
|
||||
private getTimestamp(): string {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = `${now.getMonth() + 1}`.padStart(2, '0');
|
||||
const day = `${now.getDate()}`.padStart(2, '0');
|
||||
const hour = `${now.getHours()}`.padStart(2, '0');
|
||||
const minute = `${now.getMinutes()}`.padStart(2, '0');
|
||||
const second = `${now.getSeconds()}`.padStart(2, '0');
|
||||
return `${year}${month}${day}-${hour}${minute}${second}`;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user