refactor: 环境域名可以设置为DbeaseUrl

This commit is contained in:
chenjianxing 2020-08-03 17:06:45 +08:00
parent 7cbb202309
commit ff76a7e69d
6 changed files with 39 additions and 46 deletions

View File

@ -2,7 +2,7 @@
<el-dialog :title="$t('api_test.environment.environment_config')" :visible.sync="visible" class="environment-dialog"
@close="close" append-to-body ref="environmentConfig">
<el-container v-loading="result.loading">
<ms-aside-item :title="$t('api_test.environment.environment_list')" :data="environments" :item-operators="environmentOperators" :add-fuc="addEnvironment"
<ms-aside-item :enable-aside-hidden="false" :title="$t('api_test.environment.environment_list')" :data="environments" :item-operators="environmentOperators" :add-fuc="addEnvironment"
:delete-fuc="deleteEnvironment" @itemSelected="environmentSelected" ref="environmentItems"/>
<environment-edit :environment="currentEnvironment" ref="environmentEdit" @close="close"/>
</el-container>

View File

@ -42,6 +42,7 @@
import MsApiKeyValue from "../ApiKeyValue";
import MsDialogFooter from "../../../../common/components/MsDialogFooter";
import {REQUEST_HEADERS} from "../../../../../../common/js/constants";
import {KeyValue} from "../../model/ScenarioModel";
export default {
name: "EnvironmentEdit",
@ -110,39 +111,30 @@
},
validateSocket(socket) {
if (!socket) return;
let socketInfo = socket.split(":");
if (socketInfo.length > 2) {
return false;
let urlStr = this.environment.protocol + '://' + socket;
let url = {};
try {
url = new URL(urlStr);
} catch (e) {
return false
}
let host = socketInfo[0];
let port = socketInfo[1];
if (!this.validateHost(host) || !(port == undefined || this.validatePort(port))) {
return false;
this.environment.port = url.port;
this.environment.domain = decodeURIComponent(url.hostname);
if (url.port) {
this.environment.socket = this.environment.domain + ':' + url.port + url.pathname;
} else {
this.environment.socket = this.environment.domain + url.pathname;
}
this.environment.domain = host;
this.environment.port = port;
return true;
},
validateHost(host) {
let hostReg = /^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/;
if (hostReg.test(host) || host === 'localhost') {
return true;
}
return false;
},
validatePort(port) {
let portReg = /^[1-9]\d*$/;
if (portReg.test(port) && 1 <= 1*port && 1*port <= 65535){
return true
}
return false;
},
cancel() {
this.$emit('close');
},
clearValidate() {
this.$refs["from"].clearValidate();
}
},
},
}
</script>

View File

@ -100,7 +100,7 @@
{validator: validateURL, trigger: 'blur'}
],
path: [
{max: 500, required: true, message: this.$t('commons.input_limit', [1, 500]), trigger: 'blur'},
{max: 500, message: this.$t('commons.input_limit', [0, 500]), trigger: 'blur'},
]
},
headerSuggestions: REQUEST_HEADERS
@ -117,13 +117,12 @@
},
pathChange() {
if (!this.request.path) return;
if (!this.request.path.startsWith('/')) {
this.request.path = '/' + this.request.path;
}
let url = this.getURL(this.displayUrl);
this
.request.path = decodeURIComponent(url.pathname);
this.request.urlWirhEnv = decodeURIComponent(url.origin + url.pathname);
let urlStr = url.origin + url.pathname;
let envUrl = this.request.environment.protocol + '://' + this.request.environment.socket;
let test = urlStr.substring(envUrl.length, urlStr.length);
this.request.path = decodeURIComponent(test);
},
getURL(urlStr) {
try {

View File

@ -285,11 +285,6 @@ export class HttpRequest extends Request {
isValid: false,
info: 'api_test.request.please_configure_environment_in_scenario'
}
} else if (!this.path) {
return {
isValid: false,
info: 'api_test.request.input_path'
}
}
} else {
if (!this.url) {
@ -668,12 +663,11 @@ class JMXHttpRequest {
this.protocol = url.protocol.split(":")[0];
this.pathname = this.getPostQueryParameters(request, decodeURIComponent(url.pathname));
} else {
if (environment) {
this.port = environment.port;
this.protocol = environment.protocol;
this.domain = environment.domain;
}
this.path = this.getPostQueryParameters(request, decodeURIComponent(request.path));
this.port = environment.port;
this.protocol = environment.protocol;
this.domain = environment.domain;
let url = new URL(environment.protocol + "://" + environment.socket);
this.path = this.getPostQueryParameters(request, decodeURIComponent(url.pathname));
}
}
}

View File

@ -1,7 +1,7 @@
<template>
<el-aside :width="width" class="ms-aside-container"
:style="{'margin-left': asideHidden ? '0' : '-' + width}">
<div class="hiddenBottom" @click="asideHidden = !asideHidden" :style="{'left': width}">
<div v-if="enableAsideHidden" class="hiddenBottom" @click="asideHidden = !asideHidden" :style="{'left': width}">
<i v-if="asideHidden" class="el-icon-arrow-left"/>
<i v-if="!asideHidden" class="el-icon-arrow-right"/>
</div>
@ -16,7 +16,11 @@
width: {
type: String,
default: '300px'
}
},
enableAsideHidden: {
type: Boolean,
default: true
},
},
data() {
return {

View File

@ -1,5 +1,5 @@
<template>
<ms-aside-container :width="width + 'px'">
<ms-aside-container :enable-aside-hidden="false" :width="width + 'px'">
<div class="title-bar" :style="{'height': titleBarHeight + 'px'}">
<slot name="title">
<span :style="{'line-height': titleBarHeight - 10 + 'px'}" class="title-left">
@ -58,6 +58,10 @@
];
}
},
enableAsideHidden: {
type: Boolean,
default: true
},
},
methods: {
itemSelected(index, item) {