dingtalk-design-miniapp
Version:
DingTalk Design Miniapp 提供统一钉钉风格小程序组件
60 lines (59 loc) • 1.34 kB
JavaScript
"use strict";
Component({
mixins: [],
data: {
$uiName: 'switch',
_checked: false
},
props: {
style: '',
className: '',
checked: false,
disabled: false,
isControlled: false,
data: null,
onChange: null
},
didMount: function didMount() {
this.setData({
_checked: this.props.checked
});
},
didUpdate: function didUpdate(prevProps, prevData) {
if (prevProps.checked !== this.props.checked && this.props.checked !== this.data._checked) {
this.setData({
_checked: this.props.checked
});
}
},
didUnmount: function didUnmount() {},
methods: {
onTap: function onTap(e) {
var _this$props = this.props,
disabled = _this$props.disabled,
isControlled = _this$props.isControlled,
onDmChange = _this$props.onDmChange,
onChange = _this$props.onChange,
data = _this$props.data,
dmData = _this$props.dmData;
if (disabled) {
return;
}
var checked = this.data._checked;
if (!isControlled) {
checked = !checked;
this.setData({
_checked: checked
});
}
if (onChange) {
onChange(checked, data);
return;
}
onDmChange && onDmChange({
checked: checked,
dmData: dmData
});
}
}
});