GrayManageModel.ets
5.3 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import { Logger } from 'wdKit';
import { HttpUtils } from 'wdNetwork/Index';
export interface mournsInfoModel{
switchOpen : boolean
bottomNavOpen : boolean
greyUserList : Array<string>
newsList : Array<string>
onlineState : number
rmhList : Array<string>
selectAll : boolean
serverList : Array<string>
videoList : Array<string>
md5 : string
}
const TAG: string = 'GrayManageModel';
/**
* 国殇管理
*/
export class GrayManageModel {
/**
* 用户ID
*/
private user_id = HttpUtils.getUserId()
/**
* 国殇模式开关:true-开启, false-关闭
*/
private switchOpen: boolean = false
/**
* 灰度状态: 0-待上线, 1-灰度中,2-全量发布
*/
private onlineState: number = 0
/**
* 底部导航开关(TAB图标/文字): true-开启,false-关闭
*/
private bottomNavOpen: boolean = false
/**
* 涉及范围选择,一键全选: true-全选, false-非全选
*/
private selectAll: boolean = false
/**
* 新闻频道集合
*/
private newsList: Array<string> = []
/**
* 人民号频道集合
*/
private rmhList: Array<string> = []
/**
* 视频频道集合
*/
private videoList: Array<string> = []
/**
* 服务频道集合
*/
private serverList: Array<string> = []
/**
* 灰度用户userId集合
*/
private grayUserList: Array<string> = []
public setMourning(mourns: mournsInfoModel) {
this.switchOpen = mourns.switchOpen
this.bottomNavOpen = mourns.bottomNavOpen
this.onlineState = mourns.onlineState
this.selectAll = mourns.selectAll
this.newsList = mourns.newsList
this.rmhList = mourns.rmhList
this.videoList = mourns.videoList
this.serverList = mourns.serverList
this.grayUserList = mourns.greyUserList
Logger.debug(TAG, 'LaunchDataModel.mourns', JSON.stringify(mourns))
}
// 国殇模式开启
public isMourning(): boolean {
// 基础条件:国殇模式主开关开启
if (!this.switchOpen) {
return false;
}
// 灰度发布状态下,需额外检查用户是否在灰度名单内
if (this.onlineState === 1 && !this.grayUserList.includes(`${this.user_id}`)) {
return false;
}
// 在线状态为2(全量发布)或未明确提及的其他状态,默认视为全量或同全量处理
return true;
}
// 国殇模式开启 底导国殇模式开启
public isBottomNavMourning(): boolean {
return (
this.switchOpen && // 国殇模式总开关开启
this.bottomNavOpen && // 底部导航国殇模式开关开启
(
this.onlineState !== 1 || // 非灰度发布状态直接开启
this.onlineState === 1 && this.grayUserList.includes(`${this.user_id}`) // 灰度发布且用户在灰度列表内
)
);
}
// 国殇模式开启 新闻频道国殇模式开启 一键全选: true-全选, false-非全选
public isNewsMourning(channelId: string): boolean {
// 检查最基本的前提条件
if (!this.switchOpen) {
return false;
}
// 对于灰度发布状态(onlineState === 1),用户需在灰度名单内
if (this.onlineState === 1 && !this.grayUserList.includes(`${this.user_id}`)) {
return false;
}
// 在国殇模式开启、用户符合条件的前提下:
// - 否则检查channelId是否在newsList中以决定是否开启国殇模式
return this.newsList.includes(channelId);
}
// 国殇模式开启 人民号频道国殇模式开启 一键全选: true-全选, false-非全选
public isRmhMourning(channelId: string): boolean {
// 检查最基本的前提条件
if (!this.switchOpen) {
return false;
}
// 对于灰度发布状态(onlineState === 1),用户需在灰度名单内
if (this.onlineState === 1 && !this.grayUserList.includes(`${this.user_id}`)) {
return false;
}
// 在国殇模式开启、用户符合条件的前提下:
// - 否则检查channelId是否在rmhList中以决定是否开启国殇模式
return this.rmhList.includes(channelId);
}
// 国殇模式开启 视频频道频道国殇模式开启 一键全选: true-全选, false-非全选
public isVideoMourning(channelId: string): boolean {
// 检查最基本的前提条件
if (!this.switchOpen) {
return false;
}
// 对于灰度发布状态(onlineState === 1),用户需在灰度名单内
if (this.onlineState === 1 && !this.grayUserList.includes(`${this.user_id}`)) {
return false;
}
// 在国殇模式开启、用户符合条件的前提下:
// - 否则检查channelId是否在videoList中以决定是否开启国殇模式
return this.videoList.includes(channelId);
}
// 国殇模式开启 视频频道频道国殇模式开启 一键全选: true-全选, false-非全选
public isServerMourning(channelId: string): boolean {
// 检查最基本的前提条件
if (!this.switchOpen) {
return false;
}
// 对于灰度发布状态(onlineState === 1),用户需在灰度名单内
if (this.onlineState === 1 && !this.grayUserList.includes(`${this.user_id}`)) {
return false;
}
// 在国殇模式开启、用户符合条件的前提下:
// - 否则检查channelId是否在serverList中以决定是否开启国殇模式
return this.serverList.includes(channelId);
}
}