123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. base = function () {
  2. //private menbers
  3. let isActivityOver = false;
  4. let userProfile = null;
  5. let userData = null;
  6. //private methods
  7. function init() {
  8. console.log('base init')
  9. // 判斷是否活動已結束
  10. // entranceTimer();
  11. // 用戶登入
  12. GameService.getInstanse().init().then((profile) => {
  13. $(".wapper-loading .loading__text").text("LINE登入中");
  14. // console.log(profile)
  15. userProfile = profile;
  16. getProfile();
  17. // 正式用 記得開
  18. GameService.getInstanse().userLogin()
  19. .then(_res => {
  20. console.log("_res: ",_res);
  21. $(".wapper-loading").remove();
  22. gsap.to(".wrapper", {
  23. duration: 0.5,
  24. autoAlpha: 1
  25. });
  26. userData = GameService.getInstanse().getUserData();
  27. console.log("userData: ",userData)
  28. if(userData === null) {
  29. register.LinePicHandler(profile.pictureUrl)
  30. goToRegister();
  31. }else {
  32. passport.buildPassportHandler(userData)
  33. register.insertFromData(userData);
  34. goToPassport();
  35. GameService.getInstanse().sendCompleteMessage();
  36. }
  37. // 測試用
  38. // goToPassport();
  39. // passport.buildPassportHandler(userData)
  40. // register.insertFromData(userData);
  41. // ------------------------------------------
  42. // goToRegister();
  43. // register.LinePicHandler(profile.pictureUrl)
  44. }).catch(error => {
  45. alert("[BasePage Error - userLogin]: ", error);
  46. })
  47. }).catch(error => {
  48. alert("[BasePage Error - init]: ", error);
  49. })
  50. // 返回表單頁
  51. $(".backform").on("click", function(){
  52. // console.log("backform click");
  53. goToRegister();
  54. });
  55. // 前往活動辦法頁
  56. $(".goToActivity").on("click", function(){
  57. // console.log("goToActivity click");
  58. goToMethods();
  59. });
  60. }
  61. // 活動期間判斷
  62. function entranceTimer() {
  63. var _nowDate = new Date();
  64. var _endDate = new Date("2023/09/08 23:29");
  65. if (_nowDate.getTime() >= _endDate.getTime()) {
  66. isActivityOver = true;
  67. // 活動結束後提供查詢
  68. // myAlert(``);
  69. console.log("活動已結束")
  70. } else {
  71. isActivityOver = false;
  72. console.log("活動進行中")
  73. }
  74. }
  75. function getProfile() {
  76. return userProfile
  77. }
  78. // 提醒popup
  79. function myAlert(_msg) {
  80. $('#agreeAccModal').modal('hide');
  81. $('#exampleModal').find('.alert-message').html(_msg);
  82. $('#exampleModal').modal('show');
  83. $(".modal-backdrop.show").css("backdrop-filter", "blur(2px)");
  84. $(".modal-backdrop.show").css("-webkit-backdrop-filter", "blur(2px)")
  85. }
  86. function goToRegister() {
  87. sectionFadeIn(".register");
  88. sectionFadeOut(".passport");
  89. sectionFadeOut(".methods");
  90. }
  91. function goToPassport() {
  92. sectionFadeIn(".passport");
  93. sectionFadeOut(".methods");
  94. sectionFadeOut(".register");
  95. }
  96. function goToMethods() {
  97. sectionFadeIn(".methods");
  98. sectionFadeOut(".passport");
  99. sectionFadeOut(".register");
  100. }
  101. // page進入動態
  102. function sectionFadeIn(el) {
  103. $(el).show();
  104. gsap.to(el, {
  105. duration: 0.3,
  106. autoAlpha: 1
  107. })
  108. }
  109. // page離開動態
  110. function sectionFadeOut(el) {
  111. gsap.to(el, {
  112. duration: 0.3,
  113. autoAlpha: 0,
  114. onComplete: function() {
  115. $(el).hide();
  116. }
  117. })
  118. }
  119. {
  120. $(document).ready(function () {
  121. init();
  122. });
  123. }
  124. //public
  125. return {
  126. sectionFadeIn: function(el) {
  127. sectionFadeIn(el)
  128. },
  129. sectionFadeOut: function(el) {
  130. sectionFadeOut(el)
  131. },
  132. myAlert: function (_msg) {
  133. myAlert(_msg);
  134. },
  135. getProfile,
  136. goToRegister,
  137. goToPassport,
  138. goToMethods,
  139. };
  140. };
  141. var base = new base();