Skip to content

Commit f7dd19d

Browse files
committed
feat: 新增批量、单条数据导出行为
1 parent d38506f commit f7dd19d

File tree

10 files changed

+134
-12
lines changed

10 files changed

+134
-12
lines changed

app/admin/actions/batch_export.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package actions
2+
3+
import (
4+
"strings"
5+
6+
"github.com/quarkcloudio/quark-go/v3"
7+
"github.com/quarkcloudio/quark-go/v3/template/admin/resource/actions"
8+
)
9+
10+
type BatchExportAction struct {
11+
actions.Link
12+
}
13+
14+
// 批量导出,BatchExport() | BatchExport("批量导出")
15+
func BatchExport(options ...interface{}) *BatchExportAction {
16+
action := &BatchExportAction{}
17+
18+
action.Name = "批量导出"
19+
if len(options) == 1 {
20+
action.Name = options[0].(string)
21+
}
22+
23+
return action
24+
}
25+
26+
// 初始化
27+
func (p *BatchExportAction) Init(ctx *quark.Context) interface{} {
28+
29+
// 设置按钮类型,primary | ghost | dashed | link | text | default
30+
p.Type = "link"
31+
32+
// 设置按钮大小,large | middle | small | default
33+
p.Size = "small"
34+
35+
// 执行成功后刷新的组件
36+
p.Reload = "table"
37+
38+
// 设置按钮跳转链接
39+
p.Target = "_blank"
40+
41+
// 当行为在表格行展示时,支持js表达式
42+
p.WithConfirm("确定要导出数据吗?", "导出数据可能会等待时间较长!", "modal")
43+
44+
// 在表格多选弹出层展示
45+
p.SetOnlyOnIndexTableAlert(true)
46+
47+
return p
48+
}
49+
50+
// 跳转链接
51+
func (p *BatchExportAction) GetHref(ctx *quark.Context) string {
52+
return strings.Replace(ctx.Path(), "/index", "/export?id=${id}&token="+ctx.Token(), -1)
53+
}

app/admin/actions/export.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package actions
2+
3+
import (
4+
"strings"
5+
6+
"github.com/quarkcloudio/quark-go/v3"
7+
"github.com/quarkcloudio/quark-go/v3/template/admin/resource/actions"
8+
)
9+
10+
type ExportAction struct {
11+
actions.Link
12+
}
13+
14+
// 导出-跳转类型,Export() | Export("导出")
15+
func Export(options ...interface{}) *ExportAction {
16+
action := &ExportAction{}
17+
18+
// 文字
19+
action.Name = "导出"
20+
if len(options) == 1 {
21+
action.Name = options[0].(string)
22+
}
23+
24+
return action
25+
}
26+
27+
// 初始化
28+
func (p *ExportAction) Init(ctx *quark.Context) interface{} {
29+
30+
// 设置按钮类型,primary | ghost | dashed | link | text | default
31+
p.Type = "link"
32+
33+
// 设置按钮大小,large | middle | small | default
34+
p.Size = "small"
35+
36+
// 设置按钮跳转链接
37+
p.Target = "_blank"
38+
39+
// 设置展示位置
40+
p.SetOnlyOnIndexTableRow(true)
41+
42+
return p
43+
}
44+
45+
// 跳转链接
46+
func (p *ExportAction) GetHref(ctx *quark.Context) string {
47+
return strings.Replace(ctx.Path(), "/index", "/export?id=${id}&token="+ctx.Token(), -1)
48+
}

app/admin/resources/action_log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (p *ActionLog) Init(ctx *quark.Context) interface{} {
2828
p.PageSize = 10
2929

3030
// 是否具有导出功能
31-
p.WithExport = true
31+
p.Export = true
3232

3333
return p
3434
}

app/admin/resources/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (p *User) Init(ctx *quark.Context) interface{} {
4141
p.PageSize = 10
4242

4343
// 是否具有导出功能
44-
p.WithExport = true
44+
p.Export = true
4545

4646
return p
4747
}

