index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var relation_1 = require('../common/relation');
  4. var component_1 = require('../common/component');
  5. function emit(target, value) {
  6. target.$emit('input', value);
  7. target.$emit('change', value);
  8. }
  9. component_1.VantComponent({
  10. field: true,
  11. relation: relation_1.useParent('checkbox-group'),
  12. classes: ['icon-class', 'label-class'],
  13. props: {
  14. value: Boolean,
  15. disabled: Boolean,
  16. useIconSlot: Boolean,
  17. checkedColor: String,
  18. labelPosition: {
  19. type: String,
  20. value: 'right',
  21. },
  22. labelDisabled: Boolean,
  23. shape: {
  24. type: String,
  25. value: 'round',
  26. },
  27. iconSize: {
  28. type: null,
  29. value: 20,
  30. },
  31. },
  32. data: {
  33. parentDisabled: false,
  34. },
  35. methods: {
  36. emitChange: function (value) {
  37. if (this.parent) {
  38. this.setParentValue(this.parent, value);
  39. } else {
  40. emit(this, value);
  41. }
  42. },
  43. toggle: function () {
  44. var _a = this.data,
  45. parentDisabled = _a.parentDisabled,
  46. disabled = _a.disabled,
  47. value = _a.value;
  48. if (!disabled && !parentDisabled) {
  49. this.emitChange(!value);
  50. }
  51. },
  52. onClickLabel: function () {
  53. var _a = this.data,
  54. labelDisabled = _a.labelDisabled,
  55. parentDisabled = _a.parentDisabled,
  56. disabled = _a.disabled,
  57. value = _a.value;
  58. if (!disabled && !labelDisabled && !parentDisabled) {
  59. this.emitChange(!value);
  60. }
  61. },
  62. setParentValue: function (parent, value) {
  63. var parentValue = parent.data.value.slice();
  64. var name = this.data.name;
  65. var max = parent.data.max;
  66. if (value) {
  67. if (max && parentValue.length >= max) {
  68. return;
  69. }
  70. if (parentValue.indexOf(name) === -1) {
  71. parentValue.push(name);
  72. emit(parent, parentValue);
  73. }
  74. } else {
  75. var index = parentValue.indexOf(name);
  76. if (index !== -1) {
  77. parentValue.splice(index, 1);
  78. emit(parent, parentValue);
  79. }
  80. }
  81. },
  82. },
  83. });