代码规范过滤,移除冗余代码,替换掉不推荐的包

This commit is contained in:
孟帅
2023-05-30 12:09:40 +08:00
parent c8a808fcfd
commit b2ef3487d3
74 changed files with 564 additions and 741 deletions

View File

@@ -3,14 +3,11 @@
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package view
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
"hotgo/internal/model"
"hotgo/internal/service"
@@ -42,9 +39,8 @@ func (s *sView) GetTitle(ctx context.Context, in *model.ViewGetTitleInput) strin
// RenderTpl 渲染指定模板页面
func (s *sView) RenderTpl(ctx context.Context, tpl string, data ...model.View) {
var (
viewObj = model.View{}
viewData = make(g.Map)
request = g.RequestFromCtx(ctx)
viewObj = model.View{}
request = g.RequestFromCtx(ctx)
)
if len(data) > 0 {
viewObj = data[0]
@@ -69,7 +65,7 @@ func (s *sView) RenderTpl(ctx context.Context, tpl string, data ...model.View) {
}
// 去掉空数据
viewData = gconv.Map(viewObj)
viewData := gconv.Map(viewObj)
for k, v := range viewData {
if g.IsEmpty(v) {
delete(viewData, k)
@@ -96,8 +92,6 @@ func (s *sView) Render302(ctx context.Context, data ...model.View) {
if view.Title == "" {
view.Title = "页面跳转中"
}
//view.MainTpl = s.getViewFolderName(ctx) + "/pages/302.html"
//s.Render(ctx, view)
s.RenderTpl(ctx, "default/pages/302.html", view)
}
@@ -156,37 +150,3 @@ func (s *sView) Error(ctx context.Context, err error) {
}
s.RenderTpl(ctx, "default/pages/500.html", view)
}
// 获取视图存储目录
func (s *sView) getViewFolderName(ctx context.Context) string {
return gstr.Split(g.Cfg().MustGet(ctx, "viewer.indexLayout").String(), "/")[0]
}
// 获取自动设置的MainTpl
func (s *sView) getDefaultMainTpl(ctx context.Context) string {
var (
viewFolderPrefix = s.getViewFolderName(ctx)
urlPathArray = gstr.SplitAndTrim(g.RequestFromCtx(ctx).URL.Path, "/")
mainTpl string
)
if len(urlPathArray) > 0 && urlPathArray[0] == viewFolderPrefix {
urlPathArray = urlPathArray[1:]
}
switch {
case len(urlPathArray) == 2:
// 如果2级路由为数字那么为模块的详情页面那么路由固定为/xxx/detail。
// 如果需要定制化内容模板请在具体路由方法中设置MainTpl。
if gstr.IsNumeric(urlPathArray[1]) {
urlPathArray[1] = "detail"
}
mainTpl = viewFolderPrefix + "/" + gfile.Join(urlPathArray[0], urlPathArray[1]) + ".html"
case len(urlPathArray) == 1:
mainTpl = viewFolderPrefix + "/" + urlPathArray[0] + "/index.html"
default:
// 默认首页内容
mainTpl = viewFolderPrefix + "/index/index.html"
}
return gstr.TrimLeft(mainTpl, "/")
}