添加ui转css文件接口

master
DESKTOP-4RNDQIC\29019 2021-05-09 15:22:57 +08:00
parent 80180f55f3
commit f2a1dbeba7
2 changed files with 105 additions and 41 deletions

View File

@ -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)
}

42
main.go
View File

@ -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 {