hxp
2025-06-04 f4a514d5ac952110da846636ecbb9de951eaf3d2
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
include_once "/Common/Logging.php";
include_once "/Account/User.php";
include_once "/language/lang.php";
 
\Logging\CreateLogging("playerlv.php");
$Permission = \User\Permission::P_PlayerLV;
 
$alertMsg = "";
$channel = $_SESSION['spid'];
$UserAccount = $_SESSION['UserAccount'];
$user = new \User\User($UserAccount);
if (!$user->HavePermission($Permission)) {
    exit;
}
 
$serversArray = $user->GetServers();
 
// 设置默认数据,开界面默认查选中服
$_POST["eventType"] = "PlayerLVInfo";
\CommFunc\QueryEventData($user, $retInfo);
 
// echo "_POST:", print_r($retInfo, true), "<br/>";
 
?>
 
<!DOCTYPE html>
<html>
 
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>
        <?php echo \Lang\gettext("等级分布"); ?>
    </title>
    <link rel="gettext" type="application/x-po"
        href="../language/<?php echo \Lang\getLang(); ?>/LC_MESSAGES/<?php echo \Lang\getjspodomain(); ?>.po" />
</head>
 
<body>
    <center>
        <p><b>
                <?php echo \Lang\gettext("等级分布"); ?>
            </b></P>
    </center>
    <form id="online" action="playerlv.php" method="post">
        <input type="submit" value="<?php echo \Lang\gettext("查询本服"); ?>" onclick="onCurSubmit()" />
        <input type="button" value="<?php echo \Lang\gettext("复制数据"); ?>" onclick="onCopyData()" />
        &nbsp;&nbsp;注:本数据仅为物理服数据,如果是合服则为合服数据,不包含合服后被删除的角色
        <div id="OnlinePlayerInfo"></div>
        <hr />
        <?php
        include_once "/Common/SelectServer.php";
        ?>
        <input type="submit" name="submit" id="submit" value="<?php echo \Lang\gettext("查询多服"); ?>"
            onclick="return checkMultiSubmit()" />
        <br />
        <br />
    </form>
</body>
<script type='text/javascript' src='/language/gettext.js'></script>
<script type='text/javascript' src="/js/calendar.js"></script>
<script type='text/javascript' src="/js/common.js"></script>
<script type='text/javascript' src="/Common/selectserver.js"></script>
<script type='text/javascript' src="/js/chart.min.js"></script>
<script type="text/javascript">
    window.onload = function () {
        var retInfo = '<?php echo json_encode($retInfo); ?>';
        if (retInfo == 'null') {
            return;
        }
        retInfo = JSON.parse(retInfo);
 
        let chartNum = 0;
        let insHtml, info;
        for (const serverName in retInfo) {
            let chartID;
            insHtml = "";
            insHtml += "<hr />";
            info = retInfo[serverName];
            console.log(serverName, info);
            if (info && info["OK"]) {
                chartID = "myChart" + chartNum;
                chartNum += 1;
                // insHtml += "<center>" + serverName + "</center>" + "<br/>";
                insHtml += "<canvas id=\"" + chartID + "\" ></canvas>"; // 插入画布
            } else {
                insHtml += serverName + " : " + info + "<br/>";
            }
            document.getElementById("OnlinePlayerInfo").insertAdjacentHTML("beforeEnd", insHtml);
            if (chartID) {
                drawChartLine(chartID, serverName, info["Data"]);
            }
        }
    }
 
    function drawChartLine(chartID, serverName, drData) {
 
        var lvList = [];
        for (const key in drData) {
            lvList.push(parseInt(key));
        }
        lvList.sort(function (a, b) { return a - b });
        console.log("lvList", lvList);
 
        var labels = [];
        var datasets = [];
 
        let playerCountList = [];
        for (let index = 0; index < lvList.length; index++) {
            const lvStr = lvList[index] + "";
            labels.push(lvStr);
            playerCountList.push(drData[lvStr]);
        }
 
        datasets.push({
            label: "人数",
            data: playerCountList,
            backgroundColor: 'rgba(79, 66, 255, 0.2)',
            borderColor: 'rgba(79, 66, 255, 1)',
            borderWidth: 1,
            lineTension: 0.5,
            pointRadius: 1
        });
 
        var ctx = document.getElementById(chartID);
        ctx.width = 400;
        ctx.height = 100;
        var myLineChart = new Chart(ctx, {
            type: "line",
            data: {
                labels: labels,
                datasets: datasets
            },
            options: {
                plugins: {
                    title: {
                        display: true,
                        text: serverName
                    }
                },
                scales: {
                    x: {
                        title: {
                            display: true,
                            text: "等级"
                        }
                    },
                    y: {
                        title: {
                            display: true,
                            text: "人数"
                        },
                        beginAtZero: true,
                        ticks: {
                            stepSize: 1, // 刻度间隔1
                        }
                    }
                }
            }
        });
    }
 
    function onCurSubmit() {
        document.getElementById("MultiServer").value = 0;
        return true;
    }
 
    function checkMultiSubmit() {
 
        if (!checkHaveServerSelected()) {
            return false;
        }
 
        if (!setSubmitQuerying("submit")) {
            return false;
        }
 
        return true;
    }
 
    function onCopyData() {
        var retInfo = '<?php echo json_encode($retInfo); ?>';
        if (retInfo == 'null') {
            return;
        }
        retInfo = JSON.parse(retInfo);
 
        var copydata = "";
        for (const serverName in retInfo) {
            info = retInfo[serverName];
            if (!info || !info["OK"]) {
                continue;
            }
            drData = info["Data"];
            var lvList = [];
            for (const key in drData) {
                lvList.push(parseInt(key));
            }
            lvList.sort(function(a, b) {
                return a - b
            });
 
            copydata += "<table>";
            copydata += "<tr><td>服务器: " + serverName + "</td></tr>";
            copydata += "<tr><td>等级</td><td>人数</td></tr>";
            for (let index = 0; index < lvList.length; index++) {
                const lv = lvList[index];
                const playerCount = drData[lv];
                copydata += "<tr><td>" + lv + "</td><td>" + playerCount + "</td></tr>";
            }
            copydata += "<tr></tr>";
            copydata += "</table>";
        }
        if (!copydata) {
            alert("没有数据");
            return
        }
        copyToClipboard(copydata);
        alert("表格复制成功,可直接粘贴到Excel工作表!");
    }
 
    function copyToClipboard(text) {
        var textarea = document.createElement('textarea');
        textarea.style.position = 'fixed';
        textarea.style.opacity = 0;
        textarea.value = text;
        document.body.appendChild(textarea);
        textarea.select();
        document.execCommand('copy');
        document.body.removeChild(textarea);
    }
</script>
 
</html>