zhangwei
2025-01-16 ea44321752674bc97efb7bfa987c19121c3d6881
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
// 本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID:  163,营业执照号:   91   510   13 13  32 006  19  3K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。
// #ifndef APP-PLUS || MP-WEIXIN || H5
export default {
    data() {
        return {
            transform: '',
            transformSlot: '',
            startX: 0,
            lastLeft: 0,
            resetAni: false
        }
    },
    watch: {
        resetNum(val) {
            this.startX = 0;
            this.lastLeft = 0;
            this.styleChange(0)
        }
    },
    methods: {
        getSlipDistance(left) {
            let width = this.w - this.x - 44
            let distance = left / (this.w - (this.sliderH * 2)) * width
            return distance > width ? width : distance
        },
        styleChange(left) {
            if (left == 0) {
                this.resetAni = true
            } else {
                this.resetAni = false
            }
            let slotLeft = this.getSlipDistance(left)
            this.transformSlot = 'translate3d(' + slotLeft + 'px,0,0)'
            this.transform = 'translate3d(' + left + 'px,0,0)'
        },
        touchstart(e) {
            let touch = e.touches[0] || e.changedTouches[0];
            this.startX = touch.clientX
        },
        touchmove(e) {
            if (this.isPass || this.disabled || !this.slotSrc || !this.isShow) return;
            let touch = e.touches[0] || e.changedTouches[0]
            let pageX = touch.clientX;
            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.styleChange(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 {
                    this.startX = 0;
                    this.lastLeft = 0;
                    this.disabled = false;
                    this.styleChange(0)
                    this.fail()
                }
            } else {
                //后端验证
                this.verify({
                    slip: slotLeft
                })
            }
        }
    }
}
 
// #endif
 
// #ifdef APP-PLUS|| MP-WEIXIN || H5
export default {}
// #endif