Skip to content

Commit cf9002a

Browse files
author
QM303176530
committed
自动化代码体验优化
1 parent 829fa4d commit cf9002a

File tree

11 files changed

+28
-838
lines changed

11 files changed

+28
-838
lines changed

server/api/v1/sys_auto_code.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"gin-vue-admin/service"
99
"gin-vue-admin/utils"
1010
"github.com/gin-gonic/gin"
11+
"github.com/pkg/errors"
1112
"go.uber.org/zap"
1213
"net/url"
1314
"os"
@@ -78,9 +79,14 @@ func CreateTemp(c *gin.Context) {
7879
}
7980
err := service.CreateTemp(a)
8081
if err != nil {
81-
c.Writer.Header().Add("success", "false")
82-
c.Writer.Header().Add("msg", url.QueryEscape(err.Error()))
83-
_ = os.Remove("./ginvueadmin.zip")
82+
if errors.Is(err, model.AutoMoveErr) {
83+
response.Ok(c)
84+
} else {
85+
c.Writer.Header().Add("success", "false")
86+
c.Writer.Header().Add("msg", url.QueryEscape(err.Error()))
87+
_ = os.Remove("./ginvueadmin.zip")
88+
}
89+
8490
} else {
8591
c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "ginvueadmin.zip")) // fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名
8692
c.Writer.Header().Add("Content-Type", "application/json")

server/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ require (
3333
github.com/onsi/ginkgo v1.7.0 // indirect
3434
github.com/onsi/gomega v1.4.3 // indirect
3535
github.com/pelletier/go-toml v1.6.0 // indirect
36-
github.com/pkg/errors v0.9.1 // indirect
36+
github.com/pkg/errors v0.9.1
3737
github.com/qiniu/api.v7/v7 v7.4.1
3838
github.com/satori/go.uuid v1.2.0
3939
github.com/shirou/gopsutil v2.20.8+incompatible

server/model/sys_auto_code.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package model
22

3+
import "errors"
4+
35
// 初始版本自动化代码工具
46
type AutoCodeStruct struct {
57
StructName string `json:"structName"`
@@ -24,3 +26,5 @@ type Field struct {
2426
FieldSearchType string `json:"fieldSearchType"`
2527
DictType string `json:"dictType"`
2628
}
29+
30+
var AutoMoveErr error = errors.New("创建代码成功并移动文件成功")

server/service/sys_auto_code.go

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package service
22

33
import (
4-
"errors"
54
"fmt"
65
"gin-vue-admin/global"
76
"gin-vue-admin/model"
@@ -107,7 +106,7 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
107106
return err
108107
}
109108
}
110-
return errors.New("创建代码成功并移动文件成功")
109+
return model.AutoMoveErr
111110
} else { // 打包
112111
if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil {
113112
return err
@@ -149,38 +148,6 @@ func GetColumn(tableName string, dbName string) (err error, Columns []request.Co
149148
return err, Columns
150149
}
151150

152-
//func addAutoMoveFile(data *tplData) {
153-
// if strings.Contains(data.autoCodePath, "server") {
154-
// if strings.Contains(data.autoCodePath, "router") {
155-
// apiList := strings.Split(data.autoCodePath, "/")
156-
// data.autoMoveFilePath = filepath.Join(apiList[len(apiList)-2], apiList[len(apiList)-1])
157-
// } else if strings.Contains(data.autoCodePath, "api") {
158-
// apiList := strings.Split(data.autoCodePath, "/")
159-
// data.autoMoveFilePath = filepath.Join(apiList[len(apiList)-2], "v1", apiList[len(apiList)-1])
160-
// } else if strings.Contains(data.autoCodePath, "service") {
161-
// serviceList := strings.Split(data.autoCodePath, "/")
162-
// data.autoMoveFilePath = filepath.Join(serviceList[len(serviceList)-2], serviceList[len(serviceList)-1])
163-
// } else if strings.Contains(data.autoCodePath, "model") {
164-
// modelList := strings.Split(data.autoCodePath, "/")
165-
// data.autoMoveFilePath = filepath.Join(modelList[len(modelList)-2], modelList[len(modelList)-1])
166-
// } else if strings.Contains(data.autoCodePath, "request") {
167-
// requestList := strings.Split(data.autoCodePath, "/")
168-
// data.autoMoveFilePath = filepath.Join("model", requestList[len(requestList)-2], requestList[len(requestList)-1])
169-
// }
170-
// } else if strings.Contains(data.autoCodePath, "web") {
171-
// if strings.Contains(data.autoCodePath, "js") {
172-
// jsList := strings.Split(data.autoCodePath, "/")
173-
// data.autoMoveFilePath = filepath.Join("../", "web", "src", jsList[len(jsList)-2], jsList[len(jsList)-1])
174-
// } else if strings.Contains(data.autoCodePath, "form") {
175-
// formList := strings.Split(data.autoCodePath, "/")
176-
// data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", formList[len(formList)-3], strings.Split(formList[len(formList)-1], ".")[0]+"From.vue")
177-
// } else if strings.Contains(data.autoCodePath, "table") {
178-
// vueList := strings.Split(data.autoCodePath, "/")
179-
// data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", vueList[len(vueList)-3], vueList[len(vueList)-1])
180-
// }
181-
// }
182-
//}
183-
184151
func addAutoMoveFile(data *tplData) {
185152
dir := filepath.Base(filepath.Dir(data.autoCodePath))
186153
base := filepath.Base(data.autoCodePath)

web/src/utils/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ service.interceptors.response.use(
6868
Message({
6969
showClose: true,
7070
message: response.data.msg || decodeURI(response.headers.msg),
71-
type: 'error',
71+
type: response.headers.messageType||'error',
7272
})
7373
if (response.data.data && response.data.data.reload) {
7474
store.commit('user/LoginOut')

web/src/view/dashboard/component/RaddarChart.vue

Lines changed: 0 additions & 120 deletions
This file was deleted.

0 commit comments

Comments
 (0)