<?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 $lZifj) { goto RqUG0; RqUG0: if ($lZifj->mode() == AdminCRUDBuilder::MODE_FORM) { goto j4JYo; PBCLf: foreach (NavUtil::tree() as $y2Ltn) { $jqOQ5[] = array('id' => $y2Ltn['id'], 'position' => $y2Ltn['position'], 'name' => $y2Ltn['name']); if (!empty($y2Ltn['_child'])) { foreach ($y2Ltn['_child'] as $L7qss) { $jqOQ5[] = array('id' => $L7qss['id'], 'position' => $L7qss['position'], 'name' => $y2Ltn['name'] . ' → ' . $L7qss['name']); } } } goto qM6RF; j4JYo: $jqOQ5 = array(); goto PBCLf; YDTic: ModStart::scriptFile('module/Nav/Admin/Controller/NavEdit.js'); goto Tcq8z; qM6RF: ModStart::script('window.__positionNavs=' . json_encode($jqOQ5) . ';'); goto YDTic; Tcq8z: } goto dClmr; dClmr: $lZifj->init('nav')->field(function ($lZifj) { $lZifj->id('id', 'ID'); $lZifj->select('position', '位置')->optionType(NavPosition::class)->hookRendering(function (AbstractField $pZ_lR, $jIWZA, $aaYHa) { switch ($pZ_lR->renderMode()) { case FieldRenderMode::DETAIL: case FieldRenderMode::GRID: if ($jIWZA->pid) { return AutoRenderedFieldValue::make(''); } return AutoRenderedFieldValue::make(TypeUtil::name(NavPosition::class, $jIWZA->position)); } }); $lZifj->text('name', '名称'); $lZifj->icon('icon', '图标')->help('部分主题支持图标显示'); $lZifj->link('link', '链接'); $lZifj->switch('enable', '启用')->optionsYesNo()->gridEditable(true)->defaultValue(true); $lZifj->radio('openType', '打开方式')->optionType(NavOpenType::class)->defaultValue(NavOpenType::CURRENT_WINDOW); $lZifj->display('created_at', L('Created At'))->listable(false); $lZifj->display('updated_at', L('Updated At'))->listable(false); }); goto FNvAn; FNvAn: foreach (NavPosition::getList() as $UtKOH => $fo71I) { $lZifj->scopeFilter($UtKOH, $fo71I, function (ScopeFilter $bu01d) use($UtKOH) { return $bu01d->where('position', $UtKOH); }); } goto uteYb; uteYb: $lZifj->scopeDefault(NavPosition::first()); goto p3erU; p3erU: $lZifj->hookSaved(function (Form $yZTO2) { $jIWZA = $yZTO2->item(); if ($jIWZA->pid > 0) { $eg1hm = ModelUtil::get('nav', $jIWZA->pid); ModelUtil::update('nav', $jIWZA->id, array('position' => $eg1hm['position'])); } })->hookChanged(function (Form $yZTO2) { NavUtil::clearCache(); })->canBatchDelete(true)->asTree('id', 'pid', 'sort', 'name')->treeMaxLevel(3)->title('导航设置'); goto B_sU3; B_sU3: } }