gen_avatar.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. $('input[type=file]').on('change', prepareUpload);
  2. // Grab the files and set them to our variable
  3. function prepareUpload(event) {
  4. files = event.target.files;
  5. var data = new FormData();
  6. //data.append('file', $('.img_up1').prop('files')[0]);
  7. data.append('file', files[0]);
  8. // append other variables to data if you want: data.append('field_name_x', field_value_x);
  9. $(this).next().text('');
  10. $(this).next().html('<img src="static/img/Spinner-1s-181px.gif">');
  11. $.ajax({
  12. type: 'POST',
  13. processData: false, // important
  14. contentType: false, // important
  15. data: data,
  16. url: 'uploadfile',
  17. dataType: 'json',
  18. success: function (jsonData) {
  19. event.target.previousSibling.value =jsonData.msg;
  20. $(this).prev().val(jsonData.msg);
  21. event.target.nextSibling.innerHTML = '';
  22. event.target.nextSibling.textContent = '上傳檔案';
  23. //console.log($(this).next());
  24. //$(this).next().html('上傳檔案');
  25. //$(this).next().text('上傳檔案');
  26. },
  27. error: function (error) {
  28. event.target.nextSibling.innerHTML = '';
  29. event.target.nextSibling.textContent = '上傳檔案';
  30. alert('圖片錯誤');
  31. }
  32. });
  33. }
  34. const button = document.querySelector('.next');
  35. $(".next").click(function () {
  36. button.setAttribute('disabled', '');
  37. setTimeout(function () {
  38. button.removeAttribute('disabled')
  39. }, 4000);
  40. avatar = $('.avatar').val();
  41. name_title = $('.title_new').val();
  42. txtARR = [];
  43. imgARR = [];
  44. var step;
  45. for (step = 1; step <= 10; step++) {
  46. if ($(".txtsrc" + step).val() != "") {
  47. txtARR.push($(".txtsrc" + step).val())
  48. }
  49. }
  50. var step2;
  51. for (step2 = 1; step2 <= 10; step2++) {
  52. if ($(".imgsrc" + step2).val() != "") {
  53. imgARR.push($(".imgsrc" + step2).val())
  54. }
  55. }
  56. dataOBJ = { "name": name_title, "text_content": txtARR, "image_urls": imgARR, "avatar": avatar, "client_id": client_id }
  57. objstr = JSON.stringify(dataOBJ);
  58. console.log(dataOBJ)
  59. //alert('資料已送出! 請耐心等候')
  60. $.ajax({
  61. url: '192.168.1.106:8887/make_anchor_video_v2',
  62. //url: 'http://www.choozmo.com:8888/qqreq',
  63. dataType : 'json', // 預期從server接收的資料型態
  64. contentType : 'application/json; charset=utf-8', // 要送到server的資料型態
  65. type: 'post',
  66. data: objstr,
  67. success: function(suc_data) {
  68. Swal.fire({
  69. title: "資料已送出",
  70. icon: 'success',
  71. text: `${suc_data.msg}`,
  72. confirmButtonColor: '#3085d6',
  73. });
  74. },
  75. //data:JSON.stringify({n1:"12",n2:"22"}),
  76. error: function (error) {
  77. console.error(error)
  78. }
  79. });
  80. });
  81. $(".gen_avatar").click(function () {
  82. dataOBJ = { "imgurl": $('.imgsrc').val() }
  83. objstr = JSON.stringify(dataOBJ);
  84. console.log(dataOBJ)
  85. //alert('資料已送出! 請耐心等候')
  86. $.ajax({
  87. url: '192.168.1.106:8887/swapFace',
  88. dataType: 'json', // 預期從server接收的資料型態
  89. contentType: 'application/json; charset=utf-8', // 要送到server的資料型態
  90. type: 'post',
  91. data: objstr,
  92. success: function (suc_data) {
  93. alert(suc_data.msg)
  94. },
  95. //data:JSON.stringify({n1:"12",n2:"22"}),
  96. error: function (error) {
  97. console.error(error)
  98. }
  99. });
  100. });
  101. var loaded_data = ''
  102. function openNav() {
  103. document.getElementById("mySidenav").style.width = "250px";
  104. document.querySelector('.loader').style.display = "block";
  105. $.get("192.168.1.106:8887/history_input", function (data, status) {
  106. console.log(data)
  107. loaded_data = data
  108. for (var obj of data) {
  109. var historyList = document.querySelector('.historyList');
  110. var list = document.createElement('li');
  111. list.id = obj.id;
  112. // div-imgfr
  113. var divImgfr = document.createElement('div');
  114. divImgfr.classList.add('item_imgfr');
  115. var img = document.createElement('img');
  116. img.setAttribute('src', obj['image_urls'][0]);
  117. divImgfr.appendChild(img);
  118. // div-content
  119. var contentBox = document.createElement('div');
  120. contentBox.classList.add('content-box');
  121. var boxTitle = document.createElement('p');
  122. boxTitle.classList.add('box-title');
  123. boxTitle.textContent = obj.name;
  124. boxTitle.id = obj.id;
  125. boxTitle.setAttribute('onclick', 'load_data()');
  126. var boxLink = document.createElement('span');
  127. boxLink.classList.add('box-link');
  128. boxLink.setAttribute("data-url", obj.link);
  129. boxLink.setAttribute('onclick', 'view()');
  130. boxLink.innerHTML = '<i class="fas fa-play-circle me-1"></i>觀看影片';
  131. contentBox.appendChild(boxTitle);
  132. contentBox.appendChild(boxLink);
  133. list.classList.add("historyList-item");
  134. list.setAttribute('onclick', 'load_data()');
  135. list.appendChild(divImgfr);
  136. list.appendChild(contentBox);
  137. historyList.appendChild(list);
  138. }
  139. document.querySelector('.loader').style.display = "none";
  140. });
  141. }
  142. function closeNav() {
  143. document.getElementById("mySidenav").style.width = "250px";
  144. }
  145. function view() {
  146. event.stopPropagation();
  147. console.log(event.target);
  148. if(event.target.nodeName === 'I') {
  149. return;
  150. } else {
  151. window.open(`http://${event.target.dataset.url}`, '_blank');
  152. }
  153. }
  154. function load_data() {
  155. var title = document.getElementById("title");
  156. var linker = document.getElementById("linker");
  157. myModal.hide()
  158. tid = event.srcElement.id
  159. console.log(tid);
  160. linker.setAttribute('href', `http://${loaded_data.find(item => item.id == tid).link}`)
  161. linker.setAttribute('target', '_blank')
  162. $("#linker").html(`http://${loaded_data.find(item => item.id == tid).link}`)
  163. $("#linker").show();
  164. $(".linker__box").show();
  165. $(".title_new").val(loaded_data.find(item => item.id == tid).name)
  166. var step;
  167. for (step = 1; step <= 10; step++) {
  168. $(".txtsrc" + step).val(loaded_data.find(item => item.id == tid).text_content[step - 1])
  169. }
  170. var step2;
  171. for (step2 = 1; step2 <= 10; step2++) {
  172. $(".imgsrc" + step2).val(loaded_data.find(item => item.id == tid).image_urls[step2 - 1])
  173. }
  174. }