diff --git a/server/api/v1/system/sys_user.go b/server/api/v1/system/sys_user.go index d228d217..e531bf3f 100644 --- a/server/api/v1/system/sys_user.go +++ b/server/api/v1/system/sys_user.go @@ -467,13 +467,13 @@ func (b *BaseApi) GetUserInfo(c *gin.Context) { // @Success 200 {object} response.Response{msg=string} "重置用户密码" // @Router /user/resetPassword [post] func (b *BaseApi) ResetPassword(c *gin.Context) { - var user system.SysUser - err := c.ShouldBindJSON(&user) + var rps systemReq.ResetPassword + err := c.ShouldBindJSON(&rps) if err != nil { response.FailWithMessage(err.Error(), c) return } - err = userService.ResetPassword(user.ID) + err = userService.ResetPassword(rps.ID, rps.Password) if err != nil { global.GVA_LOG.Error("重置失败!", zap.Error(err)) response.FailWithMessage("重置失败"+err.Error(), c) diff --git a/server/core/viper.go b/server/core/viper.go index 0f3c23af..d846c906 100644 --- a/server/core/viper.go +++ b/server/core/viper.go @@ -3,55 +3,26 @@ package core import ( "flag" "fmt" - "github.com/flipped-aurora/gin-vue-admin/server/core/internal" - "github.com/gin-gonic/gin" "os" "path/filepath" - "github.com/fsnotify/fsnotify" - "github.com/spf13/viper" - + "github.com/flipped-aurora/gin-vue-admin/server/core/internal" "github.com/flipped-aurora/gin-vue-admin/server/global" + "github.com/fsnotify/fsnotify" + "github.com/gin-gonic/gin" + "github.com/spf13/viper" ) -// Viper // -// 优先级: 命令行 > 环境变量 > 默认值 -// Author [SliverHorn](https://github.com/SliverHorn) -func Viper(path ...string) *viper.Viper { - var config string - - if len(path) == 0 { - flag.StringVar(&config, "c", "", "choose config file.") - flag.Parse() - if config == "" { // 判断命令行参数是否为空 - if configEnv := os.Getenv(internal.ConfigEnv); configEnv == "" { // 判断 internal.ConfigEnv 常量存储的环境变量是否为空 - switch gin.Mode() { - case gin.DebugMode: - config = internal.ConfigDefaultFile - case gin.ReleaseMode: - config = internal.ConfigReleaseFile - case gin.TestMode: - config = internal.ConfigTestFile - } - fmt.Printf("您正在使用gin模式的%s环境名称,config的路径为%s\n", gin.Mode(), config) - } else { // internal.ConfigEnv 常量存储的环境变量不为空 将值赋值于config - config = configEnv - fmt.Printf("您正在使用%s环境变量,config的路径为%s\n", internal.ConfigEnv, config) - } - } else { // 命令行参数不为空 将值赋值于config - fmt.Printf("您正在使用命令行的-c参数传递的值,config的路径为%s\n", config) - } - } else { // 函数传递的可变参数的第一个值赋值于config - config = path[0] - fmt.Printf("您正在使用func Viper()传递的值,config的路径为%s\n", config) - } +// Viper 配置 +func Viper() *viper.Viper { + config := getConfigPath() v := viper.New() v.SetConfigFile(config) v.SetConfigType("yaml") err := v.ReadInConfig() if err != nil { - panic(fmt.Errorf("Fatal error config file: %s \n", err)) + panic(fmt.Errorf("fatal error config file: %w", err)) } v.WatchConfig() @@ -62,10 +33,44 @@ func Viper(path ...string) *viper.Viper { } }) if err = v.Unmarshal(&global.GVA_CONFIG); err != nil { - panic(err) + panic(fmt.Errorf("fatal error unmarshal config: %w", err)) } // root 适配性 根据root位置去找到对应迁移位置,保证root路径有效 global.GVA_CONFIG.AutoCode.Root, _ = filepath.Abs("..") return v } + +// getConfigPath 获取配置文件路径, 优先级: 命令行 > 环境变量 > 默认值 +func getConfigPath() (config string) { + // `-c` flag parse + flag.StringVar(&config, "c", "", "choose config file.") + flag.Parse() + if config != "" { // 命令行参数不为空 将值赋值于config + fmt.Printf("您正在使用命令行的 '-c' 参数传递的值, config 的路径为 %s\n", config) + return + } + if env := os.Getenv(internal.ConfigEnv); env != "" { // 判断环境变量 GVA_CONFIG + config = env + fmt.Printf("您正在使用 %s 环境变量, config 的路径为 %s\n", internal.ConfigEnv, config) + return + } + + switch gin.Mode() { // 根据 gin 模式文件名 + case gin.DebugMode: + config = internal.ConfigDebugFile + case gin.ReleaseMode: + config = internal.ConfigReleaseFile + case gin.TestMode: + config = internal.ConfigTestFile + } + fmt.Printf("您正在使用 gin 的 %s 模式运行, config 的路径为 %s\n", gin.Mode(), config) + + _, err := os.Stat(config) + if err != nil || os.IsNotExist(err) { + config = internal.ConfigDefaultFile + fmt.Printf("配置文件路径不存在, 使用默认配置文件路径: %s\n", config) + } + + return +} diff --git a/server/go.mod b/server/go.mod index 029629aa..157477a2 100644 --- a/server/go.mod +++ b/server/go.mod @@ -13,7 +13,7 @@ require ( github.com/glebarez/sqlite v1.11.0 github.com/go-sql-driver/mysql v1.8.1 github.com/goccy/go-json v0.10.4 - github.com/golang-jwt/jwt/v5 v5.2.1 + github.com/golang-jwt/jwt/v5 v5.2.2 github.com/google/uuid v1.6.0 github.com/gookit/color v1.5.4 github.com/huaweicloud/huaweicloud-sdk-go-obs v3.24.9+incompatible diff --git a/server/go.sum b/server/go.sum index 19b5e7f0..403ba707 100644 --- a/server/go.sum +++ b/server/go.sum @@ -167,12 +167,11 @@ github.com/goccy/go-json v0.10.4/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PU github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= -github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo= -github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= -github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8= +github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA= github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A= diff --git a/server/initialize/router.go b/server/initialize/router.go index c9a61020..c3dfe1eb 100644 --- a/server/initialize/router.go +++ b/server/initialize/router.go @@ -46,7 +46,7 @@ func Routers() *gin.Engine { // VUE_APP_BASE_API = / // VUE_APP_BASE_PATH = http://localhost // 然后执行打包命令 npm run build。在打开下面3行注释 - // Router.Static("/favicon.ico", "./dist/favicon.ico") + // Router.StaticFile("/favicon.ico", "./dist/favicon.ico") // Router.Static("/assets", "./dist/assets") // dist里面的静态资源 // Router.StaticFile("/", "./dist/index.html") // 前端网页入口页面 diff --git a/server/model/system/request/sys_user.go b/server/model/system/request/sys_user.go index 45e47876..a48c46f2 100644 --- a/server/model/system/request/sys_user.go +++ b/server/model/system/request/sys_user.go @@ -33,6 +33,11 @@ type ChangePasswordReq struct { NewPassword string `json:"newPassword"` // 新密码 } +type ResetPassword struct { + ID uint `json:"ID" form:"ID"` + Password string `json:"password" form:"password" gorm:"comment:用户登录密码"` // 用户登录密码 +} + // SetUserAuth Modify user's auth structure type SetUserAuth struct { AuthorityId uint `json:"authorityId"` // 角色ID diff --git a/server/resource/package/server/model/model.go.tpl b/server/resource/package/server/model/model.go.tpl index 3114b9cc..e1603ed6 100644 --- a/server/resource/package/server/model/model.go.tpl +++ b/server/resource/package/server/model/model.go.tpl @@ -1,25 +1,7 @@ {{- if .IsAdd}} // 在结构体中新增如下字段 {{- range .Fields}} -{{- if eq .FieldType "enum" }} -{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};type:enum({{.DataTypeLong}});comment:{{.Comment}};" {{- if .Require }} binding:"required"{{- end -}}` -{{- else if eq .FieldType "picture" }} -{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}` -{{- else if eq .FieldType "video" }} -{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}` -{{- else if eq .FieldType "file" }} -{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end }} swaggertype:"array,object"` -{{- else if eq .FieldType "pictures" }} -{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end }} swaggertype:"array,object"` -{{- else if eq .FieldType "richtext" }} -{{.FieldName}} *string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end -}}` -{{- else if eq .FieldType "json" }} -{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end }} swaggertype:"object"` -{{- else if eq .FieldType "array" }} -{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end }} swaggertype:"array,object"` -{{- else }} -{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}` -{{- end }} {{ if .FieldDesc }}//{{.FieldDesc}}{{ end }} + {{ GenerateField . }} {{- end }} {{ else }} @@ -47,25 +29,7 @@ type {{.StructName}} struct { global.GVA_MODEL {{- end }} {{- range .Fields}} - {{- if eq .FieldType "enum" }} - {{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};type:enum({{.DataTypeLong}});comment:{{.Comment}};" {{- if .Require }} binding:"required"{{- end -}}` - {{- else if eq .FieldType "picture" }} - {{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}` - {{- else if eq .FieldType "video" }} - {{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}` - {{- else if eq .FieldType "file" }} - {{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end }} swaggertype:"array,object"` - {{- else if eq .FieldType "pictures" }} - {{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end }} swaggertype:"array,object"` - {{- else if eq .FieldType "richtext" }} - {{.FieldName}} *string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end -}}` - {{- else if eq .FieldType "json" }} - {{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end }} swaggertype:"object"` - {{- else if eq .FieldType "array" }} - {{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end }} swaggertype:"array,object"` - {{- else }} - {{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}` - {{- end }} {{ if .FieldDesc }}//{{.FieldDesc}}{{ end }} + {{ GenerateField . }} {{- end }} {{- if .AutoCreateResource }} CreatedBy uint `gorm:"column:created_by;comment:创建者"` diff --git a/server/resource/package/server/service/service.go.tpl b/server/resource/package/server/service/service.go.tpl index d0cbb4f8..7533c576 100644 --- a/server/resource/package/server/service/service.go.tpl +++ b/server/resource/package/server/service/service.go.tpl @@ -8,29 +8,7 @@ {{- if .IsAdd}} // Get{{.StructName}}InfoList 新增搜索语句 - {{- range .Fields}} - {{- if .FieldSearchType}} - {{- if or (eq .FieldType "enum") (eq .FieldType "pictures") (eq .FieldType "picture") (eq .FieldType "video") (eq .FieldType "json") }} -if info.{{.FieldName}} != "" { - {{- if or (eq .FieldType "enum") }} - db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+ {{ end }}*info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }}) - {{- else}} -// 数据类型为复杂类型,请根据业务需求自行实现复杂类型的查询业务 - {{- end}} -} - {{- else if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}} -if info.Start{{.FieldName}} != nil && info.End{{.FieldName}} != nil { - db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ? AND ? ",info.Start{{.FieldName}},info.End{{.FieldName}}) -} - {{- else}} -if info.{{.FieldName}} != nil{{- if eq .FieldType "string" }} && *info.{{.FieldName}} != ""{{- end }} { - db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}*info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }}) -} - {{- end }} - {{- end }} - {{- end }} - - + {{ GenerateSearchConditions .Fields }} // Get{{.StructName}}InfoList 新增排序语句 请自行在搜索语句中添加orderMap内容 {{- range .Fields}} {{- if .Sort}} @@ -174,27 +152,7 @@ func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoLis db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt) } {{- end }} - {{- range .Fields}} - {{- if .FieldSearchType}} - {{- if or (eq .FieldType "enum") (eq .FieldType "pictures") (eq .FieldType "picture") (eq .FieldType "video") (eq .FieldType "json") }} - if info.{{.FieldName}} != "" { - {{- if or (eq .FieldType "enum")}} - db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+ {{ end }}*info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }}) - {{- else}} - // 数据类型为复杂类型,请根据业务需求自行实现复杂类型的查询业务 - {{- end}} - } - {{- else if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}} - if info.Start{{.FieldName}} != nil && info.End{{.FieldName}} != nil { - db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ? AND ? ",info.Start{{.FieldName}},info.End{{.FieldName}}) - } - {{- else}} - if info.{{.FieldName}} != nil{{- if eq .FieldType "string" }} && *info.{{.FieldName}} != ""{{- end }} { - db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}*info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }}) - } - {{- end }} - {{- end }} - {{- end }} + {{ GenerateSearchConditions .Fields }} err = db.Count(&total).Error if err!=nil { return @@ -202,6 +160,10 @@ func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoLis {{- if .NeedSort}} var OrderStr string orderMap := make(map[string]bool) + {{- if .GvaModel }} + orderMap["ID"] = true + orderMap["CreatedAt"] = true + {{- end }} {{- range .Fields}} {{- if .Sort}} orderMap["{{.ColumnName}}"] = true diff --git a/server/resource/package/web/view/form.vue.tpl b/server/resource/package/web/view/form.vue.tpl index e45b3755..28c1f02e 100644 --- a/server/resource/package/web/view/form.vue.tpl +++ b/server/resource/package/web/view/form.vue.tpl @@ -1,75 +1,10 @@ {{- if .IsAdd }} // 新增表单中增加如下代码 {{- range .Fields}} - {{- if .Form}} - - {{- if .CheckDataSource}} - - - - {{- else }} - {{- if eq .FieldType "bool" }} - - {{- end }} - {{- if eq .FieldType "string" }} - {{- if .DictType}} - - - - {{- else }} - - {{- end }} - {{- end }} - {{- if eq .FieldType "richtext" }} - - {{- end }} - {{- if eq .FieldType "json" }} - // 此字段为json结构,可以前端自行控制展示和数据绑定模式 需绑定json的key为 formData.{{.FieldJson}} 后端会按照json的类型进行存取 - {{"{{"}} formData.{{.FieldJson}} {{"}}"}} - {{- end }} - {{- if eq .FieldType "array" }} - - {{- end }} - {{- if eq .FieldType "int" }} - - {{- end }} - {{- if eq .FieldType "time.Time" }} - - {{- end }} - {{- if eq .FieldType "float64" }} - - {{- end }} - {{- if eq .FieldType "enum" }} - - - - {{- end }} - {{- if eq .FieldType "picture" }} - - {{- end }} - {{- if eq .FieldType "pictures" }} - - {{- end }} - {{- if eq .FieldType "video" }} - - {{- end }} - {{- if eq .FieldType "file" }} - - {{- end }} - {{- end }} - - {{- end }} - {{- end }} + {{- if .Form}} + {{ GenerateFormItem . }} + {{- end }} +{{- end }} // 字典增加如下代码 {{- range $index, $element := .DictTypes}} @@ -85,42 +20,7 @@ const {{ $element }}Options = ref([]) // 基础formData结构增加如下字段 {{- range .Fields}} {{- if .Form}} - {{- if eq .FieldType "bool" }} -{{.FieldJson}}: false, - {{- end }} - {{- if eq .FieldType "string" }} -{{.FieldJson}}: '', - {{- end }} - {{- if eq .FieldType "richtext" }} -{{.FieldJson}}: '', - {{- end }} - {{- if eq .FieldType "int" }} -{{.FieldJson}}: {{- if or .DataSource}} undefined{{ else }} 0{{- end }}, - {{- end }} - {{- if eq .FieldType "time.Time" }} -{{.FieldJson}}: new Date(), - {{- end }} - {{- if eq .FieldType "float64" }} -{{.FieldJson}}: 0, - {{- end }} - {{- if eq .FieldType "picture" }} -{{.FieldJson}}: "", - {{- end }} - {{- if eq .FieldType "video" }} -{{.FieldJson}}: "", - {{- end }} - {{- if eq .FieldType "pictures" }} -{{.FieldJson}}: [], - {{- end }} - {{- if eq .FieldType "file" }} -{{.FieldJson}}: [], - {{- end }} - {{- if eq .FieldType "json" }} -{{.FieldJson}}: {}, - {{- end }} - {{- if eq .FieldType "array" }} -{{.FieldJson}}: [], - {{- end }} + {{ GenerateDefaultFormValue . }} {{- end }} {{- end }} // 验证规则中增加如下字段 @@ -181,62 +81,7 @@ getDataSourceFunc() {{- end }} {{- range .Fields}} {{- if .Form }} - - {{- if .CheckDataSource}} - - - - {{- else }} - {{- if eq .FieldType "bool" }} - - {{- end }} - {{- if eq .FieldType "string" }} - {{- if .DictType}} - - - - {{- else }} - - {{- end }} - {{- end }} - {{- if eq .FieldType "richtext" }} - - {{- end }} - {{- if eq .FieldType "int" }} - - {{- end }} - {{- if eq .FieldType "time.Time" }} - - {{- end }} - {{- if eq .FieldType "float64" }} - - {{- end }} - {{- if eq .FieldType "enum" }} - - - - {{- end }} - {{- if eq .FieldType "picture" }} - - {{- end }} - {{- if eq .FieldType "video" }} - - {{- end }} - {{- if eq .FieldType "pictures" }} - - {{- end }} - {{- if eq .FieldType "file" }} - - {{- end }} - {{- if eq .FieldType "json" }} - // 此字段为json结构,可以前端自行控制展示和数据绑定模式 需绑定json的key为 formData.{{.FieldJson}} 后端会按照json的类型进行存取 - {{"{{"}} formData.{{.FieldJson}} {{"}}"}} - {{- end }} - {{- if eq .FieldType "array" }} - - {{- end }} - {{- end }} - + {{ GenerateFormItem . }} {{- end }} {{- end }} @@ -333,42 +178,7 @@ const formData = ref({ {{- end }} {{- range .Fields}} {{- if .Form }} - {{- if eq .FieldType "bool" }} - {{.FieldJson}}: false, - {{- end }} - {{- if eq .FieldType "string" }} - {{.FieldJson}}: '', - {{- end }} - {{- if eq .FieldType "richtext" }} - {{.FieldJson}}: '', - {{- end }} - {{- if eq .FieldType "int" }} - {{.FieldJson}}: {{- if or .DataSource }} undefined{{ else }} 0{{- end }}, - {{- end }} - {{- if eq .FieldType "time.Time" }} - {{.FieldJson}}: new Date(), - {{- end }} - {{- if eq .FieldType "float64" }} - {{.FieldJson}}: 0, - {{- end }} - {{- if eq .FieldType "picture" }} - {{.FieldJson}}: "", - {{- end }} - {{- if eq .FieldType "video" }} - {{.FieldJson}}: "", - {{- end }} - {{- if eq .FieldType "pictures" }} - {{.FieldJson}}: [], - {{- end }} - {{- if eq .FieldType "file" }} - {{.FieldJson}}: [], - {{- end }} - {{- if eq .FieldType "json" }} - {{.FieldJson}}: {}, - {{- end }} - {{- if eq .FieldType "array" }} - {{.FieldJson}}: [], - {{- end }} + {{ GenerateDefaultFormValue . }} {{- end }} {{- end }} }) diff --git a/server/resource/package/web/view/table.vue.tpl b/server/resource/package/web/view/table.vue.tpl index c6d5f55b..60019d83 100644 --- a/server/resource/package/web/view/table.vue.tpl +++ b/server/resource/package/web/view/table.vue.tpl @@ -1,276 +1,35 @@ {{- $global := . }} {{- $templateID := printf "%s_%s" .Package .StructName }} {{- if .IsAdd }} + // 请在搜索条件中增加如下代码 -{{- range .Fields}} {{- if .FieldSearchType}} {{- if eq .FieldType "bool" }} - - - - - - - - - {{- else if .DictType}} - - - - - - {{- else if .CheckDataSource}} - - - - - - {{- else}} - - {{- if eq .FieldType "float64" "int"}} - {{if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}} - -— - - {{- else}} - - {{- end}} - {{- else if eq .FieldType "time.Time"}} - {{if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}} - - -— - - {{- else}} - - {{- end}} - {{- else}} - - {{- end}} -{{ end }}{{ end }}{{ end }} +{{- range .Fields}} + {{- if .FieldSearchType}} +{{ GenerateSearchFormItem .}} + {{ end }} +{{ end }} // 表格增加如下列代码 {{- range .Fields}} - {{- if .Table}} - {{- if .CheckDataSource }} - - - - {{- else if .DictType}} - - - - {{- else if eq .FieldType "bool" }} - - - - {{- else if eq .FieldType "time.Time" }} - - - - {{- else if eq .FieldType "picture" }} - - - - {{- else if eq .FieldType "pictures" }} - - - - {{- else if eq .FieldType "video" }} - - - - {{- else if eq .FieldType "richtext" }} - - - - {{- else if eq .FieldType "file" }} - - - - {{- else if eq .FieldType "json" }} - - - - {{- else if eq .FieldType "array" }} - - - - {{- else }} - - {{- end }} - {{- end }} - {{- end }} + {{- if .Table}} + {{ GenerateTableColumn . }} + {{- end }} +{{- end }} // 新增表单中增加如下代码 {{- range .Fields}} - {{- if .Form}} - - {{- if .CheckDataSource}} - - - - {{- else }} - {{- if eq .FieldType "bool" }} - - {{- end }} - {{- if eq .FieldType "string" }} - {{- if .DictType}} - - - - {{- else }} - - {{- end }} - {{- end }} - {{- if eq .FieldType "richtext" }} - - {{- end }} - {{- if eq .FieldType "json" }} - // 此字段为json结构,可以前端自行控制展示和数据绑定模式 需绑定json的key为 formData.{{.FieldJson}} 后端会按照json的类型进行存取 - {{"{{"}} formData.{{.FieldJson}} {{"}}"}} - {{- end }} - {{- if eq .FieldType "array" }} - {{- if .DictType}} - - - - {{- else }} - - {{- end }} - {{- end }} - {{- if eq .FieldType "int" }} - - {{- end }} - {{- if eq .FieldType "time.Time" }} - - {{- end }} - {{- if eq .FieldType "float64" }} - - {{- end }} - {{- if eq .FieldType "enum" }} - - - - {{- end }} - {{- if eq .FieldType "picture" }} - - {{- end }} - {{- if eq .FieldType "pictures" }} - - {{- end }} - {{- if eq .FieldType "video" }} - - {{- end }} - {{- if eq .FieldType "file" }} - - {{- end }} - {{- end }} - - {{- end }} - {{- end }} + {{- if .Form}} + {{ GenerateFormItem . }} + {{- end }} +{{- end }} // 查看抽屉中增加如下代码 {{- range .Fields}} {{- if .Desc }} - -{{- if .CheckDataSource }} - - {{- else if and (ne .FieldType "picture" ) (ne .FieldType "pictures" ) (ne .FieldType "file" ) (ne .FieldType "array" ) }} - {{"{{"}} detailFrom.{{.FieldJson}} {{"}}"}} - {{- else }} - {{- if eq .FieldType "picture" }} - - {{- end }} - {{- if eq .FieldType "array" }} - - {{- end }} - {{- if eq .FieldType "pictures" }} - - {{- end }} - {{- if eq .FieldType "richtext" }} - - {{- end }} - {{- if eq .FieldType "file" }} -
- - - {{"{{"}}item.name{{"}}"}} - -
- {{- end }} - {{- end }} -
+ {{ GenerateDescriptionItem . }} {{- end }} {{- end }} @@ -288,42 +47,7 @@ const {{ $element }}Options = ref([]) // 基础formData结构(变量处和关闭表单处)增加如下字段 {{- range .Fields}} {{- if .Form}} - {{- if eq .FieldType "bool" }} -{{.FieldJson}}: false, - {{- end }} - {{- if eq .FieldType "string" }} -{{.FieldJson}}: '', - {{- end }} - {{- if eq .FieldType "richtext" }} -{{.FieldJson}}: '', - {{- end }} - {{- if eq .FieldType "int" }} -{{.FieldJson}}: {{- if .DataSource}} undefined{{ else }} 0{{- end }}, - {{- end }} - {{- if eq .FieldType "time.Time" }} -{{.FieldJson}}: new Date(), - {{- end }} - {{- if eq .FieldType "float64" }} -{{.FieldJson}}: 0, - {{- end }} - {{- if eq .FieldType "picture" }} -{{.FieldJson}}: "", - {{- end }} - {{- if eq .FieldType "video" }} -{{.FieldJson}}: "", - {{- end }} - {{- if eq .FieldType "pictures" }} -{{.FieldJson}}: [], - {{- end }} - {{- if eq .FieldType "file" }} -{{.FieldJson}}: [], - {{- end }} - {{- if eq .FieldType "json" }} -{{.FieldJson}}: {}, - {{- end }} - {{- if eq .FieldType "array" }} -{{.FieldJson}}: [], - {{- end }} + {{ GenerateDefaultFormValue . }} {{- end }} {{- end }} // 验证规则中增加如下字段 @@ -374,7 +98,7 @@ getDataSourceFunc()