作者 邓超

自定义页面

... ... @@ -60,8 +60,11 @@ class CustomController extends BaseController
*/
public function index(){
// 每页数量
$limit = intval($this->param['limit']??20);
$lists = BCustom::_all($this->user['project_id'])->toArray();
$lists = BCustom::_all($this->user['project_id'],$limit)->toArray();
return $this->success($lists);
... ...
... ... @@ -4,16 +4,14 @@ namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Models\Template\AHeadFoot;
use App\Models\Template\BCustom;
use App\Models\Template\BHeadFoot;
use App\Models\Template\ATemplate;
use App\Models\Template\BTemplate;
use Illuminate\Support\Facades\DB;
/**
* 自定义 页面
* 模板
* @author:dc
* @time 2023/5/4 15:59
* @time 2023/5/9 14:00
* Class TemplateController
* @package App\Http\Controllers\Bside
*/
... ... @@ -22,141 +20,26 @@ class TemplateController extends BaseController
/**
* 头部底部的 html
* 列表
* @return \Illuminate\Http\JsonResponse
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author:dc
* @time 2023/5/4 16:15
* @time 2023/5/9 14:20
*/
public function index(){
$data = BTemplate::_get($this->user['project_id']);
$limit = intval($this->param['limit']??20);
// todo::这里要进行html的替换
$data = ATemplate::_bAll($limit);
return $this->success($data);
}
/**
* 读取编辑的html
* @author:dc
* @time 2023/5/4 16:19
*/
public function edit_html(){
$data = BHeadFoot::_get($this->user['project_id']);
if(!$data){
$data = AHeadFoot::_bDefault();
}
return $this->success([
'header' => $data[BHeadFoot::TYPE_HEADER]??'',
'footer' => $data[BHeadFoot::TYPE_FOOTER]??'',
]);
}
/**
* 保存
* @author:dc
* @time 2023/5/4 17:42
*/
public function edit_save(){
$header = $this->param['header']??'';
$footer = $this->param['footer']??'';
if(!$header && !$footer){
throw new BsideGlobalException('B01024','不能为空');
}
DB::beginTransaction();
try {
if($header){
BHeadFoot::_save($this->user['project_id'],BHeadFoot::TYPE_HEADER,$header);
}
if($footer){
BHeadFoot::_save($this->user['project_id'],BHeadFoot::TYPE_FOOTER,$footer);
}
}catch (\Throwable $e){
DB::rollBack();
throw new BsideGlobalException('B01024','保存失败');
}
DB::commit();
$this->success([]);
}
/**
* 获取系统的模板
* @author:dc
* @time 2023/5/4 16:21
*/
public function system_all_html(){
$data = AHeadFoot::_ball();
$lists = [];
// 以名字为单位区分
foreach ($data as $datum){
if(empty($lists[$datum['name']])) $lists[$datum['name']] = [];
$lists[$datum['name']]['name'] = $datum['name'];
$lists[$datum['name']]['default'] = $datum['is_default'];
$lists[$datum['name']][$datum['type']==AHeadFoot::TYPE_HEADER?'header':'footer'] = $datum['html'];
}
return $this->success(array_values($lists));
}
/**
* 自定义 列表
* @author:dc
* @time 2023/5/4 17:13
*/
public function custom(){
$data = BCustom::_all($this->user['project_id']);
return $this->success($data->toArray());
}
public function custom_create(){
}
public function custom_edit($id){
}
public function custom_delete($id){
return $this->success($data);
}
}
... ...
... ... @@ -14,7 +14,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class BCustom extends Base
{
protected $table = 'gl_bside_template_custom';
protected $table = 'gl_web_custom';
use SoftDeletes;
... ... @@ -87,13 +87,14 @@ class BCustom extends Base
* @author:dc
* @time 2023/5/8 16:29
*/
public static function _all(int $project_id)
public static function _all(int $project_id, int $limit = 20)
{
return static::where(function ($query) use ($project_id){
// 那个公司
$query->where('project_id',$project_id);
})
->get(['id','name','title','status','url','keywords','description','created_at','updated_at']);
->select(['id','name','title','status','url','keywords','description','created_at','updated_at'])
->paginate($limit);
}
/**
... ...
... ... @@ -14,7 +14,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class BNav extends Base
{
protected $table = 'gl_bside_nav';
protected $table = 'gl_web_nav';
use SoftDeletes;
... ...
<?php
namespace App\Models\Template;
/**
* 头部底部
* @author:dc
* @time 2023/5/4 15:52
* Class AHeadFoot
* @package App\Models\Template
*/
class AHeadFoot extends \App\Models\Base{
protected $table = 'gl_aside_template_header_footer';
// 分开存 头底 为了方便后期可能会 改版为 随意搭配 头底部
const TYPE_HEADER = 'H';
const TYPE_FOOTER = 'F';
const STATUS_ACTIVE = 1;
const STATUS_DISABLED = 0;
const IS_DEFAULT = 1;
/**
* b 端 查询
* @return mixed
* @author:dc
* @time 2023/5/4 16:24
*/
public static function _ball(){
return static::where('status',static::STATUS_ACTIVE)->orderBy('sort')->get(['id','name','type','html','is_default']);
}
/**
* b 端 读取默认的一个头部底部
* @return mixed
* @author:dc
* @time 2023/5/4 16:51
*/
public static function _bDefault(){
return static::where(['status'=>static::STATUS_ACTIVE,'is_default'=>static::IS_DEFAULT])
->get(['type','html'])
->pluck('html','type')
->toArray();
}
}
<?php
namespace App\Models\Template;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 由 A端增删改
* 模板
* @author:dc
* @time 2023/5/9 13:56
* Class ATemplate
* @package App\Models\Template
*/
class ATemplate extends \App\Models\Base{
protected $table = 'gl_aside_template';
protected $hidden = ['deleted_at'];
use SoftDeletes;
/**
* 显示
*/
const STATUS_ACTIVE = 1;
/**
* 隐藏
*/
const STATUS_DISABLED = 0;
/**
* b 端调用
* @param int $limit
* @return mixed
* @author:dc
* @time 2023/5/9 14:14
*/
public static function _bAll(int $limit = 20)
{
return static::where(function ($query){
$query->where('status',static::STATUS_ACTIVE);
})
->select(['id','name','url','thumb','created_at','updated_at'])
->orderBy('sort')
->paginate($limit);
}
}
... ...
... ... @@ -11,7 +11,7 @@ namespace App\Models\Template;
*/
class BTemplate extends \App\Models\Base{
protected $table = 'gl_bside_template_html';
protected $table = 'gl_web_template_html';
... ...