fix(接口定义) 模块匹配级联修改

This commit is contained in:
fit2-zhao 2021-09-17 11:33:05 +08:00 committed by fit2-zhao
parent 031263ec66
commit 85facc5364
3 changed files with 382 additions and 341 deletions

View File

@ -2,10 +2,10 @@
<div>
<div v-if="request.protocol === 'HTTP'">
<div v-if="request.url || isCustomizeReq">
<el-select v-model="request.method" style="width: 100px" size="small">
<el-select v-model="request.method" style="width: 100px;margin-right: 10px" size="small">
<el-option v-for="item in reqOptions" :key="item.id" :label="item.label" :value="item.id"/>
</el-select>
<el-input v-model="request.domain" v-if="request.isRefEnvironment && request.domain" size="small" readonly style="width: 150px"/>
<el-input v-model="request.domain" v-if="request.isRefEnvironment && request.domain" size="small" readonly style="width: 150px;margin-right: 10px"/>
<el-input :placeholder="$t('api_test.definition.request.path_all_info')" v-model="request.url"
style="width: 50%" size="small" @blur="urlChange">
</el-input>
@ -14,10 +14,10 @@
</el-checkbox>
</div>
<div v-else>
<el-select v-model="request.method" style="width: 100px" size="small">
<el-select v-model="request.method" style="width: 100px;margin-right: 10px" size="small">
<el-option v-for="item in reqOptions" :key="item.id" :label="item.label" :value="item.id"/>
</el-select>
<el-input v-model="request.domain" v-if="request.domain" size="small" readonly style="width: 150px"/>
<el-input v-model="request.domain" v-if="request.domain" size="small" readonly style="width: 150px;margin-right: 10px"/>
<el-input :placeholder="$t('api_test.definition.request.path_all_info')" style="width: 50%"
v-model="request.path" size="small" @blur="pathChange"/>
</div>
@ -139,6 +139,7 @@ export default {
white-space: nowrap;
width: 120px;
}
.is-ref-environment {
margin-left: 15px;
}

View File

@ -21,7 +21,7 @@
<el-radio label="PATH">{{ $t('api_test.definition.api_path') }}</el-radio>
</el-radio-group>
<div v-if="condition.type === 'MODULE'" style="margin-top: 6px">
<ms-select-tree size="small" :data="moduleOptions" :default-key="condition.ids" @getValue="setModule" :obj="moduleObj" clearable checkStrictly multiple v-if="!loading"/>
<ms-select-tree size="small" :data="moduleOptions" :default-key="condition.ids" @getValue="setModule" :obj="moduleObj" clearable :checkStrictly="true" multiple v-if="!loading"/>
</div>
<div v-if="condition.type === 'PATH'" style="margin-top: 6px">
<el-input v-model="pathDetails.name" :placeholder="$t('api_test.value')" clearable size="small">

View File

