😎代码优化

This commit is contained in:
zuohuaijun 2024-09-04 01:57:09 +08:00
parent 683ebe16a5
commit 7aa49e7e30
18 changed files with 598 additions and 232 deletions

View File

@ -28,5 +28,5 @@ public enum CodeGenTypeEnum
/// 种子数据
/// </summary>
[Description("种子数据")]
SeedData =3,
SeedData = 3,
}

View File

@ -5,16 +5,14 @@
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Furion.TimeCrontab;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Admin.NET.Core;
/// <summary>
/// 每天晚上2点进行数据库备份
/// </summary>
[JobDetail("job_DbBackupJob", Description = "备份数据库", GroupName = "default", Concurrent = false)]
[Cron("0 1 * * *", CronStringFormat.Default, TriggerId = "trigger_DbBackupJob", Description = "备份数据库", RunOnStart = false)]
[Cron("0 0 2 * * ? *", CronStringFormat.Default, TriggerId = "trigger_DbBackupJob", Description = "备份数据库", RunOnStart = false)]
public class DbBackupJob : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
@ -26,18 +24,18 @@ public class DbBackupJob : IJob
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
using var serviceScope = _scopeFactory.CreateScope();
var dbBackupService = serviceScope.ServiceProvider.GetRequiredService<SysDbBackupService>();
string msg = $"【{DateTime.Now}】开始备份数据库";
var originColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(msg);
Console.ForegroundColor = originColor;
using var serviceScope = _scopeFactory.CreateScope();
var dbBackupService = serviceScope.ServiceProvider.GetRequiredService<DbBackupService>();
//清理7天前的备份文件
// 清理7天前的备份文件
dbBackupService.DeleteExpiredDbFile(7);
//开始备份
// 开始备份
await dbBackupService.Backup();
msg = $"【{DateTime.Now}】数据库备份完成";

View File

@ -175,10 +175,10 @@ public class SysMenuSeedData : ISqlSugarEntitySeedData<SysMenu>
new SysMenu{ Id=1310000000445, Pid=1310000000441, Title="获取支付订单详情(微信接口)", Permission="sysWechatPay/payInfoFromWechat", Type=MenuTypeEnum.Btn, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=100 },
new SysMenu{ Id=1310000000446, Pid=1310000000441, Title="退款申请", Permission="sysWechatPay/refundDomestic", Type=MenuTypeEnum.Btn, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=100 },
new SysMenu{ Id=1310000000447, Pid=1310000000301, Title="数据库备份", Path="/platform/dbBackup", Name="dbBackup", Component="/system/dbBackup/index", Icon="ele-Coin", Type=MenuTypeEnum.Menu, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=240 },
new SysMenu{ Id=1310000000448, Pid=1310000000447, Title="查询", Permission="dbBackup/page", Type=MenuTypeEnum.Btn, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=100 },
new SysMenu{ Id=1310000000449, Pid=1310000000447, Title="删除", Permission="dbBackup/delete", Type=MenuTypeEnum.Btn, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=100 },
new SysMenu{ Id=1310000000450, Pid=1310000000447, Title="增加", Permission="dbBackup/add", Type=MenuTypeEnum.Btn, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=100 },
new SysMenu{ Id=1310000000451, Pid=1310000000301, Title="数据库备份", Path="/platform/dbBackup", Name="dbBackup", Component="/system/database/dbBackup", Icon="ele-Coin", Type=MenuTypeEnum.Menu, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=240 },
new SysMenu{ Id=1310000000452, Pid=1310000000451, Title="查询", Permission="dbBackup/page", Type=MenuTypeEnum.Btn, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=100 },
new SysMenu{ Id=1310000000453, Pid=1310000000451, Title="删除", Permission="dbBackup/delete", Type=MenuTypeEnum.Btn, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=100 },
new SysMenu{ Id=1310000000454, Pid=1310000000451, Title="增加", Permission="dbBackup/add", Type=MenuTypeEnum.Btn, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=100 },
new SysMenu{ Id=1310000000501, Pid=0, Title="日志管理", Path="/log", Name="log", Component="Layout", Icon="ele-DocumentCopy", Type=MenuTypeEnum.Dir, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=12000 },
new SysMenu{ Id=1310000000511, Pid=1310000000501, Title="访问日志", Path="/log/logvis", Name="sysLogVis", Component="/system/log/logvis/index", Icon="ele-Document", Type=MenuTypeEnum.Menu, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=100 },

