device.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * 检查是否为小程序环境
  3. * @returns 是否为小程序环境
  4. */
  5. export const isMp = (): boolean => {
  6. // #ifdef MP
  7. return true;
  8. // #endif
  9. return false;
  10. };
  11. /**
  12. * 检查是否为App环境
  13. * @returns 是否为App环境
  14. */
  15. export const isApp = (): boolean => {
  16. // #ifdef APP
  17. return true;
  18. // #endif
  19. return false;
  20. };
  21. /**
  22. * 检查是否为App-IOS环境
  23. * @returns 是否为App-IOS环境
  24. */
  25. export const isAppIOS = (): boolean => {
  26. // #ifdef APP-IOS
  27. return true;
  28. // #endif
  29. return false;
  30. };
  31. /**
  32. * 检查是否为App-Android环境
  33. * @returns 是否为App-Android环境
  34. */
  35. export const isAppAndroid = (): boolean => {
  36. // #ifdef APP-ANDROID
  37. return true;
  38. // #endif
  39. return false;
  40. };
  41. /**
  42. * 检查是否为H5环境
  43. * @returns 是否为H5环境
  44. */
  45. export const isH5 = (): boolean => {
  46. // #ifdef H5
  47. return true;
  48. // #endif
  49. return false;
  50. };
  51. /**
  52. * 检查是否为鸿蒙环境
  53. * @returns 是否为鸿蒙环境
  54. */
  55. export const isHarmony = (): boolean => {
  56. // #ifdef APP-HARMONY
  57. return true;
  58. // #endif
  59. return false;
  60. };
  61. /**
  62. * 获取设备像素比
  63. * @returns 设备像素比
  64. */
  65. export const getDevicePixelRatio = (): number => {
  66. const dpr = uni.getDeviceInfo().devicePixelRatio ?? 1;
  67. // #ifdef MP
  68. // 微信小程序高清处理
  69. return 3;
  70. // #endif
  71. return dpr;
  72. };