let MiniSite = new Object(); /** * 判断浏览器 */ MiniSite.Browser = { ie: /msie/.test(window.navigator.userAgent.toLowerCase()), moz: /gecko/.test(window.navigator.userAgent.toLowerCase()), opera: /opera/.test(window.navigator.userAgent.toLowerCase()), safari: /safari/.test(window.navigator.userAgent.toLowerCase()) }; /** * 加载外部的文件 * @param sUrl 要加载的文件的url地址 * @param fileType 要加载的文件的类型 * @fCallback 文件加载完成之后的处理函数 */ MiniSite.JsLoader = function(sUrl, fileType, fCallback) { let fileHref; if (fileType == "js") { fileHref = document.createElement('script'); fileHref.setAttribute("type", "text/javascript"); fileHref.setAttribute("src", sUrl); } else if (fileType == "css") { fileHref = document.createElement('link'); fileHref.setAttribute("rel", "stylesheet"); fileHref.setAttribute("type", "text/css"); fileHref.setAttribute("href", sUrl); } if (fileHref !== undefined) { document.getElementsByTagName("head")[0].appendChild(fileHref); if (MiniSite.Browser.ie) { fileHref.onreadystatechange = function() { if (this.readyState == 'loaded' || this.readyState == 'complete') { if (fCallback != undefined) { fCallback(); } } }; } else { fileHref.onload = function() { if (fCallback != undefined) { fCallback(); } }; } } }; //动态加载 CSS 文件 MiniSite.JsLoader("/static/css/all.css", "css"); MiniSite.JsLoader("/static/css/base.css", "css"); MiniSite.JsLoader("/static/css/style.css", "css"); //动态加载 JS 文件 MiniSite.JsLoader("https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js", "js", function() { MiniSite.JsLoader("https://cdn.jsdelivr.net/npm/vue", "js"); MiniSite.JsLoader("/static/js/bootstrap.min.js", "js"); MiniSite.JsLoader("/static/js/bootstrap-table.min.js", "js", function() { MiniSite.JsLoader("https://cdn.bootcss.com/bootstrap-table/1.12.1/locale/bootstrap-table-zh-CN.min.js", "js"); MiniSite.JsLoader("/static/js/tableExport.min.js", "js"); MiniSite.JsLoader("https://cdn.bootcss.com/bootstrap-table/1.12.1/extensions/export/bootstrap-table-export.min.js", "js"); }); MiniSite.JsLoader("https://cdn.bootcss.com/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js", "js"); MiniSite.JsLoader("/static/js/common.js", "js"); });