index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { __spreadArray } from "tslib";
  2. import { Component, triggerEvent, getValueFromProps } from '../../_util/simply';
  3. import { CheckboxGroupDefaultProps } from './props';
  4. import mixinValue from '../../mixins/value';
  5. Component(CheckboxGroupDefaultProps, {
  6. onChange: function (args, e) {
  7. if (getValueFromProps(this, 'disabled')) {
  8. return;
  9. }
  10. var event;
  11. event = e;
  12. var currentValue = this.getValue();
  13. var index = event.currentTarget.dataset.index;
  14. var selectValue = getValueFromProps(this, 'options')[index].value;
  15. if (currentValue.indexOf(selectValue) > -1) {
  16. currentValue = currentValue.filter(function (v) { return v !== selectValue; });
  17. }
  18. else {
  19. currentValue = __spreadArray(__spreadArray([], currentValue, true), [selectValue], false);
  20. }
  21. if (!this.isControlled()) {
  22. this.update(currentValue);
  23. }
  24. triggerEvent(this, 'change', currentValue, e);
  25. },
  26. }, null, [
  27. mixinValue({
  28. transformValue: function (val) {
  29. var value = val || [];
  30. return {
  31. needUpdate: true,
  32. value: value,
  33. };
  34. },
  35. }),
  36. ]);