-
zhangwei
2025-03-24 2d43a1df3f5ba42710e6d21c27d1e13bdb8dfd56
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// 本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID: 16 3,营业执照号:915  1   0 13  1332 0  0  6 19 3  K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。
// #ifdef APP-NVUE
const animation = uni.requireNativePlugin('animation');
export default {
    watch: {
        resetNum(val) {
            this.startX = 0;
            this.lastLeft = 0;
            this._animation(0)
        }
    },
    created() {
        this.startX = 0
        this.lastLeft = 0
        this.imgRef = null
        this.sliderRef = null
    },
    methods: {
        openAni() {
            this.isShow = true;
            this.$nextTick(() => {
                setTimeout(() => {
                    this.getEl()
                    this._ani(true);
                }, 50);
            });
        },
        closeAni(type) {
            this._ani(false);
        },
        _ani(type) {
            let styles = {
                opacity: type ? 1 : 0
            };
            if (!this.$refs['fui_sc_ani']) return;
            animation.transition(
                this.$refs['fui_sc_ani'].ref, {
                    styles,
                    duration: 200, //ms
                    timingFunction: 'ease-in',
                    needLayout: false,
                    delay: 0 //ms
                },
                () => {
                    if (!type) {
                        this.isShow = false;
                    }
                }
            );
        },
        getEl() {
            this.imgRef = this.$refs['imgRef'].ref
            this.sliderRef = this.$refs['sliderRef'].ref;
        },
        getSlipDistance(left) {
            let width = this.w - this.x - 44
            let distance = left / (this.w - (this.sliderH * 2)) * width
            return distance > width ? width : distance
        },
        _animation(left) {
            let slotLeft = this.getSlipDistance(left).toFixed(2)
            left = left.toFixed(2)
            if (!this.imgRef || !this.sliderRef) return;
            animation.transition(this.imgRef, {
                styles: {
                    transform: 'translate(' + slotLeft + 'px,0)'
                },
                duration: left == 0 ? 200 : 0,
                timingFunction: 'linear',
                needLayout: false,
                delay: 0
            });
            animation.transition(this.sliderRef, {
                styles: {
                    transform: 'translate(' + left + 'px,0)'
                },
                duration: left == 0 ? 200 : 0,
                timingFunction: 'linear',
                needLayout: false,
                delay: 0
            });
        },
        touchstart(e) {
            if (this.isPass || this.disabled || !this.slotSrc || !this.isShow) return;
            let touch = e.touches[0] || e.changedTouches[0];
            this.startX = touch.screenX
        },
        touchmove(e) {
            if (this.isPass || this.disabled || !this.slotSrc || !this.isShow) return;
            let touch = e.changedTouches[0];
            let pageX = touch.screenX;
            let left = pageX - this.startX + this.lastLeft;
            left = left < 0 ? 0 : left;
            let width = this.w - (this.sliderH * 2);
            left = left >= width ? width : left;
            this.startX = pageX
            this.lastLeft = left
            this._animation(left)
        },
        touchend(e) {
            if (this.isPass || this.disabled || !this.slotSrc || !this.isShow) return;
            let slotLeft = this.getSlipDistance(this.lastLeft)
            if (this.type == 1) {
                let width = this.x1 - this.x
                if (Math.abs(slotLeft - width) <= this.range) {
                    this.disabled = true
                    this.success()
                } else {
                    setTimeout(() => {
                        this.startX = 0;
                        this.lastLeft = 0;
                        this.disabled = false;
                        this._animation(0)
                        this.fail()
                    }, 20)
                }
            } else {
                //后端验证
                this.verify({
                    slip: slotLeft
                })
            }
        }
    }
}
 
// #endif
 
// #ifndef APP-NVUE
export default {}
// #endif