提交 3a60e9c1 编写于 作者: zhongyao.qiao's avatar zhongyao.qiao

feat 增加客户端判断

上级 699b060a
...@@ -16,6 +16,7 @@ import JsEncrypt from 'jsencrypt/bin/jsencrypt'; ...@@ -16,6 +16,7 @@ import JsEncrypt from 'jsencrypt/bin/jsencrypt';
window.JSEncrypt = JsEncrypt; window.JSEncrypt = JsEncrypt;
window.CryptoJS = CryptoJS; window.CryptoJS = CryptoJS;
var lastTouchEnd = 0; var lastTouchEnd = 0;
document.addEventListener('touchstart', function (event) { document.addEventListener('touchstart', function (event) {
if (event.touches.length > 1) { if (event.touches.length > 1) {
event.preventDefault(); event.preventDefault();
...@@ -43,17 +44,15 @@ document.documentElement.addEventListener( ...@@ -43,17 +44,15 @@ document.documentElement.addEventListener(
passive: false, passive: false,
} }
); );
console.log('z', vueApp.$rocNative);
vueApp.$rocNative.appInit(); vueApp.$rocNative.appInit();
vueApp.$rocNative.on('wx_ready', function () { vueApp.$rocNative.on('wx_ready', function () {
console.log('-wx_ready-', window._picaWechat); console.log('-wx_ready-', window._picaWechat);
// 初始化wx jssdk 后 执行 脚手架将 wx 对象挂在到 $rocNative对象上,后执行 小程序环境判断方法 miniProgram.getEnv // 初始化wx jssdk 后 执行 脚手架将 wx 对象挂在到 $rocNative对象上,后执行 小程序环境判断方法 miniProgram.getEnv
vueApp.$rocNative.WXInstance.miniProgram.getEnv(function (res) { vueApp.$rocNative.WXInstance.miniProgram.getEnv(function (res) {
console.log('_miniprogram', res); // true console.log('_miniprogram', res.miniprogram); // true
window._miniprogram = res.miniprogram; window._miniprogram = res.miniprogram;
}); });
}); });
console.log('---', isWeixin());
if (isWeixin()) { if (isWeixin()) {
window._picaWechat = 'wechat'; window._picaWechat = 'wechat';
} }
......
...@@ -26,15 +26,47 @@ export const formatDay = (datetime) => { ...@@ -26,15 +26,47 @@ export const formatDay = (datetime) => {
// 判断是否是微信 // 判断是否是微信
export function isWeixin() { export function isWeixin() {
const ua = window.navigator.userAgent.toLowerCase(); const ua = window.navigator.userAgent;
console.log('🚀 ~ ua:', ua); console.log('🚀 ~ ua:', ua);
// if(ua.match(/MicroMessenger/i) == 'micromessenger' || ua.match(/_SQ_/i) == '_sq_') { if (ua.match(/MicroMessenger/i) === 'MicroMessenger') {
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
return true; return true;
} else { } else {
return false; return false;
} }
} }
export function isMobile() {
const ua = window.navigator.userAgent || window.opera;
// 移动端设备列表,可以根据需要扩展
const mobileDevices = [
'Android',
'iPhone',
'iPad',
'iPod',
'BlackBerry',
'Windows Phone',
'IEMobile',
'Opera Mini',
'Mobile',
'Mobile Safari',
'Silk-Accelerated',
'Firefox Mobile',
'Kindle',
'Silk',
'Opera Mobi',
'Chrome Mobile',
'UC Browser',
'Mobile Safari',
'Mobile Chrome',
];
// 遍历移动端设备列表,检查用户代理字符串中是否包含这些关键词
for (let i = 0; i < mobileDevices.length; i++) {
if (ua.indexOf(mobileDevices[i]) !== -1) {
return true; // 是移动端
}
}
return false;
}
// 时间戳 格式化为 时分秒(00: 00: 00) // 时间戳 格式化为 时分秒(00: 00: 00)
export const formatDuring = (time) => { export const formatDuring = (time) => {
......
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
<script> <script>
import { getBanner, getRequestParm } from '@/api/entitlement'; import { getBanner, getRequestParm } from '@/api/entitlement';
import { uploadPointData } from '@/api/question'; import { uploadPointData } from '@/api/question';
import { isWeixin } from '@/utils/index'; import { isWeixin, isMobile } from '@/utils/index';
export default { export default {
data() { data() {
...@@ -104,7 +104,20 @@ export default { ...@@ -104,7 +104,20 @@ export default {
}; };
}, },
created() { created() {
if (!isWeixin()) { console.log('🚀 isMobile', isMobile());
console.log('🚀 isWeixin', isWeixin());
if (!isMobile()) {
this.$dialog
.alert({
type: 'warning',
title: '提示',
message: '请使用手机微信打开!',
confirmButtonText: '我知道了',
})
.then(() => {
// on close
});
} else if (!isWeixin()) {
this.$dialog this.$dialog
.alert({ .alert({
type: 'warning', type: 'warning',
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册