接口批量导入
This commit is contained in:
parent
d8ccd833d2
commit
81a9b47a3f
82
admin.html
82
admin.html
@ -174,6 +174,7 @@
|
|||||||
<div style="display:flex;gap:8px;align-items:center;">
|
<div style="display:flex;gap:8px;align-items:center;">
|
||||||
<el-input size="small" v-model="apiSearch" placeholder="搜索接口名称或路径" clearable style="width:220px;" prefix-icon="el-icon-search"></el-input>
|
<el-input size="small" v-model="apiSearch" placeholder="搜索接口名称或路径" clearable style="width:220px;" prefix-icon="el-icon-search"></el-input>
|
||||||
<el-button size="mini" type="primary" @click="openApiDialogForCreate">新增接口</el-button>
|
<el-button size="mini" type="primary" @click="openApiDialogForCreate">新增接口</el-button>
|
||||||
|
<el-button size="mini" type="success" @click="openBatchImportDialog">批量导入</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<el-table :data="pagedApiList" border style="width: 100%;">
|
<el-table :data="pagedApiList" border style="width: 100%;">
|
||||||
@ -407,6 +408,30 @@
|
|||||||
<el-button type="primary" @click="submitApiDialog">确定</el-button>
|
<el-button type="primary" @click="submitApiDialog">确定</el-button>
|
||||||
</span>
|
</span>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
|
<el-dialog
|
||||||
|
title="批量导入接口"
|
||||||
|
:visible.sync="batchImportDialog.visible"
|
||||||
|
width="600px"
|
||||||
|
>
|
||||||
|
<el-form label-width="80px">
|
||||||
|
<el-form-item label="JSON 数据">
|
||||||
|
<el-input
|
||||||
|
type="textarea"
|
||||||
|
:rows="10"
|
||||||
|
v-model="batchImportDialog.input"
|
||||||
|
placeholder='[{"route":"/api/xxxx","name":"登录接口"}]'
|
||||||
|
></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<div style="color:#909399;font-size:12px;margin-top:-8px;padding-left:80px;">
|
||||||
|
格式:JSON 数组,每项包含 route(请求路径)和 name(接口名称)
|
||||||
|
</div>
|
||||||
|
<span slot="footer" class="dialog-footer">
|
||||||
|
<el-button @click="batchImportDialog.visible = false">取消</el-button>
|
||||||
|
<el-button type="primary" @click="submitBatchImport">导入</el-button>
|
||||||
|
</span>
|
||||||
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -426,6 +451,10 @@
|
|||||||
editingIndex: -1,
|
editingIndex: -1,
|
||||||
form: { name: "", route: "", originalRoute: "" },
|
form: { name: "", route: "", originalRoute: "" },
|
||||||
},
|
},
|
||||||
|
batchImportDialog: {
|
||||||
|
visible: false,
|
||||||
|
input: "",
|
||||||
|
},
|
||||||
mockFiles: [],
|
mockFiles: [],
|
||||||
contentTypeOptions: [
|
contentTypeOptions: [
|
||||||
"application/json",
|
"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: {
|
computed: {
|
||||||
filteredRoutes: function () {
|
filteredRoutes: function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user