fix(系统设置): 环境相关问题修复

This commit is contained in:
fit2-zhao 2021-04-23 15:38:41 +08:00 committed by fit2-zhao
parent 6c73acd65f
commit 70bc7ef38f
2 changed files with 265 additions and 175 deletions

View File

@ -275,6 +275,10 @@
this.httpConfig.conditions.splice(index, 1);
},
copy(row) {
if (row.type === "NONE") {
this.$warning("启用条件为 '无' 的域名不支持复制!");
return;
}
const index = this.httpConfig.conditions.findIndex((d) => d.id === row.id);
let obj = {id: getUUID(), type: row.type, socket: row.socket, details: row.details, protocol: row.protocol, headers: JSON.parse(JSON.stringify(this.condition.headers)), domain: row.domain, time: new Date().getTime()};
if (index != -1) {

View File

@ -7,14 +7,14 @@
:condition.sync="condition" :is-tester-permission="isTesterPermission" @search="search" @create="createEnv">
<template v-slot:button>
<ms-table-button :is-tester-permission="isTesterPermission" icon="el-icon-box"
:content="$t('commons.import')" @click="importJSON"/>
:content="$t('commons.import')" @click="importJSON"/>
<ms-table-button :is-tester-permission="isTesterPermission" icon="el-icon-box"
:content="$t('commons.export')" @click="exportJSON"/>
</template>
</ms-table-header>
</template>
<!-- 环境列表内容 -->
<!-- 实现搜索,根据搜索内容变换显示的环境列表 -->
<!-- 实现搜索,根据搜索内容变换显示的环境列表 -->
<el-table border :data="environments.filter(env => !searchText || env.name.toLowerCase().includes(searchText.toLowerCase()))"
@selection-change="handleSelectionChange" max-height="515" class="adjust-table" style="width: 100%" ref="table">
<el-table-column type="selection"></el-table-column>
@ -27,7 +27,8 @@
</el-table-column>
<el-table-column :label="$t('api_test.environment.socket')" show-overflow-tooltip>
<template v-slot="scope">
<span>{{ parseDomainName(scope.row) }}</span>
<span v-if="parseDomainName(scope.row)!='SHOW_INFO'">{{ parseDomainName(scope.row) }}</span>
<el-button size="mini" icon="el-icon-s-data" @click="showInfo(scope.row)" v-else>查看域名详情</el-button>
</template>
</el-table-column>
<el-table-column :label="$t('commons.operating')">
@ -52,207 +53,288 @@
<div>
{{$t('project.select')}}
</div>
<el-select v-model="currentProjectId" filterable clearable >
<el-select v-model="currentProjectId" filterable clearable>
<el-option v-for="item in projectList" :key="item.id" :label="item.name" :value="item.id"></el-option>
</el-select>
</div>
<environment-edit :environment="currentEnvironment" ref="environmentEdit" @close="close"
@refreshAfterSave="refresh">
@refreshAfterSave="refresh">
</environment-edit>
</el-dialog>
<environment-import :project-list="projectList" @refresh="refresh" ref="envImport"></environment-import>
<el-dialog title="域名列表" :visible.sync="domainVisible">
<el-table :data="conditions">
<el-table-column prop="socket" :label="$t('load_test.domain')" show-overflow-tooltip width="180">
<template v-slot:default="{row}">
{{getUrl(row)}}
</template>
</el-table-column>
<el-table-column prop="type" :label="$t('api_test.environment.condition_enable')" show-overflow-tooltip min-width="100px">
<template v-slot:default="{row}">
{{getName(row)}}
</template>
</el-table-column>
<el-table-column prop="details" show-overflow-tooltip min-width="120px" :label="$t('api_test.value')">
<template v-slot:default="{row}">
{{getDetails(row)}}
</template>
</el-table-column>
<el-table-column prop="createTime" show-overflow-tooltip min-width="120px" :label="$t('commons.create_time')">
<template v-slot:default="{row}">
<span>{{ row.time | timestampFormatDate }}</span>
</template>
</el-table-column>
</el-table>
<span slot="footer" class="dialog-footer">
<el-button @click="domainVisible = false" size="mini">{{$t('commons.cancel')}}</el-button>
<el-button type="primary" @click="domainVisible = false" size="mini">{{$t('commons.confirm')}}</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import MsTableHeader from "@/business/components/common/components/MsTableHeader";
import MsTableButton from "@/business/components/common/components/MsTableButton";
import MsTableOperator from "@/business/components/common/components/MsTableOperator";
import MsTableOperatorButton from "@/business/components/common/components/MsTableOperatorButton";
import MsTablePagination from "@/business/components/common/pagination/TablePagination";
import ApiEnvironmentConfig from "@/business/components/api/test/components/ApiEnvironmentConfig";
import {Environment, parseEnvironment} from "@/business/components/api/test/model/EnvironmentModel";
import EnvironmentEdit from "@/business/components/api/test/components/environment/EnvironmentEdit";
import MsAsideItem from "@/business/components/common/components/MsAsideItem";
import MsAsideContainer from "@/business/components/common/components/MsAsideContainer";
import ProjectSwitch from "@/business/components/common/head/ProjectSwitch";
import SearchList from "@/business/components/common/head/SearchList";
import {checkoutTestManagerOrTestUser, downloadFile} from "@/common/js/utils";
import EnvironmentImport from "@/business/components/settings/project/EnvironmentImport";
export default {
name: "EnvironmentList",
components: {
EnvironmentImport,
SearchList,
ProjectSwitch,
MsAsideContainer,
MsAsideItem,
EnvironmentEdit,
ApiEnvironmentConfig,
MsTablePagination, MsTableOperatorButton, MsTableOperator, MsTableButton, MsTableHeader},
data() {
return {
btnTips: this.$t('api_test.environment.create'),
projectList: [],
condition: {envName: ''}, //
environments: [],
currentEnvironment: new Environment(),
result: {},
dialogVisible: false,
idNameMap: new Map(),
dialogTitle: '',
currentProjectId: '', //id
selectRows: [],
isTesterPermission: false,
import MsTableHeader from "@/business/components/common/components/MsTableHeader";
import MsTableButton from "@/business/components/common/components/MsTableButton";
import MsTableOperator from "@/business/components/common/components/MsTableOperator";
import MsTableOperatorButton from "@/business/components/common/components/MsTableOperatorButton";
import MsTablePagination from "@/business/components/common/pagination/TablePagination";
import ApiEnvironmentConfig from "@/business/components/api/test/components/ApiEnvironmentConfig";
import {Environment, parseEnvironment} from "@/business/components/api/test/model/EnvironmentModel";
import EnvironmentEdit from "@/business/components/api/test/components/environment/EnvironmentEdit";
import MsAsideItem from "@/business/components/common/components/MsAsideItem";
import MsAsideContainer from "@/business/components/common/components/MsAsideContainer";
import ProjectSwitch from "@/business/components/common/head/ProjectSwitch";
import SearchList from "@/business/components/common/head/SearchList";
import {checkoutTestManagerOrTestUser, downloadFile} from "@/common/js/utils";
import EnvironmentImport from "@/business/components/settings/project/EnvironmentImport";
}
},
computed: {
searchText() { //
return this.condition.name;
export default {
name: "EnvironmentList",
components: {
EnvironmentImport,
SearchList,
ProjectSwitch,
MsAsideContainer,
MsAsideItem,
EnvironmentEdit,
ApiEnvironmentConfig,
MsTablePagination, MsTableOperatorButton, MsTableOperator, MsTableButton, MsTableHeader
},
/*
搜索后对应的总条目搜索内容为空的话就是全部记录条数搜索内容不为空的话就是匹配的记录条数
*/
total() {
return this.environments
.filter(env => !this.searchText || env.name.toLowerCase().includes(this.searchText.toLowerCase())).length;
},
},
watch: {
//projectId
currentProjectId() {
// el-select''''projectId使
if (this.currentProjectId === '') {
this.currentEnvironment.projectId = null;
} else {
this.currentEnvironment.projectId = this.currentProjectId;
data() {
return {
btnTips: this.$t('api_test.environment.create'),
projectList: [],
condition: {envName: ''}, //
environments: [],
currentEnvironment: new Environment(),
result: {},
dialogVisible: false,
idNameMap: new Map(),
dialogTitle: '',
currentProjectId: '', //id
selectRows: [],
isTesterPermission: false,
domainVisible: false,
conditions: [],
}
},
computed: {
searchText() { //
return this.condition.name;
},
/*
搜索后对应的总条目搜索内容为空的话就是全部记录条数搜索内容不为空的话就是匹配的记录条数
*/
total() {
return this.environments
.filter(env => !this.searchText || env.name.toLowerCase().includes(this.searchText.toLowerCase())).length;
},
},
watch: {
//projectId
currentProjectId() {
// el-select''''projectId使
if (this.currentProjectId === '') {
this.currentEnvironment.projectId = null;
} else {
this.currentEnvironment.projectId = this.currentProjectId;
}
}
}
},
},
methods: {
list() {
this.environments = [];
let url = "/project/listAll";
this.result = this.$get(url, (response) => { //
this.projectList = response.data; //,
this.projectList.forEach(project => {
this.idNameMap.set(project.id, project.name);
});
//
this.projectList.map((project) => {
this.$get('/api/environment/list/' + project.id, response => {
let envData = response.data;
envData.forEach(env => {
this.environments.push(env);
methods: {
showInfo(row) {
const config = JSON.parse(row.config);
this.conditions = config.httpConfig.conditions;
this.domainVisible = true;
},
getName(row) {
switch (row.type) {
case "NONE":
return this.$t("api_test.definition.document.data_set.none");
case "MODULE":
return this.$t("test_track.module.module");
case "PATH":
return this.$t("api_test.definition.api_path");
}
},
getUrl(row) {
return row.protocol + "://" + row.socket;
},
getDetails(row) {
if (row && row.type === "MODULE") {
if (row.details && row.details instanceof Array) {
let value = "";
row.details.forEach((item) => {
value += item.name + ",";
});
if (value.endsWith(",")) {
value = value.substr(0, value.length - 1);
}
return value;
}
} else if (row && row.type === "PATH" && row.details.length > 0 && row.details[0].name) {
return row.details[0].value === "equals" ? this.$t("commons.adv_search.operators.equals") + row.details[0].name : this.$t("api_test.request.assertions.contains") + row.details[0].name;
} else {
return "";
}
},
list() {
this.environments = [];
let url = "/project/listAll";
this.result = this.$get(url, (response) => { //
this.projectList = response.data; //,
this.projectList.forEach(project => {
this.idNameMap.set(project.id, project.name);
});
//
this.projectList.map((project) => {
this.$get('/api/environment/list/' + project.id, response => {
let envData = response.data;
envData.forEach(env => {
this.environments.push(env);
})
})
})
})
})
},
createEnv() {
this.currentProjectId = '';
this.dialogTitle = this.$t('api_test.environment.create');
this.dialogVisible = true;
this.currentEnvironment = new Environment();
},
search(searchText) {
},
editEnv(environment) {
this.dialogTitle = this.$t('api_test.environment.config_environment');
this.currentProjectId = environment.projectId;
const temEnv = {};
Object.assign(temEnv, environment);
parseEnvironment(temEnv); //parseEnvironment
this.currentEnvironment = temEnv;
this.dialogVisible = true;
},
},
createEnv() {
this.currentProjectId = '';
this.dialogTitle = this.$t('api_test.environment.create');
this.dialogVisible = true;
this.currentEnvironment = new Environment();
},
search(searchText) {
},
editEnv(environment) {
this.dialogTitle = this.$t('api_test.environment.config_environment');
this.currentProjectId = environment.projectId;
const temEnv = {};
Object.assign(temEnv, environment);
parseEnvironment(temEnv); //parseEnvironment
this.currentEnvironment = temEnv;
this.dialogVisible = true;
},
copyEnv(environment) {
this.currentProjectId = environment.projectId; //
this.dialogTitle = this.$t('api_test.environment.copy_environment');
const temEnv = {};
Object.assign(temEnv, environment);
parseEnvironment(temEnv); //parseEnvironment
let newEnvironment = new Environment(temEnv);
newEnvironment.id = null;
newEnvironment.name = this.getNoRepeatName(newEnvironment.name);
this.dialogVisible = true;
this.currentEnvironment = newEnvironment;
copyEnv(environment) {
this.currentProjectId = environment.projectId; //
this.dialogTitle = this.$t('api_test.environment.copy_environment');
const temEnv = {};
Object.assign(temEnv, environment);
parseEnvironment(temEnv); //parseEnvironment
let newEnvironment = new Environment(temEnv);
newEnvironment.id = null;
newEnvironment.name = this.getNoRepeatName(newEnvironment.name);
this.dialogVisible = true;
this.currentEnvironment = newEnvironment;
},
deleteEnv(environment) {
if (environment.id) {
this.result = this.$get('/api/environment/delete/' + environment.id, () => {
this.$success(this.$t('commons.delete_success'));
this.list();
});
}
},
getNoRepeatName(name) {
for (let i in this.environments) {
if (this.environments[i].name === name) {
return this.getNoRepeatName(name + ' copy');
},
deleteEnv(environment) {
if (environment.id) {
this.result = this.$get('/api/environment/delete/' + environment.id, () => {
this.$success(this.$t('commons.delete_success'));
this.list();
});
}
},
getNoRepeatName(name) {
for (let i in this.environments) {
if (this.environments[i].name === name) {
return this.getNoRepeatName(name + ' copy');
}
}
return name;
},
//
close() {
this.dialogVisible = false;
this.$refs.environmentEdit.clearValidate();
},
refresh() {
this.list();
},
handleSelectionChange(value) {
this.selectRows = value;
},
importJSON() {
this.$refs.envImport.open();
},
exportJSON() {
if (this.selectRows.length < 1) {
this.$warning('请选择想要导出的环境');
return;
}
//idprojectId
const envs = JSON.parse(JSON.stringify(this.selectRows));
envs.map(env => { //idprojectId
delete env.id;
delete env.projectId;
})
downloadFile('MS_' + envs.length + '_Environments.json', JSON.stringify(envs));
},
parseDomainName(environment) { //
if (environment.config) {
const config = JSON.parse(environment.config);
if (config.httpConfig && !config.httpConfig.conditions) {
if (config.httpConfig.protocol && config.httpConfig.domain) {
return config.httpConfig.protocol + "://" + config.httpConfig.domain;
}
return "";
} else {
if (config.httpConfig.conditions.length === 1) {
let obj = config.httpConfig.conditions[0];
if (obj.protocol && obj.domain) {
return obj.protocol + "://" + obj.domain;
}
} else if (config.httpConfig.conditions.length > 1) {
return "SHOW_INFO";
}
else {
return "";
}
}
} else { //config,protocoldomain
return environment.protocol + '://' + environment.domain;
}
}
return name;
},
created() {
this.isTesterPermission = checkoutTestManagerOrTestUser();
},
//
close() {
this.dialogVisible = false;
this.$refs.environmentEdit.clearValidate();
},
refresh() {
activated() {
this.list();
},
handleSelectionChange(value) {
this.selectRows = value;
},
importJSON() {
this.$refs.envImport.open();
},
exportJSON() {
if (this.selectRows.length < 1) {
this.$warning('请选择想要导出的环境');
return ;
}
//idprojectId
const envs = JSON.parse(JSON.stringify(this.selectRows));
envs.map(env => { //idprojectId
delete env.id;
delete env.projectId;
})
downloadFile('MS_'+ envs.length + '_Environments.json' , JSON.stringify(envs));
},
parseDomainName(environment){ //
if (environment.config) {
const config = JSON.parse(environment.config);
if (!config.httpConfig.protocol) {
return '';
} else {
return config.httpConfig.protocol + "://" + config.httpConfig.domain;
}
} else { //config,protocoldomain
return environment.protocol + '://' + environment.domain;
}
}
},
created() {
this.isTesterPermission = checkoutTestManagerOrTestUser();
},
activated() {
this.list();
},
}
}
</script>
<style scoped>
@ -263,18 +345,22 @@ export default {
box-sizing: border-box;
border: solid 1px #e6e6e6;
}
.item-selected {
background: #ECF5FF;
border-left: solid #409EFF 5px;
}
.item-selected .item-right {
visibility: visible;
}
.environment-edit {
margin-left: 0;
width: 100%;
border: 0;
}
.project-item {
padding-left: 20px;
padding-right: 20px;