tree.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. MoveId string `form:"moveId"`
  24. Csrf string `form:"csrf"`
  25. Leaf bool `json:"leaf"`
  26. Children []*Tree `json:"children"`
  27. }
  28. func (l Tree) Validate() error {
  29. return validation.ValidateStruct(&l,
  30. validation.Field(&l.Name, validation.Required.Error("文件夹名称不能为空"), validation.Length(1, 60).Error("最多 15 个字符")),
  31. )
  32. }
  33. // func (l Tree) Maketree(Data []*Tree, node *Tree) { //参数为父节点,添加父节点的子节点指针切片
  34. // childs, _ := this.Havechild(Data, node) //判断节点是否有子节点并返回
  35. // if childs != nil {
  36. // // fmt.Printf("\n")
  37. // // fmt.Println(*node)
  38. // // fmt.Println("子节点:")
  39. // for _, v := range childs {
  40. // fmt.Println(*v)
  41. // } //打印
  42. // node.Child = append(node.Child, childs[0:]...) //添加子节点
  43. // for _, v := range childs { //查询子节点的子节点,并添加到子节点
  44. // _, has := Havechild(Data, v)
  45. // if has {
  46. // Maketree(Data, v) //递归添加节点
  47. // }
  48. // }
  49. // }
  50. // }
  51. // func (l Tree) Havechild(Data []*Tree, node *Tree) (child []*Tree, yes bool) {
  52. // for _, v := range Data {
  53. // if v.ParentId == node.Id {
  54. // child = append(child, v)
  55. // }
  56. // }
  57. // if child != nil {
  58. // yes = true
  59. // }
  60. // return
  61. // }
  62. // func transformjson(Data *Tree) { //转为json
  63. // Jsondata, _ := json.Marshal(Data)
  64. // fmt.Println(string(Jsondata))
  65. // }