fix 修复导出excel受详情页字段影响空白,代码生成自动格式化
This commit is contained in:
parent
361bc546c6
commit
93334da6f2
3
go.mod
3
go.mod
@ -18,6 +18,7 @@ require (
|
|||||||
github.com/tiger1103/gfast-cache v1.0.0
|
github.com/tiger1103/gfast-cache v1.0.0
|
||||||
github.com/tiger1103/gfast-token v1.0.3
|
github.com/tiger1103/gfast-token v1.0.3
|
||||||
github.com/xuri/excelize/v2 v2.7.1
|
github.com/xuri/excelize/v2 v2.7.1
|
||||||
|
golang.org/x/tools v0.6.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@ -78,12 +79,12 @@ require (
|
|||||||
golang.org/x/crypto v0.12.0 // indirect
|
golang.org/x/crypto v0.12.0 // indirect
|
||||||
golang.org/x/image v0.5.0 // indirect
|
golang.org/x/image v0.5.0 // indirect
|
||||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de // indirect
|
golang.org/x/lint v0.0.0-20190930215403-16217165b5de // indirect
|
||||||
|
golang.org/x/mod v0.8.0 // indirect
|
||||||
golang.org/x/net v0.14.0 // indirect
|
golang.org/x/net v0.14.0 // indirect
|
||||||
golang.org/x/sync v0.1.0 // indirect
|
golang.org/x/sync v0.1.0 // indirect
|
||||||
golang.org/x/sys v0.11.0 // indirect
|
golang.org/x/sys v0.11.0 // indirect
|
||||||
golang.org/x/term v0.11.0 // indirect
|
golang.org/x/term v0.11.0 // indirect
|
||||||
golang.org/x/text v0.12.0 // indirect
|
golang.org/x/text v0.12.0 // indirect
|
||||||
golang.org/x/tools v0.6.0 // indirect
|
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
@ -32,6 +32,7 @@ import (
|
|||||||
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
|
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
|
||||||
"github.com/tiger1103/gfast/v3/internal/app/system/service"
|
"github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||||
|
"golang.org/x/tools/imports"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -1154,6 +1155,7 @@ func (s *sToolsGenTable) createFile(fileName, data string, cover bool) (err erro
|
|||||||
f.WriteString(data)
|
f.WriteString(data)
|
||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
|
err = s.goFmt(fileName)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1315,3 +1317,29 @@ func (s *sToolsGenTable) SyncTable(ctx context.Context, tableId int64) (err erro
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// goFmt formats the source file and adds or removes import statements as necessary.
|
||||||
|
func (s *sToolsGenTable) goFmt(path string)(err error) {
|
||||||
|
replaceFunc := func(path, content string) string {
|
||||||
|
res, err := imports.Process(path, []byte(content), nil)
|
||||||
|
if err != nil {
|
||||||
|
g.Log().Printf(context.Background(),`error format "%s" go files: %v`, path, err)
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
return string(res)
|
||||||
|
}
|
||||||
|
if gfile.IsFile(path) {
|
||||||
|
// File format.
|
||||||
|
if gfile.ExtName(path) != "go" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = gfile.ReplaceFileFunc(replaceFunc, path)
|
||||||
|
} else {
|
||||||
|
// Folder format.
|
||||||
|
err = gfile.ReplaceDirFunc(replaceFunc, path, "*.go", true)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf(`error format "%s" go files: %v`, path, err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -8,5 +8,5 @@
|
|||||||
package consts
|
package consts
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "3.2.6"
|
Version = "3.2.7"
|
||||||
)
|
)
|
||||||
|
@ -21,7 +21,8 @@ package controller
|
|||||||
{{$hasGconv:=false}}
|
{{$hasGconv:=false}}
|
||||||
{{$hasSystemApi:=false}}
|
{{$hasSystemApi:=false}}
|
||||||
{{$hasCommonService:=false}}
|
{{$hasCommonService:=false}}
|
||||||
{{range $index, $column := .table.DetailColumns}}
|
{{if .table.ExcelPort}}
|
||||||
|
{{range $index, $column := .table.Columns}}
|
||||||
{{if ne $column.DictType ""}}
|
{{if ne $column.DictType ""}}
|
||||||
{{$hasGmap = true}}
|
{{$hasGmap = true}}
|
||||||
{{$hasGconv = true}}
|
{{$hasGconv = true}}
|
||||||
@ -36,6 +37,7 @@ package controller
|
|||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{end}}
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"{{.goModName}}/api/v1/{{.table.ModuleName}}"
|
"{{.goModName}}/api/v1/{{.table.ModuleName}}"
|
||||||
@ -101,7 +103,7 @@ func (c *{{$structName}}Controller) Export(ctx context.Context, req *{{.table.Mo
|
|||||||
listData []*model.{{.table.ClassName}}InfoRes
|
listData []*model.{{.table.ClassName}}InfoRes
|
||||||
//表头
|
//表头
|
||||||
{{$tableHeader := ""}}
|
{{$tableHeader := ""}}
|
||||||
{{range $index, $column := .table.DetailColumns}}
|
{{range $index, $column := .table.Columns}}
|
||||||
{{if and (ne $column.HtmlType "richtext") (ne $column.HtmlType "imagefile") (ne $column.HtmlType "images") (ne $column.HtmlType "file") (ne $column.HtmlType "files")}}
|
{{if and (ne $column.HtmlType "richtext") (ne $column.HtmlType "imagefile") (ne $column.HtmlType "images") (ne $column.HtmlType "file") (ne $column.HtmlType "files")}}
|
||||||
{{$tableHeader = concat $tableHeader `"` $column.ColumnComment `"` "," }}
|
{{$tableHeader = concat $tableHeader `"` $column.ColumnComment `"` "," }}
|
||||||
{{end}}
|
{{end}}
|
||||||
@ -149,7 +151,7 @@ func (c *{{$structName}}Controller) Export(ctx context.Context, req *{{.table.Mo
|
|||||||
}
|
}
|
||||||
for _,v:=range listData{
|
for _,v:=range listData{
|
||||||
var (
|
var (
|
||||||
{{range $index, $column := .table.DetailColumns}}
|
{{range $index, $column := .table.Columns}}
|
||||||
{{if and (ne $column.HtmlType "richtext") (ne $column.HtmlType "imagefile") (ne $column.HtmlType "images") (ne $column.HtmlType "file") (ne $column.HtmlType "files")}}
|
{{if and (ne $column.HtmlType "richtext") (ne $column.HtmlType "imagefile") (ne $column.HtmlType "images") (ne $column.HtmlType "file") (ne $column.HtmlType "files")}}
|
||||||
{{if or (ne $column.DictType "") (ne $column.LinkTableName "")}}
|
{{if or (ne $column.DictType "") (ne $column.LinkTableName "")}}
|
||||||
{{if eq $column.HtmlType "checkbox" "" "selects" "treeSelects"}}
|
{{if eq $column.HtmlType "checkbox" "" "selects" "treeSelects"}}
|
||||||
@ -173,7 +175,7 @@ func (c *{{$structName}}Controller) Export(ctx context.Context, req *{{.table.Mo
|
|||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
)
|
)
|
||||||
{{range $index, $column := .table.DetailColumns}}
|
{{range $index, $column := .table.Columns}}
|
||||||
{{if and (ne $column.HtmlType "richtext") (ne $column.HtmlType "imagefile") (ne $column.HtmlType "images") (ne $column.HtmlType "file") (ne $column.HtmlType "files")}}
|
{{if and (ne $column.HtmlType "richtext") (ne $column.HtmlType "imagefile") (ne $column.HtmlType "images") (ne $column.HtmlType "file") (ne $column.HtmlType "files")}}
|
||||||
{{if ne $column.DictType ""}}
|
{{if ne $column.DictType ""}}
|
||||||
{{if eq $column.HtmlType "checkbox" "" "selects" "treeSelects"}}
|
{{if eq $column.HtmlType "checkbox" "" "selects" "treeSelects"}}
|
||||||
@ -213,7 +215,7 @@ func (c *{{$structName}}Controller) Export(ctx context.Context, req *{{.table.Mo
|
|||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
dt := []interface{}{
|
dt := []interface{}{
|
||||||
{{range $index, $column := .table.DetailColumns}}
|
{{range $index, $column := .table.Columns}}
|
||||||
{{if and (ne $column.HtmlType "richtext") (ne $column.HtmlType "imagefile") (ne $column.HtmlType "images") (ne $column.HtmlType "file") (ne $column.HtmlType "files")}}
|
{{if and (ne $column.HtmlType "richtext") (ne $column.HtmlType "imagefile") (ne $column.HtmlType "images") (ne $column.HtmlType "file") (ne $column.HtmlType "files")}}
|
||||||
{{if ne $column.DictType ""}}
|
{{if ne $column.DictType ""}}
|
||||||
{{if eq $column.HtmlType "checkbox" "" "selects" "treeSelects"}}
|
{{if eq $column.HtmlType "checkbox" "" "selects" "treeSelects"}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user