代码拉取完成,页面将自动刷新
同步操作将从 go-admin/go-admin 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package controller
import (
"bytes"
"fmt"
"github.com/chenhg5/go-admin/context"
"github.com/chenhg5/go-admin/modules/auth"
"github.com/chenhg5/go-admin/modules/menu"
"github.com/chenhg5/go-admin/plugins/admin/models"
"github.com/chenhg5/go-admin/template"
"github.com/chenhg5/go-admin/template/types"
"net/http"
"path"
"strings"
)
// 显示列表
func ShowInfo(ctx *context.Context) {
defer GlobalDeferHandler(ctx)
user := ctx.UserValue["user"].(auth.User)
prefix := ctx.Request.URL.Query().Get("prefix")
page := ctx.Request.URL.Query().Get("page")
if page == "" {
page = "1"
}
pageSize := ctx.Request.URL.Query().Get("pageSize")
if pageSize == "" {
pageSize = "10"
}
sortField := ctx.Request.URL.Query().Get("sort")
if sortField == "" {
sortField = "id"
}
sortType := ctx.Request.URL.Query().Get("sort_type")
if sortType == "" {
sortType = "desc"
}
thead, infoList, paginator, title, description := models.TableList[prefix].GetDataFromDatabase(map[string]string{
"page": page,
"path": ctx.Path(),
"sortField": sortField,
"sortType": sortType,
"prefix": prefix,
"pageSize": pageSize,
})
editUrl := Config.PREFIX + "/info/" + prefix + "/edit" + GetRouteParameterString(page, pageSize, sortType, sortField)
newUrl := Config.PREFIX + "/info/" + prefix + "/new" + GetRouteParameterString(page, pageSize, sortType, sortField)
deleteUrl := Config.PREFIX + "/delete/" + prefix
tmpl, tmplName := template.Get("adminlte").GetTemplate(ctx.Request.Header.Get("X-PJAX") == "true")
menu.GlobalMenu.SetActiveClass(ctx.Path())
dataTable := template.Get(Config.THEME).DataTable().SetInfoList(infoList).SetThead(thead).SetEditUrl(editUrl).SetNewUrl(newUrl).SetDeleteUrl(deleteUrl)
table := dataTable.GetContent()
box := template.Get(Config.THEME).Box().
SetBody(table).
SetHeader(dataTable.GetDataTableHeader()).
WithHeadBorder(false).
SetFooter(paginator.GetContent()).
GetContent()
ctx.Response.Header.Add("Content-Type", "text/html; charset=utf-8")
buf := new(bytes.Buffer)
tmpl.ExecuteTemplate(buf, tmplName, types.Page{
User: user,
Menu: menu.GetGlobalMenu(user),
System: types.SystemInfo{
"0.0.1",
},
Panel: types.Panel{
Content: box,
Description: description,
Title: title,
},
AssertRootUrl: Config.PREFIX,
Title: Config.TITLE,
Logo: Config.LOGO,
MiniLogo: Config.MINILOGO,
})
ctx.WriteString(buf.String())
}
func Assert(ctx *context.Context) {
filepath := "template/adminlte/resource" + strings.Replace(ctx.Request.URL.Path, Config.PREFIX, "", 1)
data, err := template.Get("adminlte").GetAsset(filepath)
fileSuffix := path.Ext(filepath)
fileSuffix = strings.Replace(fileSuffix, ".", "", -1)
var contentType = ""
if fileSuffix == "css" || fileSuffix == "js" {
contentType = "text/" + fileSuffix + "; charset=utf-8"
} else {
contentType = "image/" + fileSuffix
}
if err != nil {
fmt.Println("asset err", err)
ctx.Write(http.StatusNotFound, map[string]string{}, "")
} else {
ctx.Write(http.StatusOK, map[string]string{
"content-type": contentType,
}, string(data))
}
}
func GetRouteParameterString(page, pageSize, sortType, sortField string) string {
return "?page=" + page + "&pageSize=" + pageSize + "&sort=" + sortField + "&sort_type=" + sortType
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。