From 4a81fb706f018a3905b58aa68cd00dff610f95cf Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Tue, 28 Sep 2021 23:38:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0duilib=20xml=E5=B8=83?= =?UTF-8?q?=E5=B1=80=E6=A0=BC=E5=BC=8F=E7=94=9F=E6=88=90c++=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6=E7=BB=91=E5=AE=9A=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/openapi.go | 55 ++++++++++++++++++++++++++++++------------- main.go | 2 +- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/controller/openapi.go b/controller/openapi.go index 4fe725e..f31ded4 100644 --- a/controller/openapi.go +++ b/controller/openapi.go @@ -107,8 +107,15 @@ func RangeWidget(p *Widget ) string{ return ret } +type Controller struct{ + Type string + Name string + Parent *Controller +} + func GetUifrom(path io.Reader) string{ list := list.List{} + decoder := xml.NewDecoder(path) for { token, _ := decoder.Token() @@ -117,24 +124,25 @@ func GetUifrom(path io.Reader) string{ } switch startElement := token.(type) { case xml.StartElement: - if(startElement.Name.Local == "widget"){ - if(list.Len() == 0){ - ins := new(Widget) - ins.Class = getAttr("class",startElement.Attr) - ins.Name = getAttr("name",startElement.Attr) - ins.Parent = nil - list.PushBack(ins) - }else{ - ins := new(Widget) - ins.Class = getAttr("class",startElement.Attr) - ins.Name = getAttr("name",startElement.Attr) - ins.Parent = list.Back().Value.(*Widget) - list.Back().Value.(*Widget).Childs.PushBack(ins) - list.PushBack(ins) - } + log.Print(0,startElement.Name) + if(list.Len() == 0){ + ins := new(Controller) + ins.Name = getAttr("name",startElement.Attr) + log.Print(ins.Name) + ins.Parent = nil + list.PushBack(ins) + }else{ + ins := new(Controller) + ins.Type = startElement.Name.Local + ins.Name = getAttr("name",startElement.Attr) + log.Print(ins.Name) + ins.Parent = list.Back().Value.(*Controller) + list.Back().Value.(*Widget).Childs.PushBack(ins) + list.PushBack(ins) } break case xml.EndElement: + log.Print(1,startElement.Name) if(startElement.Name.Local == "widget"){ if(list.Len() > 0){ if(list.Back().Value.(*Widget).Parent != nil){ @@ -145,7 +153,6 @@ func GetUifrom(path io.Reader) string{ break } } - p := list.Back().Value.(*Widget) ret := RangeWidget(p) log.Print(ret) @@ -192,3 +199,19 @@ func (this *OpenApiController) UI2CSS(c *gin.Context) { ret := GetUifrom(file) c.String(200,ret) } + + +func (this *OpenApiController) DuilibXml2Cpp(c *gin.Context) { + f, err := c.FormFile("xml") //根据name返回给第一个文件 + if err != nil { + c.String(200,"上传文件错误") + return + } + file,e := f.Open() + if nil != e{ + c.String(200,"上传文件错误") + return + } + ret := GetUifrom(file) + c.String(200,ret) +} diff --git a/main.go b/main.go index 8e791de..412e945 100644 --- a/main.go +++ b/main.go @@ -230,8 +230,8 @@ func main() { openapi.POST("/ddl2orm", openapiController.DDL2ORM) // sql ddl转gorm 结构体 openapi.POST("/ddl2markdown", openapiController.DDL2Markdown) // sql ddl转markdown 文档 openapi.POST("/ui2css", openapiController.UI2CSS) // qt ui文件转css文档 + openapi.POST("/duilib_xml2cpp", openapiController.DuilibXml2Cpp) // duilib to cpp } - e := r.Run(":" + strconv.Itoa(config.GetPort())) if nil != e { log.Print(e.Error())