export const browser = () => {
  const u = navigator.userAgent;
  return {
    trident: u.indexOf('Trident') > -1, //IE内核
    presto: u.indexOf('Presto') > -1, //opera内核
    webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
    gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
    mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
    ios: !!u.match(/Mac OS X/), //ios终端
    // ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
    android: u.indexOf('DAYAAPPA') > -1 || u.indexOf('Adr') > -1, //android终端
    iPhone: u.indexOf('DAYAAPPI') > -1, //是否为iPhone或者QQHD浏览器
    isApp:
      u.indexOf('DAYAAPPI') > -1 ||
      u.indexOf('DAYAAPPA') > -1 ||
      u.indexOf('Adr') > -1,
    iPad: u.indexOf('iPad') > -1, //是否iPad
    webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部
    weixin: u.indexOf('MicroMessenger') > -1, //是否微信 （2015-01-22新增）
    alipay: u.indexOf('AlipayClient') > -1, //是否支付宝
    huawei: !!u.match(/huawei/i) || !!u.match(/honor/i),
    xiaomi: !!u.match(/mi\s/i) || !!u.match(/redmi/i) || !!u.match(/mix/i)
  };
};

export const getRandomKey = () => {
  const key = '' + new Date().getTime() + Math.floor(Math.random() * 1000000);
  return key;
};

/**
 * 删除token
 */
export const removeAuth = () => {
  sessionStorage.removeItem('Authorization');
};

/**
 * 设置token
 * @param token
 * @returns {void}
 */
export const setAuth = (token: any) => {
  sessionStorage.setItem('Authorization', token);
};

/**
 * 获取token
 */
export const getAuth = () => {
  sessionStorage.getItem('Authorization');
};

export function checkPhone(phone: string) {
  const phoneRule =
    /^((13[0-9])|(14(0|[5-7]|9))|(15([0-3]|[5-9]))|(16(2|[5-7]))|(17[0-8])|(18[0-9])|(19([0-3]|[5-9])))\d{8}$/;
  return phoneRule.test(phone);
}

export const getHttpOrigin = () => {
	return window.location.origin
}
