Merge pull request #504 from go-admin-team/dev

1. 修复菜单的目录(#500)
1. 调整字段判断逻辑
This commit is contained in:
wenjianzhang authored and GitHub committed 2021-07-23 00:43:34 +08:00
commit 25395b5006
2 files changed
+33 -20

No files matched your search

+18 -18
View File
@@ -55,8 +55,8 @@ func (s *ResetSysUserPwdReq) Generate(model *models.SysUser) {
}
type UpdateSysUserAvatarReq struct {
UserId int `json:"userId" comment:"用户ID" vd:"required"` // 用户ID
Avatar string `json:"avatar" comment:"头像" vd:"required"`
UserId int `json:"userId" comment:"用户ID" vd:"len($)>0"` // 用户ID
Avatar string `json:"avatar" comment:"头像" vd:"len($)>0"`
common.ControlBy
}
@@ -72,8 +72,8 @@ func (s *UpdateSysUserAvatarReq) Generate(model *models.SysUser) {
}
type UpdateSysUserStatusReq struct {
UserId int `json:"userId" comment:"用户ID" vd:"required"` // 用户ID
Status string `json:"status" comment:"状态" vd:"required"`
UserId int `json:"userId" comment:"用户ID" vd:"$>0"` // 用户ID
Status string `json:"status" comment:"状态" vd:"len($)>0"`
common.ControlBy
}
@@ -90,18 +90,18 @@ func (s *UpdateSysUserStatusReq) Generate(model *models.SysUser) {
type SysUserInsertReq struct {
UserId int `json:"userId" comment:"用户ID"` // 用户ID
Username string `json:"username" comment:"用户名" vd:"required"`
Username string `json:"username" comment:"用户名" vd:"len($)>0"`
Password string `json:"password" comment:"密码"`
NickName string `json:"nickName" comment:"昵称" vd:"required"`
Phone string `json:"phone" comment:"手机号" vd:"required"`
NickName string `json:"nickName" comment:"昵称" vd:"len($)>0"`
Phone string `json:"phone" comment:"手机号" vd:"len($)>0"`
RoleId int `json:"roleId" comment:"角色ID"`
Avatar string `json:"avatar" comment:"头像"`
Sex string `json:"sex" comment:"性别"`
Email string `json:"email" comment:"邮箱" vd:"required,email"`
DeptId int `json:"deptId" comment:"部门" vd:"required"`
Email string `json:"email" comment:"邮箱" vd:"len($)>0,email"`
DeptId int `json:"deptId" comment:"部门" vd:"len($)>0"`
PostId int `json:"postId" comment:"岗位"`
Remark string `json:"remark" comment:"备注"`
Status string `json:"status" comment:"状态" vd:"required" default:"1"`
Status string `json:"status" comment:"状态" vd:"len($)>0" default:"1"`
common.ControlBy
}
@@ -129,17 +129,17 @@ func (s *SysUserInsertReq) GetId() interface{} {
type SysUserUpdateReq struct {
UserId int `json:"userId" comment:"用户ID"` // 用户ID
Username string `json:"username" comment:"用户名" vd:"required"`
NickName string `json:"nickName" comment:"昵称" vd:"required"`
Phone string `json:"phone" comment:"手机号" vd:"required"`
Username string `json:"username" comment:"用户名" vd:"len($)>0"`
NickName string `json:"nickName" comment:"昵称" vd:"len($)>0"`
Phone string `json:"phone" comment:"手机号" vd:"len($)>0"`
RoleId int `json:"roleId" comment:"角色ID"`
Avatar string `json:"avatar" comment:"头像"`
Sex string `json:"sex" comment:"性别"`
Email string `json:"email" comment:"邮箱" vd:"required,email"`
DeptId int `json:"deptId" comment:"部门" vd:"required"`
Email string `json:"email" comment:"邮箱" vd:"len($)>0,email"`
DeptId int `json:"deptId" comment:"部门" vd:"$>0"`
PostId int `json:"postId" comment:"岗位"`
Remark string `json:"remark" comment:"备注"`
Status string `json:"status" comment:"状态" vd:"required" default:"1"`
Status string `json:"status" comment:"状态" default:"1"`
common.ControlBy
}
@@ -183,6 +183,6 @@ func (s *SysUserById) GenerateM() (common.ActiveRecord, error) {
// PassWord 密码
type PassWord struct {
NewPassword string `json:"newPassword" vd:"required"`
OldPassword string `json:"oldPassword" vd:"required"`
NewPassword string `json:"newPassword" vd:"len($)>0"`
OldPassword string `json:"oldPassword" vd:"len($)>0"`
}
+15 -2
View File
@@ -2,7 +2,6 @@ package service
import (
"errors"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"gorm.io/gorm"
@@ -333,11 +332,25 @@ func (e *SysMenu) getByRoleName(roleName string) ([]models.SysMenu, error) {
} else {
role.RoleKey = roleName
err = e.Orm.Debug().Model(&role).Where("role_key = ? ", roleName).Preload("SysMenu", func(db *gorm.DB) *gorm.DB {
return db.Where(" menu_type in ('M','C')").Order("sort")
return db.Where(" menu_type in ('C')").Order("sort")
}).Find(&role).Error
if role.SysMenu != nil {
MenuList = *role.SysMenu
}
mIds := make([]int, 0)
for _, menu := range MenuList {
if menu.ParentId != 0 {
mIds = append(mIds, menu.ParentId)
}
}
var data []models.SysMenu
err = e.Orm.Where(" menu_type in ('M') and menu_id in ?", mIds).Order("sort").Find(&data).Error
if err != nil {
return nil, err
}
for _, datum := range data {
MenuList = append(MenuList, datum)
}
}
if err != nil {