Skip to the content.

NgTreeFrame

Build Status

基于 Angular 的树形组织结构框架

在线 Demo:http://www.bannary.com/ngTreeFrame/demo/

依赖

Angular

使用

引入 js

<script src="./../js/ngTreeFrame.js"></script>
<tree-frame
  tree-data="treeObj"
  bg-color-config="treeBgColorConfig"
  bg-color-for-level="bgColorForLevelConfig"
  tree-frame-config="treeFrameConfig"
  tree-node-click="treeNodeClick"
>
</tree-frame>
// 注入 ngTreeFrame
angular
  .module("demoApp", ["ngTreeFrame"])
  .controller("DemoController", function ($scope) {
    // ...
  });

参数

$scope.treeObj = {
  child: [
    {
      child: [
        {
          child: [],
          des: "",
          id: 542,
          name: "54223",
          parentCode: 465,
          type: 0,
          userName: "",
        },
      ],
      des: "",
      id: 465,
      name: "3333",
      parentCode: 123,
      type: 0,
      userName: "",
    },
    {
      child: [],
      des: "",
      id: 467,
      name: "444",
      parentCode: 123,
      type: 0,
      userName: "",
      icon: "./../icon.png",
    },
  ],
  des: "123",
  id: 123,
  name: "213",
  parentCode: 0,
  type: 0,
  userName: "",
  icon: "./../icon.png",
};
$scope.treeBgColorConfig = {
  key: "type",
  values: [
    {
      value: 0,
      bgColor: "#e1ebfd",
      color: "#000000",
    },
    {
      value: 1,
      bgColor: "#faebd7",
      color: "#000000",
    },
  ],
};
$scope.bgColorForLevelConfig = [
  {
    bgColor: "#e1ebfd",
    color: "#000000",
  },
  {
    bgColor: "#faebd7",
    color: "#000000",
  },
];
$scope.treeFrameConfig = {
  id: "id", // 唯一标识字段(不能重复)
  parentId: "parentId", // 父节点唯一标识
  icon: "icon", // 若果有图标,则显示icon的图片
  parentIcon: "./../icon.png", // 顶级父节点ico
  formatTreeData: function (treeData) {
    // ... 对数据的预处理操作
    // ...
    // 对于不显示菜单的字段配置 disableTreeMenu: true
    // ...
    return treeData;
  },
  // 菜单配置
  menuConfig: [
    {
      text: "创建子机构",
      callback: function (node) {
        // 点击菜单后要做的事
        console.log(node);
      },
    },
    {
      text: "园所管理",
      visible: function (node) {
        // 该菜单是否显示
        return node.parentId == 0;
      },
      callback: function (node) {},
    },
    {
      text: "查看",
      callback: function (node) {},
    },
    {
      text: "编辑",
      callback: function (node) {},
    },
    {
      text: "删除",
      callback: function (node) {},
    },
  ],
};
$scope.treeNodeClick = function (node) {
  console.log(node);
};