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