Skip to content

Commit 9c41ed8

Browse files
author
piexlmax
committed
Merge remote-tracking branch 'origin/main'
2 parents 4724cec + 4078dda commit 9c41ed8

File tree

49 files changed

+533
-274
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+533
-274
lines changed

server/api/v1/system/sys_user.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ func (b *BaseApi) SetUserInfo(c *gin.Context) {
275275
var user system.SysUser
276276
_ = c.ShouldBindJSON(&user)
277277
user.Username = ""
278+
user.Password = ""
279+
user.AuthorityId = ""
278280
if err := utils.Verify(user, utils.IdVerify); err != nil {
279281
response.FailWithMessage(err.Error(), c)
280282
return
@@ -299,6 +301,8 @@ func (b *BaseApi) SetSelfInfo(c *gin.Context) {
299301
var user system.SysUser
300302
_ = c.ShouldBindJSON(&user)
301303
user.Username = ""
304+
user.Password = ""
305+
user.AuthorityId = ""
302306
user.ID = utils.GetUserID(c)
303307
if err, ReqUser := userService.SetUserInfo(user); err != nil {
304308
global.GVA_LOG.Error("设置失败!", zap.Error(err))

server/config/gorm_mysql.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ type Mysql struct {
1616
func (m *Mysql) Dsn() string {
1717
return m.Username + ":" + m.Password + "@tcp(" + m.Path + ":" + m.Port + ")/" + m.Dbname + "?" + m.Config
1818
}
19+
20+
func (m *Mysql) GetLogMode() string {
21+
return m.LogMode
22+
}

server/config/gorm_pgsql.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ func (p *Pgsql) Dsn() string {
2424
func (p *Pgsql) LinkDsn(dbname string) string {
2525
return "host=" + p.Path + " user=" + p.Username + " password=" + p.Password + " dbname=" + dbname + " port=" + p.Port + " " + p.Config
2626
}
27+
28+
func (m *Pgsql) GetLogMode() string {
29+
return m.LogMode
30+
}

server/core/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func RunWindowsServer() {
3737

3838
fmt.Printf(`
3939
欢迎使用 github.com/flipped-aurora/gin-vue-admin/server
40-
当前版本:V2.5.0 beta
40+
当前版本:V2.5.0 beta.2
4141
加群方式:微信号:shouzi_1994 QQ群:622360840
4242
GVA讨论社区:https://support.qq.com/products/371961
4343
默认自动化文档地址:http://127.0.0.1%s/swagger/index.html

server/go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ require (
1818
github.com/go-sql-driver/mysql v1.5.0
1919
github.com/gookit/color v1.3.1
2020
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.8+incompatible
21+
github.com/jackc/pgx/v4 v4.15.0 // indirect
2122
github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84
2223
github.com/mojocn/base64Captcha v1.3.1
2324
github.com/natefinch/lumberjack v2.0.0+incompatible
@@ -36,10 +37,11 @@ require (
3637
github.com/unrolled/secure v1.0.7
3738
github.com/xuri/excelize/v2 v2.4.1
3839
go.uber.org/zap v1.16.0
40+
golang.org/x/crypto v0.0.0-20220213190939-1e6e3497d506 // indirect
3941
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
4042
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
4143
gorm.io/driver/mysql v1.0.1
42-
gorm.io/driver/postgres v0.2.6
43-
gorm.io/gorm v1.20.11
44+
gorm.io/driver/postgres v1.2.3
45+
gorm.io/gorm v1.22.5
4446
nhooyr.io/websocket v1.8.6
4547
)

server/go.sum

Lines changed: 58 additions & 3 deletions
Large diffs are not rendered by default.

server/initialize/internal/gorm.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import (
1010
"gorm.io/gorm/logger"
1111
)
1212

13+
type DBBASE interface {
14+
GetLogMode() string
15+
}
16+
1317
var Gorm = new(_gorm)
1418

1519
type _gorm struct{}
@@ -23,7 +27,19 @@ func (g *_gorm) Config() *gorm.Config {
2327
LogLevel: logger.Warn,
2428
Colorful: true,
2529
})
26-
switch global.GVA_CONFIG.Mysql.LogMode {
30+
var logMode DBBASE
31+
switch global.GVA_CONFIG.System.DbType {
32+
case "mysql":
33+
logMode = &global.GVA_CONFIG.Mysql
34+
break
35+
case "pgsql":
36+
logMode = &global.GVA_CONFIG.Pgsql
37+
break
38+
default:
39+
logMode = &global.GVA_CONFIG.Mysql
40+
}
41+
42+
switch logMode.GetLogMode() {
2743
case "silent", "Silent":
2844
config.Logger = _default.LogMode(logger.Silent)
2945
case "error", "Error":

server/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/flipped-aurora/gin-vue-admin/server/core"
55
"github.com/flipped-aurora/gin-vue-admin/server/global"
66
"github.com/flipped-aurora/gin-vue-admin/server/initialize"
7+
"go.uber.org/zap"
78
)
89

910
//go:generate go env -w GO111MODULE=on
@@ -19,8 +20,9 @@ import (
1920
// @name x-token
2021
// @BasePath /
2122
func main() {
22-
global.GVA_VP = core.Viper() // 初始化Viper
23-
global.GVA_LOG = core.Zap() // 初始化zap日志库
23+
global.GVA_VP = core.Viper() // 初始化Viper
24+
global.GVA_LOG = core.Zap() // 初始化zap日志库
25+
zap.ReplaceGlobals(global.GVA_LOG)
2426
global.GVA_DB = initialize.Gorm() // gorm连接数据库
2527
initialize.Timer()
2628
initialize.DBList()

server/model/system/request/sys_init.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,30 @@ func (i *InitDB) PgsqlEmptyDsn() string {
4343
// Author [SliverHorn](https://github.com/SliverHorn)
4444
func (i *InitDB) ToMysqlConfig() config.Mysql {
4545
return config.Mysql{
46-
Path: i.Host,
47-
Port: i.Port,
48-
Dbname: i.DBName,
49-
Username: i.UserName,
50-
Password: i.Password,
51-
Config: "charset=utf8mb4&parseTime=True&loc=Local",
46+
Path: i.Host,
47+
Port: i.Port,
48+
Dbname: i.DBName,
49+
Username: i.UserName,
50+
Password: i.Password,
51+
MaxIdleConns: 10,
52+
MaxOpenConns: 100,
53+
LogMode: "error",
54+
Config: "charset=utf8mb4&parseTime=True&loc=Local",
5255
}
5356
}
5457

5558
// ToPgsqlConfig 转换 config.Pgsql
5659
// Author [SliverHorn](https://github.com/SliverHorn)
5760
func (i *InitDB) ToPgsqlConfig() config.Pgsql {
5861
return config.Pgsql{
59-
Path: i.Host,
60-
Port: i.Port,
61-
Dbname: i.DBName,
62-
Username: i.UserName,
63-
Password: i.Password,
64-
Config: "sslmode=disable TimeZone=Asia/Shanghai",
62+
Path: i.Host,
63+
Port: i.Port,
64+
Dbname: i.DBName,
65+
Username: i.UserName,
66+
Password: i.Password,
67+
MaxIdleConns: 10,
68+
MaxOpenConns: 100,
69+
LogMode: "error",
70+
Config: "sslmode=disable TimeZone=Asia/Shanghai",
6571
}
6672
}

server/model/system/sys_user.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ type SysUser struct {
1818
AuthorityId string `json:"authorityId" gorm:"default:888;comment:用户角色ID"` // 用户角色ID
1919
Authority SysAuthority `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"`
2020
Authorities []SysAuthority `json:"authorities" gorm:"many2many:sys_user_authority;"`
21+
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户角色ID
22+
Email string `json:"email" gorm:"comment:用户邮箱"` // 用户邮箱
2123
}

server/resource/template/web/table.vue.tpl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@
2222
<el-input v-model="searchInfo.{{.FieldJson}}" placeholder="搜索条件" />
2323
</el-form-item>{{ end }}{{ end }}{{ end }}
2424
<el-form-item>
25-
<el-button size="mini" type="primary" icon="search" @click="onSubmit">查询</el-button>
26-
<el-button size="mini" icon="refresh" @click="onReset">重置</el-button>
25+
<el-button size="small" type="primary" icon="search" @click="onSubmit">查询</el-button>
26+
<el-button size="small" icon="refresh" @click="onReset">重置</el-button>
2727
</el-form-item>
2828
</el-form>
2929
</div>
3030
<div class="gva-table-box">
3131
<div class="gva-btn-list">
32-
<el-button size="mini" type="primary" icon="plus" @click="openDialog">新增</el-button>
32+
<el-button size="small" type="primary" icon="plus" @click="openDialog">新增</el-button>
3333
<el-popover v-model:visible="deleteVisible" placement="top" width="160">
3434
<p>确定要删除吗?</p>
3535
<div style="text-align: right; margin-top: 8px;">
36-
<el-button size="mini" type="text" @click="deleteVisible = false">取消</el-button>
37-
<el-button size="mini" type="primary" @click="onDelete">确定</el-button>
36+
<el-button size="small" type="text" @click="deleteVisible = false">取消</el-button>
37+
<el-button size="small" type="primary" @click="onDelete">确定</el-button>
3838
</div>
3939
<template #reference>
40-
<el-button icon="delete" size="mini" style="margin-left: 10px;" :disabled="!multipleSelection.length">删除</el-button>
40+
<el-button icon="delete" size="small" style="margin-left: 10px;" :disabled="!multipleSelection.length">删除</el-button>
4141
</template>
4242
</el-popover>
4343
</div>
@@ -70,7 +70,7 @@
7070
<el-table-column align="left" label="按钮组">
7171
<template #default="scope">
7272
<el-button type="text" icon="edit" size="small" class="table-button" @click="update{{.StructName}}Func(scope.row)">变更</el-button>
73-
<el-button type="text" icon="delete" size="mini" @click="deleteRow(scope.row)">删除</el-button>
73+
<el-button type="text" icon="delete" size="small" @click="deleteRow(scope.row)">删除</el-button>
7474
</template>
7575
</el-table-column>
7676
</el-table>

server/service/system/sys_user.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ func (userService *UserService) Login(u *system.SysUser) (err error, userInter *
4646
var user system.SysUser
4747
u.Password = utils.MD5V([]byte(u.Password))
4848
err = global.GVA_DB.Where("username = ? AND password = ?", u.Username, u.Password).Preload("Authorities").Preload("Authority").First(&user).Error
49+
if err == nil{
50+
var am system.SysMenu
51+
ferr := global.GVA_DB.First(&am,"name = ? AND authority_id = ?",user.Authority.DefaultRouter,user.AuthorityId).Error
52+
if errors.Is(ferr,gorm.ErrRecordNotFound) {
53+
user.Authority.DefaultRouter = "404"
54+
}
55+
}
4956
return err, &user
5057
}
5158

@@ -163,6 +170,14 @@ func (userService *UserService) SetUserInfo(reqUser system.SysUser) (err error,
163170
func (userService *UserService) GetUserInfo(uuid uuid.UUID) (err error, user system.SysUser) {
164171
var reqUser system.SysUser
165172
err = global.GVA_DB.Preload("Authorities").Preload("Authority").First(&reqUser, "uuid = ?", uuid).Error
173+
if err!=nil{
174+
return err, reqUser
175+
}
176+
var am system.SysMenu
177+
ferr := global.GVA_DB.First(&am,"name = ? AND authority_id = ?",reqUser.Authority.DefaultRouter,reqUser.AuthorityId).Error
178+
if errors.Is(ferr,gorm.ErrRecordNotFound) {
179+
reqUser.Authority.DefaultRouter = "404"
180+
}
166181
return err, reqUser
167182
}
168183

server/source/system/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ func (a *api) Initialize() error {
2222
{ApiGroup: "jwt", Method: "POST", Path: "/jwt/jsonInBlacklist", Description: "jwt加入黑名单(退出,必选)"},
2323

2424
{ApiGroup: "系统用户", Method: "DELETE", Path: "/user/deleteUser", Description: "删除用户"},
25-
{ApiGroup: "系统用户", Method: "POST", Path: "/user/register", Description: "用户注册(必选)"},
25+
{ApiGroup: "系统用户", Method: "POST", Path: "/user/register", Description: "用户注册"},
2626
{ApiGroup: "系统用户", Method: "POST", Path: "/user/getUserList", Description: "获取用户列表"},
2727
{ApiGroup: "系统用户", Method: "PUT", Path: "/user/setUserInfo", Description: "设置用户信息"},
2828
{ApiGroup: "系统用户", Method: "PUT", Path: "/user/setSelfInfo", Description: "设置自身信息(必选)"},
2929
{ApiGroup: "系统用户", Method: "GET", Path: "/user/getUserInfo", Description: "获取自身信息(必选)"},
3030
{ApiGroup: "系统用户", Method: "POST", Path: "/user/setUserAuthorities", Description: "设置权限组"},
31-
{ApiGroup: "系统用户", Method: "POST", Path: "/user/changePassword", Description: "修改密码(建(选择)"},
31+
{ApiGroup: "系统用户", Method: "POST", Path: "/user/changePassword", Description: "修改密码(建议选择)"},
3232
{ApiGroup: "系统用户", Method: "POST", Path: "/user/setUserAuthority", Description: "修改用户角色(必选)"},
3333
{ApiGroup: "系统用户", Method: "POST", Path: "/user/resetPassword", Description: "重置用户密码"},
3434

server/source/system/dictionary.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ func (d *dictionary) Initialize() error {
1919
status := new(bool)
2020
*status = true
2121
entities := []system.SysDictionary{
22-
{Name: "性别", Type: "gender", Status: status, Desc: "性别字典"},
23-
{Name: "数据库int类型", Type: "int", Status: status, Desc: "int类型对应的数据库类型"},
24-
{Name: "数据库时间日期类型", Type: "time.Time", Status: status, Desc: "数据库时间日期类型"},
25-
{Name: "数据库浮点型", Type: "float64", Status: status, Desc: "数据库浮点型"},
26-
{Name: "数据库字符串", Type: "string", Status: status, Desc: "数据库字符串"},
27-
{Name: "数据库bool类型", Type: "bool", Status: status, Desc: "数据库bool类型"},
22+
{GVA_MODEL: global.GVA_MODEL{ID: 1}, Name: "性别", Type: "gender", Status: status, Desc: "性别字典"},
23+
{GVA_MODEL: global.GVA_MODEL{ID: 2}, Name: "数据库int类型", Type: "int", Status: status, Desc: "int类型对应的数据库类型"},
24+
{GVA_MODEL: global.GVA_MODEL{ID: 3}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Desc: "数据库时间日期类型"},
25+
{GVA_MODEL: global.GVA_MODEL{ID: 4}, Name: "数据库浮点型", Type: "float64", Status: status, Desc: "数据库浮点型"},
26+
{GVA_MODEL: global.GVA_MODEL{ID: 5}, Name: "数据库字符串", Type: "string", Status: status, Desc: "数据库字符串"},
27+
{GVA_MODEL: global.GVA_MODEL{ID: 6}, Name: "数据库bool类型", Type: "bool", Status: status, Desc: "数据库bool类型"},
2828
}
2929
if err := global.GVA_DB.Create(&entities).Error; err != nil {
3030
return errors.Wrap(err, d.TableName()+"表数据初始化失败!")

0 commit comments

Comments
 (0)