index.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /** 获取浏览器信息 */
  2. export const browser = () => {
  3. const u = navigator.userAgent;
  4. // console.log("🚀 ~ u:", u)
  5. return {
  6. trident: u.indexOf("Trident") > -1, //IE内核
  7. presto: u.indexOf("Presto") > -1, //opera内核
  8. webKit: u.indexOf("AppleWebKit") > -1, //苹果、谷歌内核
  9. gecko: u.indexOf("Gecko") > -1 && u.indexOf("KHTML") == -1, //火狐内核
  10. mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
  11. ios: !!u.match(/Mac OS X/), //ios终端
  12. // ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
  13. android: u.indexOf("ORCHESTRAAPPA") > -1 || u.indexOf("Adr") > -1, //android终端
  14. iPhone: u.indexOf("ORCHESTRAAPPI") > -1, //是否为iPhone或者QQHD浏览器
  15. isApp: u.indexOf("ORCHESTRAAPPI") > -1 || u.indexOf("ORCHESTRAAPPA") > -1,
  16. isTeacher: u.indexOf("ORCHESTRATEACHER") > -1,
  17. isStudent: u.indexOf("ORCHESTRASTUDENT") > -1,
  18. isSchool: u.indexOf("ORCHESTRASCHOOL") > -1,
  19. iPad: u.indexOf("iPad") > -1, //是否iPad
  20. webApp: u.indexOf("Safari") == -1, //是否web应该程序,没有头部与底部
  21. weixin: u.indexOf("MicroMessenger") > -1, //是否微信 (2015-01-22新增)
  22. alipay: u.indexOf("AlipayClient") > -1, //是否支付宝
  23. huawei: !!u.match(/huawei/i) || !!u.match(/honor/i),
  24. xiaomi: !!u.match(/mi\s/i) || !!u.match(/redmi/i) || !!u.match(/mix/i),
  25. };
  26. };
  27. export const getRandomKey = () => {
  28. const key = "" + new Date().getTime() + Math.floor(Math.random() * 1000000);
  29. return key;
  30. };
  31. export const AuthorizationKey = "AUTHORIZATION";
  32. /** 设置token */
  33. export const setToken = (value: any) => {
  34. sessionStorage.setItem(AuthorizationKey, value);
  35. };
  36. /** 获取token */
  37. export const getToken = () => {
  38. return sessionStorage.getItem(AuthorizationKey) || "";
  39. };