From 04d3ddadd1234949024621ab6e6ed27e3d764a13 Mon Sep 17 00:00:00 2001 From: yxh Date: Fri, 14 Aug 2020 18:11:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E6=A0=91?= =?UTF-8?q?=E5=BD=A2=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/admin/gen_table.go | 39 +- go.mod | 2 +- go.sum | 4 +- .../crud/{extend.template => model.template} | 0 .../tree/{extend.template => model.template} | 0 template/vm/html/vue.template | 360 --------------- template/vm/html/vue_crud.template | 421 ++++++++++++++++++ template/vm/html/vue_tree.template | 420 +++++++++++++++++ 8 files changed, 867 insertions(+), 379 deletions(-) rename template/vm/go/crud/{extend.template => model.template} (100%) rename template/vm/go/tree/{extend.template => model.template} (100%) delete mode 100644 template/vm/html/vue.template create mode 100644 template/vm/html/vue_crud.template create mode 100644 template/vm/html/vue_tree.template diff --git a/app/controller/admin/gen_table.go b/app/controller/admin/gen_table.go index df5df81..8dc321e 100644 --- a/app/controller/admin/gen_table.go +++ b/app/controller/admin/gen_table.go @@ -195,8 +195,8 @@ func (c *Gen) Preview(r *ghttp.Request) { controllerValue := "" serviceKey := "vm/go/" + entity.BusinessName + "_service.go.vm" serviceValue := "" - extendKey := "vm/go/" + entity.BusinessName + "_extend.go.vm" - extendValue := "" + modelKey := "vm/go/" + entity.BusinessName + "_model.go.vm" + modelValue := "" apiJsKey := "vm/html/" + entity.BusinessName + "_api.js.vm" apiJsValue := "" vueKey := "vm/html/" + entity.BusinessName + "_vue.js.vm" @@ -207,6 +207,9 @@ func (c *Gen) Preview(r *ghttp.Request) { "UcFirst": func(str string) string { return gstr.UcFirst(str) }, + "add": func(a, b int) int { + return a + b + }, }) view.SetConfigWithMap(g.Map{ "Paths": []string{"template"}, @@ -217,34 +220,38 @@ func (c *Gen) Preview(r *ghttp.Request) { if entity.TplCategory == "tree" { options = gjson.New(entity.Options).ToMap() } - g.Log().Debug(options) if tmpController, err := view.Parse("vm/go/"+entity.TplCategory+"/controller.template", g.Map{"table": entity}); err == nil { controllerValue = tmpController } if tmpService, err := view.Parse("vm/go/"+entity.TplCategory+"/service.template", g.Map{"table": entity, "options": options}); err == nil { serviceValue = tmpService } - if tmpExtend, err := view.Parse("vm/go/"+entity.TplCategory+"/extend.template", g.Map{"table": entity}); err == nil { - extendValue = tmpExtend - if extendByte, err := gregex.Replace("(([\\s\t]*)\r?\n){2,}", []byte("$2\n"), []byte(extendValue)); err == nil { - extendValue = gconv.String(extendByte) - } + if tmpModel, err := view.Parse("vm/go/"+entity.TplCategory+"/model.template", g.Map{"table": entity}); err == nil { + modelValue = tmpModel + modelValue, err = c.trimBreak(modelValue) } - if tmpExtend, err := view.Parse("vm/html/js.template", g.Map{"table": entity}); err == nil { - apiJsValue = tmpExtend + if tmpJs, err := view.Parse("vm/html/js.template", g.Map{"table": entity}); err == nil { + apiJsValue = tmpJs } - if tmpExtend, err := view.Parse("vm/html/vue.template", g.Map{"table": entity}); err == nil { - vueValue = tmpExtend - if vueByte, err := gregex.Replace("(([\\s\t]*)\r?\n){2,}", []byte("$2\n"), []byte(vueValue)); err == nil { - vueValue = gconv.String(vueByte) - } + if tmpVue, err := view.Parse("vm/html/vue_"+entity.TplCategory+".template", g.Map{"table": entity, "options": options}); err == nil { + vueValue = tmpVue + vueValue, err = c.trimBreak(vueValue) } response.SusJson(true, r, "ok", g.Map{ - extendKey: extendValue, + modelKey: modelValue, serviceKey: serviceValue, controllerKey: controllerValue, apiJsKey: apiJsValue, vueKey: vueValue, }) } + +//剔除多余的换行 +func (c *Gen) trimBreak(str string) (s string, err error) { + var b []byte + if b, err = gregex.Replace("(([\\s\t]*)\r?\n){2,}", []byte("$2\n"), []byte(str)); err == nil { + s = gconv.String(b) + } + return +} diff --git a/go.mod b/go.mod index a8acf9e..57063df 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/go-ole/go-ole v1.2.4 // indirect github.com/go-openapi/spec v0.19.8 // indirect github.com/go-openapi/swag v0.19.9 // indirect - github.com/goflyfox/gtoken v1.3.17 + github.com/goflyfox/gtoken v1.3.18 github.com/gogf/gf v1.13.3 github.com/mailru/easyjson v0.7.1 // indirect github.com/mojocn/base64Captcha v1.3.1 diff --git a/go.sum b/go.sum index d783777..abce884 100644 --- a/go.sum +++ b/go.sum @@ -61,8 +61,8 @@ github.com/go-openapi/swag v0.19.9 h1:1IxuqvBUU3S2Bi4YC7tlP9SJF1gVpCvqN0T2Qof4az github.com/go-openapi/swag v0.19.9/go.mod h1:ao+8BpOPyKdpQz3AOJfbeEVpLmWAvlT1IfTe5McPyhY= github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/goflyfox/gtoken v1.3.17 h1:/HgPG7iArkJMn8SVXcDya5+6xXvWJEpR0bxnjigq2u8= -github.com/goflyfox/gtoken v1.3.17/go.mod h1:a9Q08qaHzoS+ko/AFrCBnq4KCesnRFZ/3eLIiERRhtU= +github.com/goflyfox/gtoken v1.3.18 h1:LD9FFWJxYRVlCw+Xw07UT/PBkLJC60hD3kQr+9KVF2A= +github.com/goflyfox/gtoken v1.3.18/go.mod h1:a9Q08qaHzoS+ko/AFrCBnq4KCesnRFZ/3eLIiERRhtU= github.com/gogf/gf v1.12.1/go.mod h1:5ItmC5B/St8P4hp0/waKmnvHwAfAJ1uspMvR2wUD4UA= github.com/gogf/gf v1.13.3 h1:wdyNAzOSztDkabTEqRmPeJJT93p2qBK/jPK5x+8CRSE= github.com/gogf/gf v1.13.3/go.mod h1:dGX0/BElXDBYbdJGascqfrWScj8IMeOietDjVD6/5Fc= diff --git a/template/vm/go/crud/extend.template b/template/vm/go/crud/model.template similarity index 100% rename from template/vm/go/crud/extend.template rename to template/vm/go/crud/model.template diff --git a/template/vm/go/tree/extend.template b/template/vm/go/tree/model.template similarity index 100% rename from template/vm/go/tree/extend.template rename to template/vm/go/tree/model.template diff --git a/template/vm/html/vue.template b/template/vm/html/vue.template deleted file mode 100644 index a62a779..0000000 --- a/template/vm/html/vue.template +++ /dev/null @@ -1,360 +0,0 @@ -{{$tableComment:=.table.TableComment}} - - - - \ No newline at end of file diff --git a/template/vm/html/vue_crud.template b/template/vm/html/vue_crud.template new file mode 100644 index 0000000..3c0ee19 --- /dev/null +++ b/template/vm/html/vue_crud.template @@ -0,0 +1,421 @@ +{{$columns:=.table.Columns}} +{{$pk:=""}} +{{$pkColumnName:=""}} +{{range $index, $column := .table.Columns}} {{if eq $column.IsPk "1"}} + {{$pk = $column.ColumnName}} + {{$pkColumnName = $column.ColumnName}} +{{end}}{{end}} + + + \ No newline at end of file diff --git a/template/vm/html/vue_tree.template b/template/vm/html/vue_tree.template new file mode 100644 index 0000000..2b0398e --- /dev/null +++ b/template/vm/html/vue_tree.template @@ -0,0 +1,420 @@ +{{$columns:=.table.Columns}} +{{$pk:=""}} +{{$pkColumnName:=""}} +{{range $index, $column := .table.Columns}} {{if eq $column.IsPk "1"}} + {{$pk = $column.ColumnName}} + {{$pkColumnName = $column.ColumnName}} +{{end}}{{end}} +{{$treeCode:=index .options "tree_code"}} +{{$treeName:=index .options "tree_name"}} +{{$treeParentCode:=index .options "tree_parent_code"}} + + + + \ No newline at end of file