radio.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 config from '../common/config';
  8. import { SuperComponent, wxComponent } from '../common/src/index';
  9. import Props from './props';
  10. const { prefix } = config;
  11. const name = `${prefix}-radio`;
  12. let Radio = class Radio 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.parent = null;
  24. this.relations = {
  25. '../radio-group/radio-group': {
  26. type: 'ancestor',
  27. linked(parent) {
  28. this.parent = parent;
  29. if (parent.data.align) {
  30. this.setData({ align: parent.data.align });
  31. }
  32. if (parent.data.borderless) {
  33. this.setData({ borderless: true });
  34. }
  35. },
  36. },
  37. };
  38. this.options = {
  39. multipleSlots: true,
  40. };
  41. this.lifetimes = {
  42. attached() {
  43. this.initStatus();
  44. },
  45. };
  46. this.properties = Object.assign(Object.assign({}, Props), { borderless: {
  47. type: Boolean,
  48. value: false,
  49. } });
  50. this.controlledProps = [
  51. {
  52. key: 'checked',
  53. event: 'change',
  54. },
  55. ];
  56. this.data = {
  57. prefix,
  58. classPrefix: name,
  59. customIcon: false,
  60. slotIcon: false,
  61. optionLinked: false,
  62. iconVal: [],
  63. };
  64. this.methods = {
  65. handleTap(e) {
  66. if (this.data.disabled)
  67. return;
  68. const { target } = e.currentTarget.dataset;
  69. if (target === 'text' && this.data.contentDisabled)
  70. return;
  71. this.doChange();
  72. },
  73. doChange() {
  74. const { value, checked } = this.data;
  75. if (this.$parent) {
  76. this.$parent.updateValue(value);
  77. }
  78. else {
  79. this._trigger('change', { checked: !checked });
  80. }
  81. },
  82. initStatus() {
  83. var _a, _b;
  84. const { icon } = this.data;
  85. const isIdArr = Array.isArray(((_a = this.parent) === null || _a === void 0 ? void 0 : _a.icon) || icon);
  86. this.setData({
  87. customIcon: isIdArr,
  88. slotIcon: icon === 'slot',
  89. iconVal: isIdArr ? ((_b = this.parent) === null || _b === void 0 ? void 0 : _b.icon) || icon : [],
  90. });
  91. },
  92. setDisabled(disabled) {
  93. this.setData({
  94. disabled: this.data.disabled || disabled,
  95. });
  96. },
  97. };
  98. }
  99. };
  100. Radio = __decorate([
  101. wxComponent()
  102. ], Radio);
  103. export default Radio;