photo.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. $(document).ready(function () {
  2. $(".logo").on("click", function () {
  3. window.location.href = "https://www.bibidd.com";
  4. });
  5. $(".quanpinghei").hide();
  6. var uid = localStorage.getItem("uid");
  7. if (uid) {
  8. $("#register").text("My Collection");
  9. $("#login").text("Log out");
  10. $("#login").css("backgroundColor", "#D6565A");
  11. } else {
  12. $("#register").text("Sign up");
  13. $("#login").text("Login");
  14. $("#login").css("backgroundColor", "#CE5C2A");
  15. }
  16. // 获取标签数据
  17. var labelcurrentid = 1;
  18. var labelDataArray = [];
  19. var lpage = 1;
  20. var labelname = "";
  21. function getlabelData(videopage) {
  22. $(".box").show();
  23. $.ajax({
  24. type: "post",
  25. url: "https://www.bibidd.com/bibidd/Media/shouye_resou_img_video",
  26. dataType: "json",
  27. data: {
  28. type: "img",
  29. page: videopage,
  30. },
  31. success: function (res) {
  32. labelDataArray = res.data;
  33. },
  34. complete: function (res) {
  35. // 分页
  36. let code = res.responseJSON.code;
  37. let dataNum = res.responseJSON.all_num;
  38. $(function () {
  39. $("#pagination3").pagination({
  40. currentPage: labelcurrentid,
  41. totalPage: Math.ceil(dataNum / 30),
  42. isShow: true,
  43. count: 7,
  44. homePageText: "One",
  45. endPageText: "Last",
  46. prevPageText: "Prev",
  47. nextPageText: "Next",
  48. callback: function (current) {
  49. labelcurrentid = current;
  50. getlabelData(labelcurrentid);
  51. },
  52. });
  53. Math.ceil(dataNum / 30) < 2?$('.firstPage').show():$('.firstPage').hide();
  54. });
  55. let labelHtml = "";
  56. labelHtml += '<div class="hotLabel">';
  57. $.each(labelDataArray, function (index, data) {
  58. labelHtml += '<div class="label">';
  59. labelHtml += "<p >" + data.name + "</p>";
  60. labelHtml += "<p >" + data.num + "</p>";
  61. labelHtml += "</div>";
  62. });
  63. labelHtml += "</div>";
  64. $(".labelpage").html(labelHtml);
  65. // 标签检索图片
  66. $(".label").on("click", function () {
  67. let nn = $(this).find("p").eq(0).text();
  68. $(location).attr('href', 'photo.html?labelname='+nn+'?status='+1);
  69. return;
  70. loadVideoBackground();
  71. $(".videopage").show();
  72. $(".labelpage").hide();
  73. let name = $(this).find("p").eq(0).text();
  74. $("h2").text(name);
  75. labelname = name;
  76. lpage = 1;
  77. getLabelVideoData(1);
  78. });
  79. },
  80. });
  81. }
  82. var dataArray = [];
  83. var allDataArray = [];
  84. var videotype = "zuixin";
  85. let currentid = 1;
  86. // 获取图片数据
  87. function getData(videopage) {
  88. $("#tip").hide();
  89. clearScroll();
  90. $('.bottomLoadContent').show();
  91. $.ajax({
  92. type: "post",
  93. url: "https://www.bibidd.com/bibidd/Media/imgs_info_list",
  94. dataType: "json",
  95. data: {
  96. type: videotype,
  97. page: videopage,
  98. },
  99. success: function (res) {
  100. allDataArray = res.data;
  101. dataArray = [];
  102. if (allDataArray.length > 0) {
  103. let showDataNum =
  104. allDataArray.length % 12 === 0 ? 12 : allDataArray.length % 12;
  105. for (let i = 0; i < showDataNum; i++) {
  106. dataArray.push(allDataArray[i]);
  107. }
  108. }
  109. },
  110. complete: function (res) {
  111. ispage = true;
  112. // 分页
  113. let code = res.responseJSON.code;
  114. let dataNum = res.responseJSON.all_num;
  115. $(function () {
  116. $("#pagination3").pagination({
  117. currentPage: currentid,
  118. totalPage: Math.ceil(dataNum / 36),
  119. isShow: true,
  120. count: 7,
  121. homePageText: "One",
  122. endPageText: "Last",
  123. prevPageText: "Prev",
  124. nextPageText: "Next",
  125. callback: function (current) {
  126. currentid = current;
  127. getData(currentid, videotype);
  128. },
  129. });
  130. Math.ceil(dataNum / 36) < 2?$('.firstPage').show():$('.firstPage').hide();
  131. });
  132. createDomHtml(dataArray);
  133. $("html, body").animate(
  134. {
  135. scrollTop: 0,
  136. },
  137. 10
  138. );
  139. },
  140. });
  141. }
  142. let url = window.location.search;
  143. var theRequest = new Object();
  144. if (url.indexOf("?") != -1) {
  145. var str = url.substr(1);
  146. strs = str.split("&");
  147. for (var i = 0; i < strs.length; i++) {
  148. theRequest[strs[i].split("=")[0]] = unescape(
  149. decodeURIComponent(strs[i].split("=")[1])
  150. );
  151. }
  152. }
  153. if (theRequest.navtag) {
  154. $("#tip").hide();
  155. // 其他页面进入首页
  156. if (theRequest.navtag === "Hot search") {
  157. getlabelData(labelcurrentid);
  158. $(".videopage").hide();
  159. $(".labelpage").show();
  160. } else {
  161. loadVideoBackground();
  162. $(".videopage").show();
  163. $(".labelpage").hide();
  164. if (
  165. theRequest.navtag !== "Newest" &&
  166. theRequest.navtag !== "Hot" &&
  167. theRequest.navtag !== "Recommend" &&
  168. theRequest.navtag !== "Hot search"
  169. ) {
  170. $(".searchInput").val(theRequest.navtag);
  171. $("h2").text("Image Search-" + theRequest.navtag);
  172. searchVideo(1);
  173. } else {
  174. $("h2").text(theRequest.navtag + " picture");
  175. if (theRequest.navtag === "Newest") {
  176. videotype = "zuixin";
  177. } else if (theRequest.navtag === "Hot") {
  178. videotype = "remen";
  179. } else if (theRequest.navtag === "Recommended") {
  180. videotype = "tuijian";
  181. }
  182. currentid = 1;
  183. getData(1);
  184. }
  185. }
  186. }else if(theRequest.labelname){
  187. labelname = theRequest.labelname;
  188. console.log(theRequest);
  189. console.log(theRequest.labelname);
  190. $("h2").text(theRequest.labelname);
  191. getLabelVideoData(1);
  192. } else {
  193. // 进入首页
  194. videotype = "zuixin";
  195. currentid = 1;
  196. getData(1);
  197. }
  198. if (theRequest.navtag) {
  199. // 其他页面进入首页
  200. if (theRequest.navtag === "Hot search") {
  201. getlabelData(labelcurrentid);
  202. $(".videopage").hide();
  203. $(".labelpage").show();
  204. } else {
  205. $("h2").text(
  206. theRequest.navtag !== "Newest" &&
  207. theRequest.navtag !== "Hot" &&
  208. theRequest.navtag !== "Recommend" &&
  209. theRequest.navtag !== "Hot search"
  210. ? "Image Search-" + theRequest.navtag
  211. : theRequest.navtag + " picture"
  212. );
  213. loadVideoBackground();
  214. $(".videopage").show();
  215. $(".labelpage").hide();
  216. if (theRequest.navtag === "Newest") {
  217. videotype = "zuixin";
  218. } else if (theRequest.navtag === "Hot") {
  219. videotype = "remen";
  220. } else if (theRequest.navtag === "Recommend") {
  221. videotype = "tuijian";
  222. }
  223. currentid = 1;
  224. getData(1);
  225. }
  226. } else {
  227. // 进入首页
  228. videotype = "zuixin";
  229. currentid = 1;
  230. getData(1);
  231. }
  232. // 热门tag分类
  233. $(".nav li").on("click", function () {
  234. clearScroll();
  235. $('.bottomLoadContent').show();
  236. const pname = $(this).find("p").eq(0).text();
  237. const arr = ["zuixin", "remen", "tuijian"];
  238. $("h2").text(pname + " picture");
  239. if (
  240. $(this).index() === 0 ||
  241. $(this).index() === 1 ||
  242. $(this).index() === 2
  243. ) {
  244. $(".videopage").show();
  245. $(".labelpage").hide();
  246. loadVideoBackground();
  247. videotype = arr[$(this).index()];
  248. currentid = 1;
  249. getData(1);
  250. } else {
  251. getlabelData(labelcurrentid);
  252. $(".videopage").hide();
  253. $(".labelpage").show();
  254. }
  255. });
  256. // 图片搜索
  257. $(".searchBtn").on("click", function () {
  258. $("#tip").hide();
  259. if (!$(".searchInput").val().trim()) {
  260. // 请输入搜索关键字
  261. tip("Please enter the search content");
  262. } else {
  263. loadVideoBackground();
  264. $(".videopage").show();
  265. searchVideo(1);
  266. $(".labelpage").hide();
  267. $("h2").text("Image Search-" + $(".searchInput").val().trim());
  268. }
  269. });
  270. $(document).on("keyup", function (event) {
  271. if (event.keyCode == 13) {
  272. $(".searchBtn").trigger("click");
  273. }
  274. });
  275. // 底部标签栏
  276. $(".tabbar li").on("click", function () {
  277. if ($(this).index() === 0) {
  278. $(location).attr("href", 'https://www.bibidd.com?status='+1);
  279. }
  280. // } else if ($(this).index() === 1) {
  281. // $(location).attr("href", "novel.html");
  282. // }
  283. });
  284. // 注册/登录
  285. $(".accountRight").on("click", function () {
  286. $(".loginBox").show();
  287. });
  288. $(".guanbi").on("click", function () {
  289. $(".loginBox").hide();
  290. });
  291. // 查看我的收藏
  292. $("#register").on("click", function () {
  293. if ($(this).text() === "My Collection") {
  294. $(location).attr("href", 'collection.html?status='+1);
  295. } else {
  296. // 注册
  297. $(location).attr("href", 'register.html?status=0?status='+1);
  298. }
  299. $(".loginBox").hide();
  300. });
  301. // 登录/退出登录
  302. $("#login").on("click", function () {
  303. if ($(this).text() === "Log out") {
  304. // 退出登录
  305. localStorage.removeItem("uid");
  306. location.reload();
  307. } else {
  308. // 登录
  309. $(location).attr("href", 'login.html?status='+1);
  310. }
  311. $(".loginBox").hide();
  312. });
  313. // 返回顶部
  314. $(".backToTop").on("click", function () {
  315. $("html, body").animate(
  316. {
  317. scrollTop: 0,
  318. },
  319. 500
  320. );
  321. });
  322. // 获取标签图片
  323. function getLabelVideoData(labelpage) {
  324. clearScroll();
  325. $('.bottomLoadContent').show();
  326. $.ajax({
  327. type: "post",
  328. url: "https://www.bibidd.com/bibidd/Media/select_type_detail",
  329. dataType: "json",
  330. data: {
  331. type_name: labelname,
  332. type: "img",
  333. page: labelpage,
  334. },
  335. success: function (res) {
  336. allDataArray = res.data;
  337. dataArray = [];
  338. if (allDataArray.length > 0) {
  339. let showDataNum =
  340. allDataArray.length % 12 === 0 ? 12 : allDataArray.length % 12;
  341. for (let i = 0; i < showDataNum; i++) {
  342. dataArray.push(allDataArray[i]);
  343. }
  344. }
  345. },
  346. complete: function (res) {
  347. ispage = true;
  348. // 分页
  349. let code = res.responseJSON.code;
  350. let dataNum = res.responseJSON.all_num;
  351. $(function () {
  352. $("#pagination3").pagination({
  353. currentPage: lpage,
  354. totalPage: Math.ceil(dataNum / 36),
  355. isShow: true,
  356. count: 7,
  357. homePageText: "One",
  358. endPageText: "Last",
  359. prevPageText: "Prev",
  360. nextPageText: "Next",
  361. callback: function (current) {
  362. lpage = current;
  363. getLabelVideoData(lpage);
  364. },
  365. });
  366. Math.ceil(dataNum / 36) < 2?$('.firstPage').show():$('.firstPage').hide();
  367. });
  368. createDomHtml(dataArray);
  369. $("html, body").animate(
  370. {
  371. scrollTop: 0,
  372. },
  373. 10
  374. );
  375. },
  376. });
  377. }
  378. // 图片加载背景
  379. function loadVideoBackground() {
  380. }
  381. // 视频搜索
  382. var searchcurrentid = 1;
  383. function searchVideo(videopage) {
  384. clearScroll();
  385. $('.bottomLoadContent').show();
  386. let searchInputVal = $(".searchInput").val();
  387. $.ajax({
  388. type: "post",
  389. url: "https://www.bibidd.com/bibidd/Media/sousuo_img_video",
  390. dataType: "json",
  391. data: {
  392. type_name: searchInputVal,
  393. type: "img",
  394. page: videopage,
  395. },
  396. success: function (res) {
  397. allDataArray = res.data;
  398. if(allDataArray.length==0) {
  399. $("#tip").show();
  400. $(".tiptext").text('The data you need is not found.');
  401. $('.bottomLoadContent').hide();
  402. }else{
  403. $("#tip").hide();
  404. }
  405. dataArray = [];
  406. if (allDataArray.length > 0) {
  407. let showDataNum =
  408. allDataArray.length % 12 === 0 ? 12 : allDataArray.length % 12;
  409. for (let i = 0; i < showDataNum; i++) {
  410. dataArray.push(allDataArray[i]);
  411. }
  412. }
  413. },
  414. complete: function (res) {
  415. ispage = true;
  416. // 分页
  417. let code = res.responseJSON.code;
  418. let dataNum = res.responseJSON.all_num;
  419. $(function () {
  420. $("#pagination3").pagination({
  421. currentPage: searchcurrentid,
  422. totalPage: Math.ceil(dataNum / 36),
  423. isShow: true,
  424. count: 7,
  425. homePageText: "One",
  426. endPageText: "Last",
  427. prevPageText: "Prev",
  428. nextPageText: "Next",
  429. callback: function (current) {
  430. searchcurrentid = current;
  431. searchVideo(searchcurrentid, videotype);
  432. },
  433. });
  434. Math.ceil(dataNum / 36) < 2?$('.firstPage').show():$('.firstPage').hide();
  435. });
  436. createDomHtml(dataArray);
  437. $("html, body").animate(
  438. {
  439. scrollTop: 0,
  440. },
  441. 10
  442. );
  443. },
  444. });
  445. }
  446. function tip(text) {
  447. $("#tip").show();
  448. $(".tiptext").text(text);
  449. setTimeout(() => {
  450. $("#tip").hide();
  451. }, 1000);
  452. }
  453. // 上拉加载更多
  454. var showVideoNum = 12;
  455. var ispage = true;
  456. $(window).scroll(function () {
  457. var scrollT = $(document).scrollTop();
  458. var offsetT = $(".main").offset().top;
  459. if (scrollT >= offsetT) {
  460. $(".backToTop").show();
  461. } else {
  462. $(".backToTop").hide();
  463. }
  464. let windowHeight = $(window).height();
  465. let windowScrollTop = $(window).scrollTop();
  466. let loadingHeight = $('.bottomLoadContent').height();
  467. if (windowHeight + windowScrollTop + loadingHeight >= $(document).height()) {
  468. if (ispage) {
  469. ispage = false;
  470. if (showVideoNum != 36) {
  471. $(".bottomLoadContent").show();
  472. $(".box").hide();
  473. showVideoNum += 12;
  474. showVideoNum =
  475. showVideoNum > allDataArray.length
  476. ? allDataArray.length
  477. : showVideoNum;
  478. dataArray = [];
  479. for (let i = 0; i < 12; i++) {
  480. dataArray.push(allDataArray[(showVideoNum-12+i)]);
  481. console.log(showVideoNum-12+i);
  482. }
  483. let videoHtml = "";
  484. $.each(dataArray, function (index, data) {
  485. videoHtml += '<div class="videoContent">';
  486. videoHtml +=
  487. '<div class="lazy videoPhoto" data-original="' +
  488. data.top_img +
  489. '"></div>';
  490. videoHtml += ' <div class="videoTitle">' + data.title + "</div>";
  491. videoHtml += ' <div class="videoData">';
  492. videoHtml += " <!-- 观看次数 -->";
  493. videoHtml += ' <div class="videoDataLeft">';
  494. videoHtml +=
  495. ' <img class="videoDataImgLook" src="/Public/bibidd/images/look.png" alt="" />';
  496. videoHtml +=
  497. ' <div id="looks" class="videoText">' +
  498. data.views +
  499. "</div>";
  500. videoHtml += " </div>";
  501. videoHtml += " <!-- 点赞次数 -->";
  502. videoHtml += ' <div class="videoDataRgiht">';
  503. videoHtml +=
  504. ' <img class="videoDataImgZan" src="/Public/bibidd/images/zan.png" alt="" />';
  505. videoHtml +=
  506. ' <div class="videoText">' + data.thumbs_up + "</div>";
  507. videoHtml += " </div>";
  508. videoHtml += " </div>";
  509. videoHtml += "</div>";
  510. });
  511. setTimeout(() => {
  512. $(".video").append(videoHtml);
  513. $(".bottomLoadContent").hide();
  514. var loadingUrl = "/Public/bibidd/images/loading.png";
  515. $(".lazy").lazyload({
  516. effect: "show",
  517. placeholder: loadingUrl,
  518. failurelimit: 10,
  519. skip_invisible: false,
  520. });
  521. $(".videoContent").on("click", function () {
  522. let looks = $(this).find("#looks").eq(0).text();
  523. $(this).find("#looks").eq(0).text(Number(looks)+1);
  524. $(location).attr("href","bphotodetails.html?imgid=" +
  525. allDataArray[$(this).index()].id +
  526. "&fabulous=" +
  527. allDataArray[$(this).index()].thumbs_up +
  528. "&favorite=" +
  529. allDataArray[$(this).index()].favorite +
  530. '?status='+1
  531. );
  532. });
  533. ispage = true;
  534. }, 1000);
  535. } else {
  536. $(".bottomLoadContent").hide();
  537. $(".box").show();
  538. ispage = true;
  539. }
  540. }
  541. }
  542. });
  543. // 创建视频dom元素
  544. function createDomHtml(dataArray) {
  545. let videoHtml = "";
  546. $.each(dataArray, function (index, data) {
  547. videoHtml += '<div class="videoContent">';
  548. videoHtml +=
  549. '<div class="lazy videoPhoto" data-original="' +
  550. data.top_img +
  551. '"></div>';
  552. videoHtml += ' <div class="videoTitle">' + data.title + "</div>";
  553. videoHtml += ' <div class="videoData">';
  554. videoHtml += " <!-- 观看次数 -->";
  555. videoHtml += ' <div class="videoDataLeft">';
  556. videoHtml +=
  557. ' <img class="videoDataImgLook" src="/Public/bibidd/images/look.png" alt="" />';
  558. videoHtml += ' <div id="looks" class="videoText">' + data.views + "</div>";
  559. videoHtml += " </div>";
  560. videoHtml += " <!-- 点赞次数 -->";
  561. videoHtml += ' <div class="videoDataRgiht">';
  562. videoHtml +=
  563. ' <img class="videoDataImgZan" src="/Public/bibidd/images/zan.png" alt="" />';
  564. videoHtml += ' <div class="videoText">' + data.thumbs_up + "</div>";
  565. videoHtml += " </div>";
  566. videoHtml += " </div>";
  567. videoHtml += "</div>";
  568. });
  569. $(".video").html(videoHtml);
  570. var loadingUrl = "/Public/bibidd/images/loading.png";
  571. $(".lazy").lazyload({
  572. effect: "show",
  573. placeholder: loadingUrl,
  574. failurelimit: 10,
  575. skip_invisible: false,
  576. });
  577. // 查看视频详情
  578. $(".videoContent").on("click", function () {
  579. let looks = $(this).find("#looks").eq(0).text();
  580. $(this).find("#looks").eq(0).text(Number(looks)+1);
  581. $(location).attr("href","bphotodetails.html?imgid=" +
  582. dataArray[$(this).index()].id +
  583. "&fabulous=" +
  584. dataArray[$(this).index()].thumbs_up +
  585. "&favorite=" +
  586. dataArray[$(this).index()].favorite +
  587. '?status='+1
  588. );
  589. });
  590. }
  591. function clearScroll() {
  592. showVideoNum = 12;
  593. ispage = false;
  594. scrollT = 0;
  595. offsetT = 0;
  596. $(".bottomLoadContent").show();
  597. $(".box").hide();
  598. }
  599. $('.clearTextImg').on('click', function() {
  600. $('.searchInput').val('');
  601. })
  602. });