tree.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * @description: 视图层 文件夹 models
  3. * @Author: CP
  4. * @Date: 2020-09-11 15:12:43
  5. * @FilePath: \construction_management\web\viewmodels\tree.go
  6. */
  7. package viewmodels
  8. import (
  9. validation "github.com/go-ozzo/ozzo-validation/v3"
  10. )
  11. type Tree struct {
  12. Id string `form:"id" json:"id"`
  13. Name string `form:"name" json:"name"`
  14. ProjectId string `form:"projectId"`
  15. TenderId int `form:"tenderId"`
  16. ParentId string `form:"parentId" json:"parentId"`
  17. Depth int `form:"depth"`
  18. Serial string `form:"serial"`
  19. Attribution string `form:"attribution"`
  20. Isfolder int `form:"isfolder"`
  21. CreateTime string `form:"createTime"`
  22. UpdateTime string `form:"updateTime"`
  23. Csrf string `form:"csrf"`
  24. Leaf bool `json:"leaf"`
  25. Children []*Tree `json:"children"`
  26. }
  27. func (l Tree) Validate() error {
  28. return validation.ValidateStruct(&l,
  29. validation.Field(&l.Name, validation.Required.Error("文件夹名称不能为空"), validation.Length(1, 60).Error("最多 15 个字符")),
  30. )
  31. }
  32. // func (l Tree) Maketree(Data []*Tree, node *Tree) { //参数为父节点,添加父节点的子节点指针切片
  33. // childs, _ := this.Havechild(Data, node) //判断节点是否有子节点并返回
  34. // if childs != nil {
  35. // // fmt.Printf("\n")
  36. // // fmt.Println(*node)
  37. // // fmt.Println("子节点:")
  38. // for _, v := range childs {
  39. // fmt.Println(*v)
  40. // } //打印
  41. // node.Child = append(node.Child, childs[0:]...) //添加子节点
  42. // for _, v := range childs { //查询子节点的子节点,并添加到子节点
  43. // _, has := Havechild(Data, v)
  44. // if has {
  45. // Maketree(Data, v) //递归添加节点
  46. // }
  47. // }
  48. // }
  49. // }
  50. // func (l Tree) Havechild(Data []*Tree, node *Tree) (child []*Tree, yes bool) {
  51. // for _, v := range Data {
  52. // if v.ParentId == node.Id {
  53. // child = append(child, v)
  54. // }
  55. // }
  56. // if child != nil {
  57. // yes = true
  58. // }
  59. // return
  60. // }
  61. // func transformjson(Data *Tree) { //转为json
  62. // Jsondata, _ := json.Marshal(Data)
  63. // fmt.Println(string(Jsondata))
  64. // }