Javascrpt 页面工具
* 笔者:DL
* 时间:2014-3-19
* PagingTool模块提供最基本的、网页工具栏。和页面数据 回电话 可扩展性 分页工具栏介绍,和页面呈现的数据
* 主意事项:必须引用json.js
* @module PagingTool
*/
var PagingTool = {}
PagingTool.Init = {} //初始化參数
PagingTool.funPageCallBack = function (data) {
var pParams = data.pParams;//查询參数
var pageCount = data.pageCount;//每页显示条目
var totalPages = data.totalPages;//总页数
var pageIndex = data.pParams.intNowPage; // 当前页
var pageTargetId = data.pageTargetId;
var totalCount = data.totalCount;
var pageHtml = "";
if (totalPages > 1) {
var beginPage = 1, endPage = 1;
beginPage = parseInt((pageIndex - 1) / pageCount) * pageCount + 1;
endPage = parseInt((pageIndex - 1) / pageCount) * pageCount + pageCount;
endPage = endPage > totalPages ?
totalPages : endPage;
if (pageIndex > 1) //上一页
{
pParams["intNowPage"] = 1;
pageHtml += '<a href=\"javascript:;\" onclick=\'PagingTool.Paging(' + JSON.stringify(pParams) + ')\'><<</a>';
pParams["intNowPage"] = pageIndex - 1;
pageHtml += '<a href=\"javascript:;\" onclick=\'PagingTool.Paging(' + JSON.stringify(pParams) + ')\'><</a>'
}
else {
pageHtml += '<a href=\"javascript:;\" ><<</a>'
pageHtml += '<a href=\"javascript:;\" ><</a>'
}
if (beginPage - 1 > 1) {
pParams["intNowPage"] = beginPage - 1;
pageHtml += '<a href=\"javascript:;\" onclick=\'PagingTool.Paging(' + JSON.stringify(pParams) + ')\'>...</a>'
}
//中间页码
for (var i = beginPage; i <= endPage; i++) {
if (pageIndex == i) {
pageHtml += '<a href=\"javascript:;\" class=\"current\"> ' + i + '</a>';
}
else {
pParams["intNowPage"] = i;
pageHtml += '<a href=\"javascript:;\" onclick=\'PagingTool.Paging(' + JSON.stringify(pParams) + ')\'>' + i + '</a>'
}
}
if (totalPages - endPage > 1) {
pParams["intNowPage"] = endPage + 1;
pageHtml += '<a href=\"javascript:;\" onclick=\'PagingTool.Paging(' + JSON.stringify(pParams) + ')\'>...</a>'
}
if (pageIndex < totalPages) {
pParams["intNowPage"] = pageIndex + 1;
pageHtml += '<a href=\"javascript:;\" onclick=\'PagingTool.Paging(' + JSON.stringify(pParams) + ')\'>></a>'
pParams["intNowPage"] = totalPages;
pageHtml += '<a href=\"javascript:;\" onclick=\'PagingTool.Paging(' + JSON.stringify(pParams) + ')\'>>></a>';
}
else {
pageHtml += '<a href=\"javascript:;\" >></a>'
pageHtml += '<a href=\"javascript:;\">>></a>'
}
$("#" + pageTargetId).html(pageHtml);
} else {
$("#" + pageTargetId).html("");
}
}
/**
* 返回当前集合中指定位置的元素
* @method PagingTool.Paging 分页操作方法
* @param {pParams} 查询条件 { "intUstate": 0, "intNowPage": 1, "intType": 1, "intPageSize": 3 }
* @return {HTML} 返回html loadingIcon.gif
*/
PagingTool.Paging = function (pParams) {
var funDCallBack = PagingTool.Init.DataCallBack;
var funPCallBack = PagingTool.Init.PageCallBack
var appendId = PagingTool.Init.AppendId;
var targetId = PagingTool.Init.PageTargetId;
var pageSize = PagingTool.Init.PageSize;
var pageCount = PagingTool.Init.PageCount;
$.ajax({
url: PagingTool.Init.Url,
data: pParams,
type: PagingTool.Init.Type,
dataType: "json",
beforeSend: function () {
var isElement = document.getElementById(appendId).nodeName;
var html = "";
if (isElement == "DIV") {
html = '<div id="sload" style="text-align:center; margin-top:30px;"><image src="/Content/image/base/loadingIcon.gif" /></div>';
}
else {
html = '<tr id="sload"><td colspan="50" style="text-align:center;"><image src="/Content/image/base/loadingIcon.gif" /></td></tr>';
}
$("#" + appendId).html(html);
},
complete: function () {
$("#sload").remove();
},
error: function () {
$("#sload").remove();
},
success: function (data) {
var totalCount = data.TotalCount;
var jieanCount = data.jieanCount;
if (totalCount > 0) {
var totalPages = parseInt((totalCount - 1) / pageSize + 1);
var callDBackParams = { "appendId": appendId, "jsonData": data, "totalCount": totalCount, "jieanCount": jieanCount };
var callPBackParams = { "pageTargetId": targetId, "pageSize": pageSize, "totalPages": totalPages, "pageCount": pageCount, "totalCount": totalCount, "pParams": pParams };
funDCallBack(callDBackParams);//回到函数
funPCallBack(callPBackParams);//分页控件回调函数
}
else {
var desc = returnNull(appendId, 20, "", "");//提示没有数据
$("#" + appendId + "").html(desc);
$("#" + targetId + "").html("");
//没有数据
}
}
});
}
/* 方法说明 使用说明 方法 PageTargetId【分页条呈现位置ID】 AppendId【数据呈现ID】DataCallBack【数据回调函数】PageCallBack【页面呈现回调函数】
PagingTool.Init = { "Url": "/LshSystem/User/AjaxIndex", "Type": "POST", "PageCount": 3, "PageSize": 3, "PageTargetId": "pageId", "AppendId": "appendId", "DataCallBack": funDataCallBack, "PageCallBack": PagingTool.funPageCallBack };
PagingTool.Paging({ "intUstate": 0, "intNowPage": 1, "intType": 1, "intPageSize": 3 });
//数据回调函数 页面操作逻辑
funDataCallBack= function(data) {
var appendId = data.appendId;
var jsonData = data.jsonData.PageData;
var htmlData = "";
for (var i = 0; i < jsonData.length; i++) { //便利数据
htmlData += "<tr id=\"Temp" + i + "\">" +
"<td class=\"thcenter\">" +
"<input type=\"checkbox\" value=\"" + jsonData[i].UAccount + "\" name=\"ckUAccount\" /></td>" +
"<td id=\"UAccount\">" + jsonData[i].UAccount + "</td>" +
"<td id=\"SFName\">" + jsonData[i].SFName + "</td> </tr>"
}
$("#" + appendId + "").html(htmlData);
}
*/
版权声明:本文博客原创文章,博客,未经同意,不得转载。