Skip to content

Commit 08e9c6b

Browse files
committed
优化auto
1 parent 5c94c73 commit 08e9c6b

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

server/service/sys_auto_code.go

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,34 +149,60 @@ func GetColumn(tableName string, dbName string) (err error, Columns []request.Co
149149
return err, Columns
150150
}
151151

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+
152184
func addAutoMoveFile(data *tplData) {
185+
dir := filepath.Dir(data.autoCodePath)
186+
base := filepath.Base(data.autoCodePath)
153187
if strings.Contains(data.autoCodePath, "server") {
154188
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])
189+
data.autoMoveFilePath = filepath.Join(dir, base)
157190
} 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])
191+
data.autoMoveFilePath = filepath.Join(dir, "v1", base)
160192
} 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])
193+
data.autoMoveFilePath = filepath.Join(dir, base)
163194
} 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])
195+
data.autoMoveFilePath = filepath.Join(dir, base)
166196
} 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])
197+
data.autoMoveFilePath = filepath.Join("model", dir, base)
169198
}
170199
} else if strings.Contains(data.autoCodePath, "web") {
171200
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])
201+
data.autoMoveFilePath = filepath.Join("../", "web", "src", dir, base)
174202
} 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")
203+
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Dir(dir), strings.TrimSuffix(base, filepath.Ext(base))+"From.vue")
177204
} 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])
205+
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Dir(dir), base)
180206
}
181207
}
182208
}

server/utils/file_operations.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ func FileMove(src string, dst string) (err error) {
2121
return err
2222
}
2323
var revoke = false
24+
dir := filepath.Dir(dst)
2425
Redirect:
25-
_, err = os.Stat(filepath.Dir(dst))
26+
_, err = os.Stat(dir)
2627
if err != nil {
27-
err = os.MkdirAll(filepath.Dir(dst), 0755)
28+
err = os.MkdirAll(dir, 0755)
2829
if err != nil {
2930
return err
3031
}

0 commit comments

Comments
 (0)