resize.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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) { return }
  22. const a = moment().format('YYYYMMDDHHmmss')
  23. const fname = fileName + a
  24. const blob = new Blob([data], { type: 'application/vnd.ms-excel' })
  25. if (window.navigator && window.navigator.msSaveOrOpenBlob) {
  26. navigator.msSaveBlob(blob, fname + '.xlsx')
  27. } else {
  28. const link = document.createElement('a')
  29. link.style.display = 'none'
  30. var href = URL.createObjectURL(blob)
  31. link.href = href
  32. link.setAttribute('download', fname + '.xlsx')
  33. document.body.appendChild(link)
  34. link.click()
  35. document.body.removeChild(link)
  36. window.URL.revokeObjectURL(href) // 释放掉blob对象
  37. }
  38. }
  39. function toThousands (num, decimal) {
  40. if (decimal) {
  41. num = formatDecimal(num, decimal)
  42. }
  43. return num.toString().replace(/\d+/, function (n) { // 先提取整数部分
  44. return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) {
  45. return $1 + ','
  46. })
  47. })
  48. }
  49. function formatDecimal (num, decimal) {
  50. num = num.toString()
  51. const index = num.indexOf('.')
  52. if (index !== -1) {
  53. num = num.substring(0, decimal + index + 1)
  54. } else {
  55. num = num.substring(0)
  56. }
  57. return parseFloat(num).toFixed(decimal)
  58. }