refactor: 删除无用组件

This commit is contained in:
shiziyuan9527 2021-12-07 16:12:46 +08:00 committed by shiziyuan9527
parent 8e0e0234b0
commit 440b264a66
3 changed files with 0 additions and 448 deletions

View File

@ -57,7 +57,6 @@ export default {
data() {
return {
data: [],
// result: {},
projects: [],
environments: [],
permissionProjectIds:[],
@ -159,122 +158,6 @@ export default {
this.$emit('setProjectEnvMap', map);
this.$emit('close');
},
getApiInfo(request) {
if (request.id && request.referenced === 'REF') {
let requestResult = request.requestResult;
let url = request.refType && request.refType === 'CASE' ? "/api/testcase/get/" : "/api/definition/get/";
let enable = request.enable;
this.$get(url + request.id, response => {
if (response.data) {
Object.assign(request, JSON.parse(response.data.request));
request.name = response.data.name;
request.enable = enable;
if (response.data.path && response.data.path != null) {
request.path = response.data.path;
request.url = response.data.url;
this.setUrl(request.path);
}
if (response.data.method && response.data.method != null) {
request.method = response.data.method;
}
request.requestResult = requestResult;
request.id = response.data.id;
request.disabled = true;
request.root = true;
if (!request.projectId) {
request.projectId = response.data.projectId;
}
this.reload();
this.sort();
} else {
request.referenced = "Deleted";
}
})
}
},
getScenario(scenario) {
this.result = this.$get("/api/automation/getApiScenario/" + scenario.id, response => {
if (response.data) {
scenario.loaded = true;
let obj = {};
if (response.data.scenarioDefinition) {
obj = JSON.parse(response.data.scenarioDefinition);
scenario.hashTree = obj.hashTree;
}
//scenario.disabled = true;
scenario.name = response.data.name;
if (!scenario.projectId) {
scenario.projectId = response.data.projectId;
}
scenario.headers = obj.headers;
scenario.variables = obj.variables;
scenario.environmentMap = obj.environmentMap;
this.$emit('refReload');
} else {
scenario.referenced = "Deleted";
}
})
},
recursiveSorting(arr) {
for (let i in arr) {
if (arr[i].referenced === 'REF') {
//
if (arr[i].type === "HTTPSamplerProxy") {
//
this.getApiInfo(arr[i]);
//
if (!arr[i].url || (!arr[i].url.startsWith("http://") && !arr[i].url.startsWith("https://"))) {
this.isFullUrl = false;
}
} else if (arr[i].type === "scenario") {
this.getScenario(arr[i]);
}
} else {
if (arr[i].type === "HTTPSamplerProxy") {
//
if (arr[i].enable) {
if (!arr[i].url || (!arr[i].url.startsWith("http://") && !arr[i].url.startsWith("https://"))) {
this.isFullUrl = false;
}
}
}
}
if (arr[i].hashTree != undefined && arr[i].hashTree.length > 0) {
this.recursiveSorting(arr[i].hashTree);
}
}
},
checkFullUrl(scenarioDefinition) {
for (let i in scenarioDefinition) {
// ID
let request = scenarioDefinition[i];
if (request.referenced === 'REF') {
if (request.type === "HTTPSamplerProxy") {
this.getApiInfo(request);
//
if (!request.url || (!request.url.startsWith("http://") && !request.url.startsWith("https://"))) {
this.isFullUrl = false;
}
} else if (request.type === "scenario") {
this.getScenario(request);
}
} else {
if (request.type === "HTTPSamplerProxy") {
//
if (request.enable) {
if (!request.url || (!request.url.startsWith("http://") && !request.url.startsWith("https://"))) {
this.isFullUrl = false;
}
}
}
}
if (scenarioDefinition[i].hashTree != undefined && scenarioDefinition[i].hashTree.length > 0) {
this.recursiveSorting(scenarioDefinition[i].hashTree);
}
}
},
checkEnv(data) {
let sign = true;
this.isFullUrl = true;

View File

@ -1,120 +0,0 @@
<template>
<el-popover
v-model="visible"
placement="bottom-start"
width="400"
:disabled="isReadOnly"
@show="showPopover"
trigger="click">
<el-radio-group v-model="radio" style="margin-left: 20px;" @change="radioChange">
<el-radio :label="ENV_TYPE.JSON">环境列表</el-radio>
<el-radio :label="ENV_TYPE.GROUP">环境组</el-radio>
</el-radio-group>
<env-select :project-ids="projectIds"
:result="result"
:project-env-map="projectEnvMap"
:project-list="projectList"
:show-config-button-with-out-permission="showConfigButtonWithOutPermission"
@close="visible = false"
ref="envSelect"
v-show="!radio || radio === ENV_TYPE.JSON"
@setProjectEnvMap="setProjectEnvMap"/>
<!-- todo 如果工作空间下的环境组都不包含当前项目则不显示 -->
<env-group ref="envGroup" v-show="radio === ENV_TYPE.GROUP" @close="visible = false"
@setEnvGroup="setEnvGroup" :group-id="groupId"></env-group>
<el-button type="primary" slot="reference" size="mini" style="margin-top: 2px;">
{{ $t('api_test.definition.request.run_env') }}
<i class="el-icon-caret-bottom el-icon--right"></i>
</el-button>
</el-popover>
</template>
<script>
import EnvSelect from "@/business/components/track/plan/common/EnvSelect";
import {ENV_TYPE} from "@/common/js/constants";
import EnvGroup from "@/business/components/api/automation/scenario/EnvGroup";
export default {
name: "EnvPopover",
components: {EnvGroup, EnvSelect},
props: {
projectIds: Set,
projectList: Array,
showConfigButtonWithOutPermission: {
type: Boolean,
default() {
return true;
}
},
isReadOnly: {
type: Boolean,
default() {
return false;
}
},
result: {
type: Object,
default() {
return {loading: false}
}
},
projectEnvMap: {
type: Object,
default() {
return {};
}
},
groupId: {
type: String,
default() {
return "";
}
},
environmentType: String
},
data() {
return {
visible: false,
radio: this.environmentType,
}
},
watch: {
environmentType(val) {
this.radio = val;
}
},
computed: {
ENV_TYPE() {
return ENV_TYPE;
}
},
methods: {
showPopover() {
this.$emit("showPopover");
},
openEnvSelect() {
return this.$refs.envSelect.open();
},
setProjectEnvMap(map) {
this.$emit("setProjectEnvMap", map);
},
setEnvGroup(envGroupId) {
this.$emit("setEnvGroup", envGroupId);
},
initEnv() {
return this.$refs.envSelect.initEnv();
},
checkEnv(data) {
return this.$refs.envSelect.checkEnv(data);
},
radioChange(val) {
this.$emit("update:environmentType", val);
}
}
}
</script>
<style scoped>
</style>

View File

@ -1,211 +0,0 @@
<template>
<div v-loading="result.loading">
<div v-for="pe in data" :key="pe.id" style="margin-left: 20px;">
<el-select v-model="pe['selectEnv']"
placeholder="请选择环境"
style="margin-top: 8px;width: 200px;"
size="small"
clearable>
<el-option v-for="(environment, index) in pe.envs"
:key="index"
:label="environment.name"
:value="environment.id"/>
<el-button v-if="isShowConfirmButton(pe.id)"
@click="openEnvironmentConfig(pe.id, pe['selectEnv'])"
class="ms-scenario-button"
size="mini"
type="primary">
{{ $t('api_test.environment.environment_config') }}
</el-button>
<template v-slot:empty>
<div v-if="isShowConfirmButton(pe.id)" class="empty-environment">
<el-button class="ms-scenario-button" size="mini" type="primary"
@click="openEnvironmentConfig(pe.id, pe['selectEnv'])">
{{ $t('api_test.environment.environment_config') }}
</el-button>
</div>
</template>
</el-select>
<span class="project-name" :title="getProjectName(pe.id)">
{{ getProjectName(pe.id) }}
<el-tooltip class="item"
effect="light"
:content="'存在多个环境' + '(' + pe.conflictEnv + ')'"
placement="top-end">
<i class="el-icon-warning-outline"
v-show="pe.selectEnv === '' && pe.conflictEnv !== ''"/>
</el-tooltip>
</span>
</div>
<el-button type="primary" @click="handleConfirm" size="small" class="env-confirm"> </el-button>
<!-- 环境配置 -->
<api-environment-config ref="environmentConfig" @close="environmentConfigClose"/>
</div>
</template>
<script>
import {parseEnvironment} from "@/business/components/api/test/model/EnvironmentModel";
import ApiEnvironmentConfig from "@/business/components/api/test/components/ApiEnvironmentConfig";
export default {
name: "EnvironmentSelect",
components: {ApiEnvironmentConfig},
props: {
projectIds: Set,
projectList: Array,
showConfigButtonWithOutPermission: {
type: Boolean,
default() {
return true;
}
},
result: {
type: Object,
default() {
return {loading: false}
}
},
projectEnvMap: {
type: Object,
default() {
return {};
}
}
},
data() {
return {
data: [],
permissionProjectIds: [],
dialogVisible: false,
envMap: new Map()
}
},
methods: {
isShowConfirmButton(projectId) {
if (this.showConfigButtonWithOutPermission === true) {
return true;
} else {
if (this.permissionProjectIds) {
if (this.permissionProjectIds.indexOf(projectId) < 0) {
return false;
} else {
return true;
}
} else {
return false;
}
}
},
init() {
//ID
if (this.permissionProjectIds.length === 0) {
this.getUserPermissionProjectIds();
}
let arr = [];
this.projectIds.forEach(projectId => {
const project = this.projectList.find(p => p.id === projectId);
if (project) {
let item = {id: projectId, envs: [], selectEnv: "", conflictEnv: ""};
this.data.push(item);
let p = new Promise(resolve => {
this.$get('/api/environment/list/' + projectId, res => {
let envs = res.data;
//
envs.forEach(environment => {
parseEnvironment(environment);
});
//
let temp = this.data.find(dt => dt.id === projectId);
temp.envs = envs;
let envList = [];
// projectEnvMap {"projectId": {"env1", "env2"}}
for (let pid in this.projectEnvMap) {
if (projectId === pid) {
envList = this.projectEnvMap[pid];
break;
}
}
//
if (envList.length <= 1) {
//
temp.selectEnv = envs.filter(e => e.id === envList[0]).length === 0 ? null : envList[0];
} else {
//
envList.forEach(env => {
const index = envs.findIndex(e => e.id === env);
if (index !== -1) {
item.conflictEnv = item.conflictEnv + " " + envs[index].name;
}
});
}
resolve();
})
});
arr.push(p);
}
})
return arr;
},
getUserPermissionProjectIds() {
this.$get('/project/getOwnerProjectIds/', res => {
this.permissionProjectIds = res.data;
})
},
open() {
this.data = [];
if (this.projectIds.size > 0) {
this.init();
}
},
initEnv() {
this.data = [];
return Promise.all(this.init());
},
getProjectName(id) {
const project = this.projectList.find(p => p.id === id);
return project ? project.name : "";
},
openEnvironmentConfig(projectId, envId) {
if (!projectId) {
this.$error(this.$t('api_test.select_project'));
return;
}
this.$refs.environmentConfig.open(projectId, envId);
},
handleConfirm() {
let map = new Map();
this.data.forEach(dt => {
map.set(dt.id, dt.selectEnv);
})
this.$emit('setProjectEnvMap', map);
this.$emit('close');
},
environmentConfigClose() {
// todo
}
}
}
</script>
<style scoped>
.ms-scenario-button {
margin-left: 20px;
}
.env-confirm {
margin-left: 20px;
width: 360px;
margin-top: 10px;
}
.project-name {
display: inline-block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 150px;
margin-left: 8px;
vertical-align: middle;
}
</style>