goto.js 11 KB

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