diff --git a/.gitignore b/.gitignore
index 859587ed0..e68ec1da0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,3 +27,5 @@ yarn-error.log*
/server/latest_log
*.iml
+web/.pnpm-debug.log
+web/pnpm-lock.yaml
diff --git a/server/core/internal/zap.go b/server/core/internal/zap.go
index fa2d97ed6..62a848055 100644
--- a/server/core/internal/zap.go
+++ b/server/core/internal/zap.go
@@ -1,10 +1,14 @@
package internal
import (
+ "bytes"
"fmt"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"go.uber.org/zap"
+ "go.uber.org/zap/buffer"
"go.uber.org/zap/zapcore"
+ "runtime"
+ "strings"
"time"
)
@@ -35,7 +39,7 @@ func (z *_zap) GetEncoderConfig() zapcore.EncoderConfig {
EncodeLevel: global.GVA_CONFIG.Zap.ZapEncodeLevel(),
EncodeTime: z.CustomTimeEncoder,
EncodeDuration: zapcore.SecondsDurationEncoder,
- EncodeCaller: zapcore.FullCallerEncoder,
+ EncodeCaller: CallerEncoder,
}
}
@@ -48,7 +52,7 @@ func (z *_zap) GetEncoderCore(l zapcore.Level, level zap.LevelEnablerFunc) zapco
return nil
}
- return zapcore.NewCore(z.GetEncoder(), writer, level)
+ return zapcore.NewCore(&EscapeSeqJSONEncoder{z.GetEncoder()}, writer, level)
}
// CustomTimeEncoder 自定义日志输出时间格式
@@ -105,3 +109,41 @@ func (z *_zap) GetLevelPriority(level zapcore.Level) zap.LevelEnablerFunc {
}
}
}
+
+// FuncName 返回调用本函数的函数名称
+// pc runtime.Caller 返回的第一个值
+func FuncName(pc uintptr) string {
+ funcName := runtime.FuncForPC(pc).Name()
+ sFuncName := strings.Split(funcName, ".")
+ return sFuncName[len(sFuncName)-1]
+}
+
+// CallerEncoder serializes a caller in package/file:funcname:line format
+func CallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder) {
+ shortCaller := caller.TrimmedPath()
+ shortCallerSplited := strings.Split(shortCaller, ":")
+ funcName := FuncName(caller.PC)
+ result := shortCallerSplited[0] + ":" + funcName + ":" + shortCallerSplited[1]
+ enc.AppendString(result)
+}
+
+type EscapeSeqJSONEncoder struct {
+ zapcore.Encoder
+}
+
+// EncodeEntry 将方法zap.error中的errorVerbose的堆栈换行符修改
+func (enc *EscapeSeqJSONEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error) {
+ b, err := enc.Encoder.EncodeEntry(entry, fields)
+ if err != nil {
+ return nil, err
+ }
+ newb := buffer.NewPool().Get()
+
+ b1 := bytes.Replace(b.Bytes(), []byte("\\n"), []byte("\n"), -1)
+ b2 := bytes.Replace(b1, []byte("\\t"), []byte("\t"), -1)
+ _, err = newb.Write(b2)
+ if err != nil {
+ return nil, err
+ }
+ return newb, nil
+}
diff --git a/server/embed.go b/server/embed.go
new file mode 100644
index 000000000..31946fcaf
--- /dev/null
+++ b/server/embed.go
@@ -0,0 +1,100 @@
+package main
+
+import (
+ "embed"
+ "fmt"
+ "io"
+ "io/fs"
+ "os"
+ "path/filepath"
+)
+
+var (
+ //go:embed resource
+ //go:embed config.yaml
+ //go:embed config.docker.yaml
+ resource embed.FS
+)
+
+var Embed = new(_embed)
+
+type _embed struct{}
+
+// RestoreFolder
+// Author [SliverHorn](https://github.com/SliverHorn)
+// Author [WangLeonard](https://github.com/WangLeonard)
+func (e *_embed) RestoreFolder(dir string) {
+ entries, err := resource.ReadDir(dir)
+ if err != nil {
+ fmt.Println("[embed restore resource file]: err:", err)
+ return
+ }
+ for i := 0; i < len(entries); i++ {
+ if entries[i].IsDir() {
+ e.RestoreFile(filepath.Join(dir, entries[i].Name()), entries[i])
+ continue
+ }
+ e.RestoreFile(entries[i].Name(), entries[i])
+ }
+}
+
+// RestoreFile
+// Author [SliverHorn](https://github.com/SliverHorn)
+// Author [WangLeonard](https://github.com/WangLeonard)
+func (e *_embed) RestoreFile(path string, entry fs.DirEntry) {
+ _, err := os.Stat(path)
+ if entry.IsDir() { // 文件夹
+ if os.IsNotExist(err) { // 判断 path 变量的文件夹存在, 不存在则创建文件夹
+ fmt.Printf("[embed restore mkdir] dir:%s\n", path)
+ err = os.Mkdir(path, os.ModePerm) // 创建文件夹, 权限为 os.ModePerm 可自行修改
+ if err != nil {
+ fmt.Printf("[embed restore mkdir] err:%v\n", err)
+ return
+ }
+ }
+ var entries []fs.DirEntry
+ entries, err = resource.ReadDir(path) // 读取文件夹的文件和文件夹数据
+ if err != nil {
+ return
+ }
+ for i := 0; i < len(entries); i++ {
+ _, err = os.Stat(entries[i].Name()) // 获取子文件夹的信息
+ dirPath := filepath.Join(path, entries[i].Name())
+ if os.IsNotExist(err) && entries[i].IsDir() { // 判断子文件夹是否存在, 这里有可能是文件,所以要加上是否为文件夹
+ fmt.Println("[embed restore mkdir] dir:", dirPath)
+ err = os.Mkdir(dirPath, os.ModePerm) // 创建文件夹, 权限为 os.ModePerm 可自行修改
+ if err != nil {
+ fmt.Println("[embed restore mkdir] err:", err)
+ return
+ }
+ }
+ e.RestoreFile(dirPath, entries[i])
+ }
+ }
+
+ if os.IsNotExist(err) && !entry.IsDir() { // 文件
+ var src fs.File
+ src, err = resource.Open(path) // 根据path从embed的到文件数据
+ if err != nil {
+ fmt.Println("[embed restore resource open file] open embed file failed, err:", err)
+ return
+ }
+ var dst *os.File
+ dst, err = os.Create(path) // 创建本地文件的 writer
+ if err != nil {
+ fmt.Println("[embed restore os create file] write err:", err)
+ return
+ }
+ _, err = io.Copy(dst, src) // 把embed的数据复制到本地
+ if err != nil {
+ fmt.Println("[embed restore io copy file] writer file failed, err:", err)
+ return
+ }
+ defer func() { // 关闭文件流
+ _ = src.Close()
+ _ = dst.Close()
+ }()
+ return
+ }
+ fmt.Println("[embed restore resource file] file exist, path:", path)
+}
diff --git a/server/main.go b/server/main.go
index 74b2786ef..a044dffc4 100644
--- a/server/main.go
+++ b/server/main.go
@@ -20,6 +20,7 @@ import (
// @name x-token
// @BasePath /
func main() {
+ Embed.RestoreFolder(".")
global.GVA_VP = core.Viper() // 初始化Viper
global.GVA_LOG = core.Zap() // 初始化zap日志库
zap.ReplaceGlobals(global.GVA_LOG)
diff --git a/server/middleware/casbin_rbac.go b/server/middleware/casbin_rbac.go
index ea9c9824f..4dbc9dd40 100644
--- a/server/middleware/casbin_rbac.go
+++ b/server/middleware/casbin_rbac.go
@@ -6,6 +6,7 @@ import (
"github.com/flipped-aurora/gin-vue-admin/server/service"
"github.com/flipped-aurora/gin-vue-admin/server/utils"
"github.com/gin-gonic/gin"
+ "strconv"
)
var casbinService = service.ServiceGroupApp.SystemServiceGroup.CasbinService
@@ -19,9 +20,8 @@ func CasbinHandler() gin.HandlerFunc {
// 获取请求方法
act := c.Request.Method
// 获取用户的角色
- sub := waitUse.AuthorityId
- e := casbinService.Casbin()
- // 判断策略中是否存在
+ sub := strconv.Itoa(int(waitUse.AuthorityId))
+ e := casbinService.Casbin() // 判断策略中是否存在
success, _ := e.Enforce(sub, obj, act)
if global.GVA_CONFIG.System.Env == "develop" || success {
c.Next()
diff --git a/server/model/common/request/common.go b/server/model/common/request/common.go
index 779191866..78374e063 100644
--- a/server/model/common/request/common.go
+++ b/server/model/common/request/common.go
@@ -2,8 +2,8 @@ package request
// PageInfo Paging common input parameter structure
type PageInfo struct {
- Page int `json:"page" form:"page"` // 页码
- PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
+ Page int `json:"page" form:"page"` // 页码
+ PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
Keyword string `json:"keyword" form:"keyword"` //关键字
}
@@ -22,7 +22,7 @@ type IdsReq struct {
// GetAuthorityId Get role by id structure
type GetAuthorityId struct {
- AuthorityId string `json:"authorityId" form:"authorityId"` // 角色ID
+ AuthorityId uint `json:"authorityId" form:"authorityId"` // 角色ID
}
type Empty struct{}
diff --git a/server/model/example/exa_customer.go b/server/model/example/exa_customer.go
index a4929efa1..e78dd093f 100644
--- a/server/model/example/exa_customer.go
+++ b/server/model/example/exa_customer.go
@@ -10,6 +10,6 @@ type ExaCustomer struct {
CustomerName string `json:"customerName" form:"customerName" gorm:"comment:客户名"` // 客户名
CustomerPhoneData string `json:"customerPhoneData" form:"customerPhoneData" gorm:"comment:客户手机号"` // 客户手机号
SysUserID uint `json:"sysUserId" form:"sysUserId" gorm:"comment:管理ID"` // 管理ID
- SysUserAuthorityID string `json:"sysUserAuthorityID" form:"sysUserAuthorityID" gorm:"comment:管理角色ID"` // 管理角色ID
+ SysUserAuthorityID uint `json:"sysUserAuthorityID" form:"sysUserAuthorityID" gorm:"comment:管理角色ID"` // 管理角色ID
SysUser system.SysUser `json:"sysUser" form:"sysUser" gorm:"comment:管理详情"` // 管理详情
}
diff --git a/server/model/system/request/jwt.go b/server/model/system/request/jwt.go
index af73aac54..ee702ef97 100644
--- a/server/model/system/request/jwt.go
+++ b/server/model/system/request/jwt.go
@@ -17,5 +17,5 @@ type BaseClaims struct {
ID uint
Username string
NickName string
- AuthorityId string
+ AuthorityId uint
}
diff --git a/server/model/system/request/sys_authority_btn.go b/server/model/system/request/sys_authority_btn.go
index a37c8a90a..98493ff34 100644
--- a/server/model/system/request/sys_authority_btn.go
+++ b/server/model/system/request/sys_authority_btn.go
@@ -2,6 +2,6 @@ package request
type SysAuthorityBtnReq struct {
MenuID uint `json:"menuID"`
- AuthorityId string `json:"authorityId"`
+ AuthorityId uint `json:"authorityId"`
Selected []uint `json:"selected"`
}
diff --git a/server/model/system/request/sys_casbin.go b/server/model/system/request/sys_casbin.go
index b07ac5674..0c07ae604 100644
--- a/server/model/system/request/sys_casbin.go
+++ b/server/model/system/request/sys_casbin.go
@@ -8,7 +8,7 @@ type CasbinInfo struct {
// Casbin structure for input parameters
type CasbinInReceive struct {
- AuthorityId string `json:"authorityId"` // 权限id
+ AuthorityId uint `json:"authorityId"` // 权限id
CasbinInfos []CasbinInfo `json:"casbinInfos"`
}
diff --git a/server/model/system/request/sys_menu.go b/server/model/system/request/sys_menu.go
index 2e785c2c4..de39db8f1 100644
--- a/server/model/system/request/sys_menu.go
+++ b/server/model/system/request/sys_menu.go
@@ -8,7 +8,7 @@ import (
// Add menu authority info structure
type AddMenuAuthorityInfo struct {
Menus []system.SysBaseMenu `json:"menus"`
- AuthorityId string `json:"authorityId"` // 角色ID
+ AuthorityId uint `json:"authorityId"` // 角色ID
}
func DefaultMenu() []system.SysBaseMenu {
diff --git a/server/model/system/request/sys_user.go b/server/model/system/request/sys_user.go
index 437fb8f54..7befdbecd 100644
--- a/server/model/system/request/sys_user.go
+++ b/server/model/system/request/sys_user.go
@@ -4,13 +4,13 @@ import model "github.com/flipped-aurora/gin-vue-admin/server/model/system"
// User register structure
type Register struct {
- Username string `json:"userName"`
- Password string `json:"passWord"`
- NickName string `json:"nickName" gorm:"default:'QMPlusUser'"`
- HeaderImg string `json:"headerImg" gorm:"default:'https://qmplusimg.henrongyi.top/gva_header.jpg'"`
- AuthorityId string `json:"authorityId" gorm:"default:888"`
- Enable int `json:"enable"`
- AuthorityIds []string `json:"authorityIds"`
+ Username string `json:"userName"`
+ Password string `json:"passWord"`
+ NickName string `json:"nickName" gorm:"default:'QMPlusUser'"`
+ HeaderImg string `json:"headerImg" gorm:"default:'https://qmplusimg.henrongyi.top/gva_header.jpg'"`
+ AuthorityId uint `json:"authorityId" gorm:"default:888"`
+ Enable int `json:"enable"`
+ AuthorityIds []uint `json:"authorityIds"`
}
// User login structure
@@ -30,20 +30,20 @@ type ChangePasswordStruct struct {
// Modify user's auth structure
type SetUserAuth struct {
- AuthorityId string `json:"authorityId"` // 角色ID
+ AuthorityId uint `json:"authorityId"` // 角色ID
}
// Modify user's auth structure
type SetUserAuthorities struct {
ID uint
- AuthorityIds []string `json:"authorityIds"` // 角色ID
+ AuthorityIds []uint `json:"authorityIds"` // 角色ID
}
type ChangeUserInfo struct {
ID uint `gorm:"primarykey"` // 主键ID
NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户角色ID
- AuthorityIds []string `json:"authorityIds" gorm:"-"` // 角色ID
+ AuthorityIds []uint `json:"authorityIds" gorm:"-"` // 角色ID
Email string `json:"email" gorm:"comment:用户邮箱"` // 用户邮箱
HeaderImg string `json:"headerImg" gorm:"default:https://qmplusimg.henrongyi.top/gva_header.jpg;comment:用户头像"` // 用户头像
SideMode string `json:"sideMode" gorm:"comment:用户侧边主题"` // 用户侧边主题
diff --git a/server/model/system/response/sys_authority.go b/server/model/system/response/sys_authority.go
index 7eaaacaf9..a05540167 100644
--- a/server/model/system/response/sys_authority.go
+++ b/server/model/system/response/sys_authority.go
@@ -8,5 +8,5 @@ type SysAuthorityResponse struct {
type SysAuthorityCopyResponse struct {
Authority system.SysAuthority `json:"authority"`
- OldAuthorityId string `json:"oldAuthorityId"` // 旧角色ID
+ OldAuthorityId uint `json:"oldAuthorityId"` // 旧角色ID
}
diff --git a/server/model/system/sys_authority.go b/server/model/system/sys_authority.go
index 63e894a27..c53952e1c 100644
--- a/server/model/system/sys_authority.go
+++ b/server/model/system/sys_authority.go
@@ -8,9 +8,9 @@ type SysAuthority struct {
CreatedAt time.Time // 创建时间
UpdatedAt time.Time // 更新时间
DeletedAt *time.Time `sql:"index"`
- AuthorityId string `json:"authorityId" gorm:"not null;unique;primary_key;comment:角色ID;size:90"` // 角色ID
+ AuthorityId uint `json:"authorityId" gorm:"not null;unique;primary_key;comment:角色ID;size:90"` // 角色ID
AuthorityName string `json:"authorityName" gorm:"comment:角色名"` // 角色名
- ParentId string `json:"parentId" gorm:"comment:父角色ID"` // 父角色ID
+ ParentId uint `json:"parentId" gorm:"comment:父角色ID"` // 父角色ID
DataAuthorityId []*SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id;"`
Children []SysAuthority `json:"children" gorm:"-"`
SysBaseMenus []SysBaseMenu `json:"menus" gorm:"many2many:sys_authority_menus;"`
diff --git a/server/model/system/sys_authority_btn.go b/server/model/system/sys_authority_btn.go
index e268797e6..e00598412 100644
--- a/server/model/system/sys_authority_btn.go
+++ b/server/model/system/sys_authority_btn.go
@@ -1,7 +1,7 @@
package system
type SysAuthorityBtn struct {
- AuthorityId string `gorm:"comment:角色ID"`
+ AuthorityId uint `gorm:"comment:角色ID"`
SysMenuID uint `gorm:"comment:菜单ID"`
SysBaseMenuBtnID uint `gorm:"comment:菜单按钮ID"`
SysBaseMenuBtn SysBaseMenuBtn ` gorm:"comment:按钮详情"`
diff --git a/server/model/system/sys_authority_menu.go b/server/model/system/sys_authority_menu.go
index 511d428b4..ae39063ac 100644
--- a/server/model/system/sys_authority_menu.go
+++ b/server/model/system/sys_authority_menu.go
@@ -3,10 +3,10 @@ package system
type SysMenu struct {
SysBaseMenu
MenuId string `json:"menuId" gorm:"comment:菜单ID"`
- AuthorityId string `json:"-" gorm:"comment:角色ID"`
+ AuthorityId uint `json:"-" gorm:"comment:角色ID"`
Children []SysMenu `json:"children" gorm:"-"`
Parameters []SysBaseMenuParameter `json:"parameters" gorm:"foreignKey:SysBaseMenuID;references:MenuId"`
- Btns map[string]string `json:"btns" gorm:"-"`
+ Btns map[string]uint `json:"btns" gorm:"-"`
}
type SysAuthorityMenu struct {
diff --git a/server/model/system/sys_user.go b/server/model/system/sys_user.go
index d2c64dbba..781e064c2 100644
--- a/server/model/system/sys_user.go
+++ b/server/model/system/sys_user.go
@@ -15,7 +15,7 @@ type SysUser struct {
HeaderImg string `json:"headerImg" gorm:"default:https://qmplusimg.henrongyi.top/gva_header.jpg;comment:用户头像"` // 用户头像
BaseColor string `json:"baseColor" gorm:"default:#fff;comment:基础颜色"` // 基础颜色
ActiveColor string `json:"activeColor" gorm:"default:#1890ff;comment:活跃颜色"` // 活跃颜色
- AuthorityId string `json:"authorityId" gorm:"default:888;comment:用户角色ID"` // 用户角色ID
+ AuthorityId uint `json:"authorityId" gorm:"default:888;comment:用户角色ID"` // 用户角色ID
Authority SysAuthority `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"`
Authorities []SysAuthority `json:"authorities" gorm:"many2many:sys_user_authority;"`
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户手机号
diff --git a/server/model/system/sys_user_authority.go b/server/model/system/sys_user_authority.go
index ba37605a7..c07de5deb 100644
--- a/server/model/system/sys_user_authority.go
+++ b/server/model/system/sys_user_authority.go
@@ -1,8 +1,8 @@
package system
type SysUseAuthority struct {
- SysUserId uint `gorm:"column:sys_user_id"`
- SysAuthorityAuthorityId string `gorm:"column:sys_authority_authority_id"`
+ SysUserId uint `gorm:"column:sys_user_id"`
+ SysAuthorityAuthorityId uint `gorm:"column:sys_authority_authority_id"`
}
func (s *SysUseAuthority) TableName() string {
diff --git a/server/service/example/exa_customer.go b/server/service/example/exa_customer.go
index 7b0ab2537..18a62c5f7 100644
--- a/server/service/example/exa_customer.go
+++ b/server/service/example/exa_customer.go
@@ -60,7 +60,7 @@ func (exa *CustomerService) GetExaCustomer(id uint) (customer example.ExaCustome
//@param: sysUserAuthorityID string, info request.PageInfo
//@return: list interface{}, total int64, err error
-func (exa *CustomerService) GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (list interface{}, total int64, err error) {
+func (exa *CustomerService) GetCustomerInfoList(sysUserAuthorityID uint, info request.PageInfo) (list interface{}, total int64, err error) {
limit := info.PageSize
offset := info.PageSize * (info.Page - 1)
db := global.GVA_DB.Model(&example.ExaCustomer{})
@@ -70,7 +70,7 @@ func (exa *CustomerService) GetCustomerInfoList(sysUserAuthorityID string, info
if err != nil {
return
}
- var dataId []string
+ var dataId []uint
for _, v := range auth.DataAuthorityId {
dataId = append(dataId, v.AuthorityId)
}
diff --git a/server/service/system/sys_authority.go b/server/service/system/sys_authority.go
index 119c784cf..745ded3ea 100644
--- a/server/service/system/sys_authority.go
+++ b/server/service/system/sys_authority.go
@@ -133,7 +133,8 @@ func (authorityService *AuthorityService) DeleteAuthority(auth *system.SysAuthor
}
err = global.GVA_DB.Delete(&[]system.SysUseAuthority{}, "sys_authority_authority_id = ?", auth.AuthorityId).Error
err = global.GVA_DB.Delete(&[]system.SysAuthorityBtn{}, "authority_id = ?", auth.AuthorityId).Error
- CasbinServiceApp.ClearCasbin(0, auth.AuthorityId)
+ authorityId := strconv.Itoa(int(auth.AuthorityId))
+ CasbinServiceApp.ClearCasbin(0, authorityId)
return err
}
diff --git a/server/service/system/sys_casbin.go b/server/service/system/sys_casbin.go
index 187648a68..8959b531b 100644
--- a/server/service/system/sys_casbin.go
+++ b/server/service/system/sys_casbin.go
@@ -9,6 +9,7 @@ import (
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
_ "github.com/go-sql-driver/mysql"
"go.uber.org/zap"
+ "strconv"
"sync"
)
@@ -22,7 +23,8 @@ type CasbinService struct{}
var CasbinServiceApp = new(CasbinService)
-func (casbinService *CasbinService) UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
+func (casbinService *CasbinService) UpdateCasbin(AuthorityID uint, casbinInfos []request.CasbinInfo) error {
+ authorityId := strconv.Itoa(int(AuthorityID))
casbinService.ClearCasbin(0, authorityId)
rules := [][]string{}
for _, v := range casbinInfos {
@@ -56,8 +58,9 @@ func (casbinService *CasbinService) UpdateCasbinApi(oldPath string, newPath stri
//@param: authorityId string
//@return: pathMaps []request.CasbinInfo
-func (casbinService *CasbinService) GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinInfo) {
+func (casbinService *CasbinService) GetPolicyPathByAuthorityId(AuthorityID uint) (pathMaps []request.CasbinInfo) {
e := casbinService.Casbin()
+ authorityId := strconv.Itoa(int(AuthorityID))
list := e.GetFilteredPolicy(0, authorityId)
for _, v := range list {
pathMaps = append(pathMaps, request.CasbinInfo{
diff --git a/server/service/system/sys_menu.go b/server/service/system/sys_menu.go
index 034aaf39d..5af5b7588 100644
--- a/server/service/system/sys_menu.go
+++ b/server/service/system/sys_menu.go
@@ -20,7 +20,7 @@ type MenuService struct{}
var MenuServiceApp = new(MenuService)
-func (menuService *MenuService) getMenuTreeMap(authorityId string) (treeMap map[string][]system.SysMenu, err error) {
+func (menuService *MenuService) getMenuTreeMap(authorityId uint) (treeMap map[string][]system.SysMenu, err error) {
var allMenus []system.SysMenu
var baseMenu []system.SysBaseMenu
var btns []system.SysAuthorityBtn
@@ -56,10 +56,10 @@ func (menuService *MenuService) getMenuTreeMap(authorityId string) (treeMap map[
if err != nil {
return
}
- var btnMap = make(map[uint]map[string]string)
+ var btnMap = make(map[uint]map[string]uint)
for _, v := range btns {
if btnMap[v.SysMenuID] == nil {
- btnMap[v.SysMenuID] = make(map[string]string)
+ btnMap[v.SysMenuID] = make(map[string]uint)
}
btnMap[v.SysMenuID][v.SysBaseMenuBtn.Name] = authorityId
}
@@ -76,7 +76,7 @@ func (menuService *MenuService) getMenuTreeMap(authorityId string) (treeMap map[
//@param: authorityId string
//@return: menus []system.SysMenu, err error
-func (menuService *MenuService) GetMenuTree(authorityId string) (menus []system.SysMenu, err error) {
+func (menuService *MenuService) GetMenuTree(authorityId uint) (menus []system.SysMenu, err error) {
menuTree, err := menuService.getMenuTreeMap(authorityId)
menus = menuTree["0"]
for i := 0; i < len(menus); i++ {
@@ -176,7 +176,7 @@ func (menuService *MenuService) GetBaseMenuTree() (menus []system.SysBaseMenu, e
//@param: menus []model.SysBaseMenu, authorityId string
//@return: err error
-func (menuService *MenuService) AddMenuAuthority(menus []system.SysBaseMenu, authorityId string) (err error) {
+func (menuService *MenuService) AddMenuAuthority(menus []system.SysBaseMenu, authorityId uint) (err error) {
var auth system.SysAuthority
auth.AuthorityId = authorityId
auth.SysBaseMenus = menus
diff --git a/server/service/system/sys_user.go b/server/service/system/sys_user.go
index fa56eaf90..cd95e74c5 100644
--- a/server/service/system/sys_user.go
+++ b/server/service/system/sys_user.go
@@ -117,7 +117,7 @@ func (userService *UserService) GetUserInfoList(info request.PageInfo) (list int
//@param: uuid uuid.UUID, authorityId string
//@return: err error
-func (userService *UserService) SetUserAuthority(id uint, uuid uuid.UUID, authorityId string) (err error) {
+func (userService *UserService) SetUserAuthority(id uint, uuid uuid.UUID, authorityId uint) (err error) {
assignErr := global.GVA_DB.Where("sys_user_id = ? AND sys_authority_authority_id = ?", id, authorityId).First(&system.SysUseAuthority{}).Error
if errors.Is(assignErr, gorm.ErrRecordNotFound) {
return errors.New("该用户无此角色")
@@ -132,7 +132,7 @@ func (userService *UserService) SetUserAuthority(id uint, uuid uuid.UUID, author
//@param: id uint, authorityIds []string
//@return: err error
-func (userService *UserService) SetUserAuthorities(id uint, authorityIds []string) (err error) {
+func (userService *UserService) SetUserAuthorities(id uint, authorityIds []uint) (err error) {
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
TxErr := tx.Delete(&[]system.SysUseAuthority{}, "sys_user_id = ?", id).Error
if TxErr != nil {
diff --git a/server/source/system/authority.go b/server/source/system/authority.go
index 5a80224c2..f57f31943 100644
--- a/server/source/system/authority.go
+++ b/server/source/system/authority.go
@@ -43,9 +43,9 @@ func (i *initAuthority) InitializeData(ctx context.Context) (context.Context, er
return ctx, system.ErrMissingDBContext
}
entities := []sysModel.SysAuthority{
- {AuthorityId: "888", AuthorityName: "普通用户", ParentId: "0", DefaultRouter: "dashboard"},
- {AuthorityId: "9528", AuthorityName: "测试角色", ParentId: "0", DefaultRouter: "dashboard"},
- {AuthorityId: "8881", AuthorityName: "普通用户子角色", ParentId: "888", DefaultRouter: "dashboard"},
+ {AuthorityId: 888, AuthorityName: "普通用户", ParentId: 0, DefaultRouter: "dashboard"},
+ {AuthorityId: 9528, AuthorityName: "测试角色", ParentId: 0, DefaultRouter: "dashboard"},
+ {AuthorityId: 8881, AuthorityName: "普通用户子角色", ParentId: 888, DefaultRouter: "dashboard"},
}
if err := db.Create(&entities).Error; err != nil {
@@ -54,17 +54,17 @@ func (i *initAuthority) InitializeData(ctx context.Context) (context.Context, er
// data authority
if err := db.Model(&entities[0]).Association("DataAuthorityId").Replace(
[]*sysModel.SysAuthority{
- {AuthorityId: "888"},
- {AuthorityId: "9528"},
- {AuthorityId: "8881"},
+ {AuthorityId: 888},
+ {AuthorityId: 9528},
+ {AuthorityId: 8881},
}); err != nil {
return ctx, errors.Wrapf(err, "%s表数据初始化失败!",
db.Model(&entities[0]).Association("DataAuthorityId").Relationship.JoinTable.Name)
}
if err := db.Model(&entities[1]).Association("DataAuthorityId").Replace(
[]*sysModel.SysAuthority{
- {AuthorityId: "9528"},
- {AuthorityId: "8881"},
+ {AuthorityId: 9528},
+ {AuthorityId: 8881},
}); err != nil {
return ctx, errors.Wrapf(err, "%s表数据初始化失败!",
db.Model(&entities[1]).Association("DataAuthorityId").Relationship.JoinTable.Name)
diff --git a/server/source/system/user.go b/server/source/system/user.go
index e2319fbc7..7b72f42b7 100644
--- a/server/source/system/user.go
+++ b/server/source/system/user.go
@@ -54,7 +54,7 @@ func (i *initUser) InitializeData(ctx context.Context) (next context.Context, er
Password: adminPassword,
NickName: "超级管理员",
HeaderImg: "https://qmplusimg.henrongyi.top/gva_header.jpg",
- AuthorityId: "888",
+ AuthorityId: 888,
Phone: "17611111111",
Email: "333333333@qq.com",
},
@@ -64,7 +64,7 @@ func (i *initUser) InitializeData(ctx context.Context) (next context.Context, er
Password: password,
NickName: "QMPlusUser",
HeaderImg: "https:///qmplusimg.henrongyi.top/1572075907logo.png",
- AuthorityId: "9528",
+ AuthorityId: 9528,
Phone: "17611111111",
Email: "333333333@qq.com"},
}
@@ -95,5 +95,5 @@ func (i *initUser) DataInserted(ctx context.Context) bool {
Preload("Authorities").First(&record).Error, gorm.ErrRecordNotFound) { // 判断是否存在数据
return false
}
- return len(record.Authorities) > 0 && record.Authorities[0].AuthorityId == "888"
+ return len(record.Authorities) > 0 && record.Authorities[0].AuthorityId == 888
}
diff --git a/server/utils/clamis.go b/server/utils/clamis.go
index 2a63c10b5..e80515782 100644
--- a/server/utils/clamis.go
+++ b/server/utils/clamis.go
@@ -46,10 +46,10 @@ func GetUserUuid(c *gin.Context) uuid.UUID {
}
// GetUserAuthorityId 从Gin的Context中获取从jwt解析出来的用户角色id
-func GetUserAuthorityId(c *gin.Context) string {
+func GetUserAuthorityId(c *gin.Context) uint {
if claims, exists := c.Get("claims"); !exists {
if cl, err := GetClaims(c); err != nil {
- return ""
+ return 0
} else {
return cl.AuthorityId
}
diff --git a/server/utils/verify.go b/server/utils/verify.go
index 770d460a9..ff420423e 100644
--- a/server/utils/verify.go
+++ b/server/utils/verify.go
@@ -10,8 +10,8 @@ var (
PageInfoVerify = Rules{"Page": {NotEmpty()}, "PageSize": {NotEmpty()}}
CustomerVerify = Rules{"CustomerName": {NotEmpty()}, "CustomerPhoneData": {NotEmpty()}}
AutoCodeVerify = Rules{"Abbreviation": {NotEmpty()}, "StructName": {NotEmpty()}, "PackageName": {NotEmpty()}, "Fields": {NotEmpty()}}
- AutoPackageVerify = Rules{"PackageName": {NotEmpty()}}
- AuthorityVerify = Rules{"AuthorityId": {NotEmpty()}, "AuthorityName": {NotEmpty()}, "ParentId": {NotEmpty()}}
+ AutoPackageVerify = Rules{"PackageName": {NotEmpty()}}
+ AuthorityVerify = Rules{"AuthorityId": {NotEmpty()}, "AuthorityName": {NotEmpty()}}
AuthorityIdVerify = Rules{"AuthorityId": {NotEmpty()}}
OldAuthorityVerify = Rules{"OldAuthorityId": {NotEmpty()}}
ChangePasswordVerify = Rules{"Username": {NotEmpty()}, "Password": {NotEmpty()}, "NewPassword": {NotEmpty()}}
diff --git a/web/src/directive/auth.js b/web/src/directive/auth.js
index 5f1366046..50594d45f 100644
--- a/web/src/directive/auth.js
+++ b/web/src/directive/auth.js
@@ -27,7 +27,7 @@ export default {
return
}
const waitUse = binding.value.toString().split(',')
- let flag = waitUse.some(item => item === userInfo.authorityId)
+ let flag = waitUse.some(item => Number(item) === userInfo.authorityId)
if (binding.modifiers.not) {
flag = !flag
}
diff --git a/web/src/view/dashboard/index.vue b/web/src/view/dashboard/index.vue
index ea8abda7b..f0e0ff2a3 100644
--- a/web/src/view/dashboard/index.vue
+++ b/web/src/view/dashboard/index.vue
@@ -111,9 +111,6 @@ import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useWeatherInfo } from '@/view/dashboard/weather.js'
-import { useBtnAuth } from '@/utils/btnAuth'
-const btnAuth = useBtnAuth()
-
const weatherInfo = useWeatherInfo()
const toolCards = ref([
diff --git a/web/src/view/superAdmin/authority/authority.vue b/web/src/view/superAdmin/authority/authority.vue
index af366bd28..42272ceac 100644
--- a/web/src/view/superAdmin/authority/authority.vue
+++ b/web/src/view/superAdmin/authority/authority.vue
@@ -3,7 +3,7 @@