Улучшение NumInput
This commit is contained in:
@@ -6,15 +6,26 @@
|
|||||||
class="no-mp"
|
class="no-mp"
|
||||||
:class="(error ? 'error' : '')"
|
:class="(error ? 'error' : '')"
|
||||||
:disable="disable"
|
:disable="disable"
|
||||||
|
:mask="mask"
|
||||||
>
|
>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
<template #prepend>
|
<template #prepend>
|
||||||
|
<q-icon
|
||||||
|
v-show="mmButtons"
|
||||||
|
v-ripple="modelValue != min"
|
||||||
|
style="font-size: 100%"
|
||||||
|
:class="(modelValue != min ? '' : 'disable')"
|
||||||
|
name="la la-angle-double-left"
|
||||||
|
class="button"
|
||||||
|
@click="toMin"
|
||||||
|
/>
|
||||||
|
|
||||||
<q-icon
|
<q-icon
|
||||||
v-ripple="validate(modelValue - step)"
|
v-ripple="validate(modelValue - step)"
|
||||||
:class="(validate(modelValue - step) ? '' : 'disable')"
|
:class="(validate(modelValue - step) ? '' : 'disable')"
|
||||||
name="la la-minus-circle"
|
:name="minusIcon"
|
||||||
class="button"
|
class="button"
|
||||||
@click="minus"
|
@click="onClick('minus')"
|
||||||
@mousedown.prevent.stop="onMouseDown($event, 'minus')"
|
@mousedown.prevent.stop="onMouseDown($event, 'minus')"
|
||||||
@mouseup.prevent.stop="onMouseUp"
|
@mouseup.prevent.stop="onMouseUp"
|
||||||
@mouseout.prevent.stop="onMouseUp"
|
@mouseout.prevent.stop="onMouseUp"
|
||||||
@@ -27,9 +38,9 @@
|
|||||||
<q-icon
|
<q-icon
|
||||||
v-ripple="validate(modelValue + step)"
|
v-ripple="validate(modelValue + step)"
|
||||||
:class="(validate(modelValue + step) ? '' : 'disable')"
|
:class="(validate(modelValue + step) ? '' : 'disable')"
|
||||||
name="la la-plus-circle"
|
:name="plusIcon"
|
||||||
class="button"
|
class="button"
|
||||||
@click="plus"
|
@click="onClick('plus')"
|
||||||
@mousedown.prevent.stop="onMouseDown($event, 'plus')"
|
@mousedown.prevent.stop="onMouseDown($event, 'plus')"
|
||||||
@mouseup.prevent.stop="onMouseUp"
|
@mouseup.prevent.stop="onMouseUp"
|
||||||
@mouseout.prevent.stop="onMouseUp"
|
@mouseout.prevent.stop="onMouseUp"
|
||||||
@@ -37,6 +48,16 @@
|
|||||||
@touchend.stop="onTouchEnd"
|
@touchend.stop="onTouchEnd"
|
||||||
@touchcancel.prevent.stop="onTouchEnd"
|
@touchcancel.prevent.stop="onTouchEnd"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<q-icon
|
||||||
|
v-show="mmButtons"
|
||||||
|
v-ripple="modelValue != max"
|
||||||
|
style="font-size: 100%"
|
||||||
|
:class="(modelValue != max ? '' : 'disable')"
|
||||||
|
name="la la-angle-double-right"
|
||||||
|
class="button"
|
||||||
|
@click="toMax"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</q-input>
|
</q-input>
|
||||||
</template>
|
</template>
|
||||||
@@ -49,17 +70,18 @@ import * as utils from '../../share/utils';
|
|||||||
|
|
||||||
const componentOptions = {
|
const componentOptions = {
|
||||||
watch: {
|
watch: {
|
||||||
filteredValue: function(newValue) {
|
filteredValue() {
|
||||||
if (this.validate(newValue)) {
|
this.checkErrorAndEmit(true);
|
||||||
this.error = false;
|
|
||||||
this.$emit('update:modelValue', this.string2number(newValue));
|
|
||||||
} else {
|
|
||||||
this.error = true;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
modelValue: function(newValue) {
|
modelValue(newValue) {
|
||||||
this.filteredValue = newValue;
|
this.filteredValue = newValue;
|
||||||
},
|
},
|
||||||
|
min() {
|
||||||
|
this.checkErrorAndEmit();
|
||||||
|
},
|
||||||
|
max() {
|
||||||
|
this.checkErrorAndEmit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
class NumInput {
|
class NumInput {
|
||||||
@@ -70,7 +92,11 @@ class NumInput {
|
|||||||
max: { type: Number, default: Number.MAX_VALUE },
|
max: { type: Number, default: Number.MAX_VALUE },
|
||||||
step: { type: Number, default: 1 },
|
step: { type: Number, default: 1 },
|
||||||
digits: { type: Number, default: 0 },
|
digits: { type: Number, default: 0 },
|
||||||
disable: Boolean
|
disable: Boolean,
|
||||||
|
minusIcon: {type: String, default: 'la la-minus-circle'},
|
||||||
|
plusIcon: {type: String, default: 'la la-plus-circle'},
|
||||||
|
mmButtons: Boolean,
|
||||||
|
mask: String,
|
||||||
};
|
};
|
||||||
|
|
||||||
filteredValue = 0;
|
filteredValue = 0;
|
||||||
@@ -95,6 +121,16 @@ class NumInput {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkErrorAndEmit(emit = false) {
|
||||||
|
if (this.validate(this.filteredValue)) {
|
||||||
|
this.error = false;
|
||||||
|
if (emit)
|
||||||
|
this.$emit('update:modelValue', this.string2number(this.filteredValue));
|
||||||
|
} else {
|
||||||
|
this.error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
plus() {
|
plus() {
|
||||||
const newValue = this.modelValue + this.step;
|
const newValue = this.modelValue + this.step;
|
||||||
if (this.validate(newValue))
|
if (this.validate(newValue))
|
||||||
@@ -107,12 +143,28 @@ class NumInput {
|
|||||||
this.filteredValue = newValue;
|
this.filteredValue = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onClick(way) {
|
||||||
|
if (this.clickRepeat)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (way == 'plus') {
|
||||||
|
this.plus();
|
||||||
|
} else {
|
||||||
|
this.minus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMouseDown(event, way) {
|
onMouseDown(event, way) {
|
||||||
this.startClickRepeat = true;
|
this.startClickRepeat = true;
|
||||||
this.clickRepeat = false;
|
this.clickRepeat = false;
|
||||||
|
|
||||||
if (event.button == 0) {
|
if (event.button == 0) {
|
||||||
(async() => {
|
(async() => {
|
||||||
|
if (this.inRepeatFunc)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.inRepeatFunc = true;
|
||||||
|
try {
|
||||||
await utils.sleep(300);
|
await utils.sleep(300);
|
||||||
if (this.startClickRepeat) {
|
if (this.startClickRepeat) {
|
||||||
this.clickRepeat = true;
|
this.clickRepeat = true;
|
||||||
@@ -122,9 +174,12 @@ class NumInput {
|
|||||||
} else {
|
} else {
|
||||||
this.minus();
|
this.minus();
|
||||||
}
|
}
|
||||||
await utils.sleep(50);
|
await utils.sleep(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
this.inRepeatFunc = false;
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,7 +188,12 @@ class NumInput {
|
|||||||
if (this.inTouch)
|
if (this.inTouch)
|
||||||
return;
|
return;
|
||||||
this.startClickRepeat = false;
|
this.startClickRepeat = false;
|
||||||
|
if (this.clickRepeat) {
|
||||||
|
(async() => {
|
||||||
|
await utils.sleep(50);
|
||||||
this.clickRepeat = false;
|
this.clickRepeat = false;
|
||||||
|
})();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onTouchStart(event, way) {
|
onTouchStart(event, way) {
|
||||||
@@ -151,6 +211,14 @@ class NumInput {
|
|||||||
this.inTouch = false;
|
this.inTouch = false;
|
||||||
this.onMouseUp();
|
this.onMouseUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toMin() {
|
||||||
|
this.filteredValue = this.min;
|
||||||
|
}
|
||||||
|
|
||||||
|
toMax() {
|
||||||
|
this.filteredValue = this.max;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default vueComponent(NumInput);
|
export default vueComponent(NumInput);
|
||||||
@@ -165,7 +233,9 @@ export default vueComponent(NumInput);
|
|||||||
|
|
||||||
.button {
|
.button {
|
||||||
font-size: 130%;
|
font-size: 130%;
|
||||||
border-radius: 20px;
|
border-radius: 15px;
|
||||||
|
width: 30px;
|
||||||
|
height: 30px;
|
||||||
color: #bbb;
|
color: #bbb;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user