移动设备判断

Former-commit-id: b0fcd554d934259ea58187452785c3a9a56c64a4 [formerly b0fcd554d934259ea58187452785c3a9a56c64a4 [formerly b0fcd554d934259ea58187452785c3a9a56c64a4 [formerly b0fcd554d934259ea58187452785c3a9a56c64a4 [formerly 34226601ec79c52767f74109b1813a396d2dc605 [formerly dbb1af9b0c7b60efa8f8b9f9bee8da61b3197ac3]]]]]
Former-commit-id: 4a0fac504665277509d1f4a65fa63eddf170bfc1
Former-commit-id: 3666dfaef0e6eb43a62959a00832a67540a9e0df
Former-commit-id: 14836b621d0f8d0b3d0982eec086fa6334afd80d [formerly 5b1ed7a7065b47fd37de6ed71db4c6b709ded728]
Former-commit-id: ac7827d7b5674c7bb57764686c10f1721d4ceca7
Former-commit-id: 4bb10eb0e6081ef9556380c92a992b810936477f
Former-commit-id: 12fa567115e57ce5da084eaa1cbd5e0d842f470d
Former-commit-id: a927e3bc505c09154e1054d0aee79d42711570aa
Former-commit-id: 8907e13de1ebe0478bc1d7776553f156e361ec37
This commit is contained in:
liyang
2018-07-21 08:47:51 +08:00
parent 87b8f26a85
commit 07dc8bf834
8 changed files with 29 additions and 66 deletions

View File

@@ -26,34 +26,12 @@ util.title = function (titleText) {
}
/**
* @description [ 私有 ] 获取所有的 UA 信息
* @description 获取所有的 UA 信息
*/
function getUa () {
util.ua = function () {
return new UaParser().getResult()
}
/**
* @description 返回当前设备是否是手机
*/
util.isMobile = function (ua) {
return (ua || getUa()).device.type === 'mobile'
}
/**
* @description 获取并存储用户 UA 同时对危险环境做检查
* @param {object} vm vue
*/
util.uaGet = function (vm) {
// 获取 UA
const ua = getUa()
// 存储
vm.$store.commit('d2adminUaSet', ua)
// 判断
if (util.isMobile(ua)) {
vm.$router.replace({ name: 'is-mobile' })
}
}
/**
* @description 判断是否在其内
* @param {*} ele element

View File

@@ -53,8 +53,8 @@ new Vue({
mounted () {
// D2Admin 开发环境检查更新
util.checkUpdate(this)
// 获取并记录用户 UA 同时对危险环境做出判断
util.uaGet(this)
// 获取并记录用户 UA
this.$store.commit('d2adminUaGet')
// 展示系统信息
util.showInfo()
// 用户登陆后从数据库加载一系列的设置

View File

@@ -16,17 +16,6 @@ let router = new VueRouter({ routes })
* 权限验证
*/
router.beforeEach((to, from, next) => {
const isMobile = util.isMobile()
// 禁止手机访问
if (to.name !== 'is-mobile' && isMobile) {
next({ name: 'is-mobile' })
return
}
// 如果是电脑访问手机提示页面的话 -> 跳转到首页
if (to.name === 'is-mobile' && !isMobile) {
next({ name: 'index' })
return
}
// 验证当前路由所有的匹配中是否需要有登陆验证的
if (to.matched.some(r => r.meta.requiresAuth)) {
// 这里暂时将cookie里是否存有token作为验证是否登陆的条件

View File

@@ -1 +1 @@
488c440e7112793c7321bc1ef62f74fe0bba9138
e771f2f57cedfc8d2e3e0a07a9b4f1f0ada4f152