作者 lyh

gx

... ... @@ -2,7 +2,9 @@
namespace App\Http\Controllers\Bside\Template;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\BTemplate\CustomTemplateLogic;
/**
* @remark :自定义模块
... ... @@ -19,8 +21,26 @@ class CustomTemplateController extends BaseController
* @method :post
* @time :2023/6/29 9:29
*/
public function lists(){
public function lists(CustomTemplateLogic $customTemplateLogic){
$lists = $customTemplateLogic->customTemplateLists($this->map,$this->page,$this->row,$this->order);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :获取当前自定义界面详情
* @name :read
* @author :lyh
* @method :post
* @time :2023/6/29 16:23
*/
public function read(CustomTemplateLogic $customTemplateLogic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$customTemplateLogic->customTemplateInfo();
$this->response('success');
}
/**
... ... @@ -30,8 +50,9 @@ class CustomTemplateController extends BaseController
* @method :post
* @time :2023/6/29 9:30
*/
public function save(){
public function save(CustomTemplateLogic $customTemplateLogic){
$customTemplateLogic->customTemplateSave();
$this->response('success');
}
/**
... ... @@ -41,7 +62,8 @@ class CustomTemplateController extends BaseController
* @method :post
* @time :2023/6/29 9:30
*/
public function del(){
public function del(CustomTemplateLogic $customTemplateLogic){
$customTemplateLogic->customTemplateDel();
$this->response('success');
}
}
... ...
... ... @@ -36,12 +36,7 @@ class ATemplateLogic extends BaseLogic
*/
public function aTemplateSave(){
//字符串截取
$this->param['head_html'] = characterTruncation($this->param['html'],'<header>','</header>');
$this->param['main_html'] = characterTruncation($this->param['html'],'<main>','</main>');
$this->param['footer_html'] = characterTruncation($this->param['html'],'<footer>','</footer>');
$this->param['head_css'] = characterTruncation($this->param['html'],'<style id="vvvebjs-header">','</style>');
$this->param['main_css'] = characterTruncation($this->param['html'],'<style id="vvvebjs-style">','</style>');
$this->param['footer_css'] = characterTruncation($this->param['html'],'<style id="vvvebjs-footer">','</style>');
$this->StringProcessing();
if(isset($this->param['id'])){
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
... ... @@ -52,7 +47,22 @@ class ATemplateLogic extends BaseLogic
}
return $this->success();
}
/**
* @remark :字符串处理
* @name :StringProcessing
* @author :lyh
* @method :post
* @time :2023/6/29 15:35
*/
public function StringProcessing(){
//字符串截取
$this->param['head_html'] = characterTruncation($this->param['html'],'/<header\b[^>]*>(.*?)<\/header>/s');
$this->param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');
$this->param['footer_html'] = characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s');
$this->param['head_css'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-header">(.*?)<\/style>/s');
$this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-styles">(.*?)<\/style>/s');
$this->param['footer_css'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-footer">(.*?)<\/style>/s');
}
/**
* @remark :修改模块状态
* @name :aTemplateStatus
... ...
... ... @@ -3,13 +3,63 @@
namespace App\Http\Logic\Bside\BTemplate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Template\BCustomTemplate;
class CustomTemplateLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Custom();
$this->model = new BCustomTemplate();
$this->param = $this->requestAll;
}
/**
* @remark :获取自定义模块列表
* @name :lists
* @author :lyh
* @method :post
* @time :2023/6/29 15:46
*/
public function customTemplateLists($map,$page,$row,$order = 'created_at',$filed = ['*']){
$lists = $this->model->lists($map,$page,$row,$order,$filed);
return $this->success($lists);
}
/**
* @remark :获取当前自定义界面详情
* @name :customTemplateInfo
* @author :lyh
* @method :post
* @time :2023/6/29 16:23
*/
public function customTemplateInfo(){
$info = $this->model->read(['id'=>$this->param['id']]);
if($info === false){
$this->fail('error');
}
return $this->success($info);
}
/**
* @remark :保存自定义界面
* @name :customTemplateSave
* @author :lyh
* @method :post
* @time :2023/6/29 16:21
*/
public function customTemplateSave(){
return $this->success();
}
/**
* @remark :删除自定义界面
* @name :customTemplateDel
* @author :lyh
* @method :post
* @time :2023/6/29 16:21
*/
public function customTemplateDel(){
return $this->success();
}
}
... ...
<?php
namespace App\Http\Logic\Bside;
use App\Models\RouteMap;
use App\Models\Template\Template;
use App\Models\Template\BSetting;
use App\Models\Template\BTemplate;
/**
* @author:dc
* @time 2023/5/15 13:57
* Class TemplateLogic
* @package App\Http\Logic\Bside
*/
class TemplateLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new BTemplate();
$this->param = $this->requestAll;
}
/**
* @param $param
* @return array
* @throws \App\Exceptions\AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
* @author:dc
* @time 2023/5/12 9:54
*/
public function save($param)
{
// 查询
$data = $this->first($param['data_source'],$param['data_source_id']);
if($data){
$param['id'] = $data['id'];
}else{
$param['template_id'] = BSetting::_get($this->user['project_id'])['template_id'];
}
return parent::save($param);
}
/**
* 状态修改
* @param $source
* @param $source_id
* @param $status
* @return mixed
* @throws \App\Exceptions\AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
* @author:dc
* @time 2023/5/15 14:41
*/
public function status($source,$source_id,$status){
$data = $this->first($source,$source_id);
if(!$data){
$this->fail('数据不存在');
}
$data->status = $status;
return $data->save();
}
/**
* @param $source
* @param $source_id
* @return mixed
* @author:dc
* @time 2023/5/15 14:49
*/
public function first($source,$source_id)
{
$data = BTemplate::where([
'project_id'=>$this->user['project_id'],
'data_source' => $source,
'data_source_id' => $source_id,
'template_id' => BSetting::_get($this->user['project_id'])['template_id']
])->first();
if(empty($data)){
$data = Template::where([
'id' => BSetting::_get($this->user['project_id'])['template_id']
])->first();
}
return $data;
}
/**
* @remark :使用模版并保存数据
* @name :usingTemplates
* @author :lyh
* @method :post
* @time :2023/6/27 15:26
*/
public function usingTemplates(){
//获取模版详情
$asideTemplateModel = new Template();
$templateInfo = $asideTemplateModel->read(['id'=>$this->param['template_id']]);
if($templateInfo === false){
$this->fail('当前模版不存在或已被删除');
}
$bSettingTemplateModel = new BSetting();
//查看用户模版是否已使用过
$param = [
'template_id'=>$this->param['template_id'],
'project_id'=>$this->user['project_id']
];
$bSettingTemplateInfo = $bSettingTemplateModel->read($param);
//当前用户选择模版并关联
if($bSettingTemplateInfo === false){
$rs = $bSettingTemplateModel->add($param);
if($rs === false){
$this->fail('error');
}
}
return $this->success($templateInfo);
}
}
... ... @@ -254,17 +254,12 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/type', [\App\Http\Controllers\Bside\Template\BTemplateModuleController::class, 'getType'])->name('template_module_getType');
});
});
// 自定义页面,专题页
Route::prefix('custom')->group(function () {
Route::get('/', [\App\Http\Controllers\Bside\CustomController::class, 'index'])->name('bside_custom');
Route::post('/create', [\App\Http\Controllers\Bside\CustomController::class, 'save'])->name('bside_custom_create');
Route::post('/update', [\App\Http\Controllers\Bside\CustomController::class, 'save'])->name('bside_custom_update');
Route::delete('/delete', [\App\Http\Controllers\Bside\CustomController::class, 'delete'])->name('bside_custom_delete');
Route::any('/html/{id}', [\App\Http\Controllers\Bside\CustomController::class, 'html'])->where('id', '\d+')->name('bside_custom_delete');
Route::get('/', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'lists'])->name('custom_lists');
Route::get('/save', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'save'])->name('custom_save');
Route::get('/del', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'del'])->name('custom_del');
});
// 导航栏编辑
Route::prefix('nav')->group(function () {
Route::get('/', [\App\Http\Controllers\Bside\NavController::class, 'index'])->name('bside_nav');
... ...