npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tntx/overview-tree

v1.0.2

Published

树形概览图

Downloads

10

Readme

@tntx/overview-tree 树形概览图

image

安装

npm i @tntx/overview-tree

如何使用

import React, { useEffect, useRef } from "react";
import ReactDOM from 'react-dom';
import Overview from "@tntx/overview-tree";
import { mockData } from "./mockData";

const Demo = props => {
    const [data, setData] = useState([]);
    
    useEffect(() => {
		getData();
	}, []);

	const getData = (d) => {
		setTimeout(() => {
			if (d) {
				setData([
					{
						name: "字段名称", // 名称 -- 必填
						nodeType: 10, // 类型 -- 必填
						value: "SYSTEM_VB_TEST12", // 标识 -- 必填
						version: "V1", // 版本
						id: "SYSTEM_VB_TEST12_10" // -- 必填
					},
					{
						name: "字段名称ce是长度啊", // 名称 -- 必填
						nodeType: 10, // 类型 -- 必填
						value: "SYSTEM_VB_TEST", // 标识 -- 必填
						version: "V1", // 版本
						id: "SYSTEM_VB_TEST_10" // -- 必填
					}
				]);
			} else {
				setData(mockData);
			}
		}, 100);
	};

    return (
        <Overview
            rootName="我是根节点"
            data={data}
            getData={(d) => {
                getData(d);
            }}
            onClick={(d) => {
                console.log(d);
            }}
        />
    )
};

ReactDOM.render(
    <Demo />,
    document.getElementById('root')
);

API

| 参数 | 说明 | 类型 | 默认值 | | ------------ | ------------ | ------------ | ------------ | | rootName | 根节点名称 | String | -- | | data | 单层数据结构,组件内部已为你做了tree结构拼接 | Arrary | -- | | treeData | 如果你只想渲染你的树结构,请用此属性传入数据,此时data,getData属性将失效 | Arrary | ---| | nodeTypeMap | 节点数据配置 | Object | 往下看 | | noPlus | 某个节点无扩展 | Number | 10 | | getData | 需要请求获取子节点数据回调 | Function | -- | | onClick | 点击节点回调 | Function | -- |

data 数据结构

[
    {
        name: "字段名称", // 名称 -- 必填
        nodeType: 10, // 类型 -- 必填
        value: "SYSTEM_VB_TEST12", // 标识 -- 必填
        version: "V1", // 版本
        id: "SYSTEM_VB_TEST12_10" // -- 必填
    },
    {
        name: "字段名称ce是长度啊", // 名称 -- 必填
        nodeType: 10, // 类型 -- 必填
        value: "SYSTEM_VB_TEST", // 标识 -- 必填
        id: "SYSTEM_VB_TEST_10" // -- 必填
    }
]

treeData 数据结构

[
    {
        name: "字段名称", // 名称 -- 必填
        nodeType: 10, // 类型 -- 必填
        value: "SYSTEM_VB_TEST12", // 标识 -- 必填
        id: "SYSTEM_VB_TEST12_10", // -- 必填
        children: [
            {
                name: "字段名称ce是长度啊",
                nodeType: 10,
                value: "SYSTEM_VB_TEST",
                id: "SYSTEM_VB_TEST_10",
                children: [
                    {
                        name: "字段名称ce是长度啊",
                        nodeType: 10,
                        value: "SYSTEM_VB_TEST",
                        id: "SYSTEM_VB_TEST_10"
                    }
                ]
            }
        ]
    },
    {
        name: "字段名称ce是长度啊",
        nodeType: 10,
        value: "SYSTEM_VB_TEST",
        id: "SYSTEM_VB_TEST_10"
    }
]

nodeTypeMap 默认可不填,内置数据如下:

{
    1: { name: "决策流", color: "#0FB8FE", img: require("./Base/img/1.svg") },
    2: { name: "策略集", color: "#628FE4", img: require("./Base/img/2.svg") },
    3: { name: "决策工具", color: "#CF6767", img: require("./Base/img/3.svg") },
    4: { name: "三方服务", color: "#CFAB67", img: require("./Base/img/4.svg") },
    5: { name: "模型", color: "#4DA9C9", img: require("./Base/img/5.svg") },
    6: { name: "冠军挑战者", color: "#9367C6", img: require("./Base/img/6.svg") },
    7: { name: "计算公式", color: "#D97B4E", img: require("./Base/img/7.svg") },
    8: { name: "规则", color: "#E8A530", img: require("./Base/img/8.svg") },
    9: { name: "指标", color: "#2B82EC", img: require("./Base/img/9.svg") },
    10: { name: "字段", color: "#6776CF", img: require("./Base/img/10.svg") }
}