自动化代码体验优化

This commit is contained in:
QM303176530
2020-11-08 12:47:55 +08:00
parent 829fa4dac5
commit cf9002a377
11 changed files with 28 additions and 838 deletions
+9 -3
View File
@@ -8,6 +8,7 @@ import (
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"go.uber.org/zap"
"net/url"
"os"
@@ -78,9 +79,14 @@ func CreateTemp(c *gin.Context) {
}
err := service.CreateTemp(a)
if err != nil {
c.Writer.Header().Add("success", "false")
c.Writer.Header().Add("msg", url.QueryEscape(err.Error()))
_ = os.Remove("./ginvueadmin.zip")
if errors.Is(err, model.AutoMoveErr) {
response.Ok(c)
} else {
c.Writer.Header().Add("success", "false")
c.Writer.Header().Add("msg", url.QueryEscape(err.Error()))
_ = os.Remove("./ginvueadmin.zip")
}
} else {
c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "ginvueadmin.zip")) // fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名
c.Writer.Header().Add("Content-Type", "application/json")
+1 -1
View File
@@ -33,7 +33,7 @@ require (
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
github.com/pelletier/go-toml v1.6.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1
github.com/qiniu/api.v7/v7 v7.4.1
github.com/satori/go.uuid v1.2.0
github.com/shirou/gopsutil v2.20.8+incompatible
+4
View File
@@ -1,5 +1,7 @@
package model
import "errors"
// 初始版本自动化代码工具
type AutoCodeStruct struct {
StructName string `json:"structName"`
@@ -24,3 +26,5 @@ type Field struct {
FieldSearchType string `json:"fieldSearchType"`
DictType string `json:"dictType"`
}
var AutoMoveErr error = errors.New("创建代码成功并移动文件成功")
+1 -34
View File
@@ -1,7 +1,6 @@
package service
import (
"errors"
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/model"
@@ -107,7 +106,7 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
return err
}
}
return errors.New("创建代码成功并移动文件成功")
return model.AutoMoveErr
} else { // 打包
if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil {
return err
@@ -149,38 +148,6 @@ func GetColumn(tableName string, dbName string) (err error, Columns []request.Co
return err, Columns
}
//func addAutoMoveFile(data *tplData) {
// if strings.Contains(data.autoCodePath, "server") {
// if strings.Contains(data.autoCodePath, "router") {
// apiList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join(apiList[len(apiList)-2], apiList[len(apiList)-1])
// } else if strings.Contains(data.autoCodePath, "api") {
// apiList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join(apiList[len(apiList)-2], "v1", apiList[len(apiList)-1])
// } else if strings.Contains(data.autoCodePath, "service") {
// serviceList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join(serviceList[len(serviceList)-2], serviceList[len(serviceList)-1])
// } else if strings.Contains(data.autoCodePath, "model") {
// modelList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join(modelList[len(modelList)-2], modelList[len(modelList)-1])
// } else if strings.Contains(data.autoCodePath, "request") {
// requestList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join("model", requestList[len(requestList)-2], requestList[len(requestList)-1])
// }
// } else if strings.Contains(data.autoCodePath, "web") {
// if strings.Contains(data.autoCodePath, "js") {
// jsList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join("../", "web", "src", jsList[len(jsList)-2], jsList[len(jsList)-1])
// } else if strings.Contains(data.autoCodePath, "form") {
// formList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", formList[len(formList)-3], strings.Split(formList[len(formList)-1], ".")[0]+"From.vue")
// } else if strings.Contains(data.autoCodePath, "table") {
// vueList := strings.Split(data.autoCodePath, "/")
// data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", vueList[len(vueList)-3], vueList[len(vueList)-1])
// }
// }
//}
func addAutoMoveFile(data *tplData) {
dir := filepath.Base(filepath.Dir(data.autoCodePath))
base := filepath.Base(data.autoCodePath)