isPC.js 939 B

12345678910111213141516171819202122
  1. export function isPC() {
  2. var userAgentInfo = navigator.userAgent || '';
  3. var info = typeof uni !== 'undefined' && uni.getSystemInfoSync ? uni.getSystemInfoSync() : null;
  4. if (info && info.deviceType) {
  5. if (info.deviceType === 'pc') return true;
  6. if (info.deviceType === 'phone' || info.deviceType === 'pad') return false;
  7. }
  8. var isMobileUA = /Android|iPhone|SymbianOS|Windows Phone|iPad|iPod|Mobile|Harmony|HarmonyOS/i.test(userAgentInfo);
  9. if (isMobileUA) return false;
  10. var hasTouch = false;
  11. if (typeof navigator.maxTouchPoints === 'number') {
  12. hasTouch = navigator.maxTouchPoints > 0;
  13. } else if (typeof window !== 'undefined') {
  14. hasTouch = 'ontouchstart' in window;
  15. }
  16. if (hasTouch && typeof window !== 'undefined' && window.matchMedia) {
  17. var finePointer = window.matchMedia('(pointer: fine)').matches;
  18. var canHover = window.matchMedia('(hover: hover)').matches;
  19. return finePointer || canHover;
  20. }
  21. return !hasTouch;
  22. }