index.js 2.8 KB

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