mirror of
https://github.com/quarkcloudio/quark-go.git
synced 2025-10-25 08:50:39 +08:00
chore: 优化代码
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/builder/template/adminresource/actions"
|
||||
"github.com/quarkcms/quark-go/pkg/hash"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -16,7 +15,7 @@ type ChangeAccount struct {
|
||||
}
|
||||
|
||||
// 执行行为句柄
|
||||
func (p *ChangeAccount) Handle(ctx *builder.Context, query *gorm.DB) interface{} {
|
||||
func (p *ChangeAccount) Handle(ctx *builder.Context, query *gorm.DB) error {
|
||||
data := map[string]interface{}{}
|
||||
json.Unmarshal(ctx.Body(), &data)
|
||||
if data["avatar"] != "" {
|
||||
@@ -33,13 +32,13 @@ func (p *ChangeAccount) Handle(ctx *builder.Context, query *gorm.DB) interface{}
|
||||
// 获取登录管理员信息
|
||||
adminInfo, err := (&model.Admin{}).GetAuthUser(ctx.Engine.GetConfig().AppKey, ctx.Token())
|
||||
if err != nil {
|
||||
return msg.Error(err.Error(), "")
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
err = query.Where("id", adminInfo.Id).Updates(data).Error
|
||||
if err != nil {
|
||||
return msg.Error(err.Error(), "")
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
return ctx.JSON(200, msg.Success("操作成功", "", ""))
|
||||
return ctx.JSONOk("操作成功")
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package actions
|
||||
import (
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/builder/template/adminresource/actions"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -50,10 +49,10 @@ func (p *ChangeStatus) GetApiParams() []string {
|
||||
}
|
||||
|
||||
// 执行行为句柄
|
||||
func (p *ChangeStatus) Handle(ctx *builder.Context, query *gorm.DB) interface{} {
|
||||
func (p *ChangeStatus) Handle(ctx *builder.Context, query *gorm.DB) error {
|
||||
status := ctx.Query("status")
|
||||
if status == "" {
|
||||
return ctx.JSON(200, msg.Error("参数错误!", ""))
|
||||
return ctx.JSONError("参数错误!")
|
||||
}
|
||||
|
||||
var fieldStatus int
|
||||
@@ -65,8 +64,8 @@ func (p *ChangeStatus) Handle(ctx *builder.Context, query *gorm.DB) interface{}
|
||||
|
||||
err := query.Update("status", fieldStatus).Error
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
return ctx.JSON(200, msg.Success("操作成功", "", ""))
|
||||
return ctx.JSONOk("操作成功")
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/builder/template/adminresource/actions"
|
||||
"github.com/quarkcms/quark-go/pkg/dal/db"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -16,7 +15,7 @@ type ChangeWebConfig struct {
|
||||
}
|
||||
|
||||
// 执行行为句柄
|
||||
func (p *ChangeWebConfig) Handle(ctx *builder.Context, query *gorm.DB) interface{} {
|
||||
func (p *ChangeWebConfig) Handle(ctx *builder.Context, query *gorm.DB) error {
|
||||
data := map[string]interface{}{}
|
||||
json.Unmarshal(ctx.Body(), &data)
|
||||
result := true
|
||||
@@ -40,12 +39,12 @@ func (p *ChangeWebConfig) Handle(ctx *builder.Context, query *gorm.DB) interface
|
||||
}
|
||||
|
||||
if !result {
|
||||
return ctx.JSON(200, msg.Error("操作失败,请重试!", ""))
|
||||
return ctx.JSONError("操作失败,请重试!")
|
||||
}
|
||||
|
||||
// 刷新网站配置
|
||||
(&model.Config{}).Refresh()
|
||||
|
||||
// 返回成功
|
||||
return ctx.JSON(200, msg.Success("操作成功", "", ""))
|
||||
return ctx.JSONOk("操作成功")
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package actions
|
||||
import (
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/builder/template/adminresource/actions"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -54,11 +53,11 @@ func (p *Delete) GetApiParams() []string {
|
||||
}
|
||||
|
||||
// 执行行为句柄
|
||||
func (p *Delete) Handle(ctx *builder.Context, query *gorm.DB) interface{} {
|
||||
func (p *Delete) Handle(ctx *builder.Context, query *gorm.DB) error {
|
||||
err := query.Delete("").Error
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
return ctx.JSON(200, msg.Success("操作成功", "", ""))
|
||||
return ctx.JSONOk("操作成功")
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package actions
|
||||
import (
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/builder/template/adminresource/actions"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -49,11 +48,11 @@ func (p *Disable) GetApiParams() []string {
|
||||
}
|
||||
|
||||
// 执行行为句柄
|
||||
func (p *Disable) Handle(ctx *builder.Context, query *gorm.DB) interface{} {
|
||||
func (p *Disable) Handle(ctx *builder.Context, query *gorm.DB) error {
|
||||
err := query.Update("status", 0).Error
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
return ctx.JSON(200, msg.Success("操作成功", "", ""))
|
||||
return ctx.JSONOk("操作成功")
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package actions
|
||||
import (
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/builder/template/adminresource/actions"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -49,11 +48,11 @@ func (p *Enable) GetApiParams() []string {
|
||||
}
|
||||
|
||||
// 执行行为句柄
|
||||
func (p *Enable) Handle(ctx *builder.Context, model *gorm.DB) interface{} {
|
||||
func (p *Enable) Handle(ctx *builder.Context, model *gorm.DB) error {
|
||||
err := model.Update("status", 1).Error
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
return ctx.JSON(200, msg.Success("操作成功", "", ""))
|
||||
return ctx.JSONOk("操作成功")
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package actions
|
||||
import (
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/builder/template/adminresource/actions"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -12,7 +11,7 @@ type SelectOptions struct {
|
||||
}
|
||||
|
||||
// 执行行为句柄
|
||||
func (p *SelectOptions) Handle(ctx *builder.Context, query *gorm.DB) interface{} {
|
||||
func (p *SelectOptions) Handle(ctx *builder.Context, query *gorm.DB) error {
|
||||
resource := ctx.Param("resource")
|
||||
search := ctx.Query("search")
|
||||
lists := []map[string]interface{}{}
|
||||
@@ -31,5 +30,5 @@ func (p *SelectOptions) Handle(ctx *builder.Context, query *gorm.DB) interface{}
|
||||
}
|
||||
}
|
||||
|
||||
return ctx.JSON(200, msg.Success("操作成功", "", results))
|
||||
return ctx.JSONOk("操作成功")
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/builder/template/adminresource/actions"
|
||||
"github.com/quarkcms/quark-go/pkg/dal/db"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -37,7 +36,7 @@ func (p *SyncPermission) Init() *SyncPermission {
|
||||
}
|
||||
|
||||
// 执行行为句柄
|
||||
func (p *SyncPermission) Handle(ctx *builder.Context, query *gorm.DB) interface{} {
|
||||
func (p *SyncPermission) Handle(ctx *builder.Context, query *gorm.DB) error {
|
||||
// 获取当前权限
|
||||
permissions := ctx.Engine.GetUrlPaths()
|
||||
data := []model.Permission{}
|
||||
@@ -61,18 +60,18 @@ func (p *SyncPermission) Handle(ctx *builder.Context, query *gorm.DB) interface{
|
||||
}
|
||||
}
|
||||
if len(data) == 0 {
|
||||
return ctx.JSON(200, msg.Error("暂无新增权限!", ""))
|
||||
return ctx.JSONError("暂无新增权限!")
|
||||
}
|
||||
|
||||
err := query.Create(data).Error
|
||||
if err != nil {
|
||||
return msg.Error(err.Error(), "")
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
err = db.Client.Model(&model.Permission{}).Where("name NOT IN ?", permissions).Delete("").Error
|
||||
if err != nil {
|
||||
return msg.Error(err.Error(), "")
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
return ctx.JSON(200, msg.Success("操作成功", "", ""))
|
||||
return ctx.JSONOk("操作成功")
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/quarkcms/quark-go/pkg/app/model"
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/builder/template/adminupload"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
"github.com/quarkcms/quark-go/pkg/storage"
|
||||
)
|
||||
|
||||
@@ -90,7 +89,7 @@ func (p *File) AfterHandle(ctx *builder.Context, result *storage.FileInfo) inter
|
||||
|
||||
adminInfo, err := (&model.Admin{}).GetAuthUser(ctx.Engine.GetConfig().AppKey, ctx.Token())
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
@@ -106,10 +105,10 @@ func (p *File) AfterHandle(ctx *builder.Context, result *storage.FileInfo) inter
|
||||
Status: 1,
|
||||
})
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
return ctx.JSON(200, msg.Success("上传成功", "", map[string]interface{}{
|
||||
return ctx.JSONOk("上传成功", "", map[string]interface{}{
|
||||
"id": id,
|
||||
"contentType": result.ContentType,
|
||||
"ext": result.Ext,
|
||||
@@ -118,5 +117,5 @@ func (p *File) AfterHandle(ctx *builder.Context, result *storage.FileInfo) inter
|
||||
"path": result.Path,
|
||||
"size": result.Size,
|
||||
"url": result.Url,
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/quarkcms/quark-go/pkg/app/model"
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/builder/template/adminupload"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
"github.com/quarkcms/quark-go/pkg/storage"
|
||||
)
|
||||
|
||||
@@ -39,15 +38,15 @@ func (p *Image) Init() interface{} {
|
||||
p.SavePath = "./website/storage/images/" + time.Now().Format("20060102") + "/"
|
||||
|
||||
// 添加路由映射关系
|
||||
p.AddRouteMapping("GET", "/api/admin/upload/:resource/getList", "GetList")
|
||||
p.AddRouteMapping("GET", "/api/admin/upload/:resource/delete", "Delete")
|
||||
p.AddRouteMapping("POST", "/api/admin/upload/:resource/crop", "Crop")
|
||||
p.GET("/api/admin/upload/:resource/getList", p.GetList)
|
||||
p.GET("/api/admin/upload/:resource/delete", p.Delete)
|
||||
p.POST("/api/admin/upload/:resource/crop", p.Crop)
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
// 获取文件列表
|
||||
func (p *Image) GetList(ctx *builder.Context) interface{} {
|
||||
func (p *Image) GetList(ctx *builder.Context) error {
|
||||
page := ctx.Query("page", "1")
|
||||
categoryId := ctx.Query("pictureCategoryId", "")
|
||||
searchName := ctx.Query("pictureSearchName", "")
|
||||
@@ -64,7 +63,7 @@ func (p *Image) GetList(ctx *builder.Context) interface{} {
|
||||
currentPage,
|
||||
)
|
||||
if err != nil {
|
||||
return msg.Error(err.Error(), "")
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
pagination := map[string]interface{}{
|
||||
@@ -76,34 +75,34 @@ func (p *Image) GetList(ctx *builder.Context) interface{} {
|
||||
|
||||
categorys, err := (&model.PictureCategory{}).GetAuthList(ctx.Engine.GetConfig().AppKey, ctx.Token())
|
||||
if err != nil {
|
||||
return msg.Error(err.Error(), "")
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
return ctx.JSON(200, msg.Success("上传成功", "", map[string]interface{}{
|
||||
return ctx.JSONOk("上传成功", "", map[string]interface{}{
|
||||
"pagination": pagination,
|
||||
"lists": pictures,
|
||||
"categorys": categorys,
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
// 图片删除
|
||||
func (p *Image) Delete(ctx *builder.Context) interface{} {
|
||||
func (p *Image) Delete(ctx *builder.Context) error {
|
||||
data := map[string]interface{}{}
|
||||
json.Unmarshal(ctx.Body(), &data)
|
||||
if data["id"] == "" {
|
||||
return ctx.JSON(200, msg.Error("参数错误!", ""))
|
||||
return ctx.JSONError("参数错误!")
|
||||
}
|
||||
|
||||
err := (&model.Picture{}).DeleteById(data["id"])
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
} else {
|
||||
return ctx.JSON(200, msg.Success("操作成功!", "", ""))
|
||||
return ctx.JSONError("参数错误!")
|
||||
}
|
||||
|
||||
return ctx.JSONOk("操作成功!")
|
||||
}
|
||||
|
||||
// 图片裁剪
|
||||
func (p *Image) Crop(ctx *builder.Context) interface{} {
|
||||
func (p *Image) Crop(ctx *builder.Context) error {
|
||||
var (
|
||||
result *storage.FileInfo
|
||||
err error
|
||||
@@ -111,26 +110,23 @@ func (p *Image) Crop(ctx *builder.Context) interface{} {
|
||||
|
||||
data := map[string]interface{}{}
|
||||
if err := ctx.BodyParser(&data); err != nil {
|
||||
return msg.Error(err.Error(), "")
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
if data["id"] == "" {
|
||||
return ctx.JSON(200, msg.Error("参数错误!", ""))
|
||||
}
|
||||
if data["file"] == "" {
|
||||
return ctx.JSON(200, msg.Error("参数错误!", ""))
|
||||
if data["id"] == "" || data["file"] == "" {
|
||||
return ctx.JSONError("参数错误!")
|
||||
}
|
||||
|
||||
pictureInfo, err := (&model.Picture{}).GetInfoById(data["id"])
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
if pictureInfo.Id == 0 {
|
||||
return ctx.JSON(200, msg.Error("文件不存在", ""))
|
||||
return ctx.JSONError("文件不存在")
|
||||
}
|
||||
|
||||
adminInfo, err := (&model.Admin{}).GetAuthUser(ctx.Engine.GetConfig().AppKey, ctx.Token())
|
||||
if err != nil {
|
||||
return msg.Error(err.Error(), "")
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
limitW := ctx.Query("limitW", "")
|
||||
@@ -138,12 +134,12 @@ func (p *Image) Crop(ctx *builder.Context) interface{} {
|
||||
|
||||
files := strings.Split(data["file"].(string), ",")
|
||||
if len(files) != 2 {
|
||||
return ctx.JSON(200, msg.Error("格式错误", ""))
|
||||
return ctx.JSONError("格式错误")
|
||||
}
|
||||
|
||||
fileData, err := base64.StdEncoding.DecodeString(files[1]) //成图片文件并把文件写入到buffer
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
limitSize := reflect.
|
||||
@@ -213,7 +209,7 @@ func (p *Image) Crop(ctx *builder.Context) interface{} {
|
||||
BeforeHandle(ctx *builder.Context, fileSystem *storage.FileSystem) (*storage.FileSystem, *storage.FileInfo, error)
|
||||
}).BeforeHandle(ctx, fileSystem)
|
||||
if err != nil {
|
||||
return msg.Error(err.Error(), "")
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
if fileInfo != nil {
|
||||
// 更新数据库
|
||||
@@ -237,9 +233,8 @@ func (p *Image) Crop(ctx *builder.Context) interface{} {
|
||||
FileName(pictureInfo.Name).
|
||||
Path(savePath).
|
||||
Save()
|
||||
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
// 重写url
|
||||
@@ -262,7 +257,7 @@ func (p *Image) Crop(ctx *builder.Context) interface{} {
|
||||
Status: 1,
|
||||
})
|
||||
|
||||
return ctx.JSON(200, msg.Success("裁剪成功", "", result))
|
||||
return ctx.JSONOk("裁剪成功", "", result)
|
||||
}
|
||||
|
||||
// 上传前回调
|
||||
@@ -308,7 +303,7 @@ func (p *Image) AfterHandle(ctx *builder.Context, result *storage.FileInfo) inte
|
||||
|
||||
adminInfo, err := (&model.Admin{}).GetAuthUser(ctx.Engine.GetConfig().AppKey, ctx.Token())
|
||||
if err != nil {
|
||||
return msg.Error(err.Error(), "")
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
@@ -327,10 +322,10 @@ func (p *Image) AfterHandle(ctx *builder.Context, result *storage.FileInfo) inte
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
return ctx.JSON(200, msg.Success("上传成功", "", map[string]interface{}{
|
||||
return ctx.JSONOk("上传成功", "", map[string]interface{}{
|
||||
"id": id,
|
||||
"contentType": result.ContentType,
|
||||
"ext": result.Ext,
|
||||
@@ -341,5 +336,5 @@ func (p *Image) AfterHandle(ctx *builder.Context, result *storage.FileInfo) inte
|
||||
"path": result.Path,
|
||||
"size": result.Size,
|
||||
"url": result.Url,
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ type Engine struct {
|
||||
type RouteMapping struct {
|
||||
Method string
|
||||
Path string
|
||||
HandlerName string
|
||||
Handler func(ctx *Context) error
|
||||
}
|
||||
|
||||
type DBConfig struct {
|
||||
@@ -272,7 +272,7 @@ func (p *Engine) initPaths() {
|
||||
}
|
||||
|
||||
if !hasRoutePath(routePaths, v.Method, v.Path) {
|
||||
routePaths = append(routePaths, &RouteMapping{v.Method, v.Path, v.HandlerName})
|
||||
routePaths = append(routePaths, &RouteMapping{v.Method, v.Path, v.Handler})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,7 +325,6 @@ func (p *Engine) UseHandlers() []func(ctx *Context) error {
|
||||
// 解析模版方法
|
||||
func (p *Engine) handleParser(ctx *Context) error {
|
||||
var (
|
||||
result []reflect.Value
|
||||
err error
|
||||
templateInstance interface{}
|
||||
)
|
||||
@@ -339,31 +338,7 @@ func (p *Engine) handleParser(ctx *Context) error {
|
||||
// 执行挂载的方法
|
||||
for _, v := range p.routePaths {
|
||||
if v.Path == ctx.FullPath() {
|
||||
|
||||
// 反射实例值
|
||||
value := reflect.ValueOf(templateInstance)
|
||||
if !value.IsValid() {
|
||||
continue
|
||||
}
|
||||
|
||||
// 获取实例上方法
|
||||
method := value.MethodByName(v.HandlerName)
|
||||
if !method.IsValid() {
|
||||
continue
|
||||
}
|
||||
|
||||
// 反射执行结果
|
||||
result = method.Call([]reflect.Value{
|
||||
reflect.ValueOf(ctx),
|
||||
})
|
||||
if len(result) != 1 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 执行结果
|
||||
if v, ok := result[0].Interface().(error); ok {
|
||||
err = v
|
||||
}
|
||||
err = v.Handler(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/quarkcms/quark-go/pkg/component/admin/pagecontainer"
|
||||
"github.com/quarkcms/quark-go/pkg/component/admin/statistic"
|
||||
"github.com/quarkcms/quark-go/pkg/dal/db"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
)
|
||||
|
||||
// 后台登录模板
|
||||
@@ -35,7 +34,7 @@ func (p *Template) TemplateInit() interface{} {
|
||||
p.DB = db.Client
|
||||
|
||||
// 注册路由映射
|
||||
p.GET("/api/admin/dashboard/:resource/index", "Render") // 后台仪表盘路由
|
||||
p.GET("/api/admin/dashboard/:resource/index", p.Render) // 后台仪表盘路由
|
||||
|
||||
// 标题
|
||||
p.Title = "仪表盘"
|
||||
@@ -49,12 +48,12 @@ func (p *Template) Cards(ctx *builder.Context) interface{} {
|
||||
}
|
||||
|
||||
// 组件渲染
|
||||
func (p *Template) Render(ctx *builder.Context) interface{} {
|
||||
func (p *Template) Render(ctx *builder.Context) error {
|
||||
cards := ctx.Template.(interface {
|
||||
Cards(*builder.Context) interface{}
|
||||
}).Cards(ctx)
|
||||
if cards == nil {
|
||||
return ctx.JSON(200, msg.Error("请实现Cards内容", ""))
|
||||
return ctx.JSONError("请实现Cards内容")
|
||||
}
|
||||
|
||||
var cols []interface{}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/quarkcms/quark-go/pkg/component/admin/footer"
|
||||
"github.com/quarkcms/quark-go/pkg/component/admin/layout"
|
||||
"github.com/quarkcms/quark-go/pkg/dal/db"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
)
|
||||
|
||||
// 后台登录模板
|
||||
@@ -29,13 +28,13 @@ func (p *Template) TemplateInit() interface{} {
|
||||
p.DB = db.Client
|
||||
|
||||
// 注册路由映射
|
||||
p.GET("/api/admin/layout/:resource/index", "Render") // 获取布局配置
|
||||
p.GET("/api/admin/layout/:resource/index", p.Render) // 获取布局配置
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
// 组件渲染
|
||||
func (p *Template) Render(ctx *builder.Context) interface{} {
|
||||
func (p *Template) Render(ctx *builder.Context) error {
|
||||
adminLayout := ctx.Engine.GetAdminLayout()
|
||||
|
||||
admin := &model.Admin{}
|
||||
@@ -44,13 +43,13 @@ func (p *Template) Render(ctx *builder.Context) interface{} {
|
||||
// 获取登录管理员信息
|
||||
adminInfo, err := admin.GetAuthUser(config.AppKey, ctx.Token())
|
||||
if err != nil {
|
||||
return msg.Error(err.Error(), "")
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
// 获取管理员菜单
|
||||
getMenus, err := admin.GetMenuListById(adminInfo.Id)
|
||||
if err != nil {
|
||||
return msg.Error(err.Error(), "")
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
// 页脚
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/quarkcms/quark-go/pkg/builder/template"
|
||||
"github.com/quarkcms/quark-go/pkg/component/admin/login"
|
||||
"github.com/quarkcms/quark-go/pkg/dal/db"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
)
|
||||
|
||||
// 后台登录模板
|
||||
@@ -34,11 +33,11 @@ func (p *Template) TemplateInit() interface{} {
|
||||
p.DB = db.Client
|
||||
|
||||
// 注册路由映射
|
||||
p.GET("/api/admin/login/:resource/index", "Render") // 渲染登录页面路由
|
||||
p.POST("/api/admin/login/:resource/handle", "Handle") // 后台登录执行路由
|
||||
p.GET("/api/admin/login/:resource/captchaId", "CaptchaId") // 后台登录获取验证码ID路由
|
||||
p.GET("/api/admin/login/:resource/captcha/:id", "Captcha") // 后台登录验证码路由
|
||||
p.GET("/api/admin/logout/:resource/handle", "Logout") // 后台退出执行路由
|
||||
p.GET("/api/admin/login/:resource/index", p.Render) // 渲染登录页面路由
|
||||
p.POST("/api/admin/login/:resource/handle", p.Handle) // 后台登录执行路由
|
||||
p.GET("/api/admin/login/:resource/captchaId", p.CaptchaId) // 后台登录获取验证码ID路由
|
||||
p.GET("/api/admin/login/:resource/captcha/:id", p.Captcha) // 后台登录验证码路由
|
||||
p.GET("/api/admin/logout/:resource/handle", p.Logout) // 后台退出执行路由
|
||||
|
||||
// 标题
|
||||
p.Title = "QuarkGo"
|
||||
@@ -53,32 +52,32 @@ func (p *Template) TemplateInit() interface{} {
|
||||
}
|
||||
|
||||
// 验证码ID
|
||||
func (p *Template) CaptchaId(ctx *builder.Context) interface{} {
|
||||
return ctx.JSON(200, msg.Error("请实现创建验证码ID方法", ""))
|
||||
func (p *Template) CaptchaId(ctx *builder.Context) error {
|
||||
return ctx.JSONError("请实现创建验证码ID方法")
|
||||
}
|
||||
|
||||
// 生成验证码
|
||||
func (p *Template) Captcha(ctx *builder.Context) interface{} {
|
||||
return ctx.JSON(200, msg.Error("请实现生成验证码方法", ""))
|
||||
func (p *Template) Captcha(ctx *builder.Context) error {
|
||||
return ctx.JSONError("请实现生成验证码方法")
|
||||
}
|
||||
|
||||
// 登录方法
|
||||
func (p *Template) Handle(ctx *builder.Context) interface{} {
|
||||
return ctx.JSON(200, msg.Error("请实现登录方法", ""))
|
||||
func (p *Template) Handle(ctx *builder.Context) error {
|
||||
return ctx.JSONError("请实现登录方法")
|
||||
}
|
||||
|
||||
// 退出方法
|
||||
func (p *Template) Logout(ctx *builder.Context) interface{} {
|
||||
return ctx.JSON(200, msg.Error("请实现退出方法", ""))
|
||||
func (p *Template) Logout(ctx *builder.Context) error {
|
||||
return ctx.JSONError("请实现退出方法")
|
||||
}
|
||||
|
||||
// 组件渲染
|
||||
func (p *Template) Render(ctx *builder.Context) interface{} {
|
||||
func (p *Template) Render(ctx *builder.Context) error {
|
||||
|
||||
// 模板实例
|
||||
templateInstance := ctx.Template
|
||||
if templateInstance == nil {
|
||||
return ctx.JSON(200, msg.Error("模板实例获取失败", ""))
|
||||
return ctx.JSONError("模板实例获取失败")
|
||||
}
|
||||
|
||||
// 默认登录接口
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
type ActionRequest struct{}
|
||||
|
||||
// 执行行为
|
||||
func (p *ActionRequest) Handle(ctx *builder.Context) interface{} {
|
||||
var result interface{}
|
||||
func (p *ActionRequest) Handle(ctx *builder.Context) error {
|
||||
var result error
|
||||
|
||||
// 获取模型结构体
|
||||
modelInstance := reflect.
|
||||
@@ -55,12 +55,12 @@ func (p *ActionRequest) Handle(ctx *builder.Context) interface{} {
|
||||
|
||||
if ctx.Param("uriKey") == uriKey {
|
||||
result = dropdownAction.(interface {
|
||||
Handle(*builder.Context, *gorm.DB) interface{}
|
||||
Handle(*builder.Context, *gorm.DB) error
|
||||
}).Handle(ctx, model)
|
||||
|
||||
// 执行完后回调
|
||||
err := ctx.Template.(interface {
|
||||
AfterAction(ctx *builder.Context, uriKey string, query *gorm.DB) interface{}
|
||||
AfterAction(ctx *builder.Context, uriKey string, query *gorm.DB) error
|
||||
}).AfterAction(ctx, uriKey, model)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -72,12 +72,12 @@ func (p *ActionRequest) Handle(ctx *builder.Context) interface{} {
|
||||
} else {
|
||||
if ctx.Param("uriKey") == uriKey {
|
||||
result = v.(interface {
|
||||
Handle(*builder.Context, *gorm.DB) interface{}
|
||||
Handle(*builder.Context, *gorm.DB) error
|
||||
}).Handle(ctx, model)
|
||||
|
||||
// 执行完后回调
|
||||
err := ctx.Template.(interface {
|
||||
AfterAction(ctx *builder.Context, uriKey string, query *gorm.DB) interface{}
|
||||
AfterAction(ctx *builder.Context, uriKey string, query *gorm.DB) error
|
||||
}).AfterAction(ctx, uriKey, model)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/dal/db"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
)
|
||||
|
||||
type DetailRequest struct{}
|
||||
@@ -109,13 +108,13 @@ func (p *DetailRequest) FillData(ctx *builder.Context) map[string]interface{} {
|
||||
}
|
||||
|
||||
// 获取表单初始化数据
|
||||
func (p *DetailRequest) Values(ctx *builder.Context) interface{} {
|
||||
func (p *DetailRequest) Values(ctx *builder.Context) error {
|
||||
data := p.FillData(ctx)
|
||||
|
||||
// 断言BeforeEditing方法,获取初始数据
|
||||
// 获取初始数据
|
||||
data = ctx.Template.(interface {
|
||||
BeforeDetailShowing(*builder.Context, map[string]interface{}) map[string]interface{}
|
||||
}).BeforeDetailShowing(ctx, data)
|
||||
|
||||
return ctx.JSON(200, msg.Success("获取成功", "", data))
|
||||
return ctx.JSONOk("获取成功", "", data)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/dal/db"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
)
|
||||
|
||||
type EditRequest struct{}
|
||||
@@ -80,7 +79,7 @@ func (p *EditRequest) FillData(ctx *builder.Context) map[string]interface{} {
|
||||
}
|
||||
|
||||
// 获取表单初始化数据
|
||||
func (p *EditRequest) Values(ctx *builder.Context) interface{} {
|
||||
func (p *EditRequest) Values(ctx *builder.Context) error {
|
||||
data := p.FillData(ctx)
|
||||
|
||||
// 断言BeforeEditing方法,获取初始数据
|
||||
@@ -88,5 +87,5 @@ func (p *EditRequest) Values(ctx *builder.Context) interface{} {
|
||||
BeforeEditing(*builder.Context, map[string]interface{}) map[string]interface{}
|
||||
}).BeforeEditing(ctx, data)
|
||||
|
||||
return ctx.JSON(200, msg.Success("获取成功", "", data))
|
||||
return ctx.JSONOk("获取成功", "", data)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
type EditableRequest struct{}
|
||||
|
||||
// 执行行为
|
||||
func (p *EditableRequest) Handle(ctx *builder.Context) interface{} {
|
||||
func (p *EditableRequest) Handle(ctx *builder.Context) error {
|
||||
var (
|
||||
id interface{}
|
||||
field string
|
||||
@@ -67,7 +67,7 @@ func (p *EditableRequest) Handle(ctx *builder.Context) interface{} {
|
||||
}
|
||||
|
||||
result := ctx.Template.(interface {
|
||||
AfterEditable(ctx *builder.Context, id interface{}, field string, value interface{}) interface{}
|
||||
AfterEditable(ctx *builder.Context, id interface{}, field string, value interface{}) error
|
||||
}).AfterEditable(ctx, id, field, value)
|
||||
if result != nil {
|
||||
return result
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
type ExportRequest struct{}
|
||||
|
||||
// 执行行为
|
||||
func (p *ExportRequest) Handle(ctx *builder.Context) interface{} {
|
||||
func (p *ExportRequest) Handle(ctx *builder.Context) error {
|
||||
data := p.QueryData(ctx)
|
||||
|
||||
// 获取列表字段
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
type ImportRequest struct{}
|
||||
|
||||
// 执行行为
|
||||
func (p *ImportRequest) Handle(ctx *builder.Context, indexRoute string) interface{} {
|
||||
func (p *ImportRequest) Handle(ctx *builder.Context, indexRoute string) error {
|
||||
data := map[string]interface{}{}
|
||||
json.Unmarshal(ctx.Body(), &data)
|
||||
fileId := data["fileId"]
|
||||
@@ -36,7 +36,7 @@ func (p *ImportRequest) Handle(ctx *builder.Context, indexRoute string) interfac
|
||||
}
|
||||
|
||||
if getFileId == 0 {
|
||||
return ctx.JSON(200, msg.Error("参数错误!", ""))
|
||||
return ctx.JSONError("参数错误!")
|
||||
}
|
||||
|
||||
modelInstance := reflect.
|
||||
@@ -47,7 +47,7 @@ func (p *ImportRequest) Handle(ctx *builder.Context, indexRoute string) interfac
|
||||
|
||||
importData, err := (&models.File{}).GetExcelData(getFileId)
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
// 表格头部
|
||||
@@ -131,7 +131,7 @@ func (p *ImportRequest) Handle(ctx *builder.Context, indexRoute string) interfac
|
||||
}
|
||||
|
||||
if importResult {
|
||||
return ctx.JSON(200, msg.Success("操作成功!", strings.Replace("/layout/index?api="+indexRoute, ":resource", ctx.Param("resource"), -1), ""))
|
||||
return ctx.JSONOk("操作成功!", strings.Replace("/layout/index?api="+indexRoute, ":resource", ctx.Param("resource"), -1))
|
||||
} else {
|
||||
importHead = append(importHead, "错误信息")
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
type ImportTemplateRequest struct{}
|
||||
|
||||
// 导入数据模板
|
||||
func (p *ImportTemplateRequest) Handle(ctx *builder.Context) interface{} {
|
||||
func (p *ImportTemplateRequest) Handle(ctx *builder.Context) error {
|
||||
fields := ctx.Template.(interface {
|
||||
ImportFields(ctx *builder.Context) interface{}
|
||||
}).ImportFields(ctx)
|
||||
@@ -176,7 +176,7 @@ func (p *ImportTemplateRequest) getFieldRuleMessage(rules []*rule.Rule) string {
|
||||
|
||||
if len(message) > 0 {
|
||||
return strings.Replace(strings.Trim(fmt.Sprint(message), "/"), " ", ",", -1)
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -84,11 +84,7 @@ func (p *IndexRequest) QueryData(ctx *builder.Context) interface{} {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the column filters for the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
// Get the column filters for the request.
|
||||
func (p *IndexRequest) columnFilters(ctx *builder.Context) map[string]interface{} {
|
||||
querys := ctx.AllQuerys()
|
||||
var data map[string]interface{}
|
||||
@@ -103,11 +99,7 @@ func (p *IndexRequest) columnFilters(ctx *builder.Context) map[string]interface{
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the orderings for the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
// Get the orderings for the request.
|
||||
func (p *IndexRequest) orderings(ctx *builder.Context) map[string]interface{} {
|
||||
querys := ctx.AllQuerys()
|
||||
var data map[string]interface{}
|
||||
|
||||
@@ -8,14 +8,13 @@ import (
|
||||
"github.com/gobeam/stringy"
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/dal/db"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type StoreRequest struct{}
|
||||
|
||||
// 执行行为
|
||||
func (p *StoreRequest) Handle(ctx *builder.Context) interface{} {
|
||||
func (p *StoreRequest) Handle(ctx *builder.Context) error {
|
||||
modelInstance := reflect.
|
||||
ValueOf(ctx.Template).
|
||||
Elem().
|
||||
@@ -33,14 +32,14 @@ func (p *StoreRequest) Handle(ctx *builder.Context) interface{} {
|
||||
BeforeSaving(ctx *builder.Context, data map[string]interface{}) (map[string]interface{}, error)
|
||||
}).BeforeSaving(ctx, data)
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
validator := ctx.Template.(interface {
|
||||
ValidatorForCreation(ctx *builder.Context, data map[string]interface{}) error
|
||||
}).ValidatorForCreation(ctx, data)
|
||||
if validator != nil {
|
||||
return ctx.JSON(200, msg.Error(validator.Error(), ""))
|
||||
return ctx.JSONError(validator.Error())
|
||||
}
|
||||
zeroValues := map[string]interface{}{}
|
||||
for _, v := range fields.([]interface{}) {
|
||||
@@ -112,7 +111,7 @@ func (p *StoreRequest) Handle(ctx *builder.Context) interface{} {
|
||||
|
||||
if reflectValue.IsValid() {
|
||||
if reflectFieldName.Type().String() != reflectValue.Type().String() {
|
||||
return ctx.JSON(200, msg.Error("结构体类型与传参类型不一致!", ""))
|
||||
return ctx.JSONError("结构体类型与传参类型不一致!")
|
||||
}
|
||||
|
||||
reflectFieldName.Set(reflectValue)
|
||||
@@ -139,6 +138,6 @@ func (p *StoreRequest) Handle(ctx *builder.Context) interface{} {
|
||||
}
|
||||
|
||||
return ctx.Template.(interface {
|
||||
AfterSaved(ctx *builder.Context, id int, data map[string]interface{}, result *gorm.DB) interface{}
|
||||
AfterSaved(ctx *builder.Context, id int, data map[string]interface{}, result *gorm.DB) error
|
||||
}).AfterSaved(ctx, id, data, getModel)
|
||||
}
|
||||
|
||||
@@ -8,14 +8,13 @@ import (
|
||||
"github.com/gobeam/stringy"
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/dal/db"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UpdateRequest struct{}
|
||||
|
||||
// 执行行为
|
||||
func (p *UpdateRequest) Handle(ctx *builder.Context) interface{} {
|
||||
func (p *UpdateRequest) Handle(ctx *builder.Context) error {
|
||||
modelInstance := reflect.
|
||||
ValueOf(ctx.Template).
|
||||
Elem().
|
||||
@@ -29,21 +28,21 @@ func (p *UpdateRequest) Handle(ctx *builder.Context) interface{} {
|
||||
data := map[string]interface{}{}
|
||||
json.Unmarshal(ctx.Body(), &data)
|
||||
if data["id"] == "" {
|
||||
return ctx.JSON(200, msg.Error("参数错误!", ""))
|
||||
return ctx.JSONError("参数错误!")
|
||||
}
|
||||
|
||||
data, err := ctx.Template.(interface {
|
||||
BeforeSaving(ctx *builder.Context, data map[string]interface{}) (map[string]interface{}, error)
|
||||
}).BeforeSaving(ctx, data)
|
||||
if err != nil {
|
||||
return msg.Error(err.Error(), "")
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
validator := ctx.Template.(interface {
|
||||
ValidatorForUpdate(ctx *builder.Context, data map[string]interface{}) error
|
||||
}).ValidatorForUpdate(ctx, data)
|
||||
if validator != nil {
|
||||
return validator
|
||||
return ctx.JSONError(validator.Error())
|
||||
}
|
||||
zeroValues := map[string]interface{}{}
|
||||
for _, v := range fields.([]interface{}) {
|
||||
@@ -119,7 +118,7 @@ func (p *UpdateRequest) Handle(ctx *builder.Context) interface{} {
|
||||
|
||||
if reflectValue.IsValid() {
|
||||
if reflectFieldName.Type().String() != reflectValue.Type().String() {
|
||||
return ctx.JSON(200, msg.Error("结构体类型与传参类型不一致!", ""))
|
||||
return ctx.JSONError("结构体类型与传参类型不一致!")
|
||||
}
|
||||
|
||||
reflectFieldName.Set(reflectValue)
|
||||
@@ -137,6 +136,6 @@ func (p *UpdateRequest) Handle(ctx *builder.Context) interface{} {
|
||||
}
|
||||
|
||||
return ctx.Template.(interface {
|
||||
AfterSaved(ctx *builder.Context, id int, data map[string]interface{}, result *gorm.DB) interface{}
|
||||
AfterSaved(ctx *builder.Context, id int, data map[string]interface{}, result *gorm.DB) error
|
||||
}).AfterSaved(ctx, int(data["id"].(float64)), data, getModel)
|
||||
}
|
||||
|
||||
@@ -55,19 +55,19 @@ func (p *Template) TemplateInit() interface{} {
|
||||
p.DB = db.Client
|
||||
|
||||
// 注册路由映射
|
||||
p.GET(IndexPath, "IndexRender") // 列表
|
||||
p.GET(EditablePath, "EditableRender") // 表格行内编辑
|
||||
p.Any(ActionPath, "ActionRender") // 执行行为
|
||||
p.GET(CreatePath, "CreationRender") // 创建页面
|
||||
p.POST(StorePath, "StoreRender") // 创建方法
|
||||
p.GET(EditPath, "EditRender") // 编辑页面
|
||||
p.GET(EditValuesPath, "EditValuesRender") // 获取编辑表单值
|
||||
p.POST(SavePath, "SaveRender") // 保存编辑值
|
||||
p.GET(DetailPath, "DetailRender") // 详情页面
|
||||
p.GET(ExportPath, "ExportRender") // 导出数据
|
||||
p.POST(ImportPath, "ImportRender") // 导入数据
|
||||
p.GET(ImportTemplatePath, "ImportTemplateRender") // 导入模板
|
||||
p.GET(FormPath, "FormRender") // 通用表单资源
|
||||
p.GET(IndexPath, p.IndexRender) // 列表
|
||||
p.GET(EditablePath, p.EditableRender) // 表格行内编辑
|
||||
p.Any(ActionPath, p.ActionRender) // 执行行为
|
||||
p.GET(CreatePath, p.CreationRender) // 创建页面
|
||||
p.POST(StorePath, p.StoreRender) // 创建方法
|
||||
p.GET(EditPath, p.EditRender) // 编辑页面
|
||||
p.GET(EditValuesPath, p.EditValuesRender) // 获取编辑表单值
|
||||
p.POST(SavePath, p.SaveRender) // 保存编辑值
|
||||
p.GET(DetailPath, p.DetailRender) // 详情页面
|
||||
p.GET(ExportPath, p.ExportRender) // 导出数据
|
||||
p.POST(ImportPath, p.ImportRender) // 导入数据
|
||||
p.GET(ImportTemplatePath, p.ImportTemplateRender) // 导入模板
|
||||
p.GET(FormPath, p.FormRender) // 通用表单资源
|
||||
|
||||
return p
|
||||
}
|
||||
@@ -95,17 +95,17 @@ func (p *Template) BeforeImporting(ctx *builder.Context, list [][]interface{}) [
|
||||
}
|
||||
|
||||
// 表格行内编辑执行完之后回调
|
||||
func (p *Template) AfterEditable(ctx *builder.Context, id interface{}, field string, value interface{}) interface{} {
|
||||
func (p *Template) AfterEditable(ctx *builder.Context, id interface{}, field string, value interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 行为执行完之后回调
|
||||
func (p *Template) AfterAction(ctx *builder.Context, uriKey string, query *gorm.DB) interface{} {
|
||||
func (p *Template) AfterAction(ctx *builder.Context, uriKey string, query *gorm.DB) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 列表页渲染
|
||||
func (p *Template) IndexRender(ctx *builder.Context) interface{} {
|
||||
func (p *Template) IndexRender(ctx *builder.Context) error {
|
||||
// 获取数据
|
||||
data := (&requests.IndexRequest{}).QueryData(ctx)
|
||||
|
||||
@@ -122,17 +122,17 @@ func (p *Template) IndexRender(ctx *builder.Context) interface{} {
|
||||
}
|
||||
|
||||
// 表格行内编辑
|
||||
func (p *Template) EditableRender(ctx *builder.Context) interface{} {
|
||||
func (p *Template) EditableRender(ctx *builder.Context) error {
|
||||
return (&requests.EditableRequest{}).Handle(ctx)
|
||||
}
|
||||
|
||||
// 执行行为
|
||||
func (p *Template) ActionRender(ctx *builder.Context) interface{} {
|
||||
func (p *Template) ActionRender(ctx *builder.Context) error {
|
||||
return (&requests.ActionRequest{}).Handle(ctx)
|
||||
}
|
||||
|
||||
// 创建页面渲染
|
||||
func (p *Template) CreationRender(ctx *builder.Context) interface{} {
|
||||
func (p *Template) CreationRender(ctx *builder.Context) error {
|
||||
|
||||
// 断言BeforeCreating方法,获取初始数据
|
||||
data := ctx.Template.(interface {
|
||||
@@ -152,12 +152,12 @@ func (p *Template) CreationRender(ctx *builder.Context) interface{} {
|
||||
}
|
||||
|
||||
// 创建方法
|
||||
func (p *Template) StoreRender(ctx *builder.Context) interface{} {
|
||||
func (p *Template) StoreRender(ctx *builder.Context) error {
|
||||
return (&requests.StoreRequest{}).Handle(ctx)
|
||||
}
|
||||
|
||||
// 编辑页面渲染
|
||||
func (p *Template) EditRender(ctx *builder.Context) interface{} {
|
||||
func (p *Template) EditRender(ctx *builder.Context) error {
|
||||
// 获取数据
|
||||
data := (&requests.EditRequest{}).FillData(ctx)
|
||||
|
||||
@@ -179,17 +179,17 @@ func (p *Template) EditRender(ctx *builder.Context) interface{} {
|
||||
}
|
||||
|
||||
// 获取编辑表单值
|
||||
func (p *Template) EditValuesRender(ctx *builder.Context) interface{} {
|
||||
func (p *Template) EditValuesRender(ctx *builder.Context) error {
|
||||
return (&requests.EditRequest{}).Values(ctx)
|
||||
}
|
||||
|
||||
// 保存编辑值
|
||||
func (p *Template) SaveRender(ctx *builder.Context) interface{} {
|
||||
func (p *Template) SaveRender(ctx *builder.Context) error {
|
||||
return (&requests.UpdateRequest{}).Handle(ctx)
|
||||
}
|
||||
|
||||
// 详情页渲染
|
||||
func (p *Template) DetailRender(ctx *builder.Context) interface{} {
|
||||
func (p *Template) DetailRender(ctx *builder.Context) error {
|
||||
data := (&requests.DetailRequest{}).FillData(ctx)
|
||||
|
||||
// 断言方法,获取初始数据
|
||||
@@ -210,22 +210,22 @@ func (p *Template) DetailRender(ctx *builder.Context) interface{} {
|
||||
}
|
||||
|
||||
// 导出数据
|
||||
func (p *Template) ExportRender(ctx *builder.Context) interface{} {
|
||||
func (p *Template) ExportRender(ctx *builder.Context) error {
|
||||
return (&requests.ExportRequest{}).Handle(ctx)
|
||||
}
|
||||
|
||||
// 导入数据
|
||||
func (p *Template) ImportRender(ctx *builder.Context) interface{} {
|
||||
func (p *Template) ImportRender(ctx *builder.Context) error {
|
||||
return (&requests.ImportRequest{}).Handle(ctx, IndexPath)
|
||||
}
|
||||
|
||||
// 导入数据模板
|
||||
func (p *Template) ImportTemplateRender(ctx *builder.Context) interface{} {
|
||||
func (p *Template) ImportTemplateRender(ctx *builder.Context) error {
|
||||
return (&requests.ImportTemplateRequest{}).Handle(ctx)
|
||||
}
|
||||
|
||||
// 通用表单资源
|
||||
func (p *Template) FormRender(ctx *builder.Context) interface{} {
|
||||
func (p *Template) FormRender(ctx *builder.Context) error {
|
||||
|
||||
// 断言BeforeCreating方法,获取初始数据
|
||||
data := ctx.Template.(interface {
|
||||
|
||||
@@ -117,7 +117,7 @@ func (p *Template) BeforeSaving(ctx *builder.Context, submitData map[string]inte
|
||||
}
|
||||
|
||||
// 保存数据后回调
|
||||
func (p *Template) AfterSaved(ctx *builder.Context, id int, data map[string]interface{}, result *gorm.DB) interface{} {
|
||||
func (p *Template) AfterSaved(ctx *builder.Context, id int, data map[string]interface{}, result *gorm.DB) error {
|
||||
if result.Error != nil {
|
||||
return ctx.JSONError(result.Error.Error())
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/quarkcms/quark-go/pkg/builder"
|
||||
"github.com/quarkcms/quark-go/pkg/builder/template"
|
||||
"github.com/quarkcms/quark-go/pkg/dal/db"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
"github.com/quarkcms/quark-go/pkg/storage"
|
||||
)
|
||||
|
||||
@@ -46,14 +45,14 @@ func (p *Template) TemplateInit() interface{} {
|
||||
p.Driver = storage.LocalDriver
|
||||
|
||||
// 注册路由映射
|
||||
p.POST("/api/admin/upload/:resource/handle", "Handle")
|
||||
p.POST("/api/admin/upload/:resource/base64Handle", "HandleFromBase64")
|
||||
p.POST("/api/admin/upload/:resource/handle", p.Handle)
|
||||
p.POST("/api/admin/upload/:resource/base64Handle", p.HandleFromBase64)
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
// 执行上传
|
||||
func (p *Template) Handle(ctx *builder.Context) interface{} {
|
||||
func (p *Template) Handle(ctx *builder.Context) error {
|
||||
var (
|
||||
result *storage.FileInfo
|
||||
err error
|
||||
@@ -64,10 +63,10 @@ func (p *Template) Handle(ctx *builder.Context) interface{} {
|
||||
|
||||
contentTypes := strings.Split(ctx.Header("Content-Type"), "; ")
|
||||
if len(contentTypes) != 2 {
|
||||
return ctx.JSON(200, msg.Error("Content-Type error", ""))
|
||||
return ctx.JSONError("Content-Type error")
|
||||
}
|
||||
if contentTypes[0] != "multipart/form-data" {
|
||||
return ctx.JSON(200, msg.Error("Content-Type must use multipart/form-data", ""))
|
||||
return ctx.JSONError("Content-Type must use multipart/form-data")
|
||||
}
|
||||
|
||||
limitSize := reflect.
|
||||
@@ -145,11 +144,11 @@ func (p *Template) Handle(ctx *builder.Context) interface{} {
|
||||
BeforeHandle(ctx *builder.Context, fileSystem *storage.FileSystem) (*storage.FileSystem, *storage.FileInfo, error)
|
||||
}).BeforeHandle(ctx, fileSystem)
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
if fileInfo != nil {
|
||||
return ctx.Template.(interface {
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) interface{}
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) error
|
||||
}).AfterHandle(ctx, fileInfo)
|
||||
}
|
||||
|
||||
@@ -159,22 +158,22 @@ func (p *Template) Handle(ctx *builder.Context) interface{} {
|
||||
Path(savePath).
|
||||
Save()
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
return ctx.Template.(interface {
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) interface{}
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) error
|
||||
}).AfterHandle(ctx, result)
|
||||
}
|
||||
|
||||
// 通过Base64执行上传
|
||||
func (p *Template) HandleFromBase64(ctx *builder.Context) interface{} {
|
||||
func (p *Template) HandleFromBase64(ctx *builder.Context) error {
|
||||
var (
|
||||
result *storage.FileInfo
|
||||
err error
|
||||
@@ -185,20 +184,20 @@ func (p *Template) HandleFromBase64(ctx *builder.Context) interface{} {
|
||||
|
||||
data := map[string]interface{}{}
|
||||
if err := ctx.BodyParser(&data); err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
if data["file"] == nil {
|
||||
return ctx.JSON(200, msg.Error("参数错误", ""))
|
||||
return ctx.JSONError("参数错误")
|
||||
}
|
||||
|
||||
files := strings.Split(data["file"].(string), ",")
|
||||
if len(files) != 2 {
|
||||
return ctx.JSON(200, msg.Error("格式错误", ""))
|
||||
return ctx.JSONError("格式错误")
|
||||
}
|
||||
|
||||
fileData, err := base64.StdEncoding.DecodeString(files[1]) //成图片文件并把文件写入到buffer
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
limitSize := reflect.
|
||||
@@ -269,11 +268,11 @@ func (p *Template) HandleFromBase64(ctx *builder.Context) interface{} {
|
||||
BeforeHandle(ctx *builder.Context, fileSystem *storage.FileSystem) (*storage.FileSystem, *storage.FileInfo, error)
|
||||
}).BeforeHandle(ctx, fileSystem)
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
if fileInfo != nil {
|
||||
return ctx.Template.(interface {
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) interface{}
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) error
|
||||
}).AfterHandle(ctx, fileInfo)
|
||||
}
|
||||
|
||||
@@ -284,22 +283,20 @@ func (p *Template) HandleFromBase64(ctx *builder.Context) interface{} {
|
||||
Save()
|
||||
|
||||
if err != nil {
|
||||
return ctx.JSON(200, msg.Error(err.Error(), ""))
|
||||
return ctx.JSONError(err.Error())
|
||||
}
|
||||
|
||||
return ctx.Template.(interface {
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) interface{}
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) error
|
||||
}).AfterHandle(ctx, result)
|
||||
}
|
||||
|
||||
// 上传前回调
|
||||
func (p *Template) BeforeHandle(ctx *builder.Context, fileSystem *storage.FileSystem) (*storage.FileSystem, *storage.FileInfo, error) {
|
||||
|
||||
return fileSystem, nil, nil
|
||||
}
|
||||
|
||||
// 执行上传
|
||||
func (p *Template) AfterHandle(ctx *builder.Context, result *storage.FileInfo) interface{} {
|
||||
|
||||
return ctx.JSON(200, msg.Success("上传成功", "", result))
|
||||
func (p *Template) AfterHandle(ctx *builder.Context, result *storage.FileInfo) error {
|
||||
return ctx.JSONOk("上传成功", "", result)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/quarkcms/quark-go/pkg/builder/template/mixpage"
|
||||
"github.com/quarkcms/quark-go/pkg/component/mix/form"
|
||||
"github.com/quarkcms/quark-go/pkg/dal/db"
|
||||
"github.com/quarkcms/quark-go/pkg/msg"
|
||||
)
|
||||
|
||||
// 后台登录模板
|
||||
@@ -32,8 +31,8 @@ func (p *Template) TemplateInit() interface{} {
|
||||
p.DB = db.Client
|
||||
|
||||
// 注册路由映射
|
||||
p.GET("/api/mix/form/:resource/index", "Render") // 渲染页面路由
|
||||
p.Any("/api/mix/form/:resource/submit", "Handle") // 表单提交路由
|
||||
p.GET("/api/mix/form/:resource/index", p.Render) // 渲染页面路由
|
||||
p.Any("/api/mix/form/:resource/submit", p.Handle) // 表单提交路由
|
||||
|
||||
// 标题
|
||||
p.Title = "QuarkGo"
|
||||
@@ -114,6 +113,6 @@ func (p *Template) Content(ctx *builder.Context) interface{} {
|
||||
}
|
||||
|
||||
// 执行表单
|
||||
func (p *Template) Handle(ctx *builder.Context) interface{} {
|
||||
return ctx.JSON(200, msg.Error("请自行处理表单逻辑", ""))
|
||||
func (p *Template) Handle(ctx *builder.Context) error {
|
||||
return ctx.JSONError("请自行处理表单逻辑")
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func (p *Template) TemplateInit() interface{} {
|
||||
p.DB = db.Client
|
||||
|
||||
// 注册路由映射
|
||||
p.GET("/api/mix/page/:resource/index", "Render") // 渲染页面路由
|
||||
p.GET("/api/mix/page/:resource/index", p.Render) // 渲染页面路由
|
||||
|
||||
// 标题
|
||||
p.Title = "QuarkGo"
|
||||
@@ -76,7 +76,7 @@ func (p *Template) TabBar(ctx *builder.Context) interface{} {
|
||||
}
|
||||
|
||||
// 组件渲染
|
||||
func (p *Template) Render(ctx *builder.Context) interface{} {
|
||||
func (p *Template) Render(ctx *builder.Context) error {
|
||||
var (
|
||||
components []interface{}
|
||||
swiperItems []interface{}
|
||||
|
||||
@@ -20,10 +20,10 @@ func (p *Template) GetRouteMapping() []*builder.RouteMapping {
|
||||
}
|
||||
|
||||
// 是否存在路由
|
||||
func (p *Template) hasRouteMapping(method string, path string, handlerName string) bool {
|
||||
func (p *Template) hasRouteMapping(method string, path string, handler func(ctx *builder.Context) error) bool {
|
||||
has := false
|
||||
for _, v := range p.RouteMapping {
|
||||
if v.Method == method && v.Path == path && v.HandlerName == handlerName {
|
||||
if v.Method == method && v.Path == path {
|
||||
has = true
|
||||
}
|
||||
}
|
||||
@@ -31,12 +31,12 @@ func (p *Template) hasRouteMapping(method string, path string, handlerName strin
|
||||
}
|
||||
|
||||
// 注册路由
|
||||
func (p *Template) AddRouteMapping(method string, path string, handlerName string) *Template {
|
||||
if !p.hasRouteMapping(method, path, handlerName) {
|
||||
func (p *Template) AddRouteMapping(method string, path string, handler func(ctx *builder.Context) error) *Template {
|
||||
if !p.hasRouteMapping(method, path, handler) {
|
||||
getRoute := &builder.RouteMapping{
|
||||
Method: method,
|
||||
Path: path,
|
||||
HandlerName: handlerName,
|
||||
Handler: handler,
|
||||
}
|
||||
|
||||
p.RouteMapping = append(p.RouteMapping, getRoute)
|
||||
@@ -45,43 +45,43 @@ func (p *Template) AddRouteMapping(method string, path string, handlerName strin
|
||||
}
|
||||
|
||||
// ANY请求
|
||||
func (p *Template) Any(path string, handlerName string) {
|
||||
p.AddRouteMapping("Any", path, handlerName)
|
||||
func (p *Template) Any(path string, handler func(ctx *builder.Context) error) {
|
||||
p.AddRouteMapping("Any", path, handler)
|
||||
}
|
||||
|
||||
// GET请求
|
||||
func (p *Template) GET(path string, handlerName string) {
|
||||
p.AddRouteMapping(http.MethodGet, path, handlerName)
|
||||
func (p *Template) GET(path string, handler func(ctx *builder.Context) error) {
|
||||
p.AddRouteMapping(http.MethodGet, path, handler)
|
||||
}
|
||||
|
||||
// HEAD请求
|
||||
func (p *Template) HEAD(path string, handlerName string) {
|
||||
p.AddRouteMapping(http.MethodHead, path, handlerName)
|
||||
func (p *Template) HEAD(path string, handler func(ctx *builder.Context) error) {
|
||||
p.AddRouteMapping(http.MethodHead, path, handler)
|
||||
}
|
||||
|
||||
// OPTIONS请求
|
||||
func (p *Template) OPTIONS(path string, handlerName string) {
|
||||
p.AddRouteMapping(http.MethodOptions, path, handlerName)
|
||||
func (p *Template) OPTIONS(path string, handler func(ctx *builder.Context) error) {
|
||||
p.AddRouteMapping(http.MethodOptions, path, handler)
|
||||
}
|
||||
|
||||
// POST请求
|
||||
func (p *Template) POST(path string, handlerName string) {
|
||||
p.AddRouteMapping(http.MethodPost, path, handlerName)
|
||||
func (p *Template) POST(path string, handler func(ctx *builder.Context) error) {
|
||||
p.AddRouteMapping(http.MethodPost, path, handler)
|
||||
}
|
||||
|
||||
// PUT请求
|
||||
func (p *Template) PUT(path string, handlerName string) {
|
||||
p.AddRouteMapping(http.MethodPut, path, handlerName)
|
||||
func (p *Template) PUT(path string, handler func(ctx *builder.Context) error) {
|
||||
p.AddRouteMapping(http.MethodPut, path, handler)
|
||||
}
|
||||
|
||||
// PATCH请求
|
||||
func (p *Template) PATCH(path string, handlerName string) {
|
||||
p.AddRouteMapping(http.MethodPatch, path, handlerName)
|
||||
func (p *Template) PATCH(path string, handler func(ctx *builder.Context) error) {
|
||||
p.AddRouteMapping(http.MethodPatch, path, handler)
|
||||
}
|
||||
|
||||
// DELETE请求
|
||||
func (p *Template) DELETE(path string, handlerName string) {
|
||||
p.AddRouteMapping(http.MethodDelete, path, handlerName)
|
||||
func (p *Template) DELETE(path string, handler func(ctx *builder.Context) error) {
|
||||
p.AddRouteMapping(http.MethodDelete, path, handler)
|
||||
}
|
||||
|
||||
// 默认组件渲染
|
||||
|
||||
@@ -46,16 +46,16 @@ func (p *Template) TemplateInit() interface{} {
|
||||
p.Driver = storage.LocalDriver
|
||||
|
||||
// 注册路由映射
|
||||
p.POST("/api/tool/upload/:resource/handle", "Handle")
|
||||
p.POST("/api/tool/upload/:resource/base64Handle", "HandleFromBase64")
|
||||
p.POST("/api/upload/:resource/handle", "Handle")
|
||||
p.POST("/api/upload/:resource/base64Handle", "HandleFromBase64")
|
||||
p.POST("/api/tool/upload/:resource/handle", p.Handle)
|
||||
p.POST("/api/tool/upload/:resource/base64Handle", p.HandleFromBase64)
|
||||
p.POST("/api/upload/:resource/handle", p.Handle)
|
||||
p.POST("/api/upload/:resource/base64Handle", p.HandleFromBase64)
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
// 执行上传
|
||||
func (p *Template) Handle(ctx *builder.Context) interface{} {
|
||||
func (p *Template) Handle(ctx *builder.Context) error {
|
||||
var (
|
||||
result *storage.FileInfo
|
||||
err error
|
||||
@@ -151,7 +151,7 @@ func (p *Template) Handle(ctx *builder.Context) interface{} {
|
||||
}
|
||||
if fileInfo != nil {
|
||||
return ctx.Template.(interface {
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) interface{}
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) error
|
||||
}).AfterHandle(ctx, fileInfo)
|
||||
}
|
||||
|
||||
@@ -171,12 +171,12 @@ func (p *Template) Handle(ctx *builder.Context) interface{} {
|
||||
}
|
||||
|
||||
return ctx.Template.(interface {
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) interface{}
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) error
|
||||
}).AfterHandle(ctx, result)
|
||||
}
|
||||
|
||||
// 通过Base64执行上传
|
||||
func (p *Template) HandleFromBase64(ctx *builder.Context) interface{} {
|
||||
func (p *Template) HandleFromBase64(ctx *builder.Context) error {
|
||||
var (
|
||||
result *storage.FileInfo
|
||||
err error
|
||||
@@ -275,7 +275,7 @@ func (p *Template) HandleFromBase64(ctx *builder.Context) interface{} {
|
||||
}
|
||||
if fileInfo != nil {
|
||||
return ctx.Template.(interface {
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) interface{}
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) error
|
||||
}).AfterHandle(ctx, fileInfo)
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ func (p *Template) HandleFromBase64(ctx *builder.Context) interface{} {
|
||||
}
|
||||
|
||||
return ctx.Template.(interface {
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) interface{}
|
||||
AfterHandle(ctx *builder.Context, result *storage.FileInfo) error
|
||||
}).AfterHandle(ctx, result)
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ func (p *Template) BeforeHandle(ctx *builder.Context, fileSystem *storage.FileSy
|
||||
}
|
||||
|
||||
// 执行上传
|
||||
func (p *Template) AfterHandle(ctx *builder.Context, result *storage.FileInfo) interface{} {
|
||||
func (p *Template) AfterHandle(ctx *builder.Context, result *storage.FileInfo) error {
|
||||
|
||||
return ctx.JSON(200, msg.Success("上传成功", "", result))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user