mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
feat(Picker): remove computed (#2001)
This commit is contained in:
parent
78681032b8
commit
f178552d75
@ -42,26 +42,6 @@ VantComponent({
|
||||
});
|
||||
},
|
||||
|
||||
computed: {
|
||||
count() {
|
||||
return this.data.options.length;
|
||||
},
|
||||
|
||||
baseOffset() {
|
||||
const { data } = this;
|
||||
return (data.itemHeight * (data.visibleItemCount - 1)) / 2;
|
||||
},
|
||||
|
||||
wrapperStyle() {
|
||||
const { data } = this;
|
||||
return [
|
||||
`transition: transform ${data.duration}ms`,
|
||||
`transform: translate3d(0, ${data.offset + data.baseOffset}px, 0)`,
|
||||
`line-height: ${data.itemHeight}px`
|
||||
].join('; ');
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
defaultIndex(value: number) {
|
||||
this.setIndex(value);
|
||||
@ -69,6 +49,10 @@ VantComponent({
|
||||
},
|
||||
|
||||
methods: {
|
||||
getCount() {
|
||||
return this.data.options.length;
|
||||
},
|
||||
|
||||
onTouchStart(event: Weapp.TouchEvent) {
|
||||
this.set({
|
||||
startY: event.touches[0].clientY,
|
||||
@ -83,7 +67,7 @@ VantComponent({
|
||||
this.set({
|
||||
offset: range(
|
||||
data.startOffset + deltaY,
|
||||
-(data.count * data.itemHeight),
|
||||
-(this.getCount() * data.itemHeight),
|
||||
data.itemHeight
|
||||
)
|
||||
});
|
||||
@ -98,7 +82,7 @@ VantComponent({
|
||||
const index = range(
|
||||
Math.round(-data.offset / data.itemHeight),
|
||||
0,
|
||||
data.count - 1
|
||||
this.getCount() - 1
|
||||
);
|
||||
this.setIndex(index, true);
|
||||
}
|
||||
@ -111,8 +95,10 @@ VantComponent({
|
||||
|
||||
adjustIndex(index: number) {
|
||||
const { data } = this;
|
||||
index = range(index, 0, data.count);
|
||||
for (let i = index; i < data.count; i++) {
|
||||
const count = this.getCount();
|
||||
|
||||
index = range(index, 0, count);
|
||||
for (let i = index; i < count; i++) {
|
||||
if (!this.isDisabled(data.options[i])) return i;
|
||||
}
|
||||
for (let i = index - 1; i >= 0; i--) {
|
||||
|
@ -8,7 +8,7 @@
|
||||
bind:touchend="onTouchEnd"
|
||||
bind:touchcancel="onTouchEnd"
|
||||
>
|
||||
<view style="{{ wrapperStyle }}">
|
||||
<view style="transition: transform {{ duration }}ms; line-height: {{ itemHeight }}px; transform: translate3d(0, {{ offset + (itemHeight * (visibleItemCount - 1)) / 2 }}px, 0)">
|
||||
<view
|
||||
wx:for="{{ options }}"
|
||||
wx:for-item="option"
|
||||
|
Loading…
x
Reference in New Issue
Block a user