<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Edm\Admin\Controller; use Illuminate\Routing\Controller; use ModStart\Admin\Concern\HasAdminQuickCRUD; use ModStart\Admin\Layout\AdminCRUDBuilder; use ModStart\Core\Assets\AssetsUtil; use ModStart\Field\AbstractField; use ModStart\Field\AutoRenderedFieldValue; use ModStart\Field\Tags; use ModStart\Grid\GridFilter; use ModStart\Support\Concern\HasFields; use Module\Edm\Type\EdmRandomType; class RandomController extends Controller { use HasAdminQuickCRUD; protected function crud(AdminCRUDBuilder $JeXgT) { $JeXgT->init('edm_random')->field(function ($JeXgT) { $JeXgT->id('id', 'ID'); $JeXgT->tags('tags', '标签')->tagModelField('edm_random', 'tags', Tags::SERIALIZE_TYPE_COLON_SEPARATED)->serializeType(Tags::SERIALIZE_TYPE_COLON_SEPARATED); $JeXgT->radio('type', '类型')->optionType(EdmRandomType::class)->when('=', EdmRandomType::IMAGE, function ($JeXgT) { $JeXgT->image('imageContent', '图片'); })->when('=', EdmRandomType::TEXT, function ($JeXgT) { $JeXgT->text('textContent', '文字'); })->when('=', EdmRandomType::RICH, function ($JeXgT) { $JeXgT->richHtml('richContent', '富文本'); }); $JeXgT->display('_content', '内容')->hookRendering(function (AbstractField $A02Yi, $MNZ1i, $grXZZ) { switch ($MNZ1i->type) { case EdmRandomType::RICH: return AutoRenderedFieldValue::make('<div>' . $MNZ1i->richContent . '</div>'); case EdmRandomType::TEXT: return AutoRenderedFieldValue::make('<div>' . htmlspecialchars($MNZ1i->textContent) . '</div>'); case EdmRandomType::IMAGE: return AutoRenderedFieldValue::make('<img class="tw-w-8" src="' . AssetsUtil::fixFull($MNZ1i->imageContent) . '" />'); } return '-'; }); })->gridFilter(function (GridFilter $FdfN8) { $FdfN8->eq('id', L('ID')); $FdfN8->like('tags', '标签'); })->canBatchDelete(true)->title('随机语料'); } }