wujingjing
2025-04-16 9fd9a0ac506b9f9b84d8b06a2c65efc8cf41bfa3
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
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>share</title>
    </head>
    <style>
        body,
        html {
            margin: 0;
            height: 100%;
        }
        html {
            overflow-y: hidden;
        }
    </style>
    <script src="../static/config/globalConfig.js"></script>
    <script>
        function isMobile() {
            const userAgentInfo = navigator.userAgent;
            const mobileAgents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
            const mobileFlag = mobileAgents.some((mobileAgent) => {
                return userAgentInfo.indexOf(mobileAgent) > 0;
            });
 
            return mobileFlag;
        }
 
        const isTest = window.globalConfig.Mode === 'test';
        const MobileProdShareRealUrl = window.globalConfig.WebApiUrl.MobileProdShareRealUrl;
        const MobileTestShareRealUrl = window.globalConfig.WebApiUrl.MobileTestShareRealUrl;
        const getSearchParams = (url) => {
            // 获取查询参数前的 ? 对应的索引位置
            const searchIndex = url.indexOf('?');
            // 截取出查询参数字符串,并根据 & 将其分割成一个个 name=bruce 形式字符串组成的数组
            const searchParamsArray = url.slice(searchIndex + 1).split('&');
            // 遍历数组,组成查询参数对象
            return searchParamsArray.reduce((pre, cur) => {
                const [key, value] = cur.split('=');
                return {
                    ...pre,
                    // 需要使用 decodeURIComponent 对参数进行解码
                    [key]: decodeURIComponent(value),
                };
            }, {});
        };
 
        /**
         *
         * @param {*} func 防抖函数
         * @param {*} wait 等待时长(毫秒)
         * @param {*} immediate 是否先立即触发一次
         * @description 使用方法见{@link https://mp.weixin.qq.com/s/vfnqmE1EG8UCedduDJE7Eg}
         * 触发了事件会在n毫秒后执行,但是如果在这n毫秒内又去触发,计时器又会重新计算n毫秒,等n毫秒后触发
         *
         * 事件会置后触发,新来的事件会覆盖之前的事件
         * @returns
         */
        const debounce = (func, wait = 300, immediate = false) => {
            if (!func) return undefined;
            let timer = null;
            return function (...arg) {
                if (timer !== null) {
                    clearTimeout(timer);
                } else if (immediate) {
                    func.apply(this, arg);
                }
                timer = setTimeout(() => {
                    func.apply(this, arg);
                    timer = null;
                }, wait);
            };
        };
        const getBaseUrl = () => {
            const serveUrl = window.location.origin + window.location.pathname;
            const shareSuffix = window.globalConfig.WebApiUrl.ShareUrl;
            return serveUrl.replace(shareSuffix, '');
        };
        const urlParams = getSearchParams(window.location.search);
        const id = urlParams.id;
 
        let pcShareUrl;
        let mobileShareUrl;
        const pcBaseUrl = getBaseUrl();
 
        if (isTest) {
            pcShareUrl = `${pcBaseUrl}/#/share?id=${id}`;
            mobileShareUrl = `${MobileTestShareRealUrl}/#/share?id=${id}`;
        } else {
            pcShareUrl = `${pcBaseUrl}/#/share?id=${id}`;
            mobileShareUrl = `${MobileProdShareRealUrl}/#/share?id=${id}`;
        }
        window.location.href = isMobile() ? mobileShareUrl : pcShareUrl;
    </script>
    <body></body>
</html>