From f2a1dbeba7570773413e0fcdf73f722f50128e73 Mon Sep 17 00:00:00 2001 From: "DESKTOP-4RNDQIC\\29019" <290198252@qq.com> Date: Sun, 9 May 2021 15:22:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0ui=E8=BD=ACcss=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/openapi.go | 104 ++++++++++++++++++++++++++++++++++++++++++ main.go | 42 +---------------- 2 files changed, 105 insertions(+), 41 deletions(-) diff --git a/controller/openapi.go b/controller/openapi.go index e9775e5..274f186 100644 --- a/controller/openapi.go +++ b/controller/openapi.go @@ -2,6 +2,9 @@ package controller import ( "background/utils" + "container/list" + "encoding/xml" + "io" "log" "github.com/gin-gonic/gin" @@ -65,6 +68,90 @@ func (this *OpenApiController) DDL2ORM(c *gin.Context) { } +func getAttr(name string, attr []xml.Attr) string { + for _, a := range attr { + if a.Name.Local == name { + return a.Value + } + } + return "" +} + +type Widget struct{ + Name string + Class string + Parent *Widget + Childs list.List +} + +func RangeWidget(p *Widget ) string{ + if nil == p{ + return "" + } + ret := "" + ret += p.Class + "#" + p.Name + " \r\n{\r\n}\r\n" + if(p.Childs.Len() > 0){ + wid := p.Childs.Front() + for ;wid != nil;wid = wid.Next(){ + output := "" + tmp := wid.Value.(*Widget) + for ;tmp != nil;tmp = tmp.Parent{ + output = tmp.Class + " #" + tmp.Name + " " + output + } + ret += output + "\r\n{\r\n}\r\n" + } + } + return ret +} + +func GetUifrom(path io.Reader) string{ + list := list.List{} + decoder := xml.NewDecoder(path) + for { + token, _ := decoder.Token() + if token == nil { + break + } + switch startElement := token.(type) { + case xml.StartElement: + if(startElement.Name.Local == "widget"){ + // log.Print(startElement.Name.Local) + 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) + // log.Print(list.Back().Value.(*Widget)) + ins.Parent = list.Back().Value.(*Widget) + list.Back().Value.(*Widget).Childs.PushBack(ins) + list.PushBack(ins) + } + } + break + case xml.EndElement: + if(startElement.Name.Local == "widget"){ + if(list.Len() > 0){ + if(list.Back().Value.(*Widget).Parent != nil){ + list.Remove(list.Back()) + } + } + } + break + } + } + + p := list.Back().Value.(*Widget) + ret := RangeWidget(p) + log.Print(ret) + return ret +} + + func (this *OpenApiController) DDL2Markdown(c *gin.Context) { var req ReqDDL resp := RespBase{ @@ -87,3 +174,20 @@ func (this *OpenApiController) DDL2Markdown(c *gin.Context) { resp.Msg = "OK" resp.Status = 0 } + + +func (this *OpenApiController) UI2CSS(c *gin.Context) { + + f, err := c.FormFile("ui") //根据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 5773d68..57f7215 100644 --- a/main.go +++ b/main.go @@ -8,9 +8,7 @@ import ( _ "background/docs" "background/logs" "background/model" - "encoding/xml" "log" - "os" "strconv" "github.com/gin-gonic/gin" @@ -94,45 +92,7 @@ func InitLogs() { } -func getAttr(name string, attr []xml.Attr) string { - for _, a := range attr { - if a.Name.Local == name { - return a.Value - } - } - return "" -} - - -func TestUI(){ - xmlFile, err := os.Open("process.ui") - if err != nil { - log.Fatal(err) - } - defer xmlFile.Close() - decoder := xml.NewDecoder(xmlFile) - for { - token, _ := decoder.Token() - if token == nil { - break - } - switch startElement := token.(type) { - case xml.StartElement: - log.Print(startElement.Name.Local) - if(startElement.Name.Local == "widget"){ - log.Print(getAttr("name",startElement.Attr)) - } - break - case xml.EndElement: - log.Print(startElement.Name.Local) - break - } - } -} - func main() { - log.Print("gid is", os.Getegid()) - TestUI() InitConfig() InitLogs() InitRedisConfig() @@ -239,7 +199,7 @@ func main() { openapi.POST("/diff") openapi.POST("/ddl2orm", openapiController.DDL2ORM) openapi.POST("/ddl2markdown", openapiController.DDL2Markdown) - + openapi.POST("/ui2css", openapiController.UI2CSS) } e := r.Run(":" + strconv.Itoa(config.GetPort())) if nil != e {