resize.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (function(doc, win) {
  2. var docEl = doc.documentElement,
  3. resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
  4. recalc = function() {
  5. var clientWidth = docEl.clientWidth;
  6. if (!clientWidth) return;
  7. if (clientWidth >= 1080) {
  8. docEl.style.fontSize = '100px';
  9. } else {
  10. docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
  11. }
  12. };
  13. if (!doc.addEventListener) return;
  14. win.addEventListener(resizeEvt, recalc, false);
  15. doc.addEventListener('DOMContentLoaded', recalc, false);
  16. var docEl = document.documentElement;
  17. var clientWidth = docEl.clientHeight;
  18. })(document, window);
  19. // 导出
  20. function downloadExcel(data, fileName) {
  21. if (!data) {
  22. return
  23. }
  24. const a = moment().format('YYYYMMDDHHmmss')
  25. const fname = fileName + a
  26. const blob = new Blob([data], {
  27. type: 'application/vnd.ms-excel'
  28. })
  29. if (window.navigator && window.navigator.msSaveOrOpenBlob) {
  30. navigator.msSaveBlob(blob, fname + '.xlsx')
  31. } else {
  32. const link = document.createElement('a')
  33. link.style.display = 'none'
  34. var href = URL.createObjectURL(blob)
  35. link.href = href
  36. link.setAttribute('download', fname + '.xlsx')
  37. document.body.appendChild(link)
  38. link.click()
  39. document.body.removeChild(link)
  40. window.URL.revokeObjectURL(href) // 释放掉blob对象
  41. }
  42. }
  43. function toThousands(num, decimal) {
  44. let numInfo = num ? num : 0
  45. return parseFloat(numInfo).toFixed(decimal)
  46. }