1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
| <template> <div id="app"> <el-container> <el-header><h1>接口测试小工具</h1></el-header> <el-main class="main-class"> <div class="main-up-class"> <div class="search-class"> <div class="search-class-up"> <div> <el-select v-model="ipValue" placeholder="IP" style="width: 300px" > <el-option v-for="item in optionsIp" :key="item" :label="item" :value="item" > </el-option> </el-select> </div> <div> <el-select v-model="hostValue" placeholder="端口" style="width: 200px" > <el-option v-for="item in optionsHost " :key="item" :label="item" :value="item" > </el-option> </el-select> </div> <div> <el-select v-model="pathValue" placeholder="请求路径" style="width: 480px" > <el-option v-for="item in optionsPath" :key="item" :label="item" :value="item" > </el-option> </el-select> </div> </div> <div class="search-class-next"> <el-input placeholder="输入完整路径" clearable v-model="urlValue"> <el-button slot="append" @click = "testNet">测试网络</el-button> </el-input> </div> </div> <div class="active-class"> <el-collapse v-model="activeNames" @change="handleChange"> <el-collapse-item title="请求响应报文" name="1"> <div class="context-class"> <el-card v-loading="loading" shadow="never" class="context-card-class" > <div slot="header" class="clearfix"> <span>请求报文</span> <el-button style="float: right; padding: 3px 0px 2px" type="text" @click="getPost" > 请求 </el-button> <el-button style="float: right; padding: 3px " type="text" @click="cleartextareaRequest" > 清空 </el-button> <el-button style="float: right; padding: 3px 0" type="text" @click="RequestTxt" > 获取报文 </el-button> <el-radio-group v-model="radio" style="float: right; padding: 3px 0"> <el-radio :label="1">text/xml</el-radio> <el-radio :label="2">application/json</el-radio> </el-radio-group> </div>
<el-input type="textarea" :autosize="{ minRows: 17, maxRows: 17 }" placeholder="请输入请求" v-model="textareaRequest" show-word-limit autofocus="true" > </el-input> </el-card> <el-card shadow="never" class="context-card-class"> <div slot="header" class="clearfix"> <span>响应报文</span> <el-button style="float: right; padding: 3px 0" type="text" @click="clearTextareaResponse" >清空</el-button > </div> <el-input type="textarea" :autosize="{ minRows: 17, maxRows: 17 }" placeholder="" v-model="textareaResponse" show-word-limit autofocus="true" > </el-input> </el-card> </div> </el-collapse-item> <el-collapse-item title="测试接口历史" name="2"> <div class="list-class"> <template> <el-table :data="sendDate" border style="width: 100%" > <el-table-column fixed prop="nameCose" label="接口编码" width="200"> </el-table-column> <el-table-column prop="url" label="url路径"> </el-table-column> <el-table-column prop="date" label="日期" width="150"> </el-table-column> <el-table-column fixed="right" label="操作" width="150"> <template slot-scope="scope"> <el-button @click="handleClickRequest(scope.row)" type="text" size="small" >请求报文</el-button > <el-button @click="handleClickResponse(scope.row)" type="text" size="small" >响应报文</el-button > </template> </el-table-column> </el-table> </template> </div> </el-collapse-item> <el-collapse-item title="测试接口配置" name="3"> <div class="input-with-select-add"> <el-input placeholder="IP添加" v-model="tepmIp" @keyup.enter.native="addIp" > </el-input> <el-input placeholder="端口添加" v-model="tempHost" @keyup.enter.native="addHost"> </el-input> <el-input placeholder="路径添加" v-model="tepmValurl" @keyup.enter.native="addValurl"> </el-input> </div> </el-collapse-item> <el-collapse-item title="压力测试" name="4"> <div class="input-with-select-add"> <el-input-number label="调用间隔时间(s)" v-model="num" @change="handleChange" :min="1" :max="10"></el-input-number> <el-button @click="testing()" type="primary">{{testmsg}} {{testmsg !="开始测试"?"秒":""}}</el-button> <el-button @click="testingon()" type="primary">结束测试</el-button> </div> </el-collapse-item> </el-collapse> </div> </div> </el-main> </el-container> <el-dialog title="报文" :visible.sync="dialogTableVisible"> <code>{{ msg }}</code> </el-dialog> <el-dialog title="请求报文列表" :visible.sync="dialogTableVisible_req"> <el-tag v-for="item in interData" :key="item.key" style="margin: 5px;width: 250px;" effect="plain" @click="clickInterData(item)"> {{ item.key }} </el-tag> </el-dialog> </div> </template>
<script> import axios from "axios"; import { v4 as uuidv4 } from "uuid";
export default { name: "App", data() { return { radio:1, testmsg:"开始测试", olddate:'', setInterval_:'', num:1, tepmIp:'', tempHost:'', tepmValurl:'', dialogTableVisible_req:false, dialogTableVisible: false, msg: "", nameCose:'', hostValue: "", ipValue: "", pathValue: "", activeNames: ["4"], select: "", urlValue: "", sessionStorage:"", optionsHost: ["30066"], textareaRequest: "", textareaResponse: "", optionsIp: ["10.218.7.201"], sendDate: [], interData:new Array(), optionsPath: [ "/app/baseurl/CrmService?wsdl", "/app/baseurl/UaService?wsdl", "/app/baseurl/AccountSynchro?wsdl", "/app/baseurl/AccountStatusIf?wsdl", "/app/baseurl/BindingSynchro?wsdl", "/app/baseurl/BusinessAccountQuery?wsdl" ], loading: false, }; }, created() { this.sessionStorage = window.sessionStorage; this.sessionStorage.setItem("CAP04003新增产品", '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ua="http://www.mbossuac.com.cn/ua">\n。。。。。。</soapenv:Envelope>'); }, mounted() { let len = this.sessionStorage.length; console.log("接口条数"+len) var gridData_ = new Array(); for(let i = 0; i < len; i++) { let getKey = this.sessionStorage.key(i); var getVal = this.sessionStorage.getItem(getKey); gridData_[i] = { 'key': getKey, 'val': getVal, } } this.interData = gridData_; console.log(gridData_); }, methods: { handleChangetest(){ }, testingon(){ clearInterval(this.setInterval_); this.testmsg ="开始测试"; }, testing(){ this.activeNames=["4"]; this.testmsg = 0; this.setInterval_ = setInterval(_ => {this.getPost();this.testmsg=this.testmsg+this.num},this.num * 1000); }, addValurl(){ if(this.tepmValurl){ this.optionsPath.push(this.tepmValurl); this.tepmValurl =''; this.$notify({ title: "添加成功", }); }else{ this.$notify({ title: "数据为空", type: "warning", }); } }, addHost(){ if(this.tempHost){ this.optionsHost.push(this.tempHost); this.$notify({ title: "添加成功", }); this.tempHost=''; }else{ this.$notify({ title: "数据为空", type: "warning", }); } }, addIp(){ console.log("fsdf") if(this.tepmIp){ this.optionsIp.push(this.tepmIp); this.tepmIp=''; this.$notify({ title: "添加成功", }); }else{ this.$notify({ title: "数据为空", type: "warning", }); } }, testNet(){ window.open(this.urlValue); }, clickInterData(val){ console.log(val); this.textareaRequest = val.val; this.nameCose = val.key; this.dialogTableVisible_req=false; }, RequestTxt(){ this.dialogTableVisible_req=true; }, handleClickRequest(row) { this.msg = row.data; this.dialogTableVisible = true; console.log(row); }, handleClickResponse(row) { this.msg = row.response; this.dialogTableVisible = true; console.log(row); }, clearTextareaResponse() { console.log("清空数据"); this.textareaResponse = ""; }, cleartextareaRequest() { console.log("清空数据"); this.textareaRequest = ""; }, getinit() { axios({ url: "/init", method: "get", }) .then((res) => { this.sendDate = res.data; console.log(this.sendDate); }) .catch((error) => { console.error(error); }); }, getPost() { if (!this.urlValue) { this.$notify({ title: "测试路径为空", type: "warning", }); return; } let path = this.urlValue; console.log("开始调用接口:"+path) this.loading = true; axios({ url: "/test", method: "post", data: { content: this.textareaRequest, url: path, id: uuidv4().toString(), nameCose:this.nameCose, type:this.radio, }, }).then((res) => { console.log(uuidv4()); console.log(res)
this.textareaResponse = res.data; this.loading = false; this.getinit(); this.$notify({ title: this.nameCose +" "+this.getCurrentTime(), type: "success", }); }) .catch((error) => { this.loading = false; console.error(error); this.$notify({ title: "请求异常", type: "error", }); return; }); }, getCurrentTime() { let yy = new Date().getFullYear(); let mm = new Date().getMonth()+1; let dd = new Date().getDate(); let hh = new Date().getHours(); let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes(); let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds(); return yy+'年'+mm+'月'+dd+'日'+hh+':'+mf+':'+ss; }, handleChange(val) { console.log(val); }, }, watch: { hostValue: { handler(newName, oldName) { let m = this; m.urlValue ="http://"+ m.ipValue + ":" + m.hostValue + m.pathValue; immediate: true; }, }, ipValue: { handler(newName, oldName) { let m = this; m.urlValue ="http://"+ m.ipValue + ":" + m.hostValue + m.pathValue; immediate: true; }, }, pathValue: { handler(newName, oldName) { let m = this; m.urlValue ="http://"+ m.ipValue + ":" + m.hostValue + m.pathValue; immediate: true; }, }, }, }; </script>
<style> #app { font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } html, body, #app, .el-container { padding: 0px; margin: 0px; height: 100%; }
.el-select .el-input { width: 100%; } .input-with-select .el-input-group__prepend { background-color: #fff; } .main-up-class { width: 1000px; } .http-w { width: 20px; } .search-class { width: 1000px; height: 90px; } .search-class-up { margin: 10px; display: flex; justify-content: space-between; } .search-class-next { margin: 10px; } .active-class { margin: 10px; } .context-class { display: flex; justify-content: space-between; height: 405px; } .context-card-class { height: 100%; width: 100%; margin: 5px; } .el-card__header { padding: 5px 6px !important; } .el-card__body { padding: 1px !important; } .el-textarea__inner { resize: none !important; } .main-class { display: flex !important; justify-content: center !important; border-radius: 5px;
} pre, code { font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace; }
code { margin: 0 0.15em; padding: 0 0.3em; white-space: pre-wrap; border: 1px solid #eaeaea; background-color: #f8f8f8; border-radius: 3px; display: inline; }
pre { font-size: 1em; line-height: 1em; }
pre code { white-space: pre; overflow: auto; border-radius: 3px; border: 1px solid #ccc; padding: 0.5em 0.7em; display: block !important; }
.markdown-here-wrapper[data-md-url*="wordpress."] code span { font: inherit; }
.markdown-here-wrapper[data-md-url*="wordpress."] pre { background-color: transparent; } .input-with-select-add{ display: flex !important; justify-content: center !important; margin: 10px; } </style>
|