feat: 优化商品洞察相关代码逻辑、新增性能优化 SQL 并更新前端样式
This commit is contained in:
@@ -12,6 +12,7 @@ let tagChart;
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
initCharts();
|
||||
setupNavigation();
|
||||
setupRepurchasePeriod();
|
||||
|
||||
// Fetch cutoff dates + initial page data
|
||||
fetchDataCutoff();
|
||||
@@ -181,9 +182,14 @@ async function fetchTrend() {
|
||||
}
|
||||
|
||||
// ============== PAGE 2: PRODUCT INSIGHTS ==============
|
||||
async function fetchRepurchase() {
|
||||
|
||||
// 当前选中的复购率统计周期
|
||||
let repurchaseDays = 30;
|
||||
|
||||
async function fetchRepurchase(days) {
|
||||
if (days !== undefined) repurchaseDays = days;
|
||||
try {
|
||||
const response = await fetch(`${BASE_URL}/product/repurchase`);
|
||||
const response = await fetch(`${BASE_URL}/product/repurchase?days=${repurchaseDays}`);
|
||||
if (!response.ok) return;
|
||||
const data = await response.json();
|
||||
|
||||
@@ -215,6 +221,20 @@ async function fetchRepurchase() {
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// 初始化复购率周期切换控件
|
||||
function setupRepurchasePeriod() {
|
||||
const container = document.getElementById('repurchase-period');
|
||||
if (!container) return;
|
||||
container.addEventListener('click', (e) => {
|
||||
const btn = e.target.closest('.segment-btn');
|
||||
if (!btn) return;
|
||||
container.querySelectorAll('.segment-btn').forEach(b => b.classList.remove('active'));
|
||||
btn.classList.add('active');
|
||||
const days = parseInt(btn.dataset.days);
|
||||
fetchRepurchase(days);
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchBasket() {
|
||||
try {
|
||||
const response = await fetch(`${BASE_URL}/product/basket`);
|
||||
|
||||
Reference in New Issue
Block a user