From 78751d835fc512baaa200f5509306ec1109b4632 Mon Sep 17 00:00:00 2001 From: hooray <304327508@qq.com> Date: Wed, 13 Oct 2021 10:47:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A1=86=E6=9E=B6=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=98=AF=E5=90=A6=E4=B8=BA=E7=A7=BB=E5=8A=A8=E7=AB=AF?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/settings.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/store/modules/settings.js b/src/store/modules/settings.js index 9f28d537..90ca656a 100644 --- a/src/store/modules/settings.js +++ b/src/store/modules/settings.js @@ -20,10 +20,20 @@ const getters = {} const actions = {} const mutations = { - // 设置访问模式,页面宽度小于 992px 时切换为移动端展示 + // 设置访问模式 setMode(state, width) { - if (state.enableMobileAdaptation && width < 992) { - state.mode = 'mobile' + if (state.enableMobileAdaptation) { + // 先判断 UA 是否为移动端设备(手机&平板) + if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { + state.mode = 'mobile' + } else { + // 如果为桌面设备,再根据页面宽度判断是否需要切换为移动端展示 + if (width < 992) { + state.mode = 'mobile' + } else { + state.mode = 'pc' + } + } } else { state.mode = 'pc' }