Skip to content

Commit

Permalink
feat: 优化query
Browse files Browse the repository at this point in the history
  • Loading branch information
2637309949 committed Mar 19, 2021
1 parent 5bf6a6a commit f7c75ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion platform/app/app.ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ func (ctx *Context) SuccessWithExcel(cfg ExcelConfig) {
if ctx.QueryString("__columns__") != "" {
cstr := ctx.QueryString("__columns__")
columns := []map[string]interface{}{}
json.Unmarshal([]byte(cstr), &columns)
err := json.Unmarshal([]byte(cstr), &columns)
if err != nil {
logrus.Error(err)
}
cfg.Header = columns
}
excelInfo, err := BuildExcel(cfg)
Expand Down
14 changes: 9 additions & 5 deletions platform/app/app.query.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,12 @@ func (q *Query) SetRule(rules ...string) {
}

// SetUser defined
func (q *Query) SetUser() {
q.m["uid"] = q.ctx.GetToken().GetUserID()
func (q *Query) SetUser(uid ...string) {
if len(uid) > 0 {
q.m["uid"] = uid[0]
} else {
q.m["uid"] = q.ctx.GetToken().GetUserID()
}
}

// GetUser defined
Expand Down Expand Up @@ -318,7 +322,7 @@ func (q *Query) Unescaped(s string) template.HTML {
}

// SetTags defined
func (q *Query) SetTags(tags ...struct {
func (q *Query) SetTags(params ...struct {
Key string
Value string
}) {
Expand All @@ -328,8 +332,8 @@ func (q *Query) SetTags(tags ...struct {
q.SetString("lte", q.Unescaped("<="))
q.SetString("gt", q.Unescaped(">"))
q.SetString("gte", q.Unescaped(">="))
for i := range tags {
q.SetString(tags[i].Key, tags[i].Value)
for i := range params {
q.SetString(params[i].Key, params[i].Value)
}
}

Expand Down

0 comments on commit f7c75ab

Please sign in to comment.