activity.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  6. <title></title>
  7. <link rel="stylesheet" href="/css/activity.css">
  8. <style>
  9. .activity-content {
  10. min-height: 100vh;
  11. }
  12. .activity-content img {
  13. max-width: 100%;
  14. height: auto;
  15. }
  16. .activity-content a {
  17. color: #f5a623;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <div class="container activity">
  23. <div id="activityContent" class="activity-content">
  24. </div>
  25. <div class="loading-overlay" id="loadingOverlay" style="display: none;">
  26. <div class="loading-content">
  27. <div class="loading-spinner"></div>
  28. <span class="loading-text" data-i18n="loadingText">加载中...</span>
  29. </div>
  30. </div>
  31. <div class="error-overlay" id="errorOverlay" style="display: none;">
  32. <div class="error-content">
  33. <div class="error-icon">!</div>
  34. <span class="error-text" data-i18n="errorText">加载失败,请稍后重试</span>
  35. <button class="error-retry" id="retryBtn" data-i18n="retryBtn">重试</button>
  36. </div>
  37. </div>
  38. </div>
  39. <script src="/js/app.js"></script>
  40. <script src="/js/i18n/config.js"></script>
  41. <script src="/js/i18n/locales/zh.js"></script>
  42. <script src="/js/i18n/locales/en.js"></script>
  43. <script src="/js/i18n/locales/zh_TW.js"></script>
  44. <script src="/js/i18n/locales/ja.js"></script>
  45. <script src="/js/i18n/locales/ko.js"></script>
  46. <script src="/js/i18n/locales/th.js"></script>
  47. <script src="/js/i18n/locales/fr.js"></script>
  48. <script src="/js/i18n/locales/es.js"></script>
  49. <script src="/js/i18n/locales/pt.js"></script>
  50. <script src="/js/i18n/locales/de.js"></script>
  51. <script src="/js/i18n/index.js"></script>
  52. <script>
  53. (function () {
  54. const API_URL = '/api/v1/config/activities/';
  55. const loadingOverlay = document.getElementById('loadingOverlay');
  56. const errorOverlay = document.getElementById('errorOverlay');
  57. const retryBtn = document.getElementById('retryBtn');
  58. // const backButton = document.getElementById('backButton');
  59. const activityContent = document.getElementById('activityContent');
  60. // const activityTitle = document.getElementById('activityTitle');
  61. let token = '';
  62. let activityId = '';
  63. // backButton.addEventListener('click', function () {
  64. // if (window.flutter_inappwebview && window.flutter_inappwebview.callHandler) {
  65. // window.flutter_inappwebview.callHandler('closeWebview');
  66. // }
  67. // });
  68. function showLoading() {
  69. loadingOverlay.style.display = 'flex';
  70. errorOverlay.style.display = 'none';
  71. }
  72. function hideLoading() {
  73. loadingOverlay.style.display = 'none';
  74. }
  75. function showError() {
  76. loadingOverlay.style.display = 'none';
  77. errorOverlay.style.display = 'flex';
  78. }
  79. async function getTokenFromNative() {
  80. try {
  81. const result = await window.flutter_inappwebview.callHandler('getToken');
  82. token = result;
  83. return result;
  84. } catch (e) {
  85. console.error('JSBridge getToken 调用失败', e);
  86. return null;
  87. }
  88. }
  89. async function getActivityIdFromNative() {
  90. try {
  91. const result = await window.flutter_inappwebview.callHandler('getActivityId');
  92. activityId = result;
  93. return result;
  94. } catch (e) {
  95. console.error('JSBridge getActivityId 调用失败', e);
  96. return null;
  97. }
  98. }
  99. async function fetchActivityDetail() {
  100. showLoading();
  101. try {
  102. const headers = {
  103. 'Content-Type': 'application/json',
  104. 'Accept': 'application/json',
  105. 'X-Requested-With': 'XMLHttpRequest',
  106. 'localeName': getCurrentLang(),
  107. ...globalHeaders
  108. };
  109. if (token) {
  110. headers['Authorization'] = token;
  111. }
  112. const response = await fetch(API_URL + activityId, {
  113. method: 'GET',
  114. headers: headers,
  115. credentials: 'include',
  116. timeout: 10000
  117. });
  118. if (!response.ok) {
  119. throw new Error(`请求失败! status: ${response.status}`);
  120. }
  121. const result = await response.json();
  122. const data = result.data || {};
  123. if (data.content) {
  124. const decodedHTML = decodeHTMLEntities(data.content);
  125. activityContent.innerHTML = decodedHTML;
  126. const title = data.title;
  127. document.title = title || BEXI18n.t('detailCommon', 'pageTitle');
  128. } else {
  129. activityContent.innerHTML = '<p style="color: #888; text-align: center; padding: 20px;">' + BEXI18n.t('detailCommon', 'emptyActivity') + '</p>';
  130. }
  131. hideLoading();
  132. } catch (error) {
  133. console.error('Data fetch error:', error);
  134. showError();
  135. }
  136. }
  137. BEXI18n.applyTranslations('detailCommon');
  138. retryBtn.addEventListener('click', fetchActivityDetail);
  139. document.addEventListener('DOMContentLoaded', async function () {
  140. await getTokenFromNative();
  141. await getActivityIdFromNative();
  142. if (activityId) {
  143. fetchActivityDetail();
  144. } else {
  145. console.error('未获取到 activityId');
  146. showError();
  147. }
  148. });
  149. })();
  150. function decodeHTMLEntities(text) {
  151. const textarea = document.createElement('textarea');
  152. textarea.innerHTML = text;
  153. return textarea.value;
  154. }
  155. </script>
  156. </body>
  157. </html>