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 () {