zengh
2022-05-09 52c39f5e2711e5535b689b66dfa5e100c7882b7f
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
class $moveUniAppMap {
    constructor(arg) {
        this.activeDom = arg.activeDom; //活动dom
        this.adaptDom = arg.adaptDom; //适应dom
        this.windowSize = arg.uni.getSystemInfoSync(); // 设备参数含屏幕尺寸
        let doms = arg.uni.createSelectorQuery(); //获取dom参数uni工具
        this.getDoms = (name, fn) => { //fn是会回调函数,不用promis
            doms.select(name).boundingClientRect((data) => {
                if (fn) {
                    fn(data)
                }
            }).exec()
        }
        // console.log(this.windowSize)
 
        this.start = 0;
        this.end = 0;
        this.domHeight = 0;
        this.openValue = false; //方向
        this.useHeight = arg.useHeight; //使用的低高度
        this.critical = arg.critical; //收缩展开的程度
        // this.getDoms(this.activeDom, (res) => { //获取dom最大高度
        this.maxHeight = arg.maxHeight;
        // })
        this.fn = (res) => {
            if (arg.fn) {
                arg.fn(res)
            } else {
                console.log(res, "未设置输出函数")
            }
        }
 
        return this;
    }
    ListenerTouchstart(dom) { //开始移动,记录开始点和活动dom高度
        this.start = dom.changedTouches[0].clientY;
        this.getDoms(this.activeDom, (res) => { //动态获取当前活动dom高度
            this.domHeight = res.height;
        })
        // let d = {
        //     state: "start",
        //     height: this.maxHeight,
        // };
        // // console.log(cha, "cha")
        // // console.log(+endOn - +this.start, "cha")
        // this.fn(d);
        // console.log(this.start, "this.start")
    }
    ListenerTouchmove(dom) {
        let endOn = dom.changedTouches[0].clientY;
        // console.log(that.domHeight, that.start, endOn)
        let usecha = +this.start - +endOn;
        let cha = this.domHeight + usecha;
        if (cha >= this.maxHeight) {
            cha = this.maxHeight;
        } else if (cha <= this.useHeight) {
            cha = this.useHeight;
        }
        let translate = false;
        if (usecha >= this.critical) {
            translate = true;
        }
        if (usecha <= -this.critical) {
            translate = true;
        }
        let d = {
            state: "on",
            height: cha,
            translate: translate
        };
        if (usecha >= 0) {
            d.state = "up";
        }
        // console.log(cha, "cha")
        // console.log(usecha, "cha")
        this.fn(d);
    }
    ListenerTouchend(dom) {
        this.end = dom.changedTouches[0].clientY;
        let cha, states;
        if (this.end >= this.start) {
            states = false; //方向向下收缩
            cha = this.end - this.start;
        } else {
            states = true; //方向向上抬起
            cha = this.start - this.end;
        }
        if (cha >= this.critical) {
            //高
            this.judge(states, true); //程度
        } else if (cha < this.critical) {
            //低
            this.judge(states, false); //程度
        }
        // console.log(cha)
    }
    innit() {
 
    }
    //输出事件
    judge(val, chengdu) {
        let translate = '';
        if (chengdu) {
            this.openValue = val;
            if (val) {
                this.height = this.maxHeight; //给到向上的最高高度
            } else {
                this.height = this.useHeight; //给到向下的最低高度
            }
        } else {
            this.height = this.domHeight; //给到当前高度
        }
        if (this.height == this.maxHeight) {
            translate = false;
        } else {
            translate = true;
        }
        let d = {
            state: this.openValue,
            height: this.height,
            translate: translate
        };
        // console.log(d)
        this.fn(d);
    }
}
 
export default $moveUniAppMap;