hxp
2024-11-19 3c433d5045813bd41d407b34a381cf100465621f
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
235
236
237
var gt = new Gettext({ 'domain': 'gmtjs' });
 
// 检查是否输入验证码
function CheckKey(keyid) {
    if (document.getElementById(keyid).type != "hidden" && !document.getElementById(keyid).value) {
        alert(gt.gettext("请输入授权码!"));
        return false;
    }
    return true;
}
 
// 插入超链接
function inserthyperlink(keyID) {
    var curValue = document.getElementById(keyID).value;
    // document.getElementById(keyID).value = curValue + "[{文本}]({地址})";
    document.getElementById(keyID).value = curValue + "<a>" + gt.gettext("文本") + "|openurl=url</a>";
}
 
// 插入游戏界面
function insertgameform(keyID) {
    var curValue = document.getElementById(keyID).value;
    // document.getElementById(keyID).value = curValue + "[{文本}]({dfm界面名})";
    document.getElementById(keyID).value = curValue + "<a>" + gt.gettext("文本") + "|openui=" + gt.gettext("界面编号") + "</a>";
}
 
function selectall(checkboxkey, tagcheckboxClassName) {
    var checked = document.getElementById(checkboxkey).checked;
    //var items=document.getElementsByName(tagcheckboxkey);
    var items = document.getElementsByClassName(tagcheckboxClassName);
    //循环设置所有复选框状态
    for (var i = 0; i < items.length; i++) {
        items[i].checked = checked;
    }
}
 
// 返回当前日期加减运算后的日期
function sumDateByDays(days) {
    var date = new Date();
    date.setDate(date.getDate() + days);
    var month = date.getMonth() + 1;
    var day = date.getDate();
    return date.format("yyyy-MM-dd")
}
 
// 判断是否是数字
function isRealNum(value) {
    // isNaN()函数 把空串 空格 以及NUll 按照0来处理 所以先去除
    if (value === "" || value == null) {
        return false;
    }
    return !isNaN(value) && typeof value === 'number'
}
 
//浏览器类型判定
function getOs() {
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        return "IE"; //InternetExplor
    } else if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
        return "FF"; //firefox
    } else if (isSafari = navigator.userAgent.indexOf("Safari") > 0) {
        return "SF"; //Safari
    } else if (isCamino = navigator.userAgent.indexOf("Camino") > 0) {
        return "C"; //Camino
    } else if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) {
        return "G"; //Gecko
    } else if (isMozilla = navigator.userAgent.indexOf("Opera") >= 0) {
        return "O"; //opera
    } else {
        return 'Other';
    }
}
 
//获取换行符
function getbr() {
    var os = getOs();
    if (os == 'FF' || os == 'SF') { //FireFox、谷歌浏览器用这个
        return "\n";
    } else { //IE系列用这个
        return "\r\n";
    }
}
 
/**
 * 打开子页面
 * @param {string} url 目标子页面地址,可直接带get参数
 * @param {string} target 
 * @param {int} width 
 * @param {int} height 
 */
function doopen(url, target = "sonwindow", width = 1000, height = 900) {
    // 兼容分屏
    var l = (window.screenX || window.screenLeft || 0) + (screen.availWidth - width) / 2;
    var t = (screen.availHeight - height) / 2;
    var specs = 'width=' + width + ',height=' + height + ',top=' + t + ', left = ' + l +
        ',toolbar=no,menubar=no,location=no';
    // var url = 'userlogdetail.php?GUID=' + GUID + '&Num=' + Num + "&showDetail=" + showDetail;
    myWindow = window.open(url, target, specs);
    myWindow.focus();
}
 
/**
 * AJAX请求
 * @param {*} url 
 * @param {*} cFunction 
 */
function ajaxRequest(url, cFunction, method = "GET") {
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
            cFunction(this);
        }
    };
    if (method == "GET") {
        xhttp.open("GET", url, true); // 异步
        xhttp.send();
    } else {
        var spInfo = url.split("?");
        xhttp.open("POST", spInfo[0], true);
        xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhttp.send(spInfo.length > 1 ? spInfo[1] : "");
    }
}
 
function doSubmit(to, p, method='GET') { // to:提交动作(action),p:参数 
    var myForm = document.createElement("form");
    myForm.method = method;
    myForm.action = to;
    for (var i in p) {
        var myInput = document.createElement("input");
        myInput.setAttribute("name", i); // 为input对象设置name 
        myInput.setAttribute("value", p[i]); // 为input对象设置value 
        myForm.appendChild(myInput);
    }
    document.body.appendChild(myForm);
    myForm.submit();
    document.body.removeChild(myForm); // 提交后移除创建的form 
}
 
function random(min, max) {
    return Math.round(Math.random() * (max - min)) + min;
}
 
var isQuerying = false;
function setSubmitQuerying(key) {
    if (isQuerying) {
        alert(gt.gettext("查询中..."));
        return false;
    }
    isQuerying = true;
    document.getElementById(key).value = gt.gettext("查询中...");
    return true;
}
 
/**
 * 绘制曲线图
 * @param {*} chartID 图表ID,关联html中的元素ID
 * @param {*} chartText 图表总标题
 * @param {*} xText x轴文本, 如等级
 * @param {*} yText y轴文本, 如人数
 * @param {*} labels x轴刻度文本列表, 如 等级列表
 * @param {*} datasetDataList 数据表数据列表,即每条线的数据,线的数据长度必须与x轴刻度文本列表长度一致
 * @param {*} datasetLabList 数据表标题列表,即每条线的标题,有几条线的数据即有几个标题
 */
 function drawChart_Line(chartID, chartText, xText, yText, labels, datasetDataList, datasetLabList = []) {
    var backgroundColors = [
        'rgba(79, 66, 255, 0.2)',
        'rgba(255, 99, 132, 0.2)',
        'rgba(255, 206, 86, 0.2)',
        'rgba(54, 162, 235, 0.2)',
        'rgba(75, 192, 192, 0.2)',
        'rgba(153, 102, 255, 0.2)',
        'rgba(255, 159, 64, 0.2)'
    ];
 
    var borderColors = [
        'rgba(79, 66, 255, 1)',
        'rgba(255, 99, 132, 1)',
        'rgba(255, 206, 86, 1)',
        'rgba(54, 162, 235, 1)',
        'rgba(75, 192, 192, 1)',
        'rgba(153, 102, 255, 1)',
        'rgba(255, 159, 64, 1)'
    ];
 
    var colorIndex = 0;
    var datasets = [];
    for (let i = 0; i < datasetDataList.length; i++) {
        datasets.push({
            label: datasetLabList.length > i ? datasetLabList[i] : "",
            data: datasetDataList[i],
            backgroundColor: backgroundColors[colorIndex % backgroundColors.length],
            borderColor: borderColors[colorIndex % borderColors.length],
            borderWidth: 1,
            lineTension: 0.5,
            pointRadius: 1
        });
        colorIndex += 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: chartText
                }
            },
            scales: {
                x: {
                    title: {
                        display: true,
                        text: xText
                    }
                },
                y: {
                    title: {
                        display: true,
                        text: yText
                    },
                    beginAtZero: true,
                    ticks: {
                        stepSize: 1, // 刻度间隔1
                    }
                }
            }
        }
    });
}