From 977b272ec65de8050561cb2ea80a701f5844f0e9 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Wed, 29 Sep 2021 00:37:13 +0800 Subject: [PATCH] no message --- controller/openapi.go | 65 +++++++++++++++++++++++++++++++++++++++++-- utils/helper.go | 2 ++ 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/controller/openapi.go b/controller/openapi.go index f31ded4..36e7955 100644 --- a/controller/openapi.go +++ b/controller/openapi.go @@ -4,6 +4,7 @@ import ( "background/utils" "container/list" "encoding/xml" + "fmt" "io" "log" @@ -94,7 +95,7 @@ func RangeWidget(p *Widget ) string{ for ;tmp != nil;tmp = tmp.Parent{ parent = tmp.Class + "#" + tmp.Name + " " + parent } - ret += parent + " \r\n{\r\n}\r\n" + ret += parent + ` \r\n{\r\n}\r\n` if(p.Childs.Len() > 0){ wid := p.Childs.Front() @@ -111,6 +112,7 @@ type Controller struct{ Type string Name string Parent *Controller + Childs list.List } func GetUifrom(path io.Reader) string{ @@ -201,6 +203,64 @@ func (this *OpenApiController) UI2CSS(c *gin.Context) { } +func GetXmlController(path io.Reader) string{ + list := list.List{} + maps := map[string]int{} + ret := "" + + decoder := xml.NewDecoder(path) + for { + token, _ := decoder.Token() + if token == nil { + break + } + switch startElement := token.(type) { + case xml.StartElement: + log.Print(0,startElement.Name) + if(list.Len() == 0){ + ins := new(Controller) + ins.Name = getAttr("name",startElement.Attr) + ins.Parent = nil + list.PushBack(ins) + }else{ + ins := new(Controller) + ins.Type = startElement.Name.Local + ins.Name = getAttr("name",startElement.Attr) + ins.Parent = list.Back().Value.(*Controller) + list.Back().Value.(*Controller).Childs.PushBack(ins) + list.PushBack(ins) + } + break + case xml.EndElement: + log.Print(1,startElement.Name) + break + } + } + begin := list.Front() + first := true + + for begin.Next() != nil{ + if begin.Value.(*Controller).Name != ""{ + if first{ + first = false + }else{ + log.Print(begin.Value.(*Controller).Name," ",begin.Value.(*Controller).Type) + if _,ok := maps[begin.Value.(*Controller).Type] ;ok{ + maps[begin.Value.(*Controller).Type]++ + }else{ + maps[begin.Value.(*Controller).Type] = 1 + } + // ui::Button* btn_add_new = dynamic_cast(FindControl(L"open_button")); + ret += fmt.Sprintf("ui::%s * = dynamic_cast(FindControl(L\"%s\"))\r\n",begin.Value.(*Controller).Type, + begin.Value.(*Controller).Type,begin.Value.(*Controller).Name) + } + } + begin = begin.Next() + } + + return ret +} + func (this *OpenApiController) DuilibXml2Cpp(c *gin.Context) { f, err := c.FormFile("xml") //根据name返回给第一个文件 if err != nil { @@ -212,6 +272,7 @@ func (this *OpenApiController) DuilibXml2Cpp(c *gin.Context) { c.String(200,"上传文件错误") return } - ret := GetUifrom(file) + ret := GetXmlController(file) + log.Print(ret) c.String(200,ret) } diff --git a/utils/helper.go b/utils/helper.go index e9e16df..316cfa9 100644 --- a/utils/helper.go +++ b/utils/helper.go @@ -30,6 +30,8 @@ func toCamelString(s string) string { } return string(data[:]) } + + type FieldDesc struct { FiledName string `json:"field_name"` Type string `json:"type"`