“SearchResultstest”的版本間的差異

來自Youbianku
第1行: 第1行:
?
<html>
?
<html>
?
? <style>
+
<style>
?
? ? div.pc_right td {
+
div.pc_right td {
?
? ? ? padding: 10px 10px;
+
? padding:10px 10px;
?
? ? }
+
}
?
? ? .pc_right li {
+
.pc_right li {
?
? ? ? color: #555;
+
? color: #555;
?
? ? ? font-size: 15px;
+
? font-size: 15px;
?
? ? ? line-height: 18px;
+
? line-height: 18px;
?
? ? ? margin-top: 8px;
+
? margin-top: 8px;
?
? ? ? word-wrap: break-word;
+
? word-wrap: break-word;
?
? ? }
+
}
?
? ? .paging {
+
.paging {
?
? ? ? float: right;
+
? float:right;
?
? ? }
+
}
?
? ? .paging li {
+
.paging li {
?
? ? ? display: inline-block;
+
? display: inline-block;
?
? ? ? padding-left: 20px;
+
? padding-left:20px;
?
? ? }
+
}
?
? ? .paging li a {
+
.paging li a {
?
? ? ? cursor: pointer;
+
? cursor: pointer;
?
? ? }
+
}
?
? ? .noresult {
+
.noresult {
?
? ? ? font-weight: bold;
+
? font-weight: bold;
?
? ? ? text-align: center;
+
? text-align: center;
?
? ? }
+
}
?
? ? .noresult p {
+
.noresult p {
?
? ? ? margin-top: 6px;
+
? margin-top: 6px;
?
? ? }
+
}
?
? ? a.disabled {
+
a.disabled {
?
? ? ? pointer-events: none;
+
? pointer-events: none;
?
? ? ? opacity: 0.5;
+
? filter: alpha(opacity=50); /*IE濾鏡,透明度50%*/
?
? ? ? cursor: not-allowed;
+
? -moz-opacity: 0.5; /*Firefox私有,透明度50%*/
?
? ? }
+
? opacity: 0.5; /*其他,透明度50%*/
?
? </style>
+
? cursor: not-allowed;
?
? <div class="pc_right">
+
}
?
? ? <div class="noresult unified-content"></div>
+
</style>
?+
<div class="pc_right">
?+
? <div class="noresult unified-content ">
?
?? </div>
?
?? </div>
?
? <script type="text/javascript">
+
</div>
?
? ? function getQueryVariable(variable) {
+
<script type='text/javascript'>
?
? ? ? var query = window.location.search.substring(1);
+
function getQueryVariable(variable) {
?
? ? ? var pos = query.indexOf('loc');
+
? var query = window.location.search.substring(1);
?
? ? ? var str = query[pos - 1];
+
? var pos = query.indexOf('loc');
?
? ? ? var vars = query.split(str);
+
? var str = query[pos-1];
?
? ? ? for (var i = 0; i < vars.length; i++) {
+
? var vars = query.split(str);
?
? ? ? ? var pair = vars[i].split("=");
+
? for (var i=0; i<vars.length; i++) {
?
? ? ? ? if (pair[0] == variable) { return pair[1]; }
+
? ? var pair = vars[i].split("=");
?
? ? ? }
+
? ? if(pair[0] == variable){return pair[1];}
?
? ? ? return '';
+
? }
?
? ? }
+
? return '';
?+
}
??
?
? ? var pageSize = 12;
+
var pageSize = 12;
?
? ? var currentPage = 0;
+
var currentPage = 0;
?
? ? var pages = 1;
+
var pages = 1;
?
? ? var allData = [];
+
var allData = [];
??
?
? ? // 優(yōu)化分頁渲染
+
function paging(currentPage, arr) {
?
? ? function paging(currentPage, arr) {
+
? var html = '';
?
? ? ? var html = '';
+
? var skipNum = currentPage * pageSize;
?
? ? ? var skipNum = currentPage * pageSize;
+
? var results = (skipNum + pageSize >= arr.length)?arr.slice(skipNum, arr.length): arr.slice(skipNum, skipNum + pageSize);
?
? ? ? var results = (skipNum + pageSize >= arr.length)? arr.slice(skipNum, arr.length): arr.slice(skipNum, skipNum + pageSize);
+
? var len = results.length;
?
? ? ? var len = results.length;
+
? if (results[0].street!= '') {
?
? ? ? html += '<tr><th>地址</th><th>郵編</th></tr>';
+
? ? html += '<tr><th>地址</th><th>郵編</th></tr>';
?
? ? ? for (var i = 0; i < len; i++) {
+
? ? for (var i=0; i<len; i++) {
?
? ? ? ? html += `<tr><td>${results[i].address}</td><td><a href="/${results[i].postcode}">${results[i].postcode}</a></td></tr>`;
+
? ? ? html += '<tr><td>'+results[i].address+'</td><td><a href="/'+results[i].postcode+'">'+results[i].postcode+'</a></tr>';
?
? ? ? }
?
?
? ? ? $(".zipcode-datas").html(html);
?
?
?? ? }
?
?? ? }
?
?
+
? } else {
?
?? ? // 優(yōu)化上一頁
+
?? ? html += '<tr><th>地址</th><th>郵編</th></tr>';
?
?? ? function previous() {
+
?? ? for (var i=0; i<len; i++) {
?
?? ? ? currentPage -= 1;
+
?? ? ? html += '<tr><td>'+results[i].address+'</td><td><a href="/'+results[i].postcode+'">'+results[i].postcode+'</a></td></tr>';
?
? ? ? paging(currentPage, allData);
?
?
? ? ? $(".paging li a:first").toggleClass("disabled", currentPage === 0);
?
?
? ? ? $(".paging li a:last").removeClass("disabled");
?
?
?? ? }
?
?? ? }
?+
? }
?+
? $(".zipcode-datas").html(html);
?+
}
??
?
? ? // 優(yōu)化下一頁
+
function previous() {
?
? ? function next() {
+
? currentPage -= 1;
?
? ? ? currentPage += 1;
+
? paging(currentPage, allData);
?
? ? ? paging(currentPage, allData);
+
? if (currentPage == 0) {
?
? ? ? $(".paging li a:last").toggleClass("disabled", currentPage === pages - 1);
+
? ? $(".paging li a:first").addClass("disabled");
?
? ? ? $(".paging li a:first").removeClass("disabled");
+
? }
?
? ? }
+
? $(".paging li a:last").removeClass("disabled");
?+
}
??
?
? ? function focusOnResults() {
+
function next() {
?
? ? ? document.querySelector('.pc_right').scrollIntoView({ behavior: 'smooth' });
+
? currentPage += 1;
?
? ? }
+
? paging(currentPage, allData);
?
?
+
? if (currentPage == pages-1) {
?
? ? // 統(tǒng)一顯示無結(jié)果信息
+
? ? $(".paging li a:last").addClass("disabled");
?
? ? function displayNoResultMessage(message) {
+
? }
?
? ? ? var msg = message || '抱歉,未查詢到結(jié)果!請嘗試使用更標(biāo)準(zhǔn)的地址進行查詢。';
+
? $(".paging li a:first").removeClass("disabled");
?
? ? ? $(".noresult").html(`<img src="/skins/Green/resources/images/noresult.svg" alt="無結(jié)果" width="180px" height="auto"><p>${msg}</p>`);
+
}
?
? ? ? focusOnResults();
?
?
? ? }
?
?
?
?
?
? ? // 一次性加載所有結(jié)果
?
?
? ? function updateResults(obj) {
?
?
? ? ? var contentHtml = '';
?
?
? ? ? if (obj.num === 1) {
?
?
? ? ? ? contentHtml += `
?
?
? ? ? ? ? <ul class="serach-head unified-content">
?
?
? ? ? ? ? ? <div class="tabel_response">
?
?
? ? ? ? ? ? ? <table class="zipcode-datas"><tbody>
?
?
? ? ? ? ? ? ? ? <tr><th>地址</th><td>${obj.results[0].address}</td></tr>
?
?
? ? ? ? ? ? ? ? <tr><th>郵編</th><td><a href="/${obj.results[0].postcode}">${obj.results[0].postcode}</a></td></tr>
?
?
? ? ? ? ? ? ? </tbody></table>
?
?
? ? ? ? ? ? </div>
?
?
? ? ? ? ? </ul>
?
?
? ? ? ? `;
?
?
? ? ? ? var more = `
?
?
? ? ? ? ? <div class="content-msg unified-content">
?
?
? ? ? ? ? ? <h2 class="view-title common-color">${decodeURI(address)}更多查詢推薦</h2>
?
?
? ? ? ? ? ? <p class="top-space"><a href="/如何快速查詢某個地址所屬街道辦事處??Subject=${decodeURI(address)}">??立即查詢${decodeURI(address)}所屬街道辦事處</a></p>
?
?
? ? ? ? ? ? <p class="top-space"><a href="/如何快速查詢某個地址所屬派出所?Subject=${decodeURI(address)}">??立即查詢${decodeURI(address)}附近的派出所</p>
?
?
? ? ? ? ? </div>
?
?
? ? ? ? `;
?
?
? ? ? ? contentHtml += more;
?
?
? ? ? } else if (obj.num > 1) {
?
?
? ? ? ? pages = Math.ceil(obj.results.length / pageSize);
?
?
? ? ? ? contentHtml += `
?
?
? ? ? ? ? <div class="unified-content">
?
?
? ? ? ? ? ? <ul style="margin-bottom:20px;">
?
?
? ? ? ? ? ? ? <li><b>搜索詞:</b><span itemprop="name">${decodeURI(address)}</span></li>
?
?
? ? ? ? ? ? </ul>
?
?
? ? ? ? ? ? <div class="view-content-scroll">
?
?
? ? ? ? ? ? ? <table class="zipcode-datas top-space bottom-space"></table>
?
?
? ? ? ? ? ? </div>
?
?
? ? ? ? ? ? <ul class="paging">
?
?
? ? ? ? ? ? ? <li><a href="javascript:void(0);" onclick="previous();">上一頁</a></li>
?
?
? ? ? ? ? ? ? <li><a href="javascript:void(0);" onclick="next();">下一頁</a></li>
?
?
? ? ? ? ? ? </ul>
?
?
? ? ? ? ? </div>
?
?
? ? ? ? `;
?
?
? ? ? ? paging(0, obj.results);
?
?
? ? ? ? allData = obj.results;
?
?
? ? ? }
?
?
? ? ? contentHtml += `
?
?
? ? ? ? <div class="unified-content">
?
?
? ? ? ? ? <h2 class="view-title common-color">? 提出查詢要求</h2>
?
?
? ? ? ? ? <div class="content-msg">
?
?
? ? ? ? ? ? <p class="top-space"><a target="_blank" rel="noreferrer noopener" href="/Special:Form/%E6%9F%A5%E8%AF%A2%E8%A6%81%E6%B1%82?Subject=${decodeURI(address)}">提出查詢“${decodeURI(address)}”的要求</a></p>
?
?
? ? ? ? ? ? <p class="top-space">點擊以上鏈接,可提出自己的查詢要求,管理員和網(wǎng)友會及時進行<a href="/%E7%95%99%E8%A8%80%E5%9B%9E%E5%A4%8D" title="留言回復(fù)">留言回復(fù)</a>。</p>
?
?
? ? ? ? ? </div>
?
?
? ? ? ? </div>
?
?
? ? ? `;
?
?
? ? ? $(".pc_right").html(contentHtml);
?
?
? ? ? focusOnResults();
?
?
? ? }
?
?
?
?
?
// 異步加載廣告
?
?
function loadAd() {
?
?
? var mobile_ad = `
?
?
? ? <div class="unified-content ad-mobile">
?
?
? ? ? <div class="_c5d19wrylrj"></div>
?
?
? ? </div>
?
?
? `;
?
??
?
? $(".pc_right").append(mobile_ad);
+
function focusOnResults() {
?
?
+
?? document.querySelector('.pc_right').scrollIntoView({ behavior: 'smooth' });
?
? // 動態(tài)加載廣告腳本
?
?
?? var script = document.createElement('script');
?
?
? script.type = 'text/javascript';
?
?
? script.src = '//cpro.baidustatic.com/cpro/ui/cm.js';
?
?
? script.async = true;
?
?
? document.body.appendChild(script);
?
?
}
?
}
??
?
? ? function add() {
+
</script>
?
? ? ? var loc = getQueryVariable('loc');
+
<script>
?
? ? ? var address = getQueryVariable('address');
+
function add() {
?
? ? ? var city = getQueryVariable('city');
+
? // 定義三個廣告代碼 特別需要注意的是百度聯(lián)盟的廣告不能用反屏蔽代碼,要不然無法正常解析 2021-09-16
?
? ? ? if (loc || address || city) {
+
? var pc_ad = '<div class="unified-content ad-pc"><div class="_guq2pst47gb"></div><script type="text/javascript">(window.slotbydup = window.slotbydup || []).push({id: "u6626265",container: "_guq2pst47gb",async: true});<\/script></div>';
?
? ? ? ? var d = new Date();
+
? var mobile_ad = '<div class="unified-content ad-mobile"><div class="_c5d19wrylrj"></div><script type="text/javascript">(window.slotbydup = window.slotbydup || []).push({id: "u6626285",container: "_c5d19wrylrj",async: true});<\/script><script type="text/javascript" src="//cpro.baidustatic.com/cpro/ui/cm.js" async="async" defer="defer" ><\/script></div>';
?
? ? ? ? var str = `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
+
? loc = getQueryVariable('loc');
?
? ? ? ? var key = window.btoa(str + 'youbiankuyoubianku');
+
? address = getQueryVariable('address');
?
? ? ? ? $.ajax({
+
? city = getQueryVariable('city');
?
? ? ? ? ? url: "http://www.foodsell.com.cn/api/youbianku_zhannei_search.php",
+
? if (loc!= '' || address!= '' || city!= '') {
?
? ? ? ? ? type: "POST",
+
? ? var d = new Date();
?
? ? ? ? ? data: { address: decodeURI(address), loc: decodeURI(loc), city: decodeURI(city), key: key },
+
? ? var str = d.getFullYear()+'-'+(d.getMonth()+1)+'-'+ d.getDate();
?
? ? ? ? ? success: (obj) => {
+
? ? var key = window.btoa(str+'youbiankuyoubianku');
?
? ? ? ? ? ? var obj = JSON.parse(obj);
+
? ? $.ajax({
?
? ? ? ? ? ? if (obj.msg) {
+
? ? ? url: "http://www.foodsell.com.cn/api/youbianku_zhannei_search.php",
?
? ? ? ? ? ? ? displayNoResultMessage(obj.msg);
+
? ? ? type: "POST",
?
?? ? ? ? ? ? ? return;
+
? ? ? data: { address: decodeURI(address), loc: decodeURI(loc), city: decodeURI(city), key: key },
?+
? ? ? success: (obj) => {
?+
? ? ? ? var obj = JSON.parse(obj);
?+
? ? ? ? if (obj.msg) {
?+
? ? ? ? ? var message = '<img src="/skins/Green/resources/images/noresult.svg" alt="無結(jié)果" width="180px" height="auto"><p>很抱歉!該查詢暫無結(jié)果!';
?+
? ? ? ? ? if (obj.msg === '1') {
?+
? ? ? ? ? ? message += '如果您需要查詢英文地址的郵編,推薦訪問:<a href="http://www.foodsell.com.cn/%E5%9B%BD%E9%99%85%E9%82%AE%E7%BC%96">國際郵編查詢</a>';
?+
? ? ? ? ? } else {
?+
? ? ? ? ? ? message += '請重新輸入地址進行查詢!';
?+
? ? ? ? ? }
?+
? ? ? ? ? message += '</p>';
?+
? ? ? ? ? $(".noresult").html(message);
?+
? ? ? ? ? focusOnResults();
?+
? ? ? ? ? return false;
?+
? ? ? ? }
?+
? ? ? ? if (obj.results.length == 0) {
?+
? ? ? ? ? $(".noresult").html('<img src="/skins/Green/resources/images/noresult.svg" alt="無結(jié)果" width="180px" height="auto"><p>很抱歉!該查詢暫無結(jié)果!</P>');
?+
? ? ? ? ? focusOnResults();
?+
? ? ? ? ? return false;
?+
? ? ? ? }
?+
? ? ? ? if (obj.num == 1) {
?+
? ? ? ? ? var itemFront = '<ul class="serach-head unified-content"><div class="tabel_response"><table class="zipcode-datas"><tbody>';
?+
? ? ? ? ? if (address!= '') {
?+
? ? ? ? ? ? if (loc == '') {
?+
?? ? ? ? ? ? ? itemFront += '<tr><th>搜索詞</th><td>'+decodeURI(address)+'</td></tr>';
?
?? ? ? ? ? ? }
?
?? ? ? ? ? ? }
?
?? ? ? ? ? ? if (obj.results.length === 0) {
+
? ? ? ? ? }
?
? ? ? ? ? ? ? displayNoResultMessage();
+
? ? ? ? ? itemFront += '<tr><th>地址</th><td>'+obj.results[0].address+'</td></tr><tr><th>郵編</th><td><a href="'+'/'+obj.results[0].postcode+'" >'+obj.results[0].postcode+'</a></td></tr>';
?
?? ? ? ? ? ? ? return;
+
? ? ? ? ? var more = '<div class="content-msg unified-content"><h2 class="view-title common-color">'+decodeURI(address)+'更多查詢推薦</h2><p class="top-space"><a href="/如何快速查詢某個地址所屬街道辦事處??Subject='+decodeURI(address)+'">??立即查詢'+decodeURI(address)+'所屬街道辦事處</a></p><p class="top-space"><a href="/如何快速查詢某個地址所屬派出所?Subject='+decodeURI(address)+'">??立即查詢'+decodeURI(address)+'附近的派出所</p></div></a>';
?+
? ? ? ? ? var more2 = '<div class="unified-content"><h2 class="view-title common-color"><span id="提出查詢要求"></span><span class="mw-headline" id=".E6.8F.90.E5.87.BA.E6.9F.A5.E8.AF.A2.E8.A6.81.E6.B1.82">提出查詢要求</span></h2><div class="content-msg"><p class="top-space"><a target="_blank" rel="noreferrer noopener" class="external text" href="/Special:Form/%E6%9F%A5%E8%AF%A2%E8%A6%81%E6%B1%82?Subject='+decodeURI(address)+'">提出查詢“'+decodeURI(address)+'”的要求</a></p><p class="top-space">點擊以上鏈接,可提出自己的查詢要求,管理員和網(wǎng)友會及時進行<a href="/%E7%95%99%E8%A8%80%E5%9B%9E%E5%A4%8D" title="留言回復(fù)">留言回復(fù)</a>。</p></div></div>';
?+
? ? ? ? ? var itemEnd = '</tbody></table class="top-space"></div></ul>'+mobile_ad+'<div style="width:100%;">'+more+more2;
?+
? ? ? ? ? if (obj.results[0].street!= '') {
?+
?? ? ? ? ? ? $(".pc_right").html(itemFront+itemEnd);
?+
? ? ? ? ? } else {
?+
? ? ? ? ? ? $(".pc_right").html(itemFront+itemEnd);
?+
? ? ? ? ? }
?+
? ? ? ? ? focusOnResults();
?+
? ? ? ? } else if (obj.num > 1) {
?+
? ? ? ? ? pages = parseInt(obj.results.length / pageSize) + 1;
?+
? ? ? ? ? var html = '<div class="unified-content"><ul style="margin-bottom:20px;">';
?+
? ? ? ? ? if (address!= '') {
?+
? ? ? ? ? ? if (loc == '') {
?+
?? ? ? ? ? ? ? html += '<li><b>搜索詞:</b><span itemprop="name">'+decodeURI(address)+'</span></li>';
?
?? ? ? ? ? ? }
?
?? ? ? ? ? ? }
?
? ? ? ? ? ? updateResults(obj);
?
?
? ? ? ? ? },
?
?
? ? ? ? ? error: () => {
?
?
? ? ? ? ? ? displayNoResultMessage();
?
?
? ? ? ? ? },
?
?
? ? ? ? ? complete: () => {
?
?
? ? ? ? ? ? loadAd();
?
?
?? ? ? ? ? }
?
?? ? ? ? ? }
?
? ? ? ? });
+
? ? ? ? ? html += '</ul><div class="view-content-scroll"><table class="zipcode-datas top-space bottom-space"></table></div>';
?
?? ? ? } else {
+
? ? ? ? ? if (pages > 1) {
?
?? ? ? ? displayNoResultMessage('抱歉,沒有查詢條件!');
+
? ? ? ? ? ? html += '<ul class="paging"><li><a href="javascript:void(0);" onclick="previous();">上一頁</a></li><li><a href="javascript:void(0);" onclick="next();">下一頁</a></li></ul><div style="clear:both;"></div>';
?
?? ? ? }
+
? ? ? ? ? }
?
?? ? }
+
? ? ? ? ? var more2 = '</div>'+mobile_ad+'<div class="unified-content"><h2 class="view-title common-color"><span id="提出查詢要求"></span><span class="mw-headline">? 提出查詢要求</span></h2><div class="content-msg"><p class="top-space"><a target="_blank" rel="noreferrer noopener" class="external text" href="/Special:Form/%E6%9F%A5%E8%AF%A2%E8%A6%81%E6%B1%82?Subject='+decodeURI(address)+'">提出查詢“'+decodeURI(address)+'”的要求</a></p><p class="top-space">點擊以上鏈接,可提出自己的查詢要求,管理員和網(wǎng)友會及時進行<a href="/%E7%95%99%E8%A8%80%E5%9B%9E%E5%A4%8D" title="留言回復(fù)">留言回復(fù)</a>。</p></div></div>';
?
?
+
? ? ? ? ? html += more2;
?
?? ? window.onload = add;
+
? ? ? ? ? $(".pc_right").html(html);
?
? </script>
+
? ? ? ? ? paging(0, obj.results);
?+
? ? ? ? ? allData = obj.results;
?+
? ? ? ? ? $(".paging li a:first").addClass("disabled");
?+
? ? ? ? ? focusOnResults();
?+
? ? ? ? }
?+
?? ? ? },
?+
? ? ? error: (error) => {
?+
?? ? ? ? $(".noresult").html('<img src="/skins/Green/resources/images/noresult.svg" alt="無結(jié)果" width="180px" height="auto"><p>抱歉,未查詢到結(jié)果!請嘗試使用更標(biāo)準(zhǔn)的地址進行查詢。比如:在查詢詞的前面加上城市或者區(qū)縣。</P>');
?+
? ? ? ? focusOnResults();
?+
?? ? ? },
?+
? ? ? complete: () => {}
?+
?? ? });
?+
? } else {
?+
?? ? $(".noresult").html('<img src="/skins/Green/resources/images/noresult.svg" alt="無結(jié)果" width="180px" height="auto"><p>抱歉,沒有查詢條件!</P>');
?+
? ? focusOnResults();
?+
? }
?+
}
?+
window.onload = add;
?+
</script>
?
</html>
?
</html>
?+
{{DISPLAYTITLE:搜索結(jié)果}}

2025年2月17日 (一) 15:53的版本