script_profiles.js 9.2 KB

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