Search by

tsaotai / tsaotai-pro

TsaoTai Pro — configurable Table/Form/Grid backend (ProResource + Gateway)

Maintainers

Package info

github.com/tsaotai/tsaotai-pro

pkg:composer/tsaotai/tsaotai-pro

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

2026.1.12 2026-09-07 08:19 UTC

This package is auto-updated.

Last update: 2026-09-07 08:23:15 UTC


README

版本:2026.1.12 · 日期:2026-09-07
Composer:tsaotai/tsaotai-pro
命名空间:tsaotai\pro\
源码:github.com/tsaotai/tsaotai-pro
对齐:tsaotai/tsaotai-addons

ThinkPHP 8 上的配置中后台引擎:资源定义 + Gateway 分发 + Table/Form/Grid 后端能力。
不是插件壳;不替代 addons、登录、ACL、主题。

前端另见产品仓 packages/tsaotai-pro(运行时 TsaoTai.table / form / grid)。
发版细则:PACKAGING.md

提供 / 不提供

提供 不提供
ProResource::define 与 meta / capabilities 业务 *Resource.php
ProGateway 动作分发 /api/pro/... 路由(宿主声明)
list / get / save / delete / dic / batch / reorder CSRF、captcha、Session 登录实现
导入导出 + ProTask 前端 JS
Grid SSRM 应用中心 / 租户勾选
ProHost + Contracts;Think Service 只 boot Host 脚手架 CLI

安装

composer require tsaotai/tsaotai-pro:^2026.1

Think 发现 extra.think.servicestsaotai\pro\Service

  1. 加载包内 config.phpconfig('tsaotai_pro')
  2. ProHost::bootFromConfig(...)auto_boot_host => false 可关)
  3. 自动挂路由

宿主最小接入

1. 路由

Route::any('api/pro/:plugin/:name/:action', 'Your\\ProController@dispatch')
    ->pattern(['plugin' => '[\w\-]+', 'name' => '[\w\-]+', 'action' => '[\w\-]+']);

2. 控制器实现 Responder

use tsaotai\pro\Http\ProGateway;
use tsaotai\pro\Contracts\Responder;

class ProController implements Responder
{
    public function dispatch()
    {
        return ProGateway::dispatch(
            (string) $this->request->param('plugin', ''),
            (string) $this->request->param('name', ''),
            (string) $this->request->param('action', ''),
            $this
        );
    }

    public function ok($data = null, string $msg = '') { /* JSON ok */ }
    public function fail(string $msg, int $code = 1, $data = null) { /* JSON fail */ }
    public function requireCaptcha(?string $captcha = null) { /* 危险操作验证码 */ }
}

可选 proUser(): ?array 供限流 / 审计。

3. 业务资源

约定路径:{addons_root}/{plugin}/pro/{Name}Resource.php

use tsaotai\pro\Resource\ProResource;

ProResource::define('tag', [
    'table' => 'pro_demo_tag',
    'pk' => 'id',
    'capabilities' => ['core', 'batch', 'import-export', 'reorder'],
    'search' => ['name', 'status'],
    'searchLike' => ['name'],
    'filters' => ['status'],
    'fillable' => ['name', 'status', 'amount'],
    'sortable' => ['id', 'name', 'amount'],
    // 'db' => fn () => ...,
    // 'hooks' => ['authorize' => ..., 'scopeQuery' => ...],
]);

4. 注入 Host(推荐)

包默认 auditor = noop;无 root_path() 时必须配置 addons_path

\tsaotai\pro\ProHost::boot([
    'translator'  => fn (string $s) => translate($s),
    'runtime'     => runtime_path(),
    'addons_root' => root_path() . '/addons',
    'auditor'     => fn (string $action, array $ctx) => { /* 写审计 */ },
    'config'      => fn (string $key, $default = null) => config($key) ?? $default,
]);

能力与动作

capabilities 动作
core(默认) list get save delete dic meta
batch batch(delete 须 captcha)
reorder reorder
import-export export import template
grid-ssrm grid / rows

异步任务下载 HMAC:配置 tsaotai_pro.download_secret(或宿主 common.app_key / app.app_key / common.app_id)。无密钥则拒绝签发 token

配置 tsaotai_pro

默认 说明
auto_boot_host true Service 是否自动 boot
addons_path '' 空则 root_path()/addons;再无则抛错
runtime_path '' 空则 runtime_path()
rate_limit_export 10 导出每用户每分钟
download_secret '' 下载 HMAC;空则回退其它键

安全模型(宿主责任)

  • 鉴权 / CSRF / captcha:宿主控制器
  • 行级权限:Resource hooks.authorize / scopeQuery
  • 多库:Resource db 闭包;默认 Db::connect()
  • Gateway 对外异常:过滤 SQL/堆栈特征,其余短业务文案放行
  • plugin 名仅 [\w\-]+,并校验 realpath 不逃出 addons 根

目录

src/
  ProHost.php · Service.php
  Contracts/ · Resource/ · Http/ · Query/ · Io/
config.php
tests/
VERSION · README.md · PACKAGING.md · CHANGELOG.md · LICENSE

从旧命名迁移

tsaotai/pro tsaotai/tsaotai-pro
TsaoTai\Pro\* tsaotai\pro\{Resource,Http,Query,Io}\*

无 class_alias。

测试

composer install
vendor/bin/phpunit

License

Apache-2.0