DistAppearanceTemplateController.php 5.8 KB

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