Dev273 (#1868)
* fixed: 修复addFunction下前端api.js无法创建的bug。 * feature: 增加严格角色模式 * Update system.vue * fixed: 多点登录拦截模式下,jwt换票期间不需要拉黑token。 * fixed: 修复使用ast时候产生无意义的换行的问题 * fixed: 修复跨级操作角色权限的越权问题 * feature: 优化严格模式角色鉴权操作。 * fixed: 增加菜单和api设置越权问题的限制 * feature: 增加插件打包前的自动化同步所需菜单和api的功能 * feature: 自动化代码可以默认生成导入导出 * feature: 自动化导入导出对模板进行回滚 * feature: 剔除无用的packfile代码包 * feature: 发布V2.7.3版本公测。 --------- Co-authored-by: task <ms.yangdan@gmail.com>
This commit is contained in:
@@ -1,13 +1,21 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/utils"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/utils/ast"
|
||||
"github.com/mholt/archiver/v4"
|
||||
cp "github.com/otiai10/copy"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
"go/parser"
|
||||
"go/printer"
|
||||
"go/token"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"os"
|
||||
@@ -172,3 +180,70 @@ func (s *autoCodePlugin) PubPlug(plugName string) (zipPath string, err error) {
|
||||
|
||||
return filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, fileName), nil
|
||||
}
|
||||
|
||||
func (s *autoCodePlugin) InitMenu(menuInfo request.InitMenu) (err error) {
|
||||
menuPath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin", menuInfo.PlugName, "initialize", "menu.go")
|
||||
src, err := os.ReadFile(menuPath)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
fileSet := token.NewFileSet()
|
||||
astFile, err := parser.ParseFile(fileSet, "", src, 0)
|
||||
arrayAst := ast.FindArray(astFile, "model", "SysBaseMenu")
|
||||
var menus []system.SysBaseMenu
|
||||
|
||||
parentMenu := []system.SysBaseMenu{
|
||||
{
|
||||
ParentId: 0,
|
||||
Path: menuInfo.PlugName + "Menu",
|
||||
Name: menuInfo.PlugName + "Menu",
|
||||
Hidden: false,
|
||||
Component: "view/routerHolder.vue",
|
||||
Sort: 0,
|
||||
Meta: system.Meta{
|
||||
Title: menuInfo.ParentMenu,
|
||||
Icon: "school",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err = global.GVA_DB.Find(&menus, "id in (?)", menuInfo.Menus).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
menus = append(parentMenu, menus...)
|
||||
menuExpr := ast.CreateMenuStructAst(menus)
|
||||
arrayAst.Elts = *menuExpr
|
||||
|
||||
var out []byte
|
||||
bf := bytes.NewBuffer(out)
|
||||
printer.Fprint(bf, fileSet, astFile)
|
||||
|
||||
os.WriteFile(menuPath, bf.Bytes(), 0666)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *autoCodePlugin) InitAPI(apiInfo request.InitApi) (err error) {
|
||||
apiPath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin", apiInfo.PlugName, "initialize", "api.go")
|
||||
src, err := os.ReadFile(apiPath)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
fileSet := token.NewFileSet()
|
||||
astFile, err := parser.ParseFile(fileSet, "", src, 0)
|
||||
arrayAst := ast.FindArray(astFile, "model", "SysApi")
|
||||
var apis []system.SysApi
|
||||
err = global.GVA_DB.Find(&apis, "id in (?)", apiInfo.APIs).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
apisExpr := ast.CreateApiStructAst(apis)
|
||||
arrayAst.Elts = *apisExpr
|
||||
|
||||
var out []byte
|
||||
bf := bytes.NewBuffer(out)
|
||||
printer.Fprint(bf, fileSet, astFile)
|
||||
|
||||
os.WriteFile(apiPath, bf.Bytes(), 0666)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user