@@ -7,12 +7,13 @@ import (
77 "gin-vue-admin/model"
88 "gin-vue-admin/model/request"
99 "gin-vue-admin/utils"
10- "gorm.io/gorm"
1110 "io/ioutil"
1211 "os"
1312 "path/filepath"
1413 "strings"
1514 "text/template"
15+
16+ "gorm.io/gorm"
1617)
1718
1819type tplData struct {
@@ -65,12 +66,12 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
6566 origFileName := strings .TrimSuffix (trimBase [lastSeparator + 1 :], ".tpl" )
6667 firstDot := strings .Index (origFileName , "." )
6768 if firstDot != - 1 {
68- dataList [index ].autoCodePath = autoPath + trimBase [:lastSeparator ] + "/" + autoCode .PackageName + "/" +
69- origFileName [:firstDot ] + "/" + autoCode .PackageName + origFileName [firstDot :]
69+ dataList [index ].autoCodePath = filepath . Join ( autoPath , trimBase [:lastSeparator ], autoCode .PackageName ,
70+ origFileName [:firstDot ], autoCode .PackageName + origFileName [firstDot :])
7071 }
7172 }
7273
73- if lastSeparator := strings .LastIndex (dataList [index ].autoCodePath , "/" ); lastSeparator != - 1 {
74+ if lastSeparator := strings .LastIndex (dataList [index ].autoCodePath , string ( os . PathSeparator ) ); lastSeparator != - 1 {
7475 needMkdir = append (needMkdir , dataList [index ].autoCodePath [:lastSeparator ])
7576 }
7677 }
@@ -186,26 +187,31 @@ func GetColumn(tableName string, dbName string) (err error, Columns []request.Co
186187func addAutoMoveFile (data * tplData ) {
187188 dir := filepath .Base (filepath .Dir (data .autoCodePath ))
188189 base := filepath .Base (data .autoCodePath )
189- if strings .Contains (data .autoCodePath , "server" ) {
190- if strings .Contains (data .autoCodePath , "router" ) {
190+ fileSlice := strings .Split (data .autoCodePath , string (os .PathSeparator ))
191+ n := len (fileSlice )
192+ if n <= 2 {
193+ return
194+ }
195+ if strings .Contains (fileSlice [1 ], "server" ) {
196+ if strings .Contains (fileSlice [n - 2 ], "router" ) {
191197 data .autoMoveFilePath = filepath .Join (dir , base )
192- } else if strings .Contains (data . autoCodePath , "api" ) {
198+ } else if strings .Contains (fileSlice [ n - 2 ] , "api" ) {
193199 data .autoMoveFilePath = filepath .Join (dir , "v1" , base )
194- } else if strings .Contains (data . autoCodePath , "service" ) {
200+ } else if strings .Contains (fileSlice [ n - 2 ] , "service" ) {
195201 data .autoMoveFilePath = filepath .Join (dir , base )
196- } else if strings .Contains (data . autoCodePath , "model" ) {
202+ } else if strings .Contains (fileSlice [ n - 2 ] , "model" ) {
197203 data .autoMoveFilePath = filepath .Join (dir , base )
198- } else if strings .Contains (data . autoCodePath , "request" ) {
204+ } else if strings .Contains (fileSlice [ n - 2 ] , "request" ) {
199205 data .autoMoveFilePath = filepath .Join ("model" , dir , base )
200206 }
201- } else if strings .Contains (data . autoCodePath , "web" ) {
202- if strings .Contains (data . autoCodePath , "js" ) {
207+ } else if strings .Contains (fileSlice [ 1 ] , "web" ) {
208+ if strings .Contains (fileSlice [ n - 1 ] , "js" ) {
203209 data .autoMoveFilePath = filepath .Join ("../" , "web" , "src" , dir , base )
204- } else if strings .Contains (data . autoCodePath , "workflowForm" ) {
210+ } else if strings .Contains (fileSlice [ n - 2 ] , "workflowForm" ) {
205211 data .autoMoveFilePath = filepath .Join ("../" , "web" , "src" , "view" , filepath .Base (filepath .Dir (filepath .Dir (data .autoCodePath ))), strings .TrimSuffix (base , filepath .Ext (base ))+ "WorkflowForm.vue" )
206- } else if strings .Contains (data . autoCodePath , "form" ) {
212+ } else if strings .Contains (fileSlice [ n - 2 ] , "form" ) {
207213 data .autoMoveFilePath = filepath .Join ("../" , "web" , "src" , "view" , filepath .Base (filepath .Dir (filepath .Dir (data .autoCodePath ))), strings .TrimSuffix (base , filepath .Ext (base ))+ "Form.vue" )
208- } else if strings .Contains (data . autoCodePath , "table" ) {
214+ } else if strings .Contains (fileSlice [ n - 2 ] , "table" ) {
209215 data .autoMoveFilePath = filepath .Join ("../" , "web" , "src" , "view" , filepath .Base (filepath .Dir (filepath .Dir (data .autoCodePath ))), base )
210216 }
211217 }
0 commit comments