储能智慧云小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

checkbox.js 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. import { SuperComponent, wxComponent } from '../common/src/index';
  8. import config from '../common/config';
  9. import Props from './props';
  10. const { prefix } = config;
  11. const name = `${prefix}-checkbox`;
  12. let CheckBox = class CheckBox extends SuperComponent {
  13. constructor() {
  14. super(...arguments);
  15. this.externalClasses = [
  16. `${prefix}-class`,
  17. `${prefix}-class-label`,
  18. `${prefix}-class-icon`,
  19. `${prefix}-class-content`,
  20. `${prefix}-class-border`,
  21. ];
  22. this.behaviors = ['wx://form-field'];
  23. this.relations = {
  24. '../checkbox-group/checkbox-group': {
  25. type: 'ancestor',
  26. linked(parent) {
  27. const { value, disabled, borderless } = parent.data;
  28. const valueSet = new Set(value);
  29. const checkedFromParent = valueSet.has(this.data.value);
  30. const data = {
  31. _disabled: this.data.disabled == null ? disabled : this.data.disabled,
  32. };
  33. if (borderless) {
  34. data.borderless = true;
  35. }
  36. data.checked = this.data.checked || checkedFromParent;
  37. if (this.data.checked) {
  38. parent.updateValue(this.data);
  39. }
  40. if (this.data.checkAll) {
  41. data.checked = valueSet.size > 0;
  42. }
  43. this.setData(data);
  44. },
  45. },
  46. };
  47. this.options = {
  48. multipleSlots: true,
  49. };
  50. this.properties = Object.assign(Object.assign({}, Props), { theme: {
  51. type: String,
  52. value: 'default',
  53. } });
  54. this.data = {
  55. prefix,
  56. classPrefix: name,
  57. _disabled: false,
  58. };
  59. this.observers = {
  60. disabled(v) {
  61. this.setData({ _disabled: v });
  62. },
  63. };
  64. this.controlledProps = [
  65. {
  66. key: 'checked',
  67. event: 'change',
  68. },
  69. ];
  70. this.methods = {
  71. handleTap(e) {
  72. const { _disabled, readonly, contentDisabled } = this.data;
  73. const { target } = e.currentTarget.dataset;
  74. if (_disabled || readonly || (target === 'text' && contentDisabled))
  75. return;
  76. const { value, label } = this.data;
  77. const checked = !this.data.checked;
  78. const parent = this.$parent;
  79. if (parent) {
  80. parent.updateValue(Object.assign(Object.assign({}, this.data), { checked }));
  81. }
  82. else {
  83. this._trigger('change', { context: { value, label }, checked });
  84. }
  85. },
  86. setDisabled(disabled) {
  87. this.setData({
  88. _disabled: this.data.disabled || disabled,
  89. });
  90. },
  91. };
  92. }
  93. };
  94. CheckBox = __decorate([
  95. wxComponent()
  96. ], CheckBox);
  97. export default CheckBox;