diff --git a/dixhttp/server.go b/dixhttp/server.go index aa7fabb..de725df 100644 --- a/dixhttp/server.go +++ b/dixhttp/server.go @@ -20,6 +20,9 @@ import ( //go:embed static var staticFS embed.FS +//go:embed template.html +var legacyTemplate string + // Server provides HTTP endpoints to visualize dependency relationships type Server struct { dix *dix.Dix @@ -153,6 +156,7 @@ func (s *Server) setupRoutes() { if err == nil { s.mux.Handle(base+"/static/", http.StripPrefix(base+"/static/", http.FileServer(http.FS(staticRoot)))) } + s.mux.HandleFunc(base+"/next", s.HandleNextIndex) s.mux.HandleFunc(base+"/api/search", s.HandleSearch) s.mux.HandleFunc(base+"/api/modules", s.HandleModules) s.mux.HandleFunc(base+"/api/ego", s.HandleEgo) @@ -307,6 +311,18 @@ func atoiOr(s string, def int) int { return def } +// HandleNextIndex 服务五视图实验版 UI(/next)。 +func (s *Server) HandleNextIndex(w http.ResponseWriter, r *http.Request) { + index, err := fs.ReadFile(staticFS, "static/index.html") + if err != nil { + http.Error(w, "index not found", http.StatusInternalServerError) + return + } + html := strings.ReplaceAll(string(index), "__DIX_BASE_PATH__", s.basePath) + w.Header().Set("Content-Type", "text/html; charset=utf-8") + fmt.Fprint(w, html) +} + // ServeHTTP implements http.Handler interface func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { s.mux.ServeHTTP(w, r) @@ -321,12 +337,7 @@ func (s *Server) ListenAndServe(addr string) error { func (s *Server) HandleIndex(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") w.WriteHeader(http.StatusOK) - index, err := fs.ReadFile(staticFS, "static/index.html") - if err != nil { - http.Error(w, "index not found", http.StatusInternalServerError) - return - } - html := strings.ReplaceAll(string(index), "__DIX_BASE_PATH__", s.basePath) + html := strings.ReplaceAll(legacyTemplate, "__DIX_BASE_PATH__", s.basePath) w.Header().Set("Content-Type", "text/html; charset=utf-8") fmt.Fprint(w, html) } diff --git a/dixhttp/static/js/views/graph.js b/dixhttp/static/js/views/graph.js index f57aef7..16f0948 100644 --- a/dixhttp/static/js/views/graph.js +++ b/dixhttp/static/js/views/graph.js @@ -53,7 +53,9 @@ DIX.views = DIX.views || {}; // ---------- 全局图构建(移植自旧版 renderGraph) ---------- function buildGlobal() { - const { providers, edges } = state.allData; + if (!state.allData) return { nodes: [], edges: [] }; + const providers = state.allData.providers || []; + const edges = state.allData.edges || []; const nodes = [], gedges = []; const nodeMap = new Map(); const addType = label => { @@ -291,7 +293,7 @@ DIX.views = DIX.views || {}; async function redraw() { const canvas = document.getElementById("graph-canvas"); try { - if (state.mode !== "modules") await loadData(); + await loadData(); // 详情抽屉也依赖 allData,所有模式都预载 let graph; if (state.mode === "modules") { graph = await buildModules(); diff --git a/dixhttp/static/js/views/search.js b/dixhttp/static/js/views/search.js index e9bd51d..2da8c2c 100644 --- a/dixhttp/static/js/views/search.js +++ b/dixhttp/static/js/views/search.js @@ -47,7 +47,7 @@ DIX.views.search = { box.querySelectorAll("button[data-i]").forEach(btn => { btn.addEventListener("click", () => { const h = hits[Number(btn.dataset.i)]; - if (h.kind !== "type") return; + // SearchHit 的 label 即该依赖的类型名(provider 节点为其输出类型),可直接作邻域中心 location.hash = "#/graph?center=" + encodeURIComponent(h.label); }); }); diff --git a/dixhttp/template.html b/dixhttp/template.html new file mode 100644 index 0000000..ab3dad0 --- /dev/null +++ b/dixhttp/template.html @@ -0,0 +1,3878 @@ + + + +
+ + +