index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. direction: 'vertical',
  35. },
  36. methods: {
  37. emitChange: function (value) {
  38. if (this.parent) {
  39. this.setParentValue(this.parent, value);
  40. } else {
  41. emit(this, value);
  42. }
  43. },
  44. toggle: function () {
  45. var _a = this.data,
  46. parentDisabled = _a.parentDisabled,
  47. disabled = _a.disabled,
  48. value = _a.value;
  49. if (!disabled && !parentDisabled) {
  50. this.emitChange(!value);
  51. }
  52. },
  53. onClickLabel: function () {
  54. var _a = this.data,
  55. labelDisabled = _a.labelDisabled,
  56. parentDisabled = _a.parentDisabled,
  57. disabled = _a.disabled,
  58. value = _a.value;
  59. if (!disabled && !labelDisabled && !parentDisabled) {
  60. this.emitChange(!value);
  61. }
  62. },
  63. setParentValue: function (parent, value) {
  64. var parentValue = parent.data.value.slice();
  65. var name = this.data.name;
  66. var max = parent.data.max;
  67. if (value) {
  68. if (max && parentValue.length >= max) {
  69. return;
  70. }
  71. if (parentValue.indexOf(name) === -1) {
  72. parentValue.push(name);
  73. emit(parent, parentValue);
  74. }
  75. } else {
  76. var index = parentValue.indexOf(name);
  77. if (index !== -1) {
  78. parentValue.splice(index, 1);
  79. emit(parent, parentValue);
  80. }
  81. }
  82. },
  83. },
  84. });