script_profiles.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. const btnLoginPage = document.querySelector('.btn-login');
  2. const btnUserProfile = document.querySelector('.btn-userProfile');
  3. const btnLogout = document.querySelector('.btn-logout');
  4. function getCookie(name) {
  5. const value = `; ${document.cookie}`;
  6. const parts = value.split(`; ${name}=`);
  7. if (parts.length === 2) return parts.pop().split(';').shift();
  8. }
  9. function renderView() {
  10. let token = getCookie('jwt_token');
  11. if(!token) {
  12. return;
  13. }
  14. // axios.defaults.withCredentials = false;
  15. axios({
  16. method: 'post',
  17. url: 'https://www.choozmo.com:8887/user_profile',
  18. headers: {
  19. 'accept': 'text/html',
  20. 'Authorization': `Bearer ${token}`
  21. }
  22. }).then(res => {
  23. console.log(res.data);
  24. const userInfo = res.data;
  25. if(userInfo.user_info.left_sec < 20){
  26. Swal.fire({
  27. title: "剩餘秒數不足",
  28. text: '您的影片額度即將不足,加值以持續使用',
  29. icon: 'warning',
  30. showCancelButton: true,
  31. cancelButtonText: 'Cancel',
  32. confirmButtonColor: '#3085d6',
  33. confirmButtonText: '加值'
  34. }).then(result => {
  35. if (result.isConfirmed) {
  36. location.href = "pricing.html";
  37. }
  38. });
  39. }
  40. // const str = `<img src="static/img/undraw_male_avatar_323b.svg" alt="">
  41. // <p class="card-profile-txt">User Profile</p>
  42. // <p class="card-profile-cnt">${userInfo.user_info.userName}</p>
  43. // <p class="card-profile-cnt">${userInfo.user_info.email}</p>
  44. // <div class="d-flex justify-content-around">
  45. // <div>
  46. // <p set-lan="html:used">已使用</p>
  47. // <p><strong>${userInfo.user_info.total_sec}</strong><span set-lan="html:sec">秒</span></p>
  48. // </div>
  49. // <div>
  50. // <p set-lan="html:left">未使用</p>
  51. // <p><strong>${userInfo.user_info.left_sec}</strong><span set-lan="html:sec">秒</span></p>
  52. // </div>
  53. // </div>`;
  54. const str = `<img src="static/img/undraw_male_avatar_323b.svg" alt="">
  55. <p class="card-profile-txt">User Profile</p>
  56. <p class="card-profile-cnt">${userInfo.user_info.userName}</p>
  57. <p class="card-profile-cnt">${userInfo.user_info.email}</p>
  58. <div class="d-flex justify-content-around">
  59. <div>
  60. <p set-lan="html:used">已使用</p>
  61. <p><strong>${userInfo.user_info.total_sec}</strong><span set-lan="html:sec">秒</span></p>
  62. </div>
  63. <div>
  64. <p set-lan="html:left">未使用</p>
  65. <p><strong>${userInfo.user_info.left_sec}</strong><span set-lan="html:sec">秒</span></p>
  66. </div>
  67. </div>`;
  68. // 使用者名稱
  69. const userName = `<h2 class="user-name text-white mt-4 fw-bold">Hello,${userInfo.user_info.userName}</h2>`;
  70. // 已使用
  71. const usedtime=`<h1 class="text-center">${userInfo.user_info.total_sec}&ensp;<span style="font-size:15px;" set-lan="html:sec">秒</span></h1>`;
  72. // 未使用
  73. const NotUsedTime=`<h1 class="text-center">${userInfo.user_info.left_sec}&ensp;<span style="font-size:15px;" set-lan="html:sec">秒</span></h1>`;
  74. // user資訊
  75. const infContent=`
  76. <div class="inf-content">
  77. <p>${userInfo.user_info.userName}</p>
  78. <p>***************&nbsp;<a href="./reset_pwd_email.html" set-lan="html:resetPsd">更改密碼</a></p>
  79. <p>${userInfo.user_info.email}</p>
  80. </div>`;
  81. // 歷史紀錄
  82. // const historicalrecord
  83. var historicalrecord=''
  84. for (var i = 0; i < userInfo.video_info.length; i++) {
  85. historicalrecord+='\
  86. <tr>\
  87. <td class="px-0">'+userInfo.video_info[i].time_stamp+'</td>\
  88. <td class="px-0">'+userInfo.video_info[i].title+'</td>\
  89. <td class="px-0 w-25">'+userInfo.video_info[i].duration+'</td>\
  90. </tr>`\
  91. ';
  92. }
  93. $('.historical-content').html(historicalrecord);
  94. $('.userinf').html(infContent);
  95. $('.userName').html(userName);
  96. $('.used-time').html(usedtime);
  97. $('.not-used-time').html(NotUsedTime);
  98. $('.card-profile').html(str);
  99. $('.card-profile').html(str);
  100. }).catch(err => {
  101. console.log(err);
  102. })
  103. }
  104. renderView();
  105. function checkLogin() {
  106. let token = getCookie('jwt_token');
  107. if(token) {
  108. btnLoginPage.style.display = 'none';
  109. btnLogout.style.display = 'block';
  110. btnUserProfile.style.display = 'block';
  111. } else {
  112. window.location.href = 'login.html';
  113. btnLoginPage.style.display = 'block';
  114. btnLogout.style.display = 'none';
  115. btnUserProfile.style.display = 'none';
  116. }
  117. }
  118. checkLogin();
  119. $(".historical-record").hide();
  120. $( ".check-history" ).click(function() {
  121. $(".historical-record").toggle();
  122. $(".arrowdown").toggleClass("arrowdoup");
  123. });
  124. var loaded_data = ''
  125. function openNav() {
  126. document.getElementById("mySidenav").style.width = "250px";
  127. document.querySelector('.loader').style.display = "block";
  128. let token = getCookie('jwt_token');
  129. axios({
  130. method: 'post',
  131. url: 'https://www.choozmo.com:8887/history_input',
  132. headers: {
  133. 'accept': 'application/json',
  134. 'Authorization': `Bearer ${token}`
  135. }
  136. }).then(res => {
  137. console.log(res.data);
  138. loaded_data = res.data;
  139. for (var obj of loaded_data) {
  140. var historyList = document.querySelector('.historyList');
  141. var list = document.createElement('li');
  142. list.id = obj.id;
  143. // div-imgfr
  144. var divImgfr = document.createElement('div');
  145. divImgfr.classList.add('item_imgfr');
  146. var img = document.createElement('img');
  147. img.setAttribute('src', obj['image_urls'][0]);
  148. divImgfr.appendChild(img);
  149. // div-content
  150. var contentBox = document.createElement('div');
  151. contentBox.classList.add('content-box');
  152. var boxTitle = document.createElement('p');
  153. boxTitle.classList.add('box-title');
  154. boxTitle.textContent = obj.name;
  155. boxTitle.id = obj.id;
  156. boxTitle.setAttribute('onclick', `direct(${obj.id})`);
  157. var boxLink = document.createElement('span');
  158. boxLink.classList.add('box-link');
  159. boxLink.setAttribute("data-url", obj.link);
  160. boxLink.setAttribute('onclick', 'view()');
  161. boxLink.innerHTML = '<i class="fas fa-play-circle me-1"></i>觀看影片';
  162. contentBox.appendChild(boxTitle);
  163. contentBox.appendChild(boxLink);
  164. list.classList.add("historyList-item");
  165. list.setAttribute('onclick', `direct(${obj.id})`);
  166. list.appendChild(divImgfr);
  167. list.appendChild(contentBox);
  168. historyList.appendChild(list);
  169. }
  170. document.querySelector('.loader').style.display = "none";
  171. }).catch(err => {
  172. console.log(err);
  173. });
  174. }
  175. function direct(id) {
  176. location.href = `make_video.html?id=${id}`;
  177. }
  178. function view() {
  179. event.stopPropagation();
  180. console.log(event.target);
  181. if (event.target.nodeName === 'I') {
  182. return;
  183. } else {
  184. window.open(`http://${event.target.dataset.url}`, '_blank');
  185. }
  186. }