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>
+8 -2
View File
@@ -235,7 +235,7 @@
<a-row :gutter="24">
<a-col :span="12">
<a-form-item label="树字典">
<j-tree-dict v-model="formData.treeDict" placeholder="请选择树字典" parentCode="B01" />
<j-tree-dict v-model="formData.treeDict" :labelInValue="true" placeholder="请选择树字典" parentCode="A01" />
</a-form-item>
</a-col>
<a-col :span="12">选中的值(v-model){{ formData.treeDict }}</a-col>
@@ -277,7 +277,7 @@
<a-row :gutter="24">
<a-col :span="12">
<a-form-item label="分类字典树">
<j-category-select v-model="formData.selectCategory" pcode="B01" :multiple="true"/>
<j-category-select v-model="formData.selectCategory" pcode="A01" :multiple="true" @change="changeCate"/>
</a-form-item>
</a-col>
<a-col :span="12">选中的值(v-model){{ formData.selectCategory }}</a-col>
@@ -575,6 +575,9 @@ sayHi('hello, world!')`
],
}
},
created(){
console.log(this.formData.jInput)
},
computed: {
nameList: function() {
@@ -586,6 +589,9 @@ sayHi('hello, world!')`
}
},
methods: {
changeCate(){
console.log("ok")
},
getDepartIdValue() {
return this.form.getFieldValue('departId')
},
@@ -14,7 +14,7 @@
<a-form-item label="父级节点" :labelCol="labelCol" :wrapperCol="wrapperCol">
<j-tree-select
ref="treeSelect"
placeholder="请选择父级节点"
placeholder=""
v-decorator="['pid', validatorRules.pid]"
dict="sys_category,name,id"
pidField="pid"