-
-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
1,211 additions
and
949 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,98 @@ | ||
import rules from '../behaviors/rules'; | ||
|
||
Component({ | ||
behaviors: ['wx://form-field', rules], | ||
behaviors: ['wx://form-field'], | ||
externalClasses: ['l-class', 'l-error-text', 'l-error-text-class'], | ||
relations: { | ||
'../checkbox/index': { | ||
type: 'child', | ||
// linked() { | ||
// this.onChangeHandle(); | ||
// }, | ||
// linkChanged() { | ||
// this.onChangeHandle(); | ||
// }, | ||
// unlinked() { | ||
// this.onChangeHandle(); | ||
// } | ||
linked(target) { | ||
this.init(target); | ||
}, | ||
linkChanged() { | ||
}, | ||
unlinked() { | ||
// this.init(target); | ||
} | ||
} | ||
}, | ||
properties: { | ||
current: { | ||
type: Array, | ||
value: [], | ||
observer: 'onChangeHandle' | ||
}, | ||
// 选项的排列方式 一行显示 or 多行显示 | ||
placement: { | ||
type: String, | ||
value: 'column', //column row | ||
}, | ||
// 最多选中值 | ||
maxSelected: { | ||
type: [Number,null], | ||
value: null | ||
}, | ||
minSelected: { | ||
type: [Number,null], | ||
value: null | ||
} | ||
}, | ||
data: { | ||
value: [], | ||
list: [], | ||
length: null | ||
}, | ||
attached() { | ||
this.initRules(); | ||
}, | ||
ready() { | ||
const len = this.items().length; | ||
this.data.length = len; | ||
this.setData({ | ||
length: len | ||
}); | ||
this.onChangeHandle(); | ||
|
||
let { minSelected, maxSelected} = this.properties; | ||
this.checkMax(minSelected, maxSelected); | ||
}, | ||
methods: { | ||
items() { | ||
let items = this.getRelationNodes('../checkbox/index'); | ||
return items; | ||
|
||
init(target) { | ||
if(this._keys === undefined) this._keys = {}; | ||
if(this._selected === undefined) this._selected = {}; | ||
this.checkDefaultItem(target); | ||
this.checkedKeyRepeat(target); | ||
}, | ||
// checkbox change | ||
onChangeHandle(val = this.data.current) { | ||
let items = this.getRelationNodes('../checkbox/index'); | ||
const len = items.length; | ||
if (len === this.data.length) { | ||
items.forEach(item => { | ||
let type = val.indexOf(item.data.value) !== -1; | ||
item.onChangeHandle(type, 'init'); | ||
}); | ||
|
||
checkedKeyRepeat(target) { | ||
let { key } = target.properties; | ||
if(this._keys[key]) { | ||
throw new Error(`keys有重复元素, chekbox的key属性不能重复:${key}`); | ||
} else { | ||
this._keys[key] = true; | ||
} | ||
}, | ||
currentChange(val) { | ||
|
||
// const index = this.data.current.indexOf(val.value) | ||
this.data.list.push(val); | ||
this.setData({ | ||
value: this.data.list | ||
}); | ||
checkDefaultItem(target) { | ||
const { key, checked } = target.properties; | ||
if(checked) { | ||
this._selected[key] = checked; | ||
} | ||
}, | ||
|
||
onEmitEventHandle(current) { | ||
checkMax(min, max) { | ||
if(min !== null && min < 0) { | ||
throw new Error('最小选择个数必须大于等于0'); | ||
} | ||
if(max !== null && max < 0) { | ||
throw new Error('最多选择个数必须大于0'); | ||
} | ||
if(max !== null && min !== null && min >= max) { | ||
throw new Error('最多选择个数必须大于最小选择个数'); | ||
} | ||
}, | ||
|
||
const index = this.data.current.indexOf(current.value); | ||
index === -1 ? this.data.current.push(current.value) : this.data.current.splice(index, 1); | ||
index === -1 ? this.data.list.push(current) : this.data.list.splice(index, 1); | ||
this.setData({ | ||
current: this.data.current | ||
}, () => { | ||
this.validatorData({ | ||
value: this.data.value | ||
}); | ||
}); | ||
onEmitEventHandle(currentItem) { | ||
currentItem.checked ? this.addSelect(currentItem.key):this.removeSelect(currentItem.key); | ||
|
||
const all = JSON.parse(JSON.stringify(this.data.list)); | ||
for (let i = 0; i < all.length; i++) { | ||
delete all[i].all; | ||
} | ||
current.all = all; | ||
this.setData({ | ||
value: all | ||
this.triggerEvent('linchange', currentItem, { | ||
bubbles: true, | ||
composed: true | ||
}); | ||
this.triggerEvent('linchange', current); | ||
}, | ||
onEmitOverflowHandle(data){ | ||
this.triggerEvent('linout', data, { | ||
bubbles: true, | ||
composed: true | ||
}); | ||
}, | ||
removeSelect(key) { | ||
delete this._selected[key]; | ||
}, | ||
addSelect(key) { | ||
this._selected[key] = key; | ||
} | ||
|
||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"component": true, | ||
"usingComponents": { | ||
"l-error-tip":"../error-tip/index" | ||
"l-error-tip":"../error-tip/index", | ||
"l-checkbox": "../checkbox/index" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<view class="l-class checkbox-group-{{placement}}"> | ||
<slot></slot> | ||
<view class="l-class checkbox-group checkbox-group-{{placement}} "> | ||
<slot></slot> | ||
</view> | ||
<l-error-tip l-error-text-class="l-error-text l-error-text-class" errorText="{{errorText}}" wx:if="{{errorText}}"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
.checkbox-group-row{display:flex;flex-direction:row}.checkbox-group-column{display:flex;flex-direction:column} | ||
.checkbox-group{flex-wrap:wrap}.checkbox-group-row{display:flex;flex-direction:row}.checkbox-group-column{display:flex;flex-direction:column} |
Oops, something went wrong.