作者 邓超

自定义页面

  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside;
  4 +
  5 +use App\Models\Template\AHeadFoot;
  6 +
  7 +/**
  8 + * 模板
  9 + * @author:dc
  10 + * @time 2023/5/4 17:10
  11 + * Class TemplateController
  12 + * @package App\Http\Controllers\Aside
  13 + */
  14 +class TemplateController extends BaseController
  15 +{
  16 +
  17 +
  18 + /**
  19 + * 列表
  20 + * @author:dc
  21 + * @time 2023/5/4 17:10
  22 + */
  23 + public function index(){
  24 +
  25 +
  26 + }
  27 +
  28 +
  29 + /**
  30 + * 编辑
  31 + * @author:dc
  32 + * @time 2023/5/4 16:19
  33 + */
  34 + public function edit(){
  35 +
  36 + }
  37 +
  38 +
  39 + /**
  40 + * 删除
  41 + * @author:dc
  42 + * @time 2023/5/4 17:10
  43 + */
  44 + public function delete(){
  45 +
  46 +
  47 + }
  48 +
  49 +
  50 +
  51 +
  52 +
  53 +}
@@ -2,8 +2,12 @@ @@ -2,8 +2,12 @@
2 2
3 namespace App\Http\Controllers\Bside; 3 namespace App\Http\Controllers\Bside;
4 4
  5 +use App\Enums\Common\Code;
  6 +use App\Exceptions\BsideGlobalException;
5 use App\Models\Template\AHeadFoot; 7 use App\Models\Template\AHeadFoot;
  8 +use App\Models\Template\BCustom;
6 use App\Models\Template\BHeadFoot; 9 use App\Models\Template\BHeadFoot;
  10 +use Illuminate\Support\Facades\DB;
7 11
8 /** 12 /**
9 * 自定义 页面 13 * 自定义 页面
@@ -28,6 +32,10 @@ class TemplateController extends BaseController @@ -28,6 +32,10 @@ class TemplateController extends BaseController
28 32
29 $data = BHeadFoot::_get($this->user['project_id']); 33 $data = BHeadFoot::_get($this->user['project_id']);
30 34
  35 + // todo::这里要进行html的替换
  36 +
  37 +
  38 +
31 return $this->success([ 39 return $this->success([
32 'header' => $data[BHeadFoot::TYPE_HEADER]??'', 40 'header' => $data[BHeadFoot::TYPE_HEADER]??'',
33 'footer' => $data[BHeadFoot::TYPE_FOOTER]??'', 41 'footer' => $data[BHeadFoot::TYPE_FOOTER]??'',
@@ -41,7 +49,7 @@ class TemplateController extends BaseController @@ -41,7 +49,7 @@ class TemplateController extends BaseController
41 * @time 2023/5/4 16:19 49 * @time 2023/5/4 16:19
42 */ 50 */
43 public function edit_html(){ 51 public function edit_html(){
44 - $data = BHeadFoot::_getEditHtml($this->user['project_id']); 52 + $data = BHeadFoot::_get($this->user['project_id']);
45 53
46 if(!$data){ 54 if(!$data){
47 $data = AHeadFoot::_bDefault(); 55 $data = AHeadFoot::_bDefault();
@@ -53,6 +61,32 @@ class TemplateController extends BaseController @@ -53,6 +61,32 @@ class TemplateController extends BaseController
53 ]); 61 ]);
54 } 62 }
55 63
  64 + /**
  65 + * 保存
  66 + * @author:dc
  67 + * @time 2023/5/4 17:42
  68 + */
  69 + public function edit_save(){
  70 +
  71 + DB::beginTransaction();
  72 +
  73 + try {
  74 + BHeadFoot::_save($this->user['project_id'],BHeadFoot::TYPE_HEADER,'');
  75 +
  76 + BHeadFoot::_save($this->user['project_id'],BHeadFoot::TYPE_HEADER,'');
  77 + }catch (\Throwable $e){
  78 + DB::rollBack();
  79 +
  80 + throw new BsideGlobalException('B01024','保存失败');
  81 + }
  82 +
  83 + DB::commit();
  84 +
  85 +
  86 + $this->success([]);
  87 +
  88 + }
  89 +
56 90
57 /** 91 /**
58 * 获取系统的模板 92 * 获取系统的模板
@@ -81,4 +115,38 @@ class TemplateController extends BaseController @@ -81,4 +115,38 @@ class TemplateController extends BaseController
81 115
82 116
83 117
  118 +
  119 +
  120 +
  121 + /**
  122 + * 自定义 列表
  123 + * @author:dc
  124 + * @time 2023/5/4 17:13
  125 + */
  126 + public function custom(){
  127 +
  128 + $data = BCustom::_all($this->user['project_id']);
  129 +
  130 +
  131 + return $this->success($data->toArray());
  132 + }
  133 +
  134 +
  135 + public function custom_create(){
  136 +
  137 + }
  138 +
  139 + public function custom_edit($id){
  140 +
  141 + }
  142 +
  143 + public function custom_delete($id){
  144 +
  145 + }
  146 +
  147 +
  148 +
  149 +
  150 +
  151 +
