<?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 $A2Tuf) { goto anSOm; SMicE: $A2Tuf->scopeDefault(NavPosition::first()); goto daVPG; daVPG: $A2Tuf->hookSaved(function (Form $OkcU0) { $vPOhn = $OkcU0->item(); if ($vPOhn->pid > 0) { $m_RDE = ModelUtil::get('nav', $vPOhn->pid); ModelUtil::update('nav', $vPOhn->id, array('position' => $m_RDE['position'])); } })->hookChanged(function (Form $OkcU0) { NavUtil::clearCache(); })->canBatchDelete(true)->asTree('id', 'pid', 'sort', 'name')->treeMaxLevel(3)->title('导航设置'); goto IHvsd; gqwSP: $A2Tuf->init('nav')->field(function ($A2Tuf) { $A2Tuf->id('id', 'ID'); $A2Tuf->select('position', '位置')->optionType(NavPosition::class)->hookRendering(function (AbstractField $iuKOG, $vPOhn, $x0NZ_) { switch ($iuKOG->renderMode()) { case FieldRenderMode::DETAIL: case FieldRenderMode::GRID: if ($vPOhn->pid) { return AutoRenderedFieldValue::make(''); } return AutoRenderedFieldValue::make(TypeUtil::name(NavPosition::class, $vPOhn->position)); } }); $A2Tuf->text('name', '名称'); $A2Tuf->icon('icon', '图标')->help('部分主题支持图标显示'); $A2Tuf->link('link', '链接'); $A2Tuf->switch('enable', '启用')->optionsYesNo()->gridEditable(true)->defaultValue(true); $A2Tuf->radio('openType', '打开方式')->optionType(NavOpenType::class)->defaultValue(NavOpenType::CURRENT_WINDOW); $A2Tuf->display('created_at', L('Created At'))->listable(false); $A2Tuf->display('updated_at', L('Updated At'))->listable(false); }); goto TI5Sz; anSOm: if ($A2Tuf->mode() == AdminCRUDBuilder::MODE_FORM) { goto b09iH; b09iH: $dTYk3 = array(); goto mMUI8; K2VHB: ModStart::scriptFile('module/Nav/Admin/Controller/NavEdit.js'); goto KNPKS; mMUI8: foreach (NavUtil::tree() as $PSYn9) { $dTYk3[] = array('id' => $PSYn9['id'], 'position' => $PSYn9['position'], 'name' => $PSYn9['name']); if (!empty($PSYn9['_child'])) { foreach ($PSYn9['_child'] as $kC_8Q) { $dTYk3[] = array('id' => $kC_8Q['id'], 'position' => $kC_8Q['position'], 'name' => $PSYn9['name'] . ' → ' . $kC_8Q['name']); } } } goto ZuZZM; ZuZZM: ModStart::script('window.__positionNavs=' . json_encode($dTYk3) . ';'); goto K2VHB; KNPKS: } goto gqwSP; TI5Sz: foreach (NavPosition::getList() as $Jo7ME => $gbkxa) { $A2Tuf->scopeFilter($Jo7ME, $gbkxa, function (ScopeFilter $cbHm3) use($Jo7ME) { return $cbHm3->where('position', $Jo7ME); }); } goto SMicE; IHvsd: } }