View File

@ -4,17 +4,13 @@
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Admin.NET.Core.Service;
public class BackupDto
public class DbBackupOutput
{
public long Size { get; set; }
public string FileName { get; set; }
public DateTime CreateTime { get; set; }
public long Size { get; set; }
}

View File

@ -4,31 +4,58 @@
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Admin.NET.Core.Service;
public class DbBackupService : IDynamicApiController, ITransient
/// <summary>
/// 系统数据库备份服务 🧩
/// </summary>
[ApiDescriptionSettings(Order = 255)]
public class SysDbBackupService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<SysUser> _sysUserRep;
private readonly string backupDir;
public DbBackupService(SqlSugarRepository<SysUser> sysUserRep)
public SysDbBackupService(SqlSugarRepository<SysUser> sysUserRep)
{
_sysUserRep = sysUserRep;
backupDir = Path.Combine(App.WebHostEnvironment.WebRootPath, "DbBackup");
}
/// <summary>
/// 备份数据库
/// 获取备份列表 🔖
/// </summary>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Add")]
[DisplayName("获取备份列表")]
public List<DbBackupOutput> GetList()
{
try
{
var fileList = Directory.GetFiles(backupDir);
var dbBackupList = new List<DbBackupOutput>();
foreach (var item in fileList)
{
var info = new FileInfo(item);
dbBackupList.Add(new DbBackupOutput
{
FileName = info.Name,
Size = info.Length,
CreateTime = info.CreationTime
});
}
return dbBackupList;
}
catch
{
return null;
}
}
/// <summary>
/// 备份数据库 🔖
/// </summary>
/// <returns></returns>
[ApiDescriptionSettings(Name = "Add"), HttpPost]
[DisplayName("备份数据库")]
public async Task AddBackup()
{
@ -36,10 +63,22 @@ public class DbBackupService : IDynamicApiController, ITransient
}
/// <summary>
/// 备份数据库 用于job调用
/// 删除备份 🔖
/// </summary>
/// <param name="fileName"></param>
[ApiDescriptionSettings(Name = "Delete"), HttpPost]
[DisplayName("删除备份")]
public void DeleteBackup([FromQuery] string fileName)
{
var path = Path.Combine(backupDir, fileName);
File.Delete(path);
}
/// <summary>
/// 备份数据库
/// </summary>
/// <returns></returns>
[ApiDescriptionSettings(false)]
[NonAction]
public async Task Backup()
{
await Task.Run(() =>
@ -48,9 +87,10 @@ public class DbBackupService : IDynamicApiController, ITransient
foreach (var option in options.ConnectionConfigs)
{
var configId = option.ConfigId == null || string.IsNullOrWhiteSpace(option.ConfigId.ToString())
? SqlSugarConst.MainConfigId
: option.ConfigId.ToString();
if (option?.DbType == SqlSugar.DbType.MySql) //备份mysql 其他数据库自行扩展
? SqlSugarConst.MainConfigId : option.ConfigId.ToString();
// 备份mysql 其他数据库自行扩展
if (option?.DbType == SqlSugar.DbType.MySql)
{
var path = Path.Combine(backupDir, $"{configId}-{DateTime.Now:yyyyMMddHHmmss}.sql");
_sysUserRep.Context.DbMaintenance.BackupDataBase(_sysUserRep.Context.Ado.Connection.Database, path);
@ -63,7 +103,7 @@ public class DbBackupService : IDynamicApiController, ITransient
/// 删除过期备份文件
/// </summary>
/// <param name="day">过期天数</param>
[ApiDescriptionSettings(false)]
[NonAction]
public void DeleteExpiredDbFile(int day = 7)
{
var list = Directory.GetFiles(backupDir);
@ -83,41 +123,4 @@ public class DbBackupService : IDynamicApiController, ITransient
}
}
}
/// <summary>
/// 获取备份列表
/// </summary>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Page")]
[DisplayName("获取备份列表")]
public List<BackupDto> GetBackupList()
{
var list = Directory.GetFiles(backupDir);
var result = new List<BackupDto>();
foreach (var item in list)
{
var info = new FileInfo(item);
result.Add(new BackupDto
{
FileName = info.Name,
Size = info.Length,
CreateTime = info.CreationTime
});
}
return result;
}
/// <summary>
/// 删除备份
/// </summary>
/// <param name="fileName"></param>
[HttpPost]
[ApiDescriptionSettings(Name = "Delete")]
[DisplayName("删除备份")]
public void DeleteBackup([FromQuery] string fileName)
{
var path = Path.Combine(backupDir, fileName);
File.Delete(path);
}
}

View File

@ -21,6 +21,7 @@ export * from './apis/sys-common-api';
export * from './apis/sys-config-api';
export * from './apis/sys-const-api';
export * from './apis/sys-database-api';
export * from './apis/sys-db-backup-api';
export * from './apis/sys-dict-data-api';
export * from './apis/sys-dict-type-api';
export * from './apis/sys-email-api';

View File

@ -0,0 +1,288 @@
/* tslint:disable */
/* eslint-disable */
/**
* Admin.NET
* .NET <br/><u><b><font color='FF0000'> 👮</font></b></u>
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
import globalAxios, { AxiosResponse, AxiosInstance, AxiosRequestConfig } from 'axios';
import { Configuration } from '../configuration';
// Some imports not used depending on template conditions
// @ts-ignore
import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base';
import { AdminResultListDbBackupOutput } from '../models';
/**
* SysDbBackupApi - axios parameter creator
* @export
*/
export const SysDbBackupApiAxiosParamCreator = function (configuration?: Configuration) {
return {
/**
*
* @summary 🔖
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiSysDbBackupAddPost: async (options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/api/sysDbBackup/add`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, 'https://example.com');
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions :AxiosRequestConfig = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
// authentication Bearer required
// http bearer authentication required
if (configuration && configuration.accessToken) {
const accessToken = typeof configuration.accessToken === 'function'
? await configuration.accessToken()
: await configuration.accessToken;
localVarHeaderParameter["Authorization"] = "Bearer " + accessToken;
}
const query = new URLSearchParams(localVarUrlObj.search);
for (const key in localVarQueryParameter) {
query.set(key, localVarQueryParameter[key]);
}
for (const key in options.params) {
query.set(key, options.params[key]);
}
localVarUrlObj.search = (new URLSearchParams(query)).toString();
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
return {
url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
options: localVarRequestOptions,
};
},
/**
*
* @summary 🔖
* @param {string} [fileName]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiSysDbBackupDeletePost: async (fileName?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/api/sysDbBackup/delete`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, 'https://example.com');
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions :AxiosRequestConfig = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
// authentication Bearer required
// http bearer authentication required
if (configuration && configuration.accessToken) {
const accessToken = typeof configuration.accessToken === 'function'
? await configuration.accessToken()
: await configuration.accessToken;
localVarHeaderParameter["Authorization"] = "Bearer " + accessToken;
}
if (fileName !== undefined) {
localVarQueryParameter['fileName'] = fileName;
}
const query = new URLSearchParams(localVarUrlObj.search);
for (const key in localVarQueryParameter) {
query.set(key, localVarQueryParameter[key]);
}
for (const key in options.params) {
query.set(key, options.params[key]);
}
localVarUrlObj.search = (new URLSearchParams(query)).toString();
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
return {
url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
options: localVarRequestOptions,
};
},
/**
*
* @summary 🔖
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiSysDbBackupListGet: async (options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/api/sysDbBackup/list`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, 'https://example.com');
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions :AxiosRequestConfig = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
// authentication Bearer required
// http bearer authentication required
if (configuration && configuration.accessToken) {
const accessToken = typeof configuration.accessToken === 'function'
? await configuration.accessToken()
: await configuration.accessToken;
localVarHeaderParameter["Authorization"] = "Bearer " + accessToken;
}
const query = new URLSearchParams(localVarUrlObj.search);
for (const key in localVarQueryParameter) {
query.set(key, localVarQueryParameter[key]);
}
for (const key in options.params) {
query.set(key, options.params[key]);
}
localVarUrlObj.search = (new URLSearchParams(query)).toString();
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
return {
url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
options: localVarRequestOptions,
};
},
}
};
/**
* SysDbBackupApi - functional programming interface
* @export
*/
export const SysDbBackupApiFp = function(configuration?: Configuration) {
return {
/**
*
* @summary 🔖
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiSysDbBackupAddPost(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<void>>> {
const localVarAxiosArgs = await SysDbBackupApiAxiosParamCreator(configuration).apiSysDbBackupAddPost(options);
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
return axios.request(axiosRequestArgs);
};
},
/**
*
* @summary 🔖
* @param {string} [fileName]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiSysDbBackupDeletePost(fileName?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<void>>> {
const localVarAxiosArgs = await SysDbBackupApiAxiosParamCreator(configuration).apiSysDbBackupDeletePost(fileName, options);
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
return axios.request(axiosRequestArgs);
};
},
/**
*
* @summary 🔖
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiSysDbBackupListGet(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<AdminResultListDbBackupOutput>>> {
const localVarAxiosArgs = await SysDbBackupApiAxiosParamCreator(configuration).apiSysDbBackupListGet(options);
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
return axios.request(axiosRequestArgs);
};
},
}
};
/**
* SysDbBackupApi - factory interface
* @export
*/
export const SysDbBackupApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
return {
/**
*
* @summary 🔖
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiSysDbBackupAddPost(options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
return SysDbBackupApiFp(configuration).apiSysDbBackupAddPost(options).then((request) => request(axios, basePath));
},
/**
*
* @summary 🔖
* @param {string} [fileName]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiSysDbBackupDeletePost(fileName?: string, options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
return SysDbBackupApiFp(configuration).apiSysDbBackupDeletePost(fileName, options).then((request) => request(axios, basePath));
},
/**
*
* @summary 🔖
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiSysDbBackupListGet(options?: AxiosRequestConfig): Promise<AxiosResponse<AdminResultListDbBackupOutput>> {
return SysDbBackupApiFp(configuration).apiSysDbBackupListGet(options).then((request) => request(axios, basePath));
},
};
};
/**
* SysDbBackupApi - object-oriented interface
* @export
* @class SysDbBackupApi
* @extends {BaseAPI}
*/
export class SysDbBackupApi extends BaseAPI {
/**
*
* @summary 🔖
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof SysDbBackupApi
*/
public async apiSysDbBackupAddPost(options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
return SysDbBackupApiFp(this.configuration).apiSysDbBackupAddPost(options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary 🔖
* @param {string} [fileName]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof SysDbBackupApi
*/
public async apiSysDbBackupDeletePost(fileName?: string, options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
return SysDbBackupApiFp(this.configuration).apiSysDbBackupDeletePost(fileName, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary 🔖
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof SysDbBackupApi
*/
public async apiSysDbBackupListGet(options?: AxiosRequestConfig) : Promise<AxiosResponse<AdminResultListDbBackupOutput>> {
return SysDbBackupApiFp(this.configuration).apiSysDbBackupListGet(options).then((request) => request(this.axios, this.basePath));
}
}

View File

@ -399,6 +399,14 @@ export interface AddUserInput {
*/
signature?: string | null;
/**
* Token版本号
*
* @type {number}
* @memberof AddUserInput
*/
tokenVersion?: number;
/**
*
*

View File

@ -0,0 +1,71 @@
/* tslint:disable */
/* eslint-disable */
/**
* Admin.NET
* .NET <br/><u><b><font color='FF0000'> 👮</font></b></u>
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
import { DbBackupOutput } from './db-backup-output';
/**
*
*
* @export
* @interface AdminResultListDbBackupOutput
*/
export interface AdminResultListDbBackupOutput {
/**
*
*
* @type {number}
* @memberof AdminResultListDbBackupOutput
*/
code?: number;
/**
* successwarningerror
*
* @type {string}
* @memberof AdminResultListDbBackupOutput
*/
type?: string | null;
/**
*
*
* @type {string}
* @memberof AdminResultListDbBackupOutput
*/
message?: string | null;
/**
*
*
* @type {Array<DbBackupOutput>}
* @memberof AdminResultListDbBackupOutput
*/
result?: Array<DbBackupOutput> | null;
/**
*
*
* @type {any}
* @memberof AdminResultListDbBackupOutput
*/
extras?: any | null;
/**
*
*
* @type {Date}
* @memberof AdminResultListDbBackupOutput
*/
time?: Date;
}

View File

@ -13,12 +13,13 @@
*/
/**
* <br />&nbsp; Frontend = 1<br />&nbsp; Backend = 2<br />
* <br />&nbsp; Frontend = 1<br />&nbsp; Backend = 2<br />&nbsp; SeedData = 3<br />
* @export
* @enum {string}
*/
export enum CodeGenTypeEnum {
NUMBER_1 = 1,
NUMBER_2 = 2
NUMBER_2 = 2,
NUMBER_3 = 3
}

View File

@ -0,0 +1,40 @@
/* tslint:disable */
/* eslint-disable */
/**
* Admin.NET
* .NET <br/><u><b><font color='FF0000'> 👮</font></b></u>
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
/**
*
*
* @export
* @interface DbBackupOutput
*/
export interface DbBackupOutput {
/**
* @type {string}
* @memberof DbBackupOutput
*/
fileName?: string | null;
/**
* @type {Date}
* @memberof DbBackupOutput
*/
createTime?: Date;
/**
* @type {number}
* @memberof DbBackupOutput
*/
size?: number;
}

View File

@ -36,6 +36,7 @@ export * from './admin-result-list-code-gen-config';
export * from './admin-result-list-column-ouput';
export * from './admin-result-list-const-output';
export * from './admin-result-list-database-output';
export * from './admin-result-list-db-backup-output';
export * from './admin-result-list-db-column-output';
export * from './admin-result-list-db-table-info';
export * from './admin-result-list-enum-entity';
@ -149,6 +150,7 @@ export * from './data-table';
export * from './database-output';
export * from './date-time-format-info';
export * from './day-of-week';
export * from './db-backup-output';
export * from './db-column-input';
export * from './db-column-output';
export * from './db-object-type';

View File

@ -414,6 +414,14 @@ export interface SysUser {
*/
signature?: string | null;
/**
* Token版本号
*
* @type {number}
* @memberof SysUser
*/
tokenVersion?: number;
/**
*
*

View File

@ -399,6 +399,14 @@ export interface UpdateUserInput {
*/
signature?: string | null;
/**
* Token版本号
*
* @type {number}
* @memberof UpdateUserInput
*/
tokenVersion?: number;
/**
*
*

View File

@ -414,6 +414,14 @@ export interface UserOutput {
*/
signature?: string | null;
/**
* Token版本号
*
* @type {number}
* @memberof UserOutput
*/
tokenVersion?: number;
/**
*
*

View File

@ -17,25 +17,3 @@ export const getAllDictList = () =>
url: `${Api.AllDictList}`,
method: 'get',
});
// 获取所有备份文件
export const getBackupList = () =>
request({
url: `/api/dbBackup/page`,
method: 'post',
});
// 新增备份文件
export const addBackup = () =>
request({
url: `/api/dbBackup/add`,
method: 'post',
});
// 删除备份文件
export const deleteBackup = (fileName: String) =>
request({
url: `/api/dbBackup/delete`,
method: 'post',
params: { fileName },
});

View File

@ -0,0 +1,85 @@
<template>
<div>
<el-card class="full-table" shadow="hover" style="margin-top: 5px">
<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options">
<template #toolbar_buttons>
<el-button type="primary" icon="ele-Plus" @click="handleAdd" v-auth="'dbBackup/add'" :loading="loading"> 新增 </el-button>
</template>
<template #toolbar_tools> </template>
<template #row_createTime="{ row }">
<el-tooltip :content="row.createTime" placement="top">
<span>{{ formatPast(row.createTime) }}</span>
</el-tooltip>
</template>
<template #row_size="{ row }">
<span>{{ (row.size / 1024 / 1024).toFixed(2) }} MB</span>
</template>
<template #row_buttons="{ row }">
<el-tooltip content="删除" placement="top">
<el-button icon="ele-Delete" text type="danger" v-auth="'dbBackup/delete'" @click="handleDelete(row)"> </el-button>
</el-tooltip>
</template>
</vxe-grid>
</el-card>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { VxeGridInstance } from 'vxe-table';
import { useVxeTable } from '/@/hooks/useVxeTableOptionsHook';
import { formatPast } from '/@/utils/formatTime';
import { getAPI } from '/@/utils/axios-utils';
import { SysDbBackupApi } from '/@/api-services/api';
const xGrid = ref<VxeGridInstance>();
const loading = ref(false);
//
const options = useVxeTable(
{
id: 'dbBackup',
name: '备份信息',
columns: [
// { type: 'checkbox', width: 40, fixed: 'left' },
{ type: 'seq', title: '序号', width: 60, fixed: 'left' },
{ field: 'fileName', title: '文件名称', minWidth: 200, showOverflow: 'tooltip' },
{ field: 'size', title: '文件大小', width: 150, showOverflow: 'tooltip', slots: { default: 'row_size' } },
{ field: 'createTime', title: '备份时间', width: 200, showOverflow: 'tooltip', slots: { default: 'row_createTime' } },
{ title: '操作', fixed: 'right', width: 150, showOverflow: true, slots: { default: 'row_buttons' } },
],
},
{
//
proxyConfig: { autoLoad: true, ajax: { query: () => handleQueryApi() } },
//
pagerConfig: { enabled: false },
//
toolbarConfig: { enabled: false },
}
);
// api
const handleQueryApi = async () => {
return await getAPI(SysDbBackupApi).apiSysDbBackupListGet();
};
//
const handleAdd = async () => {
loading.value = true;
await getAPI(SysDbBackupApi).apiSysDbBackupAddPost();
loading.value = false;
await xGrid.value?.commitProxy('reload');
};
//
const handleDelete = async (row: any) => {
loading.value = true;
await getAPI(SysDbBackupApi).apiSysDbBackupDeletePost(row.fileName);
loading.value = false;
await xGrid.value?.commitProxy('reload');
};
</script>
<style scoped></style>

View File

@ -1,129 +0,0 @@
<template>
<div>
<el-card class="full-table" shadow="hover" style="margin-top: 5px">
<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" v-on="gridEvents">
<template #toolbar_buttons>
<el-button
type="primary"
icon="ele-Plus"
@click="handleAdd"
v-auth="'dbBackup/add'"
:loading="loading"
>
新增
</el-button>
</template>
<template #toolbar_tools> </template>
<template #row_createTime="{ row }">
<el-tooltip :content="row.createTime" placement="top">
<span>{{ formatPast(row.createTime) }}</span>
</el-tooltip>
</template>
<template #row_size="{ row }">
<span>{{ (row.size / 1024 / 1024).toFixed(2) }} MB</span>
</template>
<template #row_buttons="{ row }">
<el-tooltip content="删除" placement="top">
<el-button
icon="ele-Delete"
text
type="danger"
v-auth="'dbBackup/delete'"
@click="handleDelete(row)"
>
</el-button>
</el-tooltip>
</template>
</vxe-grid>
</el-card>
</div>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { ElMessageBox, ElMessage } from "element-plus";
import { VxeGridInstance, VxeGridListeners } from "vxe-table";
import { useVxeTable } from "/@/hooks/useVxeTableOptionsHook";
import { formatPast } from "/@/utils/formatTime";
import { getBackupList, addBackup, deleteBackup } from "/@/api/system/admin";
const xGrid = ref<VxeGridInstance>();
const loading = ref(false);
//
const options = useVxeTable(
{
id: "dbBackup",
name: "备份信息",
columns: [
// { type: 'checkbox', width: 40, fixed: 'left' },
{ type: "seq", title: "序号", width: 60, fixed: "left" },
{
field: "fileName",
title: "文件名称",
minWidth: 180,
showOverflow: "tooltip",
treeNode: true,
align: "left",
headerAlign: "center",
},
{
field: "size",
title: "文件大小",
width: 100,
showOverflow: "tooltip",
slots: { default: "row_size" },
},
{
field: "createTime",
title: "备份时间",
width: 140,
showOverflow: "tooltip",
slots: { default: "row_createTime" },
},
{
title: "操作",
fixed: "right",
width: 100,
showOverflow: true,
slots: { default: "row_buttons" },
},
],
},
// vxeGrid()vxe-table
{
stripe: false,
//
checkboxConfig: { range: false },
//
proxyConfig: { autoLoad: true, ajax: { query: () => handleQueryApi() } },
//
pagerConfig: { enabled: false },
//
toolbarConfig: { export: false },
//
treeConfig: { expandAll: false },
}
);
// api
const handleQueryApi = async () => {
return getBackupList();
};
const handleAdd = async () => {
loading.value = true;
await addBackup();
loading.value = false;
await xGrid.value?.commitProxy("reload");
};
const handleDelete = async (row: any) => {
loading.value = true;
await deleteBackup(row.fileName);
loading.value = false;
await xGrid.value?.commitProxy("reload");
};
</script>
<style scoped></style>