<?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\Core\Util\SerializeUtil; 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 $P2vse) { goto b9Z3c; b9Z3c: if ($P2vse->mode() == AdminCRUDBuilder::MODE_FORM) { goto h_AoM; x7pCJ: ModStart::scriptFile('module/Nav/Admin/Controller/NavEdit.js'); goto D6ri3; wSGO4: foreach (NavUtil::tree() as $Iim2u) { $AgDpo[] = array('id' => $Iim2u['id'], 'position' => $Iim2u['position'], 'name' => $Iim2u['name']); if (!empty($Iim2u['_child'])) { foreach ($Iim2u['_child'] as $qFtk6) { $AgDpo[] = array('id' => $qFtk6['id'], 'position' => $qFtk6['position'], 'name' => $Iim2u['name'] . ' → ' . $qFtk6['name']); } } } goto WQKvh; WQKvh: ModStart::script('window.__positionNavs=' . SerializeUtil::jsonEncode($AgDpo) . ';'); goto x7pCJ; h_AoM: $AgDpo = array(); goto wSGO4; D6ri3: } goto mTUhg; mTUhg: $P2vse->init('nav')->field(function ($P2vse) { $P2vse->id('id', 'ID'); $P2vse->select('position', '位置')->optionType(NavPosition::class)->hookRendering(function (AbstractField $jJyrp, $YaV4m, $DbHm9) { switch ($jJyrp->renderMode()) { case FieldRenderMode::DETAIL: case FieldRenderMode::GRID: if ($YaV4m->pid) { return AutoRenderedFieldValue::make(''); } return AutoRenderedFieldValue::make(TypeUtil::name(NavPosition::class, $YaV4m->position)); } }); $P2vse->text('name', '名称'); $P2vse->icon('icon', '图标')->help('部分主题支持图标显示'); $P2vse->link('link', '链接'); $P2vse->switch('enable', '启用')->optionsYesNo()->gridEditable(true)->defaultValue(true); $P2vse->radio('openType', '打开方式')->optionType(NavOpenType::class)->defaultValue(NavOpenType::CURRENT_WINDOW); $P2vse->display('created_at', L('Created At'))->listable(false); $P2vse->display('updated_at', L('Updated At'))->listable(false); }); goto YUl8U; MzguK: $P2vse->scopeDefault(NavPosition::first()); goto Ho6fB; Ho6fB: $P2vse->hookSaved(function (Form $NX6uw) { $YaV4m = $NX6uw->item(); if ($YaV4m->pid > 0) { $GislP = ModelUtil::get('nav', $YaV4m->pid); ModelUtil::update('nav', $YaV4m->id, array('position' => $GislP['position'])); } })->hookChanged(function (Form $NX6uw) { NavUtil::clearCache(); })->canBatchDelete(true)->asTree('id', 'pid', 'sort', 'name')->treeMaxLevel(3)->title('导航设置'); goto B8btb; YUl8U: foreach (NavPosition::getList() as $sFwJk => $jkY57) { $P2vse->scopeFilter($sFwJk, $jkY57, function (ScopeFilter $mHisM) use($sFwJk) { return $mHisM->where('position', $sFwJk); }); } goto MzguK; B8btb: } }