index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const prefixCls = 'i-radio';
  2. Component({
  3. externalClasses: ['i-class'],
  4. relations: {
  5. '../radio-group/index': {
  6. type: 'parent'
  7. }
  8. },
  9. properties: {
  10. value: {
  11. type: String,
  12. value: ''
  13. },
  14. checked: {
  15. type: Boolean,
  16. value: false
  17. },
  18. disabled: {
  19. type: Boolean,
  20. value: false
  21. },
  22. color: {
  23. type: String,
  24. value: '#2d8cf0'
  25. },
  26. position: {
  27. type: String,
  28. value: 'left', //left right
  29. observer: 'setPosition'
  30. },
  31. setClass: {
  32. type: Boolean,
  33. value: false
  34. }
  35. },
  36. data: {
  37. checked: true,
  38. positionCls: `${prefixCls}-radio-left`,
  39. },
  40. attached() {
  41. this.setPosition();
  42. },
  43. methods: {
  44. changeCurrent(current) {
  45. this.setData({ checked: current });
  46. },
  47. radioChange() {
  48. if (this.data.disabled) return;
  49. const item = { current: !this.data.checked, value: this.data.value };
  50. const parent = this.getRelationNodes('../radio-group/index')[0];
  51. parent ? parent.emitEvent(item) : this.triggerEvent('change', item);
  52. },
  53. setPosition() {
  54. this.setData({
  55. positionCls: this.data.position.indexOf('left') !== -1 ? `${prefixCls}-radio-left` : `${prefixCls}-radio-right`,
  56. });
  57. }
  58. }
  59. });