Explorar el Código

多选 兼容名称

lincl hace 1 año
padre
commit
0e33531f72
Se han modificado 2 ficheros con 36 adiciones y 4 borrados
  1. 25 4
      src/components/Form/form.vue
  2. 11 0
      src/components/Form/index.vue

+ 25 - 4
src/components/Form/form.vue

@ -144,10 +144,31 @@ export default {
		},
		onSelChange(value, item){
			if(item.onChange){
				var exist = _.filter(item.optionList, (v)=>{
					return v.value == value
				})
				item.onChange(exist)
				if(item.multiple){
					if(item.valueName.length < value.length){
						var exist = _.find(item.optionList, (v)=>{
							return v.value == value[value.length - 1]
						})
						item.valueName.push(exist.label)
					} else {
						if(value.length == 0){
							item.valueName = []
						} else {
							_.each(item._value_bak, (v, i)=>{
								if(value.indexOf(v) === -1){
									item.valueName.splice(i, 1)
								}
							})
						}
					}
					item._value_bak = _.assign([], value)
					item.onChange(value, item.valueName)
				} else {
					var exist = _.filter(item.optionList, (v)=>{
						return v.value == value
					})
					item.onChange(exist)
				}
			}
		},
		onCheckboxChange(values, item){

+ 11 - 0
src/components/Form/index.vue

@ -105,6 +105,9 @@ export default {
				form[v.id] = v.value||v.value===0||v.value===false? v.value :  v.type=='checkbox'? [] :""
				rules[v.id] = this.setRule(v)
			}
			if(v.type=='select' && v.multiple){
				v._value_bak = _.assign([], form[v.id])
			}
		});
		this.form = form
		this.rules = rules
@ -184,8 +187,16 @@ export default {
			})
		},
		setValues(model){
			var exist
			for(var k in model){
				this.form[k] = model[k]
				exist = _.find(this.configs.fields, v=>{
					return v.id == k
				})
				if(exist && exist.type=='select' && exist.multiple){
					exist._value_bak = _.assign([], this.form[exist.id])
				}
			}
		},
		setValue(id, value){