1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- /*
- * @description: 视图层 文件夹 models
- * @Author: CP
- * @Date: 2020-09-11 15:12:43
- * @FilePath: \construction_management\web\viewmodels\tree.go
- */
- package viewmodels
- import (
- validation "github.com/go-ozzo/ozzo-validation/v3"
- )
- // Leaf 叶子节点为true 可以显示创建标段
- // IsBid为true 目录下已包含标段
- type Tree struct {
- Id string `form:"id" json:"id" `
- Name string `form:"name" json:"name"`
- ProjectId string `form:"projectId" json:"projectId"`
- BidsectionId string `form:"bidsectionId" json:"bidsectionId"`
- ParentId string `form:"parentId" json:"parentId"`
- Depth int `form:"depth" json:"depth"`
- Serial string `form:"serial" json:"serial"`
- Attribution string `form:"attribution" json:"attribution"`
- Isfolder int `form:"isfolder" json:"isfolder"`
- CreateTime string `form:"createTime" json:"createTime"`
- UpdateTime string `form:"updateTime" json:"updateTime"`
- TargetFolderId string `form:"targetFolderId" json:"targetFolderId"`
- Accounts int `form:"accounts" json:"accounts"`
- Csrf string `form:"csrf" json:"csrf"`
- // Leaf bool `json:"leaf" `
- HasFolder bool `json:"hasFolder" `
- IsBid bool `json:"isBid" `
- IsEnd bool `json:"isEnd"`
- ChildsTotal int `json:"childsTotal"`
- Children []*Tree `json:"children"`
- }
- func (l Tree) Validate() error {
- return validation.ValidateStruct(&l,
- validation.Field(&l.Id, validation.Required.Error("文件夹ID不能为空")),
- validation.Field(&l.Name, validation.Required.Error("文件夹名称不能为空"), validation.Length(1, 60).Error("最多 15 个字符")),
- )
- }
- // func (l Tree) Maketree(Data []*Tree, node *Tree) { //参数为父节点,添加父节点的子节点指针切片
- // childs, _ := this.Havechild(Data, node) //判断节点是否有子节点并返回
- // if childs != nil {
- // // fmt.Printf("\n")
- // // fmt.Println(*node)
- // // fmt.Println("子节点:")
- // for _, v := range childs {
- // fmt.Println(*v)
- // } //打印
- // node.Child = append(node.Child, childs[0:]...) //添加子节点
- // for _, v := range childs { //查询子节点的子节点,并添加到子节点
- // _, has := Havechild(Data, v)
- // if has {
- // Maketree(Data, v) //递归添加节点
- // }
- // }
- // }
- // }
- // func (l Tree) Havechild(Data []*Tree, node *Tree) (child []*Tree, yes bool) {
- // for _, v := range Data {
- // if v.ParentId == node.Id {
- // child = append(child, v)
- // }
- // }
- // if child != nil {
- // yes = true
- // }
- // return
- // }
- // func transformjson(Data *Tree) { //转为json
- // Jsondata, _ := json.Marshal(Data)
- // fmt.Println(string(Jsondata))
- // }
|