From 4cc0f471686426a06d186ba40cfd68ebe8697605 Mon Sep 17 00:00:00 2001 From: SliverHorn Date: Tue, 26 Jan 2021 17:12:51 +0800 Subject: [PATCH 01/19] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=20=E8=BF=94=E5=9B=9E=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=90=8E,=E4=BB=8D=E7=84=B6=E6=89=A7=E8=A1=8C=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=88=9B=E5=BB=BA=E4=BB=A3=E7=A0=81bug,=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dbug,=20#367?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/sys_menu.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server/service/sys_menu.go b/server/service/sys_menu.go index d83ce6e4c6..bf7fddbfbd 100644 --- a/server/service/sys_menu.go +++ b/server/service/sys_menu.go @@ -89,12 +89,11 @@ func getBaseChildrenList(menu *model.SysBaseMenu, treeMap map[string][]model.Sys //@param: menu model.SysBaseMenu //@return: err error -func AddBaseMenu(menu model.SysBaseMenu) (err error) { +func AddBaseMenu(menu model.SysBaseMenu) error { if !errors.Is(global.GVA_DB.Where("name = ?", menu.Name).First(&model.SysBaseMenu{}).Error, gorm.ErrRecordNotFound) { - err = errors.New("存在重复name,请修改name") + return errors.New("存在重复name,请修改name") } - err = global.GVA_DB.Create(&menu).Error - return err + return global.GVA_DB.Create(&menu).Error } //@author: [piexlmax](https://github.com/piexlmax) From ed498511671bc4f1577dc38004843fbb05cf3fac Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Tue, 9 Feb 2021 19:25:14 +0800 Subject: [PATCH 02/19] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=AD=90?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=A8=A1=E5=BC=8F=E4=B8=8B=E4=B8=A4=E4=B8=AA?= =?UTF-8?q?keepalive=E7=9B=B8=E4=BA=92=E5=88=87=E6=8D=A2=20keepalive?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/view/systemTools/index.vue | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/web/src/view/systemTools/index.vue b/web/src/view/systemTools/index.vue index b0c84753e1..7cd5e90714 100644 --- a/web/src/view/systemTools/index.vue +++ b/web/src/view/systemTools/index.vue @@ -1,12 +1,15 @@ - \ No newline at end of file + From 6a0a763a96c826fb754fa599da277c0d84aa1a0c Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Tue, 9 Feb 2021 19:25:56 +0800 Subject: [PATCH 03/19] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=AD=90?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=A8=A1=E5=BC=8F=E4=B8=8B=E4=B8=A4=E4=B8=AA?= =?UTF-8?q?keepalive=E7=9B=B8=E4=BA=92=E5=88=87=E6=8D=A2=20keepalive?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/view/example/index.vue | 15 +++++++++------ web/src/view/layout/index.vue | 4 ++-- web/src/view/superAdmin/index.vue | 15 +++++++++------ web/src/view/systemTools/autoCode/index.vue | 2 +- web/src/view/workflow/index.vue | 15 +++++++++------ 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/web/src/view/example/index.vue b/web/src/view/example/index.vue index 5b1352915c..87b57206e6 100644 --- a/web/src/view/example/index.vue +++ b/web/src/view/example/index.vue @@ -1,12 +1,15 @@ - \ No newline at end of file + diff --git a/web/src/view/layout/index.vue b/web/src/view/layout/index.vue index 80ee671f59..99c71c17e5 100644 --- a/web/src/view/layout/index.vue +++ b/web/src/view/layout/index.vue @@ -67,11 +67,11 @@ - + - + diff --git a/web/src/view/superAdmin/index.vue b/web/src/view/superAdmin/index.vue index fd90ecdf2c..cbaa63694c 100644 --- a/web/src/view/superAdmin/index.vue +++ b/web/src/view/superAdmin/index.vue @@ -1,12 +1,15 @@ - \ No newline at end of file + diff --git a/web/src/view/systemTools/autoCode/index.vue b/web/src/view/systemTools/autoCode/index.vue index 38baafa22a..ffac6ecef5 100644 --- a/web/src/view/systemTools/autoCode/index.vue +++ b/web/src/view/systemTools/autoCode/index.vue @@ -357,7 +357,7 @@ export default { const fdTypes = ["string", "int", "bool", "float64", "time.Time"]; fdTypes.map(async fdtype => { const res = await getDict(fdtype); - res.map(item => { + res&&res.map(item => { this.fdMap[item.label] = fdtype; }); }); diff --git a/web/src/view/workflow/index.vue b/web/src/view/workflow/index.vue index a6ddb55922..eed056232b 100644 --- a/web/src/view/workflow/index.vue +++ b/web/src/view/workflow/index.vue @@ -1,12 +1,15 @@ - \ No newline at end of file + From 457e9bb2f682279d8d88686980c2b6bda8f4862b Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Thu, 11 Feb 2021 19:00:06 +0800 Subject: [PATCH 04/19] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=96=B0=E5=A2=9E=E9=A2=84=E8=A7=88=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/v1/sys_auto_code.go | 41 ++++++++++++- server/router/sys_auto_code.go | 1 + server/service/sys_auto_code.go | 103 ++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 3 deletions(-) diff --git a/server/api/v1/sys_auto_code.go b/server/api/v1/sys_auto_code.go index 679f4be32e..15c88942e1 100644 --- a/server/api/v1/sys_auto_code.go +++ b/server/api/v1/sys_auto_code.go @@ -1,19 +1,54 @@ package v1 import ( + "errors" "fmt" "gin-vue-admin/global" "gin-vue-admin/model" "gin-vue-admin/model/response" "gin-vue-admin/service" "gin-vue-admin/utils" - "github.com/gin-gonic/gin" - "github.com/pkg/errors" - "go.uber.org/zap" "net/url" "os" + + "github.com/gin-gonic/gin" + "go.uber.org/zap" ) +// @Tags AutoCode +// @Summary 预览创建后的代码 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body model.AutoCodeStruct true "预览创建代码" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" +// @Router /autoCode/preview [post] +func PreviewTemp(c *gin.Context) { + var a model.AutoCodeStruct + _ = c.ShouldBindJSON(&a) + if err := utils.Verify(a, utils.AutoCodeVerify); err != nil { + response.FailWithMessage(err.Error(), c) + return + } + if a.AutoCreateApiToSql { + if err := service.AutoCreateApi(&a); err != nil { + global.GVA_LOG.Error("自动化创建失败!请自行清空垃圾数据!", zap.Any("err", err)) + c.Writer.Header().Add("success", "false") + c.Writer.Header().Add("msg", url.QueryEscape("自动化创建失败!请自行清空垃圾数据!")) + return + } + } + m, err := service.PreviewTemp(a) + if err != nil { + c.Writer.Header().Add("success", "false") + c.Writer.Header().Add("msg", url.QueryEscape(err.Error())) + } else { + c.Writer.Header().Add("Content-Type", "application/json") + c.Writer.Header().Add("success", "true") + c.JSON(200, m) + } +} + // @Tags AutoCode // @Summary 自动代码模板 // @Security ApiKeyAuth diff --git a/server/router/sys_auto_code.go b/server/router/sys_auto_code.go index 77526d739e..723471d054 100644 --- a/server/router/sys_auto_code.go +++ b/server/router/sys_auto_code.go @@ -8,6 +8,7 @@ import ( func InitAutoCodeRouter(Router *gin.RouterGroup) { AutoCodeRouter := Router.Group("autoCode") { + AutoCodeRouter.POST("preview", v1.PreviewTemp) // 获取自动创建代码预览 AutoCodeRouter.POST("createTemp", v1.CreateTemp) // 创建自动化代码 AutoCodeRouter.GET("getTables", v1.GetTables) // 获取对应数据库的表 AutoCodeRouter.GET("getDB", v1.GetDB) // 获取数据库 diff --git a/server/service/sys_auto_code.go b/server/service/sys_auto_code.go index 0e2d404cdf..ac76bdc2e2 100644 --- a/server/service/sys_auto_code.go +++ b/server/service/sys_auto_code.go @@ -23,6 +23,109 @@ type tplData struct { autoMoveFilePath string } +//@author: [songzhibin97](https://github.com/songzhibin97) +//@function: PreviewTemp +//@description: 预览创建代码 +//@param: model.AutoCodeStruct +//@return: map[string]string, error + +func PreviewTemp(autoCode model.AutoCodeStruct) (map[string]string, error) { + basePath := "resource/template" + // 获取 basePath 文件夹下所有tpl文件 + tplFileList, err := GetAllTplFile(basePath, nil) + if err != nil { + return nil, err + } + dataList := make([]tplData, 0, len(tplFileList)) + fileList := make([]string, 0, len(tplFileList)) + needMkdir := make([]string, 0, len(tplFileList)) // 当文件夹下存在多个tpl文件时,改为map更合理 + // 根据文件路径生成 tplData 结构体,待填充数据 + for _, value := range tplFileList { + dataList = append(dataList, tplData{locationPath: value}) + } + // 生成 *Template, 填充 template 字段 + for index, value := range dataList { + dataList[index].template, err = template.ParseFiles(value.locationPath) + if err != nil { + return nil, err + } + } + // 生成文件路径,填充 autoCodePath 字段,readme.txt.tpl不符合规则,需要特殊处理 + // resource/template/web/api.js.tpl -> autoCode/web/autoCode.PackageName/api/autoCode.PackageName.js + // resource/template/readme.txt.tpl -> autoCode/readme.txt + autoPath := "autoCode/" + for index, value := range dataList { + trimBase := strings.TrimPrefix(value.locationPath, basePath+"/") + if trimBase == "readme.txt.tpl" { + dataList[index].autoCodePath = autoPath + "readme.txt" + continue + } + + if lastSeparator := strings.LastIndex(trimBase, "/"); lastSeparator != -1 { + origFileName := strings.TrimSuffix(trimBase[lastSeparator+1:], ".tpl") + firstDot := strings.Index(origFileName, ".") + if firstDot != -1 { + dataList[index].autoCodePath = filepath.Join(autoPath, trimBase[:lastSeparator], autoCode.PackageName, + origFileName[:firstDot], autoCode.PackageName+origFileName[firstDot:]) + } + } + + if lastSeparator := strings.LastIndex(dataList[index].autoCodePath, string(os.PathSeparator)); lastSeparator != -1 { + needMkdir = append(needMkdir, dataList[index].autoCodePath[:lastSeparator]) + } + } + + // 写入文件前,先创建文件夹 + if err = utils.CreateDir(needMkdir...); err != nil { + return nil, err + } + + // 创建map + ret := make(map[string]string) + + // 生成map + for _, value := range dataList { + ext := "" + if ext = filepath.Ext(value.autoCodePath); ext == ".txt" { + continue + } + fileList = append(fileList, value.autoCodePath) + f, err := os.OpenFile(value.autoCodePath, os.O_CREATE|os.O_WRONLY, 0755) + if err != nil { + return nil, err + } + if err = value.template.Execute(f, autoCode); err != nil { + return nil, err + } + _ = f.Close() + f, err = os.OpenFile(value.autoCodePath, os.O_CREATE|os.O_RDONLY, 0755) + if err != nil { + return nil, err + } + builder := strings.Builder{} + builder.WriteString("```\n") + data, err := ioutil.ReadAll(f) + if err != nil { + return nil, err + } + builder.Write(data) + builder.WriteString("\n```") + if ext != "" && strings.Contains(ext, ".") { + builder.WriteString(strings.Replace(ext, ".", "", -1)) + } + + ret[value.autoCodePath] = builder.String() + _ = f.Close() + + } + defer func() { // 移除中间文件 + if err := os.RemoveAll(autoPath); err != nil { + return + } + }() + return ret, nil +} + //@author: [piexlmax](https://github.com/piexlmax) //@function: CreateTemp //@description: 创建代码 From 5d27f133475c42ea9c49adbf55a448343395d188 Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Thu, 11 Feb 2021 19:33:11 +0800 Subject: [PATCH 05/19] =?UTF-8?q?=E6=8A=BD=E5=87=BA=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AE=B9=E4=BC=98=E5=8C=96PreviewTemp?= =?UTF-8?q?=E5=92=8CCreateTemp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/sys_auto_code.go | 143 +++++++++++++------------------- 1 file changed, 57 insertions(+), 86 deletions(-) diff --git a/server/service/sys_auto_code.go b/server/service/sys_auto_code.go index ac76bdc2e2..02d1e294dc 100644 --- a/server/service/sys_auto_code.go +++ b/server/service/sys_auto_code.go @@ -16,6 +16,11 @@ import ( "gorm.io/gorm" ) +const ( + autoPath = "autoCode/" + basePath = "resource/template" +) + type tplData struct { template *template.Template locationPath string @@ -30,50 +35,10 @@ type tplData struct { //@return: map[string]string, error func PreviewTemp(autoCode model.AutoCodeStruct) (map[string]string, error) { - basePath := "resource/template" - // 获取 basePath 文件夹下所有tpl文件 - tplFileList, err := GetAllTplFile(basePath, nil) + dataList, _, needMkdir, err := getNeedList(&autoCode) if err != nil { return nil, err } - dataList := make([]tplData, 0, len(tplFileList)) - fileList := make([]string, 0, len(tplFileList)) - needMkdir := make([]string, 0, len(tplFileList)) // 当文件夹下存在多个tpl文件时,改为map更合理 - // 根据文件路径生成 tplData 结构体,待填充数据 - for _, value := range tplFileList { - dataList = append(dataList, tplData{locationPath: value}) - } - // 生成 *Template, 填充 template 字段 - for index, value := range dataList { - dataList[index].template, err = template.ParseFiles(value.locationPath) - if err != nil { - return nil, err - } - } - // 生成文件路径,填充 autoCodePath 字段,readme.txt.tpl不符合规则,需要特殊处理 - // resource/template/web/api.js.tpl -> autoCode/web/autoCode.PackageName/api/autoCode.PackageName.js - // resource/template/readme.txt.tpl -> autoCode/readme.txt - autoPath := "autoCode/" - for index, value := range dataList { - trimBase := strings.TrimPrefix(value.locationPath, basePath+"/") - if trimBase == "readme.txt.tpl" { - dataList[index].autoCodePath = autoPath + "readme.txt" - continue - } - - if lastSeparator := strings.LastIndex(trimBase, "/"); lastSeparator != -1 { - origFileName := strings.TrimSuffix(trimBase[lastSeparator+1:], ".tpl") - firstDot := strings.Index(origFileName, ".") - if firstDot != -1 { - dataList[index].autoCodePath = filepath.Join(autoPath, trimBase[:lastSeparator], autoCode.PackageName, - origFileName[:firstDot], autoCode.PackageName+origFileName[firstDot:]) - } - } - - if lastSeparator := strings.LastIndex(dataList[index].autoCodePath, string(os.PathSeparator)); lastSeparator != -1 { - needMkdir = append(needMkdir, dataList[index].autoCodePath[:lastSeparator]) - } - } // 写入文件前,先创建文件夹 if err = utils.CreateDir(needMkdir...); err != nil { @@ -89,7 +54,6 @@ func PreviewTemp(autoCode model.AutoCodeStruct) (map[string]string, error) { if ext = filepath.Ext(value.autoCodePath); ext == ".txt" { continue } - fileList = append(fileList, value.autoCodePath) f, err := os.OpenFile(value.autoCodePath, os.O_CREATE|os.O_WRONLY, 0755) if err != nil { return nil, err @@ -133,52 +97,10 @@ func PreviewTemp(autoCode model.AutoCodeStruct) (map[string]string, error) { //@return: error func CreateTemp(autoCode model.AutoCodeStruct) (err error) { - basePath := "resource/template" - // 获取 basePath 文件夹下所有tpl文件 - tplFileList, err := GetAllTplFile(basePath, nil) + dataList, fileList, needMkdir, err := getNeedList(&autoCode) if err != nil { return err } - dataList := make([]tplData, 0, len(tplFileList)) - fileList := make([]string, 0, len(tplFileList)) - needMkdir := make([]string, 0, len(tplFileList)) // 当文件夹下存在多个tpl文件时,改为map更合理 - // 根据文件路径生成 tplData 结构体,待填充数据 - for _, value := range tplFileList { - dataList = append(dataList, tplData{locationPath: value}) - } - // 生成 *Template, 填充 template 字段 - for index, value := range dataList { - dataList[index].template, err = template.ParseFiles(value.locationPath) - if err != nil { - return err - } - } - - // 生成文件路径,填充 autoCodePath 字段,readme.txt.tpl不符合规则,需要特殊处理 - // resource/template/web/api.js.tpl -> autoCode/web/autoCode.PackageName/api/autoCode.PackageName.js - // resource/template/readme.txt.tpl -> autoCode/readme.txt - autoPath := "autoCode/" - for index, value := range dataList { - trimBase := strings.TrimPrefix(value.locationPath, basePath+"/") - if trimBase == "readme.txt.tpl" { - dataList[index].autoCodePath = autoPath + "readme.txt" - continue - } - - if lastSeparator := strings.LastIndex(trimBase, "/"); lastSeparator != -1 { - origFileName := strings.TrimSuffix(trimBase[lastSeparator+1:], ".tpl") - firstDot := strings.Index(origFileName, ".") - if firstDot != -1 { - dataList[index].autoCodePath = filepath.Join(autoPath, trimBase[:lastSeparator], autoCode.PackageName, - origFileName[:firstDot], autoCode.PackageName+origFileName[firstDot:]) - } - } - - if lastSeparator := strings.LastIndex(dataList[index].autoCodePath, string(os.PathSeparator)); lastSeparator != -1 { - needMkdir = append(needMkdir, dataList[index].autoCodePath[:lastSeparator]) - } - } - // 写入文件前,先创建文件夹 if err = utils.CreateDir(needMkdir...); err != nil { return err @@ -186,7 +108,6 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) { // 生成文件 for _, value := range dataList { - fileList = append(fileList, value.autoCodePath) f, err := os.OpenFile(value.autoCodePath, os.O_CREATE|os.O_WRONLY, 0755) if err != nil { return err @@ -379,3 +300,53 @@ func AutoCreateApi(a *model.AutoCodeStruct) (err error) { }) return err } + +func getNeedList(autoCode *model.AutoCodeStruct) (dataList []tplData, fileList []string, needMkdir []string, err error) { + // 获取 basePath 文件夹下所有tpl文件 + tplFileList, err := GetAllTplFile(basePath, nil) + if err != nil { + return nil, nil, nil, err + } + dataList = make([]tplData, 0, len(tplFileList)) + fileList = make([]string, 0, len(tplFileList)) + needMkdir = make([]string, 0, len(tplFileList)) // 当文件夹下存在多个tpl文件时,改为map更合理 + // 根据文件路径生成 tplData 结构体,待填充数据 + for _, value := range tplFileList { + dataList = append(dataList, tplData{locationPath: value}) + } + // 生成 *Template, 填充 template 字段 + for index, value := range dataList { + dataList[index].template, err = template.ParseFiles(value.locationPath) + if err != nil { + return nil, nil, nil, err + } + } + // 生成文件路径,填充 autoCodePath 字段,readme.txt.tpl不符合规则,需要特殊处理 + // resource/template/web/api.js.tpl -> autoCode/web/autoCode.PackageName/api/autoCode.PackageName.js + // resource/template/readme.txt.tpl -> autoCode/readme.txt + autoPath := "autoCode/" + for index, value := range dataList { + trimBase := strings.TrimPrefix(value.locationPath, basePath+"/") + if trimBase == "readme.txt.tpl" { + dataList[index].autoCodePath = autoPath + "readme.txt" + continue + } + + if lastSeparator := strings.LastIndex(trimBase, "/"); lastSeparator != -1 { + origFileName := strings.TrimSuffix(trimBase[lastSeparator+1:], ".tpl") + firstDot := strings.Index(origFileName, ".") + if firstDot != -1 { + dataList[index].autoCodePath = filepath.Join(autoPath, trimBase[:lastSeparator], autoCode.PackageName, + origFileName[:firstDot], autoCode.PackageName+origFileName[firstDot:]) + } + } + + if lastSeparator := strings.LastIndex(dataList[index].autoCodePath, string(os.PathSeparator)); lastSeparator != -1 { + needMkdir = append(needMkdir, dataList[index].autoCodePath[:lastSeparator]) + } + } + for _, value := range dataList { + fileList = append(fileList, value.autoCodePath) + } + return dataList, fileList, needMkdir, err +} From f0a49a958e7f41ffd15b5c23218e1ddeaa4020d7 Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Sat, 13 Feb 2021 16:22:50 +0800 Subject: [PATCH 06/19] =?UTF-8?q?initdb=E9=BB=98=E8=AE=A4string=E9=95=BF?= =?UTF-8?q?=E5=BA=A6=E6=94=B9=E4=B8=BA191?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/v1/sys_auto_code.go | 18 +-- server/cmd/gva/mysql.go | 2 +- server/cmd/information/system/api.go | 1 + server/cmd/information/system/casbin.go | 1 + server/service/sys_auto_code.go | 14 +- web/package.json | 148 +++++++++--------- web/src/api/autoCode.js | 22 ++- .../autoCode/component/previewCodeDialg.vue | 58 +++++++ web/src/view/systemTools/autoCode/index.vue | 80 ++++++---- 9 files changed, 207 insertions(+), 137 deletions(-) create mode 100644 web/src/view/systemTools/autoCode/component/previewCodeDialg.vue diff --git a/server/api/v1/sys_auto_code.go b/server/api/v1/sys_auto_code.go index 15c88942e1..435e9bf2ea 100644 --- a/server/api/v1/sys_auto_code.go +++ b/server/api/v1/sys_auto_code.go @@ -30,22 +30,12 @@ func PreviewTemp(c *gin.Context) { response.FailWithMessage(err.Error(), c) return } - if a.AutoCreateApiToSql { - if err := service.AutoCreateApi(&a); err != nil { - global.GVA_LOG.Error("自动化创建失败!请自行清空垃圾数据!", zap.Any("err", err)) - c.Writer.Header().Add("success", "false") - c.Writer.Header().Add("msg", url.QueryEscape("自动化创建失败!请自行清空垃圾数据!")) - return - } - } - m, err := service.PreviewTemp(a) + autoCode, err := service.PreviewTemp(a) if err != nil { - c.Writer.Header().Add("success", "false") - c.Writer.Header().Add("msg", url.QueryEscape(err.Error())) + global.GVA_LOG.Error("预览失败!", zap.Any("err", err)) + response.FailWithMessage("预览失败", c) } else { - c.Writer.Header().Add("Content-Type", "application/json") - c.Writer.Header().Add("success", "true") - c.JSON(200, m) + response.OkWithDetailed(gin.H{"autoCode": autoCode}, "预览成功", c) } } diff --git a/server/cmd/gva/mysql.go b/server/cmd/gva/mysql.go index 5c6ac94a77..a17e14886a 100644 --- a/server/cmd/gva/mysql.go +++ b/server/cmd/gva/mysql.go @@ -44,7 +44,7 @@ func (m *_mysql) Init() { m._config.DisableForeignKeyConstraintWhenMigrating = true m.db, m.err = gorm.Open(mysql.New(mysql.Config{ DSN: global.GVA_CONFIG.Mysql.Dsn(), // DSN data source name - DefaultStringSize: 256, // string 类型字段的默认长度 + DefaultStringSize: 191, // string 类型字段的默认长度 DisableDatetimePrecision: true, // 禁用 datetime 精度,MySQL 5.6 之前的数据库不支持 DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引 DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列 diff --git a/server/cmd/information/system/api.go b/server/cmd/information/system/api.go index ef0477f839..0461d6e881 100644 --- a/server/cmd/information/system/api.go +++ b/server/cmd/information/system/api.go @@ -92,6 +92,7 @@ var apis = []model.SysApi{ {global.GVA_MODEL{ID: 77, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/getMyNeed", "获取我的待办", "workflowProcess", "GET"}, {global.GVA_MODEL{ID: 78, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/getWorkflowMoveByID", "根据id获取当前节点详情和历史", "workflowProcess", "GET"}, {global.GVA_MODEL{ID: 79, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/completeWorkflowMove", "提交工作流", "workflowProcess", "POST"}, + {global.GVA_MODEL{ID: 80, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/preview", "预览自动化代码", "autoCode", "POST"}, } //@author: [SliverHorn](https://github.com/SliverHorn) diff --git a/server/cmd/information/system/casbin.go b/server/cmd/information/system/casbin.go index 1fb9303881..e71f3117cc 100644 --- a/server/cmd/information/system/casbin.go +++ b/server/cmd/information/system/casbin.go @@ -55,6 +55,7 @@ var carbines = []gormadapter.CasbinRule{ {PType: "p", V0: "888", V1: "/customer/customer", V2: "GET"}, {PType: "p", V0: "888", V1: "/customer/customerList", V2: "GET"}, {PType: "p", V0: "888", V1: "/autoCode/createTemp", V2: "POST"}, + {PType: "p", V0: "888", V1: "/autoCode/preview", V2: "POST"}, {PType: "p", V0: "888", V1: "/autoCode/getTables", V2: "GET"}, {PType: "p", V0: "888", V1: "/autoCode/getDB", V2: "GET"}, {PType: "p", V0: "888", V1: "/autoCode/getColumn", V2: "GET"}, diff --git a/server/service/sys_auto_code.go b/server/service/sys_auto_code.go index 02d1e294dc..bd16d6fc1c 100644 --- a/server/service/sys_auto_code.go +++ b/server/service/sys_auto_code.go @@ -67,18 +67,20 @@ func PreviewTemp(autoCode model.AutoCodeStruct) (map[string]string, error) { return nil, err } builder := strings.Builder{} - builder.WriteString("```\n") + builder.WriteString("```") + if ext != "" && strings.Contains(ext, ".") { + builder.WriteString(strings.Replace(ext, ".", "", -1)) + } + builder.WriteString("\n\n") data, err := ioutil.ReadAll(f) if err != nil { return nil, err } builder.Write(data) - builder.WriteString("\n```") - if ext != "" && strings.Contains(ext, ".") { - builder.WriteString(strings.Replace(ext, ".", "", -1)) - } + builder.WriteString("\n\n```") - ret[value.autoCodePath] = builder.String() + pathArr := strings.Split(value.autoCodePath,"\\") + ret[pathArr[1]+"-"+pathArr[3]] = builder.String() _ = f.Close() } diff --git a/web/package.json b/web/package.json index e09a45fbc7..76b70c24cc 100644 --- a/web/package.json +++ b/web/package.json @@ -1,75 +1,77 @@ { - "name": "gin-vue-admin", - "version": "0.1.0", - "private": true, - "scripts": { - "serve": "node openDocument.js && vue-cli-service serve", - "build": "vue-cli-service build", - "lint": "vue-cli-service lint" + "name": "gin-vue-admin", + "version": "0.1.0", + "private": true, + "scripts": { + "serve": "node openDocument.js && vue-cli-service serve", + "build": "vue-cli-service build", + "lint": "vue-cli-service lint" + }, + "dependencies": { + "@antv/dom-util": "2.0.2", + "@antv/g-canvas": "^0.4.12", + "@antv/g6": "3.5.2", + "@antv/matrix-util": "2.0.7", + "@antv/util": "~2.0.9", + "@moefe/vue-aplayer": "^2.0.0-beta.5", + "axios": "^0.19.2", + "core-js": "^3.6.5", + "echarts": "^4.7.0", + "element-ui": "^2.12.0", + "highlight.js": "^10.6.0", + "marked": "^2.0.0", + "node-sass": "^4.14.1", + "path": "^0.12.7", + "qs": "^6.8.0", + "quill": "^1.3.7", + "sass-loader": "^8.0.0", + "screenfull": "^5.0.2", + "script-ext-html-webpack-plugin": "^2.1.4", + "spark-md5": "^3.0.1", + "timeline-vuejs": "1.1.1", + "vue": "^2.6.10", + "vue-particle-line": "^0.1.4", + "vue-router": "^3.1.3", + "vue-simple-uploader": "^0.7.4", + "vuescroll": "^4.14.4", + "vuex": "^3.1.1", + "vuex-persist": "^2.1.0" + }, + "devDependencies": { + "@vue/cli-plugin-babel": "^4.5.6", + "@vue/cli-plugin-eslint": "^4.5.6", + "@vue/cli-service": "^4.5.6", + "babel-eslint": "^10.1.0", + "eslint": "^6.7.2", + "eslint-plugin-vue": "^6.2.2", + "vue-template-compiler": "^2.6.10", + "core-js": "^3.3.2", + "node-sass": "^4.12.0", + "numericjs": "^1.2.6", + "raw-loader": "^3.1.0", + "sass-loader": "^8.0.0" + }, + "eslintConfig": { + "root": true, + "env": { + "node": true }, - "dependencies": { - "@moefe/vue-aplayer": "^2.0.0-beta.5", - "axios": "^0.19.2", - "core-js": "^3.6.5", - "echarts": "^4.7.0", - "element-ui": "^2.12.0", - "node-sass": "^4.14.1", - "path": "^0.12.7", - "qs": "^6.8.0", - "quill": "^1.3.7", - "sass-loader": "^8.0.0", - "screenfull": "^5.0.2", - "script-ext-html-webpack-plugin": "^2.1.4", - "spark-md5": "^3.0.1", - "timeline-vuejs": "1.1.1", - "vue": "^2.6.10", - "vue-particle-line": "^0.1.4", - "vue-router": "^3.1.3", - "vue-simple-uploader": "^0.7.4", - "vuescroll": "^4.14.4", - "vuex": "^3.1.1", - "vuex-persist": "^2.1.0", - "@antv/dom-util": "2.0.2", - "@antv/matrix-util": "2.0.7", - "@antv/g-canvas": "^0.4.12", - "@antv/g6": "3.5.2", - "@antv/util": "~2.0.9" - }, - "devDependencies": { - "@vue/cli-plugin-babel": "^4.5.6", - "@vue/cli-plugin-eslint": "^4.5.6", - "@vue/cli-service": "^4.5.6", - "babel-eslint": "^10.1.0", - "eslint": "^6.7.2", - "eslint-plugin-vue": "^6.2.2", - "vue-template-compiler": "^2.6.10", - "core-js": "^3.3.2", - "node-sass": "^4.12.0", - "numericjs": "^1.2.6", - "raw-loader": "^3.1.0", - "sass-loader": "^8.0.0" - }, - "eslintConfig": { - "root": true, - "env": { - "node": true - }, - "extends": [ - "plugin:vue/essential", - "eslint:recommended" - ], - "rules": {}, - "parserOptions": { - "parser": "babel-eslint" - } - }, - "postcss": { - "plugins": { - "autoprefixer": {} - } - }, - "browserslist": [ - "> 1%", - "last 2 versions" - ] -} \ No newline at end of file + "extends": [ + "plugin:vue/essential", + "eslint:recommended" + ], + "rules": {}, + "parserOptions": { + "parser": "babel-eslint" + } + }, + "postcss": { + "plugins": { + "autoprefixer": {} + } + }, + "browserslist": [ + "> 1%", + "last 2 versions" + ] +} diff --git a/web/src/api/autoCode.js b/web/src/api/autoCode.js index df146affa3..a5756b516f 100644 --- a/web/src/api/autoCode.js +++ b/web/src/api/autoCode.js @@ -1,16 +1,13 @@ import service from '@/utils/request' -// @Tags api -// @Summary 分页获取角色列表 -// @Security ApiKeyAuth -// @accept application/json -// @Produce application/json -// @Param data body modelInterface.PageInfo true "分页获取用户列表" -// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}" -// @Router /api/getApiList [post] -// { -// page int -// pageSize int -// } + +export const preview = (data) => { + return service({ + url: "/autoCode/preview", + method: 'post', + data, + }) +} + export const createTemp = (data) => { return service({ url: "/autoCode/createTemp", @@ -20,7 +17,6 @@ export const createTemp = (data) => { }) } - // @Tags SysApi // @Summary 获取当前所有数据库 // @Security ApiKeyAuth diff --git a/web/src/view/systemTools/autoCode/component/previewCodeDialg.vue b/web/src/view/systemTools/autoCode/component/previewCodeDialg.vue new file mode 100644 index 0000000000..ecc0d8128b --- /dev/null +++ b/web/src/view/systemTools/autoCode/component/previewCodeDialg.vue @@ -0,0 +1,58 @@ + + + + + \ No newline at end of file diff --git a/web/src/view/systemTools/autoCode/index.vue b/web/src/view/systemTools/autoCode/index.vue index ffac6ecef5..e7a134a26c 100644 --- a/web/src/view/systemTools/autoCode/index.vue +++ b/web/src/view/systemTools/autoCode/index.vue @@ -58,7 +58,7 @@ - + @@ -117,6 +117,7 @@ id , created_at , updated_at , deleted_at 会自动生成请勿重复创建
+ 预览代码 生成代码
@@ -127,6 +128,13 @@ 确 定 + + + + + + From d32a13d24535f2bb243ccf0c4710b704a4cbb809 Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Tue, 23 Feb 2021 14:47:39 +0800 Subject: [PATCH 17/19] =?UTF-8?q?=E6=9B=B4=E6=94=B9=20=E6=8D=90=E8=B5=A0?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index ca272a4162..6584d9917b 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username -custom: https://afdian.net/@Gin-Vue-Admin +custom: https://www.gin-vue-admin.com/docs/coffee From 127a6b161ec7d5f20bdd2773f4f8b5823cd9cba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=87=E6=B7=BC=EF=BC=88piexlmax?= <303176530@qq.com> Date: Tue, 23 Feb 2021 15:50:10 +0800 Subject: [PATCH 18/19] Update FUNDING.yml --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 6584d9917b..75703ec57a 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -2,7 +2,7 @@ github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] patreon: # Replace with a single Patreon username -open_collective: # Replace with a single Open Collective username +open_collective: gin-vue-admin ko_fi: # Replace with a single Ko-fi username tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry From a3e4e9f42ebd6ff3cf2648450d463a910230a781 Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Wed, 24 Feb 2021 09:53:45 +0800 Subject: [PATCH 19/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BF=AB=E9=80=9F?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E7=88=B6=E7=BA=A7=E8=8F=9C=E5=8D=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=20=E4=BF=AE=E5=A4=8D=E6=9C=AC=E5=9C=B0=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=87=E4=BB=B6=E7=94=A8=E6=88=B7=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=A4=B4=E5=83=8F=E5=AD=98=E5=9C=A8=E9=97=AE=E9=A2=98=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/view/person/person.vue | 2 +- web/src/view/superAdmin/menu/menu.vue | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/web/src/view/person/person.vue b/web/src/view/person/person.vue index e12527cd44..2cde321b8c 100644 --- a/web/src/view/person/person.vue +++ b/web/src/view/person/person.vue @@ -4,7 +4,7 @@
-
+
重新上传 diff --git a/web/src/view/superAdmin/menu/menu.vue b/web/src/view/superAdmin/menu/menu.vue index b4dd84b8bb..c02fc23fc4 100644 --- a/web/src/view/superAdmin/menu/menu.vue +++ b/web/src/view/superAdmin/menu/menu.vue @@ -97,8 +97,9 @@ v-model="form.parentId" > - + + 如果菜单包含子菜单,请创建router-view二级路由页面或者点我设置