rpt_public.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. function getScreenDPI() {
  2. if (SCREEN_DPI.length === 0) {
  3. if (window.screen.deviceXDPI != undefined) {
  4. SCREEN_DPI.push(window.screen.deviceXDPI);
  5. SCREEN_DPI.push(window.screen.deviceYDPI);
  6. } else {
  7. let tmpNode = document.createElement("DIV");
  8. tmpNode.style.cssText = "width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden";
  9. document.body.appendChild(tmpNode);
  10. SCREEN_DPI.push(parseInt(tmpNode.offsetWidth));
  11. SCREEN_DPI.push(parseInt(tmpNode.offsetHeight));
  12. tmpNode.parentNode.removeChild(tmpNode);
  13. }
  14. }
  15. return SCREEN_DPI;
  16. }
  17. function setupDateFormat() {
  18. Date.prototype.Format = function (fmt) {
  19. let o = {
  20. "M+": this.getMonth() + 1, //月份
  21. "d+": this.getDate(), //日
  22. "h+": this.getHours(), //小时
  23. "m+": this.getMinutes(), //分
  24. "s+": this.getSeconds(), //秒
  25. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  26. "S": this.getMilliseconds() //毫秒
  27. };
  28. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  29. for (let k in o)
  30. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  31. return fmt;
  32. };
  33. }
  34. function dynamicLoadJs(url, type, callback) {
  35. let head = document.getElementsByTagName('head')[0];
  36. let script = document.createElement('script');
  37. script.type = 'text/javascript';
  38. script.src = url;
  39. if(callback) {
  40. script.onload = script.onreadystatechange = function (event) {
  41. callback(type);
  42. script.onload = script.onreadystatechange = null;
  43. };
  44. }
  45. head.appendChild(script);
  46. }
  47. /**
  48. * 获取 blob
  49. * @param {String} url 目标文件地址
  50. * @return {Promise}
  51. */
  52. function getBlobPublic(url) {
  53. return new Promise(resolve => {
  54. const xhr = new XMLHttpRequest();
  55. xhr.open('GET', url, true);
  56. xhr.responseType = 'blob';
  57. xhr.onload = () => {
  58. if (xhr.status === 200) {
  59. resolve(xhr.response);
  60. } else {
  61. resolve('not found!');
  62. }
  63. };
  64. xhr.send();
  65. });
  66. }