diff --git a/main/ui/js/alp_unit.js b/main/ui/js/alp_unit.js new file mode 100644 index 0000000..41999c0 --- /dev/null +++ b/main/ui/js/alp_unit.js @@ -0,0 +1,97 @@ +/** 实现了对AplpineJS模块的动态加载和模块的初始化 */ + +// 模块的cache,减少对服务器的访问次数 +var units_cache=new Map(); + +// 模块初始化 +var units_dom_init = new Map(); + +//装载单个uit +function load_unit(matche,reinit){ + let unit_src = matche.getAttribute("alp-unit"); + + if (unit_src==null) return + + //cache中存在,不用再此网络加载 + if (units_cache.has(unit_src)) { + + if (!units_dom_init.has(matche)){ + + //未被初始化,则初始化 + matche.innerHTML=units_cache.get(unit_src); + }else if(reinit){ + //强制重新初始化渲染 + matche.innerHTML=units_cache.get(unit_src); + } + + + }else{ + + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function () { + if (xhr.readyState == 4 && xhr.status == 200) { + + var text = xhr.responseText.split("