예제 #1
0
파일: common.go 프로젝트: joyplus/admin
func (this *CommonController) GetTree(userinfo interface{}) []Tree {
	nodes, _ := m.GetNodeTree(0, 1)
	tree := make([]Tree, len(nodes))
	if nil == userinfo {
		return tree
	}
	fmt.Println("******* userinfo:", userinfo)
	accesslist, _ := GetAccessRightList(userinfo.(m.User).Id)
	fmt.Println("******* accesslist:", accesslist)
	adminuser := beego.AppConfig.String("rbac_admin_user")
	isAdminUser := false
	if userinfo.(m.User).Username == adminuser {
		isAdminUser = true
	}
	for k, v := range nodes {
		tree[k].Id = v["Id"].(int64)
		tree[k].Text = v["Title"].(string)
		children, _ := m.GetNodeTree(v["Id"].(int64), 2)
		tree[k].Children = []Tree{}
		for _, v1 := range children {
			url := v["Name"].(string) + "/" + v1["Name"].(string)
			if !isAdminUser {
				if r := hasAccessRight(accesslist, url); !r {
					continue
				}
			}
			node := Tree{}
			node.Id = v1["Id"].(int64)
			node.Text = v1["Title"].(string)
			node.Attributes.Url = "/" + url
			tree[k].Children = append(tree[k].Children, node)
		}
	}
	for i := 0; i < len(tree); i++ {
		if len(tree[i].Children) == 0 {
			if i == len(tree) {
				tree = tree[:i]
				break
			} else {
				tree = append(tree[:i], tree[i+1:]...)
				i--
			}

		}
	}

	return tree
}
예제 #2
0
func (this *CommonController) GetTree() []Tree {
	nodes, _ := m.GetNodeTree(0, 1)
	tree := make([]Tree, len(nodes))
	for k, v := range nodes {
		tree[k].Id = v["Id"].(int64)
		tree[k].Text = v["Title"].(string)
		children, _ := m.GetNodeTree(v["Id"].(int64), 2)
		tree[k].Children = make([]Tree, len(children))
		for k1, v1 := range children {
			tree[k].Children[k1].Id = v1["Id"].(int64)
			tree[k].Children[k1].Text = v1["Title"].(string)
			tree[k].Children[k1].Attributes.Url = "/" + v["Name"].(string) + "/" + v1["Name"].(string)
		}
	}
	return tree
}