后端

init.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. window.SITE_CONFIG.cdnUrl + '/static/plugins/echarts-3.8.5/echarts.common.min.js',
  13. // 业务
  14. window.SITE_CONFIG.cdnUrl + '/static/js/manifest.js',
  15. window.SITE_CONFIG.cdnUrl + '/static/js/vendor.js',
  16. window.SITE_CONFIG.cdnUrl + '/static/js/app.js'
  17. ]
  18. };
  19. // 图标
  20. (function () {
  21. var _icon = document.createElement('link');
  22. _icon.setAttribute('rel', 'shortcut icon');
  23. _icon.setAttribute('type', 'image/x-icon');
  24. _icon.setAttribute('href', resList.icon);
  25. document.getElementsByTagName('head')[0].appendChild(_icon);
  26. })();
  27. // 样式
  28. (function () {
  29. document.getElementsByTagName('html')[0].style.opacity = 0;
  30. var i = 0;
  31. var _style = null;
  32. var createStyles = function () {
  33. if (i >= resList.css.length) {
  34. document.getElementsByTagName('html')[0].style.opacity = 1;
  35. return;
  36. }
  37. _style = document.createElement('link');
  38. _style.href = resList.css[i];
  39. _style.setAttribute('rel', 'stylesheet');
  40. _style.onload = function () {
  41. i++;
  42. createStyles();
  43. }
  44. document.getElementsByTagName('head')[0].appendChild(_style);
  45. }
  46. createStyles();
  47. })();
  48. // 脚本
  49. document.onreadystatechange = function () {
  50. if (document.readyState === 'interactive') {
  51. var i = 0;
  52. var _script = null;
  53. var createScripts = function () {
  54. if (i >= resList.js.length) {
  55. return;
  56. }
  57. _script = document.createElement('script');
  58. _script.src = resList.js[i];
  59. _script.onload = function () {
  60. i++;
  61. createScripts();
  62. }
  63. document.getElementsByTagName('body')[0].appendChild(_script);
  64. }
  65. createScripts();
  66. }
  67. };
  68. })();