import { Notification } from 'element-ui'
import Cookie from 'js-cookie'
const detectZoom = () => {
    let ratio = 0,
      screen = window.screen,
      ua = navigator.userAgent.toLowerCase();

     if (window.devicePixelRatio !== undefined) {
        ratio = window.devicePixelRatio;
    }
    else if (~ua.indexOf('msie')) {  
      if (screen.deviceXDPI && screen.logicalXDPI) {
        ratio = screen.deviceXDPI / screen.logicalXDPI;
      }
    }
    else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
      ratio = window.outerWidth / window.innerWidth;
    }

     if (ratio){
      ratio = Math.round(ratio * 100);
    }

    return ratio;
}

setTimeout(() => {
    const zoom = detectZoom()
    if(zoom !== 100 && !Cookie.get('dy-zoom')) {
        Notification({
            title: '警告',
            dangerouslyUseHTMLString: true,
            message: `<div style="font-size: 13px">你的浏览器目前处于缩放状态，页面可能会出现错位现象，建议100%大小显示。</div>`,
            type: 'warning',
            offset: 100,
            duration: 0,
            onClose: () => {
                Cookie.set('dy-zoom', zoom, { expires: 1 })
            }
        })
    }
}, 10000)
