未验证 提交 68317c1f 编写于 作者: Mr.奇淼('s avatar Mr.奇淼( 提交者: GitHub

调整角色ID为uint格式,增加embed打包,更改日志格式。 (#1144)

* feature: 根据 #377 pr进行修改embed, 打包静态文件夹与配置文件

* 修改角色id为uint

* 修改日志格式
Co-authored-by: Sliver_Horn's avatarSliverHorn <503551462@qq.com>
Co-authored-by: cg831344's avatarcg81344 <cg831344@126.com>
上级 78e6271f
......@@ -27,3 +27,5 @@ yarn-error.log*
/server/latest_log
*.iml
web/.pnpm-debug.log
web/pnpm-lock.yaml
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
}
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)
}
......@@ -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)
......
......@@ -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()
......
......@@ -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{}
......@@ -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:管理详情"` // 管理详情
}
......@@ -17,5 +17,5 @@ type BaseClaims struct {
ID uint
Username string
NickName string
AuthorityId string
AuthorityId uint
}
......@@ -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"`
}
......@@ -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"`
}
......
......@@ -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 {
......
......@@ -8,9 +8,9 @@ type Register struct {
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"`
AuthorityId uint `json:"authorityId" gorm:"default:888"`
Enable int `json:"enable"`
AuthorityIds []string `json:"authorityIds"`
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:用户侧边主题"` // 用户侧边主题
......
......@@ -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
}
......@@ -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;"`
......
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:按钮详情"`
......
......@@ -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 {
......
......@@ -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:用户手机号"` // 用户手机号
......
......@@ -2,7 +2,7 @@ package system
type SysUseAuthority struct {
SysUserId uint `gorm:"column:sys_user_id"`
SysAuthorityAuthorityId string `gorm:"column:sys_authority_authority_id"`
SysAuthorityAuthorityId uint `gorm:"column:sys_authority_authority_id"`
}
func (s *SysUseAuthority) TableName() string {
......
......@@ -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)
}
......
......@@ -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
}
......
......@@ -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{
......
......@@ -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
......
......@@ -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 {
......
......@@ -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)
......
......@@ -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
}
......@@ -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
}
......
......@@ -11,7 +11,7 @@ var (
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()}}
AuthorityVerify = Rules{"AuthorityId": {NotEmpty()}, "AuthorityName": {NotEmpty()}}
AuthorityIdVerify = Rules{"AuthorityId": {NotEmpty()}}
OldAuthorityVerify = Rules{"OldAuthorityId": {NotEmpty()}}
ChangePasswordVerify = Rules{"Username": {NotEmpty()}, "Password": {NotEmpty()}, "NewPassword": {NotEmpty()}}
......
......@@ -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
}
......
......@@ -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([
......
......@@ -3,7 +3,7 @@
<warning-bar title="注:右上角头像下拉可切换角色" />
<div class="gva-table-box">
<div class="gva-btn-list">
<el-button size="small" type="primary" icon="plus" @click="addAuthority('0')">新增角色</el-button>
<el-button size="small" type="primary" icon="plus" @click="addAuthority(0)">新增角色</el-button>
</div>
<el-table
:data="tableData"
......@@ -125,7 +125,7 @@ const mustUint = (rule, value, callback) => {
const AuthorityOption = ref([
{
authorityId: '0',
authorityId: 0,
authorityName: '根角色'
}
])
......@@ -139,20 +139,20 @@ const apiDialogFlag = ref(false)
const copyForm = ref({})
const form = ref({
authorityId: '',
authorityId: 0,
authorityName: '',
parentId: '0'
parentId: 0
})
const rules = ref({
authorityId: [
{ required: true, message: '请输入角色ID', trigger: 'blur' },
{ validator: mustUint, trigger: 'blur' }
{ validator: mustUint, trigger: 'blur', message: '必须为正整数' }
],
authorityName: [
{ required: true, message: '请输入角色名', trigger: 'blur' }
],
parentId: [
{ required: true, message: '请选择请求方式', trigger: 'blur' }
{ required: true, message: '请选择父角色', trigger: 'blur' },
]
})
......@@ -239,9 +239,9 @@ const initForm = () => {
authorityForm.value.resetFields()
}
form.value = {
authorityId: '',
authorityId: 0,
authorityName: '',
parentId: '0'
parentId: 0
}
}
// 关闭窗口
......@@ -253,7 +253,8 @@ const closeDialog = () => {
// 确定弹窗
const enterDialog = () => {
if (form.value.authorityId === '0') {
form.value.authorityId = Number(form.value.authorityId)
if (form.value.authorityId === 0) {
ElMessage({
type: 'error',
message: '角色id不能为0'
......@@ -292,10 +293,10 @@ const enterDialog = () => {
case 'copy': {
const data = {
authority: {
authorityId: 'string',
authorityName: 'string',
authorityId: 0,
authorityName: '',
datauthorityId: [],
parentId: 'string'
parentId: 0
},
oldAuthorityId: 0
}
......@@ -323,7 +324,7 @@ const enterDialog = () => {
const setOptions = () => {
AuthorityOption.value = [
{
authorityId: '0',
authorityId: 0,
authorityName: '根角色'
}
]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册