photo.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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/Mediaonefive/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);
  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/Mediaonefive/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 === "Classify") {
  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 !== "Classify"
  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. $("h2").text(theRequest.labelname);
  189. getLabelVideoData(1);
  190. } else {
  191. // 进入首页
  192. videotype = "zuixin";
  193. currentid = 1;
  194. getData(1);
  195. }
  196. if (theRequest.navtag) {
  197. // 其他页面进入首页
  198. if (theRequest.navtag === "Classify") {
  199. getlabelData(labelcurrentid);
  200. $(".videopage").hide();
  201. $(".labelpage").show();
  202. } else {
  203. $("h2").text(
  204. theRequest.navtag !== "Newest" &&
  205. theRequest.navtag !== "Hot" &&
  206. theRequest.navtag !== "Recommend" &&
  207. theRequest.navtag !== "Classify"
  208. ? "Image Search-" + theRequest.navtag
  209. : theRequest.navtag + " picture"
  210. );
  211. loadVideoBackground();
  212. $(".videopage").show();
  213. $(".labelpage").hide();
  214. if (theRequest.navtag === "Newest") {
  215. videotype = "zuixin";
  216. } else if (theRequest.navtag === "Hot") {
  217. videotype = "remen";
  218. } else if (theRequest.navtag === "Recommend") {
  219. videotype = "tuijian";
  220. }
  221. currentid = 1;
  222. getData(1);
  223. }
  224. } else {
  225. // 进入首页
  226. videotype = "zuixin";
  227. currentid = 1;
  228. getData(1);
  229. }
  230. // 热门tag分类
  231. $(".nav li").on("click", function () {
  232. clearScroll();
  233. $('.bottomLoadContent').show();
  234. const pname = $(this).find("p").eq(0).text();
  235. const arr = ["zuixin", "remen", "tuijian"];
  236. $("h2").text(pname + " picture");
  237. if (
  238. $(this).index() === 0 ||
  239. $(this).index() === 1 ||
  240. $(this).index() === 2
  241. ) {
  242. $(".videopage").show();
  243. $(".labelpage").hide();
  244. loadVideoBackground();
  245. videotype = arr[$(this).index()];
  246. currentid = 1;
  247. getData(1);
  248. } else {
  249. getlabelData(labelcurrentid);
  250. $(".videopage").hide();
  251. $(".labelpage").show();
  252. }
  253. });
  254. // 图片搜索
  255. $(".searchBtn").on("click", function () {
  256. $("#tip").hide();
  257. if (!$(".searchInput").val().trim()) {
  258. // 请输入搜索关键字
  259. tip("Please enter the search content");
  260. } else {
  261. loadVideoBackground();
  262. $(".videopage").show();
  263. searchVideo(1);
  264. $(".labelpage").hide();
  265. $("h2").text("Image Search-" + $(".searchInput").val().trim());
  266. }
  267. });
  268. $(document).on("keyup", function (event) {
  269. if (event.keyCode == 13) {
  270. $(".searchBtn").trigger("click");
  271. }
  272. });
  273. // 底部标签栏
  274. $(".tabbar li").on("click", function () {
  275. if ($(this).index() === 0) {
  276. $(location).attr("href", 'https://www.bibidd.com/bibidd_testtest');
  277. }
  278. // } else if ($(this).index() === 1) {
  279. // $(location).attr("href", "novel.html");
  280. // }
  281. });
  282. // 注册/登录
  283. $(".accountRight").on("click", function () {
  284. $(".loginBox").show();
  285. });
  286. $(".guanbi").on("click", function () {
  287. $(".loginBox").hide();
  288. });
  289. // 查看我的收藏
  290. $("#register").on("click", function () {
  291. if ($(this).text() === "My Collection") {
  292. $(location).attr("href", 'collection.html');
  293. } else {
  294. // 注册
  295. $(location).attr("href", 'register.html');
  296. }
  297. $(".loginBox").hide();
  298. });
  299. // 登录/退出登录
  300. $("#login").on("click", function () {
  301. if ($(this).text() === "Log out") {
  302. // 退出登录
  303. localStorage.removeItem("uid");
  304. location.reload();
  305. } else {
  306. // 登录
  307. $(location).attr("href", 'blogin.html');
  308. }
  309. $(".loginBox").hide();
  310. });
  311. // 返回顶部
  312. $(".backToTop").on("click", function () {
  313. $("html, body").animate(
  314. {
  315. scrollTop: 0,
  316. },
  317. 500
  318. );
  319. });
  320. // 获取标签图片
  321. function getLabelVideoData(labelpage) {
  322. clearScroll();
  323. $('.bottomLoadContent').show();
  324. $.ajax({
  325. type: "post",
  326. url: "https://www.bibidd.com/bibidd/Mediaonefive/select_type_detail",
  327. dataType: "json",
  328. data: {
  329. type_name: labelname,
  330. type: "img",
  331. page: labelpage,
  332. },
  333. success: function (res) {
  334. allDataArray = res.data;
  335. dataArray = [];
  336. if (allDataArray.length > 0) {
  337. let showDataNum =
  338. allDataArray.length % 12 === 0 ? 12 : allDataArray.length % 12;
  339. for (let i = 0; i < showDataNum; i++) {
  340. dataArray.push(allDataArray[i]);
  341. }
  342. }
  343. },
  344. complete: function (res) {
  345. ispage = true;
  346. // 分页
  347. let code = res.responseJSON.code;
  348. let dataNum = res.responseJSON.all_num;
  349. $(function () {
  350. $("#pagination3").pagination({
  351. currentPage: lpage,
  352. totalPage: Math.ceil(dataNum / 36),
  353. isShow: true,
  354. count: 7,
  355. homePageText: "One",
  356. endPageText: "Last",
  357. prevPageText: "Prev",
  358. nextPageText: "Next",
  359. callback: function (current) {
  360. lpage = current;
  361. getLabelVideoData(lpage);
  362. },
  363. });
  364. Math.ceil(dataNum / 36) < 2?$('.firstPage').show():$('.firstPage').hide();
  365. });
  366. createDomHtml(dataArray);
  367. $("html, body").animate(
  368. {
  369. scrollTop: 0,
  370. },
  371. 10
  372. );
  373. },
  374. });
  375. }
  376. // 图片加载背景
  377. function loadVideoBackground() {
  378. }
  379. // 视频搜索
  380. var searchcurrentid = 1;
  381. function searchVideo(videopage) {
  382. clearScroll();
  383. $('.bottomLoadContent').show();
  384. let searchInputVal = $(".searchInput").val();
  385. $.ajax({
  386. type: "post",
  387. url: "https://www.bibidd.com/bibidd/Mediaonefive/sousuo_img_video",
  388. dataType: "json",
  389. data: {
  390. type_name: searchInputVal,
  391. type: "img",
  392. page: videopage,
  393. },
  394. success: function (res) {
  395. allDataArray = res.data;
  396. if(allDataArray.length==0) {
  397. $("#tip").show();
  398. $(".tiptext").text('The data you need is not found.');
  399. $('.bottomLoadContent').hide();
  400. }else{
  401. $("#tip").hide();
  402. }
  403. dataArray = [];
  404. if (allDataArray.length > 0) {
  405. let showDataNum =
  406. allDataArray.length % 12 === 0 ? 12 : allDataArray.length % 12;
  407. for (let i = 0; i < showDataNum; i++) {
  408. dataArray.push(allDataArray[i]);
  409. }
  410. }
  411. },
  412. complete: function (res) {
  413. ispage = true;
  414. // 分页
  415. let code = res.responseJSON.code;
  416. let dataNum = res.responseJSON.all_num;
  417. $(function () {
  418. $("#pagination3").pagination({
  419. currentPage: searchcurrentid,
  420. totalPage: Math.ceil(dataNum / 36),
  421. isShow: true,
  422. count: 7,
  423. homePageText: "One",
  424. endPageText: "Last",
  425. prevPageText: "Prev",
  426. nextPageText: "Next",
  427. callback: function (current) {
  428. searchcurrentid = current;
  429. searchVideo(searchcurrentid, videotype);
  430. },
  431. });
  432. Math.ceil(dataNum / 36) < 2?$('.firstPage').show():$('.firstPage').hide();
  433. });
  434. createDomHtml(dataArray);
  435. $("html, body").animate(
  436. {
  437. scrollTop: 0,
  438. },
  439. 10
  440. );
  441. },
  442. });
  443. }
  444. function tip(text) {
  445. $("#tip").show();
  446. $(".tiptext").text(text);
  447. setTimeout(() => {
  448. $("#tip").hide();
  449. }, 1000);
  450. }
  451. // 上拉加载更多
  452. var showVideoNum = 12;
  453. var ispage = true;
  454. $(window).scroll(function () {
  455. var scrollT = $(document).scrollTop();
  456. var offsetT = $(".main").offset().top;
  457. if (scrollT >= offsetT) {
  458. $(".backToTop").show();
  459. } else {
  460. $(".backToTop").hide();
  461. }
  462. let windowHeight = $(window).height();
  463. let windowScrollTop = $(window).scrollTop();
  464. let loadingHeight = $('.bottomLoadContent').height();
  465. if (windowHeight + windowScrollTop + loadingHeight >= $(document).height()) {
  466. if (ispage) {
  467. ispage = false;
  468. if (showVideoNum != 36) {
  469. $(".bottomLoadContent").show();
  470. $(".box").hide();
  471. showVideoNum += 12;
  472. showVideoNum =
  473. showVideoNum > allDataArray.length
  474. ? allDataArray.length
  475. : showVideoNum;
  476. dataArray = [];
  477. for (let i = 0; i < 12; i++) {
  478. dataArray.push(allDataArray[(showVideoNum-12+i)]);
  479. }
  480. let videoHtml = "";
  481. $.each(dataArray, function (index, data) {
  482. videoHtml += '<div class="videoContent">';
  483. videoHtml +=
  484. '<div class="lazy videoPhoto" data-original="' +
  485. data.top_img +
  486. '"></div>';
  487. videoHtml += ' <div class="videoTitle">' + data.title + "</div>";
  488. videoHtml += ' <div class="videoData">';
  489. videoHtml += " <!-- 观看次数 -->";
  490. videoHtml += ' <div class="videoDataLeft">';
  491. videoHtml +=
  492. ' <img class="videoDataImgLook" src="/Public/bibidd/images/look.png" alt="" />';
  493. videoHtml +=
  494. ' <div id="looks" class="videoText">' +
  495. data.views +
  496. "</div>";
  497. videoHtml += " </div>";
  498. videoHtml += " <!-- 点赞次数 -->";
  499. videoHtml += ' <div class="videoDataRgiht">';
  500. videoHtml +=
  501. ' <img class="videoDataImgZan" src="/Public/bibidd/images/zan.png" alt="" />';
  502. videoHtml +=
  503. ' <div class="videoText">' + data.thumbs_up + "</div>";
  504. videoHtml += " </div>";
  505. videoHtml += " </div>";
  506. videoHtml += "</div>";
  507. });
  508. setTimeout(() => {
  509. $(".video").append(videoHtml);
  510. $(".bottomLoadContent").hide();
  511. var loadingUrl = "/Public/bibidd/images/loading.png";
  512. $(".lazy").lazyload({
  513. effect: "show",
  514. placeholder: loadingUrl,
  515. failurelimit: 10,
  516. skip_invisible: false,
  517. });
  518. $(".videoContent").on("click", function () {
  519. let looks = $(this).find("#looks").eq(0).text();
  520. $(this).find("#looks").eq(0).text(Number(looks)+1);
  521. $(location).attr("href","bphotodetails.html?imgid=" +
  522. allDataArray[$(this).index()].id +
  523. "&fabulous=" +
  524. allDataArray[$(this).index()].thumbs_up +
  525. "&favorite=" +
  526. allDataArray[$(this).index()].favorite
  527. );
  528. });
  529. ispage = true;
  530. }, 1000);
  531. } else {
  532. $(".bottomLoadContent").hide();
  533. $(".box").show();
  534. ispage = true;
  535. }
  536. }
  537. }
  538. });
  539. // 创建视频dom元素
  540. function createDomHtml(dataArray) {
  541. let videoHtml = "";
  542. $.each(dataArray, function (index, data) {
  543. videoHtml += '<div class="videoContent">';
  544. videoHtml +=
  545. '<div class="lazy videoPhoto" data-original="' +
  546. data.top_img +
  547. '"></div>';
  548. videoHtml += ' <div class="videoTitle">' + data.title + "</div>";
  549. videoHtml += ' <div class="videoData">';
  550. videoHtml += " <!-- 观看次数 -->";
  551. videoHtml += ' <div class="videoDataLeft">';
  552. videoHtml +=
  553. ' <img class="videoDataImgLook" src="/Public/bibidd/images/look.png" alt="" />';
  554. videoHtml += ' <div id="looks" class="videoText">' + data.views + "</div>";
  555. videoHtml += " </div>";
  556. videoHtml += " <!-- 点赞次数 -->";
  557. videoHtml += ' <div class="videoDataRgiht">';
  558. videoHtml +=
  559. ' <img class="videoDataImgZan" src="/Public/bibidd/images/zan.png" alt="" />';
  560. videoHtml += ' <div class="videoText">' + data.thumbs_up + "</div>";
  561. videoHtml += " </div>";
  562. videoHtml += " </div>";
  563. videoHtml += "</div>";
  564. });
  565. $(".video").html(videoHtml);
  566. var loadingUrl = "/Public/bibidd/images/loading.png";
  567. $(".lazy").lazyload({
  568. effect: "show",
  569. placeholder: loadingUrl,
  570. failurelimit: 10,
  571. skip_invisible: false,
  572. });
  573. // 查看视频详情
  574. $(".videoContent").on("click", function () {
  575. let looks = $(this).find("#looks").eq(0).text();
  576. $(this).find("#looks").eq(0).text(Number(looks)+1);
  577. $(location).attr("href","bphotodetails.html?imgid=" +
  578. dataArray[$(this).index()].id +
  579. "&fabulous=" +
  580. dataArray[$(this).index()].thumbs_up +
  581. "&favorite=" +
  582. dataArray[$(this).index()].favorite
  583. );
  584. });
  585. }
  586. function clearScroll() {
  587. showVideoNum = 12;
  588. ispage = false;
  589. scrollT = 0;
  590. offsetT = 0;
  591. $(".bottomLoadContent").show();
  592. $(".box").hide();
  593. }
  594. $('.clearTextImg').on('click', function() {
  595. $('.searchInput').val('');
  596. })
  597. });