wangzhibo
4 天以前 10595d8632f959d0954d1939243196f4eed02372
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
import { defineStore } from "pinia";
import { nextTick, ref } from "vue";
import { throttle } from "lodash-es";
 
export const useTools = defineStore("cs.tools", () => {
    const visible = ref(false);
    const mode = ref("");
 
    // 打开
    function open(m: string) {
        if (visible.value && mode.value === m) {
            return close();
        }
 
        visible.value = true;
        mode.value = m;
    }
 
    // 关闭
    function close() {
        visible.value = false;
    }
 
    return {
        visible,
        mode,
        open,
        close,
    };
});
 
export const useScroller = defineStore("cs.scroller", () => {
    // 滚动距离
    const top = ref(0);
 
    // 滚动动画
    const animation = ref(true);
 
    let n = 0;
 
    // 滚动到指定位置
    const scrollTo = throttle((scrollTop: number, smooth: boolean = true) => {
        nextTick().then(() => {
            top.value = scrollTop;
 
            animation.value = smooth;
        });
    }, 500);
 
    // 滚动到底部
    const scrollToBottom = (smooth?: boolean) => {
        scrollTo(100000 + n++, smooth);
    };
 
    return {
        animation,
        top,
        scrollToBottom,
        scrollTo,
    };
});