upload2.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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: 'uploadmp3',
  17. dataType: 'json',
  18. success: function (jsonData) {
  19. window.location.href = "/modifyScript?id="+jsonData;
  20. },
  21. error: function (error) {
  22. alert('發生錯誤');
  23. }
  24. });
  25. }
  26. const button = document.querySelector('.next');
  27. $(".next").click(function () {
  28. button.setAttribute('disabled', '');
  29. setTimeout(function () {
  30. button.removeAttribute('disabled')
  31. }, 4000);
  32. avatar = $('.avatar').val();
  33. name_title = $('.title_new').val();
  34. txtARR = [];
  35. imgARR = [];
  36. var step;
  37. for (step = 1; step <= 10; step++) {
  38. if ($(".txtsrc" + step).val() != "") {
  39. txtARR.push($(".txtsrc" + step).val())
  40. }
  41. }
  42. var step2;
  43. for (step2 = 1; step2 <= 10; step2++) {
  44. if ($(".imgsrc" + step2).val() != "") {
  45. imgARR.push($(".imgsrc" + step2).val())
  46. }
  47. }
  48. dataOBJ = { "name": name_title, "text_content": txtARR, "image_urls": imgARR, "avatar": avatar, "client_id": client_id }
  49. objstr = JSON.stringify(dataOBJ);
  50. console.log(dataOBJ)
  51. //alert('資料已送出! 請耐心等候')
  52. $.ajax({
  53. url: '/make_anchor_video_v2',
  54. //url: 'http://www.choozmo.com:8888/qqreq',
  55. dataType : 'json', // 預期從server接收的資料型態
  56. contentType : 'application/json; charset=utf-8', // 要送到server的資料型態
  57. type: 'post',
  58. data: objstr,
  59. success: function(suc_data) {
  60. Swal.fire({
  61. title: "資料已送出",
  62. icon: 'success',
  63. text: `${suc_data.msg}`,
  64. confirmButtonColor: '#3085d6',
  65. });
  66. },
  67. //data:JSON.stringify({n1:"12",n2:"22"}),
  68. error: function (error) {
  69. console.error(error)
  70. }
  71. });
  72. });
  73. $(".gen_avatar").click(function () {
  74. dataOBJ = { "imgurl": $('.imgsrc').val() }
  75. objstr = JSON.stringify(dataOBJ);
  76. console.log(dataOBJ)
  77. //alert('資料已送出! 請耐心等候')
  78. $.ajax({
  79. url: '/swapFace',
  80. dataType: 'json', // 預期從server接收的資料型態
  81. contentType: 'application/json; charset=utf-8', // 要送到server的資料型態
  82. type: 'post',
  83. data: objstr,
  84. success: function (suc_data) {
  85. alert(suc_data.msg)
  86. },
  87. //data:JSON.stringify({n1:"12",n2:"22"}),
  88. error: function (error) {
  89. console.error(error)
  90. }
  91. });
  92. });
  93. function view() {
  94. event.stopPropagation();
  95. console.log(event.target);
  96. if(event.target.nodeName === 'I') {
  97. return;
  98. } else {
  99. window.open(`http://${event.target.dataset.url}`, '_blank');
  100. }
  101. }
  102. function load_data() {
  103. var title = document.getElementById("title");
  104. var linker = document.getElementById("linker");
  105. myModal.hide()
  106. tid = event.srcElement.id
  107. console.log(tid);
  108. linker.setAttribute('href', `http://${loaded_data.find(item => item.id == tid).link}`)
  109. linker.setAttribute('target', '_blank')
  110. $("#linker").html(`http://${loaded_data.find(item => item.id == tid).link}`)
  111. $("#linker").show();
  112. $(".linker__box").show();
  113. $(".title_new").val(loaded_data.find(item => item.id == tid).name)
  114. var step;
  115. for (step = 1; step <= 10; step++) {
  116. $(".txtsrc" + step).val(loaded_data.find(item => item.id == tid).text_content[step - 1])
  117. }
  118. var step2;
  119. for (step2 = 1; step2 <= 10; step2++) {
  120. $(".imgsrc" + step2).val(loaded_data.find(item => item.id == tid).image_urls[step2 - 1])
  121. }
  122. }