2021-08-06 11:40:18 +08:00
|
|
|
<template>
|
|
|
|
|
<transition name="el-zoom-in-center">
|
2021-09-15 09:45:49 +08:00
|
|
|
<div v-show="browserWindowZoom" class="zoom" style="z-index: 101;">
|
2021-08-06 11:40:18 +08:00
|
|
|
<i class="nz-icon nz-icon-about-full"></i>
|
|
|
|
|
<span>{{$t('tip.zoomStatusPrompt')}}</span>
|
|
|
|
|
<button class="zoom-button" @click="doNotAskAgain">{{$t('tip.doNotAskAgain')}}</button>
|
|
|
|
|
</div>
|
|
|
|
|
</transition>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
name: 'browserWindowZoom',
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
browserWindowZoom: false,
|
|
|
|
|
timer: null,
|
|
|
|
|
flag: true
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted () {
|
|
|
|
|
// 获取localStorage中的key值
|
|
|
|
|
const data = localStorage.getItem('browserZoom')
|
|
|
|
|
// 判断是否执行缩放弹框功能
|
|
|
|
|
if (data != 0) {
|
|
|
|
|
window.addEventListener('resize', this.browserZoom)
|
2021-08-12 14:28:23 +08:00
|
|
|
document.addEventListener('DOMContentLoaded', this.browserZoom)
|
2021-08-06 11:40:18 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
beforeDestroy () {
|
|
|
|
|
// 移除定时器
|
|
|
|
|
clearInterval(this.timer)
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
doNotAskAgain () {
|
|
|
|
|
// 点击事件隐藏弹框
|
|
|
|
|
this.browserWindowZoom = false
|
|
|
|
|
// 存储localStorage的key值
|
|
|
|
|
localStorage.setItem('browserZoom', 0)
|
|
|
|
|
// 移除事件
|
|
|
|
|
window.removeEventListener('resize', this.browserZoom)
|
2021-08-12 14:28:23 +08:00
|
|
|
document.removeEventListener('DOMContentLoaded', this.browserZoom)
|
2021-08-06 11:40:18 +08:00
|
|
|
},
|
|
|
|
|
browserZoom () {
|
|
|
|
|
// 初始缩放比例
|
|
|
|
|
let originPixelRatio = localStorage.devicePixelRatio
|
|
|
|
|
if (!originPixelRatio) {
|
|
|
|
|
originPixelRatio = window.devicePixelRatio
|
|
|
|
|
// 整数才保存
|
|
|
|
|
if (Number.isInteger(originPixelRatio)) {
|
|
|
|
|
localStorage.devicePixelRatio = originPixelRatio
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let lastPixelRatio = originPixelRatio
|
|
|
|
|
const currentPixelRatio = window.devicePixelRatio
|
|
|
|
|
if (currentPixelRatio !== lastPixelRatio) {
|
|
|
|
|
// console.log('缩放比例是:' + Math.round(1000 * (currentPixelRatio / originPixelRatio)) / 10 + '%');
|
|
|
|
|
// 计算缩放百分比
|
|
|
|
|
const zoom = Math.round(1000 * (currentPixelRatio / originPixelRatio)) / 10 + '%'
|
|
|
|
|
if (zoom != '100%') {
|
|
|
|
|
// 缩放时显示弹框
|
|
|
|
|
this.browserWindowZoom = true
|
2021-08-09 14:21:17 +08:00
|
|
|
// 定义开关防止重复触发
|
2021-08-06 11:40:18 +08:00
|
|
|
let flag = true
|
|
|
|
|
// 定时器5秒后隐藏弹框
|
|
|
|
|
if (flag === true) {
|
2021-08-09 14:21:17 +08:00
|
|
|
// 设置定时器
|
2021-08-06 11:40:18 +08:00
|
|
|
this.timer = setTimeout(() => {
|
|
|
|
|
this.browserWindowZoom = false
|
|
|
|
|
}, 5000)
|
2021-08-09 14:21:17 +08:00
|
|
|
// 关闭
|
2021-08-06 11:40:18 +08:00
|
|
|
flag = false
|
|
|
|
|
}
|
2021-08-09 14:21:17 +08:00
|
|
|
// 打开
|
2021-08-06 11:40:18 +08:00
|
|
|
flag = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 记住上一次的设备像素比
|
|
|
|
|
lastPixelRatio = currentPixelRatio
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|