浏览器强制用谷歌,提供exe下载包

This commit is contained in:
guoyue 2022-10-08 13:38:46 +08:00
parent d13dbbb09a
commit 667d53484e
1 changed files with 79 additions and 0 deletions

View File

@ -24,6 +24,9 @@ import 'vue3-video-play-emiyagm/dist/style.css' // 引入css
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
console.log(111, 'main')
/**
* @author chuzhixin 1204505056@qq.com
* @description 正式环境默认使用mock正式项目记得注释后再打包
@ -54,3 +57,79 @@ router.beforeEach((to, from, next) => {
document.body.scrollTop = 0
next()
})
//
function judgeAgent() {
let userAgent = navigator.userAgent // userAgent
console.log('userAgent------------>', userAgent);
let isOpera = userAgent.indexOf('Opera') > -1
//Opera
if (isOpera) {
return 'Opera'
}
//Firefox
if (userAgent.indexOf('Firefox') > -1) {
return 'FF'
}
//chorme
if (userAgent.indexOf('Chrome') > -1) {
return 'Chrome'
}
//Safari
if (userAgent.indexOf('Safari') > -1) {
return 'Safari'
}
//IE
if (
userAgent.indexOf('compatible') > -1 &&
userAgent.indexOf('MSIE') > -1 &&
!isOpera
) {
return 'IE'
}
//Edge
if (userAgent.indexOf('Trident') > -1) {
return 'Edge'
}
}
function downloadFile(name, url) {
const alink = document.createElement('a');
alink.download = name;// ,,IE10
alink.href = url;// url
alink.click(); //
}
function getPCNum() {
const agent = navigator.userAgent.toLowerCase();
if (agent.indexOf('win32') >= 0 || agent.indexOf('wow32') >= 0) {
return 32;
}
if (agent.indexOf('win64') >= 0 || agent.indexOf('wow64') >= 0) {
return 64;
}
}
console.log('------判断浏览器------>', judgeAgent());
//
if (judgeAgent() !== 'Chrome') {
ElMessageBox.confirm('当前仅支持Chrome浏览器是否进行下载', '提示', {
confirmButtonText: '下载',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
//
const agent = getPCNum();
console.log('agent------------>', agent);
if (agent == 64) {
// 64
// downloadFile(_global.config.loginInfo.name_32, _global.config.loginInfo.url_32);
downloadFile('ChromeStandaloneSetup64.exe', '/static/download/ChromeStandaloneSetup64.exe');
} else {
// 32
downloadFile('ChromeStandalonesetup32.exe', '/static/download/standalonesetup32.exe');
}
}).catch(() => {
});
}