此处公告通常对读者进行申明或对该WIKI某些规则进行公告,请在确认后修改本通告
本WIKI编辑权限开放,欢迎收藏起来防止迷路,也希望有爱的小伙伴和我们一起编辑哟~
编辑帮助:目录 • BWIKI反馈留言板
此处公告通常对读者进行申明或对该WIKI某些规则进行公告,请在确认后修改本通告。本WIKI编辑权限开放,欢迎收藏起来防止迷路,也希望有爱的小伙伴和我们一起编辑哟~
Widget:数据查询
<style> li.btn.queryParams.selected { color: #333 !important; background-color: #e6e6e6; border-color: #adadad; outline: 0; -webkit-box-shadow: inset 0 3px 5px rgba(0,0,0,.125); box-shadow: inset 0 3px 5px rgba(0,0,0,.125); } </style>
<nav style="text-align:right;" aria-label="Page navigation">
</nav>
<nav style="text-align:right;" aria-label="Page navigation">
</nav> <script type="text/javascript"> var submitBtnId = ""; var tableHeader = ("").replace("{ |", "{|"); var tableFooter = '\n|}'; var conditions = ""; var printColumn = paramsFormmatter("", "|?"); var parameters = paramsFormmatter(("").replace(/:/g, "="), "|"); var limit = ; var count = 0; var firstQuery = ""; window.onload = function (){ if(String(firstQuery) === "true") queryData(); bindClickEvents(); }
function bindClickEvents(){ $("body").on("click", ".btn.queryParams", function(){ var isSelected = $(this).hasClass("selected"); $(this)[isSelected?"removeClass":"addClass"]("selected"); }).on("click", "#" + submitBtnId, function(){ queryData() }).on("click", ".gridPageBtn, .gridFirstPageBtn, .gridLastPageBtn", function(){ if($(this).hasClass("hide") || $(this).hasClass("active")) return false; var page = $(this).attr("data-page") || $(this).text(); getPageData(limit, refreshPager(count, limit, page)); }) }
function queryData(){ conditions = getQueryParams(); $.getJSON( mw.util.wikiScript( 'api'), { format: 'json', action: 'parse', text: '{'+'{#ask:'+conditions +'|format=count}}', contentmodel: 'wikitext' }).done( function ( data ) { count = parseInt($(data.parse.text["*"]).text()); $("#queryCount").text(count); $("#queryLimit").text(limit); refreshPager(count, limit, 1); getPageData(limit, 1); }); }
function getPageData(limit, page){ limit = Number(limit); page = Number(page); var parametersTemp = parameters + "|limit=" + limit + "|offset=" + (page-1) * limit; var queryText = tableHeader + '{'+'{#ask:' + conditions + printColumn + parametersTemp + '}}' + tableFooter; $.getJSON( mw.util.wikiScript( 'api'), { format: 'json', action: 'parse', text: queryText, contentmodel: 'wikitext' }).done( function ( data ) { $("#queryDataGrid").html(data.parse.text["*"]) }); }
function refreshPager(count, limit, page){ var sumPage = Math.min(Math.ceil(Number(count)/Number(limit))); page = Number(page); page = page === 0 ? 1 : page; page = page < 0 ? sumPage : page; var pageStart = Math.max(1, page-2); var pageEnd = Math.min(Math.ceil(count/limit), pageStart + 4); pageStart = pageEnd <= 5 ? 1 : pageStart; var $a = $("<a>").attr({href:"#"}); var btnArray = []; for(var i = pageStart; i <= pageEnd; i++){
btnArray.push($("