【修复】修复自建组件的问题

This commit is contained in:
zer0Black
2021-05-06 16:31:24 +08:00
parent 38ba2b705a
commit c830b7ba0e
11 changed files with 191 additions and 111 deletions
@@ -9,7 +9,7 @@
:loadData="asyncLoadTreeData" :loadData="asyncLoadTreeData"
:value="treeValue" :value="treeValue"
v-bind="_attrs" v-bind="_attrs"
v-on="$listeners" v-on="childListeners"
:treeData="treeData" :treeData="treeData"
:multiple="multiple" :multiple="multiple"
@change="onChange"> @change="onChange">
@@ -79,6 +79,22 @@
} }
}, },
computed:{
_attrs() {
let attrs
attrs = { ...this.$attrs }
return attrs
},
//透传给下级组件的事件,需要排除本组件使用的change事件
childListeners() {
const vm = this;
let result = Object.assign({},
this.$listeners,
)
delete result.change;
return result;
}
},
watch: { watch: {
value () { value () {
this.loadItemByCode() this.loadItemByCode()
@@ -93,13 +109,6 @@
this.loadItemByCode() this.loadItemByCode()
}) })
}, },
computed:{
_attrs() {
let attrs
attrs = { ...this.$attrs }
return attrs
}
},
methods: { methods: {
/**加载一级节点 */ /**加载一级节点 */
loadRoot(){ loadRoot(){
@@ -159,7 +168,7 @@
/* /*
* 使用$listeners向上暴露事件---和$emit一起使用出现的问题:change事件会执行两遍 * 使用$listeners向上暴露事件---和$emit一起使用出现的问题:change事件会执行两遍
* 解决办法:改变选中时提交的事件名*/ * 解决办法:改变选中时提交的事件名*/
this.$emit('select-change', value, obj) this.$emit('change', value, obj)
}, },
asyncLoadTreeData (treeNode) { asyncLoadTreeData (treeNode) {
return new Promise((resolve) => { return new Promise((resolve) => {
@@ -211,7 +220,7 @@
/* /*
* 使用$listeners向上暴露事件---和$emit一起使用出现的问题:change事件会执行两遍 * 使用$listeners向上暴露事件---和$emit一起使用出现的问题:change事件会执行两遍
* 解决办法:改变选中时提交的事件名*/ * 解决办法:改变选中时提交的事件名*/
this.$emit('select-change', ''); this.$emit('change', '');
this.treeValue = '' this.treeValue = ''
} else if (Array.isArray(value)) { } else if (Array.isArray(value)) {
let labels = [] let labels = []
@@ -254,7 +263,7 @@
//2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 这个牛逼 //2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 这个牛逼
model: { model: {
prop: 'value', prop: 'value',
event: 'select-change' event: 'change'
} }
} }
</script> </script>
+23 -10
View File
@@ -11,7 +11,7 @@
:showTime="true" :showTime="true"
:format="dateFormat" :format="dateFormat"
v-bind="$attrs" v-bind="$attrs"
v-on="$listeners" v-on="childListeners"
:getCalendarContainer="getCalendarContainer"> :getCalendarContainer="getCalendarContainer">
</a-date-picker> </a-date-picker>
<!--YYYY-MM-DD--> <!--YYYY-MM-DD-->
@@ -25,7 +25,7 @@
:showTime="false" :showTime="false"
:format="dateFormat" :format="dateFormat"
v-bind="$attrs" v-bind="$attrs"
v-on="$listeners" v-on="childListeners"
:getCalendarContainer="getCalendarContainer"> :getCalendarContainer="getCalendarContainer">
</a-date-picker> </a-date-picker>
<!--YYYY-MM--> <!--YYYY-MM-->
@@ -36,7 +36,7 @@
:disabled="disabled || readOnly" :disabled="disabled || readOnly"
:format="dateFormat" :format="dateFormat"
v-bind="$attrs" v-bind="$attrs"
v-on="$listeners" v-on="childListeners"
@change="handleMonthChange"> @change="handleMonthChange">
</a-month-picker> </a-month-picker>
<!--YYYY--> <!--YYYY-->
@@ -49,7 +49,7 @@
:disabled="disabled || readOnly" :disabled="disabled || readOnly"
:open="yearShowOne" :open="yearShowOne"
v-bind="$attrs" v-bind="$attrs"
v-on="$listeners" v-on="childListeners"
:getCalendarContainer="getCalendarContainer" :getCalendarContainer="getCalendarContainer"
@openChange="openChangeOne" @openChange="openChangeOne"
@panelChange="panelChangeOne"> @panelChange="panelChangeOne">
@@ -101,13 +101,26 @@
return { return {
yearShowOne:false, //控制年份模态框的显示与否 yearShowOne:false, //控制年份模态框的显示与否
year:'', // mode==“year” 专用 year:'', // mode==“year” 专用
momVal:!dateStr?null:moment(dateStr,this.dateFormat), momVal:!dateStr?null:moment(dateStr,this.dateFormat)
}
},
computed: {
//透传给下级组件的事件,需要排除本组件使用的change事件
childListeners() {
const vm = this;
let result = Object.assign({},
this.$listeners,
)
delete result.change;
return result;
} }
}, },
watch: { watch: {
value (val) { value (val) {
let fm = this.dateFormat let fm = this.dateFormat
moment.prototype.toJSON = function(){return moment(this).format(fm)} moment.prototype.toJSON = function(){
return moment(this).format(fm)
}
if(!val){ if(!val){
this.momVal = null this.momVal = null
}else{ }else{
@@ -118,10 +131,10 @@
methods: { methods: {
moment, moment,
handleDateChange(mom,dateStr){ handleDateChange(mom,dateStr){
this.$emit('date-change', dateStr); this.$emit('change', dateStr);
}, },
handleMonthChange(mom,dateStr){ handleMonthChange(mom,dateStr){
this.$emit('date-change',dateStr) this.$emit('change',dateStr)
}, },
/** /**
* 弹出日历和关闭日历的回调 * 弹出日历和关闭日历的回调
@@ -135,13 +148,13 @@
this.yearShowOne = false this.yearShowOne = false
let year = moment(value,this.dateFormat).year().toString() // 处理成字符串 let year = moment(value,this.dateFormat).year().toString() // 处理成字符串
this.year = value //组件显示的 this.year = value //组件显示的
this.$emit('date-change',year) this.$emit('change',year)
} }
}, },
//2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 //2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型
model: { model: {
prop: 'value', prop: 'value',
event: 'date-change' event: 'change'
} }
} }
</script> </script>
+14 -3
View File
@@ -13,7 +13,7 @@
:isMultiple="isMultiple" :isMultiple="isMultiple"
:showUploadList="isMultiple" :showUploadList="isMultiple"
v-bind="$attrs" v-bind="$attrs"
v-on="$listeners" v-on="childListeners"
@change="handleChange" @change="handleChange"
@preview="handlePreview" @preview="handlePreview"
:class="!isMultiple?'imgupload':''"> :class="!isMultiple?'imgupload':''">
@@ -84,6 +84,17 @@
} }
//update-end-author:wangshuai date:20201021 for:LOWCOD-969 新增number属性,用于判断上传数量 //update-end-author:wangshuai date:20201021 for:LOWCOD-969 新增number属性,用于判断上传数量
}, },
computed: {
//透传给下级组件的事件,需要排除本组件使用的change事件
childListeners() {
const vm = this;
let result = Object.assign({},
this.$listeners,
)
delete result.change;
return result;
}
},
watch:{ watch:{
value: { value: {
handler(val,oldValue) { handler(val,oldValue) {
@@ -194,7 +205,7 @@
if(arr.length>0){ if(arr.length>0){
path = arr.join(",") path = arr.join(",")
} }
this.$emit('image-change', path); this.$emit('change', path);
}, },
handleDelete(file){ handleDelete(file){
//如有需要新增 删除逻辑 //如有需要新增 删除逻辑
@@ -209,7 +220,7 @@
}, },
model: { model: {
prop: 'value', prop: 'value',
event: 'image-change' event: 'change'
} }
} }
</script> </script>
+22 -11
View File
@@ -3,7 +3,7 @@
:value="inputVal" :value="inputVal"
@input="backValue" @input="backValue"
v-bind="$props" v-bind="$props"
v-on="$listeners" v-on="childListeners"
></a-input> ></a-input>
</template> </template>
@@ -40,6 +40,22 @@
default: false default: false
}, },
}, },
data(){
return {
inputVal:''
}
},
computed: {
//透传给下级组件的事件,需要排除本组件使用的change事件
childListeners() {
const vm = this;
let result = Object.assign({},
this.$listeners,
)
delete result.change;
return result;
}
},
watch:{ watch:{
value:{ value:{
immediate:true, immediate:true,
@@ -52,15 +68,6 @@
this.backValue({ target: { value: this.inputVal } }) this.backValue({ target: { value: this.inputVal } })
}, },
}, },
model: {
prop: 'value',
event: 'input_change'
},
data(){
return {
inputVal:''
}
},
methods:{ methods:{
initVal(){ initVal(){
if(!this.value){ if(!this.value){
@@ -108,8 +115,12 @@
break; break;
default: default:
} }
this.$emit('input_change', text); this.$emit('change', text);
} }
},
model: {
prop: 'value',
event: 'change'
} }
} }
</script> </script>
@@ -5,8 +5,6 @@
:value="arrayValue" :value="arrayValue"
@change="onChange" @change="onChange"
option-filter-prop="children" option-filter-prop="children"
v-bind="$attrs"
v-on="$listeners"
> >
<a-select-option <a-select-option
v-for="(item,index) in newOptions" v-for="(item,index) in newOptions"
+23 -15
View File
@@ -4,8 +4,7 @@
v-if="query" v-if="query"
style="width: 100%" style="width: 100%"
@change="handleSelectChange" @change="handleSelectChange"
v-bind="$attrs" >
v-on="$listeners">
<a-select-option v-for="(item, index) in queryOption" :key="index" :value="item.value"> <a-select-option v-for="(item, index) in queryOption" :key="index" :value="item.value">
{{ item.text }} {{ item.text }}
</a-select-option> </a-select-option>
@@ -16,7 +15,7 @@
:disabled="disabled" :disabled="disabled"
@change="handleChange" @change="handleChange"
v-bind="$attrs" v-bind="$attrs"
v-on="$listeners"/> v-on="childListeners"/>
</div> </div>
</template> </template>
<script> <script>
@@ -49,6 +48,23 @@
checkStatus: false checkStatus: false
} }
}, },
computed:{
queryOption(){
let arr = []
arr.push({value:this.options[0],text:'是'})
arr.push({value:this.options[1],text:'否'})
return arr;
},
//透传给下级组件的事件,需要排除本组件使用的change事件
childListeners() {
const vm = this;
let result = Object.assign({},
this.$listeners,
)
delete result.change;
return result;
}
},
watch: { watch: {
value:{ value:{
immediate: true, immediate: true,
@@ -56,7 +72,7 @@
if(!this.query){ if(!this.query){
if(!val){ if(!val){
this.checkStatus = false this.checkStatus = false
this.$emit('check-change', this.options[1]); this.$emit('change', this.options[1]);
}else{ }else{
if(this.options[0]==val){ if(this.options[0]==val){
this.checkStatus = true this.checkStatus = true
@@ -69,26 +85,18 @@
} }
} }
}, },
computed:{
queryOption(){
let arr = []
arr.push({value:this.options[0],text:'是'})
arr.push({value:this.options[1],text:'否'})
return arr;
}
},
methods: { methods: {
handleChange(checked){ handleChange(checked){
let flag = checked===false?this.options[1]:this.options[0]; let flag = checked===false?this.options[1]:this.options[0];
this.$emit('check-change', flag); this.$emit('change', flag);
}, },
handleSelectChange(value){ handleSelectChange(value){
this.$emit('check-change', value); this.$emit('change', value);
} }
}, },
model: { model: {
prop: 'value', prop: 'value',
event: 'check-change' event: 'change'
} }
} }
</script> </script>
+34 -41
View File
@@ -67,6 +67,10 @@
<script> <script>
import get from 'lodash.get' import get from 'lodash.get'
const LEFT_FROZEN = 1; // 1为左侧冻结
const RIGHT_FROZEN = 2; // 2为右侧冻结
const NO_FROZEN = 3; // 3为不冻结或解冻
export default { export default {
name: 'JTable', name: 'JTable',
props: { props: {
@@ -271,28 +275,23 @@ export default {
}) })
}, },
fixedChange(e, dataIndex) { fixedChange(e, dataIndex) {
// 冻结列头的参数 if (e.target.value === LEFT_FROZEN) {
// 1为左侧冻结
// 2为右侧冻结
// 3为不冻结或解冻
if (e.target.value === 1) {
//左侧冻结 //左侧冻结
this.curTableColumns.find((item) => { this.curTableColumns.find((item) => {
if (item.dataIndex === dataIndex) { if (item.dataIndex === dataIndex) {
item.fixed = 'left' item.fixed = 'left'
} }
}) })
// 左侧冻结,先把冻结项删除,再unshift到数组首位 // // 左侧冻结,先把冻结项删除,再unshift到数组首位
let arr // let arr
for (let i = 0; i < this.curTableColumns.length; i++) { // for (let i = 0; i < this.curTableColumns.length; i++) {
if (this.curTableColumns[i].dataIndex === dataIndex) { // if (this.curTableColumns[i].dataIndex === dataIndex) {
arr = this.curTableColumns.splice(i, 1) // arr = this.curTableColumns.splice(i, 1)
break // break
} // }
} // }
this.curTableColumns.unshift(arr[0]) // this.curTableColumns.unshift(arr[0])
} else if (e.target.value === 2) { } else if (e.target.value === RIGHT_FROZEN) {
//右侧冻结 //右侧冻结
this.curTableColumns.find((item) => { this.curTableColumns.find((item) => {
if (item.dataIndex === dataIndex) { if (item.dataIndex === dataIndex) {
@@ -300,14 +299,14 @@ export default {
} }
}) })
// 右侧冻结,先把冻结项删除,再push到数组末位 // 右侧冻结,先把冻结项删除,再push到数组末位
let arr // let arr
for (let i = 0; i < this.curTableColumns.length; i++) { // for (let i = 0; i < this.curTableColumns.length; i++) {
if (this.curTableColumns[i].dataIndex === dataIndex) { // if (this.curTableColumns[i].dataIndex === dataIndex) {
arr = this.curTableColumns.splice(i, 1) // arr = this.curTableColumns.splice(i, 1)
break // break
} // }
} // }
this.curTableColumns.push(arr[0]) // this.curTableColumns.push(arr[0])
} else { } else {
this.curTableColumns.find((item) => { this.curTableColumns.find((item) => {
//解冻 //解冻
@@ -315,7 +314,7 @@ export default {
item.fixed = false item.fixed = false
} }
}) })
this.diffColunms() // this.diffColunms()
} }
}, },
// 列头重新排序 // 列头重新排序
@@ -326,26 +325,20 @@ export default {
this.curTableColumns.forEach((item) => { this.curTableColumns.forEach((item) => {
if (!item.fixed) { if (!item.fixed) {
newColumnsList.push(item) newColumnsList.push(item)
} } else if (item.fixed === 'left') {
})
this.curTableColumns.forEach((item) => {
if (item.fixed === 'left') {
newFixedLeftList.push(item) newFixedLeftList.push(item)
} } else if (item.fixed === 'right') {
})
this.curTableColumns.forEach((item) => {
if (item.fixed === 'right') {
newFixedRightList.push(item) newFixedRightList.push(item)
} }
}) })
// 冒泡排序,根据key重新排序 // TODO 冒泡排序,根据key重新排序
for (var i = 0; i < newColumnsList.length - 1; i++) { // for (var i = 0; i < newColumnsList.length - 1; i++) {
for (var j = 0; j < newColumnsList.length - 1 - i; j++) { // for (var j = 0; j < newColumnsList.length - 1 - i; j++) {
if (newColumnsList[j].key > newColumnsList[j + 1].key) { // if (newColumnsList[j].key > newColumnsList[j + 1].key) {
;[newColumnsList[j], newColumnsList[j + 1]] = [newColumnsList[j + 1], newColumnsList[j]] // [newColumnsList[j], newColumnsList[j + 1]] = [newColumnsList[j + 1], newColumnsList[j]]
} // }
} // }
} // }
// 解构赋值,重新定义列头List // 解构赋值,重新定义列头List
this.curTableColumns = [...[...newFixedLeftList, ...newColumnsList], ...newFixedRightList] this.curTableColumns = [...[...newFixedLeftList, ...newColumnsList], ...newFixedRightList]
}, },
+14 -3
View File
@@ -5,7 +5,7 @@
:value="momVal" :value="momVal"
:format="dateFormat" :format="dateFormat"
v-bind="$attrs" v-bind="$attrs"
v-on="$listeners" v-on="childListeners"
:getCalendarContainer="getCalendarContainer" :getCalendarContainer="getCalendarContainer"
@change="handleTimeChange"/> @change="handleTimeChange"/>
</template> </template>
@@ -51,6 +51,17 @@
momVal:!timeStr?null:moment(timeStr,this.dateFormat) momVal:!timeStr?null:moment(timeStr,this.dateFormat)
} }
}, },
computed: {
//透传给下级组件的事件,需要排除本组件使用的change事件
childListeners() {
const vm = this;
let result = Object.assign({},
this.$listeners,
)
delete result.change;
return result;
}
},
watch: { watch: {
value (val) { value (val) {
if(!val){ if(!val){
@@ -63,13 +74,13 @@
methods: { methods: {
moment, moment,
handleTimeChange(mom,timeStr){ handleTimeChange(mom,timeStr){
this.$emit('time-change', timeStr); this.$emit('change', timeStr);
} }
}, },
//2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 这个牛逼 //2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 这个牛逼
model: { model: {
prop: 'value', prop: 'value',
event: 'time-change' event: 'change'
} }
} }
</script> </script>
+13 -4
View File
@@ -12,7 +12,7 @@
@change="onChange" @change="onChange"
@search="onSearch" @search="onSearch"
v-bind="_attrs" v-bind="_attrs"
v-on="$listeners"> v-on="childListeners">
</a-tree-select> </a-tree-select>
</template> </template>
@@ -93,6 +93,15 @@
let attrs let attrs
attrs = { ...this.$attrs } attrs = { ...this.$attrs }
return attrs return attrs
},
//透传给下级组件的事件,需要排除本组件使用的change事件
childListeners() {
const vm = this;
let result = Object.assign({},
this.$listeners,
)
delete result.change;
return result;
} }
}, },
created(){ created(){
@@ -101,7 +110,7 @@
}, },
model: { model: {
prop: 'value', prop: 'value',
event: 'select-change' event: 'change'
}, },
methods:{ methods:{
loadViewInfo(){ loadViewInfo(){
@@ -191,9 +200,9 @@
/* /*
* 使用$listeners向上暴露事件---和$emit一起使用出现的问题:change事件会执行两遍 * 使用$listeners向上暴露事件---和$emit一起使用出现的问题:change事件会执行两遍
* 解决办法:改变选中时提交的事件名*/ * 解决办法:改变选中时提交的事件名*/
this.$emit('select-change', ''); this.$emit('change', '');
}else{ }else{
this.$emit('select-change', value.value); this.$emit('change', value.value);
} }
this.treeValue = value this.treeValue = value
}, },
+14 -5
View File
@@ -15,7 +15,7 @@
:multiple="multiple" :multiple="multiple"
:show-search="!multiple" :show-search="!multiple"
v-bind="_attrs" v-bind="_attrs"
v-on="$listeners" v-on="childListeners"
@change="onChange"> @change="onChange">
</a-tree-select> </a-tree-select>
<a-tree-select <a-tree-select
@@ -128,6 +128,15 @@
let attrs let attrs
attrs = { ...this.$attrs } attrs = { ...this.$attrs }
return attrs return attrs
},
//透传给下级组件的事件,需要排除本组件使用的change事件
childListeners() {
const vm = this;
let result = Object.assign({},
this.$listeners,
)
delete result.change;
return result;
} }
}, },
created(){ created(){
@@ -267,15 +276,15 @@
/* /*
* 使用$listeners向上暴露事件---和$emit一起使用出现的问题:change事件会执行两遍 * 使用$listeners向上暴露事件---和$emit一起使用出现的问题:change事件会执行两遍
* 解决办法:改变选中时提交的事件名*/ * 解决办法:改变选中时提交的事件名*/
this.$emit('select-change', ''); this.$emit('change', '');
this.treeValue = null this.treeValue = null
} else if (value instanceof Array) { } else if (value instanceof Array) {
//多选 //多选
this.$emit('select-change', value.join(',').toString()) //修改第一次选中时,选中为空的情况 this.$emit('change', value.join(',').toString()) //修改第一次选中时,选中为空的情况
this.treeValue = value this.treeValue = value
} else { } else {
//单选 //单选
this.$emit('select-change', value) this.$emit('change', value)
this.treeValue = value this.treeValue = value
} }
}, },
@@ -307,7 +316,7 @@
//2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 //2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型
model: { model: {
prop: 'value', prop: 'value',
event: 'select-change' event: 'change'
} }
} }
//递归整个树,判断是否是叶子节点----同步获取数据时用到 //递归整个树,判断是否是叶子节点----同步获取数据时用到
+14 -6
View File
@@ -13,7 +13,7 @@
:listType="complistType" :listType="complistType"
@preview="handlePreview" @preview="handlePreview"
v-bind="$attrs" v-bind="$attrs"
v-on="$listeners" v-on="childListeners"
:class="{'uploadty-disabled':disabled}"> :class="{'uploadty-disabled':disabled}">
<template> <template>
<div v-if="isImageComp"> <div v-if="isImageComp">
@@ -125,12 +125,21 @@
} }
}, },
computed:{ computed:{
//透传给下级组件的事件,需要排除本组件使用的change事件
childListeners() {
const vm = this;
let result = Object.assign({},
this.$listeners,
)
delete result.change;
return result;
},
isImageComp(){ isImageComp(){
return this.fileType === FILE_TYPE_IMG return this.fileType === FILE_TYPE_IMG
}, },
complistType(){ complistType(){
return this.fileType === FILE_TYPE_IMG?'picture-card':'text' return this.fileType === FILE_TYPE_IMG?'picture-card':'text'
} },
}, },
created(){ created(){
const token = Vue.ls.get(ACCESS_TOKEN); const token = Vue.ls.get(ACCESS_TOKEN);
@@ -139,7 +148,6 @@
this.containerId = 'container-ty-'+new Date().getTime(); this.containerId = 'container-ty-'+new Date().getTime();
//---------------------------- end 图片左右换位置 ------------------------------------- //---------------------------- end 图片左右换位置 -------------------------------------
}, },
methods:{ methods:{
initFileListArr(val){ initFileListArr(val){
if(!val || val.length==0){ if(!val || val.length==0){
@@ -188,7 +196,7 @@
if(arr.length>0){ if(arr.length>0){
path = arr.join(",") path = arr.join(",")
} }
this.$emit('file-change', path); this.$emit('change', path);
}, },
beforeUpload(file){ beforeUpload(file){
this.uploadGoOn=true this.uploadGoOn=true
@@ -249,7 +257,7 @@
} }
// update-end-author:lvdandan date:20200603 for:【TESTA-514】【开源issue】多个文件同时上传时,控制台报错 // update-end-author:lvdandan date:20200603 for:【TESTA-514】【开源issue】多个文件同时上传时,控制台报错
} }
this.$emit('file-change', this.newFileList); this.$emit('change', this.newFileList);
} }
} }
}, },
@@ -268,7 +276,7 @@
mounted(){}, mounted(){},
model: { model: {
prop: 'value', prop: 'value',
event: 'file-change' event: 'change'
} }
} }
</script> </script>