Commit a3e91f89 authored by 黄奎's avatar 黄奎

插件修改

parent 96903729
......@@ -47,7 +47,9 @@ module.exports = function(ctx) {
build: {
vueRouterMode: 'hash', // available values: 'hash', 'history'
env: ctx.dev ? {
API: 'https://localhost:5001/api'
//http://192.168.1.27:8300/api
//https://localhost:5001/api
API: 'http://192.168.1.27:8300/api'
} : {
API: 'https://prod.api.com'
},
......
<template>
<div style="width:300px" :id="id">
<!--多选-->
<template v-if="multiple">
<q-select filled v-model="resultObj" :options="selectList" clearable @clear="clearData()" :label="tipText"
:multiple="multiple" emit-value map-options>
......@@ -15,6 +16,7 @@
</template>
</q-select>
</template>
<!--单选-->
<template v-else>
<q-select filled v-model="resultObj[0]" :options="selectList" clearable @clear="clearData()" :label="tipText"
:multiple="multiple" emit-value map-options>
......@@ -30,7 +32,6 @@
</template>
</q-select>
</template>
</div>
</template>
<script>
......@@ -100,6 +101,7 @@
}
this.setTreeCheckNode()
},
//有默认值
defaultArray: {
handler(newValue) {
if (this.defaultArray && this.defaultArray.length > 0) {
......
<template>
<q-card style="width: 360px;">
<q-input ref="selectTree" standout="bg-primary text-white" v-model="showMsg" :label="tipText"
@click.native="isShowSelect = !isShowSelect">
<!-- <template v-slot:append>
<q-btn round dense flat icon="search" />
</template> -->
</q-input>
<q-card style="width:100%;position:absolute;z-index:100;background:#fff;border:1px solid rgba(0, 0, 0, 0.12);">
<q-btn-group push v-if="isShowSelect" :spread="true">
<q-btn v-if="multiple" push label="全选" @click="checkAll()" />
<q-btn push label="清空" @click="clearMsg()" />
<q-btn push label="确认" @click="getCheckValue()" />
<q-btn push label="关闭" @click="isShowSelect=false" />
</q-btn-group>
<q-tree style="height:250px;overflow-y: scroll;" v-if="isShowSelect" :nodes="treeData" :node-key="nodeKey"
:label-key="labelKey" :children-key="childrenKey" tick-strategy="strict" :default-expand-all="defaultExpandAll"
no-connectors :ticked.sync="chooseArray">
</q-tree>
</q-card>
</q-card>
</template>
<script>
export default {
props: {
//树形结构列表
treeData: {
type: Array,
required: true
},
//是否默认展开
defaultExpandAll: {
type: Boolean,
default: false
},
//是否多选
multiple: {
type: Boolean,
default: false
},
//默认选中值
defaultArray: {
type: Array,
required: true,
},
//节点Key
nodeKey: {
type: String,
default: 'id'
},
//节点名称
labelKey: {
type: String,
default: 'name'
},
//子节点名称
childrenKey: {
type: String,
default: 'children'
},
//下拉框提示信息
tipText: {
type: String,
default: '请选择'
}
},
data() {
return {
//是否显示树状选择器
isShowSelect: false,
selectList: [],
defaultProps: {
children: 'children',
label: 'label'
},
showMsg: "",
chooseArray: [],
resultObj: "",
}
},
watch: {
isShowSelect(val) {
//隐藏select自带的下拉框
this.$refs.selectTree.blur();
if (val) {
// 下拉面板展开-选中节点-展开节点
this.setTreeCheckNode();
}
},
chooseArray(val) {
if (!this.multiple && this.chooseArray && this.chooseArray.length > 1) {
var lastItem = this.chooseArray[this.chooseArray.length - 1];
this.chooseArray = [lastItem];
}
this.setTreeCheckNode()
},
defaultArray: {
handler(newValue) {
if (this.defaultArray && this.defaultArray.length > 0) {
this.defaultArray.forEach(item => {
if (item != '') {
if (this.multiple) {
this.chooseArray.push(item)
} else {
this.chooseArray = [item];
}
}
})
}
this.setTreeCheckNode();
},
immediate: true
}
},
mounted() {},
methods: {
//全选
checkAll() {
var tempArray = [];
var nodes = this.findTreeNode(this.treeData);
if (nodes && nodes.length > 0) {
nodes.forEach(item => {
tempArray.push(item.value)
});
}
this.chooseArray = tempArray;
},
//清空选中
clearMsg() {
this.chooseArray = [];
},
//返回选中的值
getCheckValue() {
this.isShowSelect = false;
this.$emit('getChild', this.resultObj);
},
//设置下拉框选择
setTreeCheckNode() {
var that = this;
this.selectList = [];
if (this.multiple) {
this.resultObj = [];
} else {
this.resultObj = "";
}
this.showMsg = "";
var tempStr = "";
var nodes = this.findTreeNode(this.treeData);
if (this.chooseArray && this.chooseArray.length > 0 && nodes && nodes.length > 0) {
this.chooseArray.forEach(id => {
nodes.forEach((item, index) => {
if (item.value == id) {
this.selectList.push({
value: item.value,
label: item.label
});
tempStr += "," + item.label;
if (this.multiple) {
this.resultObj.push(item.value);
} else {
this.resultObj = item.value;
}
}
})
})
if (tempStr && tempStr != '') {
this.showMsg = tempStr.substring(1, tempStr.length);
}
}
},
//获取所有节点
findTreeNode(tree) {
var temp = [];
var that = this;
//获取子节点
var getChildNodes = function (tree) {
if (tree && tree.length > 0) {
for (var i = 0; i < tree.length; i++) {
var item = tree[i];
temp.push({
label: tree[i][that.labelKey],
value: tree[i][that.nodeKey]
});
if (tree[i][that.childrenKey]) {
getChildNodes(tree[i][that.childrenKey]);
}
}
}
};
getChildNodes(tree);
return temp;
}
}
}
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment