collectionphotodetails.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. $(document).ready(function() {
  2. $('.quanpinghei').hide();
  3. // 页面传参
  4. var url = window.location.search;
  5. // 判断图片是否被收藏参数
  6. var collectionStatus;
  7. var theRequest = new Object();
  8. if (url.indexOf("?") != -1) {
  9. var str = url.substr(1);
  10. strs = str.split("&");
  11. for (var i = 0; i < strs.length; i++) {
  12. theRequest[strs[i].split("=")[0]] = unescape(
  13. decodeURIComponent(strs[i].split("=")[1])
  14. );
  15. }
  16. }
  17. var username = localStorage.getItem('username');
  18. var uid = localStorage.getItem("uid");
  19. if (uid) {
  20. $("#register").text("My Collection");
  21. $("#login").text("Log out");
  22. $("#login").css("backgroundColor", "#D6565A");
  23. } else {
  24. $("#register").text("Sign up");
  25. $("#login").text("Login");
  26. $("#login").css("backgroundColor", "#CE5C2A");
  27. }
  28. // 获取视频id
  29. var imgid = theRequest.videoid;
  30. // 获取点赞数量
  31. var fabulous = theRequest.fabulous;
  32. $('.fabulous').find("p").eq(0).text(fabulous);
  33. // 获取图片数据
  34. function getData() {
  35. $.ajax({
  36. type:'post',
  37. url:'https://www.bibidd.com/bibidd/Mediaonefive/img_detail',
  38. dataType: "json",
  39. data: {
  40. imgs_id: imgid
  41. },
  42. success: function (res) {
  43. },
  44. complete:function(res) {
  45. let dataArray = res.responseJSON.data;
  46. let imgListHtml = '';
  47. $.each(dataArray, function(index, data) {
  48. imgListHtml += '<img class="img" src="'+data+'" alt="">';
  49. })
  50. $('.imgList').html(imgListHtml);
  51. $('.img').on('click',function() {
  52. $('.bigImgWrap').show();
  53. $('.bigImg').attr('src', dataArray[$(this).index()]);
  54. })
  55. }
  56. })
  57. }
  58. getData();
  59. // 判断当前是否可以进行收藏相关交互
  60. var collectionChange = false;
  61. // 判断该图片是否被收藏接口
  62. function collectionData() {
  63. $.ajax({
  64. type:'post',
  65. url:'https://www.bibidd.com/bibidd/Mediaonefive/yn_shoucang',
  66. dataType: "json",
  67. data: {
  68. type:'img',
  69. cid:imgid,
  70. uid:uid
  71. },
  72. success: function (res) {
  73. },
  74. complete:function(res) {
  75. let collectionData = res.responseJSON.message;
  76. collectionChange = true;
  77. if(collectionData === 'ok') {
  78. // 已经被收藏
  79. $('.collection img').attr('src','/Public/bibidd/images/xingsel.png');
  80. // $('.collection').find("p").eq(0).text('Favorite');
  81. collectionStatus = true;
  82. }else {
  83. // 没被收藏
  84. $('.collection img').attr('src','/Public/bibidd/images/xing.png');
  85. // $('.collection').find("p").eq(0).text('Not collected');
  86. collectionStatus = false;
  87. }
  88. }
  89. })
  90. }
  91. if(uid){
  92. collectionData();
  93. }else{
  94. // $('.collection').find("p").eq(0).text('Not collected');
  95. }
  96. // 点赞
  97. var fabulousStatus = true;
  98. $('.fabulous').on('click', function() {
  99. $('.collection img').attr('src','/Public/bibidd/images/load.png');
  100. setTimeout(() => {
  101. $('.collection img').attr('src','/Public/bibidd/images/zan.png');
  102. $.ajax({
  103. type:'post',
  104. url:'https://www.bibidd.com/bibidd/Mediaonefive/dianzan_img_video',
  105. dataType: "json",
  106. data: {
  107. type:'img',
  108. cid:imgid,
  109. uid:uid
  110. },
  111. success: function (res) {
  112. },
  113. complete:function(res) {
  114. let fabulous = $('.fabulous').find("p").eq(0).text();
  115. $('.fabulous').find("p").eq(0).text(Number(fabulous) + 1);
  116. fabulousStatus = true;
  117. }
  118. })
  119. }, 2000);
  120. })
  121. $('.guanbi').on('click', function() {
  122. $('.loginBox').hide();
  123. })
  124. // 查看我的收藏
  125. $('#register').on('click', function() {
  126. if($(this).text()==='My Collection') {
  127. $(location).attr('href', 'collection.html');
  128. }else {
  129. // 注册
  130. $(location).attr('href', 'register.html');
  131. }
  132. $('.loginBox').hide();
  133. })
  134. // 登录/退出登录
  135. $('#login').on('click', function() {
  136. if($(this).text()==='Log out') {
  137. // 退出登录
  138. localStorage.removeItem('uid');
  139. location.reload();
  140. }else {
  141. // 登录
  142. $(location).attr('href', 'blogin.html');
  143. }
  144. $('.loginBox').hide();
  145. })
  146. // 收藏
  147. $('.collection').on('click', function() {
  148. if(uid){
  149. if(collectionStatus) {
  150. $('.collection img').attr('src','/Public/bibidd/images/xing.png');
  151. // $('.collection').find("p").eq(0).text('Not collected');
  152. collectionclose();
  153. }else {
  154. $('.collection img').attr('src','/Public/bibidd/images/xingsel.png');
  155. // $('.collection').find("p").eq(0).text('Favorite');
  156. collectionAdd();
  157. }
  158. }else{
  159. // 弹窗提示去登录
  160. $('.loginBox').show();
  161. }
  162. })
  163. // 添加收藏
  164. function collectionAdd() {
  165. $.ajax({
  166. type:'post',
  167. url:'https://www.bibidd.com/bibidd/Mediaonefive/add_to_shoucang',
  168. dataType: "json",
  169. data: {
  170. type:'img',
  171. cid:imgid,
  172. uid:uid
  173. },
  174. success: function (res) {
  175. },
  176. complete:function(res) {
  177. collectionChange = true;
  178. let collectionData = res.responseJSON.message;
  179. if(collectionData === 'ok') {
  180. // 已经被收藏
  181. $('.collection img').attr('src','/Public/bibidd/images/xingsel.png');
  182. // $('.collection').find("p").eq(0).text('Favorite');
  183. collectionStatus = true;
  184. }else {
  185. $('.collection img').attr('src','/Public/bibidd/images/xing.png');
  186. // $('.collection').find("p").eq(0).text('Not collected');
  187. collectionStatus = false;
  188. tip('请稍后重试');
  189. }
  190. }
  191. })
  192. }
  193. // 取消收藏
  194. function collectionclose() {
  195. $.ajax({
  196. type:'post',
  197. url:'https://www.bibidd.com/bibidd/Mediaonefive/quxiao_shoucang',
  198. dataType: "json",
  199. data: {
  200. type:'img',
  201. cid:imgid,
  202. uid:uid
  203. },
  204. success: function (res) {
  205. },
  206. complete:function(res) {
  207. let collectionData = res.responseJSON.message;
  208. if(collectionData === 'ok') {
  209. // 已经取消收藏
  210. $('.collection img').attr('src','/Public/bibidd/images/xing.png');
  211. // $('.collection').find("p").eq(0).text('Not collected');
  212. collectionStatus = false;
  213. }else {
  214. $('.collection img').attr('src','/Public/bibidd/images/xingsel.png');
  215. // $('.collection').find("p").eq(0).text('Favorite');
  216. collectionStatus = true;
  217. tip('Please try again later');
  218. }
  219. }
  220. })
  221. }
  222. $('.back').on('click', function() {
  223. history.back(-1);
  224. })
  225. function tip(text) {
  226. $('#tip').show();
  227. $('tiptext').text(text);
  228. setTimeout(() => {
  229. $('#tip').hide();
  230. }, 1000);
  231. }
  232. $('.guanbiBigImg img').on('click',function() {
  233. $('.bigImgWrap').hide();
  234. })
  235. })