<?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 $IuwRA) { goto wDfaN; DLZR1: $IuwRA->scopeDefault(NavPosition::first()); goto DQvWi; DQvWi: $IuwRA->hookSaved(function (Form $s4jIj) { $Z32UA = $s4jIj->item(); if ($Z32UA->pid > 0) { $KXaOI = ModelUtil::get('nav', $Z32UA->pid); ModelUtil::update('nav', $Z32UA->id, array('position' => $KXaOI['position'])); } })->hookChanged(function (Form $s4jIj) { NavUtil::clearCache(); })->canBatchDelete(true)->asTree('id', 'pid', 'sort', 'name')->treeMaxLevel(3)->title('导航设置'); goto WSy_q; wDfaN: if ($IuwRA->mode() == AdminCRUDBuilder::MODE_FORM) { goto Apxia; fjm6E: ModStart::script('window.__positionNavs=' . json_encode($mXhRp) . ';'); goto Izcdu; Izcdu: ModStart::scriptFile('module/Nav/Admin/Controller/NavEdit.js'); goto AHi91; Apxia: $mXhRp = array(); goto N8H0M; N8H0M: foreach (NavUtil::tree() as $YxV2x) { $mXhRp[] = array('id' => $YxV2x['id'], 'position' => $YxV2x['position'], 'name' => $YxV2x['name']); if (!empty($YxV2x['_child'])) { foreach ($YxV2x['_child'] as $Hl3dS) { $mXhRp[] = array('id' => $Hl3dS['id'], 'position' => $Hl3dS['position'], 'name' => $YxV2x['name'] . ' → ' . $Hl3dS['name']); } } } goto fjm6E; AHi91: } goto LQX5e; cGwNz: foreach (NavPosition::getList() as $rY0hM => $hsART) { $IuwRA->scopeFilter($rY0hM, $hsART, function (ScopeFilter $wPpmz) use($rY0hM) { return $wPpmz->where('position', $rY0hM); }); } goto DLZR1; LQX5e: $IuwRA->init('nav')->field(function ($IuwRA) { $IuwRA->id('id', 'ID'); $IuwRA->select('position', '位置')->optionType(NavPosition::class)->hookRendering(function (AbstractField $UdGHQ, $Z32UA, $OPJGK) { switch ($UdGHQ->renderMode()) { case FieldRenderMode::DETAIL: case FieldRenderMode::GRID: if ($Z32UA->pid) { return AutoRenderedFieldValue::make(''); } return AutoRenderedFieldValue::make(TypeUtil::name(NavPosition::class, $Z32UA->position)); } }); $IuwRA->text('name', '名称'); $IuwRA->icon('icon', '图标')->help('部分主题支持图标显示'); $IuwRA->link('link', '链接'); $IuwRA->switch('enable', '启用')->optionsYesNo()->gridEditable(true)->defaultValue(true); $IuwRA->radio('openType', '打开方式')->optionType(NavOpenType::class)->defaultValue(NavOpenType::CURRENT_WINDOW); $IuwRA->display('created_at', L('Created At'))->listable(false); $IuwRA->display('updated_at', L('Updated At'))->listable(false); }); goto cGwNz; WSy_q: } }