features.js 2.19 KB
/**
 * 功能开关配置
 *
 * @description 用于控制功能的启用/禁用状态,方便灰度发布和功能回滚
 * @module config/features
 */

/**
 * 功能配置项
 *
 * @property {boolean} tabbarBadge - TabBar 红点提醒功能
 * - true: 启用红点提醒(根据后端返回的 unread_count 判断)
 * - false: 禁用红点提醒
 *
 * @property {string} tabbarBadgeField - 红点字段名称
 * - 从用户信息接口读取该字段判断是否显示红点
 * - 当前使用 'unread_msg_count'(getProfileAPI 返回字段)
 *
 * @property {number} tabbarBadgeThreshold - 红点显示阈值
 * - 当 unread_count >= 该值时显示红点
 * - 默认为 1,即有未读消息时显示
 */
export const features = {
  /**
   * TabBar 红点提醒功能开关
   *
   * @type {boolean}
   * @default false - 默认关闭,等接口字段确定后再开启
   */
  tabbarBadge: true,

  /**
   * 红点字段名称
   *
   * @type {string}
   * @default 'unread_count'
   *
   * @example
   * // 如果后端返回不同字段,修改这里即可
   * tabbarBadgeField: 'has_notification'  // 布尔值
   * tabbarBadgeField: 'unread_count'     // 数字
   * tabbarBadgeField: 'message_badge'    // 对象
   */
  tabbarBadgeField: 'unread_msg_count',

  /**
   * 红点显示阈值
   *
   * @type {number}
   * @default 1
   *
   * @description
   * - 当字段为数字时:unread_count >= 1 显示红点
   * - 当字段为布尔值时:此配置无效
   */
  tabbarBadgeThreshold: 1
}

/**
 * 检查功能是否启用
 *
 * @param {string} featureName - 功能名称
 * @returns {boolean} 功能是否启用
 *
 * @example
 * import { isFeatureEnabled } from '@/config/features'
 *
 * if (isFeatureEnabled('tabbarBadge')) {
 *   // 显示红点
 * }
 */
export function isFeatureEnabled(featureName) {
  return features[featureName] === true
}

/**
 * 获取功能配置
 *
 * @param {string} featureName - 功能名称
 * @returns {*} 功能配置值
 *
 * @example
 * import { getFeatureConfig } from '@/config/features'
 *
 * const field = getFeatureConfig('tabbarBadgeField')
 * console.log(field) // 'unread_count'
 */
export function getFeatureConfig(featureName) {
  return features[featureName]
}