DistAppearanceTemplateController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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'].'" title="'.$file_name.'">'. $file_name.'</a>';
  57. } else {
  58. $file_name = '<span class="custom-blue-bold">'. $file_name.'</span>';
  59. }
  60. $html .= '<li class="list-group-item has-submenu">';
  61. $html .= '<i class="fa '.$fa.'"></i> '. $file_name;
  62. $html .= $this->treeBuilder($value);
  63. $html .= '</li>';
  64. }
  65. $html .= '</ul>';
  66. return $html;
  67. }
  68. private function treeBuilder($value) {
  69. $html = '';
  70. if (!empty($value['children'])) {
  71. $html = '<ul class="submenu">';
  72. foreach ($value['children'] as $k => $v) {
  73. $fa = 'fa-angle-down';
  74. $file_name = $v['file_name'];
  75. if ($v['file_type'] == 1) {
  76. $fa = 'fa-angle-right';
  77. $file_name = '<a href="#" class="file-action" file_id="'. $v['id'].'" title="'.$file_name.'">'. $file_name.'</a>';
  78. } else {
  79. $file_name = '<span class="custom-blue-bold">'. $file_name.'</span>';
  80. }
  81. $html .= '<li class="list-group-item"><i class="fa '.$fa.'"></i> '. $file_name;
  82. if (!empty($v['children'])) {
  83. $html .= $this->treeBuilder($v);
  84. }
  85. $html .= '</li>';
  86. }
  87. $html .= '</ul>';
  88. }
  89. return $html;
  90. }
  91. //
  92. // /**
  93. // * page index
  94. // */
  95. // public function index(Content $content)
  96. // {
  97. // return $content
  98. // ->header('列表')
  99. // ->description('全部')
  100. // ->breadcrumb(['text'=>'列表','url'=>''])
  101. // ->body($this->grid());
  102. // }
  103. //
  104. // /**
  105. // * Make a grid builder.
  106. // *
  107. // * @return Grid
  108. // */
  109. // protected function grid()
  110. // {
  111. // return Grid::make(new DistAppearanceTemplate(), function (Grid $grid) {
  112. // $grid->column('id')->sortable();
  113. // $grid->column('dist_id');
  114. // $grid->column('appearance_id');
  115. // $grid->column('file_name');
  116. // $grid->column('file_path');
  117. // $grid->column('content');
  118. // $grid->column('created_at');
  119. // $grid->column('updated_at')->sortable();
  120. //
  121. // $grid->filter(function (Grid\Filter $filter) {
  122. // $filter->equal('id');
  123. //
  124. // });
  125. // });
  126. // }
  127. //
  128. // /**
  129. // * Make a show builder.
  130. // *
  131. // * @param mixed $id
  132. // *
  133. // * @return Show
  134. // */
  135. // protected function detail($id)
  136. // {
  137. // return Show::make($id, new DistAppearanceTemplate(), function (Show $show) {
  138. // $show->field('id');
  139. // $show->field('dist_id');
  140. // $show->field('appearance_id');
  141. // $show->field('file_name');
  142. // $show->field('file_path');
  143. // $show->field('content');
  144. // $show->field('created_at');
  145. // $show->field('updated_at');
  146. // });
  147. // }
  148. //
  149. // /**
  150. // * Make a form builder.
  151. // *
  152. // * @return Form
  153. // */
  154. // protected function form()
  155. // {
  156. // return Form::make(new DistAppearanceTemplate(), function (Form $form) {
  157. // $form->display('id');
  158. // $form->text('dist_id');
  159. // $form->text('appearance_id');
  160. // $form->text('file_name');
  161. // $form->text('file_path');
  162. // $form->text('content');
  163. //
  164. // $form->display('created_at');
  165. // $form->display('updated_at');
  166. // });
  167. // }
  168. }