PHPackages                             lartrix/thinkrix - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Admin Panels](/categories/admin)
4. /
5. lartrix/thinkrix

ActiveLibrary[Admin Panels](/categories/admin)

lartrix/thinkrix
================

ThinkPHP 8 后台管理包，为 trix 前端提供 API 接口

1.0.49(1w ago)155MITPHPPHP ^8.1CI passing

Since Jun 12Pushed 1w agoCompare

[ Source](https://github.com/maliang/thinkrix)[ Packagist](https://packagist.org/packages/lartrix/thinkrix)[ RSS](/packages/lartrix-thinkrix/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (7)Versions (48)Used By (0)

Lartrix Think (Thinkrix)
========================

[](#lartrix-think-thinkrix)

> ThinkPHP 8 后台管理包，为 [Trix](https://github.com/lartrix/trix) 前端提供完整 API 接口

Thinkrix 是 [Lartrix](https://github.com/lartrix/lartrix)（Laravel 版）的 ThinkPHP 移植版，两者功能同步。前端统一使用 [Trix](https://github.com/lartrix/trix)（Vue 3 + NaiveUI + vschema-ui），后端生态共享。

模块生态协议
------

[](#模块生态协议)

当前版本包含破坏性升级，旧 Registry 配置名和旧的独立 manifest 约定不再兼容：

- 模块仍使用根目录 `module.json`，但**只有 `module.json.trix` 是 Trix 生态协议**。`name`、`providers`、`middleware` 等顶层字段属于 ThinkPHP 模块运行时，不会被当作 Trix 清单字段解析。
- 模块市场配置统一位于 `config/thinkrix.php` 的 `module_market` 节点；市场 Auth Key 只使用环境变量 `TRIX_AUTH_KEY`，不再读取 `THINKRIX_MODULE_REGISTRY_*`、`TRIX_REGISTRY_*` 等旧名称。
- 项目安装计划只会原子写入 `config/trix-project.php`。根目录 `trix-project.json` 是项目发布清单，不是安装后的运行时配置。

```
THINKRIX_MODULE_MARKET_URL=https://registry.example.com/api
TRIX_AUTH_KEY=your-auth-key
THINKRIX_MODULE_MARKET_SIGNATURE_KEY=your-signature-key
```

```
{
  "name": "Demo",
  "enabled": false,
  "trix": {
    "schema_version": "trix.module.v1",
    "id": "vendor.demo",
    "name": "Demo",
    "version": "1.0.0",
    "type": "module",
    "adapter": {
      "language": "php",
      "language_version": ">=8.1",
      "framework": "thinkphp",
      "framework_version": ">=8.0",
      "status": "stable"
    }
  }
}
```

项目安装先解析 Registry 安装计划并生成 `config/trix-project.php`；加上 `--execute` 后，才会依次下载、校验、暂存、复核并复制缺失模块：

```
php think thinkrix:project-install vendor.project --dry-run
php think thinkrix:project-install vendor.project --execute
```

安全边界是强制的：市场 HTTP 请求不跟随重定向；包下载地址必须与 `module_market.url` 的 scheme、host、port 同源；暂存、复制和更新替换前都会递归拒绝符号链接。Zip 预检还会拒绝目录穿越、绝对路径和 Windows 盘符路径，安装链路不会自动执行包内脚本。

模块接口按职责拆分：`ModuleController` 仅管理本地已安装模块及 Logo；`ModuleMarketController` 负责市场列表和模块/项目安装；`ModulePublishController` 负责模块与项目发布。宿主项目需要替换控制器时，应分别配置 `controllers.module`、`controllers.module_market` 和 `controllers.module_publish`。

完整说明见 [模块开发与生态](docs/guide/modules.md)。

---

功能特性
----

[](#功能特性)

- **用户管理** — 用户 CRUD、角色分配、状态管理、批量删除、Excel 导出
- **角色管理** — 角色 CRUD、权限分配、启用/禁用
- **权限管理** — 树形权限管理、按模块归组
- **菜单管理** — 树形菜单配置、JSON Schema 渲染、图标选择器
- **系统设置** — 标题/Logo/版权等站点配置
- **数据字典** — 字典分组/项管理，前端 Select 选项
- **通知中心** — 消息管理、已读/未读、轮询/WebSocket 实时推送
- **模块管理** — 文件系统模块发现、启停管理、模块市场
- **主题配置** — 亮/暗模式、主题色、布局模式等全量前端配置
- **实时消息** — 支持轮询(polling)和 WebSocket 两种模式，可配置开关和间隔
- **导航栏扩展** — 支持通过配置添加自定义图标按钮，或通过 schema\_api 返回任意 UI
- **Token 认证** — Bearer Token，支持多 guard 隔离、过期时间配置
- **RBAC 权限** — 基于角色的访问控制，支持权限继承
- **二级后台** — 模块化开发，支持独立后台（如商户后台）
- **代码生成** — 模块脚手架命令，快速生成 CRUD

---

安装
--

[](#安装)

### 环境要求

[](#环境要求)

- PHP 8.1+
- ThinkPHP 8.0+
- MySQL 5.7+ / MariaDB 10.3+
- Composer 2.x

### 步骤

[](#步骤)

```
# 1. 引入包
composer require lartrix/thinkrix

# 2. 发布前端资源（首次安装）
php think thinkrix:publish

# 3. 安装（建表、初始化数据）
php think thinkrix:install

# 4. 前端访问
# 浏览器打开 http://your-domain/admin
# 默认管理员 admin，密码由安装时生成
```

安装命令会自动执行迁移或兜底建表，并创建超级管理员角色、权限、默认菜单和系统设置。

---

配置
--

[](#配置)

安装后配置文件位于 `config/thinkrix.php`，支持环境变量覆盖：

配置键环境变量默认值说明`path``THINKRIX_PATH``/admin`前端入口路径`api_prefix``THINKRIX_API_PREFIX``api/admin`API 路由前缀`guard``THINKRIX_GUARD``admin`当前 guard 名称`theme.appTitle``THINKRIX_APP_TITLE``Thinkrix Admin`系统标题`logo``THINKRIX_LOGO``/admin/favicon.svg`系统 Logo`super_admin_role``THINKRIX_SUPER_ADMIN_ROLE``super-admin`超级管理员角色`realtime.driver``THINKRIX_REALTIME_DRIVER``polling`实时消息模式（polling/ws）`realtime.polling.interval``THINKRIX_REALTIME_POLLING_INTERVAL``15000`轮询间隔（毫秒）`header.global_search``THINKRIX_HEADER_GLOBAL_SEARCH``true`显示全局搜索`header.notification``THINKRIX_HEADER_NOTIFICATION``true`显示通知中心`header.lang_switch``THINKRIX_HEADER_LANG_SWITCH``true`显示语言切换完整配置项参见 `config/thinkrix.php`。

---

增加语言
----

[](#增加语言)

语言种类由 Thinkrix 后端配置提供，不需要修改或重新编译 Trix 前端。例如增加日语：

```
// config/thinkrix.php
'languages' => [
    'zh-CN' => ['label' => '中文', 'file' => 'zh-cn', 'naive_locale' => 'zh-CN'],
    'en-US' => ['label' => 'English', 'file' => 'en-us', 'naive_locale' => 'en-US'],
    'ja-JP' => ['label' => '日本語', 'file' => 'ja-jp', 'naive_locale' => 'en-US'],
],
```

然后创建项目语言文件 `config/lang/ja-jp.php`。它可以同时包含后端 Schema 文案和 Trix 界面翻译；项目语言会覆盖包内同名键。切换语言后，前端会从 `/translations` 动态加载语言包并缓存，无需增加前端语言模块。

`naive_locale` 控制 Naive UI 日期、分页等内置文案的基础语言，目前支持 `zh-CN` 和 `en-US`；其他语言可以先选择其中一个作为回退。

---

命令参考
----

[](#命令参考)

命令说明`php think thinkrix:install`全新安装（建表+初始化数据）`php think thinkrix:publish`发布前端静态资源`php think thinkrix:make-backend`创建二级后台模块`php think thinkrix:remove-backend`删除二级后台模块`php think thinkrix:module-list`列出已安装模块`php think thinkrix:module-make`创建新模块`php think thinkrix:module-enable`启用模块`php think thinkrix:module-disable`禁用模块`php think thinkrix:module-delete`删除模块`php think thinkrix:module-publish-config`发布模块配置到项目---

导航栏自定义
------

[](#导航栏自定义)

支持两种方式在右上角添加自定义按钮：

### 1. 简单图标按钮（配置即可）

[](#1-简单图标按钮配置即可)

```
// config/thinkrix.php
'header' => [
    'custom_items' => [
        [
            'icon'        => 'carbon:notification',
            'tooltip'     => '消息中心',
            'badge_api'   => '/api/custom/unread',  // 返回 { count: N }
            'badge_color' => '#f00',
            'click'       => 'link',
            'click_target'=> 'https://my-app.com',
        ],
    ],
],
```

### 2. 高级自定义（通过 schema API 返回任意 UI）

[](#2-高级自定义通过-schema-api-返回任意-ui)

```
'header' => [
    'custom_items' => [
        ['schema_api' => '/api/admin/header/my-dropdown'],
    ],
],
```

`schema_api` 接口返回 vschema-ui JSON 节点，支持 NaiveUI 所有组件（Popover、Dropdown、Switch 等）。

---

实时消息配置
------

[](#实时消息配置)

```
'realtime' => [
    'enabled' => true,
    'driver' => 'polling',    // polling | ws
    'polling' => [
        'interval' => 15000,  // 毫秒
        'api' => '/notifications/poll',
    ],
    'websocket' => [
        'url' => '',
        'protocol' => 'ws',
    ],
],
```

启用后前端每 `interval` 毫秒调用 `/notifications/poll?since_id=X` 拉取增量消息。 开发者可继承 `RealtimeService` 重写 `getNewMessages()` / `getUnreadCount()` 实现自定义逻辑。

---

Schema Builder
--------------

[](#schema-builder)

通过 PHP 代码构建 JSON Schema，由前端 vschema-ui 渲染为 NaiveUI 组件。

### 示例：CRUD 页面

[](#示例crud-页面)

```
use Thinkrix\Schema\Components\NaiveUI\{Button, Input, Select, SwitchC, Tag, Space, Popconfirm};
use Thinkrix\Schema\Components\Business\{CrudPage, OptForm};
use Thinkrix\Schema\Actions\{SetAction, CallAction, FetchAction, IfAction};

// 表单
$form = OptForm::make('formData')
    ->fields([
        ['用户名', 'username', Input::make()->placeholder('请输入用户名')],
        ['角色', 'roles', Select::make()->multiple(true)->options('{{ roleOptions }}')],
        ['状态', 'status', SwitchC::make(), true],
    ])
    ->buttons([
        Button::make()->on('click', SetAction::make('formVisible', false))->text('取消'),
        Button::make()->type('primary')->on('click', ['call' => 'handleSubmit'])->text('确定'),
    ]);

// 数据表格
$schema = CrudPage::make('用户管理')
    ->apiPrefix('/users')
    ->columns([
        ['key' => 'id', 'title' => 'ID', 'width' => 80],
        ['key' => 'username', 'title' => '用户名'],
        ['key' => 'status', 'title' => '状态', 'slot' => [
            Tag::make()->props(['type' => "{{ row.status ? 'success' : 'error' }}"])
                ->children(["{{ row.status ? '启用' : '禁用' }}"]),
        ]],
        ['key' => 'actions', 'title' => '操作', 'slot' => [
            Button::make()->type('primary')->text('编辑')
                ->on('click', [SetAction::make('editingId', '{{ row.id }}'), SetAction::make('formVisible', true)]),
        ]],
    ])
    ->defaultPageSize(15)
    ->build();

return success($schema->toArray());
```

支持组件：120+ NaiveUI 组件封装 + 自定义业务组件（CrudPage、OptForm、DataTable 等）。

---

文件结构
----

[](#文件结构)

```
lartrix-think/
├── composer.json
├── config/thinkrix.php         # 配置文件
├── database/migrations/        # 数据库迁移
├── src/
│   ├── ThinkrixService.php     # 服务注册
│   ├── Support/
│   │   └── helpers.php         # success/error 工具函数
│   ├── Exceptions/             # 异常处理（ApiException）
│   ├── Exports/                # Excel 导出（PhpSpreadsheet）
│   ├── Middleware/              # 认证、权限、异常处理中间件
│   ├── Services/               # 业务服务层
│   │   ├── AuthService.php     # Token 认证
│   │   ├── PermissionService.php # RBAC 权限
│   │   ├── RealtimeService.php # 实时消息轮询
│   │   └── ModuleService.php   # 模块管理
│   ├── Models/                 # 数据模型
│   ├── Controllers/            # API 控制器
│   ├── Commands/               # 20+ 控制台命令
│   ├── Schema/                 # Schema Builder
│   │   ├── Actions/            # 8 种 Action 类型
│   │   └── Components/         # 120+ UI 组件封装
│   └── routes.php              # API 路由
├── resources/admin/            # 前端编译产物
├── stubs/                      # 代码生成模板
└── tests/                      # 测试

```

---

与 Laravel 版的差异
--------------

[](#与-laravel-版的差异)

Thinkrix 与 [Lartrix](https://github.com/lartrix/lartrix)（Laravel 版）功能同步，主要差异：

方面Lartrix (Laravel)Thinkrix (ThinkPHP)框架Laravel 10/11/12ThinkPHP 8Excel 导出maatwebsite/excelPhpSpreadsheet（自带封装）权限包Spatie Permission自定义 RBACTokenLaravel Sanctum自定义 Bearer Token多态关联Eloquent morphToManyBelongsToMany + wherePivot配置发布`php artisan vendor:publish``php think thinkrix:publish`---

License
-------

[](#license)

MIT

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance98

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

47

Last Release

12d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/42ab86818b2e560875e3e225875117c48519118b76a519b61151b388c62d21df?d=identicon)[maliang](/maintainers/maliang)

---

Top Contributors

[![maliang](https://avatars.githubusercontent.com/u/367390?v=4)](https://github.com/maliang "maliang (54 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lartrix-thinkrix/health.svg)

```
[![Health](https://phpackages.com/badges/lartrix-thinkrix/health.svg)](https://phpackages.com/packages/lartrix-thinkrix)
```

###  Alternatives

[zoujingli/think-library

Core library and common services for ThinkAdmin

8373.4k20](/packages/zoujingli-think-library)[craftcms/cms

Craft CMS

3.6k3.6M3.2k](/packages/craftcms-cms)[bedita/manager

BEdita Manager - official admin webapp for BEdita4 API

131.2k](/packages/bedita-manager)[saithink/saiadmin

webman plugin

28411.6k1](/packages/saithink-saiadmin)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k14](/packages/2lenet-crudit-bundle)[pimcore/studio-backend-bundle

Pimcore Studio Backend Bundle

20203.9k22](/packages/pimcore-studio-backend-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
