index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const prefixCls = 'i-checkbox';
  2. Component({
  3. externalClasses: ['i-class'],
  4. relations: {
  5. '../checkbox-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. },
  32. data: {
  33. checked: true,
  34. positionCls: `${prefixCls}-checkbox-left`,
  35. },
  36. attached() {
  37. this.setPosition();
  38. },
  39. methods: {
  40. changeCurrent(current) {
  41. this.setData({ checked: current });
  42. },
  43. checkboxChange() {
  44. if (this.data.disabled) return;
  45. const item = { current: !this.data.checked, value: this.data.value };
  46. const parent = this.getRelationNodes('../checkbox-group/index')[0];
  47. parent ? parent.emitEvent(item) : this.triggerEvent('change', item);
  48. },
  49. setPosition() {
  50. this.setData({
  51. positionCls: this.data.position.indexOf('left') !== -1 ? `${prefixCls}-checkbox-left` : `${prefixCls}-checkbox-right`,
  52. });
  53. }
  54. }
  55. });