mrshanebarron/tree-view 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mrshanebarron/tree-view

最新稳定版本:v1.0.3

Composer 安装命令:

composer require mrshanebarron/tree-view

包简介

Tree view component for Laravel - supports Livewire and Vue

README 文档

README

Hierarchical tree structure component for Laravel applications. Supports nested items, expand/collapse, selection, and custom icons. Works with Livewire and Vue 3.

Installation

composer require mrshanebarron/tree-view

Livewire Usage

Basic Usage

@php
$items = [
    [
        'id' => 'src',
        'label' => 'src',
        'icon' => 'folder',
        'children' => [
            ['id' => 'app', 'label' => 'App.vue', 'icon' => 'file'],
            ['id' => 'main', 'label' => 'main.js', 'icon' => 'file'],
        ]
    ],
    ['id' => 'readme', 'label' => 'README.md', 'icon' => 'file'],
];
@endphp

<livewire:sb-tree-view :items="$items" />

With Default Expanded

<livewire:sb-tree-view :items="$items" :expanded="['src', 'components']" />

Selectable Items

<livewire:sb-tree-view :items="$items" :selectable="true" />

With Icons

<livewire:sb-tree-view :items="$items" :show-icons="true" />

Livewire Props

Prop Type Default Description
items array [] Tree structure array
expanded array [] IDs of initially expanded nodes
selectable boolean false Enable item selection
showIcons boolean true Show folder/file icons

Item Structure

$items = [
    [
        'id' => 'unique-id',       // Required: unique identifier
        'label' => 'Display Name', // Required: visible text
        'icon' => 'folder',        // Optional: 'folder' or 'file'
        'children' => [            // Optional: nested items
            ['id' => 'child-1', 'label' => 'Child Item', 'icon' => 'file'],
        ],
    ],
];

Events

<livewire:sb-tree-view
    :items="$items"
    :selectable="true"
    @tree-item-selected="handleSelect"
/>

Vue 3 Usage

Setup

import { SbTreeView } from './vendor/sb-tree-view';
app.component('SbTreeView', SbTreeView);

Basic Usage

<template>
  <SbTreeView :items="items" />
</template>

<script setup>
const items = [
  {
    id: 'docs',
    label: 'Documents',
    icon: 'folder',
    children: [
      { id: 'resume', label: 'Resume.pdf', icon: 'file' },
    ]
  }
];
</script>

With Selection

<template>
  <SbTreeView
    :items="items"
    :selectable="true"
    :expanded="['docs']"
    @selected="handleSelect"
  />
</template>

<script setup>
function handleSelect(id) {
  console.log('Selected:', id);
}
</script>

Vue Props

Prop Type Default Description
items Array [] Tree items
expanded Array [] Expanded node IDs
selectable Boolean false Enable selection
showIcons Boolean true Show icons

Events

Event Payload Description
selected string Emitted when item is selected
expanded string Emitted when node is expanded
collapsed string Emitted when node is collapsed

Use Cases

File Explorer

$items = $this->buildFileTree(base_path());

private function buildFileTree(string $path): array
{
    $items = [];
    foreach (scandir($path) as $file) {
        if ($file === '.' || $file === '..') continue;

        $fullPath = $path . '/' . $file;
        $item = [
            'id' => $fullPath,
            'label' => $file,
            'icon' => is_dir($fullPath) ? 'folder' : 'file',
        ];

        if (is_dir($fullPath)) {
            $item['children'] = $this->buildFileTree($fullPath);
        }

        $items[] = $item;
    }
    return $items;
}

Category Browser

$items = Category::with('children')
    ->whereNull('parent_id')
    ->get()
    ->map(fn($cat) => $this->categoryToTreeItem($cat))
    ->toArray();

private function categoryToTreeItem($category): array
{
    return [
        'id' => (string) $category->id,
        'label' => $category->name,
        'icon' => $category->children->count() ? 'folder' : 'file',
        'children' => $category->children->map(
            fn($c) => $this->categoryToTreeItem($c)
        )->toArray(),
    ];
}

Organization Chart

$items = [
    [
        'id' => 'ceo',
        'label' => 'CEO',
        'icon' => 'folder',
        'children' => [
            [
                'id' => 'cto',
                'label' => 'CTO',
                'icon' => 'folder',
                'children' => [
                    ['id' => 'dev1', 'label' => 'Developer 1', 'icon' => 'file'],
                    ['id' => 'dev2', 'label' => 'Developer 2', 'icon' => 'file'],
                ]
            ],
            ['id' => 'cfo', 'label' => 'CFO', 'icon' => 'file'],
        ]
    ]
];

Styling

The tree view includes:

  • Indented nested levels
  • Expand/collapse chevron icons
  • Folder and file icons
  • Selection highlight
  • Hover effects

Requirements

  • PHP 8.1+
  • Laravel 10, 11, or 12
  • Tailwind CSS 3.x
  • Alpine.js

License

MIT License

mrshanebarron/tree-view 适用场景与选型建议

mrshanebarron/tree-view 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mrshanebarron/tree-view 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mrshanebarron/tree-view 我们能提供哪些服务?
定制开发 / 二次开发

基于 mrshanebarron/tree-view 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-14