前端工具文件
编程语言
2018-06-05 05:12:19
阅读次数: 1
function UtileObj() {
this.Pagination = function (pageTotal, pageCount, currentPage) {
this.pageNumArray = [];
var pageStart,pageEnd;
if (currentPage <= pageCount / 2 + 1) {
pageStart = 1;
pageEnd = pageCount;
} else if (currentPage > pageCount / 2 + 1) {
pageStart = currentPage - pageCount / 2;
pageEnd = currentPage + pageCount / 2 - 1;
}
// 对pageEnd 进行校验,并重新赋值
if (pageEnd > pageTotal) {
pageEnd = pageTotal;
}
if (pageEnd <= pageCount) {// 当不足pageNum数目时,要全部显示,所以pageStart要始终置为1
pageStart = 1;
}
for (var i = pageStart; i <= pageEnd; i++) {
this.pageNumArray.push(i);
}
return (this.pageNumArray);
};
this.lazyloadJS = function (url) {
var t = document.createElement("script");
t.src = url;
document.body.appendChild(t);
};
this.lazyloadCCS = function (url) {
var t = document.createElement("link");
t.href = url;
t.rel = "stylesheet";
document.body.appendChild(t);
};
this.formatTime = function (date, type){
var date = new Date(date),
year = date.getFullYear(),
month = date.getMonth() + 1,
day = date.getDate(),
hour = date.getHours(),
minute = date.getMinutes(),
second = date.getSeconds();
switch (type) {
case 'hh:mm:ss YYYY-MM-dd':
return hour < 12? 'AM':'PM'+ ' ' +[hour, minute, second].map(this.formatNumber).join(':')+ ' ' + [year, month, day].map(this.formatNumber).join('-');
case 'dd-MM-YY':
// 一月:Jan .二月:Feb.三月:Mar. 四月:Apr.五月:May. 六月:Jun.
// 七月:Jul.八月:Aug.九月:Sept.十月:Oct.十一月:Nov.十二月:Dec.
var monthCn = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];
return [day, monthCn[month-1],year].map(this.formatNumber).join('-');
}
};
this.formatNumber = function (n){
n = n.toString();
return n[1] ? n : '0' + n
};
this.jeDateLinkage = function(timeId) {
var startTime = {
multiPane: true,
onClose: false,
isClear: false,
isToday: false, //是否显示清空
minDate: '2013-01-01 0:0:0',
maxDate: $.nowDate({DD: 0}), //最大日期 当前日期的前一天
format: 'YYYY-MM-DD',
okfun: function(obj){
table_param.time = (new Date(obj.val)).getTime();
},
clearfun:function(elem, val) {
table_param.time = '';
}
};
$('#' + timeId).jeDate(startTime);
};
this.timeoutLogin = function() {
var curtime = new Date().getTime(),
a = sessionStorage.getItem('loginTime') - (-owlzerOBj.G_DDP_SEESION_CHECK);
if (a < curtime) {
sessionStorage.clear();
Q.go('login');
} else {
sessionStorage.setItem('loginTime',curtime);
}
};
// 提示框
this.alertP = function(msg, time) {
var t = time || 1000,$alertId = $('#alertId');
$alertId.css('display','block');
$('#alertId .boostTip').html(msg);
var a = setTimeout(function () {
$alertId.css('display','none');
clearTimeout(a)
}, t)
}
}
<!--弹框提示信息-->
<div id="alertId" class="boostTipBox">
<div class="boostTip"></div>
</div>
/*提示框的样式*/
.boostTipBox {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 999;
}
.boostTip {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto auto;
width: 400px;
height: 128px;
line-height: 126px;
text-align: center;
border: 1px solid #dadada;
border-radius: 4px;
background: #fff;
box-shadow: 0 0 10px #bbb;
}
分页使用
table_allPages: owlzerOBj.UTILE.Pagination(data.error_info.totalPage, table_param.pageSize, table_param.pageNum)
<!--分页-->
<ul id="paginationId" class="carListFy margin_right_64">
</ul>
// 分页
var pageList = '';
$.each(tableObj.table_allPages, function (i, items) {
pageList += '<li class="carListPage" data-index="' + items + '">' + items + '</li>';
});
pageList += '<li id="carListAfter" class="carListAfter"></li><li class="carListPageTo"><span>跳到</span><input type="text" name="goToPage"/></li><li class="carListSure"><span id="goToPage">确定</span></li>';
// console.log(timeTd + list);
$pagId.html(pageList);
$("#paginationId").find(".carListPage").eq(table_param.pageNum - 1).addClass("bluePage").siblings().removeClass('bluePage');
/*分页*/
.carListFy {
margin: 10px auto 50px;
display: table
}
.carListFy > li {
display: table-cell;
vertical-align: middle
}
.carListPre {
height: 26px;
width: 26px;
border: 1px solid #dadada;
cursor: pointer;
background: url(../images/qamgr.png) no-repeat 10px -283px
}
.carListPreFirst {
background-position: 10px -263px;
}
.carListPage {
height: 26px;
min-width: 26px;
padding: 0 2px;
cursor: pointer;
border: 1px solid #dadada;
color: #27282A;
text-align: center;
line-height: 25px
}
.carListAfter {
height: 26px;
width: 26px;
border: 1px solid #dadada;
cursor: pointer;
background: url(../images/qamgr.png) no-repeat 10px -323px
}
.carListAfterLast {
background-position: 10px -303px;
}
.carListPageTo {
margin-left: 20px
}
.carListPageTo > span {
color: #686868;
padding-left: 10px
}
.carListPageTo > input {
border: 1px solid #dadada;
width: 40px;
line-height: 24px;
padding-left: 5px;
margin: 0 10px;
}
.carListSure {
color: #188AE2;
margin-left: 20px;
cursor: pointer
}
.margin_right_64 {
margin-right: 64px
}
.bluePage {
background: #188AE2;
color: #fff
}
.bg_e5e9f7 {
background: #e5e9f7;
}
转载自blog.csdn.net/web_cgh/article/details/80568971