zoom.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Notification } from 'element-ui'
  2. import Cookie from 'js-cookie'
  3. const detectZoom = () => {
  4. let ratio = 0,
  5. screen = window.screen,
  6. ua = navigator.userAgent.toLowerCase();
  7. if (window.devicePixelRatio !== undefined) {
  8. ratio = window.devicePixelRatio;
  9. }
  10. else if (~ua.indexOf('msie')) {
  11. if (screen.deviceXDPI && screen.logicalXDPI) {
  12. ratio = screen.deviceXDPI / screen.logicalXDPI;
  13. }
  14. }
  15. else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
  16. ratio = window.outerWidth / window.innerWidth;
  17. }
  18. if (ratio){
  19. ratio = Math.round(ratio * 100);
  20. }
  21. return ratio;
  22. }
  23. setTimeout(() => {
  24. const zoom = detectZoom()
  25. if(zoom !== 100 && !Cookie.get('dy-zoom')) {
  26. Notification({
  27. title: '警告',
  28. dangerouslyUseHTMLString: true,
  29. message: `<div style="font-size: 13px">你的浏览器目前处于缩放状态,页面可能会出现错位现象,建议100%大小显示。</div>`,
  30. type: 'warning',
  31. offset: 100,
  32. duration: 0,
  33. onClose: () => {
  34. Cookie.set('dy-zoom', zoom, { expires: 1 })
  35. }
  36. })
  37. }
  38. }, 10000)