From e0e060799fd5ffb7cbd4685966f2b36a4a4f41b2 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期二, 01 九月 2026 10:26:00 +0800
Subject: [PATCH] fix: 新疆-绿能 1.打包部署配置
---
src/api/system/database/index.ts | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/src/api/system/database/index.ts b/src/api/system/database/index.ts
new file mode 100644
index 0000000..261d7f2
--- /dev/null
+++ b/src/api/system/database/index.ts
@@ -0,0 +1,50 @@
+import { requestClient } from '#/api/request';
+
+function downloadBlob(blob: Blob, headers?: any) {
+ let filename = 'backup.sql';
+ if (headers) {
+ const disposition = headers['content-disposition'] || headers['Content-Disposition'];
+ if (disposition && disposition.indexOf('filename=') !== -1) {
+ const matches = disposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
+ if (matches != null && matches[1]) {
+ filename = matches[1].replace(/['"]/g, '');
+ }
+ }
+ }
+
+ const url = window.URL.createObjectURL(blob);
+ const link = document.createElement('a');
+ link.style.display = 'none';
+ link.href = url;
+ link.setAttribute('download', decodeURIComponent(filename));
+ document.body.append(link);
+ link.click();
+ link.remove();
+ window.URL.revokeObjectURL(url);
+}
+
+/** 涓嬭浇鏁版嵁搴撳浠芥枃浠� */
+export function backupDatabase(onDownloadProgress?: (progressEvent: any) => void) {
+ return requestClient.request('/system/database/backup', {
+ method: 'GET',
+ responseType: 'blob',
+ timeout: 300000, // 5鍒嗛挓
+ onDownloadProgress,
+ responseReturn: 'raw',
+ }).then((res: any) => {
+ const blob = res.data || res;
+ if (blob instanceof Blob) {
+ downloadBlob(blob, res.headers);
+ }
+ return res;
+ }).catch((err: any) => {
+ if (err instanceof Blob) {
+ downloadBlob(err);
+ return err;
+ } else if (err?.response?.data instanceof Blob) {
+ downloadBlob(err.response.data, err.response.headers);
+ return err;
+ }
+ throw err;
+ });
+}
--
Gitblit v1.9.3