Skip to content

Commit f55cc6d

Browse files
committed
chore: 优化代码
1 parent 055013c commit f55cc6d

File tree

5 files changed

+50
-28
lines changed

5 files changed

+50
-28
lines changed

app/admin/uploads/image.go

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/quarkcloudio/quark-go/v3"
12+
"github.com/quarkcloudio/quark-go/v3/dto/request"
1213
"github.com/quarkcloudio/quark-go/v3/dto/response"
1314
"github.com/quarkcloudio/quark-go/v3/model"
1415
"github.com/quarkcloudio/quark-go/v3/service"
@@ -52,50 +53,50 @@ func (p *Image) RouteInit() interface{} {
5253

5354
// 获取文件列表
5455
func (p *Image) GetList(ctx *quark.Context) error {
55-
page := ctx.Query("page", "1")
56-
categoryId := ctx.Query("categoryId", "")
57-
name := ctx.Query("name", "")
58-
startDate := ctx.Query("createtime[0]", "")
59-
endDate := ctx.Query("createtime[1]", "")
60-
currentPage, _ := strconv.Atoi(page.(string))
56+
imageListReq := request.ImageListReq{}
57+
err := ctx.Bind(&imageListReq)
58+
if err != nil {
59+
return ctx.CJSONError("参数错误")
60+
}
6161

6262
adminInfo, _ := service.NewAuthService(ctx).GetAdmin()
6363
pictures, total, err := service.NewAttachmentService().GetListBySearch(
6464
adminInfo.Id,
6565
"IMAGE",
66-
categoryId,
67-
name,
68-
startDate,
69-
endDate,
70-
currentPage,
66+
imageListReq.CategoryId,
67+
imageListReq.Name,
68+
imageListReq.Createtime[0],
69+
imageListReq.Createtime[1],
70+
imageListReq.Page,
7171
)
7272
if err != nil {
7373
return ctx.CJSONError(err.Error())
7474
}
7575

76-
pagination := map[string]interface{}{
77-
"defaultCurrent": 1,
78-
"current": currentPage,
79-
"pageSize": 8,
80-
"total": total,
81-
}
82-
8376
categorys, err := service.NewAttachmentCategoryService().GetList(adminInfo.Id)
8477
if err != nil {
8578
return ctx.CJSONError(err.Error())
8679
}
8780

88-
return ctx.CJSONOk("获取成功", map[string]interface{}{
89-
"pagination": pagination,
90-
"lists": pictures,
91-
"categorys": categorys,
81+
return ctx.CJSONOk("获取成功", response.ImageListResp{
82+
Pagination: response.Pagination{
83+
Current: imageListReq.Page,
84+
DefaultCurrent: 1,
85+
PageSize: 8,
86+
Total: total,
87+
},
88+
List: pictures,
89+
Categorys: categorys,
9290
})
9391
}
9492

9593
// 图片删除
9694
func (p *Image) Delete(ctx *quark.Context) error {
9795
data := map[string]interface{}{}
98-
json.Unmarshal(ctx.Body(), &data)
96+
if err := ctx.BodyParser(&data); err != nil {
97+
return ctx.CJSONError("参数错误")
98+
}
99+
99100
if data["id"] == "" {
100101
return ctx.CJSONError("参数错误")
101102
}
@@ -127,9 +128,6 @@ func (p *Image) Crop(ctx *quark.Context) error {
127128
if err != nil {
128129
return ctx.CJSONError(err.Error())
129130
}
130-
if pictureInfo.Id == 0 {
131-
return ctx.CJSONError("文件不存在")
132-
}
133131

134132
adminInfo, err := service.NewAuthService(ctx).GetAdmin()
135133
if err != nil {

dto/request/upload.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package request
2+
3+
// 获取图片列表请求
4+
type ImageListReq struct {
5+
Page int `query:"page"`
6+
CategoryId int `query:"categoryId"`
7+
Name string `query:"name"`
8+
Createtime []string `query:"createtime"`
9+
}

dto/response/upload.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,18 @@ type UploadResp struct {
1212
Url string `json:"url"`
1313
Extra interface{} `json:"extra"`
1414
}
15+
16+
// 获取图片列表请求
17+
type Pagination struct {
18+
DefaultCurrent int `json:"defaultCurrent"`
19+
Current interface{} `json:"current"`
20+
PageSize int `json:"pageSize"`
21+
Total interface{} `json:"total"`
22+
}
23+
24+
// 获取图片列表请求
25+
type ImageListResp struct {
26+
Pagination Pagination `json:"pagination"`
27+
List interface{} `json:"list"`
28+
Categorys interface{} `json:"categorys"`
29+
}

engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
AppName = "QuarkGo"
2323

2424
// 版本号
25-
Version = "3.8.8"
25+
Version = "3.8.9"
2626

2727
// 包名
2828
PkgName = "github.com/quarkcloudio/quark-go/v3"

web/app/admin/693.async.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)