Skip to content

Commit a05aca1

Browse files
committedMay 9, 2021
feat: ✨ 判断是否是PC端,如果非PC端则跳转到移动端页面
1 parent 466b8e6 commit a05aca1

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed
 

‎src/main.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Vue from 'vue'
2+
import './plugins/toMobile.js'
23
import VueProgressBar from 'vue-progressbar'
34
import './plugins/axios'
45
import App from './App.vue'
@@ -11,17 +12,17 @@ import './plugins/element.js'
1112
import moment from 'moment'
1213
import './style/common.scss'
1314
import AsideAd from '@/components/AsideAd.vue'
14-
import * as Sentry from '@sentry/browser'
15-
import { Vue as VueIntegration } from '@sentry/integrations'
15+
// import * as Sentry from '@sentry/browser'
16+
// import { Vue as VueIntegration } from '@sentry/integrations'
1617

17-
if (process.env.NODE_ENV === 'production') {
18-
Sentry.init({
19-
dsn: 'https://53e44732a0fd4c398fe614fd058f1668@o412908.ingest.sentry.io/5296080',
20-
release: process.env.RELEASE_VERSION,
21-
environment: process.env.NODE_ENV,
22-
integrations: [new VueIntegration({ Vue, attachProps: true, logErrors: true })]
23-
})
24-
}
18+
// if (process.env.NODE_ENV === 'production') {
19+
// Sentry.init({
20+
// dsn: 'https://53e44732a0fd4c398fe614fd058f1668@o412908.ingest.sentry.io/5296080',
21+
// release: process.env.RELEASE_VERSION,
22+
// environment: process.env.NODE_ENV,
23+
// integrations: [new VueIntegration({ Vue, attachProps: true, logErrors: true })]
24+
// })
25+
// }
2526

2627
// console.log(process.env.VUE_APP_host)
2728
// console.log(process.env.VUE_APP_pathname)

‎src/plugins/toMobile.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* eslint-disable no-useless-escape */
2+
/* eslint-disable no-mixed-operators */
3+
// 移动端跳转
4+
var OS = (function () {
5+
var a = navigator.userAgent
6+
var b = /(?:Android)/.test(a)
7+
var d = /(?:Firefox)/.test(a)
8+
var e = /(?:Mobile)/.test(a)
9+
var f = b && e
10+
var g = b && !f
11+
var c = /(?:iPad.*OS)/.test(a)
12+
var h = !c && /(?:iPhone\sOS)/.test(a)
13+
var k = c || g || /(?:PlayBook)/.test(a) || d && /(?:Tablet)/.test(a)
14+
a = !k && (b || h || /(?:(webOS|hpwOS)[\s\/]|BlackBerry.*Version\/|BB10.*Version\/|CriOS\/)/.test(a) || d && e)
15+
return {
16+
android: b,
17+
androidPad: g,
18+
androidPhone: f,
19+
ipad: c,
20+
iphone: h,
21+
tablet: k,
22+
phone: a
23+
}
24+
}())
25+
if (OS.phone || OS.ipad) {
26+
const url = `${location.origin}${location.pathname.replace('/vue-blog', '/blogNuxtM')}${location.search}${location.hash}`
27+
location.href = url
28+
}

0 commit comments

Comments
 (0)
Please sign in to comment.