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" :placeholder="placeholder"
:loadData="asyncLoadTreeData" :loadData="asyncLoadTreeData"
:value="treeValue" :value="treeValue"
v-bind="_attrs"
v-on="$listeners"
:treeData="treeData" :treeData="treeData"
:multiple="multiple" :multiple="multiple"
@change="onChange"> @change="onChange">
@@ -19,11 +21,7 @@
export default { export default {
name: 'JCategorySelect', name: 'JCategorySelect',
props: { props:{
value:{
type: String,
required: false
},
placeholder:{ placeholder:{
type: String, type: String,
default: '请选择', default: '请选择',
@@ -74,7 +72,6 @@
tableName:"", tableName:"",
text:"", text:"",
code:"", code:"",
} }
}, },
watch: { watch: {
@@ -91,6 +88,13 @@
this.loadItemByCode() this.loadItemByCode()
}) })
}, },
computed:{
_attrs() {
let attrs
attrs = { ...this.$attrs }
return attrs
}
},
methods: { methods: {
/**加载一级节点 */ /**加载一级节点 */
loadRoot(){ loadRoot(){
@@ -141,11 +145,12 @@
} }
}, },
backValue(value,label){ backValue(value,label){
console.log(label)
let obj = {} let obj = {}
if(this.back){ if(this.back){
obj[this.back] = label obj[this.back] = label
} }
this.$emit('change', value, obj) // this.$emit('change', value, obj)
}, },
asyncLoadTreeData (treeNode) { asyncLoadTreeData (treeNode) {
return new Promise((resolve) => { return new Promise((resolve) => {
@@ -194,7 +199,7 @@
onChange(value){ onChange(value){
if(!value){ if(!value){
this.$emit('change', ''); // this.$emit('change', '');
this.treeValue = '' this.treeValue = ''
} else if (Array.isArray(value)) { } else if (Array.isArray(value)) {
let labels = [] let labels = []
+9 -14
View File
@@ -10,7 +10,8 @@
:value="treeValue" :value="treeValue"
:treeData="treeData" :treeData="treeData"
@change="onChange" @change="onChange"
@search="onSearch"> v-bind="_attrs"
v-on="$listeners">
</a-tree-select> </a-tree-select>
</template> </template>
@@ -29,10 +30,6 @@
} }
}, },
props:{ props:{
value:{
type: String,
required: false
},
placeholder:{ placeholder:{
type: String, type: String,
default: '请选择', default: '请选择',
@@ -86,6 +83,13 @@
} }
} }
}, },
computed:{
_attrs(){
let attrs
attrs = { ...this.$attrs }
return attrs
}
},
created(){ created(){
this.loadRoot() this.loadRoot()
this.loadViewInfo() this.loadViewInfo()
@@ -178,17 +182,8 @@
} }
}, },
onChange(value){ onChange(value){
console.log(value)
if(!value){
this.$emit('change', '');
}else{
this.$emit('change', value.value);
}
this.treeValue = value this.treeValue = value
}, },
onSearch(value){
console.log(value)
},
getCurrTreeData(){ getCurrTreeData(){
return this.treeData return this.treeData
} }
+15 -7
View File
@@ -14,6 +14,8 @@
:treeData="treeData" :treeData="treeData"
:multiple="multiple" :multiple="multiple"
:show-search="!multiple" :show-search="!multiple"
v-bind="_attrs"
v-on="$listeners"
@change="onChange"> @change="onChange">
</a-tree-select> </a-tree-select>
<a-tree-select <a-tree-select
@@ -29,6 +31,8 @@
:treeData="treeData" :treeData="treeData"
:multiple="multiple" :multiple="multiple"
:show-search="!multiple" :show-search="!multiple"
v-bind="_attrs"
v-on="$listeners"
@change="onChange"> @change="onChange">
</a-tree-select> </a-tree-select>
</div> </div>
@@ -49,10 +53,10 @@
required:false, required:false,
default:true default:true
}, },
value:{ // value:{
type: String, // type: String,
required: false // required: false
}, // },
placeholder:{ placeholder:{
type: String, type: String,
default: '请选择', default: '请选择',
@@ -119,6 +123,13 @@
this.loadRoot() this.loadRoot()
} }
}, },
computed:{
_attrs() {
let attrs
attrs = { ...this.$attrs }
return attrs
}
},
created(){ created(){
this.validateProp().then(()=>{ this.validateProp().then(()=>{
this.initDictInfo() this.initDictInfo()
@@ -251,15 +262,12 @@
}, },
onChange(value){ onChange(value){
if(!value){ if(!value){
this.$emit('change', '');
this.treeValue = null this.treeValue = null
} else if (value instanceof Array) { } else if (value instanceof Array) {
//多选 //多选
this.$emit('change', value.join(',').toString()) //修改第一次选中时,选中为空的情况
this.treeValue = value this.treeValue = value
} else { } else {
//单选 //单选
this.$emit('change', value)
this.treeValue = value this.treeValue = value
} }
}, },
@@ -31,6 +31,9 @@
{ title: '角色编码', dataIndex: 'roleCode', align: 'center', width: 120 } { title: '角色编码', dataIndex: 'roleCode', align: 'center', width: 120 }
] ]
} }
},
created(){
console.log(this.$attrs)
} }
} }
</script> </script>
+8 -2
View File
@@ -235,7 +235,7 @@
<a-row :gutter="24"> <a-row :gutter="24">
<a-col :span="12"> <a-col :span="12">
<a-form-item label="树字典"> <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-form-item>
</a-col> </a-col>
<a-col :span="12">选中的值(v-model){{ formData.treeDict }}</a-col> <a-col :span="12">选中的值(v-model){{ formData.treeDict }}</a-col>
@@ -277,7 +277,7 @@
<a-row :gutter="24"> <a-row :gutter="24">
<a-col :span="12"> <a-col :span="12">
<a-form-item label="分类字典树"> <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-form-item>
</a-col> </a-col>
<a-col :span="12">选中的值(v-model){{ formData.selectCategory }}</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: { computed: {
nameList: function() { nameList: function() {
@@ -586,6 +589,9 @@ sayHi('hello, world!')`
} }
}, },
methods: { methods: {
changeCate(){
console.log("ok")
},
getDepartIdValue() { getDepartIdValue() {
return this.form.getFieldValue('departId') return this.form.getFieldValue('departId')
}, },
@@ -14,7 +14,7 @@
<a-form-item label="父级节点" :labelCol="labelCol" :wrapperCol="wrapperCol"> <a-form-item label="父级节点" :labelCol="labelCol" :wrapperCol="wrapperCol">
<j-tree-select <j-tree-select
ref="treeSelect" ref="treeSelect"
placeholder="请选择父级节点" placeholder=""
v-decorator="['pid', validatorRules.pid]" v-decorator="['pid', validatorRules.pid]"
dict="sys_category,name,id" dict="sys_category,name,id"
pidField="pid" pidField="pid"