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