123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- namespace App\Admin\Controllers;
- use App\Admin\Repositories\DistAppearanceTemplate;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- use Dcat\Admin\Layout\Content;
- use Dcat\Admin\Admin;
- use App\Admin\Forms\AceLeft;
- use Illuminate\Http\Request;
- use Illuminate\Support\Str;
- use Dcat\Admin\Widgets\Card;
- class DistAppearanceTemplateController extends AdminController
- {
- /*
- * monaco editor 编辑代码
- */
- public function ace(Content $content,Request $request) {
- $content->view('admin.pages-custom.ace_content');
- if ($request->isMethod('post') || false == empty($request->get('act'))) {
- if($request->get('act') == 'tree') {
- //获取代码树形结构
- $appearance_id = $request->get('appearance_id');
- $dist_id = $request->get('dist_id');
- return $this->showTree($appearance_id, $dist_id);
- } elseif ($request->get('act') == 'content') {
- //得到文件内容
- $id = $request->get('id');
- return DistAppearanceTemplate::getContent($id);
- } elseif ($request->get('act') == 'content_save') {
- //保存文件内容
- $template_id = $request->get('template_id');
- $content = $request->get('content');
- return DistAppearanceTemplate::saveContent($template_id, $content);
- }
- }
- $leftForm = new AceLeft();
- return $content
- ->header('Template Editor')
- ->body(admin_view('admin.pages-custom.ace',['leftForm'=>$leftForm]));
- }
- /*
- * 显示代码树
- */
- private function showTree($appearance_id, $dist_id) {
- $appearance_id = empty($appearance_id) ? 0 : $appearance_id;
- $dist_id = empty($dist_id) ? 0 : $dist_id;
- $tree = DistAppearanceTemplate::getTemplateTree($appearance_id, $dist_id);
- $html = '<ul class="list-group list-group-flush">';
- foreach ($tree as $key => $value) {
- $fa = 'fa-angle-down';
- $file_name = $value['file_name'];
- if ($value['file_type'] == 1) {
- $fa = 'fa-angle-right';
- $file_name = '<a href="#" class="file-action" file_id="'. $value['id'].'" title="'.$file_name.'">'. $file_name.'</a>';
- } else {
- $file_name = '<span class="custom-blue-bold">'. $file_name.'</span>';
- }
- $html .= '<li class="list-group-item has-submenu">';
- $html .= '<i class="fa '.$fa.'"></i> '. $file_name;
- $html .= $this->treeBuilder($value);
- $html .= '</li>';
- }
- $html .= '</ul>';
- return $html;
- }
- private function treeBuilder($value) {
- $html = '';
- if (!empty($value['children'])) {
- $html = '<ul class="submenu">';
- foreach ($value['children'] as $k => $v) {
- $fa = 'fa-angle-down';
- $file_name = $v['file_name'];
- if ($v['file_type'] == 1) {
- $fa = 'fa-angle-right';
- $file_name = '<a href="#" class="file-action" file_id="'. $v['id'].'" title="'.$file_name.'">'. $file_name.'</a>';
- } else {
- $file_name = '<span class="custom-blue-bold">'. $file_name.'</span>';
- }
- $html .= '<li class="list-group-item"><i class="fa '.$fa.'"></i> '. $file_name;
- if (!empty($v['children'])) {
- $html .= $this->treeBuilder($v);
- }
- $html .= '</li>';
- }
- $html .= '</ul>';
- }
- return $html;
- }
- //
- // /**
- // * page index
- // */
- // public function index(Content $content)
- // {
- // return $content
- // ->header('列表')
- // ->description('全部')
- // ->breadcrumb(['text'=>'列表','url'=>''])
- // ->body($this->grid());
- // }
- //
- // /**
- // * Make a grid builder.
- // *
- // * @return Grid
- // */
- // protected function grid()
- // {
- // return Grid::make(new DistAppearanceTemplate(), function (Grid $grid) {
- // $grid->column('id')->sortable();
- // $grid->column('dist_id');
- // $grid->column('appearance_id');
- // $grid->column('file_name');
- // $grid->column('file_path');
- // $grid->column('content');
- // $grid->column('created_at');
- // $grid->column('updated_at')->sortable();
- //
- // $grid->filter(function (Grid\Filter $filter) {
- // $filter->equal('id');
- //
- // });
- // });
- // }
- //
- // /**
- // * Make a show builder.
- // *
- // * @param mixed $id
- // *
- // * @return Show
- // */
- // protected function detail($id)
- // {
- // return Show::make($id, new DistAppearanceTemplate(), function (Show $show) {
- // $show->field('id');
- // $show->field('dist_id');
- // $show->field('appearance_id');
- // $show->field('file_name');
- // $show->field('file_path');
- // $show->field('content');
- // $show->field('created_at');
- // $show->field('updated_at');
- // });
- // }
- //
- // /**
- // * Make a form builder.
- // *
- // * @return Form
- // */
- // protected function form()
- // {
- // return Form::make(new DistAppearanceTemplate(), function (Form $form) {
- // $form->display('id');
- // $form->text('dist_id');
- // $form->text('appearance_id');
- // $form->text('file_name');
- // $form->text('file_path');
- // $form->text('content');
- //
- // $form->display('created_at');
- // $form->display('updated_at');
- // });
- // }
- }
|