Revert "feat(controller): 完善基础控制器及默认页面渲染"

This reverts commit 37c78d9a4e.
This commit is contained in:
2026-02-21 12:46:38 +08:00
parent 37c78d9a4e
commit 1a3bd1a6b3
4 changed files with 32 additions and 34 deletions

View File

@@ -1,13 +0,0 @@
package admin
import "github.com/gin-gonic/gin"
type BaseController struct {
}
func (con BaseController) Success(c *gin.Context) {
c.String(200, "成功")
}
func (con BaseController) Error(c *gin.Context) {
c.String(200, "失败")
}

View File

@@ -3,11 +3,10 @@ package admin
import "github.com/gin-gonic/gin" import "github.com/gin-gonic/gin"
type UserController struct { type UserController struct {
BaseController
} }
func (con UserController) Index(c *gin.Context) { func (con UserController) Index(c *gin.Context) {
con.Success(c) c.String(200, "管理员用户列表")
} }
func (con UserController) Show(c *gin.Context) { func (con UserController) Show(c *gin.Context) {

View File

@@ -8,7 +8,7 @@ type DefaultController struct {
} }
func (con DefaultController) Index(c *gin.Context) { func (con DefaultController) Index(c *gin.Context) {
c.HTML(200, "pages/index", gin.H{}) c.String(200, "首页")
} }
func (con DefaultController) Article(c *gin.Context) { func (con DefaultController) Article(c *gin.Context) {
c.String(200, "文章详情") c.String(200, "文章详情")

View File

@@ -1,3 +1,4 @@
{{/* 定义index页面模板 */}}
{{define "pages/index"}} {{define "pages/index"}}
<!doctype html> <!doctype html>
<html lang="zh"> <html lang="zh">
@@ -5,52 +6,63 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{.title}}</title> <title>{{.title}}</title>
<!-- 组件特定样式块 -->
<link rel="stylesheet" href="/static/navbar.css"> <link rel="stylesheet" href="/static/navbar.css">
<link rel="stylesheet" href="/static/footer.css"> <link rel="stylesheet" href="/static/footer.css">
</head> </head>
<body> <body>
{{template "layout/navbar"}} {{template "layout/navbar"}}
{{/* 基本数据输出示例 - 直接渲染标题变量 */}}
<h2>{{.title}}</h2> <h2>{{.title}}</h2>
{{/* 模板变量定义示例 - 将标题赋值给局部变量t */}}
{{$t := .title}} {{$t := .title}}
<h4>{{$t}}</h4> <h4>{{$t}}</h4>
{{if ge .score 60}} {{/* 条件判断示例 - 根据score值判断是否及格 */}}
<p>及格</p> {{if ge .score 60}} <!-- ge: 大于等于 -->
<p>及格</p>
{{else}} {{else}}
<p>不及格</p> <p></p>
{{end}} {{end}}
{{range $key, $value := .hobby}} {{/* 简单数组循环遍历示例 */}}
<ul> {{range $key, $value := .hobby}} <!-- 遍历爱好列表 -->
<li>{{$key}}--{{$value}}</li> <ul>
</ul> <li>{{$key}}--{{$value}}</li> <!-- 输出索引和值 -->
</ul>
{{end}} {{end}}
{{range $key, $value := .newsList}} {{/* 结构体数组循环遍历示例 */}}
<ul> {{range $key, $value := .newsList}} <!-- 遍历文章列表 -->
<li>{{$key}}--{{$value.Title}}--{{$value.Content}}</li> <ul>
</ul> <li>{{$key}}--{{$value.Title}}--{{$value.Content}}</li> <!-- 输出索引和文章属性 -->
</ul>
{{end}} {{end}}
{{/* 空数组处理示例 - 当newsList2为空时显示提示信息 */}}
{{range $key, $value := .newsList2}} {{range $key, $value := .newsList2}}
<ul> <ul>
<li>{{$key}}--{{$value.Title}}--{{$value.Content}}</li> <li>{{$key}}--{{$value.Title}}--{{$value.Content}}</li>
</ul> </ul>
{{else}} {{else}}
<li>没有数据</li> <li>没有数据</li> <!-- 当数组为空时执行 -->
{{end}} {{end}}
{{with .news}} {{/* 结构体数据访问示例 - 使用with语句简化结构体属性访问 */}}
{{.Title}} {{with .news}} <!-- 针对news结构体设置上下文 -->
{{.Content}} {{.Title}} <!-- 直接访问Title属性等同于.news.Title -->
{{.Content}} <!-- 直接访问Content属性等同于.news.Content -->
{{end}} {{end}}
<br> <br>
{{.data}} {{/* 自定义模板函数使用示例 */}}
{{.data}} <!-- 输出原始时间戳 -->
{{template "layout/footer"}}
{{ template "layout/footer"}}
</body> </body>
</html> </html>
{{end}} {{end}}