优化代码

This commit is contained in:
刘祥超
2023-08-08 14:17:16 +08:00
parent 22aca2e80c
commit 5db14ec84a
58 changed files with 159 additions and 125 deletions

View File

@@ -8,7 +8,6 @@ import (
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"net/http"
"reflect"
)
type LocationHelper struct {
@@ -35,19 +34,19 @@ func (this *LocationHelper) BeforeAction(actionPtr actions.ActionWrapper) {
// 路径信息
var currentLocationConfig *serverconfigs.HTTPLocationConfig = nil
parentActionValue := reflect.ValueOf(actionPtr).Elem().FieldByName("ParentAction")
if parentActionValue.IsValid() {
parentAction, isOk := parentActionValue.Interface().(actionutils.ParentAction)
if isOk {
var locationId = action.ParamInt64("locationId")
locationConfig, isOk := FindLocationConfig(&parentAction, locationId)
if !isOk {
return
}
action.Data["locationId"] = locationId
action.Data["locationConfig"] = locationConfig
currentLocationConfig = locationConfig
parentActionValue, ok := actionPtr.(interface {
Parent() *actionutils.ParentAction
})
if ok {
var parentAction = parentActionValue.Parent()
var locationId = action.ParamInt64("locationId")
locationConfig, isOk := FindLocationConfig(parentAction, locationId)
if !isOk {
return
}
action.Data["locationId"] = locationId
action.Data["locationConfig"] = locationConfig
currentLocationConfig = locationConfig
}
// 左侧菜单

View File

@@ -1,6 +1,7 @@
package locationutils
import (
"context"
"encoding/json"
"errors"
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
@@ -30,7 +31,7 @@ func FindLocationConfig(parentAction *actionutils.ParentAction, locationId int64
return
}
err = locationConfig.Init(nil)
err = locationConfig.Init(context.TODO())
if err != nil {
parentAction.ErrorPage(err)
return