Skip to content

Commit

Permalink
Merge branch 'main' into i18n-dev-new
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedHassanNasr committed Aug 3, 2023
2 parents 560efb7 + 0e78080 commit cd6756b
Show file tree
Hide file tree
Showing 43 changed files with 610 additions and 103 deletions.
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@
[声明式API版](https://github.com/flipped-aurora/gin-vue-admin/tree/v2.4.x) |
[声明式API多语言(i18n)版](https://github.com/flipped-aurora/gin-vue-admin/tree/i18n-dev)

## 赞助商
Gin-Vue-Admin是一个全栈自动化代码的开源项目,其持续开发完全得益于这些令人敬畏的赞助的支持。如果你想加入他们,请考虑<a target="_blank" href="https://gin-vue-admin.com/empower/index.html#%E5%85%B6%E4%BB%96%E6%9C%8D%E5%8A%A1">赞助Gin-Vue-Admin</a>的开发。
<p align="center">
<h3 align="center">Sponsor</h3>
</p>
<p align="center">
<a target="_blank" href="https://www.mingdao.com?s=utm_84&utm_source=gin-vue-admin&utm_medium=banner&utm_campaign=github&utm_content=IT%E8%B5%8B%E8%83%BD%E4%B8%9A%E5%8A%A1">
<img alt="special sponsor appwrite" src="https://gin-vue-admin.com/guanwang/mingdao.png" width="300">
</a>
</p>
# 项目文档
[在线文档](https://www.gin-vue-admin.com) : https://www.gin-vue-admin.com

Expand Down
1 change: 1 addition & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Server struct {
Mssql Mssql `mapstructure:"mssql" json:"mssql" yaml:"mssql"`
Pgsql Pgsql `mapstructure:"pgsql" json:"pgsql" yaml:"pgsql"`
Oracle Oracle `mapstructure:"oracle" json:"oracle" yaml:"oracle"`
Sqlite Sqlite `mapstructure:"sqlite" json:"sqlite" yaml:"sqlite"`
DBList []SpecializedDB `mapstructure:"db-list" json:"db-list" yaml:"db-list"`
// oss
Local Local `mapstructure:"local" json:"local" yaml:"local"`
Expand Down
17 changes: 17 additions & 0 deletions server/config/gorm_sqlite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package config

import (
"path/filepath"
)

type Sqlite struct {
GeneralDB `yaml:",inline" mapstructure:",squash"`
}

func (s *Sqlite) Dsn() string {
return filepath.Join(s.Path, s.Dbname+".db")
}

func (s *Sqlite) GetLogMode() string {
return s.LogMode
}
61 changes: 61 additions & 0 deletions server/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5124,6 +5124,64 @@
}
}
},
"config.Sqlite": {
"type": "object",
"properties": {
"config": {
"description": "高级配置",
"type": "string"
},
"db-name": {
"description": "数据库名",
"type": "string"
},
"engine": {
"description": "数据库引擎,默认InnoDB",
"type": "string",
"default": "InnoDB"
},
"log-mode": {
"description": "是否开启Gorm全局日志",
"type": "string"
},
"log-zap": {
"description": "是否通过zap写入日志文件",
"type": "boolean"
},
"max-idle-conns": {
"description": "空闲中的最大连接数",
"type": "integer"
},
"max-open-conns": {
"description": "打开到数据库的最大连接数",
"type": "integer"
},
"password": {
"description": "数据库密码",
"type": "string"
},
"path": {
"description": "服务器地址:端口",
"type": "string"
},
"port": {
"description": ":端口",
"type": "string"
},
"prefix": {
"description": "全局表前缀,单独定义TableName则不生效",
"type": "string"
},
"singular": {
"description": "是否开启全局禁用复数,true表示开启",
"type": "boolean"
},
"username": {
"description": "数据库用户名",
"type": "string"
}
}
},
"config.Qiniu": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -5245,6 +5303,9 @@
"pgsql": {
"$ref": "#/definitions/config.Pgsql"
},
"sqlite": {
"$ref": "#/definitions/config.Sqlite"
},
"qiniu": {
"$ref": "#/definitions/config.Qiniu"
},
Expand Down
4 changes: 2 additions & 2 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/fsnotify/fsnotify v1.4.9
github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6
github.com/gin-gonic/gin v1.9.0
github.com/glebarez/sqlite v1.8.0
github.com/go-redis/redis/v8 v8.11.5
github.com/go-sql-driver/mysql v1.7.1
github.com/gofrs/uuid v4.0.0+incompatible
Expand Down Expand Up @@ -58,7 +59,6 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/glebarez/go-sqlite v1.21.1 // indirect
github.com/glebarez/sqlite v1.8.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
Expand Down Expand Up @@ -113,7 +113,7 @@ require (
go.uber.org/atomic v1.6.0 // indirect
go.uber.org/multierr v1.5.0 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect
golang.org/x/image v0.5.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,8 @@ golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190501045829-6d32002ffd75/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
2 changes: 2 additions & 0 deletions server/initialize/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func Gorm() *gorm.DB {
return GormOracle()
case "mssql":
return GormMssql()
case "sqlite":
return GormSqlite()
default:
return GormMysql()
}
Expand Down
2 changes: 1 addition & 1 deletion server/initialize/gorm_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/flipped-aurora/gin-vue-admin/server/config"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/initialize/internal"
_ "github.com/go-sql-driver/mysql"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
Expand All @@ -20,7 +21,6 @@ func GormMysql() *gorm.DB {
DSN: m.Dsn(), // DSN data source name
DefaultStringSize: 191, // string 类型字段的默认长度
SkipInitializeWithVersion: false, // 根据版本自动配置

}
if db, err := gorm.Open(mysql.New(mysqlConfig), internal.Gorm.Config(m.Prefix, m.Singular)); err != nil {
return nil
Expand Down
1 change: 0 additions & 1 deletion server/initialize/gorm_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func GormOracleByConfig(m config.Oracle) *gorm.DB {
oracleConfig := mysql.Config{
DSN: m.Dsn(), // DSN data source name
DefaultStringSize: 191, // string 类型字段的默认长度

}
if db, err := gorm.Open(mysql.New(oracleConfig), internal.Gorm.Config(m.Prefix, m.Singular)); err != nil {
panic(err)
Expand Down
42 changes: 42 additions & 0 deletions server/initialize/gorm_sqlite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package initialize

import (
"github.com/flipped-aurora/gin-vue-admin/server/config"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/initialize/internal"
"github.com/glebarez/sqlite"
"gorm.io/gorm"
)

// GormSqlite 初始化Sqlite数据库
func GormSqlite() *gorm.DB {
s := global.GVA_CONFIG.Sqlite
if s.Dbname == "" {
return nil
}

if db, err := gorm.Open(sqlite.Open(s.Dsn()), internal.Gorm.Config(s.Prefix, s.Singular)); err != nil {
panic(err)
} else {
sqlDB, _ := db.DB()
sqlDB.SetMaxIdleConns(s.MaxIdleConns)
sqlDB.SetMaxOpenConns(s.MaxOpenConns)
return db
}
}

// GormSqliteByConfig 初始化Sqlite数据库用过传入配置
func GormSqliteByConfig(s config.Sqlite) *gorm.DB {
if s.Dbname == "" {
return nil
}

if db, err := gorm.Open(sqlite.Open(s.Dsn()), internal.Gorm.Config(s.Prefix, s.Singular)); err != nil {
panic(err)
} else {
sqlDB, _ := db.DB()
sqlDB.SetMaxIdleConns(s.MaxIdleConns)
sqlDB.SetMaxOpenConns(s.MaxOpenConns)
return db
}
}
2 changes: 1 addition & 1 deletion server/initialize/internal/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (g *_gorm) Config(prefix string, singular bool) *gorm.Config {
},
DisableForeignKeyConstraintWhenMigrating: true,
}
_default := logger.New(NewWriter(log.New(os.Stdout, "\r\n", log.LstdFlags)), logger.Config{
_default := logger.New(log.New(os.Stdout, "\r\n", log.LstdFlags), logger.Config{
SlowThreshold: 200 * time.Millisecond,
LogLevel: logger.Warn,
Colorful: true,
Expand Down
File renamed without changes.
39 changes: 32 additions & 7 deletions server/model/system/request/sys_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
)

type InitDB struct {
DBType string `json:"dbType"` // 数据库类型
Host string `json:"host"` // 服务器地址
Port string `json:"port"` // 数据库连接端口
UserName string `json:"userName" binding:"required"` // 数据库用户名
Password string `json:"password"` // 数据库密码
DBName string `json:"dbName" binding:"required"` // 数据库名
Language string `json:"language",omitempty` // DB initial langauge // added by mohamed hassan to support multilanguage
DBType string `json:"dbType"` // 数据库类型
Host string `json:"host"` // 服务器地址
Port string `json:"port"` // 数据库连接端口
UserName string `json:"userName"` // 数据库用户名
Password string `json:"password"` // 数据库密码
DBName string `json:"dbName" binding:"required"` // 数据库名
DBPath string `json:"dbPath"` // sqlite数据库文件路径
Language string `json:"language",omitempty` // DB initial langauge // added by mohamed hassan to support multilanguage
}

// MysqlEmptyDsn msyql 空数据库 建库链接
Expand All @@ -40,6 +41,12 @@ func (i *InitDB) PgsqlEmptyDsn() string {
return "host=" + i.Host + " user=" + i.UserName + " password=" + i.Password + " port=" + i.Port + " dbname=" + "postgres" + " " + "sslmode=disable TimeZone=Asia/Shanghai"
}

// SqliteEmptyDsn sqlite 空数据库 建库链接
// Author Kafumio
func (i *InitDB) SqliteEmptyDsn() string {
return i.DBPath + "\\" + i.DBName + ".db"
}

// ToMysqlConfig 转换 config.Mysql
// Author [SliverHorn](https://github.com/SliverHorn)
func (i *InitDB) ToMysqlConfig() config.Mysql {
Expand Down Expand Up @@ -75,3 +82,21 @@ func (i *InitDB) ToPgsqlConfig() config.Pgsql {
},
}
}

// ToSqliteConfig 转换 config.Sqlite
// Author [Kafumio](https://github.com/Kafumio)
func (i *InitDB) ToSqliteConfig() config.Sqlite {
return config.Sqlite{
GeneralDB: config.GeneralDB{
Path: i.DBPath,
Port: i.Port,
Dbname: i.DBName,
Username: i.UserName,
Password: i.Password,
MaxIdleConns: 10,
MaxOpenConns: 100,
LogMode: "error",
Config: "",
},
}
}
1 change: 1 addition & 0 deletions server/model/system/sys_auto_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type AutoCodeStruct struct {
NeedSort bool `json:"-"`
HasPic bool `json:"-"`
HasFile bool `json:"-"`
NeedJSON bool `json:"-"`
}

func (a *AutoCodeStruct) Pretreatment() {
Expand Down
4 changes: 3 additions & 1 deletion server/resource/autocode_template/server/model.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package {{.Package}}
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
{{ if .HasTimer }}"time"{{ end }}
{{ if .HasFile }}"gorm.io/datatypes"{{ end }}
{{ if .NeedJSON }}"gorm.io/datatypes"{{ end }}
)

// {{.StructName}} 结构体
Expand All @@ -15,6 +15,8 @@ type {{.StructName}} struct {
{{- else if eq .FieldType "picture" }}
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}"`
{{- else if eq .FieldType "file" }}
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}"`
{{- else if eq .FieldType "pictures" }}
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}"`
{{- else if ne .FieldType "string" }}
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}"`
Expand Down
12 changes: 12 additions & 0 deletions server/resource/autocode_template/web/form.vue.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
{{- if eq .FieldType "picture" }}
<SelectImage v-model="formData.{{ .FieldJson }}" />
{{- end }}
{{- if eq .FieldType "pictures" }}
<SelectImage v-model="formData.{{ .FieldJson }}" multiple />
{{- end }}
</el-form-item>
{{- end }}
<el-form-item>
Expand Down Expand Up @@ -96,6 +99,15 @@ const formData = ref({
{{- if eq .FieldType "float64" }}
{{.FieldJson}}: 0,
{{- end }}
{{- if eq .FieldType "picture" }}
{{.FieldJson}}: "",
{{- end }}
{{- if eq .FieldType "pictures" }}
{{.FieldJson}}: [],
{{- end }}
{{- if eq .FieldType "file" }}
{{.FieldJson}}: [],
{{- end }}
{{- end }}
})
// 验证规则
Expand Down
Loading

0 comments on commit cd6756b

Please sign in to comment.