GrayManageModel.ets 5.3 KB
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);
  }

}