1、对a-tree-select组件的props属性向下透传

2、a-tree-select组件的事件全部向上暴露
This commit is contained in:
yaoyanan
2021-04-06 18:06:13 +08:00
parent f0c601ad09
commit 6743281d9f
6 changed files with 49 additions and 32 deletions
@@ -8,6 +8,8 @@
:placeholder="placeholder"
:loadData="asyncLoadTreeData"
:value="treeValue"
v-bind="_attrs"
v-on="$listeners"
:treeData="treeData"
:multiple="multiple"
@change="onChange">
@@ -19,11 +21,7 @@
export default {
name: 'JCategorySelect',
props: {
value:{
type: String,
required: false
},
props:{
placeholder:{
type: String,
default: '请选择',
@@ -74,7 +72,6 @@
tableName:"",
text:"",
code:"",
}
},
watch: {
@@ -91,6 +88,13 @@
this.loadItemByCode()
})
},
computed:{
_attrs() {
let attrs
attrs = { ...this.$attrs }
return attrs
}
},
methods: {
/**加载一级节点 */
loadRoot(){
@@ -141,11 +145,12 @@
}
},
backValue(value,label){
console.log(label)
let obj = {}
if(this.back){
obj[this.back] = label
}
this.$emit('change', value, obj)
// this.$emit('change', value, obj)
},
asyncLoadTreeData (treeNode) {
return new Promise((resolve) => {
@@ -194,7 +199,7 @@
onChange(value){
if(!value){
this.$emit('change', '');
// this.$emit('change', '');
this.treeValue = ''
} else if (Array.isArray(value)) {
let labels = []
+9 -14
View File
@@ -10,7 +10,8 @@
:value="treeValue"
:treeData="treeData"
@change="onChange"
@search="onSearch">
v-bind="_attrs"
v-on="$listeners">
</a-tree-select>
</template>
@@ -29,10 +30,6 @@
}
},
props:{
value:{
type: String,
required: false
},
placeholder:{
type: String,
default: '请选择',
@@ -86,6 +83,13 @@
}
}
},
computed:{
_attrs(){
let attrs
attrs = { ...this.$attrs }
return attrs
}
},
created(){
this.loadRoot()
this.loadViewInfo()
@@ -178,17 +182,8 @@
}
},
onChange(value){
console.log(value)
if(!value){
this.$emit('change', '');
}else{
this.$emit('change', value.value);
}
this.treeValue = value
},
onSearch(value){
console.log(value)
},
getCurrTreeData(){
return this.treeData
}
+15 -7
View File
@@ -14,6 +14,8 @@
:treeData="treeData"
:multiple="multiple"
:show-search="!multiple"
v-bind="_attrs"
v-on="$listeners"
@change="onChange">
</a-tree-select>
<a-tree-select
@@ -29,6 +31,8 @@
:treeData="treeData"
:multiple="multiple"
:show-search="!multiple"
v-bind="_attrs"
v-on="$listeners"
@change="onChange">
</a-tree-select>
</div>
@@ -49,10 +53,10 @@
required:false,
default:true
},
value:{
type: String,
required: false
},
// value:{
// type: String,
// required: false
// },
placeholder:{
type: String,
default: '请选择',
@@ -119,6 +123,13 @@
this.loadRoot()
}
},
computed:{
_attrs() {
let attrs
attrs = { ...this.$attrs }
return attrs
}
},
created(){
this.validateProp().then(()=>{
this.initDictInfo()
@@ -251,15 +262,12 @@
},
onChange(value){
if(!value){
this.$emit('change', '');
this.treeValue = null
} else if (value instanceof Array) {
//多选
this.$emit('change', value.join(',').toString()) //修改第一次选中时,选中为空的情况
this.treeValue = value
} else {
//单选
this.$emit('change', value)
this.treeValue = value
}
},
@@ -31,6 +31,9 @@
{ title: '角色编码', dataIndex: 'roleCode', align: 'center', width: 120 }
]
}
},
created(){
console.log(this.$attrs)
}
}
</script>