@ -14,7 +14,8 @@
:expand-on-click-node="multiple&&expandClickNode"
:check-on-click-node="checkClickNode"
:highlight-current="true"
@check-change="nodeClick"
@check="clickDeal"
:default-checked-keys="checkedId"
:filter-node-method="filterNode"
@node-click="nodeClick"/>
<el-select slot="reference" ref="select" :size="size"
@ -30,379 +31,418 @@
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
</el-select>
<el-row>
<el-button v-if="multiple" class="ok" @click="isShowSelect=false" size="mini" type="text">{{$t('commons.confirm')}}</el-button>
<el-button v-if="multiple" class="ok" @click="isShowSelect=false" size="mini" type="text">{{ $t('commons.confirm') }}</el-button>
</el-row>
</el-popover>
</div>
</template>
<script>
import OutsideClick from "@/common/js/outside-click";
import OutsideClick from "@/common/js/outside-click";
export default {
name: 'SelectTree',
directives: {OutsideClick},
props: {
//
data: {
type: Array,
default() {
return [];
}
},
obj: {
type: Object,
required: false,
default: () => {
return {
id: 'id',// ID
label: 'name',//
children: 'children', //
path: 'path',//
content: 'content',//
pid: 'pid',//id
}
}
},
disabled: {
type: Boolean,
default: false,
},
//
multiple: {
type: Boolean,
default() {
return false;
}
},
//
clearable: {
type: Boolean,
default() {
return false;
}
},
//
collapseTags: {
type: Boolean,
default() {
return false;
}
},
//
checkStrictly: {
type: Boolean,
default() {
return false;
}
},
//
checkClickNode: {
type: Boolean,
default() {
return false;
}
},
//
expandClickNode: {
type: Boolean,
default() {
return false;
}
},
// key
defaultKey: {
type: [Number, String, Array, Object],
default() {
return [];
}
},
size: {
type: String,
default() {
return 'small';
}
},
width: {
type: String,
default() {
return '100%';
}
},
height: {
type: String,
default() {
return '300px';
export default {
name: 'SelectTree',
directives: {OutsideClick},
props: {
//
data: {
type: Array,
default() {
return [];
}
},
obj: {
type: Object,
required: false,
default: () => {
return {
id: 'id',// ID
label: 'name',//
children: 'children', //
path: 'path',//
content: 'content',//
pid: 'pid',//id
disabled: this.isDisabled
}
}
},
//
data() {
return {
popoverWidth: "0px",//
isShowSelect: false, //
options: [],//select option
returnDatas: [],//
returnDataKeys: [],//
filterText: "",
loading:false,
};
disabled: {
type: Boolean,
default: false,
},
computed: {
treeData() { //
return JSON.stringify(this.data).indexOf(this.obj.children) !== -1 ? this.data : this.switchTree();
},
//
multiple: {
type: Boolean,
default() {
return false;
}
},
mounted() {
this.init();
//
clearable: {
type: Boolean,
default() {
return false;
}
},
methods: {
outsideClick(e) {
e.stopPropagation();
this.isShowSelect = false;
},
init() {
if (this.defaultKey != undefined && this.defaultKey.length > 0) {
if (this.multiple) {
//
if (Object.prototype.toString.call(this.defaultKey).indexOf("Array") != -1) {
if (Object.prototype.toString.call(this.defaultKey[0]).indexOf("Object") != -1) {//
this.setDatas(this.defaultKey);
} else if (Object.prototype.toString.call(this.defaultKey[0]).indexOf("Number") != -1
|| Object.prototype.toString.call(this.defaultKey[0]).indexOf("String") != -1) {
this.setKeys(this.defaultKey);
} else {
console.log("多选:传入参数类型不匹配");
return;
}
//
collapseTags: {
type: Boolean,
default() {
return false;
}
},
//
checkStrictly: {
type: Boolean,
default() {
return false;
}
},
//
checkClickNode: {
type: Boolean,
default() {
return false;
}
},
//
expandClickNode: {
type: Boolean,
default() {
return false;
}
},
// key
defaultKey: {
type: [Number, String, Array, Object],
default() {
return [];
}
},
size: {
type: String,
default() {
return 'small';
}
},
width: {
type: String,
default() {
return '100%';
}
},
height: {
type: String,
default() {
return '300px';
}
}
},
//
data() {
return {
popoverWidth: "0px",//
isShowSelect: false, //
options: [],//select option
returnDatas: [],//
returnDataKeys: [],//
filterText: "",
loading: false,
checkedId: [],
};
},
computed: {
treeData() { //
return JSON.stringify(this.data).indexOf(this.obj.children) !== -1 ? this.data : this.switchTree();
},
},
mounted() {
this.init();
},
methods: {
updated() {
//
this.$refs.tree.setCheckedKeys(this.checkedId)
},
clickDeal(currentObj, treeStatus) {
//
let selected = treeStatus.checkedKeys.indexOf(currentObj.id) // -1
//
if (selected !== -1) {
//
this.selectedParent(currentObj)
//
this.uniteChildSame(currentObj, true)
} else {
//
if (currentObj.children && currentObj.children.length !== 0) {
this.uniteChildSame(currentObj, false)
}
}
this.nodeClick(currentObj, treeStatus)
},
//
uniteChildSame(treeList, isSelected) {
this.$refs.tree.setChecked(treeList.id, isSelected)
if (treeList.children) {
for (let i = 0; i < treeList.children.length; i++) {
this.uniteChildSame(treeList.children[i], isSelected)
}
}
},
//
selectedParent(currentObj) {
let currentNode = this.$refs.tree.getNode(currentObj)
if (currentNode.parent.key !== undefined) {
this.$refs.tree.setChecked(currentNode.parent, true)
this.selectedParent(currentNode.parent)
}
},
outsideClick(e) {
e.stopPropagation();
this.isShowSelect = false;
},
init() {
if (this.defaultKey != undefined && this.defaultKey.length > 0) {
if (this.multiple) {
//
if (Object.prototype.toString.call(this.defaultKey).indexOf("Array") != -1) {
if (Object.prototype.toString.call(this.defaultKey[0]).indexOf("Object") != -1) {//
this.setDatas(this.defaultKey);
} else if (Object.prototype.toString.call(this.defaultKey[0]).indexOf("Number") != -1
|| Object.prototype.toString.call(this.defaultKey[0]).indexOf("String") != -1) {
this.setKeys(this.defaultKey);
} else {
console.log("多选:传入参数类型不匹配");
return;
}
} else {
//
if (Object.prototype.toString.call(this.defaultKey).indexOf("Number") != -1
|| Object.prototype.toString.call(this.defaultKey).indexOf("String") != -1
|| Object.prototype.toString.call(this.defaultKey).indexOf("Object") != -1) {
this.setKey(this.defaultKey);
} else {
console.log("单选:传入参数类型不匹配");
return;
}
return;
}
} else {
//
if (Object.prototype.toString.call(this.defaultKey).indexOf("Number") != -1
|| Object.prototype.toString.call(this.defaultKey).indexOf("String") != -1
|| Object.prototype.toString.call(this.defaultKey).indexOf("Object") != -1) {
this.setKey(this.defaultKey);
} else {
return;
}
}
},
//select[]
selectClick() {
if (this.disabled) {
return;
}
this.$nextTick(function () {//
this.popoverWidth = this.$refs.select.$el.clientWidth - 26;
})
//
return this.isShowSelect = !this.isShowSelect
},
//:
nodeClick(data, node) {
if (!this.multiple) {//
this.isShowSelect = false;
this.setKey(node.key);
} else {//
let checkedKeys = this.$refs.tree.getCheckedKeys(); // key
let t = [];
this.options = checkedKeys.map((item) => {//option
let node = this.$refs.tree.getNode(item); // node
t.push(node.data);
return {label: node.label, value: node.key};
});
this.returnDataKeys = this.options.map((item) => {
return item.value;
});
this.returnDatas = t;
}
},
//:
clean() {
this.$refs.tree.setCurrentKey(null);//key
this.returnDatas = null;
this.returnDataKeys = '';
this.popoverHide();
},
//: key
setKey(thisKey) {
this.$refs.tree.setCurrentKey(thisKey);
let node = this.$refs.tree.getNode(thisKey);
if (node && node.data) {
this.setData(node.data);
}
},
//
setData(data) {
this.options = [];
this.options.push({label: data[this.obj.label], value: data[this.obj.id]});
this.returnDatas = data;
this.returnDataKeys = data[this.obj.id]
},
//: keys
setKeys(thisKeys) {
this.$refs.tree.setCheckedKeys(thisKeys);
this.returnDataKeys = thisKeys;
}
},
//select[]
selectClick() {
if (this.disabled) {
return;
}
this.$nextTick(function () {//
this.popoverWidth = this.$refs.select.$el.clientWidth - 26;
})
//
return this.isShowSelect = !this.isShowSelect
},
//:
nodeClick(data, node) {
if (!this.multiple) {//
this.isShowSelect = false;
this.setKey(node.key);
} else {//
let checkedKeys = this.$refs.tree.getCheckedKeys(); // key
let t = [];
thisKeys.map((item) => {//option
this.options = checkedKeys.map((item) => {//option
let node = this.$refs.tree.getNode(item); // node
t.push(node.data);
this.options.push({label: node.label, value: node.key});
return {label: node.label, value: node.key};
});
this.returnDataKeys = this.options.map((item) => {
return item.value;
});
this.returnDatas = t;
this.popoverHide()
},
//:
setDatas(data) {
this.$refs.tree.setCheckedNodes(data);
this.returnDatas = data;
let t = [];
data.map((item) => {//option
t.push(item[this.obj.id]);
});
this.returnDataKeys = t;
this.popoverHide()
},
// ,select
removeTag(val) {
this.$refs.tree.setChecked(val, false);//
let node = this.$refs.tree.getNode(val);//
if (!this.checkStrictly && node.childNodes.length > 0) {
this.treeToList(node).map(item => {
if (item.childNodes.length <= 0) {
this.$refs.tree.setChecked(item, false);
}
});
}
this.nodeClick();
this.popoverHide();
}
},
//:
clean() {
this.$refs.tree.setCurrentKey(null);//key
this.returnDatas = null;
this.returnDataKeys = '';
this.popoverHide();
},
//
popoverHide() {
this.$emit('getValue', this.returnDataKeys, this.returnDatas ? this.returnDatas : {});
},
//
clearSelectedNodes() {
let checkedKeys = this.$refs.tree.getCheckedKeys(); // key
for (let i = 0; i < checkedKeys.length; i++) {
this.$refs.tree.setChecked(checkedKeys[i], false);
}
},
},
//: key
setKey(thisKey) {
this.$refs.tree.setCurrentKey(thisKey);
let node = this.$refs.tree.getNode(thisKey);
if (node && node.data) {
this.setData(node.data);
}
},
//
setData(data) {
this.options = [];
this.options.push({label: data[this.obj.label], value: data[this.obj.id]});
this.returnDatas = data;
this.returnDataKeys = data[this.obj.id]
//
treeToList(tree) {
let queen = [];
let out = [];
queen = queen.concat(tree);
while (queen.length) {
let first = queen.shift();
if (first.childNodes) {
queen = queen.concat(first.childNodes);
},
//: keys
setKeys(thisKeys) {
this.$refs.tree.setCheckedKeys(thisKeys);
this.returnDataKeys = thisKeys;
let t = [];
thisKeys.map((item) => {//option
let node = this.$refs.tree.getNode(item); // node
t.push(node.data);
this.options.push({label: node.label, value: node.key});
return {label: node.label, value: node.key};
});
this.returnDatas = t;
this.popoverHide()
},
//:
setDatas(data) {
this.$refs.tree.setCheckedNodes(data);
this.returnDatas = data;
let t = [];
data.map((item) => {//option
t.push(item[this.obj.id]);
});
this.returnDataKeys = t;
this.popoverHide()
},
// ,select
removeTag(val) {
this.$refs.tree.setChecked(val, false);//
let node = this.$refs.tree.getNode(val);//
if (!this.checkStrictly && node.childNodes.length > 0) {
this.treeToList(node).map(item => {
if (item.childNodes.length <= 0) {
this.$refs.tree.setChecked(item, false);
}
out.push(first);
}
return out;
},
switchTree() {
return this.buildTree(this.data, this.defaultValue);
},
//
buildTree(data, id) {
const fa = (id) => {
const temp = [];
for (let i = 0; i < data.length; i++) {
const n = data[i];
if (n[this.obj.pid] === id) {
n[this.obj.children] = fa(n[this.obj.id]);
temp.push(n);
}
}
return temp;
};
return fa(id);
},
filterNode(value, data) {
if (!value) return true;
if (data.label) {
return data.label.indexOf(value.toLowerCase()) !== -1;
}
return false;
},
reload() {
this.loading = true
this.$nextTick(() => {
this.loading = false
});
},
}
this.nodeClick();
this.popoverHide();
},
//
popoverHide() {
this.$emit('getValue', this.returnDataKeys, this.returnDatas ? this.returnDatas : {});
},
//
clearSelectedNodes() {
let checkedKeys = this.$refs.tree.getCheckedKeys(); // key
for (let i = 0; i < checkedKeys.length; i++) {
this.$refs.tree.setChecked(checkedKeys[i], false);
}
},
watch: {
// eslint-disable-next-line no-unused-vars
isShowSelect(val) {
// select
this.$refs.select.blur();
},
treeData: {//tree
handler: function () {
this.$nextTick(() => {
this.init();
})
},
deep: true
},
filterText(val) {
//
treeToList(tree) {
let queen = [];
let out = [];
queen = queen.concat(tree);
while (queen.length) {
let first = queen.shift();
if (first.childNodes) {
queen = queen.concat(first.childNodes);
}
out.push(first);
}
return out;
},
switchTree() {
return this.buildTree(this.data, this.defaultValue);
},
//
buildTree(data, id) {
const fa = (id) => {
const temp = [];
for (let i = 0; i < data.length; i++) {
const n = data[i];
if (n[this.obj.pid] === id) {
n[this.obj.children] = fa(n[this.obj.id]);
temp.push(n);
}
}
return temp;
};
return fa(id);
},
filterNode(value, data) {
if (!value) return true;
if (data.label) {
return data.label.indexOf(value.toLowerCase()) !== -1;
}
return false;
},
reload() {
this.loading = true
this.$nextTick(() => {
this.loading = false
});
},
},
watch: {
// eslint-disable-next-line no-unused-vars
isShowSelect(val) {
// select
this.$refs.select.blur();
},
treeData: {//tree
handler: function () {
this.$nextTick(() => {
this.$refs.tree.filter(val);
});
this.init();
})
},
filter(val) {
this.$nextTick(() => {
this.$refs.tree.filter(val);
});
},
}
};
deep: true
},
filterText(val) {
this.$nextTick(() => {
this.$refs.tree.filter(val);
});
},
filter(val) {
this.$nextTick(() => {
this.$refs.tree.filter(val);
});
},
}
};
</script>
<style scoped>
.mask {
height: 100%;
position: fixed;
top: 0;
left: 0;
opacity: 0;
z-index: 11;
}
.mask {
height: 100%;
position: fixed;
top: 0;
left: 0;
opacity: 0;
z-index: 11;
}
.common-tree {
overflow: auto;
min-height: 200px;
max-height: 400px;
}
.common-tree {
overflow: auto;
min-height: 200px;
max-height: 400px;
}
.ms-tree-select {
width: 100%;
z-index: 111;
}
/deep/.el-tree-node__children{
overflow: inherit;
}
.ok {
float: right;
}
.ms-tree-select {
width: 100%;
z-index: 111;
}
.el-row {
padding-top: 0px !important;
}
/deep/ .el-tree-node__children {
overflow: inherit;
}
.ok {
float: right;
}
.el-row {
padding-top: 0px !important;
}
</style>