---
title: 基本展示
order: 1
---

本 Demo 演示一行文字的用法。

<!-- prettier-ignore -->
````jsx

import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import ActionTree from '@riil-frontend/component-action-tree';
import { Checkbox } from '@alifd/next';

const getIconPath = (iconName) => `../demo/images/${iconName}.svg`;

var treeData = [
	{
		id: '0',
		label: '网络设备',
		icon: getIconPath('res_netdevices'),
		count: '1',
		operation: [
			{ type: 'add' },{ type: 'add',icon:'wenjianjia',label: '添加文件夹' },
			{ type: 'edit',label: '重命名' },
			{ type: 'delete' },
			{
				type: 'open',
				icon: 'smile',
				label: '启用',
				preDivider: true,
			},
		],
		children: [
			{
				id: '0-0',
				parentId: '0',
				label: '锐捷交换机',
				icon: getIconPath('res_exchanger'),
				operation: [{ type: 'add', }],
			},
			{
				id: '0-1',
				parentId: '0',
				label: '锐捷路由器',
				icon: getIconPath('res_router'),
				operation: [{ type: 'add',icon:'Icon-baoguo_hezi_o' }, { type: 'edit' }],
			},	
			{
				id: '0-2',
				parentId: '0',
				label: 'label追加',
				append:true,
				icon: getIconPath('res_router'),
			},
		],
	},
	{
		id: '1',
		label: '主机',
		icon: getIconPath('res_host'),
		children: [
			{
				id: '1-0',
				parentId: '1',
				label: '数据库',
				icon: getIconPath('res_database'),
			}
		],
	},
];
const loopTree = (data, key, callback) => {
	data.forEach((item, index, arr) => {
		if (item.id === key) {
			return callback(item, index, arr);
		}
		if (item.children) {
			return loopTree(item.children, key, callback);
		}
	});
};

const clone = (data) => JSON.parse(JSON.stringify(data));
function App() {
	const inputProps={style:{width:'50px'},maxLength:20,defaultValue:'未命名'}
	const [dataSource, setDataSource] = useState(clone(treeData));
	const [showIcon, setShowIcon] = useState(true);
	const [showCount, setShowCount] = useState(true);
	const [draggable, setDraggable] = useState(true);
	const [showPopupIcon, setShowPopupIcon] = useState(true);
	const [addNodeBottom, setAddNodeBottom] = useState(false);
	const onAdd = (node) => {
		console.log("add:"+node);
		console.dir(node);
		loopTree(treeData, node.parentId, (parent, index, arr) => {
			const addNode = { ...node, id: new Date() + '', operation: [{ type: 'add' }, { type: 'edit' }, { type: 'delete' }] };
			parent.children = parent.children || [];
			parent.children.splice(node.index,0,addNode);
		});
		setDataSource(clone(treeData));
	};
	const onEdit = (node) => {
		loopTree(treeData, node.id, (item, index, arr) => {
			arr[index] = node;
		});
		setDataSource(clone(treeData));
	};
	const onDelete = (node) => {
		loopTree(treeData, node.id, (item, index, arr) => {
			arr.splice(index, 1);
		});
		setDataSource(clone(treeData));
	};
	const onDrag = (dataSource) => {
		setDataSource(clone(dataSource));
	};
	const onOperation = (node, type) => {
		if (type == 'add') {
			onAdd(node);
		} else if (type == 'edit') {
			onEdit(node);
		} else if (type == 'delete') {
			onDelete(node);
		} else {
			console.log(`on${type}`);
		}
	};
	const onSelect = (selectedKeys, extra) => console.log('onSelect', selectedKeys);

	return (
		<div style={{ width: 400}}>
			<div style={{ marginBottom: 8, borderBottom: '#e4e8ed solid 1px' }}>
				<Checkbox
					checked={showIcon}
					onChange={(b) => {
						setShowIcon(b);
					}}
				>
					是否显示节点图标
				</Checkbox>
				<br />
				<Checkbox
					checked={showCount}
					onChange={(b) => {
						setShowCount(b);
					}}
				>
					是否显示统计数字
				</Checkbox>
				<br />
				<Checkbox
					checked={draggable}
					onChange={(b) => {
						setDraggable(b);
					}}
				>
					是否支持节点拖动
				</Checkbox>
				<br />
				<Checkbox
					checked={showPopupIcon}
					onChange={(b) => {
						setShowPopupIcon(b);
					}}
				>
					是否显示...浮层中的按钮图标
				</Checkbox>
				<br />
				<Checkbox
					checked={addNodeBottom}
					onChange={(b) => {
						setAddNodeBottom(b);
					}}
				>
					添加后的节点出现在底部
				</Checkbox>
				<br />
				<br />
			</div>
			<ActionTree 
				dataSource={dataSource} 
				showIcon={showIcon} 
				showCount={showCount} 
				draggable={draggable} 
				onOperation={onOperation} 
				inputProps={inputProps}
				onDrag={onDrag} 
				onSelect={onSelect} 
				showPopupIcon={showPopupIcon}
				addNodePosition={addNodeBottom ? 'bottom' : 0}
				/>
		</div>
	);
}

ReactDOM.render(<App />, mountNode);

````
