Skip to content

Commit

Permalink
update gf v1.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbiao committed Dec 9, 2019
1 parent 2979328 commit 3c0414a
Show file tree
Hide file tree
Showing 25 changed files with 152 additions and 77 deletions.
13 changes: 13 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
Change Log 更新说明
------------------------------
## 2019-12-09 v0.2.0
1. gf版本升级到v1.10.0并且gtoken升级为1.3.7
2. 升级gtoken v1.3.7
3. 将原有代码配置改为新版本支持的配置文件形式
4. 修复菜单和配置管理页面展示问题
5. 优化前后端分离返回值
6. 规范sys_menu表父id
```sql
ALTER TABLE `sys_menu`
CHANGE COLUMN `parentid` `parent_id` int(11) NOT NULL DEFAULT 0 COMMENT '父id' AFTER `id`;
```
7. 加入树结构层级删除限制

## 2019-11-12 v0.1.4
1. gf版本升级到v1.9.10

Expand Down
8 changes: 0 additions & 8 deletions boot/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,8 @@ func initConfig() {
v.AddPath("template")

// glog配置
logPath := c.GetString("log-path")
glog.SetPath(logPath)
glog.SetStdoutPrint(true)

s.SetServerRoot("public")
s.SetNameToUriType(ghttp.URI_TYPE_ALLLOWER)
s.SetLogPath(logPath)
s.SetErrorLogEnabled(true)
//s.SetAccessLogEnabled(true)
s.SetPort(c.GetInt("http-port"))

glog.Info("########service finish.")

Expand Down
5 changes: 2 additions & 3 deletions boot/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ func bindRouter() {

s.BindHandler(urlPath+"/admin/welcome.html", common.Welcome)
// 中间件
s.Group(urlPath+"/", func(g *ghttp.RouterGroup) {
g.Middleware(middle.MiddlewareLog, middle.MiddlewareCommon)
})
s.BindMiddleware(urlPath+"/*", middle.MiddlewareLog)
s.BindMiddleware(urlPath+"/*", middle.MiddlewareCommon)

s.Group(urlPath+"/system", func(g *ghttp.RouterGroup) {
// 系统路由
Expand Down
9 changes: 7 additions & 2 deletions config/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
log-path = "./logs"
http-port = 80
url-path = ""
[server]
Address = ":80"
ServerRoot = "public"
LogPath = "./logs"
AccessLogEnabled = false
ErrorLogEnabled = true
PProfEnabled = true

# title设置
[setting]
Expand Down
2 changes: 1 addition & 1 deletion deploy/gcs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ INSERT INTO `sys_log` VALUES (12090, 1, '用户', 'sys_user', 1, '登录', NULL,
DROP TABLE IF EXISTS `sys_menu`;
CREATE TABLE `sys_menu` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`parentid` int(11) NOT NULL DEFAULT 0 COMMENT '父id',
`parent_id` int(11) NOT NULL DEFAULT 0 COMMENT '父id',
`name` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '名称/11111',
`icon` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '菜单图标',
`urlkey` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '菜单key',
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module gcs

require (
github.com/goflyfox/gtoken v1.3.6
github.com/gogf/gf v1.9.10
github.com/goflyfox/gtoken v1.3.7
github.com/gogf/gf v1.10.0
)

go 1.13
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,30 @@ github.com/gf-third/yaml v1.0.1 h1:pqD4ix+65DqGphU1MDnToPZfGYk0tuuwRzuTSl3g0d0=
github.com/gf-third/yaml v1.0.1/go.mod h1:t443vj0txEw3+E0MOtkr83kt+PrZg2I8SRuYfn85NM0=
github.com/goflyfox/gtoken v1.3.5 h1:VqWKUxGEdo9dPAwEu4nqQRP7Y04XurVHjM/S+m8xVp4=
github.com/goflyfox/gtoken v1.3.5/go.mod h1:q44WQTSzDjn6e4/ZgIvyiH0ThAWzZfGtCrRQN4r7y/s=
github.com/goflyfox/gtoken v1.3.6 h1:gDnseDqSCWQrB5Pphy0VVMVClPE34zwIDv5FF0dWerw=
github.com/goflyfox/gtoken v1.3.6/go.mod h1:0r23tBl3H4DUMfjV+kNM4WEnyL96fCt0og2zt9dEN4k=
github.com/goflyfox/gtoken v1.3.7 h1:ANqlwMwMPlQYXsKaZ1chkqMMPtY8FQsGj6ju5vmyvfE=
github.com/goflyfox/gtoken v1.3.7/go.mod h1:7Es7wbBEyHVpa21yj6XBAb5dFyeEINq0XJyha1XBAy4=
github.com/gogf/gf v1.8.2 h1:SVHCXOZVHz2cFwNpQ9JrZYRPcXYT5+oaCTAw8uyjHUQ=
github.com/gogf/gf v1.8.2/go.mod h1:qJRcq0s3RskjJIZKsSHjZkpxw91rd0EAh+4CUbawbXQ=
github.com/gogf/gf v1.9.6 h1:3UBKrl2/+Wdpqs6oiRIHsMf40uaIdDQXpbnkGjXpNQU=
github.com/gogf/gf v1.9.6/go.mod h1:sitJZHjmT9B+923N4mH5rkM19AugKG+BxI47R64bR08=
github.com/gogf/gf v1.9.10 h1:lPBf0EOxv6AXVWN46EKLID0GMHDGOrs4ZAi/RUJbt+c=
github.com/gogf/gf v1.9.10/go.mod h1:sitJZHjmT9B+923N4mH5rkM19AugKG+BxI47R64bR08=
github.com/gogf/gf v1.10.0 h1:O6QwrdlQ06Nq/mp3EMwGckPA6xnWg2L+k5u+mYCiges=
github.com/gogf/gf v1.10.0/go.mod h1:/37gncPmuM06D4YSqiDze9GsasDtF2QnWkUfKeiGW/Q=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grokify/html-strip-tags-go v0.0.0-20190921062105-daaa06bf1aaf h1:wIOAyJMMen0ELGiFzlmqxdcV1yGbkyHBAB6PolcNbLA=
github.com/grokify/html-strip-tags-go v0.0.0-20190921062105-daaa06bf1aaf/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88=
github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand All @@ -39,9 +48,11 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190924092210-98129a5cf4a0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
google.golang.org/appengine v1.6.3/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
9 changes: 6 additions & 3 deletions module/common/loginAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ func LoginSubmit(r *ghttp.Request) (string, interface{}) {
base.Fail(r, "用户名或密码为空")
}

model := system.SysUser{Username: username}.GetByUsername()
model, err := system.SysUser{Username: username}.GetByUsername()
if err != nil {
base.Error(r, "服务异常,请联系管理员")
}

if model.Id <= 0 {
base.Fail(r, "用户名或密码错误:"+username)
Expand All @@ -52,8 +55,8 @@ func LoginSubmit(r *ghttp.Request) (string, interface{}) {
base.Fail(r, "账号状态异常,请联系管理员")
}

reqPassword, err := gmd5.Encrypt(passwd + model.Salt)
if err != nil {
reqPassword, err2 := gmd5.Encrypt(passwd + model.Salt)
if err2 != nil {
glog.Error("login password encrypt error", err)
base.Error(r, "login password encrypt error")
}
Expand Down
16 changes: 8 additions & 8 deletions module/component/middle/MiddlewareLog.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func MiddlewareLog(r *ghttp.Request) {
no = gconv.String(beforeTime)
}

glog.Info(fmt.Sprintf("[REQUEST_%s_%d][url:%s][params:%s]",
no, r.Id, r.URL.Path, params))
glog.Info(fmt.Sprintf("[REQUEST_%s][url:%s][params:%s]",
no, r.URL.Path, params))
}

r.Middleware.Next()
Expand All @@ -57,14 +57,14 @@ func MiddlewareLog(r *ghttp.Request) {
afterTime := gtime.Millisecond()

if r.IsFileRequest() {
glog.Info(fmt.Sprintf("[FILE_%s_%d][diff:%d][url:%s][params:%s]",
no, r.Id, afterTime-beforeTime, r.URL.Path, params))
glog.Info(fmt.Sprintf("[FILE_%s][diff:%d][url:%s][params:%s]",
no, afterTime-beforeTime, r.URL.Path, params))
} else if afterTime-beforeTime > 1000 {
glog.Warning(fmt.Sprintf("[RESPONSE_%s_%d][diff:%d][url:%s][params:%s][data:%s]",
no, r.Id, afterTime-beforeTime, r.URL.Path, params, data))
glog.Warning(fmt.Sprintf("[RESPONSE_%s][diff:%d][url:%s][params:%s][data:%s]",
no, afterTime-beforeTime, r.URL.Path, params, data))
} else {
glog.Info(fmt.Sprintf("[RESPONSE_%s_%d][diff:%d][url:%s][params:%s][data:%s]",
no, r.Id, afterTime-beforeTime, r.URL.Path, params, data))
glog.Info(fmt.Sprintf("[RESPONSE_%s][diff:%d][url:%s][params:%s][data:%s]",
no, afterTime-beforeTime, r.URL.Path, params, data))
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion module/system/departmentAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func (action *DepartmentAction) Get(r *ghttp.Request) {
func (action *DepartmentAction) Delete(r *ghttp.Request) {
id := r.GetInt("id")

form := base.NewForm(g.Map{"parentId": id})
childModel := SysDepartment{}.GetOne(&form)
if childModel.Id > 0 {
base.Fail(r, "请先删除子机构")
}

model := SysDepartment{Id: id}
model.UpdateId = base.GetUser(r).Id
model.UpdateTime = utils.GetNow()
Expand Down Expand Up @@ -102,7 +108,13 @@ func (action *DepartmentAction) Page(r *ghttp.Request) {
model := SysDepartment{}

page := model.Page(&form)
base.Succ(r, g.Map{"list": page, "form": form})
base.Succ(r,
g.Map{
"page": form.Page,
"rows": page,
"total": form.TotalPage,
"records": form.TotalSize,
})
}

// path: /jqgrid
Expand Down
4 changes: 4 additions & 0 deletions module/system/departmentModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func (model SysDepartment) GetOne(form *base.BaseForm) SysDepartment {
where += " and id = ? "
params = append(params, gconv.Int(form.Params["id"]))
}
if form.Params != nil && form.Params["parentId"] != "" {
where += " and parent_id = ? "
params = append(params, gconv.Int(form.Params["parentId"]))
}

var resData SysDepartment
err := model.dbModel("t").Where(where, params).Fields(model.columns()).Struct(&resData)
Expand Down
8 changes: 7 additions & 1 deletion module/system/logAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ func (action *LogAction) Page(r *ghttp.Request) {
model := SysLog{}

page := model.Page(&form)
base.Succ(r, g.Map{"list": page, "form": form})
base.Succ(r,
g.Map{
"page": form.Page,
"rows": page,
"total": form.TotalPage,
"records": form.TotalSize,
})
}

// path: /jqgrid
Expand Down
22 changes: 17 additions & 5 deletions module/system/menuAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func (action *MenuAction) Get(r *ghttp.Request) {
func (action *MenuAction) Delete(r *ghttp.Request) {
id := r.GetInt("id")

form := base.NewForm(g.Map{"parentId": id})
childModel := SysMenu{}.GetOne(&form)
if childModel.Id > 0 {
base.Fail(r, "请先删除子菜单")
}

model := SysMenu{Id: id}
model.UpdateId = base.GetUser(r).Id
model.UpdateTime = utils.GetNow()
Expand Down Expand Up @@ -87,17 +93,17 @@ func (action *MenuAction) Save(r *ghttp.Request) {
base.Succ(r, "")
}

// path: /list
func (action *MenuAction) List(r *ghttp.Request) {
// path: /tree
func (action *MenuAction) Tree(r *ghttp.Request) {
form := base.NewForm(r.GetPostMap())
model := SysMenu{}

list := model.List(&form)
base.Succ(r, list)
}

// path: /tree
func (action *MenuAction) Tree(r *ghttp.Request) {
// path: /list
func (action *MenuAction) List(r *ghttp.Request) {
form := base.NewForm(r.GetPostMap())
model := SysMenu{}

Expand All @@ -111,7 +117,13 @@ func (action *MenuAction) Page(r *ghttp.Request) {
model := SysMenu{}

page := model.Page(&form)
base.Succ(r, g.Map{"list": page, "form": form})
base.Succ(r,
g.Map{
"page": form.Page,
"rows": page,
"total": form.TotalPage,
"records": form.TotalSize,
})
}

// path: /jqgrid
Expand Down
30 changes: 17 additions & 13 deletions module/system/menuModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import (

type SysMenu struct {
// columns START
Id int `json:"id" gconv:"id,omitempty"` // 主键
Parentid int `json:"parentid" gconv:"parentid,omitempty"` // 父id
Name string `json:"name" gconv:"name,omitempty"` // 名称/11111
Icon string `json:"icon" gconv:"icon,omitempty"` // 菜单图标
Urlkey string `json:"urlkey" gconv:"urlkey,omitempty"` // 菜单key
Url string `json:"url" gconv:"url,omitempty"` // 链接地址
Perms string `json:"perms" gconv:"perms,omitempty"` // 授权(多个用逗号分隔,如:user:list,user:create)
Status int `json:"status" gconv:"status,omitempty"` // 状态//radio/2,隐藏,1,显示
Type int `json:"type" gconv:"type,omitempty"` // 类型//select/1,目录,2,菜单,3,按钮
Sort int `json:"sort" gconv:"sort,omitempty"` // 排序
Level int `json:"level" gconv:"level,omitempty"` // 级别
Id int `json:"id" gconv:"id,omitempty"` // 主键
ParentId int `json:"parentId" gconv:"parent_id,omitempty"` // 父id
Name string `json:"name" gconv:"name,omitempty"` // 名称/11111
Icon string `json:"icon" gconv:"icon,omitempty"` // 菜单图标
Urlkey string `json:"urlkey" gconv:"urlkey,omitempty"` // 菜单key
Url string `json:"url" gconv:"url,omitempty"` // 链接地址
Perms string `json:"perms" gconv:"perms,omitempty"` // 授权(多个用逗号分隔,如:user:list,user:create)
Status int `json:"status" gconv:"status,omitempty"` // 状态//radio/2,隐藏,1,显示
Type int `json:"type" gconv:"type,omitempty"` // 类型//select/1,目录,2,菜单,3,按钮
Sort int `json:"sort" gconv:"sort,omitempty"` // 排序
Level int `json:"level" gconv:"level,omitempty"` // 级别
// columns END

base.BaseModel
Expand Down Expand Up @@ -51,6 +51,10 @@ func (model SysMenu) GetOne(form *base.BaseForm) SysMenu {
where += " and id = ? "
params = append(params, gconv.Int(form.Params["id"]))
}
if form.Params != nil && form.Params["parentId"] != "" {
where += " and parent_id = ? "
params = append(params, gconv.Int(form.Params["parentId"]))
}

var resData SysMenu
err := model.dbModel("t").Where(where, params).Fields(model.columns()).Struct(&resData)
Expand Down Expand Up @@ -81,7 +85,7 @@ func (model SysMenu) ListUser(userId int, userType int) []SysMenu {
}

func (model SysMenu) List(form *base.BaseForm) []SysMenu {
where := " 1 = 1 and t.enable = 1 and t.status = 1 "
where := " 1 = 1 and t.enable = 1 and t.status = 1"
var params []interface{}
if form.Params != nil && form.Params["name"] != "" {
where += " and name like ? "
Expand Down Expand Up @@ -226,6 +230,6 @@ func (model SysMenu) TableName() string {
}

func (model SysMenu) columns() string {
sqlColumns := "t.id,t.parentid,t.name,t.icon,t.urlkey,t.url,t.perms,t.status,t.type,t.sort,t.level,t.enable,t.update_time as updateTime,t.update_id as updateId,t.create_time as createTime,t.create_id as createId"
sqlColumns := "t.id,t.parent_id as parentId,t.name,t.icon,t.urlkey,t.url,t.perms,t.status,t.type,t.sort,t.level,t.enable,t.update_time as updateTime,t.update_id as updateId,t.create_time as createTime,t.create_id as createId"
return sqlColumns
}
14 changes: 10 additions & 4 deletions module/system/roleAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func (action *RoleAction) Save(r *ghttp.Request) {
}

menus := r.GetPostString("menus")
if menus == "" {
base.Fail(r, "参数错误")
}
//if menus == "" {
// base.Fail(r, "参数错误")
//}

userId := base.GetUser(r).Id

Expand Down Expand Up @@ -111,7 +111,13 @@ func (action *RoleAction) Page(r *ghttp.Request) {
model := SysRole{}

page := model.Page(&form)
base.Succ(r, g.Map{"list": page, "form": form})
base.Succ(r,
g.Map{
"page": form.Page,
"rows": page,
"total": form.TotalPage,
"records": form.TotalSize,
})
}

// path: /jqgrid
Expand Down
5 changes: 5 additions & 0 deletions module/system/roleMenuModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ func (model *SysRoleMenu) Insert() int64 {
// 批量绑定菜单关系
func (model SysRoleMenu) saveRoleMenus(roleId int, menus string) {
SysRoleMenu{RoleId: roleId}.DeleteByRoleId()

// 空删除所有绑定菜单
if menus == "" {
return
}
menuIdArray := gstr.Split(menus, ",")
list := g.List{}
for _, menuId := range menuIdArray {
Expand Down
Loading

0 comments on commit 3c0414a

Please sign in to comment.