Files
vf_react/src/views/Community/components/DynamicNews/constants.js
2026-02-03 14:42:37 +08:00

92 lines
2.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// src/views/Community/components/DynamicNews/constants.js
// 动态新闻卡片组件 - 常量配置
// ========== 分页配置常量 ==========
/**
* 分页大小计算依据:
*
* 【纵向模式 (VERTICAL_PAGE_SIZE)】
* - 每页显示 10 条数据
* - 使用传统分页器,用户手动翻页
*
* 【主线模式】
* - 使用独立 API不需要分页配置
*/
export const PAGINATION_CONFIG = {
VERTICAL_PAGE_SIZE: 10, // 纵向模式每页数量 (传统分页)
INITIAL_PAGE: 1, // 初始页码
};
// ========== 显示模式常量 ==========
export const DISPLAY_MODES = {
VERTICAL: 'vertical', // 纵向分栏模式
MAINLINE: 'mainline', // 主线分组模式(按 lv2 概念分组)
};
export const DEFAULT_MODE = DISPLAY_MODES.VERTICAL;
// ========== Toast 提示配置 ==========
export const TOAST_CONFIG = {
DURATION_ERROR: 3000, // 错误提示持续时间(毫秒)
DURATION_WARNING: 2000, // 警告提示持续时间(毫秒)
};
// ========== Socket 刷新防抖配置 ==========
/**
* Socket 新事件刷新防抖延迟(毫秒)
*
* 作用:避免短时间内收到多个新事件时频繁刷新列表
*
* 场景示例:
* - 第 1 秒:收到新事件 → 延迟 2 秒刷新
* - 第 2 秒:收到新事件 → 取消上次,重新延迟 2 秒
* - 第 3 秒:收到新事件 → 取消上次,重新延迟 2 秒
* - 第 5 秒:触发刷新 → 只发送 1 次 API 请求
*
* 推荐值2000ms (2 秒)
* - 太短(如 500ms→ 仍可能触发多次刷新
* - 太长(如 5000ms→ 用户感知延迟过高
*/
export const REFRESH_DEBOUNCE_DELAY = 2000;
// ========== 盘中自动刷新配置 ==========
/**
* 盘中自动刷新间隔(毫秒)
*
* 作用:在交易时间内定时刷新列表,保持行情数据实时性
*
* 交易时间:周一至周五 9:30-11:30 和 13:00-15:00
*
* 推荐值60000ms (1 分钟)
* - 太短(如 30s→ API 压力大,用户体验干扰
* - 太长(如 5min→ 数据时效性降低
*/
export const AUTO_REFRESH_INTERVAL = 60000;
/**
* 判断当前是否在交易时间内
* @returns {boolean} 是否在交易时间
*/
export const isTradingTime = () => {
const now = new Date();
const day = now.getDay(); // 0=周日, 1-5=周一至周五, 6=周六
// 周末不是交易时间
if (day === 0 || day === 6) return false;
const hours = now.getHours();
const minutes = now.getMinutes();
const totalMinutes = hours * 60 + minutes;
// 上午盘9:30 - 11:30 (570 - 690 分钟)
const morningStart = 9 * 60 + 30; // 9:30
const morningEnd = 11 * 60 + 30; // 11:30
// 下午盘13:00 - 15:00 (780 - 900 分钟)
const afternoonStart = 13 * 60; // 13:00
const afternoonEnd = 15 * 60; // 15:00
return (totalMinutes >= morningStart && totalMinutes <= morningEnd) ||
(totalMinutes >= afternoonStart && totalMinutes <= afternoonEnd);
};