init.js 2.3 KB

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