search.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. {extend name="layout/base" /}
  2. {block name="title"}
  3. <title>麻花网络手机游戏_资讯_开服开测_礼包搜索_麻花网络</title>
  4. <meta name="keywords" content="手机游戏搜索,手机游戏资讯搜索,手机游戏开服开测搜索,手机游戏礼包搜索"/>
  5. <meta name="description" content="
  6. 麻花网络搜索功能,帮您找到想要的手机游戏以及全面的新闻资讯、游戏礼包等信息,输入关键字即可快速搜索。"/>
  7. {/block}
  8. {block name="header"}
  9. <link rel="stylesheet" href="__STATIC__/css/mobile/style.css">
  10. <link rel="stylesheet" href="__STATIC__/css/mobile/game-info.css">
  11. <style>
  12. .warp-search-cont{
  13. top: 0.556rem;
  14. z-index: 666;
  15. }
  16. .no_content{
  17. margin-top: 30%;
  18. }
  19. </style>
  20. {/block}
  21. {block name="content"}
  22. <!-- header start -->
  23. <header class="top">
  24. <div class="header search-page">
  25. <a href="javascript:history.back(-1)"><img src="__STATIC__/images/mobile/icon/left.png"></a>
  26. <div class="search">
  27. <input type="text" value="{$keyword}" autocomplete="off" class="search-content" id="keywords" />
  28. <img src="__STATIC__/images/mobile/icon/close-01.png" class="cancel">
  29. </div>
  30. <a href="javascript:;"><img src="__STATIC__/images/mobile/icon/search.png" class="input-search" id="search"></a>
  31. </div>
  32. <ul class="game_rec">
  33. <li><a href="javascript:;" class="active search_game">游戏 ({$list->total()})</a></li>
  34. <li><a href="javascript:;" class="search_new">资讯 ({$newsList->total()})</a></li>
  35. </ul>
  36. </header>
  37. <div class="warp-search-cont">
  38. <ul class="search_cont" id="search_ul">
  39. </ul>
  40. </div>
  41. <!-- header end -->
  42. <div class="game-list search-game">
  43. {volist name="list" id="vo"}
  44. <div class="game-info">
  45. <a href="{$vo.gameUrl}">
  46. {if($vo.libaonum)}
  47. <img src="__STATIC__/images/mobile/icon/gift.png" class="gift">
  48. {/if}
  49. <img lazy-src="{$vo.icon}" src="__STATIC__/images/icon/150-150.png" class="smallIcon" >
  50. <div class="content">
  51. <h4 class="title">{$vo.nickname}</h4>
  52. <p>{$vo.subject}<span>|</span>{$vo.type}<span>|</span>{$vo.size}</p>
  53. {if($vo['publicity'])}<P>{$vo.publicity}</P>{/if}
  54. </div>
  55. </a>
  56. <div class="download">
  57. <a href="javascript:;">下载</a>
  58. <p class="android_down_url">{$vo.download}</p>
  59. <p class="ios_down_url">{$vo.ios_download}</p>
  60. </div>
  61. </div>
  62. {/volist}
  63. {empty name="$list"}
  64. <!-- 无相关游戏 -->
  65. <div class="no_content" >
  66. <div>
  67. <img src="/static/images/mobile/icon/game.png">
  68. <p>抱歉暂未搜索到相关游戏,请换个关键词试一试吧!</p>
  69. </div>
  70. </div>
  71. <!-- 无相关游戏end-->
  72. {/empty}
  73. </div>
  74. <div class="info-new search-new hide" style="margin-top: 1rem;">
  75. {volist name="newsList" id="vo"}
  76. <div class="new-info">
  77. <a href="{$vo.url}"> <img lazy-src="{$vo.image}" src="__STATIC__/images/icon/990-625.png" class="new-img"></a>
  78. <div>
  79. <a href="{$vo.url}">
  80. <h4>{$vo.title}</h4>
  81. <p>{$vo.createtime}</p>
  82. </a>
  83. </div>
  84. </div>
  85. {/volist}
  86. {empty name="$newsList"}
  87. <!-- 无相关资讯 -->
  88. <div class="no_content">
  89. <div>
  90. <img src="/static/images/mobile/icon/information.png" style="width: 2rem;">
  91. <p>抱歉暂未搜索到相关资讯,请换个关键词试一试吧!</p>
  92. </div>
  93. </div>
  94. <!-- 无相关资讯end-->
  95. {/empty}
  96. </div>
  97. <div class="weui-loadmore">
  98. <i class="weui-loading"></i>
  99. <span class="weui-loadmore__tips">数据加载中,请稍等</span>
  100. </div>
  101. <div class="no-more-data"><span></span>已经到底啦(>_<)<span></span></div>
  102. {include file="layout/footer" /}
  103. {/block}
  104. {block name="detail_js"}
  105. <script>
  106. $(".search_new").click(function(){
  107. $(this).addClass("active");
  108. $(".search_game").removeClass("active");
  109. $(".game-list").addClass("hide");
  110. $(".search-new").removeClass("hide");
  111. $(".no-more-data").hide();
  112. // 底部位置
  113. var iHigh = document.body.clientHeight;
  114. var aHigh = $(window).height();
  115. var head = $("header").height();
  116. var h = $("footer").height();
  117. if (aHigh > (iHigh + head + h)) {
  118. $(".footer").addClass("fixed");
  119. }else{
  120. $(".footer").removeClass("fixed");
  121. }
  122. })
  123. $(".search_game").click(function(){
  124. $(this).addClass("active");
  125. $(".search_new").removeClass("active");
  126. $(".game-list").removeClass("hide");
  127. $(".search-new").addClass("hide");
  128. $(".no-more-data").hide();
  129. var iHigh = document.body.clientHeight;
  130. var aHigh = window.screen.height;
  131. var head = $("header").height();
  132. // var h = $("footer").height();
  133. if (aHigh > (iHigh + head)) {
  134. $(".footer").addClass("fixed");
  135. }else{
  136. $(".footer").removeClass("fixed");
  137. }
  138. })
  139. $('.search').on('click', function() {
  140. $('#keywords').focus();
  141. });
  142. $('.search').trigger('click');
  143. $(".search-content").keyup(function() {
  144. var text = $(this).val();
  145. text = text.replace(/\s*/g, "");
  146. if (text != "") {
  147. $.ajax({
  148. type: 'POST',
  149. url: '/game/ajaxGameList',
  150. dataType: 'json',
  151. data: { keyword: text },
  152. success: function (json) {
  153. if ($.isEmptyObject(json)) {
  154. $("#search_ul").empty();
  155. $(".warp-search-cont").hide();
  156. } else {
  157. var html = '',
  158. turl = '/game101';
  159. $.each(json, function (i, row) {
  160. toUrl = turl.replace('101', row.id)
  161. html += '<li><a href="' + row.url + '" target="_blank">' + row.nickname + '</a></li>';
  162. });
  163. arrow = '<div class="border-up-empty"><span></span></div>'
  164. $("#search_ul").html(html + arrow);
  165. }
  166. if($(".search_cont li").length > 0){
  167. $(".warp-search-cont").show();
  168. }else{
  169. $(".warp-search-cont").hide();
  170. }
  171. }
  172. });
  173. $(this).next().show();
  174. // $(".warp-search-cont").show();
  175. } else {
  176. $(this).next().hide();
  177. $("#search_ul").empty();
  178. $(".warp-search-cont").hide();
  179. }
  180. })
  181. $(".search-content").click(function(){
  182. if($(".search_cont li").length > 0){
  183. $(".warp-search-cont").show();
  184. }
  185. var text = $(this).val();
  186. text = text.replace(/\s*/g, "");
  187. if (text != "") {
  188. $.ajax({
  189. type: 'POST',
  190. url: '/game/ajaxGameList',
  191. dataType: 'json',
  192. data: { keyword: text },
  193. success: function (json) {
  194. if ($.isEmptyObject(json)) {
  195. $("#search_ul").empty();
  196. $(".warp-search-cont").hide();
  197. } else {
  198. var html = '',
  199. turl = '/game101';
  200. $.each(json, function (i, row) {
  201. toUrl = turl.replace('101', row.id)
  202. html += '<li><a href="' + toUrl + '">' + row.nickname + '</a></li>';
  203. });
  204. arrow = '<div class="border-up-empty"><span></span></div>'
  205. $("#search_ul").html(html + arrow);
  206. }
  207. if($(".search_cont li").length > 0){
  208. $(".warp-search-cont").show();
  209. }else{
  210. $(".warp-search-cont").hide();
  211. }
  212. }
  213. });
  214. $(this).next().show();
  215. // $(".warp-search-cont").show();
  216. } else {
  217. $(this).next().hide();
  218. $("#search_ul").empty();
  219. $(".warp-search-cont").hide();
  220. }
  221. })
  222. $(".cancel").click(function() {
  223. $(this).prev().val("");
  224. $(this).hide();
  225. $(".warp-search-cont").hide();
  226. $(".search_cont").html("");
  227. })
  228. // 粘贴事件监控
  229. $.fn.pasteEvents = function(delay) {
  230. if (delay == undefined) delay = 10;
  231. return $(this).each(function() {
  232. var $el = $(this);
  233. $el.on("paste", function() {
  234. $el.trigger("prepaste");
  235. setTimeout(function() {
  236. $el.trigger("postpaste");
  237. }, delay);
  238. });
  239. });
  240. };
  241. // 使用
  242. $(".search-content").on("postpaste", function() {
  243. var text = $(this).val();
  244. text = text.replace(/\s*/g, "");
  245. if (text != "") {
  246. $(this).next().show();
  247. $(".warp-search-cont").show();
  248. } else {
  249. $(this).next().hide();
  250. $(".warp-search-cont").hide();
  251. }
  252. }).pasteEvents();
  253. $(".warp-search-cont").click(function(e) {
  254. var target = $(e.target);
  255. if (target.closest(".search-content").length != 0) return;
  256. $(".warp-search-cont").hide();
  257. })
  258. // 加载更多
  259. var currentPage = parseInt("{$list->currentPage()}");
  260. var lastPage = parseInt("{$list->lastPage()}");
  261. var total = parseInt("{$list->total()}");
  262. var new_currentPage = parseInt("{$newsList->currentPage()}");
  263. var new_lastPage = parseInt("{$newsList->lastPage()}");
  264. var new_total = parseInt("{$newsList->total()}");
  265. var defaultImg = "__STATIC__/images/icon/150-150.png";
  266. $(".no-more-data").hide();
  267. var loading = false; //状态标记
  268. $(document.body).infinite(90).on("infinite", function() {
  269. if (loading) return;
  270. loading = true;
  271. if($('.search_game').hasClass("active")){
  272. // 游戏加载更多
  273. if (currentPage + 1 > lastPage) {
  274. $(".weui-loadmore").hide();
  275. if (currentPage > 1) {
  276. $(".no-more-data").show();
  277. }
  278. loading = false;
  279. return false;
  280. }else{
  281. $(".weui-loadmore").show();
  282. }
  283. var keyword = encodeURI('{$keyword}');
  284. setTimeout(function() {
  285. currentPage += 1;
  286. $.ajax({
  287. url: '/search/_getGameList' + '?keyword=' + keyword ,
  288. type: 'post',
  289. timeOut: 10000,
  290. dataType: 'json',
  291. data: {
  292. "page": currentPage
  293. },
  294. async: false,
  295. success: function (res) {
  296. console.log(res);
  297. var arr = res.list.data;
  298. arr.forEach(function(vo, index) {
  299. var html='';
  300. html += "<div class='game-info'>"+
  301. "<a href='"+vo.gameUrl+"'>"+
  302. "<img lazy-src='"+vo.icon+"' src='/static/images/icon/150-150.png' class='smallIcon' />"+
  303. "<div class='content'><h4>"+vo.nickname+"</h4><p>"+vo.subject+"<span>|</span>"+vo.type+"<span>|</span>"+vo.size+"</p>";
  304. if(vo.publicity){
  305. html += "<P>"+vo.publicity+"</P>";
  306. }
  307. html += "</div></a>"+
  308. "<div class='download'>"+
  309. "<a href='javascript:;'>下载</a>"+
  310. "<p class='android_down_url'>"+vo.download+"</p>"+
  311. "<p class='ios_down_url'>"+vo.ios_download+"</p></div></div>";
  312. $(".game-list").append(html);
  313. });
  314. },
  315. error: function() {
  316. $.alert("网络错误,请刷新页面重试");
  317. }
  318. });
  319. $.getScript("/static/js/mobile/reload.js");
  320. $(".weui-loadmore").hide();
  321. loading = false;
  322. }, 500); //模拟延迟
  323. }else{
  324. // 资讯加载更多
  325. if (new_currentPage + 1 > new_lastPage) {
  326. $(".weui-loadmore").hide();
  327. if (new_currentPage > 1) {
  328. $(".no-more-data").show();
  329. }
  330. loading = false;
  331. return false;
  332. }else{
  333. $(".weui-loadmore").show();
  334. }
  335. $(".no-more-data").hide();
  336. $(".weui-loadmore").show();
  337. setTimeout(function() {
  338. var keyword = encodeURI('{$keyword}');
  339. new_currentPage += 1;
  340. $.ajax({
  341. url: '/search/_getNewsList' + '?keyword=' + keyword ,
  342. type: 'post',
  343. timeOut: 10000,
  344. dataType: 'json',
  345. data: {
  346. "page": new_currentPage
  347. },
  348. async: false,
  349. success: function (res) {
  350. console.log(res);
  351. var arr = res.list.data;
  352. arr.forEach(function(vo, index) {
  353. var html='';
  354. html += '<div class="new-info">'+
  355. '<a href="'+vo.url+'"> <img lazy-src="'+vo.image+'" src="__STATIC__/images/icon/990-625.png" class="new-img"></a>'+
  356. '<div>'+
  357. '<a href="'+vo.url+'">'+
  358. '<h4>'+vo.title+'</h4>'+
  359. '<p>'+vo.createtime+'</p></a>'+
  360. '</div>'+
  361. '</div>';
  362. $(".info-new").append(html);
  363. });
  364. },
  365. error: function() {
  366. $.alert("网络错误,请刷新页面重试");
  367. }
  368. });
  369. $.getScript("/static/js/mobile/reload.js");
  370. $(".weui-loadmore").hide();
  371. loading = false;
  372. }, 500); //模拟延迟
  373. }
  374. });
  375. // 搜索历史
  376. if($(".history-search ul li").length ==0){
  377. $(".history-search").hide();
  378. }else{
  379. $(".history-search").show();
  380. }
  381. $(function(){
  382. update_history();
  383. // 绑定回车事件
  384. $(document).keydown(function(event){
  385. if(event.keyCode==13){
  386. $("#search").click();
  387. }
  388. });
  389. // 搜索点击事件
  390. $("#search").click(function(){
  391. var keywords = $("#keywords").val();
  392. keywords= keywords.replace(/\s*/g, "");
  393. historya(keywords); //添加到缓存
  394. update_history(); //更新搜索历史
  395. if (keywords == ""){
  396. keywords ="空之轨迹";
  397. }
  398. location.href = "/search/keyword/" + keywords;
  399. })
  400. })
  401. /**
  402. * [update_history 更新搜索历史]
  403. * @return {[type]} [description]
  404. */
  405. function update_history(){
  406. console.log(mystorage.get("keywords"));
  407. var history = mystorage.get("keywords");
  408. if (history) {
  409. var html = "";
  410. $.each(history,function(i,v){
  411. html += "<li><a href=''>"+v+"</a><a href='javascript:;' class='delete'><img src='/static/images/mobile/icon/close.png'></a></li>"
  412. })
  413. $(".history-search ul").html(html);
  414. };
  415. if($(".history-search ul li").length ==0){
  416. $(".history-search").hide();
  417. }else{
  418. $(".history-search").show();
  419. }
  420. // 点击删除历史
  421. $(".delete").click(function(){
  422. var tqtest = $(this).prev().html();
  423. var history = mystorage.get("keywords");
  424. history.splice($.inArray(tqtest,history),1);
  425. mystorage.set("keywords",history);
  426. $(this).parents("li").remove();
  427. update_history();
  428. })
  429. }
  430. /**
  431. * [history //搜索历史函数存储]
  432. * @param {[type]} value [搜索词]
  433. * @return {[type]} [description]
  434. */
  435. function historya(value){
  436. var data = mystorage.get("keywords");
  437. if (!data) {
  438. var data = []; //定义一个空数组
  439. }else if(data.length === 10){ //搜索历史数量
  440. data.pop(); //删除数组最后一个元素
  441. }else{
  442. };
  443. if (value) { //判断搜索词是否为空
  444. if (data.indexOf(value)<0) { //判断搜索词是否存在数组中
  445. // data.push(value); //搜索词添加到数组中
  446. data.splice(0, 0,value); //搜索词添加到数组第一个位置
  447. mystorage.set("keywords",data); //存储到本地化存储中
  448. }else{
  449. data.splice($.inArray(value,data),1);
  450. data.splice(0, 0,value); //搜索词添加到数组第一个位置
  451. mystorage.set("keywords",data); //存储到本地化存储中
  452. };
  453. };
  454. }
  455. /**
  456. * [mystorage 存储localstorage时候最好是封装一个自己的键值,在这个值里存储自己的内容对象,封装一个方法针对自己对象进行操作。避免冲突也会在开发中更方便。]
  457. * @param {String} ){ var ms [description]
  458. * @return {[type]} [description]
  459. console.log(mystorage.set('tqtest','tqtestcontent'));//存储
  460. console.log(mystorage.set('aa','123'));//存储
  461. console.log(mystorage.set('tqtest1','tqtestcontent1'));//存储
  462. console.log(mystorage.set('tqtest1','newtqtestcontent1'));//修改
  463. console.log(mystorage.get('tqtest'));//读取
  464. console.log(mystorage.remove('tqtest'));//删除
  465. mystorage.clear();//整体清除
  466. */
  467. var mystorage = (function mystorage(){
  468. var ms = "mystorage";
  469. var storage=window.localStorage;
  470. if(!window.localStorage){
  471. alert("浏览器不支持localstorage");
  472. return false;
  473. }
  474. var set = function(key,value){
  475. //存储
  476. var mydata = storage.getItem(ms);
  477. if(!mydata){
  478. this.init();
  479. mydata = storage.getItem(ms);
  480. }
  481. mydata = JSON.parse(mydata);
  482. mydata.data[key] = value;
  483. storage.setItem(ms,JSON.stringify(mydata));
  484. return mydata.data;
  485. };
  486. var get = function(key){
  487. //读取
  488. var mydata = storage.getItem(ms);
  489. if(!mydata){
  490. return false;
  491. }
  492. mydata = JSON.parse(mydata);
  493. return mydata.data[key];
  494. };
  495. var remove = function(key){
  496. //读取
  497. var mydata = storage.getItem(ms);
  498. if(!mydata){
  499. return false;
  500. }
  501. mydata = JSON.parse(mydata);
  502. delete mydata.data[key];
  503. storage.setItem(ms,JSON.stringify(mydata));
  504. return mydata.data;
  505. };
  506. var clear = function(){
  507. //清除对象
  508. storage.removeItem(ms);
  509. };
  510. var init = function(){
  511. storage.setItem(ms,'{"data":{}}');
  512. };
  513. return {
  514. set : set,
  515. get : get,
  516. remove : remove,
  517. init : init,
  518. clear : clear
  519. };
  520. })();
  521. </script>
  522. {/block}