From 5ec26ef4584e1a9c8f48f89cf1749f91b92d8a93 Mon Sep 17 00:00:00 2001 From: maslow Date: Thu, 9 Sep 2021 18:21:00 +0800 Subject: [PATCH] feat(sys-client): impl import/export app; --- packages/system-client/src/api/application.js | 29 +++++ packages/system-client/src/utils/file.js | 28 ++++ .../src/views/application/index.vue | 121 ++++++++++++++++-- 3 files changed, 166 insertions(+), 12 deletions(-) create mode 100644 packages/system-client/src/utils/file.js diff --git a/packages/system-client/src/api/application.js b/packages/system-client/src/api/application.js index 25d90dbe63..4c1f027e50 100644 --- a/packages/system-client/src/api/application.js +++ b/packages/system-client/src/api/application.js @@ -176,3 +176,32 @@ export async function removeApplicationService(appid) { }) return res } + +/** + * 导出应用 + * @param {string} appid + * @returns + */ +export async function exportApplication(appid) { + const res = await request({ + url: `/apps/${appid}/export`, + method: 'get' + }) + return res +} + +/** + * 导入应用 + * @param {string} appid + * @returns + */ +export async function importApplication(appid, import_data) { + const res = await request({ + url: `/apps/${appid}/import`, + method: 'post', + data: { + import_data + } + }) + return res +} diff --git a/packages/system-client/src/utils/file.js b/packages/system-client/src/utils/file.js new file mode 100644 index 0000000000..b674a4cf93 --- /dev/null +++ b/packages/system-client/src/utils/file.js @@ -0,0 +1,28 @@ + +/** + * export raw text + * @param {string} name + * @param {string} data + */ +export function exportRawText(name, data) { + var urlObject = window.URL || window.webkitURL || window + var export_blob = new Blob([data]) + var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a') + save_link.href = urlObject.createObjectURL(export_blob) + save_link.download = name + save_link.click() +} + +/** + * read text from local file + * @param {File} file + */ +export async function readTextFromFile(file, encoding = 'utf-8') { + const reader = new FileReader() + reader.readAsText(file) + + return new Promise((resolve, reject) => { + reader.onload = () => resolve(reader.result) + reader.onerror = error => reject(error) + }) +} diff --git a/packages/system-client/src/views/application/index.vue b/packages/system-client/src/views/application/index.vue index 3c732231e9..12e175f66d 100644 --- a/packages/system-client/src/views/application/index.vue +++ b/packages/system-client/src/views/application/index.vue @@ -22,8 +22,8 @@ - - + - - +