From 94e8931f434696c0014bdf2e3c8c86a520f6e3e0 Mon Sep 17 00:00:00 2001 From: trungduong Date: Sun, 6 Jul 2025 14:57:47 +0700 Subject: [PATCH] Update New --- VinFontApp/Controllers/TypeFontsController.cs | 11 +- VinFontApp/Program.cs | 2 +- VinFontApp/Views/Partial/MenuAP.cshtml | 6 +- VinFontApp/wwwroot/js/libs/js-AGrid.js | 4 +- VinFontApp/wwwroot/js/libs/js-AMenu.js | 2 +- VinFontApp/wwwroot/js/libs/js-core.js | 148 ++++++++---------- 6 files changed, 77 insertions(+), 96 deletions(-) diff --git a/VinFontApp/Controllers/TypeFontsController.cs b/VinFontApp/Controllers/TypeFontsController.cs index 6ffbf52..d5cdbb3 100644 --- a/VinFontApp/Controllers/TypeFontsController.cs +++ b/VinFontApp/Controllers/TypeFontsController.cs @@ -5,20 +5,19 @@ namespace VinFontApp.Controllers { public class TypeFontsController : Controller { - [PageInfor("2001", "Type Font", "/TypeFont/*")] + [PageInfor("2001", "Type Font", "/TypeFonts/*")] [Layout(LayoutOptions.Custom, "Async1")] public async Task Index(string? id) { if (id != null) { - NavItem list = WSNavigation.GetListMenu()[1]; - NavItem? result = list.SubItem.FirstOrDefault(l => l.Url.Split('/').Last().Equals(id)); - if (result != null) + NavItem list = (await WSNavigation.GetListMenu())[1]; + if (list.SubItem != null && list.SubItem.Count > 0) { - ViewData["PageID"] = result.ID; + NavItem? result = list.SubItem.FirstOrDefault(l => l.Url.Split('/').Last().Equals(id)); + if (result != null) ViewData["PageID"] = result.ID; } } - ViewBag.ID = id; return await this.ViewAsync(); } diff --git a/VinFontApp/Program.cs b/VinFontApp/Program.cs index 76bcda3..d06f781 100644 --- a/VinFontApp/Program.cs +++ b/VinFontApp/Program.cs @@ -2,7 +2,7 @@ using AppLibs.Libs; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.StaticFiles; -WSNavigation.LoadJson(); +await WSNavigation.LoadJson(); var builder = WebApplication.CreateBuilder(args); #if (!DEBUG) diff --git a/VinFontApp/Views/Partial/MenuAP.cshtml b/VinFontApp/Views/Partial/MenuAP.cshtml index eb872f9..bc7eb34 100644 --- a/VinFontApp/Views/Partial/MenuAP.cshtml +++ b/VinFontApp/Views/Partial/MenuAP.cshtml @@ -1,6 +1,6 @@ @using AppLibs.Libs @{ - List t = WSNavigation.GetListMenu(); + List t = await WSNavigation.GetListMenu(); } @@ -9,7 +9,7 @@ if (i.SubItem == null) { } else @@ -19,7 +19,7 @@
@foreach (var j in i.SubItem) { - + }
diff --git a/VinFontApp/wwwroot/js/libs/js-AGrid.js b/VinFontApp/wwwroot/js/libs/js-AGrid.js index c4ec7ef..05a58b5 100644 --- a/VinFontApp/wwwroot/js/libs/js-AGrid.js +++ b/VinFontApp/wwwroot/js/libs/js-AGrid.js @@ -168,8 +168,8 @@ export default class AGrid extends window.AObject { let i = 0; let col = 0; let l = 0; - console.log(this.listGrid); - console.log(this.listCols); + //console.log(this.listgrid); + //console.log(this.listcols); this.listGrid.forEach((v, k) => { let t = 0; let cVal; diff --git a/VinFontApp/wwwroot/js/libs/js-AMenu.js b/VinFontApp/wwwroot/js/libs/js-AMenu.js index 3d7a1da..db7122e 100644 --- a/VinFontApp/wwwroot/js/libs/js-AMenu.js +++ b/VinFontApp/wwwroot/js/libs/js-AMenu.js @@ -125,7 +125,7 @@ export default class AMenu extends window.AObject { } addEventClick(e) { - window.app.initNavApp(e.currentTarget.getAttribute("href")); + window.app.initNavApp(e.currentTarget.getAttribute("href"), e.currentTarget.hasAttribute("isflexpage")); } closeExpandMenu() { Array.from(this.navM.querySelectorAll(".nav-i.has-sub")).forEach(el => { diff --git a/VinFontApp/wwwroot/js/libs/js-core.js b/VinFontApp/wwwroot/js/libs/js-core.js index fd0e32e..11717db 100644 --- a/VinFontApp/wwwroot/js/libs/js-core.js +++ b/VinFontApp/wwwroot/js/libs/js-core.js @@ -650,34 +650,47 @@ 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")); + + this.initNavApp(ev.currentTarget.getAttribute("href"), ev.currentTarget.hasAttribute("isflexpage")); }).bind(this); this.addSystemEvent(this.eventName, el, f2, groups); el.setAttribute("app-nav", true); } }).bind(this)); } - initNavApp(t) { + initNavApp(t, flex=false) { this.isRedirectPage = true; - this.callLoadPage(window.GetAbsoluteURL(t)); + this.callLoadPage(window.GetAbsoluteURL(t), flex); } callLoadPage(url, flex = false) { - if (flex) { - url = window.getPathFromUrl(url); - this.cachePage.searchFlexPage(url, ((result) => { - if (result) { + url = window.getPathFromUrl(url); + this.cachePage.searchFlexPage(url, ((result) => { + if (result) { + this.cachePage.get(result.layout.linkID, ((result1) => { + console.log(result); - } - }).bind(this)); - } else { - this.cachePage.get(url, ((result) => { - if (result) { - this.setContentPage(result, url); // Set content page từ cache - } else { - this.getPage(url); // Load mới nếu chưa có trong cache - } - }).bind(this)); - } + if (result1) { + console.log(result); + this.setContentPage(result1, url); + } else { + this.getPage(url, result) + } + }).bind(this), "flex"); + } else { + 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'); @@ -709,7 +722,7 @@ class AApp extends window.AObject { }).bind(this)); l.processScript(page.doc); } - getPage(url) { + getPage(url, rs = null) { var xhr = new XMLHttpRequest(); xhr.open("GET", this.addAttributeURL(url, "?vr=cAsync")); xhr.send(); @@ -717,13 +730,13 @@ class AApp extends window.AObject { if (evt.currentTarget.readyState == 4 && evt.currentTarget.status == 200) { if (evt.currentTarget.responseText) { var jP = JSON.parse(evt.currentTarget.responseText); - this.loadPage(jP, window.GetAbsoluteURL(url)); + this.loadPage(jP, window.GetAbsoluteURL(url), rs); } } }.bind(this); xhr.addEventListener("readystatechange", f, false); } - loadPage(o, url) { + loadPage(o, url, rs) { const title = o.Title; const idPage = o.PageId; const doc2 = new DOMParser().parseFromString(o.Scripts, "text/html"); @@ -761,13 +774,14 @@ class AApp extends window.AObject { } callLoadLayout(lName) { this.cachePage.get(lName, ((result) => { + if (result) { this.setLayout(result); // Set content page từ cache } else { console.log("connect new Layout"); this.loadLayout(); // Load mới nếu chưa có trong cache } - + }).bind(this), "layout"); } @@ -792,7 +806,6 @@ class AApp extends window.AObject { if (this.lName !== "None") { const l = window.ALayout.get(this.lName); if (!l.isLoaded) { - console.log("render M"); l.renderMenu(); this.isLoadedLayout = true; this.trigger("layoutLoaded", null); @@ -845,7 +858,7 @@ class CacheManager { this.countFP = 0; this._loadIndex(); window.addEventListener("beforeunload", (function (e) { - + this.storage.set("treePage", this.flexPages.toJSON(), function () { }); }).bind(this)); } @@ -863,29 +876,25 @@ class CacheManager { } _loadIndex() { - this.storage.getAllKeys(((keys, type) => { - if (type == "cache") { - let pending = 0; - keys.forEach(((key) => { - if (!key.startsWith(`${this.storage.prefix}|`)) return; + this.storage.getAllKeys(((keys) => { + let pending = 0; + keys.forEach(((key) => { + if (!key.startsWith(`${this.storage.prefix}|`)) return; - const shortKey = key.replace(`${this.storage.prefix}|`, ""); - const [type, id] = shortKey.split("|"); + const shortKey = key.replace(`${this.storage.prefix}|`, ""); + const [type, id] = shortKey.split("|"); - if (type === "pI") { - pending++; - this.storage.get(key, (data) => { - if (data) this.pageMap.set(id, data); - if (--pending === 0) this._finishInit(); - }, true); - } else if (type === "layout") { - this.layoutMap.set(id, true); - } - }).bind(this)); - if (pending === 0) this._finishInit(); // Trường hợp không có key nào là "pI" - } else { - - } + if (type === "treePage") { + pending++; + this.storage.get(key, (data) => { + if (data) this.flexPages.fromJSON(data); + if (--pending === 0) this._finishInit(); + }, true); + } else if (type === "layout") { + this.layoutMap.set(id, true); + } + }).bind(this)); + if (pending === 0) this._finishInit(); // Trường hợp không có key nào là "pI" }).bind(this)); } @@ -911,18 +920,7 @@ class CacheManager { callback(null); return; } - - if (type === "page") { - const pInfo = this.pageMap.get(id); - if (!pInfo) { - callback(null); - return; - } - data.doc = new DOMParser().parseFromString(data.doc, "text/html").head; - callback(Object.assign(data, pInfo, { url: id })); - } else { - callback(data); - } + callback(data); }); }); } @@ -951,27 +949,17 @@ class CacheManager { dynamicF: obj.dynamicF }; // Lưu dữ liệu htmlData vào storage - if (obj.flexPageID !== "None") { - const idN = this.genShortID(); - this.flexPages.insert(obj.flexPageID, { "id": idN, "info": info }); - - this.storage.set(idN, htmlData, function () { }, type = "flex"); - if (this.countFP > 5) { - this.countFP = 0 - } - console.log(this.flexPages); + const idN = this.genShortID(); + let url = (obj.flexPageID !== "None") ? obj.flexPageID : window.getPathFromUrl(id); + this.flexPages.insert(url, { "linkID": idN, "info": info }); + this.storage.set(idN, htmlData, function () { }, type = "flex"); + if (this.countFP > 5) { + this.countFP = 0; + //this.storage.set("treePage", this.flexPages.toJSON(), function () { }); } else { - this.storage.set(key, htmlData, function () { }); - - - // Lưu thông tin trang vào pageMap và storage - this.pageMap.set(id, info); - this.storage.set(`pI|${id}`, info, function () { }); + this.countFP++; } - - - } else if (type == "flex") { - + this.storage.set("treePage", this.flexPages.toJSON(), function () { }); } else { const layout = { Content: obj.Content, @@ -1078,13 +1066,7 @@ class CacheStorage { let store = tx.objectStore("cache"); let req = store.getAllKeys(); req.onsuccess = (evt) => { - callback(evt.target.result, "cache"); - }; - tx = this.db.transaction("fpCache", "readonly"); - store = tx.objectStore("fpCache"); - req = store.getAllKeys(); - req.onsuccess = (evt) => { - callback(evt.target.result, "flex"); + callback(evt.target.result); }; } });