features.js
2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* 功能开关配置
*
* @description 用于控制功能的启用/禁用状态,方便灰度发布和功能回滚
* @module config/features
*/
/**
* 功能配置项
*
* @property {boolean} tabbarBadge - TabBar 红点提醒功能
* - true: 启用红点提醒(根据后端返回的 unread_count 判断)
* - false: 禁用红点提醒
*
* @property {string} tabbarBadgeField - 红点字段名称
* - 从用户信息接口读取该字段判断是否显示红点
* - 当前使用 'unread_count',后续可能根据实际接口调整
*
* @property {number} tabbarBadgeThreshold - 红点显示阈值
* - 当 unread_count >= 该值时显示红点
* - 默认为 1,即有未读消息时显示
*/
export const features = {
/**
* TabBar 红点提醒功能开关
*
* @type {boolean}
* @default false - 默认关闭,等接口字段确定后再开启
*/
tabbarBadge: false,
/**
* 红点字段名称
*
* @type {string}
* @default 'unread_count'
*
* @example
* // 如果后端返回不同字段,修改这里即可
* tabbarBadgeField: 'has_notification' // 布尔值
* tabbarBadgeField: 'unread_count' // 数字
* tabbarBadgeField: 'message_badge' // 对象
*/
tabbarBadgeField: 'unread_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]
}