goto.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. // $('.sec05-moblie-container').slick({
  2. // arrows: false,
  3. // slidesToShow: 1,
  4. // slidesToScroll: 1,
  5. // infinite: false,
  6. // centerMode: true,
  7. // });
  8. $(".sendbox").hide();
  9. $(document).on("click", ".collectcontent", function (event) {
  10. $(".sendbox").show(500);
  11. $(this).addClass("select");
  12. $(".select").siblings().removeClass('select');
  13. });
  14. $(document).on("click", ".close", function (event) {
  15. // $(this).siblings('.collectcard').removeClass('select');
  16. $(".sendbox").hide(500);
  17. $(".collectcontent").removeClass("select");
  18. });
  19. // 收藏頁面
  20. function collection(collectuserid='') {
  21. console.log('Call collection(' + collectuserid + ')'); // test
  22. $.ajax({
  23. method: "GET",
  24. url: "https://ark.cards:8228/collection/" + collectuserid + "",
  25. dataType: "json",
  26. })
  27. .done(function (msg) {
  28. console.log(msg);
  29. // console.log(Object.keys(msg).length);
  30. let msgLen = Object.keys(msg).length;
  31. console.log(msgLen);
  32. var collectcontent = '';
  33. if (msg[0].id == undefined) {
  34. collectcontent += '<p>' + msg + '</p>';
  35. } else {
  36. for (var i = 0; i < msgLen; i++) {
  37. collectcontent += '\
  38. <div class="collectcontent col">\
  39. <input style="display: none;" type="checkbox" value="'+ msg[i].id + '" name="nftid" id="' + msg[i].id + '">\
  40. <label for="'+ msg[i].id + '">\
  41. <div class="collectcard card h-100">\
  42. <a target="_blank">\
  43. <img src="'+ msg[i].imgurl + '"class="card-img-top" alt="...">\
  44. </a>\
  45. <div class="card-body p-2">\
  46. <a target="_blank">\
  47. <h5 class="card-title pt-3">'+ msg[i].title + '</h5>\
  48. </a>\
  49. <p class="card-text">\
  50. '+ msg[i].context + ' \
  51. </p>\
  52. <p class="card-text row">\
  53. <small class="text-muted col-6 px-1">\
  54. <img class="mb-1 mx-1 d-inline" style="width: 10px; object-fit: cover; "\
  55. src="./img/sec05/Icon awesome-ethereum.png" alt=""><span>'+ msg[i].cost + '</span>\
  56. </small>\
  57. <small class="price col-6 px-0 text-center">\
  58. <img class="mb-1 mx-1 d-inline" style="width: 12px; object-fit: cover; " src="./img/sec05/like.png" alt=""><span>'+ msg[i].likes + '</span></small>\
  59. </p>\
  60. </div>\
  61. </div>\
  62. </label>\
  63. </div>';
  64. }
  65. }
  66. $('.sec05-moblie-container').html(collectcontent);
  67. });
  68. }
  69. // 購買頁面
  70. function shop(collectuserid='') {
  71. console.log('Call shop(' + collectuserid + ')'); // test
  72. $.ajax({
  73. method: "GET",
  74. url: "https://ark.cards:8228/shop/" + collectuserid + "",
  75. // url: "https://ark.cards:8228/shop/Uf161c92b16f84357987a78c2b4b47719",
  76. dataType: "json",
  77. })
  78. .done(function (msg) {
  79. console.log(msg);
  80. // console.log(Object.keys(msg).length);
  81. let msgLen = Object.keys(msg).length;
  82. console.log(msgLen);
  83. var nftmall = '';
  84. var buybox = "";
  85. for (var i = 0; i < msgLen; i++) {
  86. nftmall += '\
  87. <div class="nftmall col">\
  88. <input style="display:none" type="checkbox" value="'+ msg[i].id + '" name="nftid" class="nftname" id="' + msg[i].id + '">\
  89. <label for="'+ msg[i].id + '">\
  90. <div class="collectcard card h-100">\
  91. <a target="_blank">\
  92. <img src="'+ msg[i].imgurl + '"class="card-img-top" alt="...">\
  93. </a>\
  94. <div class="card-body p-2">\
  95. <a target="_blank">\
  96. <h5 class="card-title pt-3">'+ msg[i].title + '</h5>\
  97. </a>\
  98. <p class="card-text">\
  99. '+ msg[i].context + ' \
  100. </p>\
  101. <p class="card-text row">\
  102. <small class="text-muted col-6 px-1">\
  103. <img class="mb-1 mx-1 d-inline" style="width: 10px; object-fit: cover; "\
  104. src="./img/sec05/Icon awesome-ethereum.png" alt=""><span>'+ msg[i].cost + '</span>\
  105. </small>\
  106. <small class="price col-6 px-0 text-center">\
  107. <img class="mb-1 mx-1 d-inline" style="width: 12px; object-fit: cover; " src="./img/sec05/like.png" alt=""><span>'+ msg[i].likes + '</span>\
  108. </small>\
  109. </p>\
  110. </div>\
  111. </div>\
  112. </label>\
  113. </div>';
  114. }
  115. buybox += '\
  116. <div class="p-2">\
  117. <input style="border-radius: 10px; border:none; display: none;" class="p-2 w-100 mb-3" type="text" name="userid" value="' + collectuserid + '" placeholder="請輸入您的userid" required>\
  118. <div class="text-end px-2">\
  119. <p class="text-start text-white mb-2">※一次只能購買一則NFT收藏品</p>\
  120. <button type="button" style="border:1px solid #fff; border-radius: 30px;" class="close btn text-white px-3">取消</button>\
  121. <input style="border-radius: 30px; background:#fff; border: none;" class="send-btn px-3 ms-1 py-2" type="submit" value="購買">\
  122. </div>\
  123. </div>\
  124. </div>';
  125. $('.sec06-nft-mall').html(nftmall);
  126. $('.buybox').html(buybox);
  127. });
  128. }
  129. // Qrcode頁面
  130. function get_data(collectuserid='') {
  131. console.log('Call get_data(' + collectuserid + ')'); // test
  132. $.ajax({
  133. method: "GET",
  134. url: "https://ark.cards:8228/receive/" + collectuserid + "",
  135. // url:"https://api.ptt.cx:8228/receive/Uf161c92b16f84357987a78c2b4b47719",
  136. dataType: "json",
  137. })
  138. .done(function (msg) {
  139. console.log(msg);
  140. var Qrcodeimg = '';
  141. var useraddress = '';
  142. Qrcodeimg += '\
  143. <img class="img-fluid" src="./qrcode/'+ collectuserid + '.png" alt="">\
  144. ';
  145. useraddress += '\
  146. '+ msg.useraddress + '\
  147. ';
  148. $('#Qrcode').html(Qrcodeimg);
  149. $('#copy').html(useraddress);
  150. });
  151. }
  152. // $(document).ready(function () {
  153. // // 收藏頁面
  154. // collection(collectuserid);
  155. // // 購買頁面
  156. // shop(collectuserid);
  157. // // Qrcode頁面
  158. // get_data(collectuserid);
  159. // });
  160. $(".buybox").hide();
  161. $(document).on("click", ".nftmall", function (event) {
  162. $(".buybox").show(500);
  163. $(this).addClass("select");
  164. $(".select").siblings().removeClass('select');
  165. });
  166. $(document).on("click", ".close", function (event) {
  167. // $(this).siblings('.collectcard').removeClass('select');
  168. $(".buybox").hide(500);
  169. $(".nftmall").removeClass("select");
  170. $(".nftname").prop("checked", false);
  171. });
  172. $.fn.serializeObject = function () {
  173. alert('serializeObject()'); // test
  174. var o = {};
  175. var a = this.serializeArray();
  176. // o["id"] = 0;
  177. // o["time_stamp"] = "";
  178. $.each(a, function () {
  179. if (o[this.name]) {
  180. if (!o[this.name].push) {
  181. o[this.name] = [o[this.name]];
  182. }
  183. o[this.name].push(this.value || '');
  184. } else {
  185. o[this.name] = this.value || '';
  186. }
  187. });
  188. return o;
  189. };
  190. // 確定發送按鈕處理
  191. $(".collect-send").submit(function (e) {
  192. /* var formRef = $('#form1').serializeArray();
  193. var jsonString = JSON.stringify(formRef);*/
  194. var jsonInfo = $('.collect-send').serializeObject();
  195. var jsonString = JSON.stringify(jsonInfo);
  196. console.log(jsonString),
  197. $.ajax({
  198. type: 'POST',
  199. url: 'https://ark.cards:8228/send',
  200. data: jsonString,
  201. dataType: 'json',
  202. async: false,
  203. success: function (data) {
  204. console.log('送出成功: ' + JSON.stringify(data));
  205. alert("送出成功");
  206. window.location.href = "collect.html";
  207. },
  208. beforeSend: function () {
  209. console.log('beforeSend');
  210. },
  211. complete: function () {
  212. console.log('complete');
  213. },
  214. error: function (jqXHR, textStatus, errorThrown) {
  215. console.log(JSON.stringify(jqXHR));
  216. console.log("AJAX errr: " + textStatus + ' : ' + errorThrown);
  217. console.log('送出失敗: ' + jqXHR.responseText);
  218. }
  219. });
  220. return false;
  221. });
  222. $(".nft-buy").submit(function (e) {
  223. /* var formRef = $('#form1').serializeArray();
  224. var jsonString = JSON.stringify(formRef);*/
  225. var jsonInfo = $('.nft-buy').serializeObject();
  226. var jsonString = JSON.stringify(jsonInfo);
  227. console.log(jsonString),
  228. $.ajax({
  229. type: 'POST',
  230. url: 'https://ark.cards:8228/buy',
  231. data: jsonString,
  232. dataType: 'json',
  233. success: function (data) {
  234. console.log('購買成功: ' + data);
  235. alert("購買成功");
  236. location.reload();
  237. },
  238. beforeSend: function () {
  239. console.log('beforeSend');
  240. },
  241. complete: function () {
  242. console.log('complete');
  243. },
  244. error: function (jqXHR, textStatus, errorThrown) {
  245. console.log(JSON.stringify(jqXHR));
  246. console.log("AJAX errr: " + textStatus + ' : ' + errorThrown);
  247. console.log('送出失敗: ' + jqXHR.responseText);
  248. }
  249. });
  250. return false;
  251. });
  252. function copyEvent(id) {
  253. var str = document.getElementById(id);
  254. window.getSelection().selectAllChildren(str);
  255. document.execCommand("Copy")
  256. toastr.options = {
  257. // 參數設定[註1]
  258. "closeButton": false, // 顯示關閉按鈕
  259. "debug": false, // 除錯
  260. "newestOnTop": false, // 最新一筆顯示在最上面
  261. "progressBar": false, // 顯示隱藏時間進度條
  262. "positionClass": "toast-top-center", // 位置的類別
  263. "preventDuplicates": false, // 隱藏重覆訊息
  264. "onclick": null, // 當點選提示訊息時,則執行此函式
  265. "showDuration": "300", // 顯示時間(單位: 毫秒)
  266. "hideDuration": "1000", // 隱藏時間(單位: 毫秒)
  267. "timeOut": "1000", // 當超過此設定時間時,則隱藏提示訊息(單位: 毫秒)
  268. "extendedTimeOut": "1000", // 當使用者觸碰到提示訊息時,離開後超過此設定時間則隱藏提示訊息(單位: 毫秒)
  269. "showEasing": "swing", // 顯示動畫時間曲線
  270. "hideEasing": "linear", // 隱藏動畫時間曲線
  271. "showMethod": "fadeIn", // 顯示動畫效果
  272. "hideMethod": "fadeOut" // 隱藏動畫效果
  273. }
  274. toastr.success("複製成功");
  275. }