From 62153288158dd7cc6d0d46175aaad51d952b8d31 Mon Sep 17 00:00:00 2001 From: dyzsoft Date: Wed, 24 Nov 2021 15:23:22 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9Acasbin=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E4=BC=98=E5=8C=96=EF=BC=8C=E5=9C=A8=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E8=8E=B7=E5=8F=96=E8=AF=B7=E6=B1=82=E7=9A=84?= =?UTF-8?q?=20Path=EF=BC=8C=E5=9C=A8CasbinModel=E5=AE=9A=E4=B9=89=E4=B8=AD?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E4=BD=BF=E7=94=A8keymatch2=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=EF=BC=8C=E5=87=8F=E5=B0=91=E4=B8=80=E6=AC=A1?= =?UTF-8?q?path=E8=8E=B7=E5=8F=96=E5=92=8C=E5=87=BD=E6=95=B0=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E3=80=82=20server/middleware/casbin=5Frbac.go?= =?UTF-8?q?=EF=BC=9A18=E8=A1=8C=E4=BF=AE=E6=94=B9=E4=B8=BA=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E7=9A=84path=E4=BD=9C=E4=B8=BAobj=20server/service/sy?= =?UTF-8?q?stem/sys=5Fcasbin.go:=E5=88=A0=E6=8E=89=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E6=B3=A8=E5=86=8C=E5=87=BD=E6=95=B0=20server/resource?= =?UTF-8?q?/rbac=5Fmodel.conf=EF=BC=9A=E9=AA=8C=E8=AF=81=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BAkeyMathc2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/middleware/casbin_rbac.go | 4 ++-- server/resource/rbac_model.conf | 2 +- server/service/system/sys_casbin.go | 28 ---------------------------- 3 files changed, 3 insertions(+), 31 deletions(-) diff --git a/server/middleware/casbin_rbac.go b/server/middleware/casbin_rbac.go index b21345ec..ea9c9824 100644 --- a/server/middleware/casbin_rbac.go +++ b/server/middleware/casbin_rbac.go @@ -14,8 +14,8 @@ var casbinService = service.ServiceGroupApp.SystemServiceGroup.CasbinService func CasbinHandler() gin.HandlerFunc { return func(c *gin.Context) { waitUse, _ := utils.GetClaims(c) - // 获取请求的URI - obj := c.Request.URL.RequestURI() + // 获取请求的PATH + obj := c.Request.URL.Path // 获取请求方法 act := c.Request.Method // 获取用户的角色 diff --git a/server/resource/rbac_model.conf b/server/resource/rbac_model.conf index 04ebedff..b5918d45 100644 --- a/server/resource/rbac_model.conf +++ b/server/resource/rbac_model.conf @@ -11,4 +11,4 @@ g = _, _ e = some(where (p.eft == allow)) [matchers] -m = r.sub == p.sub && ParamsMatch(r.obj,p.obj) && r.act == p.act +m = r.sub == p.sub && keyMatch2(r.obj,p.obj) && r.act == p.act diff --git a/server/service/system/sys_casbin.go b/server/service/system/sys_casbin.go index c583ab07..118173c6 100644 --- a/server/service/system/sys_casbin.go +++ b/server/service/system/sys_casbin.go @@ -2,11 +2,9 @@ package system import ( "errors" - "strings" "sync" "github.com/casbin/casbin/v2" - "github.com/casbin/casbin/v2/util" gormadapter "github.com/casbin/gorm-adapter/v3" "github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/model/system" @@ -104,33 +102,7 @@ func (casbinService *CasbinService) Casbin() *casbin.SyncedEnforcer { once.Do(func() { a, _ := gormadapter.NewAdapterByDB(global.GVA_DB) syncedEnforcer, _ = casbin.NewSyncedEnforcer(global.GVA_CONFIG.Casbin.ModelPath, a) - syncedEnforcer.AddFunction("ParamsMatch", casbinService.ParamsMatchFunc) }) _ = syncedEnforcer.LoadPolicy() return syncedEnforcer } - -//@author: [piexlmax](https://github.com/piexlmax) -//@function: ParamsMatch -//@description: 自定义规则函数 -//@param: fullNameKey1 string, key2 string -//@return: bool - -func (casbinService *CasbinService) ParamsMatch(fullNameKey1 string, key2 string) bool { - key1 := strings.Split(fullNameKey1, "?")[0] - // 剥离路径后再使用casbin的keyMatch2 - return util.KeyMatch2(key1, key2) -} - -//@author: [piexlmax](https://github.com/piexlmax) -//@function: ParamsMatchFunc -//@description: 自定义规则函数 -//@param: args ...interface{} -//@return: interface{}, error - -func (casbinService *CasbinService) ParamsMatchFunc(args ...interface{}) (interface{}, error) { - name1 := args[0].(string) - name2 := args[1].(string) - - return casbinService.ParamsMatch(name1, name2), nil -} From 0e174786bf6c97e0393b8a583e34a1ec4697e035 Mon Sep 17 00:00:00 2001 From: bypanghu Date: Wed, 24 Nov 2021 15:58:43 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fixed:=20web=E5=85=A8=E7=AB=AF=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0gva=20=E6=9D=83=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/index.html | 13 ++-- web/package.json | 2 + web/src/core/config.js | 47 +++++++++++- web/src/core/gin-vue-admin.js | 26 +++++-- web/src/view/login/index.vue | 53 ++++++++++--- web/vite.config.js | 141 ++++++++++++++++++---------------- web/yarn.lock | 13 ++++ 7 files changed, 201 insertions(+), 94 deletions(-) diff --git a/web/index.html b/web/index.html index 7f114f9b..06ff7d4e 100644 --- a/web/index.html +++ b/web/index.html @@ -1,15 +1,18 @@ - + + - + + -
- +
+ - + + \ No newline at end of file diff --git a/web/package.json b/web/package.json index b32113d5..98a63abc 100644 --- a/web/package.json +++ b/web/package.json @@ -38,12 +38,14 @@ "@vue/compiler-sfc": "^3.1.5", "babel-eslint": "^10.1.0", "babel-plugin-import": "^1.13.3", + "chalk": "^4.1.2", "dotenv": "^10.0.0", "eslint": "^6.7.2", "eslint-plugin-vue": "^7.0.0", "sass": "^1.26.5", "sass-loader": "^8.0.2", "vite": "2", + "vite-plugin-banner": "^0.1.3", "vite-plugin-importer": "^0.2.5" } } diff --git a/web/src/core/config.js b/web/src/core/config.js index 920dc908..3ad93751 100644 --- a/web/src/core/config.js +++ b/web/src/core/config.js @@ -3,8 +3,49 @@ */ const config = { - appName: 'Gin-Vue-Admin', - appLogo: 'https://www.gin-vue-admin.com/img/logo.png' + appName: 'Gin-Vue-Admin', + appLogo: 'https://www.gin-vue-admin.com/img/logo.png', + showViteLogo: true } -export default config + +export const viteLogo = (env) => { + if (config.showViteLogo) { + const chalk = require('chalk') + console.log( + chalk.green( + `> 欢迎使用Gin-Vue-Admin,开源地址:https://github.com/flipped-aurora/gin-vue-admin` + ) + ) + console.log( + chalk.green( + `> 当前版本:V2.4.6 Apache` + ) + ) + console.log( + chalk.green( + `> 加群方式:微信:shouzi_1994 QQ群:622360840` + ) + ) + console.log( + chalk.green( + `> 默认自动化文档地址:http://127.0.0.1:${env.VITE_SERVER_PORT}/swagger/index.html` + ) + ) + console.log( + chalk.green( + `> 默认自动化文档地址:http://127.0.0.1:${env.VITE_SERVER_PORT}/swagger/index.html` + ) + ) + console.log( + chalk.green( + `> 默认前端文件运行地址:http://127.0.0.1:${env.VITE_CLI_PORT}` + ) + ) + console.log('\n') + } +} + + + +export default config \ No newline at end of file diff --git a/web/src/core/gin-vue-admin.js b/web/src/core/gin-vue-admin.js index 4e31d772..17443d18 100644 --- a/web/src/core/gin-vue-admin.js +++ b/web/src/core/gin-vue-admin.js @@ -7,12 +7,22 @@ import { register } from './global' export const run = function(app) { register(app) - console.log(` - 欢迎使用 Gin-Vue-Admin - 当前版本:V2.4.5 beta - 加群方式:微信:shouzi_1994 QQ群:622360840 - 默认自动化文档地址:http://127.0.0.1:${import.meta.env.VITE_SERVER_PORT}/swagger/index.html - 默认前端文件运行地址:http://127.0.0.1:${import.meta.env.VITE_CLI_PORT} - 如果项目让您获得了收益,希望您能请团队喝杯可乐:https://www.gin-vue-admin.com/docs/coffee - `) + console.log( + `%c gva启动完成 %c 当前版本V2.4.6 Apache%c`, + 'background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', + 'background:#007aff ;padding: 1px 5px; border-radius: 0 3px 3px 0; color: #fff; font-weight: bold;', + 'background:transparent' + ) + console.log(`欢迎使用 %c Gin-Vue-Admin %c +%c 微信 %c shouzi_1994 %c +%c QQ群 %c 622360840 %c + `, + 'background:#007aff ;padding: 1px 5px; border-radius: 3px; color: #fff; font-weight: bold;margin-bottom:4px;', + 'background:transparent', + 'background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', + 'background:#007aff ;padding: 1px 5px; border-radius: 0 3px 3px 0; color: #fff; font-weight: bold;;margin-bottom:4px;', + 'background:transparent', + 'background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', + 'background:#007aff ;padding: 1px 5px; border-radius: 0 3px 3px 0; color: #fff; font-weight: bold;;margin-bottom:4px;', + 'background:transparent') } \ No newline at end of file diff --git a/web/src/view/login/index.vue b/web/src/view/login/index.vue index aa49d5c4..e76c022d 100644 --- a/web/src/view/login/index.vue +++ b/web/src/view/login/index.vue @@ -3,10 +3,19 @@