diff --git a/env.config.js b/env.config.js index 22057c1..cb339b0 100644 --- a/env.config.js +++ b/env.config.js @@ -12,16 +12,20 @@ const getRepoInfo = require('git-repo-info'); const envConfig = { dev : { - base_url: 'https://k8s-horse-gateway.mashibing.cn' + base_url: 'https://k8s-horse-gateway.mashibing.cn', + h5_url:'http://k8s-shop-app.mashibing.cn/' }, test : { - base_url: 'https://k8s-horse-gateway.mashibing.cn' + base_url: 'https://k8s-horse-gateway.mashibing.cn', + h5_url:'http://k8s-shop-app.mashibing.cn/' }, beta : { - base_url: 'https://you-gateway.mashibing.com' + base_url: 'https://you-gateway.mashibing.com', + h5_url:'https://you-app.mashibing.com/' }, prod : { - base_url: 'https://you-gateway.mashibing.com' + base_url: 'https://you-gateway.mashibing.com', + h5_url:'https://you-app.mashibing.com/' } } const branch = getRepoInfo().branch; // 调用获取git信息 diff --git a/middleware/browser.js b/middleware/browser.js new file mode 100644 index 0000000..4f6d2b4 --- /dev/null +++ b/middleware/browser.js @@ -0,0 +1,126 @@ +import ENV from '@/plugins/config/env.js'; +export default function (context) { + context.userAgent = process.server ? context.req.headers['user-agent'] : navigator.userAgent; + // 各主流浏览器 + function getBrowser() { + var u = context.userAgent; + var bws = [ + { + name: 'sgssapp', + it: /sogousearch/i.test(u), + }, + { + name: 'wechat', + it: /MicroMessenger/i.test(u), + }, + { + name: 'weibo', + it: !!u.match(/Weibo/i), + }, + { + name: 'uc', + it: !!u.match(/UCBrowser/i) || u.indexOf(' UBrowser') > -1, + }, + { + name: 'sogou', + it: u.indexOf('MetaSr') > -1 || u.indexOf('Sogou') > -1, + }, + { + name: 'xiaomi', + it: u.indexOf('MiuiBrowser') > -1, + }, + { + name: 'baidu', + it: u.indexOf('Baidu') > -1 || u.indexOf('BIDUBrowser') > -1, + }, + { + name: '360', + it: u.indexOf('360EE') > -1 || u.indexOf('360SE') > -1, + }, + { + name: '2345', + it: u.indexOf('2345Explorer') > -1, + }, + { + name: 'edge', + it: u.indexOf('Edge') > -1, + }, + { + name: 'edg', + it: u.indexOf('Edg') > -1, + }, + { + name: 'ie11', + it: u.indexOf('Trident') > -1 && u.indexOf('rv:11.0') > -1, + }, + { + name: 'ie', + it: u.indexOf('compatible') > -1 && u.indexOf('MSIE') > -1, + }, + { + name: 'firefox', + it: u.indexOf('Firefox') > -1, + }, + { + name: 'safari', + it: u.indexOf('Safari') > -1 && u.indexOf('Chrome') === -1, + }, + { + name: 'qqbrowser', + it: u.indexOf('MQQBrowser') > -1 && u.indexOf(' QQ') === -1, + }, + { + name: 'qq', + it: u.indexOf('QQ') > -1, + }, + { + name: 'chrome', + it: u.indexOf('Chrome') > -1 || u.indexOf('CriOS') > -1, + }, + { + name: 'opera', + it: u.indexOf('Opera') > -1 || u.indexOf('OPR') > -1, + }, + ]; + + for (var i = 0; i < bws.length; i++) { + if (bws[i].it) { + return bws[i].name; + } + } + + return 'other'; + } + + var os = (function () { + var ua = context.userAgent, + isWindowsPhone = /(?:Windows Phone)/.test(ua), + isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone, + isAndroid = /(?:Android)/.test(ua), + isFireFox = /(?:Firefox)/.test(ua), + isChrome = /(?:Chrome|CriOS)/.test(ua), + isTablet = + /(?:iPad|PlayBook)/.test(ua) || + (isAndroid && !/(?:Mobile)/.test(ua)) || + (isFireFox && /(?:Tablet)/.test(ua)), + isPhone = /(?:iPhone)/.test(ua) && !isTablet, + isPc = !isPhone && !isAndroid && !isSymbian; + return { + isTablet: isTablet, + isPhone: isPhone, + isAndroid: isAndroid, + isPc: isPc, + isChrome: isChrome, + }; + })(); + + if (os.isAndroid || os.isPhone) { + console.log('手机'); + let url = ENV.h5_url + context.redirect(url); + } else if (os.isTablet) { + console.log('平板'); + } else if (os.isPc) { + console.log('电脑'); + } +} diff --git a/nuxt.config.js b/nuxt.config.js index 1288de9..b8b34fc 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -30,7 +30,7 @@ export default { component: resolve(__dirname, 'pages/index/index.vue') }) }, - middleware: ['redirect'] + middleware: ['redirect','browser'] }, // Global CSS: https://go.nuxtjs.dev/config-css