Skip to content

Commit ff6dc64

Browse files
authored
Merge pull request #21 from songhahaha66/main
feat: add import/export page
2 parents e988b17 + 3a5f4df commit ff6dc64

8 files changed

Lines changed: 425 additions & 6 deletions

File tree

components.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ declare module 'vue' {
2525
NDescriptions: typeof import('naive-ui')['NDescriptions']
2626
NDescriptionsItem: typeof import('naive-ui')['NDescriptionsItem']
2727
NDialogProvider: typeof import('naive-ui')['NDialogProvider']
28-
NDivider: typeof import('naive-ui')['NDivider']
2928
NDrawer: typeof import('naive-ui')['NDrawer']
3029
NDrawerContent: typeof import('naive-ui')['NDrawerContent']
3130
NDropdown: typeof import('naive-ui')['NDropdown']
@@ -50,6 +49,7 @@ declare module 'vue' {
5049
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
5150
NModal: typeof import('naive-ui')['NModal']
5251
NNotificationProvider: typeof import('naive-ui')['NNotificationProvider']
52+
NP: typeof import('naive-ui')['NP']
5353
NPageHeader: typeof import('naive-ui')['NPageHeader']
5454
NPopconfirm: typeof import('naive-ui')['NPopconfirm']
5555
NProgress: typeof import('naive-ui')['NProgress']
@@ -67,6 +67,8 @@ declare module 'vue' {
6767
NText: typeof import('naive-ui')['NText']
6868
NThing: typeof import('naive-ui')['NThing']
6969
NTooltip: typeof import('naive-ui')['NTooltip']
70+
NUpload: typeof import('naive-ui')['NUpload']
71+
NUploadDragger: typeof import('naive-ui')['NUploadDragger']
7072
NVirtualList: typeof import('naive-ui')['NVirtualList']
7173
RouterLink: typeof import('vue-router')['RouterLink']
7274
RouterView: typeof import('vue-router')['RouterView']

composables/useExport.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { exportFile } from '~/utils/export-file';
2+
3+
export const useImportExport = () => {
4+
const { $api } = useNuxtApp();
5+
const message = useMessage();
6+
const { t } = useI18n();
7+
8+
const isLoading = ref(false);
9+
10+
/**
11+
* 导出完整的IAM配置
12+
* 调用后端 /export-iam 接口,返回ZIP格式文件
13+
*/
14+
const exportIamConfig = async (): Promise<void> => {
15+
try {
16+
isLoading.value = true;
17+
18+
// 调用后端导出接口,不解析JSON以获取原始Response对象
19+
const response = await $api.request('/export-iam', {
20+
method: 'GET',
21+
headers: {
22+
'Accept': 'application/zip',
23+
},
24+
}, false);
25+
26+
// 生成文件名,包含时间戳
27+
const timestamp = new Date().toISOString().slice(0, 19).replace(/[:-]/g, '');
28+
const fileName = `iam-config-export-${timestamp}.zip`;
29+
30+
// 获取blob数据
31+
const blob = await response.blob();
32+
33+
// 创建包含blob和headers的响应对象格式,兼容exportFile函数
34+
const exportResponse = {
35+
data: blob,
36+
headers: {
37+
'content-type': 'application/zip',
38+
filename: encodeURIComponent(fileName),
39+
},
40+
};
41+
42+
// 使用现有的导出工具函数下载文件
43+
exportFile(exportResponse, fileName);
44+
45+
message.success(t('IAM configuration exported successfully'));
46+
} catch (error: any) {
47+
console.error('IAM export error:', error);
48+
message.error(error.message || t('Failed to export IAM configuration'));
49+
} finally {
50+
isLoading.value = false;
51+
}
52+
};
53+
54+
/**
55+
* 导入IAM配置
56+
* 调用后端 /import-iam 接口,上传ZIP格式文件
57+
*/
58+
const importIamConfig = async (file: File): Promise<void> => {
59+
try {
60+
isLoading.value = true;
61+
62+
// 调用后端导入接口
63+
await $api.request('/import-iam', {
64+
method: 'PUT',
65+
body: file, // 直接发送文件对象
66+
headers: {
67+
'Content-Type': 'application/zip',
68+
},
69+
}, false);
70+
71+
message.success(t('IAM configuration imported successfully'));
72+
} catch (error: any) {
73+
console.error('IAM import error:', error);
74+
message.error(error.message || t('Failed to import IAM configuration'));
75+
} finally {
76+
isLoading.value = false;
77+
}
78+
};
79+
80+
return {
81+
isLoading: readonly(isLoading),
82+
exportIamConfig,
83+
importIamConfig,
84+
};
85+
};

config/navs.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export default [
2222
to: '/users',
2323
icon: 'ri:file-user-line',
2424
},
25+
{
26+
label: 'Import/Export',
27+
to: '/import-export',
28+
icon: 'ri:download-2-line',
29+
},
2530
{
2631
label: 'Performance',
2732
to: '/performance',

i18n/locales/en-US.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,5 +793,30 @@
793793
"Please fill in at least one configuration item": "Please fill in at least one configuration item",
794794
"Please select resource name": "Please select resource name",
795795
"Please select at least one event": "Please select at least one event",
796-
"Are you sure you want to delete this notification configuration?": "Are you sure you want to delete this notification configuration?"
796+
"Are you sure you want to delete this notification configuration?": "Are you sure you want to delete this notification configuration?",
797+
"Import/Export": "Import/Export",
798+
"IAM": "IAM",
799+
"IAM Configuration Export": "IAM Configuration Export",
800+
"Export all IAM configurations including users, groups, policies, and access keys in a ZIP file.": "Export all IAM configurations including users, groups, policies, and access keys in a ZIP file.",
801+
"Users AK/SK": "Users AK/SK",
802+
"AK/SK": "AK/SK",
803+
"The exported file contains sensitive information. Please keep it secure.": "The exported file contains sensitive information. Please keep it secure.",
804+
"Export IAM Configuration": "Export IAM Configuration",
805+
"Download complete IAM configuration as ZIP file": "Download complete IAM configuration as ZIP file",
806+
"Export Now": "Export Now",
807+
"Exporting...": "Exporting...",
808+
"IAM configuration exported successfully": "IAM configuration exported successfully",
809+
"Failed to export IAM configuration": "Failed to export IAM configuration",
810+
"IAM Configuration Import": "IAM Configuration Import",
811+
"Import IAM configurations from a previously exported ZIP file.": "Import IAM configurations from a previously exported ZIP file.",
812+
"Select ZIP File": "Select ZIP File",
813+
"Click or drag ZIP file to this area to upload": "Click or drag ZIP file to this area to upload",
814+
"Only ZIP files are supported, and file size should not exceed 10MB": "Only ZIP files are supported, and file size should not exceed 10MB",
815+
"Import IAM Configuration": "Import IAM Configuration",
816+
"Ready to import: {filename}": "Ready to import: {filename}",
817+
"Please select a ZIP file to import": "Please select a ZIP file to import",
818+
"Import Now": "Import Now",
819+
"Importing...": "Importing...",
820+
"IAM configuration imported successfully": "IAM configuration imported successfully",
821+
"Failed to import IAM configuration": "Failed to import IAM configuration"
797822
}

i18n/locales/tr-TR.json

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,5 +794,36 @@
794794
"Please fill in at least one configuration item": "Lütfen en az bir yapılandırma öğesi doldurun",
795795
"Please select resource name": "Lütfen kaynak adını seçin",
796796
"Please select at least one event": "Lütfen en az bir etkinlik seçin",
797-
"Are you sure you want to delete this notification configuration?": "Bu bildirim yapılandırmasını silmek istediğinizden emin misiniz?"
797+
"Are you sure you want to delete this notification configuration?": "Bu bildirim yapılandırmasını silmek istediğinizden emin misiniz?",
798+
"Import/Export": "İçe/Dışa Aktar",
799+
"Export IAM": "IAM Dışa Aktar",
800+
"IAM Export": "IAM Dışa Aktar",
801+
"IAM Configuration Export": "IAM Yapılandırma Dışa Aktar",
802+
"Export all IAM configurations including users, groups, policies, and access keys in a ZIP file.": "Kullanıcıları, grupları, politikaları ve erişim anahtarlarını içeren tüm IAM yapılandırmalarını ZIP dosyası olarak dışa aktarın.",
803+
"Users and Access Keys": "Kullanıcılar ve Erişim Anahtarları",
804+
"IAM Policies": "IAM Politikaları",
805+
"AK/SK": "AK/SK",
806+
"The exported file contains sensitive information. Please keep it secure.": "Dışa aktarılan dosya hassas bilgiler içerir. Lütfen güvende tutun.",
807+
"Export IAM Configuration": "IAM Yapılandırmasını Dışa Aktar",
808+
"Download complete IAM configuration as ZIP file": "Tam IAM yapılandırmasını ZIP dosyası olarak indir",
809+
"Export Now": "Şimdi Dışa Aktar",
810+
"Exporting...": "Dışa Aktarılıyor...",
811+
"IAM configuration exported successfully": "IAM yapılandırması başarıyla dışa aktarıldı",
812+
"Failed to export IAM configuration": "IAM yapılandırması dışa aktarılamadı",
813+
"Bucket Export": "Depolama Alanı Dışa Aktar",
814+
"Logs Export": "Günlük Dışa Aktar",
815+
"IAM Configuration Import": "IAM Yapılandırma İçe Aktar",
816+
"Import IAM configurations from a previously exported ZIP file.": "Önceden dışa aktarılmış bir ZIP dosyasından IAM yapılandırmalarını içe aktarın.",
817+
"Importing will incrementally update existing configurations. New items will be added and existing items will be updated.": "İçe aktarma mevcut yapılandırmaları artımlı olarak güncelleyecektir. Yeni öğeler eklenecek ve mevcut öğeler güncellenecektir.",
818+
"Select ZIP File": "ZIP Dosyası Seç",
819+
"Click or drag ZIP file to this area to upload": "Yüklemek için bu alana ZIP dosyasını tıklayın veya sürükleyin",
820+
"Only ZIP files are supported, and file size should not exceed 10MB": "Sadece ZIP dosyaları desteklenir ve dosya boyutu 10MB'ı aşmamalıdır",
821+
"Import IAM Configuration": "IAM Yapılandırmasını İçe Aktar",
822+
"Ready to import: {filename}": "İçe aktarma hazır: {filename}",
823+
"Please select a ZIP file to import": "Lütfen içe aktarılacak bir ZIP dosyası seçin",
824+
"Import Now": "Şimdi İçe Aktar",
825+
"Importing...": "İçe Aktarılıyor...",
826+
"IAM configuration imported successfully": "IAM yapılandırması başarıyla içe aktarıldı",
827+
"Failed to import IAM configuration": "IAM yapılandırması içe aktarılamadı",
828+
"Coming soon...": "Yakında..."
798829
}

i18n/locales/zh-CN.json

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,5 +794,35 @@
794794
"Please fill in at least one configuration item": "请至少填写一个配置项",
795795
"Please select resource name": "请选择资源名称",
796796
"Please select at least one event": "请至少选择一个事件",
797-
"Are you sure you want to delete this notification configuration?": "您确定要删除此通知配置吗?"
797+
"Are you sure you want to delete this notification configuration?": "您确定要删除此通知配置吗?",
798+
"Import/Export": "导入/导出",
799+
"Export IAM": "导出IAM",
800+
"IAM Export": "IAM导出",
801+
"IAM Configuration Export": "IAM配置导出",
802+
"Export all IAM configurations including users, groups, policies, and access keys in a ZIP file.": "导出所有IAM配置,包括用户、用户组、策略和访问密钥,打包为ZIP文件。",
803+
"IAM Policies": "IAM策略",
804+
"AK/SK": "AK/SK",
805+
"The exported file contains sensitive information. Please keep it secure.": "导出的文件包含敏感信息,请妥善保管。",
806+
"Export IAM Configuration": "导出IAM配置",
807+
"Download complete IAM configuration as ZIP file": "下载完整的IAM配置ZIP文件",
808+
"Export Now": "立即导出",
809+
"Exporting...": "导出中...",
810+
"IAM configuration exported successfully": "IAM配置导出成功",
811+
"Failed to export IAM configuration": "IAM配置导出失败",
812+
"Bucket Export": "存储桶导出",
813+
"Logs Export": "日志导出",
814+
"IAM Configuration Import": "IAM配置导入",
815+
"Import IAM configurations from a previously exported ZIP file.": "从之前导出的ZIP文件导入IAM配置。",
816+
"Importing will incrementally update existing configurations. New items will be added and existing items will be updated.": "导入将增量更新现有配置。新增项目将被添加,现有项目将被更新。",
817+
"Select ZIP File": "选择ZIP文件",
818+
"Click or drag ZIP file to this area to upload": "点击或拖拽ZIP文件到此区域上传",
819+
"Only ZIP files are supported, and file size should not exceed 10MB": "仅支持ZIP文件,文件大小不应超过10MB",
820+
"Import IAM Configuration": "导入IAM配置",
821+
"Ready to import: {filename}": "准备导入:{filename}",
822+
"Please select a ZIP file to import": "请选择要导入的ZIP文件",
823+
"Import Now": "立即导入",
824+
"Importing...": "导入中...",
825+
"IAM configuration imported successfully": "IAM配置导入成功",
826+
"Failed to import IAM configuration": "IAM配置导入失败",
827+
"Coming soon...": "即将推出..."
798828
}

lib/api-client.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ class ApiClient {
2727
async request(url: string, options: RequestOptions = {}, parseJson: boolean = true) {
2828
url = this.config?.baseUrl ? joinURL(this.config?.baseUrl, url) : url;
2929
options.headers = { ...this.config?.headers, ...options.headers };
30-
// 处理body的数据格式
31-
options.body ? (options.body = JSON.stringify(options.body)) : null;
30+
// 处理body的数据格式,只对普通对象序列化
31+
if (options.body &&
32+
!(options.body instanceof FormData) &&
33+
!(options.body instanceof Blob) &&
34+
!(options.body instanceof ArrayBuffer) &&
35+
!(options.body instanceof Uint8Array) &&
36+
!(options.body instanceof File)) {
37+
options.body = JSON.stringify(options.body);
38+
}
3239

3340
if (options.params) {
3441
const queryString = new URLSearchParams(options.params).toString();

0 commit comments

Comments
 (0)