UNPKG

wx-mini-weview

Version:

weixin UI

113 lines (104 loc) 2.54 kB
const { WvInheritable } = require('../../behaviors/WvInheritable'); Component({ options: { styleIsolation: 'apply-shared', addGlobalClass: true }, externalClasses: ['ext-class'], behaviors: [ WvInheritable({ properties: { // Item index (assigned by parent) index: { type: Number, value: -1 }, // Item value value: { type: null, value: null }, // Disabled state disabled: { type: Boolean, value: false }, // Selection theme theme: { type: String, value: 'wv-theme-primary wv-content-light' }, // Selected state selected: { type: Boolean, value: false }, // 选中状态的表现形式: 'scale', 'border', 'none' selectionType: { type: String, value: 'none' }, // Show checkmark checkmark: { type: Boolean, value: true }, // Checkmark position checkmarkPosition: { type: String, value: 'top-right' }, // Checkmark size checkmarkSize: { type: String, value: '60rpx' }, // Scale size when selected scaleSize: { type: String, value: '1.06' } }, childrenProperties: {} }) ], relations: { '../selector/selector': { type: 'parent', linked(target) { this.linkParentNode('selector', target); }, unlinked() { this.unlinkParentNode('selector'); } } }, lifetimes: { attached() { if (this.data.wvInheritableApply.value === null || this.data.wvInheritableApply.value === undefined) { this.setInheritedProps({ value: this.data.wvInheritableApply.index }); } } }, methods: { /** * Handle item tap */ onTap() { if (this.data.wvInheritableApply.disabled) return; // Notify parent using toggle method const parentSelector = this.getParentNode('selector'); if (parentSelector) { parentSelector.toggle(this.data.wvInheritableApply.index); } // Trigger tap event this.triggerEvent('itemtap', { value: this.data.wvInheritableApply.value, index: this.data.wvInheritableApply.index, selected: this.data.wvInheritableApply.selected }); } } });