From 81a9b47a3fc8b69597cd2d52515ca938f4133add Mon Sep 17 00:00:00 2001 From: dongzp <975303544@qq.com> Date: Thu, 4 Jun 2026 12:24:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=89=B9=E9=87=8F=E5=AF=BC?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin.html | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/admin.html b/admin.html index 44b5f74..b4e067b 100644 --- a/admin.html +++ b/admin.html @@ -174,6 +174,7 @@
新增接口 + 批量导入
@@ -407,6 +408,30 @@ 确定 + + + + + + + +
+ 格式:JSON 数组,每项包含 route(请求路径)和 name(接口名称) +
+ + 取消 + 导入 + +
@@ -426,6 +451,10 @@ editingIndex: -1, form: { name: "", route: "", originalRoute: "" }, }, + batchImportDialog: { + visible: false, + input: "", + }, mockFiles: [], contentTypeOptions: [ "application/json", @@ -925,6 +954,59 @@ } } }, + openBatchImportDialog: function () { + this.batchImportDialog.input = ""; + this.batchImportDialog.visible = true; + }, + submitBatchImport: async function () { + var raw = (this.batchImportDialog.input || "").trim(); + if (!raw) { + this.$message.error("请输入 JSON 数据"); + return; + } + var list; + try { + list = JSON.parse(raw); + } catch (e) { + this.$message.error("JSON 格式不正确:" + e.message); + return; + } + if (!Array.isArray(list) || list.length === 0) { + this.$message.error("请输入非空 JSON 数组"); + return; + } + var okCount = 0; + var failCount = 0; + for (var i = 0; i < list.length; i++) { + var item = list[i]; + if (!item || !item.route || !item.name) { + failCount++; + continue; + } + try { + var resp = await fetch("/__api-list", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ route: item.route, name: item.name }), + }); + var data = await resp.json(); + if (resp.ok && data.success !== false) { + okCount++; + } else { + failCount++; + } + } catch (err) { + failCount++; + } + } + if (okCount > 0) { + this.$message.success("成功导入 " + okCount + " 条" + (failCount > 0 ? ",失败 " + failCount + " 条" : "")); + } else { + this.$message.error("导入失败,共 " + failCount + " 条"); + } + this.batchImportDialog.visible = false; + await this.loadApiList(); + }, }, computed: { filteredRoutes: function () {