engine.go

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

2525
// 版本号
26-
Version = "3.8.15"
26+
Version = "3.9.0"
2727

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

i18n/.gitkeep

Whitespace-only changes.

template/admin/resource/performs_queries.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@ func (p *Template) EditableQuery(ctx *quark.Context, query *gorm.DB) *gorm.DB {
273273

274274
// 导出查询
275275
func (p *Template) ExportQuery(ctx *quark.Context, query *gorm.DB) *gorm.DB {
276+
id := ctx.Query("id", "")
277+
if id != "" {
278+
if strings.Contains(id.(string), ",") {
279+
query.Where("id IN ?", strings.Split(id.(string), ","))
280+
} else {
281+
query.Where("id = ?", id)
282+
}
283+
}
276284

277285
return query
278286
}

template/admin/resource/resolves_searches.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ func (p *Template) IndexSearches(ctx *quark.Context) interface{} {
2525
search := template.GetTableSearch(ctx)
2626

2727
// 是否携带导出功能
28-
withExport := template.GetWithExport()
29-
if withExport {
28+
export := template.GetExport()
29+
if export {
30+
exportText := template.GetExportText() // 导出按钮文字内容
3031
search = search.
31-
SetExportText("导出").
32+
SetExportText(exportText).
3233
SetExportApi(strings.Replace(ExportPath, ":resource", ctx.Param("resource"), -1))
3334
}
3435

template/admin/resource/resource.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ type Template struct {
4646
TableActionColumnWidth int // 列表页表格行为列的宽度
4747
TablePolling int // 列表页表格是否轮询数据
4848
TableListToTree interface{} // 列表页数据转换为树形结构, true 或者 map[string]interface{}{"pkName": "id",""pidName": "pid","childrenName": "children","rootId":0}
49+
Export bool // 列表是否具有导出功能
50+
ExportText string // 列表导出按钮文字内容
4951
PageSize interface{} // 列表页分页配置
5052
PageSizeOptions []int // 指定每页可以显示多少条,[10, 20, 50, 100]
5153
QueryOrder string // 全局排序规则
5254
IndexQueryOrder string // 列表页排序规则
5355
ExportQueryOrder string // 导出数据排序规则
5456
Model interface{} // 挂载模型
55-
WithExport bool // 是否具有导出功能
5657
}
5758

5859
// 初始化
@@ -90,6 +91,9 @@ func (p *Template) TemplateInit(ctx *quark.Context) interface{} {
9091
// 列表页表格标题后缀
9192
p.TableTitleSuffix = "列表"
9293

94+
// 列表导出按钮文字内容
95+
p.ExportText = "导出"
96+
9397
// 页面是否携带返回Icon
9498
p.BackIcon = true
9599

@@ -223,8 +227,13 @@ func (p *Template) GetExportQueryOrder() string {
223227
}
224228

225229
// 获取是否具有导出功能
226-
func (p *Template) GetWithExport() bool {
227-
return p.WithExport
230+
func (p *Template) GetExport() bool {
231+
return p.Export
232+
}
233+
234+
// 获取导出按钮文字内容
235+
func (p *Template) GetExportText() string {
236+
return p.ExportText
228237
}
229238

230239
// 字段

template/admin/resource/types/resourcer.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ type Resourcer interface {
5757
// 列表页列表数据转换为树形结构
5858
GetTableListToTree() interface{}
5959

60+
// 获取是否具有导出功能
61+
GetExport() bool
62+
63+
// 获取导出按钮文字内容
64+
GetExportText() string
65+
6066
// 获取分页配置
6167
GetPageSize() interface{}
6268

@@ -72,9 +78,6 @@ type Resourcer interface {
7278
// 获取导出数据排序规则
7379
GetExportQueryOrder() string
7480

75-
// 获取是否具有导出功能
76-
GetWithExport() bool
77-
7881
// 数据导出前回调
7982
BeforeExporting(ctx *quark.Context, list []map[string]interface{}) []interface{}
8083

0 commit comments

Comments
 (0)