function getWeekday(date: string | number | Date) {
  if (!date) return '异常日期';
  const daysOfWeek = ['日', '一', '二', '三', '四', '五', '六'];  // 星期几的中文表示
  const day = new Date(date).getDay();  // 获取星期几,0: 星期日, 1: 星期一, ..., 6: 星期六
  return '周' + daysOfWeek[day];
}

/**
   * 将16进制颜色和透明度值合并为RGBA格式
   * @param {string} hex 16进制颜色(例如:#000000)
   * @param {number} alpha 透明度值(0-1之间)
   * @returns {string} RGBA格式的颜色值
   */
function hexToRgba(hex: string, alpha: number) {
  // 去掉 # 符号
  hex = hex.replace('#', '');

  // 如果是三位数的6进制,转为6位数(例如:#fff -> #ffffff)
  if (hex.length === 3) {
    hex = hex.split('').map(function (hex) {
      return hex + hex;
    }).join('');
  }

  // 解析颜色值
  const r = parseInt(hex.substring(0, 2), 16);
  const g = parseInt(hex.substring(2, 4), 16);
  const b = parseInt(hex.substring(4, 6), 16);

  // 返回RGBA格式的颜色值
  return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}


// 防抖
function debounce (fn: any, time: number) {
  let timer: number;
  return function (this: any, ...args: any[]) {
    clearTimeout(timer);
    timer = setTimeout(() => {
      fn.apply(this, args);
      clearTimeout(timer);
    }, time);
  };
}

// 节流
function throttle (fn: any, time: number) {
  let inThrottle: any;
  return function (this: any, ...args: any[]) {
    // const context = this;
    // const args = arguments;
    if (!inThrottle) {
      fn.apply(this, args);
      inThrottle = true;
      setTimeout(function () {
        inThrottle = false;
      }, time);
    }
  };
}

// 获取周几
import * as moment from 'moment';
function getWeek (date: any) { // 参数时间戳
  let week = moment.default(date).day();
  switch (week) {
    case 1:
      return '周一';
    case 2:
      return '周二';
    case 3:
      return '周三';
    case 4:
      return '周四';
    case 5:
      return '周五';
    case 6:
      return '周六';
    case 0:
      return '周日';
  }
}

function getTeamErrorLogo(team_logo:any){
  if(team_logo){
    return `this.src='${team_logo}';this.onerror=null`;
  }else{
    return "this.src='https://img2.ydniu.com/app/images/team_logo.png';this.onerror=null"
  }
}

function getTeamLazyErrorLogo(team_logo:any){
  if(team_logo){
    return team_logo;
  }else{
    return "https://img2.ydniu.com/app/images/team_logo.png";
  }
}

export { getWeekday, hexToRgba, debounce, throttle, getWeek, getTeamErrorLogo, getTeamLazyErrorLogo };