PHP code example of lartrix / thinkrix

1. Go to this page and download the library: Download lartrix/thinkrix library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lartrix / thinkrix example snippets


// 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/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',
        ],
    ],
],

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

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

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());
bash
php think thinkrix:project-install vendor.project --dry-run
php think thinkrix:project-install vendor.project --execute
bash
# 1. 引入包
composer 首次安装)
php think thinkrix:publish

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

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