update v0.0.2 twa sys

This commit is contained in:
2025-11-18 11:48:01 +07:00
parent b4b191f829
commit a586da6edc
40 changed files with 1347 additions and 937 deletions

View File

@ -104,14 +104,14 @@ window.getOS = function () {
return os;
}
window.GetAbsoluteURL = function(relativeURL) {
window.GetAbsoluteURL = function (relativeURL) {
if (relativeURL.startsWith(window.location.origin)) {
return relativeURL;
}
return window.location.origin + relativeURL;
}
window.getPathFromUrl = function(url) {
window.getPathFromUrl = function (url) {
const parsed = new URL(url);
return parsed.pathname + parsed.search + parsed.hash;
}
@ -377,9 +377,9 @@ window.AObject = class {
const eventMap = this.systemEvents.get(element);
if (eventMap) {
const data = eventMap.get(eventName);
if (data && typeof data.callback === 'function') {
element.removeEventListener(eventName , data.callback, false);
element.removeEventListener(eventName, data.callback, false);
eventMap.delete(eventName);
// Nếu element không còn event nào, xóa khỏi systemEvents
if (eventMap.size === 0) {
@ -387,7 +387,7 @@ window.AObject = class {
}
}
}
}
this.parentEventMap.delete(parent);
}
@ -406,7 +406,7 @@ window.AObject = class {
}
addCustomEvent(id, element, groups = null) {
if (!this.customEvents.has(id)) {
this.customEvents.set(id, { "ele":element, "groups":groups });
this.customEvents.set(id, { "ele": element, "groups": groups });
}
if (groups) {
if (!this.parentEventMap.has("Custom" + parent)) {
@ -429,6 +429,7 @@ window.AObject = class {
}
this.parentEventMap.get(parent).add({ element, eventName });
}
}
removeAllChildNodes(parent) {
while (parent.firstChild) {
@ -541,12 +542,11 @@ class AApp extends window.AObject {
this.metaPage = document.head.querySelector("meta[name=idPage]");
this.pageName = this.metaPage.getAttribute("pageName");
this.lName = this.metaPage.getAttribute("layName");
console.log(this.lName);
var tmp = document.querySelector(container);
this.mainApp = tmp.querySelector("[main-content]") ? tmp.querySelector("[main-content]") : tmp;
var f = function (ev) {
if (ev.state) {
this.cachePage.get(ev.state.url, ((result) => {
this.cachePage.get(ev.state.url, ((result) => {
if (result == null) {
} else {
@ -655,7 +655,7 @@ class AApp extends window.AObject {
this.addSystemEvent("click", el, f1, groups)
const f2 = (function (ev) {
if (window.isValidPointerClick(ev)) return;
this.initNavApp(ev.currentTarget.getAttribute("href"), ev.currentTarget.hasAttribute("isflexpage"));
}).bind(this);
this.addSystemEvent(this.eventName, el, f2, groups);
@ -689,8 +689,7 @@ class AApp extends window.AObject {
doc: doc,
dynamicF: a.dynamicF
};
this.setContentPage(obj, url);
this.setContentPage(obj, url);
} else {
this.getPage(url, result)
}
@ -699,17 +698,6 @@ class AApp extends window.AObject {
this.getPage(url);
}
}).bind(this));
//if (flex) {
//} else {
// this.cachePage.get(url, ((result) => {
// if (result) {
// // Set content page từ cache
// } else {
// this.getPage(url); // Load mới nếu chưa có trong cache
// }
// }).bind(this));
//}
}
loadContentPage(content) {
const tpl = document.createElement('template');
@ -723,12 +711,10 @@ class AApp extends window.AObject {
document.title = page.title + " - " + this.pageName;
var meta = document.head.querySelector("meta[name=idPage]");
document.body.setAttribute("page", page.idPage);
meta.content = page.idPage;
this.lName = page.lName;
meta.setAttribute("layName", page.lName);
meta.setAttribute("layName", page.lName);
this.loadContentPage(page.html);
window.history.pushState({"url":url}, page.title, url);
window.history.pushState({ "url": url }, page.title, url);
}
setContentPage(page, url) {
this.contentPage(page, url);
@ -778,7 +764,6 @@ class AApp extends window.AObject {
loadedPage() {
this.metaPage = document.head.querySelector("meta[name=idPage]");
if (this.metaPage != null && this.isLoadedLayout) {
console.log(window.location.href);
this.cachePage.searchFlexPage(window.getPathFromUrl(window.location.href), ((tmp) => {
tmp = tmp.layout.info;
if (tmp != null && tmp.dynamicF != null) {
@ -790,7 +775,7 @@ class AApp extends window.AObject {
this.initNavs(this.metaPage.content);
this.trigger("pageLoaded", null);
}).bind(this));
} else {
window.requestTimeout(this.loadedPage.bind(this), 10, window.registerCancel);
}
@ -803,9 +788,9 @@ class AApp extends window.AObject {
console.log("connect new Layout");
this.loadLayout(); // Load mới nếu chưa có trong cache
}
}).bind(this), "layout");
}
loadLayout() {
(function () {
@ -825,10 +810,9 @@ class AApp extends window.AObject {
}).bind(this)();
}
loadedLayout() {
console.log(this.lName);
if (this.lName !== "None") {
const l = window.ALayout.get(this.lName);
if (!l.isLoaded) {
if (!l.isLoaded) {
l.renderMenu();
this.isLoadedLayout = true;
this.trigger("layoutLoaded", null);
@ -928,7 +912,7 @@ class CacheManager {
// Lấy thông tin trang hoặc layout
// Lấy dữ liệu từ cache (localStorage hoặc IndexedDB nếu cần)
get(id, callback, type = "cahce") {
this._onReady(() => {
@ -986,7 +970,7 @@ class CacheManager {
this.countFP++;
}
this.storage.set("treePage", this.flexPages.toJSON(), function () { });
} else {
} else {
const layout = {
Content: obj.Content,
Scripts: obj.Scripts
@ -1054,7 +1038,7 @@ class CacheStorage {
del.onblocked = () => {
console.warn("deleteDatabase blocked (tab khác đang giữ kết nối)");
};
}
_flushQueue() {
while (this.queue.length) {
@ -1104,7 +1088,7 @@ class CacheStorage {
}
});
}
set(key, data, callback = () => { }, type="cache") {
set(key, data, callback = () => { }, type = "cache") {
this._onReady(() => {
if (this.db) {
let tx, store, req;
@ -1117,7 +1101,7 @@ class CacheStorage {
store = tx.objectStore("cache");
store.put({ key: this._key(key), value: data, ts: Date.now() });
}
tx.oncomplete = () => callback(null);
tx.onerror = (e) => callback(e);
} else {
@ -1126,7 +1110,7 @@ class CacheStorage {
localStorage.setItem(this._key(key), JSON.stringify({ data, ts: Date.now() }));
callback(null);
} catch (e) {
callback(e);
}
}