radio.js 3.8 KB

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