合伙人运营小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

radio.js 4.0KB

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.init();
  39. },
  40. };
  41. this.properties = Object.assign(Object.assign({}, Props), { borderless: {
  42. type: Boolean,
  43. value: false,
  44. } });
  45. this.controlledProps = [
  46. {
  47. key: 'checked',
  48. event: 'change',
  49. },
  50. ];
  51. this.data = {
  52. prefix,
  53. classPrefix: name,
  54. customIcon: false,
  55. slotIcon: false,
  56. optionLinked: false,
  57. iconVal: [],
  58. _placement: '',
  59. _disabled: false,
  60. };
  61. this.observers = {
  62. disabled(v) {
  63. this.setData({ _disabled: v });
  64. },
  65. };
  66. this.methods = {
  67. handleTap(e) {
  68. const { _disabled, readonly, contentDisabled } = this.data;
  69. const { target } = e.currentTarget.dataset;
  70. if (_disabled || readonly || (target === 'text' && contentDisabled))
  71. return;
  72. this.doChange();
  73. },
  74. doChange() {
  75. const { value, checked, allowUncheck } = this.data;
  76. if (this.$parent) {
  77. this.$parent.updateValue(checked && allowUncheck ? null : value);
  78. }
  79. else {
  80. this._trigger('change', { checked: checked && allowUncheck ? false : !checked });
  81. }
  82. },
  83. init() {
  84. var _a, _b, _c, _d, _e, _f;
  85. const { icon } = this.data;
  86. const isIdArr = Array.isArray(((_a = this.$parent) === null || _a === void 0 ? void 0 : _a.icon) || icon);
  87. this.setData({
  88. customIcon: isIdArr,
  89. slotIcon: icon === 'slot',
  90. iconVal: isIdArr ? ((_b = this.$parent) === null || _b === void 0 ? void 0 : _b.icon) || icon : [],
  91. _placement: (_f = (_c = this.data.placement) !== null && _c !== void 0 ? _c : (_e = (_d = this.$parent) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.placement) !== null && _f !== void 0 ? _f : 'left',
  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;