You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
5.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//十六进制颜色值域RGB格式颜色值之间的相互转换
//-------------------------------------
//十六进制颜色值的正则表达式
var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
/*RGB颜色转换为16进制*/
String.prototype.colorHex = function () {
var that = this;
if (/^(rgb|RGB)/.test(that)) {
var aColor = that.replace(/(?:\(|\)|rgb|RGB)*/g, "").split(",");
var strHex = "#";
for (var i = 0; i < aColor.length; i++) {
var hex = Number(aColor[i]).toString(16);
if (hex === "0") {
hex += hex;
}
strHex += hex;
}
if (strHex.length !== 7) {
strHex = that;
}
return strHex;
} else if (reg.test(that)) {
var aNum = that.replace(/#/, "").split("");
if (aNum.length === 6) {
return that;
} else if (aNum.length === 3) {
var numHex = "#";
for (var i = 0; i < aNum.length; i += 1) {
numHex += (aNum[i] + aNum[i]);
}
return numHex;
}
} else {
return that;
}
};
//-------------------------------------------------
/*16进制颜色转为RGB格式*/
String.prototype.colorRgb = function () {
var sColor = this.toLowerCase();
if (sColor && reg.test(sColor)) {
if (sColor.length === 4) {
var sColorNew = "#";
for (var i = 1; i < 4; i += 1) {
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
}
sColor = sColorNew;
}
//处理六位的颜色值
var sColorChange = [];
for (var i = 1; i < 7; i += 2) {
sColorChange.push(parseInt("0x" + sColor.slice(i, i + 2)));
}
return "RGB(" + sColorChange.join(",") + ")";
} else {
return sColor;
}
};
//-------------------------------------------------
// var sRgb = "RGB(255, 255, 255)" , sHex = "#00538b";
// var sHexColor = sRgb.colorHex();//转换为十六进制方法
// var sRgbColor = sHex.colorRgb();//转为RGB颜色值的方法
// console.log(sHexColor);
// console.log(sRgbColor);
/**
* 获取指定年月的最后一天
* @param {Number} year 年份,公元年
* @param {Number} month 月份有效值1~12
* @return {Number} 返回1~31之间的一个数
*/
function getLastDay(year, month) {
var d = new Date(0);
if (month == 12) {
d.setUTCFullYear(year + 1);
d.setUTCMonth(0);
} else {
d.setUTCFullYear(year);
d.setUTCMonth(month);
}
d.setTime(d.getTime() - 1);
return d.getUTCDate();
}
/**
* 功能:转换字符串到日期
*/
function convertStrToDate(date) {
date = date.substring(0, 19);
date = date.replace(/-/g, '/');
var timestamp = new Date(date).getTime();
// 根据毫秒数构建 Date 对象
var d1 = new Date(timestamp);
return d1;
}
//迭代方式实现
function padding1(num, length) {
for (var len = (num + "").length; len < length; len = num.length) {
num = "0" + num;
}
return num;
}
//检查是否为正浮点数
function isFloat(str) {
var reg = /^(0|[1-9]\d*|[1-9]\d*\.\d+|0\.\d*[1-9]\d*)$/;
if (reg.test(str)) {
return true;
} else {
return false;
}
}
//获取cookie
function getCookie(name) {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg))
return unescape(arr[2]);
else
return null;
}
//为了能在表格中上下左右和回车键操作,黄海也是拼了~
$(document).on('keydown', '.layui-table-edit', function (e) {
var td = $(this).parent('td')
, tr = td.parent('tr')
, trs = tr.parent().parent().find("tr")
, tr_index = tr.index()
, td_index = td.index()
, td_last_index = tr.find('[data-edit ="text"]:last').index()
, td_first_index = tr.find('[data-edit ="text"]:first').index();
switch (e.keyCode) {
// 右39
case 39:
td.nextAll('[data-edit ="text"]:first').click();
if (td_index == td_last_index) {
tr.next().find('td').eq(td_first_index).click();
if (tr_index == trs.length - 1)
trs.eq(0).find('td').eq(td_first_index).click();
}
setTimeout(function () {
$('.layui-table-edit').select()
}, 0);
break;
// 左37
case 37:
td.prevAll('[data-edit="text"]:first').click();
setTimeout(function () {
$('.layui-table-edit').select()
}, 0);
break;
//上38
case 38:
tr.prev().find('td').eq(td_index).click();
setTimeout(function () {
$('.layui-table-edit').select()
}, 0);
break;
//chr(13) 回车
case 13:
// 下40
case 40:
tr.next().find('td').eq(td_index).click();
setTimeout(function () {
$('.layui-table-edit').select()
}, 0);
break;
}
});