diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 123e1ebf..fb65e63f 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -16,10 +16,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- - name: Set up Go 1.15
+ - name: Set up Go 1.18
uses: actions/setup-go@v3
with:
- go-version: 1.15
+ go-version: 1.18
id: go
- name: Check out code into the Go module directory
diff --git a/README.Zh-cn.md b/README.Zh-cn.md
index f1e65809..4126e065 100644
--- a/README.Zh-cn.md
+++ b/README.Zh-cn.md
@@ -13,14 +13,18 @@
[在线文档](https://doc.go-admin.dev)
-[github在线文档](https://wenjianzhang.github.io)
-
-[gitee在线文档](http://mydearzwj.gitee.io/go-admin-doc/)
-
[前端项目](https://github.com/go-admin-team/go-admin-ui)
[视频教程](https://space.bilibili.com/565616721/channel/detail?cid=125737)
+## 🎬 在线体验
+
+vue体验:[https://www.go-admin.dev](https://www.go-admin.dev/#/login)
+> ⚠️⚠️⚠️ 账号 / 密码: admin / 123456
+
+antd体验:[https://preview.go-admin.dev](https://preview.go-admin.dev/)
+> ⚠️⚠️⚠️ 账号 / 密码: admin / 123456
+
## ✨ 特性
- 遵循 RESTful API 设计规范
@@ -102,7 +106,7 @@
### 环境要求
-go 1.17
+go 1.18
node版本: v14.16.0
@@ -238,12 +242,6 @@ npm install --registry=https://registry.npm.taobao.org
npm run dev
```
-## 🎬 在线体验
-
-> admin / 123456
-
-演示地址:[http://www.go-admin.dev](http://www.go-admin.dev/#/login)
-
## 📨 互动
@@ -259,12 +257,34 @@ npm run dev
-## 💎 主要成员
+## 💎 贡献者
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
## JetBrains 开源证书支持
@@ -274,7 +294,8 @@ npm run dev
## 🤝 特别感谢
-1. [chengxiao](https://github.com/chengxiao)
+1. [ant-design](https://github.com/ant-design/ant-design)
+2. [ant-design-pro](https://github.com/ant-design/ant-design-pro)
2. [gin](https://github.com/gin-gonic/gin)
2. [casbin](https://github.com/casbin/casbin)
2. [spf13/viper](https://github.com/spf13/viper)
@@ -285,6 +306,7 @@ npm run dev
2. [ruoyi-vue](https://gitee.com/y_project/RuoYi-Vue)
2. [form-generator](https://github.com/JakHuang/form-generator)
+
## 🤟 打赏
> 如果你觉得这个项目帮助到了你,你可以帮作者买一杯果汁表示鼓励 :tropical_drink:
@@ -299,4 +321,4 @@ npm run dev
[MIT](https://github.com/go-admin-team/go-admin/blob/master/LICENSE.md)
-Copyright (c) 2020 wenjianzhang
+Copyright (c) 2022 wenjianzhang
diff --git a/README.md b/README.md
index ddc66d84..596e5d4c 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,14 @@ The front-end and back-end separation authority management system based on Gin +
[Video tutorial](https://space.bilibili.com/565616721/channel/detail?cid=125737)
+## 🎬 Online Demo
+
+vue demo:[https://www.go-admin.dev](https://www.go-admin.dev/#/login)
+> 账号 / 密码: admin / 123456
+
+antd demo:[https://preview.go-admin.dev](https://preview.go-admin.dev/)
+> 账号 / 密码: admin / 123456
+>
## ✨ Feature
- Follow RESTful API design specifications
@@ -96,7 +104,7 @@ At the same time, a series of tutorials including videos and documents are provi
### Environmental requirements
-go 1.17
+go 1.18
nodejs: v14.16.0
@@ -222,12 +230,6 @@ npm install # or cnpm install
npm run dev
```
-## 🎬 Online Demo
-> admin / 123456
-
-演示地址:[http://www.go-admin.dev](http://www.go-admin.dev/#/login)
-
-
## 📨 Interactive
@@ -241,12 +243,33 @@ npm run dev
-## 💎 Members
+## 💎 Contributors
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -258,7 +281,9 @@ The `go-admin` project has always been developed in the GoLand integrated develo
## 🤝 Thanks
-1. [chengxiao](https://github.com/chengxiao)
+
+1. [ant-design](https://github.com/ant-design/ant-design)
+2. [ant-design-pro](https://github.com/ant-design/ant-design-pro)
2. [gin](https://github.com/gin-gonic/gin)
2. [casbin](https://github.com/casbin/casbin)
2. [spf13/viper](https://github.com/spf13/viper)
@@ -282,4 +307,4 @@ The `go-admin` project has always been developed in the GoLand integrated develo
[MIT](https://github.com/go-admin-team/go-admin/blob/master/LICENSE.md)
-Copyright (c) 2020 wenjianzhang
+Copyright (c) 2022 wenjianzhang
diff --git a/app/admin/apis/sys_role.go b/app/admin/apis/sys_role.go
index 1a1e75b0..d7ee1e7f 100644
--- a/app/admin/apis/sys_role.go
+++ b/app/admin/apis/sys_role.go
@@ -2,6 +2,7 @@ package apis
import (
"fmt"
+ "go-admin/common/global"
"net/http"
"github.com/gin-gonic/gin/binding"
@@ -128,7 +129,12 @@ func (e SysRole) Insert(c *gin.Context) {
e.Error(500, err, "创建失败,"+err.Error())
return
}
-
+ _, err = global.LoadPolicy(c)
+ if err != nil {
+ e.Logger.Error(err)
+ e.Error(500, err, "创建失败,"+err.Error())
+ return
+ }
e.OK(req.GetId(), "创建成功")
}
@@ -165,6 +171,13 @@ func (e SysRole) Update(c *gin.Context) {
return
}
+ _, err = global.LoadPolicy(c)
+ if err != nil {
+ e.Logger.Error(err)
+ e.Error(500, err, "更新失败,"+err.Error())
+ return
+ }
+
e.OK(req.GetId(), "更新成功")
}
diff --git a/app/admin/service/sys_menu.go b/app/admin/service/sys_menu.go
index e2d8a35e..1bdb3746 100644
--- a/app/admin/service/sys_menu.go
+++ b/app/admin/service/sys_menu.go
@@ -1,9 +1,10 @@
package service
import (
- "errors"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
+ "github.com/pkg/errors"
"gorm.io/gorm"
+ "strings"
"go-admin/app/admin/models"
"go-admin/app/admin/service/dto"
@@ -92,6 +93,11 @@ func (e *SysMenu) Insert(c *dto.SysMenuInsertReq) *SysMenu {
_ = e.AddError(err)
}
c.MenuId = data.MenuId
+ err = e.initPaths(&data)
+ if err != nil {
+ e.Log.Errorf("db error:%s", err)
+ _ = e.AddError(err)
+ }
return e
}
@@ -127,6 +133,7 @@ func (e *SysMenu) Update(c *dto.SysMenuUpdateReq) *SysMenu {
var alist = make([]models.SysApi, 0)
var model = models.SysMenu{}
tx.Preload("SysApi").First(&model, c.GetId())
+ oldPath := model.Paths
tx.Where("id in ?", c.Apis).Find(&alist)
err = tx.Model(&model).Association("SysApi").Delete(model.SysApi)
if err != nil {
@@ -146,6 +153,12 @@ func (e *SysMenu) Update(c *dto.SysMenuUpdateReq) *SysMenu {
_ = e.AddError(errors.New("无权更新该数据"))
return e
}
+ var menuList []models.SysMenu
+ tx.Where("paths like ?", oldPath+"%").Find(&menuList)
+ for _, v := range menuList {
+ v.Paths = strings.Replace(v.Paths, oldPath, model.Paths, 1)
+ tx.Model(&v).Update("paths", v.Paths)
+ }
return e
}
@@ -321,55 +334,46 @@ func (e *SysMenu) SetMenuRole(roleName string) (m []models.SysMenu, err error) {
}
func (e *SysMenu) getByRoleName(roleName string) ([]models.SysMenu, error) {
- var MenuList []models.SysMenu
var role models.SysRole
var err error
if roleName == "admin" {
var data []models.SysMenu
- err = e.Orm.Where(" menu_type in ('M','C')").Order("sort").Find(&data).Error
- MenuList = data
+ err = e.Orm.Where(" menu_type in ('M','C') and deleted_at is null and created_at>'2021-08-13'").
+ Order("sort").
+ Find(&data).
+ Error
+ err = errors.WithStack(err)
+ return data, err
} else {
role.RoleKey = roleName
- buttons := make([]models.SysMenu,0)
- err = e.Orm.Debug().Model(&role).Where("role_key = ? ", roleName).Preload("SysMenu", func(db *gorm.DB) *gorm.DB {
- return db.Where(" menu_type in ('F')").Order("sort")
- }).Find(&role).Error
- if role.SysMenu != nil {
- buttons = *role.SysMenu
- }
- mIds := make([]int, 0)
- for _, menu := range buttons {
- if menu.ParentId != 0 {
- mIds = append(mIds, menu.ParentId)
- }
- }
- var dataC []models.SysMenu
- err = e.Orm.Where(" menu_type in ('C') and menu_id in ?", mIds).Order("sort").Find(&dataC).Error
- if err != nil {
- return nil, err
- }
- for _, datum := range dataC {
- MenuList = append(MenuList, datum)
- }
- cIds := make([]int, 0)
+ err = e.Orm.
+ Model(&role).
+ Where("role_key = ? ", roleName).
+ Preload("SysMenu", func(db *gorm.DB) *gorm.DB {
+ return db.Where(" menu_type in ('F','C')").Order("sort")
+ }).
+ Find(&role).Error
+ MenuList := *role.SysMenu
+ mIds := make([]string, 0)
+ mp := make(map[string]string, 0)
for _, menu := range MenuList {
- if menu.ParentId != 0 {
- cIds = append(cIds, menu.ParentId)
+ ids := strings.Split(menu.Paths, "/")
+ for _, id := range ids {
+ if mp[id] == "" {
+ mp[id] = id
+ mIds = append(mIds, id)
+ }
}
}
- var dataM []models.SysMenu
- err = e.Orm.Where(" menu_type in ('M') and menu_id in ?", cIds).Order("sort").Find(&dataM).Error
+ var data []models.SysMenu
+ err = e.Orm.Where(" menu_id in ? and menu_type in ('M','C')", mIds).
+ Order("sort").
+ Find(&data).
+ Error
if err != nil {
return nil, err
}
- for _, datum := range dataM {
- MenuList = append(MenuList, datum)
- }
+ return data, err
}
-
- if err != nil {
- e.Log.Errorf("db error:%s", err)
- }
- return MenuList, err
}
diff --git a/cmd/migrate/migration/version/1599190683659_tables.go b/cmd/migrate/migration/version/1599190683659_tables.go
index 64780788..5862dae3 100644
--- a/cmd/migrate/migration/version/1599190683659_tables.go
+++ b/cmd/migrate/migration/version/1599190683659_tables.go
@@ -17,7 +17,7 @@ func init() {
func _1599190683659Tables(db *gorm.DB, version string) error {
return db.Transaction(func(tx *gorm.DB) error {
- err := tx.Debug().Migrator().AutoMigrate(
+ err := tx.Set("gorm:table_options", "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4").Migrator().AutoMigrate(
new(models.CasbinRule),
new(models.SysDept),
new(models.SysConfig),
diff --git a/common/global/adm.go b/common/global/adm.go
index 510aedbd..6f40ad99 100644
--- a/common/global/adm.go
+++ b/common/global/adm.go
@@ -2,7 +2,7 @@ package global
const (
// Version go-admin version info
- Version = "2.0.12"
+ Version = "2.1.0"
)
var (
diff --git a/common/middleware/customerror.go b/common/middleware/customerror.go
index a16dccbb..121a2e7a 100644
--- a/common/middleware/customerror.go
+++ b/common/middleware/customerror.go
@@ -2,7 +2,6 @@ package middleware
import (
"fmt"
- "go-admin/common"
"net/http"
"strconv"
"strings"
@@ -34,13 +33,18 @@ func CustomError(c *gin.Context) {
c.Request.URL,
statusCode,
c.Request.RequestURI,
- common.GetClientIP(c),
+ c.ClientIP(),
p[2],
)
c.JSON(http.StatusOK, gin.H{
"code": statusCode,
"msg": p[2],
})
+ } else {
+ c.JSON(http.StatusOK, gin.H{
+ "code": 500,
+ "msg": "未知异常,请联系管理员!",
+ })
}
default:
panic(err)
diff --git a/go.mod b/go.mod
index 22321ed9..022df7ab 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
module go-admin
-go 1.15
+go 1.18
require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
@@ -16,7 +16,6 @@ require (
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.12+incompatible
github.com/mssola/user_agent v0.5.2
github.com/opentracing/opentracing-go v1.1.0
- github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.0
github.com/qiniu/go-sdk/v7 v7.11.1
github.com/robfig/cron/v3 v3.0.1
@@ -26,10 +25,110 @@ require (
github.com/swaggo/swag v1.6.7
github.com/unrolled/secure v1.0.8
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
- golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
gorm.io/driver/mysql v1.0.4-0.20201206014609-ae5fd10184f6
gorm.io/driver/postgres v1.0.6-0.20201208020313-1ed927cfab53
gorm.io/driver/sqlite v1.1.5-0.20201206014648-c84401fbe3ba
gorm.io/driver/sqlserver v1.0.4
gorm.io/gorm v1.21.11
)
+
+require (
+ github.com/BurntSushi/toml v0.3.1 // indirect
+ github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect
+ github.com/KyleBanks/depth v1.2.1 // indirect
+ github.com/PuerkitoBio/purell v1.1.1 // indirect
+ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
+ github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
+ github.com/beorn7/perks v1.0.1 // indirect
+ github.com/bsm/redislock v0.5.0 // indirect
+ github.com/cespare/xxhash/v2 v2.1.1 // indirect
+ github.com/chanxuehong/rand v0.0.0-20201110082127-2f19a1bdd973 // indirect
+ github.com/chanxuehong/wechat v0.0.0-20201110083048-0180211b69fd // indirect
+ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc // indirect
+ github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
+ github.com/fatih/color v1.9.0 // indirect
+ github.com/fsnotify/fsnotify v1.4.7 // indirect
+ github.com/ghodss/yaml v1.0.0 // indirect
+ github.com/gin-contrib/sse v0.1.0 // indirect
+ github.com/git-chglog/git-chglog v0.0.0-20190611050339-63a4e637021f // indirect
+ github.com/go-admin-team/go-admin-core/plugins/logger/zap v0.0.0-20210610020726-2db73adb505d // indirect
+ github.com/go-admin-team/gorm-adapter/v3 v3.2.1-0.20210902112335-4148cb356a24 // indirect
+ github.com/go-ole/go-ole v1.2.6 // indirect
+ github.com/go-openapi/jsonpointer v0.19.3 // indirect
+ github.com/go-openapi/jsonreference v0.19.3 // indirect
+ github.com/go-openapi/spec v0.19.4 // indirect
+ github.com/go-openapi/swag v0.19.5 // indirect
+ github.com/go-playground/locales v0.14.0 // indirect
+ github.com/go-playground/universal-translator v0.18.0 // indirect
+ github.com/go-playground/validator/v10 v10.8.0 // indirect
+ github.com/go-redis/redis/v7 v7.4.0 // indirect
+ github.com/go-sql-driver/mysql v1.5.0 // indirect
+ github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
+ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
+ github.com/golang/protobuf v1.4.3 // indirect
+ github.com/golang/snappy v0.0.1 // indirect
+ github.com/gorilla/websocket v1.4.2 // indirect
+ github.com/henrylee2cn/ameda v1.4.10 // indirect
+ github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 // indirect
+ github.com/imdario/mergo v0.3.9 // indirect
+ github.com/inconshreveable/mousetrap v1.0.0 // indirect
+ github.com/jackc/chunkreader/v2 v2.0.1 // indirect
+ github.com/jackc/pgconn v1.8.0 // indirect
+ github.com/jackc/pgio v1.0.0 // indirect
+ github.com/jackc/pgpassfile v1.0.0 // indirect
+ github.com/jackc/pgproto3/v2 v2.0.6 // indirect
+ github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
+ github.com/jackc/pgtype v1.6.2 // indirect
+ github.com/jackc/pgx/v4 v4.10.0 // indirect
+ github.com/jinzhu/inflection v1.0.0 // indirect
+ github.com/jinzhu/now v1.1.2 // indirect
+ github.com/json-iterator/go v1.1.11 // indirect
+ github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
+ github.com/leodido/go-urn v1.2.1 // indirect
+ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
+ github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e // indirect
+ github.com/mattn/go-colorable v0.1.7 // indirect
+ github.com/mattn/go-isatty v0.0.12 // indirect
+ github.com/mattn/go-sqlite3 v1.14.5 // indirect
+ github.com/mattn/goveralls v0.0.2 // indirect
+ github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
+ github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
+ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
+ github.com/modern-go/reflect2 v1.0.1 // indirect
+ github.com/mojocn/base64Captcha v1.3.1 // indirect
+ github.com/nsqio/go-nsq v1.0.8 // indirect
+ github.com/nyaruka/phonenumbers v1.0.55 // indirect
+ github.com/pkg/errors v0.9.1 // indirect
+ github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
+ github.com/prometheus/client_model v0.2.0 // indirect
+ github.com/prometheus/common v0.26.0 // indirect
+ github.com/prometheus/procfs v0.6.0 // indirect
+ github.com/robinjoseph08/redisqueue/v2 v2.1.0 // indirect
+ github.com/shamsher31/goimgext v1.0.0 // indirect
+ github.com/shirou/gopsutil v2.19.12+incompatible // indirect
+ github.com/spf13/cast v1.3.1 // indirect
+ github.com/spf13/pflag v1.0.3 // indirect
+ github.com/tklauser/go-sysconf v0.3.9 // indirect
+ github.com/tklauser/numcpus v0.3.0 // indirect
+ github.com/tsuyoshiwada/go-gitcmd v0.0.0-20180205145712-5f1f5f9475df // indirect
+ github.com/ugorji/go/codec v1.1.7 // indirect
+ github.com/urfave/cli v1.22.1 // indirect
+ github.com/yusufpapurcu/wmi v1.2.2 // indirect
+ go.uber.org/atomic v1.6.0 // indirect
+ go.uber.org/multierr v1.5.0 // indirect
+ go.uber.org/zap v1.15.0 // indirect
+ golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect
+ golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
+ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
+ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect
+ golang.org/x/sys v0.0.0-20220111092808-5a964db01320 // indirect
+ golang.org/x/text v0.3.7 // indirect
+ golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
+ golang.org/x/tools v0.0.0-20210106214847-113979e3529a // indirect
+ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
+ google.golang.org/protobuf v1.26.0-rc.1 // indirect
+ gopkg.in/AlecAivazis/survey.v1 v1.8.5 // indirect
+ gopkg.in/kyokomi/emoji.v1 v1.5.1 // indirect
+ gopkg.in/yaml.v2 v2.3.0 // indirect
+ gorm.io/plugin/dbresolver v1.1.0 // indirect
+)