function getScreenDPI() { if (SCREEN_DPI.length === 0) { if (window.screen.deviceXDPI != undefined) { SCREEN_DPI.push(window.screen.deviceXDPI); SCREEN_DPI.push(window.screen.deviceYDPI); } else { let tmpNode = document.createElement("DIV"); tmpNode.style.cssText = "width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden"; document.body.appendChild(tmpNode); SCREEN_DPI.push(parseInt(tmpNode.offsetWidth)); SCREEN_DPI.push(parseInt(tmpNode.offsetHeight)); tmpNode.parentNode.removeChild(tmpNode); } } return SCREEN_DPI; } function setupDateFormat() { Date.prototype.Format = function (fmt) { let o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (let k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; }; } function dynamicLoadJs(url, type, callback) { let head = document.getElementsByTagName('head')[0]; let script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; if(callback) { script.onload = script.onreadystatechange = function (event) { callback(type); script.onload = script.onreadystatechange = null; }; } head.appendChild(script); } /** * 获取 blob * @param {String} url 目标文件地址 * @return {Promise} */ function getBlobPublic(url) { return new Promise(resolve => { const xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'blob'; xhr.onload = () => { if (xhr.status === 200) { resolve(xhr.response); } else { resolve('not found!'); } }; xhr.send(); }); }