activity.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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/common.js"></script>
  40. <script>
  41. (function () {
  42. const API_URL = '/api/v1/config/activities/';
  43. const loadingOverlay = document.getElementById('loadingOverlay');
  44. const errorOverlay = document.getElementById('errorOverlay');
  45. const retryBtn = document.getElementById('retryBtn');
  46. // const backButton = document.getElementById('backButton');
  47. const activityContent = document.getElementById('activityContent');
  48. // const activityTitle = document.getElementById('activityTitle');
  49. let token = '';
  50. let activityId = '';
  51. // backButton.addEventListener('click', function () {
  52. // window.BEXBridge.closeWebview();
  53. // });
  54. function showLoading() {
  55. loadingOverlay.style.display = 'flex';
  56. errorOverlay.style.display = 'none';
  57. }
  58. function hideLoading() {
  59. loadingOverlay.style.display = 'none';
  60. }
  61. function showError() {
  62. loadingOverlay.style.display = 'none';
  63. errorOverlay.style.display = 'flex';
  64. }
  65. async function fetchActivityDetail() {
  66. showLoading();
  67. try {
  68. const headers = {
  69. 'Content-Type': 'application/json',
  70. 'Accept': 'application/json',
  71. 'X-Requested-With': 'XMLHttpRequest',
  72. 'localeName': getCurrentLang(),
  73. ...globalHeaders
  74. };
  75. if (token) {
  76. headers['Authorization'] = token;
  77. }
  78. const response = await fetch(API_URL + activityId, {
  79. method: 'GET',
  80. headers: headers,
  81. credentials: 'include',
  82. timeout: 10000
  83. });
  84. if (!response.ok) {
  85. throw new Error(`请求失败! status: ${response.status}`);
  86. }
  87. const result = await response.json();
  88. const data = result.data || {};
  89. if (data.content) {
  90. const decodedHTML = decodeHTMLEntities(data.content);
  91. activityContent.innerHTML = decodedHTML;
  92. const title = data.title;
  93. document.title = title || BEXI18n.t('detailCommon', 'pageTitle');
  94. } else {
  95. activityContent.innerHTML = '<p style="color: #888; text-align: center; padding: 20px;">' + BEXI18n.t('detailCommon', 'emptyActivity') + '</p>';
  96. }
  97. hideLoading();
  98. } catch (error) {
  99. console.error('Data fetch error:', error);
  100. showError();
  101. }
  102. }
  103. BEXI18n.applyTranslations('detailCommon');
  104. retryBtn.addEventListener('click', fetchActivityDetail);
  105. document.addEventListener('DOMContentLoaded', async function () {
  106. try {
  107. token = await window.BEXBridge.getToken();
  108. } catch (error) {
  109. }
  110. activityId = await window.BEXBridge.getActivityId();
  111. if (activityId) {
  112. fetchActivityDetail();
  113. } else {
  114. console.error('未获取到 activityId');
  115. showError();
  116. }
  117. });
  118. })();
  119. function decodeHTMLEntities(text) {
  120. const textarea = document.createElement('textarea');
  121. textarea.innerHTML = text;
  122. return textarea.value;
  123. }
  124. </script>
  125. </body>
  126. </html>