84 } 152 }
@@ -18,7 +18,7 @@ class AHeadFoot extends \App\Models\Base{ @@ -18,7 +18,7 @@ class AHeadFoot extends \App\Models\Base{
18 const TYPE_FOOTER = 'F'; 18 const TYPE_FOOTER = 'F';
19 19
20 const STATUS_ACTIVE = 1; 20 const STATUS_ACTIVE = 1;
21 - const STATUS_DISABLED = 1; 21 + const STATUS_DISABLED = 0;
22 22
23 const IS_DEFAULT = 1; 23 const IS_DEFAULT = 1;
24 24
  1 +<?php
  2 +
  3 +namespace App\Models\Template;
  4 +
  5 +use Illuminate\Database\Eloquent\SoftDeletes;
  6 +
  7 +/**
  8 + * 自定义 页面
  9 + * @author:dc
  10 + * @time 2023/5/4 17:18
  11 + * Class BCustom
  12 + * @package App\Models\Template
  13 + */
  14 +class BCustom extends \App\Models\Base{
  15 +
  16 + protected $table = 'gl_bside_template_custom';
  17 +
  18 + use SoftDeletes;
  19 +
  20 +
  21 + const STATUS_ACTIVE = 1;
  22 +
  23 + const STATUS_DISABLED = 0;
  24 +
  25 +
  26 + /**
  27 + * 读取列表
  28 + * @param $project_id
  29 + * @return mixed
  30 + * @author:dc
  31 + * @time 2023/5/4 17:22
  32 + */
  33 + public static function _all($project_id){
  34 + return static::where([
  35 + 'project_id' => $project_id
  36 + ])->paginate(20);
  37 + }
  38 +
  39 +
  40 +
  41 +
  42 +
  43 +
  44 +}
@@ -18,7 +18,7 @@ class BHeadFoot extends \App\Models\Base{ @@ -18,7 +18,7 @@ class BHeadFoot extends \App\Models\Base{
18 const TYPE_FOOTER = 'F'; 18 const TYPE_FOOTER = 'F';
19 19
20 // const STATUS_ACTIVE = 1; 20 // const STATUS_ACTIVE = 1;
21 -// const STATUS_DISABLED = 1; 21 +// const STATUS_DISABLED = 0;
22 22
23 23
24 /** 24 /**
@@ -31,8 +31,33 @@ class BHeadFoot extends \App\Models\Base{ @@ -31,8 +31,33 @@ class BHeadFoot extends \App\Models\Base{
31 return static::where(['project_id'=>$project_id,'is_use'=>1])->get(['html','type'])->pluck('html','type')->toArray(); 31 return static::where(['project_id'=>$project_id,'is_use'=>1])->get(['html','type'])->pluck('html','type')->toArray();
32 } 32 }
33 33
34 - public static function _getEditHtml($project_id){  
35 - return static::where(['project_id'=>$project_id,'is_use'=>1])->get(['origin_html','type'])->pluck('origin_html','type')->toArray(); 34 +
  35 + public static function _all($project_id){
  36 + return static::where(['project_id'=>$project_id,'is_use'=>1])->get();
  37 + }
  38 +
  39 +
  40 + /**
  41 + * 保存
  42 + * @param $project_id
  43 + * @param $type
  44 + * @param $html
  45 + * @author:dc
  46 + * @time 2023/5/4 17:50
  47 + */
  48 + public static function _save($project_id,$type,$html){
  49 + $data = static::where(['project_id'=>$project_id,'is_use'=>1])->first();
  50 + if(!$data){
  51 + $data = new static();
  52 + $data->project_id = $project_id;
  53 + $data->type = $type;
  54 + $data->is_use = 1;
  55 + }
  56 + $data->html = $html;
  57 +
  58 + $data->save();
  59 +
  60 + return $data->id;
36 } 61 }
37 62
38 63
@@ -43,6 +43,15 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w @@ -43,6 +43,15 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w
43 }); 43 });
44 44
45 45
  46 + // 自定义页面 模板,头部底部
  47 + Route::prefix('template')->group(function () {
  48 + Route::get('/', [\App\Http\Controllers\Aside\TemplateController::class, 'index'])->name('admin.template_header_footer');
  49 + Route::get('/edit', [\App\Http\Controllers\Aside\TemplateController::class, 'edit'])->name('admin.template_header_footer_edit');
  50 + Route::get('/delete', [\App\Http\Controllers\Aside\TemplateController::class, 'delete'])->name('admin.template_header_footer_system');
  51 + });
  52 +
  53 +
  54 +
46 }); 55 });
47 56
48 //无需登录验证的路由组 57 //无需登录验证的路由组
@@ -166,7 +166,9 @@ Route::middleware(['bloginauth'])->group(function () { @@ -166,7 +166,9 @@ Route::middleware(['bloginauth'])->group(function () {
166 Route::prefix('template')->group(function () { 166 Route::prefix('template')->group(function () {
167 Route::get('/', [\App\Http\Controllers\Bside\TemplateController::class, 'index'])->name('template_header_footer'); 167 Route::get('/', [\App\Http\Controllers\Bside\TemplateController::class, 'index'])->name('template_header_footer');
168 Route::get('/edit', [\App\Http\Controllers\Bside\TemplateController::class, 'edit_html'])->name('template_header_footer_edit'); 168 Route::get('/edit', [\App\Http\Controllers\Bside\TemplateController::class, 'edit_html'])->name('template_header_footer_edit');
  169 + Route::post('/edit', [\App\Http\Controllers\Bside\TemplateController::class, 'edit_save'])->name('template_header_footer_edit_save');
169 Route::get('/system', [\App\Http\Controllers\Bside\TemplateController::class, 'system_all_html'])->name('template_header_footer_system'); 170 Route::get('/system', [\App\Http\Controllers\Bside\TemplateController::class, 'system_all_html'])->name('template_header_footer_system');
  171 + Route::get('/custom', [\App\Http\Controllers\Bside\TemplateController::class, 'custom'])->name('template_custom');
170 }); 172 });
171 173
172 174