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
|
}
|
}
|
}
|
}
|
});
|
}
|