script_profiles.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. // const str = `<img src="static/img/undraw_male_avatar_323b.svg" alt="">
  26. // <p class="card-profile-txt">User Profile</p>
  27. // <p class="card-profile-cnt">${userInfo.user_info.userName}</p>
  28. // <p class="card-profile-cnt">${userInfo.user_info.email}</p>
  29. // <div class="d-flex justify-content-around">
  30. // <div>
  31. // <p set-lan="html:used">已使用</p>
  32. // <p><strong>${userInfo.user_info.total_sec}</strong><span set-lan="html:sec">秒</span></p>
  33. // </div>
  34. // <div>
  35. // <p set-lan="html:left">未使用</p>
  36. // <p><strong>${userInfo.user_info.left_sec}</strong><span set-lan="html:sec">秒</span></p>
  37. // </div>
  38. // </div>`;
  39. const str = `<img src="static/img/undraw_male_avatar_323b.svg" alt="">
  40. <p class="card-profile-txt">User Profile</p>
  41. <p class="card-profile-cnt">${userInfo.user_info.userName}</p>
  42. <p class="card-profile-cnt">${userInfo.user_info.email}</p>
  43. <div class="d-flex justify-content-around">
  44. <div>
  45. <p set-lan="html:used">已使用</p>
  46. <p><strong>${userInfo.user_info.total_sec}</strong><span set-lan="html:sec">秒</span></p>
  47. </div>
  48. <div>
  49. <p set-lan="html:left">未使用</p>
  50. <p><strong>${userInfo.user_info.left_sec}</strong><span set-lan="html:sec">秒</span></p>
  51. </div>
  52. </div>`;
  53. // 使用者名稱
  54. const userName = `<h2 class="user-name text-white mt-4 fw-bold">Hello,${userInfo.user_info.userName}</h2>`;
  55. // 已使用
  56. const usedtime=`<h1 class="text-center">${userInfo.user_info.total_sec}&ensp;<span style="font-size:15px;">秒</span></h1>`;
  57. // 未使用
  58. const NotUsedTime=`<h1 class="text-center">${userInfo.user_info.left_sec}&ensp;<span style="font-size:15px;">秒</span></h1>`;
  59. // user資訊
  60. const infContent=`
  61. <div class="inf-content">
  62. <p>${userInfo.user_info.userName}</p>
  63. <p>***************&nbsp;<a href="">更改密碼</a></p>
  64. <p>${userInfo.user_info.email}</p>
  65. </div>`;
  66. // 歷史紀錄
  67. // const historicalrecord
  68. var historicalrecord=''
  69. for (var i = 0; i < userInfo.video_info.length; i++) {
  70. historicalrecord+='\
  71. <tr>\
  72. <td class="px-0">'+userInfo.video_info[i].time_stamp+'</td>\
  73. <td class="px-0">'+userInfo.video_info[i].title+'</td>\
  74. <td class="px-0 w-25">'+userInfo.video_info[i].duration+'</td>\
  75. </tr>`\
  76. ';
  77. }
  78. $('.historical-content').html(historicalrecord);
  79. $('.userinf').html(infContent);
  80. $('.userName').html(userName);
  81. $('.used-time').html(usedtime);
  82. $('.not-used-time').html(NotUsedTime);
  83. $('.card-profile').html(str);
  84. $('.card-profile').html(str);
  85. }).catch(err => {
  86. console.log(err);
  87. })
  88. }
  89. renderView();
  90. function checkLogin() {
  91. let token = getCookie('jwt_token');
  92. if(token) {
  93. btnLoginPage.style.display = 'none';
  94. btnLogout.style.display = 'block';
  95. btnUserProfile.style.display = 'block';
  96. } else {
  97. window.location.href = 'login.html';
  98. btnLoginPage.style.display = 'block';
  99. btnLogout.style.display = 'none';
  100. btnUserProfile.style.display = 'none';
  101. }
  102. }
  103. checkLogin();
  104. $(".historical-record").hide();
  105. $( ".check-history" ).click(function() {
  106. $(".historical-record").toggle();
  107. $(".arrowdown").toggleClass("arrowdoup");
  108. });