DistAppearanceTemplateController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\DistAppearanceTemplate;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. use Dcat\Admin\Layout\Content;
  9. use Dcat\Admin\Admin;
  10. use App\Admin\Forms\monacoLeft;
  11. use Illuminate\Http\Request;
  12. class DistAppearanceTemplateController extends AdminController
  13. {
  14. /*
  15. * monaco editor 编辑代码
  16. */
  17. public function monaco(Content $content,Request $request) {
  18. if ($request->isMethod('post')) {
  19. if($request->get('act') == 'tree') {
  20. //获取代码树形结构
  21. $appearance_id = $request->get('appearance_id');
  22. $dist_id = $request->get('dist_id');
  23. return $this->showTree($appearance_id, $dist_id);
  24. } elseif ($request->get('act') == 'content') {
  25. //得到文件内容
  26. $id = $request->get('id');
  27. return DistAppearanceTemplate::getContent($id);
  28. } elseif ($request->get('act') == 'save') {
  29. //保存文件内容
  30. $template_id = $request->get('template_id');
  31. $content = $request->get('content');
  32. return DistAppearanceTemplate::saveContent($template_id, $content);
  33. }
  34. }
  35. $leftForm = new monacoLeft();
  36. return $content->body(admin_view('admin.pages-custom.monaco',['leftForm'=>$leftForm]));
  37. }
  38. /*
  39. * 显示代码树
  40. */
  41. private function showTree($appearance_id, $dist_id) {
  42. $appearance_id = empty($appearance_id) ? 0 : $appearance_id;
  43. $dist_id = empty($dist_id) ? 0 : $dist_id;
  44. $tree = DistAppearanceTemplate::getTemplateTree($appearance_id, $dist_id);
  45. $html = '<ul class="list-group list-group-flush">';
  46. foreach ($tree as $key => $value) {
  47. $fa = 'fa-angle-down';
  48. $file_name = $value['file_name'];
  49. if ($value['file_type'] == 1) {
  50. $fa = 'fa-angle-right';
  51. $file_name = '<a href="#" class="file-action" file_id="'. $value['id'].'">'. $file_name.'</a>';
  52. }
  53. $html .= '<li class="list-group-item has-submenu">';
  54. $html .= '<i class="fa '.$fa.'"></i> '. $file_name;
  55. $html .= $this->treeBuilder($value);
  56. $html .= '</li>';
  57. }
  58. $html .= '</ul>';
  59. return $html;
  60. }
  61. private function treeBuilder($value) {
  62. $html = '';
  63. if (!empty($value['children'])) {
  64. $html = '<ul class="submenu">';
  65. foreach ($value['children'] as $k => $v) {
  66. $fa = 'fa-angle-down';
  67. $file_name = $v['file_name'];
  68. if ($v['file_type'] == 1) {
  69. $fa = 'fa-angle-right';
  70. $file_name = '<a href="#" class="file-action" file_id="'. $v['id'].'">'. $file_name.'</a>';
  71. }
  72. $html .= '<li class="list-group-item"><i class="fa '.$fa.'"></i> '. $file_name;
  73. if (!empty($v['children'])) {
  74. $html .= $this->treeBuilder($v);
  75. }
  76. $html .= '</li>';
  77. }
  78. $html .= '</ul>';
  79. }
  80. return $html;
  81. }
  82. //
  83. // /**
  84. // * page index
  85. // */
  86. // public function index(Content $content)
  87. // {
  88. // return $content
  89. // ->header('列表')
  90. // ->description('全部')
  91. // ->breadcrumb(['text'=>'列表','url'=>''])
  92. // ->body($this->grid());
  93. // }
  94. //
  95. // /**
  96. // * Make a grid builder.
  97. // *
  98. // * @return Grid
  99. // */
  100. // protected function grid()
  101. // {
  102. // return Grid::make(new DistAppearanceTemplate(), function (Grid $grid) {
  103. // $grid->column('id')->sortable();
  104. // $grid->column('dist_id');
  105. // $grid->column('appearance_id');
  106. // $grid->column('file_name');
  107. // $grid->column('file_path');
  108. // $grid->column('content');
  109. // $grid->column('created_at');
  110. // $grid->column('updated_at')->sortable();
  111. //
  112. // $grid->filter(function (Grid\Filter $filter) {
  113. // $filter->equal('id');
  114. //
  115. // });
  116. // });
  117. // }
  118. //
  119. // /**
  120. // * Make a show builder.
  121. // *
  122. // * @param mixed $id
  123. // *
  124. // * @return Show
  125. // */
  126. // protected function detail($id)
  127. // {
  128. // return Show::make($id, new DistAppearanceTemplate(), function (Show $show) {
  129. // $show->field('id');
  130. // $show->field('dist_id');
  131. // $show->field('appearance_id');
  132. // $show->field('file_name');
  133. // $show->field('file_path');
  134. // $show->field('content');
  135. // $show->field('created_at');
  136. // $show->field('updated_at');
  137. // });
  138. // }
  139. //
  140. // /**
  141. // * Make a form builder.
  142. // *
  143. // * @return Form
  144. // */
  145. // protected function form()
  146. // {
  147. // return Form::make(new DistAppearanceTemplate(), function (Form $form) {
  148. // $form->display('id');
  149. // $form->text('dist_id');
  150. // $form->text('appearance_id');
  151. // $form->text('file_name');
  152. // $form->text('file_path');
  153. // $form->text('content');
  154. //
  155. // $form->display('created_at');
  156. // $form->display('updated_at');
  157. // });
  158. // }
  159. }