diff --git a/code/app/home/view/shikong/baseH5.html b/code/app/home/view/shikong/baseH5.html index dceeb40..93b9c89 100644 --- a/code/app/home/view/shikong/baseH5.html +++ b/code/app/home/view/shikong/baseH5.html @@ -107,6 +107,9 @@ {/block} + {include file="public/footer" /} {block name="customize"} diff --git a/code/public/template/default/js/common.js b/code/public/template/default/js/common.js index 09e4db9..4f9b116 100644 --- a/code/public/template/default/js/common.js +++ b/code/public/template/default/js/common.js @@ -341,7 +341,7 @@ function displayHistory() { // 方法1:使用 fetch API async function reportStats(data) { - console.log(strPushApi) + try { const response = await fetch(strPushApi+'/publish', { method: 'POST', @@ -349,7 +349,7 @@ async function reportStats(data) { headers: { 'Content-Type': 'application/json', // 如果需要认证可以添加 - // 'Authorization': 'Bearer your-token' + 'Authorization': 'Bearer your-token' }, body: JSON.stringify(data) }); diff --git a/code/public/template/kuangyu/public/js/common.js b/code/public/template/kuangyu/public/js/common.js index 5b7e7b8..fe34517 100644 --- a/code/public/template/kuangyu/public/js/common.js +++ b/code/public/template/kuangyu/public/js/common.js @@ -421,7 +421,7 @@ async function reportStats(data) { headers: { 'Content-Type': 'application/json', // 如果需要认证可以添加 - // 'Authorization': 'Bearer your-token' + 'Authorization': 'Bearer your-token' }, body: JSON.stringify(data) }); diff --git a/code/public/template/shikong/js/index.js b/code/public/template/shikong/js/index.js index 61cf8ea..ec9216b 100644 --- a/code/public/template/shikong/js/index.js +++ b/code/public/template/shikong/js/index.js @@ -148,8 +148,38 @@ function throttlingFnV2(fn, delay) { }; } +// 方法1:使用 fetch API +async function reportStats(data) { + + try { + const response = await fetch(strPushApi+'/publish', { + method: 'POST', + // mode: 'no-cors', // 添加这行 + headers: { + 'Content-Type': 'application/json', + // 如果需要认证可以添加 + 'Authorization': 'Bearer your-token' + }, + body: JSON.stringify(data) + }); + + if (!response.ok) { + throw new Error('上报失败'); + } + + // const result = await response.json(); + // console.log('上报成功:', result); + // return result; + } catch (error) { + console.error('上报错误:', error); + } +} + $(function () { + + + // checkoutHuiyuanTip() if ($(".novel-reader").length === 0) { let _scrollY = 0; // 记录上一次滚动位置 @@ -291,3 +321,18 @@ $(function () { })(); +document.addEventListener("DOMContentLoaded", function () { + + if (typeof strNovelId !== "undefined") { + + // 使用示例 + const statsData = { + n_id: strNovelId, + }; + // 调用方法1 + reportStats(statsData); + + // addHistoryFun() + } +}) +