gen_avatar.js 6.6 KB

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