八个组件的props透传,事件向上暴露

This commit is contained in:
yaoyanan
2021-04-07 17:57:14 +08:00
parent 53a032bc97
commit 139fe266e1
12 changed files with 108 additions and 57 deletions
@@ -254,7 +254,7 @@
//2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 这个牛逼 //2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 这个牛逼
model: { model: {
prop: 'value', prop: 'value',
event: 'change' event: 'select-change'
} }
} }
</script> </script>
+13 -5
View File
@@ -10,6 +10,8 @@
:value="momVal" :value="momVal"
:showTime="true" :showTime="true"
:format="dateFormat" :format="dateFormat"
v-bind="$attrs"
v-on="$listeners"
:getCalendarContainer="getCalendarContainer"> :getCalendarContainer="getCalendarContainer">
</a-date-picker> </a-date-picker>
<!--YYYY-MM-DD--> <!--YYYY-MM-DD-->
@@ -22,6 +24,8 @@
:value="momVal" :value="momVal"
:showTime="false" :showTime="false"
:format="dateFormat" :format="dateFormat"
v-bind="$attrs"
v-on="$listeners"
:getCalendarContainer="getCalendarContainer"> :getCalendarContainer="getCalendarContainer">
</a-date-picker> </a-date-picker>
<!--YYYY-MM--> <!--YYYY-MM-->
@@ -31,6 +35,8 @@
:value="momVal" :value="momVal"
:disabled="disabled || readOnly" :disabled="disabled || readOnly"
:format="dateFormat" :format="dateFormat"
v-bind="$attrs"
v-on="$listeners"
@change="handleMonthChange"> @change="handleMonthChange">
</a-month-picker> </a-month-picker>
<!--YYYY--> <!--YYYY-->
@@ -42,6 +48,8 @@
:value="year" :value="year"
:disabled="disabled || readOnly" :disabled="disabled || readOnly"
:open="yearShowOne" :open="yearShowOne"
v-bind="$attrs"
v-on="$listeners"
:getCalendarContainer="getCalendarContainer" :getCalendarContainer="getCalendarContainer"
@openChange="openChangeOne" @openChange="openChangeOne"
@panelChange="panelChangeOne"> @panelChange="panelChangeOne">
@@ -55,7 +63,7 @@
props: { props: {
placeholder:{ placeholder:{
type: String, type: String,
default: '', default: '请选择',
required: false required: false
}, },
value:{ value:{
@@ -108,10 +116,10 @@
methods: { methods: {
moment, moment,
handleDateChange(mom,dateStr){ handleDateChange(mom,dateStr){
this.$emit('change', dateStr); this.$emit('date-change', dateStr);
}, },
handleMonthChange(mom,dateStr){ handleMonthChange(mom,dateStr){
this.$emit('change',dateStr) this.$emit('date-change',dateStr)
}, },
/** /**
* 弹出日历和关闭日历的回调 * 弹出日历和关闭日历的回调
@@ -125,13 +133,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('change',year) this.$emit('date-change',year)
} }
}, },
//2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 //2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型
model: { model: {
prop: 'value', prop: 'value',
event: 'change' event: 'date-change'
} }
} }
</script> </script>
+9 -1
View File
@@ -1,5 +1,8 @@
<template> <template>
<a-tooltip placement="topLeft"> <a-tooltip
placement="topLeft"
v-bind="$attrs"
v-on="$listeners">
<template slot="title"> <template slot="title">
<span>{{value}}</span> <span>{{value}}</span>
</template> </template>
@@ -20,6 +23,11 @@
required: false, required: false,
default: 25, default: 25,
} }
},
//在定义组件时,指定父组件调用时候的传值属性(prop)和事件类型(event),事件名称要和$emit传的一致
model:{
prop:'value',
event:'change'
} }
} }
</script> </script>
@@ -12,6 +12,8 @@
:disabled="disabled" :disabled="disabled"
:isMultiple="isMultiple" :isMultiple="isMultiple"
:showUploadList="isMultiple" :showUploadList="isMultiple"
v-bind="$attrs"
v-on="$listeners"
@change="handleChange" @change="handleChange"
@preview="handlePreview" @preview="handlePreview"
:class="!isMultiple?'imgupload':''"> :class="!isMultiple?'imgupload':''">
@@ -48,7 +50,7 @@
name: 'JImageUpload', name: 'JImageUpload',
data(){ data(){
return { return {
uploadAction:window._CONFIG['domianURL']+"/sys/common/upload", uploadAction:window._CONFIG['domianURL'] + '/sys/common/upload',
uploadLoading:false, uploadLoading:false,
picUrl:false, picUrl:false,
headers:{}, headers:{},
@@ -108,6 +110,7 @@
} }
}, },
created(){ created(){
console.log(window._CONFIG['domianURL'] + '/sys/common/upload')
const token = Vue.ls.get(ACCESS_TOKEN); const token = Vue.ls.get(ACCESS_TOKEN);
this.headers = {"X-Access-Token":token} this.headers = {"X-Access-Token":token}
}, },
@@ -205,7 +208,7 @@
if(arr.length>0){ if(arr.length>0){
path = arr.join(",") path = arr.join(",")
} }
this.$emit('change', path); this.$emit('image-change', path);
}, },
handleDelete(file){ handleDelete(file){
//如有需要新增 删除逻辑 //如有需要新增 删除逻辑
@@ -221,7 +224,7 @@
}, },
model: { model: {
prop: 'value', prop: 'value',
event: 'change' event: 'image-change'
} }
} }
</script> </script>
@@ -12,6 +12,8 @@
accept=".xls,.xlsx" accept=".xls,.xlsx"
:fileList="fileList" :fileList="fileList"
:remove="handleRemove" :remove="handleRemove"
v-bind="$attrs"
v-on="$listeners"
:beforeUpload="beforeUpload"> :beforeUpload="beforeUpload">
<a-button> <a-button>
<a-icon type="upload" /> <a-icon type="upload" />
@@ -43,6 +45,11 @@
default: '', default: '',
required: false required: false
}, },
visible:{
type: Boolean,
default: '',
required: false
},
biz:{ biz:{
type: String, type: String,
default: '', default: '',
@@ -51,7 +58,6 @@
}, },
data(){ data(){
return { return {
visible:false,
uploading:false, uploading:false,
fileList:[], fileList:[],
uploadAction:'', uploadAction:'',
@@ -66,9 +72,9 @@
} }
}, },
created () { created () {
console.log(this.$attrs)
this.uploadAction = window._CONFIG['domianURL']+this.url this.uploadAction = window._CONFIG['domianURL']+this.url
}, },
methods:{ methods:{
handleClose(){ handleClose(){
this.visible=false this.visible=false
@@ -5,6 +5,8 @@
: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"
@@ -74,25 +76,6 @@
this.newOptions = this.options this.newOptions = this.options
}, },
methods:{ methods:{
// search(val){
// let newArr = []
// this.newOptions = this.options
// if (this.options && this.options.length > 0){
// this.options.forEach((item,index)=>{
// if (item.text.indexOf(val) != -1){
// newArr.push(item)
// }
// })
// this.$nextTick(()=>{
// this.newOptions = newArr
// })
// }else {
// this.newOptions = this.options
// }
// },
// blur(){
// this.newOptions = this.options
// },
onChange (selectedValue) { onChange (selectedValue) {
this.newOptions = this.options this.newOptions = this.options
if(this.triggerChange){ if(this.triggerChange){
@@ -109,6 +92,5 @@
} }
} }
}, },
} }
</script> </script>
+16 -5
View File
@@ -1,11 +1,22 @@
<template> <template>
<div> <div>
<a-select v-if="query" style="width: 100%" @change="handleSelectChange"> <a-select
v-if="query"
style="width: 100%"
@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>
</a-select> </a-select>
<a-switch v-else v-model="checkStatus" :disabled="disabled" @change="handleChange"/> <a-switch
v-else
v-model="checkStatus"
:disabled="disabled"
@change="handleChange"
v-bind="$attrs"
v-on="$listeners"/>
</div> </div>
</template> </template>
<script> <script>
@@ -69,15 +80,15 @@
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('change', flag); this.$emit('check-change', flag);
}, },
handleSelectChange(value){ handleSelectChange(value){
this.$emit('change', value); this.$emit('check-change', value);
} }
}, },
model: { model: {
prop: 'value', prop: 'value',
event: 'change' event: 'check-change'
} }
} }
</script> </script>
+4 -2
View File
@@ -4,6 +4,8 @@
:placeholder="placeholder" :placeholder="placeholder"
:value="momVal" :value="momVal"
:format="dateFormat" :format="dateFormat"
v-bind="$attrs"
v-on="$listeners"
:getCalendarContainer="getCalendarContainer" :getCalendarContainer="getCalendarContainer"
@change="handleTimeChange"/> @change="handleTimeChange"/>
</template> </template>
@@ -61,13 +63,13 @@
methods: { methods: {
moment, moment,
handleTimeChange(mom,timeStr){ handleTimeChange(mom,timeStr){
this.$emit('change', timeStr); this.$emit('time-change', timeStr);
} }
}, },
//2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 这个牛逼 //2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 这个牛逼
model: { model: {
prop: 'value', prop: 'value',
event: 'change' event: 'time-change'
} }
} }
</script> </script>
+1 -1
View File
@@ -101,7 +101,7 @@
}, },
model: { model: {
prop: 'value', prop: 'value',
event: 'change' event: 'select-change'
}, },
methods:{ methods:{
loadViewInfo(){ loadViewInfo(){
+4 -4
View File
@@ -281,13 +281,13 @@
return this.treeData return this.treeData
}, },
validateProp(){ validateProp(){
let mycondition = this.condition let myCondition = this.condition
return new Promise((resolve,reject)=>{ return new Promise((resolve,reject)=>{
if(!mycondition){ if(!myCondition){
resolve(); resolve();
}else{ }else{
try { try {
let test=JSON.parse(mycondition); let test=JSON.parse(myCondition);
if(typeof test == 'object' && test){ if(typeof test == 'object' && test){
resolve() resolve()
}else{ }else{
@@ -305,7 +305,7 @@
//2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 //2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型
model: { model: {
prop: 'value', prop: 'value',
event: 'change' event: 'select-change'
} }
} }
//递归整个树,判断是否是叶子节点----同步获取数据时用到 //递归整个树,判断是否是叶子节点----同步获取数据时用到
+8 -6
View File
@@ -12,7 +12,6 @@
<a-upload <a-upload
name="file" name="file"
:multiple="true"
:action="uploadAction" :action="uploadAction"
:headers="headers" :headers="headers"
:data="{'biz':bizPath}" :data="{'biz':bizPath}"
@@ -23,6 +22,8 @@
:returnUrl="returnUrl" :returnUrl="returnUrl"
:listType="complistType" :listType="complistType"
@preview="handlePreview" @preview="handlePreview"
v-bind="$attrs"
v-on="$listeners"
:class="{'uploadty-disabled':disabled}"> :class="{'uploadty-disabled':disabled}">
<template> <template>
<div v-if="isImageComp"> <div v-if="isImageComp">
@@ -162,6 +163,7 @@
} }
}, },
created(){ created(){
console.log(this.$attrs)
const token = Vue.ls.get(ACCESS_TOKEN); const token = Vue.ls.get(ACCESS_TOKEN);
//---------------------------- begin 图片左右换位置 ------------------------------------- //---------------------------- begin 图片左右换位置 -------------------------------------
this.headers = {"X-Access-Token":token}; this.headers = {"X-Access-Token":token};
@@ -236,7 +238,7 @@
if(arr.length>0){ if(arr.length>0){
path = arr.join(",") path = arr.join(",")
} }
this.$emit('change', path); this.$emit('file-change', path);
}, },
beforeUpload(file){ beforeUpload(file){
this.uploadGoOn=true this.uploadGoOn=true
@@ -298,7 +300,7 @@
} }
// update-end-author:lvdandan date:20200603 for:【TESTA-514】【开源issue】多个文件同时上传时,控制台报错 // update-end-author:lvdandan date:20200603 for:【TESTA-514】【开源issue】多个文件同时上传时,控制台报错
} }
this.$emit('change', this.newFileList); this.$emit('file-change', this.newFileList);
} }
} }
}, },
@@ -339,7 +341,7 @@
} }
} }
this.currentImg = last this.currentImg = last
this.$emit('change',arr.join(',')) this.$emit('file-change',arr.join(','))
} }
}, },
moveNext(){ moveNext(){
@@ -360,7 +362,7 @@
} }
} }
this.currentImg = next this.currentImg = next
this.$emit('change',arr.join(',')) this.$emit('file-change',arr.join(','))
} }
}, },
getIndexByUrl(){ getIndexByUrl(){
@@ -420,7 +422,7 @@
}, },
model: { model: {
prop: 'value', prop: 'value',
event: 'change' event: 'file-change'
} }
} }
</script> </script>
+36 -7
View File
@@ -158,7 +158,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-date v-model="jdate.value" :showType="'year'" dateFormat="YYYY"/> <j-date v-model="jdate.value" :showType="'time'" dateFormat="YYYY-MM-DD HH:mm:ss"/>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :span="12">日期选择框(v-model){{ jdate.value }}</a-col> <a-col :span="12">日期选择框(v-model){{ jdate.value }}</a-col>
@@ -178,7 +178,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-ellipsis :value="jellipsis.value" :length="30"/> <j-ellipsis :value="jellipsis.value" :length="20" @text-change="selectChange"/>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :span="12">过长剪切:{{ jellipsis.value }}</a-col> <a-col :span="12">过长剪切:{{ jellipsis.value }}</a-col>
@@ -198,7 +198,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-select-multiple v-model="jselectMultiple.value" :options="jselectMultiple.options"/> <j-select-multiple v-model="jselectMultiple.value" :options="jselectMultiple.options" @change="selectChange"/>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :span="12">多选下拉框(v-model){{ jselectMultiple.value }}</a-col> <a-col :span="12">多选下拉框(v-model){{ jselectMultiple.value }}</a-col>
@@ -328,11 +328,10 @@
</a-form-item> </a-form-item>
</a-col> </a-col>
</a-row> </a-row>
<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-image-upload v-model="imgList"></j-image-upload> <j-image-upload v-model="imgList" title="22"></j-image-upload>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :span="12">选中的值(v-model){{ imgList }}</a-col> <a-col :span="12">选中的值(v-model){{ imgList }}</a-col>
@@ -340,7 +339,7 @@
<a-row :gutter="24" style="margin-top: 65px;margin-bottom:50px;"> <a-row :gutter="24" style="margin-top: 65px;margin-bottom:50px;">
<a-col :span="12"> <a-col :span="12">
<a-form-item label="文件上传"> <a-form-item label="文件上传">
<j-upload v-model="fileList"></j-upload> <j-upload v-model="fileList" title="ddd" :multiple="true"></j-upload>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :span="12"> <a-col :span="12">
@@ -417,6 +416,23 @@
<a-col :span="12">选择的值(v-model){{ formData.jPopup }}</a-col> <a-col :span="12">选择的值(v-model){{ formData.jPopup }}</a-col>
</a-row> </a-row>
<a-row :gutter="24">
<a-col :span="12">
<a-form-item label="JSwitch示例">
<j-switch v-model="formData.sw"></j-switch>
</a-form-item>
</a-col>
<a-col :span="12">选择的值(v-model){{ formData.sw }}</a-col>
</a-row>
<a-row :gutter="24">
<a-col :span="12">
<a-form-item label="JTime示例">
<j-time v-model="formData.mm"></j-time>
</a-form-item>
</a-col>
<a-col :span="12">选择的值(v-model){{ formData.mm }}</a-col>
</a-row>
</a-form> </a-form>
</div> </div>
@@ -449,6 +465,9 @@
import JAreaLinkage from '@comp/jero/JAreaLinkage' import JAreaLinkage from '@comp/jero/JAreaLinkage'
import JMarkdownEditor from '@/components/jero/JMarkdownEditor/index' import JMarkdownEditor from '@/components/jero/JMarkdownEditor/index'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag' import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import JSwitch from '@/components/jero/JSwitch.vue'
import JImportModal from '@/components/jero/JImportModal.vue'
import JTime from '@/components/jero/JTime.vue'
export default { export default {
name: 'SelectDemo', name: 'SelectDemo',
@@ -470,10 +489,14 @@
JCodeEditor, JCodeEditor,
JDate, JEditor, JEllipsis, JSlider, JSelectMultiple, JDate, JEditor, JEllipsis, JSlider, JSelectMultiple,
JCron, JTreeSelect, JSuperQuery, JMultiSelectTag, JCron, JTreeSelect, JSuperQuery, JMultiSelectTag,
JSearchSelectTag JSearchSelectTag,
JSwitch,
JImportModal,
JTime
}, },
data() { data() {
return { return {
ss:false,
selectList: [], selectList: [],
selectedDepUsers: '', selectedDepUsers: '',
formData: { formData: {
@@ -589,6 +612,12 @@ sayHi('hello, world!')`
} }
}, },
methods: { methods: {
as(){
this.ss = true
},
selectChange(){
console.log("ok")
},
getDepartIdValue() { getDepartIdValue() {
return this.form.getFieldValue('departId') return this.form.getFieldValue('departId')
}, },