DistAppearanceTemplateController.php 5.5 KB

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