index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. (0, component_1.VantComponent)({
  10. field: true,
  11. relation: (0, 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. }
  41. else {
  42. emit(this, value);
  43. }
  44. },
  45. toggle: function () {
  46. var _a = this.data, parentDisabled = _a.parentDisabled, disabled = _a.disabled, value = _a.value;
  47. if (!disabled && !parentDisabled) {
  48. this.emitChange(!value);
  49. }
  50. },
  51. onClickLabel: function () {
  52. var _a = this.data, labelDisabled = _a.labelDisabled, parentDisabled = _a.parentDisabled, disabled = _a.disabled, value = _a.value;
  53. if (!disabled && !labelDisabled && !parentDisabled) {
  54. this.emitChange(!value);
  55. }
  56. },
  57. setParentValue: function (parent, value) {
  58. var parentValue = parent.data.value.slice();
  59. var name = this.data.name;
  60. var max = parent.data.max;
  61. if (value) {
  62. if (max && parentValue.length >= max) {
  63. return;
  64. }
  65. if (parentValue.indexOf(name) === -1) {
  66. parentValue.push(name);
  67. emit(parent, parentValue);
  68. }
  69. }
  70. else {
  71. var index = parentValue.indexOf(name);
  72. if (index !== -1) {
  73. parentValue.splice(index, 1);
  74. emit(parent, parentValue);
  75. }
  76. }
  77. },
  78. },
  79. });