| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
- <title>活动详情</title>
- <link rel="stylesheet" href="/css/activity.css">
- <style>
- .activity-content {
- min-height: 100vh;
- }
- .activity-content img {
- max-width: 100%;
- height: auto;
- }
- .activity-content a {
- color: #f5a623;
- }
- </style>
- </head>
- <body>
- <div class="container activity">
- <div id="activityContent" class="activity-content">
- </div>
- <div class="loading-overlay" id="loadingOverlay" style="display: none;">
- <div class="loading-content">
- <div class="loading-spinner"></div>
- <span class="loading-text">加载中...</span>
- </div>
- </div>
- <div class="error-overlay" id="errorOverlay" style="display: none;">
- <div class="error-content">
- <div class="error-icon">!</div>
- <span class="error-text">加载失败,请稍后重试</span>
- <button class="error-retry" id="retryBtn">重试</button>
- </div>
- </div>
- </div>
- <script>
- (function () {
- const API_URL = '/api/v1/config/activities/';
- const loadingOverlay = document.getElementById('loadingOverlay');
- const errorOverlay = document.getElementById('errorOverlay');
- const retryBtn = document.getElementById('retryBtn');
- // const backButton = document.getElementById('backButton');
- const activityContent = document.getElementById('activityContent');
- // const activityTitle = document.getElementById('activityTitle');
- let token = '';
- let activityId = '';
- // backButton.addEventListener('click', function () {
- // if (window.flutter_inappwebview && window.flutter_inappwebview.callHandler) {
- // window.flutter_inappwebview.callHandler('closeWebview');
- // }
- // });
- function showLoading() {
- loadingOverlay.style.display = 'flex';
- errorOverlay.style.display = 'none';
- }
- function hideLoading() {
- loadingOverlay.style.display = 'none';
- }
- function showError() {
- loadingOverlay.style.display = 'none';
- errorOverlay.style.display = 'flex';
- }
- async function getTokenFromNative() {
- try {
- const result = await window.flutter_inappwebview.callHandler('getToken');
- token = result;
- return result;
- } catch (e) {
- console.error('JSBridge getToken 调用失败', e);
- return null;
- }
- }
- async function getActivityIdFromNative() {
- try {
- const result = await window.flutter_inappwebview.callHandler('getActivityId');
- activityId = result;
- return result;
- } catch (e) {
- console.error('JSBridge getActivityId 调用失败', e);
- return null;
- }
- }
- async function fetchActivityDetail() {
- showLoading();
- try {
- const headers = {
- 'Content-Type': 'application/json',
- 'Accept': 'application/json',
- 'X-Requested-With': 'XMLHttpRequest',
- };
- if (token) {
- headers['Authorization'] = token;
- }
- const response = await fetch(API_URL + activityId, {
- method: 'GET',
- headers: headers,
- credentials: 'include',
- timeout: 10000
- });
-
- if (!response.ok) {
- throw new Error(`请求失败! status: ${response.status}`);
- }
-
- const result = await response.json();
- const data = result.data || {};
- if (data.content) {
- const decodedHTML = decodeHTMLEntities(data.content);
- activityContent.innerHTML = decodedHTML;
- } else {
- activityContent.innerHTML = '<p style="color: #888; text-align: center; padding: 20px;">暂无活动内容</p>';
- }
- hideLoading();
- } catch (error) {
- console.error('Data fetch error:', error);
- showError();
- }
- }
- retryBtn.addEventListener('click', fetchActivityDetail);
- document.addEventListener('DOMContentLoaded', async function () {
- await getTokenFromNative();
- await getActivityIdFromNative();
- if (activityId) {
- fetchActivityDetail();
- } else {
- console.error('未获取到 activityId');
- showError();
- }
- });
- })();
- function decodeHTMLEntities(text) {
- const textarea = document.createElement('textarea');
- textarea.innerHTML = text;
- return textarea.value;
- }
- </script>
- </body>
- </html>
|