Commit 78755518 authored by antoor's avatar antoor

Rewriting resource loading program

重写资源加载方案
parent 0fe0c127
'use strict';
// 加载jQuery
window.$ = window.jQuery = require('../static/libs/jquery/dist/jquery.min.js');
$(document).ready(() => {
/**
* 时间格式化函数
* @param {String} format 格式化字符串,如yyyy/mm/dd hh:ii:ss
* @return {String} 格式化完毕的字符串
*/
Date.prototype.format = function(format) {
const o = {
let o = {
"M+" : this.getMonth()+1,
"d+" : this.getDate(),
"h+" : this.getHours(),
......@@ -12,22 +22,92 @@ $(document).ready(() => {
if(/(y+)/.test(format)) {
format=format.replace(RegExp.$1, (this.getFullYear()+"").substr(4- RegExp.$1.length))
};
for(var k in o) {
for(let k in o) {
if(new RegExp("("+ k +")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length==1? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
}
}
return format;
}
layer.config({extend: 'extend/layer.ext.js'});
function loadJS(js, cb) {
var script = document.createElement('script');
script.src = js;
script.onload = cb;
document.head.appendChild(script);
/**
* 加载JS函数
* @param {String} js js地址
* @return {Promise} 返回Promise操作对象
*/
function loadJS(js) {
return new Promise((res, rej) => {
let script = document.createElement('script');
script.src = js;
script.onload = res;
document.head.appendChild(script);
});
}
/**
* 加载CSS函数
* @param {String} css css地址
* @return {Promise} 返回Promise操作对象
*/
function loadCSS(css) {
return new Promise((res, rej) => {
let style = document.createElement('link');
style.rel = 'stylesheet';
style.href = css;
style.onload = res;
document.head.appendChild(style);
});
}
loadJS('../static/libs/dhtmlx/codebase/dhtmlx_pro.js', () => {
loadJS('../static/build/app.bundle.js', null);
// 开始加载css
loadCSS(
'../static/libs/bmenu/bmenu.css'
).then(() => {
return loadCSS('../static/libs/toastr/toastr.css');
}).then(() => {
return loadCSS('../static/libs/layer/src/skin/layer.css');
}).then(() => {
return loadCSS('../static/libs/layer/src/skin/layer.ext.css');
}).then(() => {
return loadCSS('../static/libs/laydate/need/laydate.css');
}).then(() => {
return loadCSS('../static/libs/laydate/skins/default/laydate.css');
}).then(() => {
return loadCSS('../static/libs/terminal/css/jquery.terminal.css');
}).then(() => {
return loadCSS('../static/libs/font-awesome/css/font-awesome.css');
}).then(() => {
return loadCSS('../static/libs/dhtmlx/codebase/dhtmlx.css');
}).then(() => {
return loadCSS('../static/libs/dhtmlx/skins/mytheme/dhtmlx.css');
});
// 加载js资源
loadJS(
'../static/libs/ace/ace.js'
).then(() => {
return loadJS('../static/libs/ace/ext-language_tools.js');
}).then(() => {
return loadJS('../static/libs/bmenu/bmenu.js');
}).then(() => {
return loadJS('../static/libs/toastr/toastr.js');
}).then(() => {
return loadJS('../static/libs/layer/src/layer.js');
}).then(() => {
return loadJS('../static/libs/laydate/laydate.js');
}).then(() => {
return loadJS('../static/libs/terminal/js/jquery.terminal-src.js');
}).then(() => {
return loadJS('../static/libs/dhtmlx/codebase/dhtmlx_pro.js');
}).then(() => {
/**
* 配置layer弹出层
* @param {[type]} {extend: 'extend/layer.ext.js'} [description]
* @return {[type]} [description]
*/
layer.config({extend: 'extend/layer.ext.js'});
// 加载程序入口
return loadJS('../static/build/app.bundle.js');
});
});
\ No newline at end of file
});
......@@ -3,31 +3,11 @@
<head>
<meta charset="utf-8"/>
<title>AntSword</title>
<link rel="stylesheet" href="../static/libs/bmenu/bmenu.css" />
<link rel="stylesheet" href="../static/libs/toastr/toastr.css" />
<link rel="stylesheet" href="../static/libs/layer/src/skin/layer.css" />
<link rel="stylesheet" href="../static/libs/layer/src/skin/layer.ext.css" />
<link rel="stylesheet" href="../static/libs/laydate/need/laydate.css" />
<link rel="stylesheet" href="../static/libs/laydate/skins/default/laydate.css" />
<link rel="stylesheet" href="../static/libs/terminal/css/jquery.terminal.css" />
<link rel="stylesheet" href="../static/libs/font-awesome/css/font-awesome.css" />
<link rel="stylesheet" href="../static/libs/dhtmlx/codebase/dhtmlx.css" />
<link rel="stylesheet" href="../static/libs/dhtmlx/skins/mytheme/dhtmlx.css" />
<link rel="stylesheet" href="../static/css/index.css" />
<script>
window.$ = window.jQuery = require('../static/libs/jquery/dist/jquery.min.js');
</script>
<script src="../static/libs/ace/ace.js"></script>
<script src="../static/libs/ace/ext-language_tools.js"></script>
<script src="../static/libs/bmenu/bmenu.js"/></script>
<script src="../static/libs/toastr/toastr.js"></script>
<script src="../static/libs/layer/src/layer.js"></script>
<script src="../static/libs/laydate/laydate.js"></script>
<script src="../static/libs/terminal/js/jquery.terminal-src.js"></script>
<link rel="stylesheet" href="../static/css/index.css"/>
<script>require('../source/load.entry.jsx');</script>
</head>
<body>
<div id="loading"></div>
<div id="container"></div>
</body>
<script src="../static/build/load.bundle.js"></script>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment