index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var component_1 = require("../common/component");
  4. component_1.VantComponent({
  5. field: true,
  6. classes: [
  7. 'input-class',
  8. 'plus-class',
  9. 'minus-class'
  10. ],
  11. props: {
  12. value: null,
  13. integer: Boolean,
  14. disabled: Boolean,
  15. inputWidth: String,
  16. asyncChange: Boolean,
  17. disableInput: Boolean,
  18. min: {
  19. type: null,
  20. value: 1
  21. },
  22. max: {
  23. type: null,
  24. value: Number.MAX_SAFE_INTEGER
  25. },
  26. step: {
  27. type: null,
  28. value: 1
  29. },
  30. showPlus: {
  31. type: Boolean,
  32. value: true
  33. },
  34. showMinus: {
  35. type: Boolean,
  36. value: true
  37. },
  38. disablePlus: Boolean,
  39. disableMinus: Boolean
  40. },
  41. computed: {
  42. minusDisabled: function () {
  43. return this.data.disabled || this.data.disableMinus || this.data.value <= this.data.min;
  44. },
  45. plusDisabled: function () {
  46. return this.data.disabled || this.data.disablePlus || this.data.value >= this.data.max;
  47. }
  48. },
  49. watch: {
  50. value: function (value) {
  51. if (value === '') {
  52. return;
  53. }
  54. var newValue = this.range(value);
  55. if (typeof newValue === 'number' && +this.data.value !== newValue) {
  56. this.set({ value: newValue });
  57. }
  58. },
  59. max: 'check',
  60. min: 'check',
  61. },
  62. data: {
  63. focus: false
  64. },
  65. created: function () {
  66. this.set({
  67. value: this.range(this.data.value)
  68. });
  69. },
  70. methods: {
  71. check: function () {
  72. var newValue = this.range(this.data.value);
  73. if (typeof newValue === 'number' && +this.data.value !== newValue) {
  74. this.set({ value: newValue });
  75. }
  76. },
  77. onFocus: function (event) {
  78. this.$emit('focus', event.detail);
  79. },
  80. onBlur: function (event) {
  81. var value = this.range(this.data.value);
  82. this.triggerInput(value);
  83. this.$emit('blur', event.detail);
  84. },
  85. // limit value range
  86. range: function (value) {
  87. value = String(value).replace(/[^0-9.-]/g, '');
  88. return Math.max(Math.min(this.data.max, value), this.data.min);
  89. },
  90. onInput: function (event) {
  91. var _a = (event.detail || {}).value, value = _a === void 0 ? '' : _a;
  92. this.triggerInput(value);
  93. },
  94. onChange: function (type) {
  95. if (this.data[type + "Disabled"]) {
  96. this.$emit('overlimit', type);
  97. return;
  98. }
  99. var diff = type === 'minus' ? -this.data.step : +this.data.step;
  100. var value = Math.round((+this.data.value + diff) * 100) / 100;
  101. this.triggerInput(this.range(value));
  102. this.$emit(type);
  103. },
  104. onMinus: function () {
  105. this.onChange('minus');
  106. },
  107. onPlus: function () {
  108. this.onChange('plus');
  109. },
  110. triggerInput: function (value) {
  111. this.set({
  112. value: this.data.asyncChange ? this.data.value : value
  113. });
  114. this.$emit('change', value);
  115. }
  116. }
  117. });