DistAppearanceTemplateController.php 6.1 KB

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