package handlers import ( "net/http" "strconv" "simple_portal/models" "github.com/gin-gonic/gin" ) // AccessLogsGet 渲染访问日志页面,支持按IP和动作类型筛选。 func AccessLogsGet(c *gin.Context) { username, _ := c.Get("username") page, _ := strconv.Atoi(c.DefaultQuery("page", "1")) if page < 1 { page = 1 } pageSize := 30 filterIP := c.Query("ip") filterAction := c.DefaultQuery("action", "") logs, total, err := models.GetAccessLogs(page, pageSize, filterIP, filterAction) if err != nil { logs = []models.AccessLog{} total = 0 } totalPages := (total + pageSize - 1) / pageSize if totalPages < 1 { totalPages = 1 } c.HTML(http.StatusOK, "admin/access_logs.html", gin.H{ "Title": "访问日志", "Username": username, "Logs": logs, "Page": page, "TotalPages": totalPages, "Total": total, "FilterIP": filterIP, "FilterAction": filterAction, }) }