mirror of
https://github.com/youzan/vant.git
synced 2026-05-02 01:01:43 +08:00
[improvement] Rate: support touch move select (#1951)
This commit is contained in:
+20
-1
@@ -1,11 +1,12 @@
|
||||
<template>
|
||||
<div :class="b()">
|
||||
<div :class="b()" @touchmove="onTouchMove">
|
||||
<svg
|
||||
v-for="(isFull, index) in list"
|
||||
:fill="disabled ? disabledColor : isFull ? color : voidColor"
|
||||
viewBox="0 0 32 32"
|
||||
:style="style"
|
||||
:class="b('item')"
|
||||
:data-index="index"
|
||||
@click="onSelect(index)"
|
||||
>
|
||||
<path :d="isFull ? 'M32 12.408l-11.056-1.607-4.944-10.018-4.944 10.018-11.056 1.607 8 7.798-1.889 11.011 9.889-5.199 9.889 5.199-1.889-11.011 8-7.798z' : 'M32 12.408l-11.056-1.607-4.944-10.018-4.944 10.018-11.056 1.607 8 7.798-1.889 11.011 9.889-5.199 9.889 5.199-1.889-11.011 8-7.798zM16 23.547l-6.983 3.671 1.334-7.776-5.65-5.507 7.808-1.134 3.492-7.075 3.492 7.075 7.807 1.134-5.65 5.507 1.334 7.776-6.983-3.671z'" />
|
||||
@@ -66,6 +67,24 @@ export default create({
|
||||
this.$emit('input', index + 1);
|
||||
this.$emit('change', index + 1);
|
||||
}
|
||||
},
|
||||
|
||||
onTouchMove(event) {
|
||||
if (!document.elementFromPoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
const { clientX, clientY } = event.touches[0];
|
||||
const target = document.elementFromPoint(clientX, clientY);
|
||||
if (target && target.dataset) {
|
||||
const { index } = target.dataset;
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (index) {
|
||||
this.onSelect(+index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user