api测试界面,未完待续

This commit is contained in:
q4speed 2020-04-23 15:22:09 +08:00
parent 83c6442b94
commit 97976ea417
5 changed files with 115 additions and 106 deletions

View File

@ -13,7 +13,6 @@
</el-row> </el-row>
<ms-view/> <ms-view/>
<ms-web-socket/>
</el-col> </el-col>
</template> </template>
@ -21,7 +20,6 @@
import MsTopMenus from "./components/common/head/HeaderTopMenus"; import MsTopMenus from "./components/common/head/HeaderTopMenus";
import MsView from "./components/common/router/View"; import MsView from "./components/common/router/View";
import MsUser from "./components/common/head/HeaderUser"; import MsUser from "./components/common/head/HeaderUser";
import MsWebSocket from "./components/common/websocket/WebSocket";
export default { export default {
name: 'app', name: 'app',
@ -33,7 +31,6 @@
beforeCreate() { beforeCreate() {
this.$get("/isLogin").then(response => { this.$get("/isLogin").then(response => {
if (response.data.success) { if (response.data.success) {
window.console.log(response.data);
this.$setLang(response.data.data); this.$setLang(response.data.data);
this.auth = true; this.auth = true;
} else { } else {
@ -43,7 +40,7 @@
window.location.href = "/login" window.location.href = "/login"
}); });
}, },
components: {MsWebSocket, MsUser, MsView, MsTopMenus}, components: {MsUser, MsView, MsTopMenus},
methods: {} methods: {}
} }
</script> </script>

View File

@ -11,7 +11,7 @@
<el-option v-for="project in projects" :key="project.id" :label="project.name" :value="project.id"/> <el-option v-for="project in projects" :key="project.id" :label="project.name" :value="project.id"/>
</el-select> </el-select>
</el-input> </el-input>
<el-button type="primary" plain :disabled="isDisabled" @click="saveTest">保存</el-button> <el-button type="primary" plain :disabled="isDisabled" @click="saveTest">{{$t('commons.save')}}</el-button>
</el-row> </el-row>
</el-header> </el-header>
<ms-api-scenario-config :scenarios="test.scenarioDefinition" ref="config"/> <ms-api-scenario-config :scenarios="test.scenarioDefinition" ref="config"/>
@ -41,17 +41,15 @@
} }
}, },
beforeRouteUpdate(to, from, next) {
if (to.params.type === "edit") {
this.getTest(to.query.id);
} else {
this.test = new Test();
this.$refs.config.reset();
}
next();
},
watch: { watch: {
'$route'(to) {
if (to.params.type === "edit") {
this.getTest(to.query.id);
} else {
this.test = new Test();
this.$refs.config.reset();
}
},
test: { test: {
handler: function () { handler: function () {
this.change = true; this.change = true;
@ -65,7 +63,7 @@
this.result = this.$get("/api/get/" + id, response => { this.result = this.$get("/api/get/" + id, response => {
let item = response.data; let item = response.data;
this.test.reset({ this.test = new Test({
id: item.id, id: item.id,
projectId: item.projectId, projectId: item.projectId,
name: item.name, name: item.name,

View File

@ -3,17 +3,8 @@
<div class="main-content"> <div class="main-content">
<el-card> <el-card>
<template v-slot:header> <template v-slot:header>
<div> <ms-table-header :condition.sync="condition" @search="search" :title="$t('commons.test')"
<el-row type="flex" justify="space-between" align="middle"> @create="create"/>
<span class="title">{{$t('commons.test')}}</span>
<span class="search">
<el-input type="text" size="small" :placeholder="$t('load_test.search_by_name')"
prefix-icon="el-icon-search"
maxlength="60"
v-model="condition" @change="search" clearable/>
</span>
</el-row>
</div>
</template> </template>
<el-table :data="tableData" class="test-content"> <el-table :data="tableData" class="test-content">
<el-table-column <el-table-column
@ -65,13 +56,14 @@
<script> <script>
import MsTablePagination from "../../common/pagination/TablePagination"; import MsTablePagination from "../../common/pagination/TablePagination";
import MsTableHeader from "../../common/components/MsTableHeader";
export default { export default {
components: {MsTablePagination}, components: {MsTableHeader, MsTablePagination},
data() { data() {
return { return {
result: {}, result: {},
condition: "", condition: {name: ""},
projectId: null, projectId: null,
tableData: [], tableData: [],
multipleSelection: [], multipleSelection: [],
@ -83,10 +75,11 @@
} }
}, },
beforeRouteUpdate(to, from, next) { watch: {
this.projectId = to.params.projectId; '$route'(to) {
this.search(); this.projectId = to.params.projectId;
next(); this.initTableData();
}
}, },
created: function () { created: function () {
@ -95,9 +88,12 @@
}, },
methods: { methods: {
create() {
this.$router.push('/api/test/create');
},
search() { search() {
let param = { let param = {
name: this.condition, name: this.condition.name,
}; };
if (this.projectId !== 'all') { if (this.projectId !== 'all') {
@ -129,7 +125,7 @@
message: this.$t('commons.delete_success'), message: this.$t('commons.delete_success'),
type: 'success' type: 'success'
}); });
this.initTableData(); this.search();
}); });
} }
} }

View File

@ -1,27 +1,5 @@
import {generateId} from "element-ui/src/utils/util"; import {generateId} from "element-ui/src/utils/util";
const assign = function (obj, options) {
if (options) {
for (let name in options) {
if (options.hasOwnProperty(name)) {
if (!(obj[name] instanceof Array)) {
obj[name] = options[name];
}
}
}
}
}
const assigns = function (target, source, type) {
if (target instanceof Array && source instanceof Array) {
if (source && source.length > 0) {
source.forEach((options) => {
target.push(new type(options));
})
}
}
}
export const BODY_TYPE = { export const BODY_TYPE = {
KV: "KV", KV: "KV",
TEXT: "TEXT" TEXT: "TEXT"
@ -33,54 +11,80 @@ export const ASSERTION_TYPE = {
RESPONSE_TIME: "RESPONSE_TIME" RESPONSE_TIME: "RESPONSE_TIME"
} }
export class Test { class BaseConfig {
constructor(options) {
this.reset(options); set(options) {
options = this.initOptions(options)
for (let name in options) {
if (options.hasOwnProperty(name)) {
if (!(this[name] instanceof Array)) {
this[name] = options[name];
}
}
}
} }
reset(options) { sets(types, options) {
options = this.getDefaultOptions(options); options = this.initOptions(options)
if (types) {
for (let name in types) {
if (types.hasOwnProperty(name) && options.hasOwnProperty(name)) {
options[name].forEach((o) => {
this[name].push(new types[name](o));
})
}
}
}
}
initOptions(options) {
return options || {};
}
}
export class Test extends BaseConfig {
constructor(options) {
super();
this.id = null; this.id = null;
this.name = null; this.name = null;
this.projectId = null; this.projectId = null;
this.scenarioDefinition = []; this.scenarioDefinition = [];
assign(this, options); this.set(options);
assigns(this.scenarioDefinition, options.scenarioDefinition, Scenario); this.sets({scenarioDefinition: Scenario}, options);
} }
getDefaultOptions(options) { initOptions(options) {
options = options || {}; options = options || {};
options.scenarioDefinition = options.scenarioDefinition || [new Scenario()]; options.scenarioDefinition = options.scenarioDefinition || [new Scenario()];
return options; return options;
} }
} }
export class Scenario { export class Scenario extends BaseConfig {
constructor(options) { constructor(options) {
options = this.getDefaultOptions(options); super();
this.name = null; this.name = null;
this.url = null; this.url = null;
this.variables = []; this.variables = [];
this.headers = []; this.headers = [];
this.requests = []; this.requests = [];
assign(this, options); this.set(options);
assigns(this.variables, options.variables, KeyValue); this.sets({variables: KeyValue, headers: KeyValue, requests: Request}, options);
assigns(this.headers, options.headers, KeyValue);
assigns(this.requests, options.requests, Request);
} }
getDefaultOptions(options) { initOptions(options) {
options = options || {}; options = options || {};
options.requests = options.requests || [new Request()]; options.requests = options.requests || [new Request()];
return options; return options;
} }
} }
export class Request { export class Request extends BaseConfig {
constructor(options) { constructor(options) {
options = this.getDefaultOptions(options); super();
this.randomId = generateId(); this.randomId = generateId();
this.name = null; this.name = null;
this.url = null; this.url = null;
@ -91,13 +95,12 @@ export class Request {
this.assertions = null; this.assertions = null;
this.extract = []; this.extract = [];
assign(this, options); this.set(options);
assigns(this.parameters, options.parameters, KeyValue); this.sets({parameters: KeyValue, headers: KeyValue}, options);
assigns(this.headers, options.headers, KeyValue);
// TODO assigns extract // TODO assigns extract
} }
getDefaultOptions(options) { initOptions(options) {
options = options || {}; options = options || {};
options.method = "GET"; options.method = "GET";
options.body = new Body(options.body); options.body = new Body(options.body);
@ -106,15 +109,15 @@ export class Request {
} }
} }
export class Body { export class Body extends BaseConfig {
constructor(options) { constructor(options) {
options = options || {}; super();
this.type = null; this.type = null;
this.text = null; this.text = null;
this.kvs = []; this.kvs = [];
assign(this, options); this.set(options);
assigns(this.kvs, options.kvs, KeyValue); this.sets({kvs: KeyValue}, options);
} }
isKV() { isKV() {
@ -122,72 +125,69 @@ export class Body {
} }
} }
export class KeyValue { export class KeyValue extends BaseConfig {
constructor(options) { constructor(options) {
options = options || {}; super();
this.key = null; this.key = null;
this.value = null; this.value = null;
assign(this, options); this.set(options);
} }
} }
export class Assertions { export class Assertions extends BaseConfig {
constructor(options) { constructor(options) {
options = this.getDefaultOptions(options); super();
this.text = []; this.text = [];
this.regex = []; this.regex = [];
this.responseTime = null; this.responseTime = null;
assign(this, options); this.set(options);
assigns(this.text, options.text, KeyValue); this.sets({text: KeyValue, regex: KeyValue}, options);
assigns(this.regex, options.regex, KeyValue);
} }
getDefaultOptions(options) { initOptions(options) {
options = options || {}; options = options || {};
options.responseTime = new ResponseTime(options.responseTime); options.responseTime = new ResponseTime(options.responseTime);
return options; return options;
} }
} }
class AssertionType { class AssertionType extends BaseConfig {
constructor(type) { constructor(type) {
super();
this.type = type; this.type = type;
} }
} }
export class Text extends AssertionType { export class Text extends AssertionType {
constructor(options) { constructor(options) {
options = options || {};
super(ASSERTION_TYPE.TEXT); super(ASSERTION_TYPE.TEXT);
this.subject = null; this.subject = null;
this.condition = null; this.condition = null;
this.value = null; this.value = null;
assign(this, options); this.set(options);
} }
} }
export class Regex extends AssertionType { export class Regex extends AssertionType {
constructor(options) { constructor(options) {
options = options || {};
super(ASSERTION_TYPE.REGEX); super(ASSERTION_TYPE.REGEX);
this.subject = null; this.subject = null;
this.expression = null; this.expression = null;
this.description = null; this.description = null;
assign(this, options); this.set(options);
} }
} }
export class ResponseTime extends AssertionType { export class ResponseTime extends AssertionType {
constructor(options) { constructor(options) {
options = options || {};
super(ASSERTION_TYPE.RESPONSE_TIME); super(ASSERTION_TYPE.RESPONSE_TIME);
this.responseInTime = null; this.responseInTime = null;
assign(this, options); this.set(options);
} }
} }

View File

@ -1,11 +1,11 @@
<template> <template>
<div> <div v-loading="result.loading">
<div class="recent-text"> <div class="recent-text">
<i class="el-icon-time"/> <i class="el-icon-time"/>
<span>{{options.title}}</span> <span>{{options.title}}</span>
<i class="el-icon-refresh" @click="recent"/>
</div> </div>
<el-menu-item :key="i.id" v-for="i in items" <el-menu-item :key="i.id" v-for="i in items" :index="getIndex(i)" :route="getRouter(i)">
:index="getIndex(i)" :route="getRouter(i)">
<span class="title">{{ i.name }}</span> <span class="title">{{ i.name }}</span>
</el-menu-item> </el-menu-item>
</div> </div>
@ -21,14 +21,11 @@
options: Object options: Object
}, },
mounted() { mounted() {
if (hasRoles(ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) { this.recent();
this.$get(this.options.url, (response) => {
this.items = response.data;
});
}
}, },
data() { data() {
return { return {
result: {},
items: [] items: []
} }
}, },
@ -45,6 +42,16 @@
} }
} }
} }
},
methods: {
recent: function () {
if (hasRoles(ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
this.result = this.$get(this.options.url, (response) => {
this.items = response.data;
});
}
}
} }
} }
</script> </script>
@ -60,6 +67,17 @@
.recent-text span { .recent-text span {
padding-left: 6px; padding-left: 6px;
line-height: 36px;
}
.recent-text .el-icon-refresh {
cursor: pointer;
float: right;
line-height: 36px;
}
.recent-text .el-icon-refresh:hover {
color: #BBBBBB;
} }
.title { .title {