feat: 数据库备份下载支持

This commit is contained in:
许俊杰 2025-03-20 13:42:02 +08:00
parent 34d9c80c5f
commit b00675c00e
2 changed files with 35 additions and 0 deletions

View File

@ -50,6 +50,8 @@ public class SysDbBackupService : IDynamicApiController, ITransient
}); });
} }
dbBackupList = dbBackupList.OrderByDescending(u => u.CreateTime).ToList();
return dbBackupList; return dbBackupList;
} }
catch catch
@ -156,4 +158,19 @@ public class SysDbBackupService : IDynamicApiController, ITransient
} }
} }
} }
/// <summary>
/// 下载备份 🔖
/// </summary>
/// <param name="fileName"></param>
[ApiDescriptionSettings(Name = "Download"), HttpGet]
[DisplayName("下载备份")]
[AllowAnonymous]
[NonUnify]
public IActionResult Download(string fileName)
{
var path = Path.Combine(_backupDir, fileName);
var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return new FileStreamResult(fs, "application/octet-stream") { FileDownloadName = fileName };
}
} }

View File

@ -28,6 +28,7 @@
</template> </template>
<template #row_buttons="{ row }"> <template #row_buttons="{ row }">
<el-button icon="ele-Delete" text type="danger" v-auth="'dbBackup/delete'" @click="handleDelete(row)"> 删除 </el-button> <el-button icon="ele-Delete" text type="danger" v-auth="'dbBackup/delete'" @click="handleDelete(row)"> 删除 </el-button>
<el-button icon="ele-Download" text type="primary" @click="handleDownload(row)"> 下载 </el-button>
</template> </template>
</vxe-grid> </vxe-grid>
</el-card> </el-card>
@ -127,6 +128,23 @@ const handleDelete = async (row: any) => {
state.loading = false; state.loading = false;
} }
}; };
//
const handleDownload = (row: any) => {
const baseUrl = import.meta.env.VITE_API_URL;
let url = `${baseUrl}/api/sysDbBackup/download/${row.fileName}`;
const tempLink = document.createElement('a');
tempLink.style.display = 'none';
tempLink.href = url;
tempLink.setAttribute('download', row.fileName);
if (typeof tempLink.download === 'undefined') {
tempLink.setAttribute('target', '_blank');
}
document.body.appendChild(tempLink);
tempLink.click();
document.body.removeChild(tempLink);
};
</script> </script>
<style scoped></style> <style scoped></style>