<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Nav\Admin\Controller; use Illuminate\Routing\Controller; use ModStart\Admin\Concern\HasAdminQuickCRUD; use ModStart\Admin\Layout\AdminCRUDBuilder; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Type\TypeUtil; use ModStart\Field\AbstractField; use ModStart\Field\AutoRenderedFieldValue; use ModStart\Field\Type\FieldRenderMode; use ModStart\Form\Form; use ModStart\ModStart; use ModStart\Repository\Filter\ScopeFilter; use ModStart\Support\Concern\HasFields; use Module\Nav\Type\NavOpenType; use Module\Nav\Type\NavPosition; use Module\Nav\Util\NavUtil; class NavController extends Controller { use HasAdminQuickCRUD; protected function crud(AdminCRUDBuilder $kC4To) { goto eEd56; eEd56: if ($kC4To->mode() == AdminCRUDBuilder::MODE_FORM) { goto rJqXm; bsG5D: foreach (NavUtil::tree() as $nfRLq) { $ZC1pt[] = array('id' => $nfRLq['id'], 'position' => $nfRLq['position'], 'name' => $nfRLq['name']); if (!empty($nfRLq['_child'])) { foreach ($nfRLq['_child'] as $VWZQW) { $ZC1pt[] = array('id' => $VWZQW['id'], 'position' => $VWZQW['position'], 'name' => $nfRLq['name'] . ' → ' . $VWZQW['name']); } } } goto wMMXy; K2gVi: ModStart::scriptFile('module/Nav/Admin/Controller/NavEdit.js'); goto phB2N; wMMXy: ModStart::script('window.__positionNavs=' . json_encode($ZC1pt) . ';'); goto K2gVi; rJqXm: $ZC1pt = array(); goto bsG5D; phB2N: } goto J51lV; N5OPq: $kC4To->scopeDefault(NavPosition::first()); goto xgYE7; J51lV: $kC4To->init('nav')->field(function ($kC4To) { $kC4To->id('id', 'ID'); $kC4To->select('position', '位置')->optionType(NavPosition::class)->hookRendering(function (AbstractField $TMEcx, $kHxHl, $hwsPf) { switch ($TMEcx->renderMode()) { case FieldRenderMode::DETAIL: case FieldRenderMode::GRID: if ($kHxHl->pid) { return AutoRenderedFieldValue::make(''); } return AutoRenderedFieldValue::make(TypeUtil::name(NavPosition::class, $kHxHl->position)); } }); $kC4To->text('name', '名称'); $kC4To->icon('icon', '图标')->help('部分主题支持图标显示'); $kC4To->link('link', '链接'); $kC4To->switch('enable', '启用')->optionsYesNo()->gridEditable(true)->defaultValue(true); $kC4To->radio('openType', '打开方式')->optionType(NavOpenType::class)->defaultValue(NavOpenType::CURRENT_WINDOW); $kC4To->display('created_at', L('Created At'))->listable(false); $kC4To->display('updated_at', L('Updated At'))->listable(false); }); goto miwra; xgYE7: $kC4To->hookSaved(function (Form $l3dqy) { $kHxHl = $l3dqy->item(); if ($kHxHl->pid > 0) { $MGuuU = ModelUtil::get('nav', $kHxHl->pid); ModelUtil::update('nav', $kHxHl->id, array('position' => $MGuuU['position'])); } })->hookChanged(function (Form $l3dqy) { NavUtil::clearCache(); })->canBatchDelete(true)->asTree('id', 'pid', 'sort', 'name')->treeMaxLevel(3)->title('导航设置'); goto KWAK8; miwra: foreach (NavPosition::getList() as $FYJFh => $VRDYW) { $kC4To->scopeFilter($FYJFh, $VRDYW, function (ScopeFilter $bWyIm) use($FYJFh) { return $bWyIm->where('position', $FYJFh); }); } goto N5OPq; KWAK8: } }