feat 数据库版本,并且增加状态码
This commit is contained in:
+34
-2
@@ -88,6 +88,11 @@
|
||||
<span>{{ scope.row.filePath }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="返回状态码" width="120" align="center">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.statusCode || 200 }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="启用" width="90" align="center">
|
||||
<template slot-scope="scope">
|
||||
<el-switch v-model="scope.row.enabled"></el-switch>
|
||||
@@ -263,6 +268,14 @@
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="返回状态码">
|
||||
<el-input-number
|
||||
v-model="routeDialog.form.statusCode"
|
||||
:min="100"
|
||||
:max="599"
|
||||
style="width: 100%;"
|
||||
></el-input-number>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否启用 Mock">
|
||||
<el-switch v-model="routeDialog.form.enabled"></el-switch>
|
||||
</el-form-item>
|
||||
@@ -347,6 +360,7 @@
|
||||
originalRawRoute: "",
|
||||
route: "",
|
||||
filePath: "",
|
||||
statusCode: 200,
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
@@ -394,7 +408,7 @@
|
||||
return item.route === route;
|
||||
});
|
||||
},
|
||||
toRouteArray: function (routesObj) {
|
||||
toRouteArray: function (routesObj, routeStatusesObj) {
|
||||
var self = this;
|
||||
return Object.keys(routesObj || {}).map(function (rawRoute) {
|
||||
var enabled = !rawRoute.startsWith("#");
|
||||
@@ -404,6 +418,7 @@
|
||||
rawRoute: rawRoute,
|
||||
route: route,
|
||||
filePath: routesObj[rawRoute],
|
||||
statusCode: Number(routeStatusesObj && routeStatusesObj[rawRoute]) || 200,
|
||||
apiName: matched ? matched.name : "",
|
||||
selectedApiRoute: matched ? matched.route : "",
|
||||
enabled: enabled,
|
||||
@@ -422,6 +437,17 @@
|
||||
});
|
||||
return obj;
|
||||
},
|
||||
toRouteStatusObject: function (routeArray) {
|
||||
var obj = {};
|
||||
(routeArray || []).forEach(function (item) {
|
||||
var route = (item.route || "").trim();
|
||||
if (!route) return;
|
||||
var routeKey = item.enabled === false ? "#" + route : route;
|
||||
var statusCode = Number(item.statusCode) || 200;
|
||||
obj[routeKey] = statusCode;
|
||||
});
|
||||
return obj;
|
||||
},
|
||||
removeRoute: function (index) {
|
||||
var actualIndex =
|
||||
(this.routePagination.currentPage - 1) * this.routePagination.pageSize +
|
||||
@@ -436,6 +462,7 @@
|
||||
originalRawRoute: "",
|
||||
route: "",
|
||||
filePath: "",
|
||||
statusCode: 200,
|
||||
enabled: true,
|
||||
};
|
||||
},
|
||||
@@ -474,6 +501,7 @@
|
||||
originalRawRoute: item.rawRoute || item.route || "",
|
||||
route: item.route || "",
|
||||
filePath: item.filePath || "mock/",
|
||||
statusCode: Number(item.statusCode) || 200,
|
||||
enabled: item.enabled !== false,
|
||||
};
|
||||
this.routeDialog.visible = true;
|
||||
@@ -578,7 +606,10 @@
|
||||
var resp = await fetch("/__config");
|
||||
var data = await resp.json();
|
||||
this.form.config = Object.assign({}, this.form.config, data.config || {});
|
||||
this.form.routes = this.toRouteArray(data.routes || {});
|
||||
this.form.routes = this.toRouteArray(
|
||||
data.routes || {},
|
||||
data.routeStatuses || {},
|
||||
);
|
||||
this.routePagination.currentPage = 1;
|
||||
} catch (err) {
|
||||
this.$message.error("加载配置失败: " + err.message);
|
||||
@@ -588,6 +619,7 @@
|
||||
var payload = {
|
||||
config: this.form.config,
|
||||
routes: this.toRouteObject(this.form.routes),
|
||||
routeStatuses: this.toRouteStatusObject(this.form.routes),
|
||||
};
|
||||
try {
|
||||
var resp = await fetch("/__config", {
|
||||
|
||||
Reference in New Issue
Block a user