1 |
- import eventBus from"../utils/eventBus";Component({externalClasses:["l-class","l-error-text","l-error-text-class"],behaviors:["wx://form-field"],relations:{"../radio/index":{type:"child",linked(){this.init()},linkChanged(){},unlinked(){this.init()}}},properties:{current:{type:String},noneChecked:{type:Boolean,value:!0},placement:{type:String,value:"column"}},data:{currentLength:0},methods:{checkedKeyRepeat(e){let t=e.map(e=>e.data.key);const n=this.isRepeat(t);if(!1!==n)throw new Error(`keys有重复元素, radio的key属性不能重复:${n}`)},isRepeat(e){let t={};for(let n in e){if(t[e[n]])return e[n];t[e[n]]=!0}return!1},init(){const e=this.getRelationNodes("../radio/index");this.checkedKeyRepeat(e),this.onChangeHandle(e)},onChangeHandle(e){e.forEach(e=>{let t=this.properties.current==e.data.key;e.setChecked(t,e.data.key)})},onEmitEventHandle(e,t){this.properties.current=t?e.key:null;const n=this.getRelationNodes("../radio/index");this.onChangeHandle(n),Object.assign(e,{currentKey:this.properties.current}),this.triggerEvent("linchange",e,{bubbles:!0,composed:!0}),eventBus.emit(`lin-form-change-${this.id}`,this.id)},getValues(){return this.data.current},reset(){this.data.current=""}},observers:{current:function(){this.init()}}});
|