|
...
|
...
|
@@ -46,7 +46,7 @@ class VisualizationLogic extends BaseLogic |
|
|
|
$source = $data['source'];
|
|
|
|
$source_id = $data['source_id'];
|
|
|
|
$type = $this->getType($source,$source_id);
|
|
|
|
$typeArray = [1,3,5,7];//单页数据
|
|
|
|
$typeArray = [BTemplate::TYPE_ONE,BTemplate::TYPE_THREE,BTemplate::TYPE_FIVE,BTemplate::TYPE_SEVEN];//单页数据
|
|
|
|
if(in_array($type,$typeArray)){
|
|
|
|
$bTemplateModel = new BTemplate();
|
|
|
|
$info = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]);
|
|
...
|
...
|
@@ -54,7 +54,7 @@ class VisualizationLogic extends BaseLogic |
|
|
|
$html = '';
|
|
|
|
}else{
|
|
|
|
$html = $info['html'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{//模块数据
|
|
|
|
$bTemplateMainModel = new BTemplateMain();
|
|
|
|
$info = $bTemplateMainModel->read(['type'=>$type]);
|
|
...
|
...
|
@@ -67,6 +67,13 @@ class VisualizationLogic extends BaseLogic |
|
|
|
return $this->success(['html'=>$html]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :根据type获取source类型
|
|
|
|
* @name :getSource
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/6 11:25
|
|
|
|
*/
|
|
|
|
public function getSource($type){
|
|
|
|
$source_id = 0;
|
|
|
|
if ($type == 2){$source = 2;$source_id = 1;
|
|
...
|
...
|
@@ -98,10 +105,8 @@ class VisualizationLogic extends BaseLogic |
|
|
|
$templateInfo = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]);
|
|
|
|
if($templateInfo === false){
|
|
|
|
$data = [
|
|
|
|
'html'=>$this->param['html'],
|
|
|
|
'project_id'=>$this->user['project_id'],
|
|
|
|
'source'=>$source,
|
|
|
|
'source_id'=>$source_id,
|
|
|
|
'html'=>$this->param['html'], 'project_id'=>$this->user['project_id'],
|
|
|
|
'source'=>$source, 'source_id'=>$source_id,
|
|
|
|
];
|
|
|
|
$bTemplateModel->add($data);
|
|
|
|
}else{
|
|
...
|
...
|
@@ -139,51 +144,83 @@ class VisualizationLogic extends BaseLogic |
|
|
|
$page_array = (array)$this->user['is_visualization']->page_array;//获取定制界面
|
|
|
|
//查看当前类型是否是定制界面
|
|
|
|
if(in_array($type,$page_array)){//是定制界面
|
|
|
|
if(in_array($type,[1,3,5,7])){//单页
|
|
|
|
$templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前定制单页是否有代码块
|
|
|
|
if($templateInfo === false){
|
|
|
|
return $this->getVisualizationHtml($type);
|
|
|
|
}else{//非定制界面
|
|
|
|
return $this->getTemplateHtml();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :定制界面获取html
|
|
|
|
* @name :getVisualizationHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/6 11:47
|
|
|
|
*/
|
|
|
|
public function getVisualizationHtml($type){
|
|
|
|
if(in_array($type,[1,3,5,7])){//单页
|
|
|
|
$templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前定制单页是否有代码块
|
|
|
|
if($templateInfo === false){
|
|
|
|
$this->fail('请先上传定制代码块');
|
|
|
|
}
|
|
|
|
return ['html'=>$templateInfo['html']];
|
|
|
|
}else{//模块页
|
|
|
|
$templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前页面是否可视化
|
|
|
|
if($templateInfo === false){//获取代码块
|
|
|
|
$bTemplateMainModel = new BTemplateMain();
|
|
|
|
$mainInfo = $bTemplateMainModel->read(['type'=>$type]);
|
|
|
|
if($mainInfo === false){
|
|
|
|
$this->fail('请先上传定制代码块');
|
|
|
|
}
|
|
|
|
return ['html'=>$templateInfo['html']];
|
|
|
|
}else{//模块页
|
|
|
|
$templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前页面是否可视化
|
|
|
|
if($templateInfo === false){//获取代码块
|
|
|
|
$bTemplateMainModel = new BTemplateMain();
|
|
|
|
$mainInfo = $bTemplateMainModel->read(['type'=>$type]);
|
|
|
|
if($mainInfo === false){
|
|
|
|
$this->fail('请先上传定制代码块');
|
|
|
|
}
|
|
|
|
return ['html'=>$mainInfo['main_html']];
|
|
|
|
}
|
|
|
|
return ['html'=>$templateInfo['html']];
|
|
|
|
return ['html'=>$mainInfo['main_html']];
|
|
|
|
}
|
|
|
|
}else{//非定制界面
|
|
|
|
$bSettingModel = new Setting();
|
|
|
|
$settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
|
|
|
|
if($settingInfo === false){
|
|
|
|
$this->fail('请先选择模版');
|
|
|
|
//替换为公共头部和底部
|
|
|
|
$templateCommonModel = new BTemplateCommon();
|
|
|
|
$headerFooterHtml = $templateCommonModel->read(['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
|
|
|
|
$html = $templateInfo['html'];
|
|
|
|
if($headerFooterHtml !== false){
|
|
|
|
$html = preg_replace('/<header\b[^>]*>(.*?)<\/header>/s', $headerFooterHtml['head_html'], $html);
|
|
|
|
$html = preg_replace('/<footer\b[^>]*>(.*?)<\/footer>/s', $headerFooterHtml['footer_html'], $html);
|
|
|
|
$html = preg_replace('/<style id="globalsojs-header">(.*?)<\/style>/s', $headerFooterHtml['head_css'], $html);
|
|
|
|
$html = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', $headerFooterHtml['footer_css'], $html);
|
|
|
|
}
|
|
|
|
$templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);//查看当前页面是否可视化
|
|
|
|
if($templateInfo === false){
|
|
|
|
//根据类型在获取中间部分
|
|
|
|
$mainData = $this->getCommonMain($this->param['source'],$this->param['source_id']);
|
|
|
|
}else{
|
|
|
|
$mainData = [
|
|
|
|
'main_html'=>$templateInfo['main_html'],
|
|
|
|
'main_css'=>$templateInfo['main_css']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
//获取公共头部底部
|
|
|
|
$commonInfo = $this->getCommonPage($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);
|
|
|
|
//拼接数据
|
|
|
|
$html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
|
|
|
|
$commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html'];
|
|
|
|
$html = $this->getHeadFooter($html);
|
|
|
|
return ['html'=>$html,'template_id'=>$settingInfo['template_id']];
|
|
|
|
return ['html'=>$html];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :非定制项目获取html
|
|
|
|
* @name :getTemplateHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/6 11:44
|
|
|
|
*/
|
|
|
|
public function getTemplateHtml(){
|
|
|
|
$bSettingModel = new Setting();
|
|
|
|
$settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
|
|
|
|
if($settingInfo === false){
|
|
|
|
$this->fail('请先选择模版');
|
|
|
|
}
|
|
|
|
$templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);//查看当前页面是否可视化
|
|
|
|
if($templateInfo === false){
|
|
|
|
//根据类型在获取中间部分
|
|
|
|
$mainData = $this->getCommonMain($this->param['source'],$this->param['source_id']);
|
|
|
|
}else{
|
|
|
|
$mainData = [
|
|
|
|
'main_html'=>$templateInfo['main_html'],
|
|
|
|
'main_css'=>$templateInfo['main_css']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
//获取公共头部底部
|
|
|
|
$commonInfo = $this->getCommonPage($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);
|
|
|
|
//拼接数据
|
|
|
|
$html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
|
|
|
|
$commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html'];
|
|
|
|
$html = $this->getHeadFooter($html);
|
|
|
|
return $this->success(['html'=>$html,'template_id'=>$settingInfo['template_id']]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :拼接获取公共头部底部
|
|
|
|
* @name :getHeadFooter
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -226,7 +263,7 @@ class VisualizationLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取类型
|
|
|
|
* @remark :定制界面根据source+source_id获取type类型
|
|
|
|
* @name :getType
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
...
|
...
|
@@ -247,7 +284,7 @@ class VisualizationLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取设置的类型
|
|
|
|
* @remark :非定制获取设置头部底部的类型
|
|
|
|
* @name :getType
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
...
|
...
|
@@ -284,7 +321,7 @@ class VisualizationLogic extends BaseLogic |
|
|
|
$type = $this->getType($this->param['source'],$this->param['source_id']);
|
|
|
|
try {
|
|
|
|
if(in_array($type,$page_array)){//定制页面
|
|
|
|
$this->saveVisualizationHtml();
|
|
|
|
$this->saveVisualizationHtml($type);
|
|
|
|
}else{
|
|
|
|
$this->saveTemplateHtml();
|
|
|
|
}
|
|
...
|
...
|
@@ -301,23 +338,53 @@ class VisualizationLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/5 15:42
|
|
|
|
*/
|
|
|
|
public function saveVisualizationHtml(){
|
|
|
|
public function saveVisualizationHtml($type){
|
|
|
|
$bTemplateModel = new BTemplate();
|
|
|
|
$templateInfo = $bTemplateModel->read([
|
|
|
|
'source'=>$this->param['source'], 'project_id'=>$this->user['project_id'],
|
|
|
|
'source_id'=>$this->param['source_id'], 'template_id'=>0
|
|
|
|
]);
|
|
|
|
if($templateInfo === false){
|
|
|
|
$this->param['project_id'] = $this->user['project_id'];
|
|
|
|
$this->param['template_id'] = 0;
|
|
|
|
// $this->param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');
|
|
|
|
// $this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');
|
|
|
|
$bTemplateModel->add($this->param);
|
|
|
|
try {
|
|
|
|
//更新头部底部
|
|
|
|
$this->visualizationSaveHeaderFooter($type);
|
|
|
|
if($templateInfo === false){
|
|
|
|
$this->param['project_id'] = $this->user['project_id'];
|
|
|
|
$this->param['template_id'] = 0;
|
|
|
|
$bTemplateModel->add($this->param);
|
|
|
|
}else{
|
|
|
|
$param['html'] = $this->param['html'];
|
|
|
|
$bTemplateModel->edit($param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id'],'template_id'=>0]);
|
|
|
|
}
|
|
|
|
}catch (\Exception $e){
|
|
|
|
$this->fail('系统错误,请联系管理员');
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :定制界面保存头部底部
|
|
|
|
* @name :visualizationSaveHeaderFooter
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/6 10:41
|
|
|
|
*/
|
|
|
|
public function visualizationSaveHeaderFooter($type){
|
|
|
|
//更新头部底部代码
|
|
|
|
$header_footer = [
|
|
|
|
'head_html'=>characterTruncation($this->param['html'],'/<header\b[^>]*>(.*?)<\/header>/s'),
|
|
|
|
'head_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s'),
|
|
|
|
'footer_html'=>characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s'),
|
|
|
|
'footer_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
|
|
|
|
];
|
|
|
|
$templateCommonModel = new BTemplateCommon();
|
|
|
|
$info = $templateCommonModel->read(['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
|
|
|
|
if($info === false){
|
|
|
|
$header_footer['template_id'] = 0;
|
|
|
|
$header_footer['project_id'] = $this->user['project_id'];
|
|
|
|
$header_footer['type'] = $type;
|
|
|
|
$templateCommonModel->add($header_footer);
|
|
|
|
}else{
|
|
|
|
// $param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');
|
|
|
|
// $param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');
|
|
|
|
$param['html'] = $this->param['html'];
|
|
|
|
$bTemplateModel->edit($param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id'],'template_id'=>0]);
|
|
|
|
$templateCommonModel->edit($header_footer,['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
...
|
...
|
|