From bf110e56e220b92e4a4a67e9ee172469ed8637a2 Mon Sep 17 00:00:00 2001 From: expoli <31023767+expoli@users.noreply.github.com> Date: Mon, 13 Mar 2023 12:11:45 +0800 Subject: [PATCH] [fix] TypeError: navigator.userAgentData.mobile is undefined --- lib/utils.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/utils.js b/lib/utils.js index 0b997696..59c760e9 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -124,3 +124,30 @@ export const getListByPage = function (list, pageIndex, pageSize) { pageIndex * pageSize ) } + +/** + * 判断是否移动设备 + */ +export const isMobile = () => { + let isMobile = false + if (!isBrowser()) { + return isMobile + } + // if (!isMobile && navigator.userAgentData.mobile) { + // isMobile = true + // } + + if (!isMobile && (/Mobi|Android|iPhone/i.test(navigator.userAgent))) { + isMobile = true + } + + if (/Android|iPhone|iPad|iPod/i.test(navigator.platform)) { + isMobile = true + } + + if (typeof window.orientation !== 'undefined') { + isMobile = true + } + + return isMobile +}