init.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * 动态加载初始资源
  3. */
  4. ;(function() {
  5. var resList = {
  6. icon: window.SITE_CONFIG.cdnUrl + '/static/img/favicon.ico',
  7. css: [
  8. window.SITE_CONFIG.cdnUrl + '/static/css/app.css',
  9. window.SITE_CONFIG.cdnUrl + '/static/plugins/previewcsv/heiho.css',
  10. ],
  11. js: [
  12. // 插件, 放置业务之前加载, 以免业务需求依赖插件时, 还未加载出错
  13. // 插件 - echarts
  14. window.SITE_CONFIG.cdnUrl + '/static/plugins/echarts-3.8.5/echarts.common.min.js',
  15. // 插件 - ueditor
  16. window.SITE_CONFIG.cdnUrl + '/static/plugins/ueditor-1.4.3.3/ueditor.config.js',
  17. window.SITE_CONFIG.cdnUrl + '/static/plugins/ueditor-1.4.3.3/ueditor.all.min.js',
  18. window.SITE_CONFIG.cdnUrl + '/static/plugins/ueditor-1.4.3.3/lang/zh-cn/zh-cn.js',
  19. window.SITE_CONFIG.cdnUrl + '/static/plugins/previewcsv/heiho.js',
  20. // 业务
  21. window.SITE_CONFIG.cdnUrl + '/static/js/manifest.js',
  22. // window.SITE_CONFIG.cdnUrl + '/static/js/vendor.js',
  23. window.SITE_CONFIG.cdnUrl + '/static/js/app.js'
  24. ]
  25. };
  26. // 图标
  27. (function () {
  28. var _icon = document.createElement('link');
  29. _icon.setAttribute('rel', 'shortcut icon');
  30. _icon.setAttribute('type', 'image/x-icon');
  31. _icon.setAttribute('href', resList.icon);
  32. document.getElementsByTagName('head')[0].appendChild(_icon);
  33. })();
  34. // 样式
  35. (function () {
  36. document.getElementsByTagName('html')[0].style.opacity = 0;
  37. var i = 0;
  38. var _style = null;
  39. var createStyles = function () {
  40. if (i >= resList.css.length) {
  41. document.getElementsByTagName('html')[0].style.opacity = 1;
  42. return;
  43. }
  44. _style = document.createElement('link');
  45. _style.href = resList.css[i];
  46. _style.setAttribute('rel', 'stylesheet');
  47. _style.onload = function () {
  48. i++;
  49. createStyles();
  50. }
  51. document.getElementsByTagName('head')[0].appendChild(_style);
  52. }
  53. createStyles();
  54. })();
  55. // 脚本
  56. document.onreadystatechange = function () {
  57. if (document.readyState === 'interactive') {
  58. var i = 0;
  59. var _script = null;
  60. var createScripts = function () {
  61. if (i >= resList.js.length) {
  62. return;
  63. }
  64. _script = document.createElement('script');
  65. _script.src = resList.js[i];
  66. _script.onload = function () {
  67. i++;
  68. createScripts();
  69. }
  70. document.getElementsByTagName('body')[0].appendChild(_script);
  71. }
  72. createScripts();
  73. }
  74. };
  75. })();