“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;
?
? filter: alpha(opacity=50); /*IE濾鏡,透明度50%*/
+
? ? ? opacity: 0.5;
?
? -moz-opacity: 0.5; /*Firefox私有,透明度50%*/
+
? ? ? cursor: not-allowed;
?
? opacity: 0.5; /*其他,透明度50%*/
+
? ? }
?
? cursor: not-allowed;
+
? </style>
?
}
+
? <div class="pc_right">
?
</style>
+
? ? <div class="noresult unified-content"></div>
?
<div class="pc_right">
?
?
? <div class="noresult unified-content ">
?
?
?? </div>
?
?? </div>
?
</div>
+
? <script type="text/javascript">
?
<script src="https://recaptcha.net/recaptcha/api.js?render=6LfzZpYaAAAAADMx6JU1u9AqxAcJLknI3CUOUgDQ"></script>
+
? ? 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 currentPage = 0;
?+
? ? var pages = 1;
?+
? ? var allData = [];
?+
?
?+
? ? // 優(yōu)化分頁渲染
?+
? ? function paging(currentPage, arr) {
?+
? ? ? var html = '';
?+
? ? ? var skipNum = currentPage * pageSize;
?+
? ? ? var results = (skipNum + pageSize >= arr.length)? arr.slice(skipNum, arr.length): arr.slice(skipNum, skipNum + pageSize);
?+
? ? ? var len = results.length;
?+
? ? ? html += '<tr><th>地址</th><th>郵編</th></tr>';
?+
? ? ? 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>`;
?+
? ? ? }
?+
? ? ? $(".zipcode-datas").html(html);
?+
? ? }
?+
?
?+
? ? // 優(yōu)化上一頁
?+
? ? function previous() {
?+
? ? ? currentPage -= 1;
?+
? ? ? paging(currentPage, allData);
?+
? ? ? $(".paging li a:first").toggleClass("disabled", currentPage === 0);
?+
? ? ? $(".paging li a:last").removeClass("disabled");
?+
? ? }
?+
?
?+
? ? // 優(yōu)化下一頁
?+
? ? function next() {
?+
? ? ? currentPage += 1;
?+
? ? ? paging(currentPage, allData);
?+
? ? ? $(".paging li a:last").toggleClass("disabled", currentPage === pages - 1);
?+
? ? ? $(".paging li a:first").removeClass("disabled");
?+
? ? }
??
?
var pageSize = 12;
+
? ? function focusOnResults() {
?
var currentPage = 0;
+
? ? ? document.querySelector('.pc_right').scrollIntoView({ behavior: 'smooth' });
?
var pages = 1;
+
? ? }
?
var allData = [];
?
??
?
function paging(currentPage, arr) {
+
? ? // 統(tǒng)一顯示無結(jié)果信息
?
? var html = '';
+
? ? function displayNoResultMessage(message) {
?
? var skipNum = currentPage * pageSize;
+
? ? ? var msg = message || '抱歉,未查詢到結(jié)果!請嘗試使用更標準的地址進行查詢。';
?
? var results = (skipNum + pageSize >= arr.length)?arr.slice(skipNum, arr.length): arr.slice(skipNum, skipNum + pageSize);
+
? ? ? $(".noresult").html(`<img src="/skins/Green/resources/images/noresult.svg" alt="無結(jié)果" width="180px" height="auto"><p>${msg}</p>`);
?
? var len = results.length;
+
? ? ? focusOnResults();
?
? if (results[0].street!= '') {
?
?
? ? html += '<tr><th>地址</th><th>郵編</th></tr>';
?
?
? ? for (var i=0; i<len; i++) {
?
?
? ? ? html += '<tr><td>'+results[i].address+'</td><td><a href="/'+results[i].postcode+'">'+results[i].postcode+'</a></tr>';
?
?
?? ? }
?
?? ? }
?
? } else {
+
?
?
? ? html += '<tr><th>地址</th><th>郵編</th></tr>';
+
? ? // 一次性加載所有結(jié)果
?
? ? for (var i=0; i<len; i++) {
+
? ? function updateResults(obj) {
?
? ? ? html += '<tr><td>'+results[i].address+'</td><td><a href="/'+results[i].postcode+'">'+results[i].postcode+'</a></td></tr>';
+
? ? ? 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();
?
?? ? }
?
?? ? }
?
? }
?
?
? $(".zipcode-datas").html(html);
?
?
}
?
??
?
function previous() {
+
// 異步加載廣告
?
?? currentPage -= 1;
+
function loadAd() {
?
? paging(currentPage, allData);
+
?? var mobile_ad = `
?
? if (currentPage == 0) {
+
? ? <div class="unified-content ad-mobile">
?
? ? $(".paging li a:first").addClass("disabled");
+
? ? ? <div class="_c5d19wrylrj"></div>
?
? }
+
? ? </div>
?
?? $(".paging li a:last").removeClass("disabled");
+
?? `;
?
}
?
??
?
function next() {
+
?? $(".pc_right").append(mobile_ad);
?
? currentPage += 1;
?
?
? paging(currentPage, allData);
?
?
? if (currentPage == pages-1) {
?
?
? ? $(".paging li a:last").addClass("disabled");
?
?
? }
?
?
?? $(".paging li a:first").removeClass("disabled");
?
?
}
?
??
?
function focusOnResults() {
+
? // 動態(tài)加載廣告腳本
?
?? document.querySelector('.pc_right').scrollIntoView({ behavior: 'smooth' });
+
?? 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);
?
}
?
}
??
?
</script>
+
?? ? function add() {
?
<script>
+
? ? ? var loc = getQueryVariable('loc');
?
?? ? window.onload = function() {
+
? ? ? var address = getQueryVariable('address');
?
? ? ? ? grecaptcha.execute('6LfzZpYaAAAAADMx6JU1u9AqxAcJLknI3CUOUgDQ', {action: 'homepage'}).then(function(token) {
+
? ? ? var city = getQueryVariable('city');
?
? ? ? ? ? ? // 調(diào)用add函數(shù)并傳入token
+
? ? ? if (loc || address || city) {
?
? ? ? ? ? ? add(token);
+
? ? ? ? var d = new Date();
?
? ? ? ? });
+
? ? ? ? var str = `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
?
? ? };
+
? ? ? ? var key = window.btoa(str + 'youbiankuyoubianku');
?
function add(token) {
+
? ? ? ? $.ajax({
?
? // 定義三個廣告代碼 特別需要注意的是百度聯(lián)盟的廣告不能用反屏蔽代碼,要不然無法正常解析 2021-09-16
+
? ? ? ? ? url: "http://www.foodsell.com.cn/api/youbianku_zhannei_search.php",
?
? 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>';
+
? ? ? ? ? type: "POST",
?
? 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>';
+
? ? ? ? ? data: { address: decodeURI(address), loc: decodeURI(loc), city: decodeURI(city), key: key },
?
? loc = getQueryVariable('loc');
+
? ? ? ? ? success: (obj) => {
?
? address = getQueryVariable('address');
+
? ? ? ? ? ? var obj = JSON.parse(obj);
?
? city = getQueryVariable('city');
+
? ? ? ? ? ? if (obj.msg) {
?
? if (loc!= '' || address!= '' || city!= '') {
+
? ? ? ? ? ? ? displayNoResultMessage(obj.msg);
?
? ? var d = new Date();
+
? ? ? ? ? ? ? return;
?
? ? var str = d.getFullYear()+'-'+(d.getMonth()+1)+'-'+ d.getDate();
?
?
? ? var key = window.btoa(str+'youbiankuyoubianku');
?
?
? ? $.ajax({
?
?
? ? ? url: "http://www.foodsell.com.cn/api/youbianku_zhannei_search.php",
?
?
? ? ? type: "POST",
?
?
? ? ? data: { address: decodeURI(address), loc: decodeURI(loc), city: decodeURI(city), key: key,token:token},
?
?
? ? ? 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) {
?
? ? ? ? ? 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>';
+
? ? ? ? ? ? ? displayNoResultMessage();
?
? ? ? ? ? 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>';
+
?? ? ? ? ? ? ? return;
?
? ? ? ? ? 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>';
+
? ? ? ? });
?
? ? ? ? ? if (pages > 1) {
+
?? ? ? } else {
?
? ? ? ? ? ? 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>';
+
?? ? ? ? displayNoResultMessage('抱歉,沒有查詢條件!');
?
? ? ? ? ? }
+
?? ? ? }
?
? ? ? ? ? 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;
+
?
?
? ? ? ? ? $(".pc_right").html(html);
+
?? ? window.onload = add;
?
? ? ? ? ? paging(0, obj.results);
+
?? </script>
?
? ? ? ? ? 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é)果!請嘗試使用更標準的地址進行查詢。比如:在查詢詞的前面加上城市或者區(qū)縣。</P>');
?
?
? ? ? ? focusOnResults();
?
?
? ? ? },
?
?
?? ? ? complete: () => {}
?
?
?? ? });
?
?
? ? ? gtag('event', 'search', {
?
?
? ? ? ? 'event_category': 'zhanneisearch',
?
?
? ? ? ? 'event_label': $("input#content").val(),
?
?
? ? ? ? 'value': $("input#content").val()
?
?
? ? ? });
?
?
? } else {
?
?
?? ? $(".noresult").html('<img src="/skins/Green/resources/images/noresult.svg" alt="無結(jié)果" width="180px" height="auto"><p>抱歉,沒有查詢條件!</P>');
?
?
? ? focusOnResults();
?
?
?? }
?
?
}
?
?
</script>
?
?
</html>
?
</html>
?
{{DISPLAYTITLE:搜索結(jié)果}}
?

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