作者 lyh

gx

@@ -62,8 +62,8 @@ class BTemplateLogic extends BaseLogic @@ -62,8 +62,8 @@ class BTemplateLogic extends BaseLogic
62 * @time :2023/6/29 9:44 62 * @time :2023/6/29 9:44
63 */ 63 */
64 public function getTemplate(){ 64 public function getTemplate(){
65 - $settingInfo = $this->getSettingTemplate();//模版详情  
66 - $data = $this->getHtml($settingInfo,$this->param['source'],$this->param['source_id'],$this->param['is_custom'] ?? 0); 65 + $template_id = $this->getSettingTemplate($this->param['source'],$this->param['source_id']);//设置的模版id
  66 + $data = $this->getHtml($template_id,$this->param['source'],$this->param['source_id'],$this->param['is_custom'] ?? 0);
67 return $this->success($data); 67 return $this->success($data);
68 } 68 }
69 69
@@ -74,14 +74,12 @@ class BTemplateLogic extends BaseLogic @@ -74,14 +74,12 @@ class BTemplateLogic extends BaseLogic
74 * @method :post 74 * @method :post
75 * @time :2023/12/13 10:47 75 * @time :2023/12/13 10:47
76 */ 76 */
77 - public function getHtml($settingInfo,$source,$source_id,$is_custom = 0){  
78 - $templateInfo = $this->webTemplateInfo($settingInfo['template_id'],$source,$source_id,$is_custom); 77 + public function getHtml($template_id,$source,$source_id,$is_custom){
  78 + $templateInfo = $this->webTemplateInfo($template_id,$source,$source_id,$is_custom);
79 if($templateInfo === false){ 79 if($templateInfo === false){
80 if($this->user['is_customized'] == BTemplate::SOURCE_VISUALIZATION){//处理定制页面初始数据 80 if($this->user['is_customized'] == BTemplate::SOURCE_VISUALIZATION){//处理定制页面初始数据
81 - $result = $this->isCustomizedPage($source,$source_id);//查看当前页面是否定制  
82 - if($result !== true){  
83 - return ['html'=>$result['html'],'template_id'=>$result['template_id']];  
84 - } 81 + $html = $this->isCustomizedPage($source,$source_id);//查看当前页面是否定制
  82 + return $this->success(['html'=>$html,'template_id'=>$template_id]);
85 } 83 }
86 $mainInfo = $this->getCommonMain($source,$source_id);//获取中间部分代码 84 $mainInfo = $this->getCommonMain($source,$source_id);//获取中间部分代码
87 }else{ 85 }else{
@@ -91,13 +89,13 @@ class BTemplateLogic extends BaseLogic @@ -91,13 +89,13 @@ class BTemplateLogic extends BaseLogic
91 $type = $this->getCustomizedType($source, $source_id);//定制获取头部底部类型 89 $type = $this->getCustomizedType($source, $source_id);//定制获取头部底部类型
92 $commonInfo = $this->getCommonPage(['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);//获取定制头部 90 $commonInfo = $this->getCommonPage(['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);//获取定制头部
93 $html = $this->handleAllHtml($commonInfo,$templateInfo['html']); 91 $html = $this->handleAllHtml($commonInfo,$templateInfo['html']);
94 - return ['html'=>$html,'template_id'=>$settingInfo['template_id']]; 92 + return $this->success(['html'=>$html,'template_id'=>$template_id]);
95 } 93 }
96 - $commonInfo = $this->getCommonPage($source,$source_id,$settingInfo['template_id']);//获取头部 94 + $commonInfo = $this->getCommonPage($source,$source_id,$template_id);//获取头部
97 $html = $commonInfo['head_css'].$mainInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other']. 95 $html = $commonInfo['head_css'].$mainInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
98 $commonInfo['head_html'].$mainInfo['main_html'].$commonInfo['footer_html']; 96 $commonInfo['head_html'].$mainInfo['main_html'].$commonInfo['footer_html'];
99 $html = $this->getHeadFooter($html); 97 $html = $this->getHeadFooter($html);
100 - return ['html'=>$html,'template_id'=>$settingInfo['template_id']]; 98 + return $this->success(['html'=>$html,'template_id'=>$template_id]);
101 } 99 }
102 100
103 /** 101 /**
@@ -134,7 +132,7 @@ class BTemplateLogic extends BaseLogic @@ -134,7 +132,7 @@ class BTemplateLogic extends BaseLogic
134 if($customHtmlInfo === false){ 132 if($customHtmlInfo === false){
135 $this->fail('定制页面,请先上传代码块'); 133 $this->fail('定制页面,请先上传代码块');
136 } 134 }
137 - return ['html'=>$customHtmlInfo['html']]; 135 + return $customHtmlInfo['html'];
138 } 136 }
139 return true; 137 return true;
140 } 138 }
@@ -167,13 +165,21 @@ class BTemplateLogic extends BaseLogic @@ -167,13 +165,21 @@ class BTemplateLogic extends BaseLogic
167 * @method :post 165 * @method :post
168 * @time :2023/12/13 10:48 166 * @time :2023/12/13 10:48
169 */ 167 */
170 - public function getSettingTemplate(){ 168 + public function getSettingTemplate($source,$source_id){
  169 + if($this->user['is_customized'] == BTemplate::SOURCE_VISUALIZATION) {//定制项目
  170 + $type = $this->getCustomizedType($source, $source_id);//获取定制界面类型
  171 + //查看当前页面是否定制,是否开启可视化
  172 + $page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
  173 + if (in_array($type, $page_array)) {//是定制界面
  174 + return 0;
  175 + }
  176 + }
171 $bSettingModel = new Setting(); 177 $bSettingModel = new Setting();
172 $info = $bSettingModel->read(['project_id'=>$this->user['project_id']]); 178 $info = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
173 if($info === false){ 179 if($info === false){
174 $this->fail('请先选择模版'); 180 $this->fail('请先选择模版');
175 } 181 }
176 - return $info; 182 + return $info['template_id'];
177 } 183 }
178 184
179 /** 185 /**
@@ -390,7 +396,7 @@ class BTemplateLogic extends BaseLogic @@ -390,7 +396,7 @@ class BTemplateLogic extends BaseLogic
390 * @time :2023/12/13 17:05 396 * @time :2023/12/13 17:05
391 */ 397 */
392 public function saveCommonHtml($html,$source,$source_id,$template_id){ 398 public function saveCommonHtml($html,$source,$source_id,$template_id){
393 - $type = $this->getType($source,$source_id);//获取头部类型1-9(首页到自定义页面) 399 + $type = $this->getType($source,$source_id,$template_id);//获取头部类型1-9(首页到自定义页面)
394 $templateCommonModel = new BTemplateCommon(); 400 $templateCommonModel = new BTemplateCommon();
395 $commonInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type]);//查看当前头部是否存在 401 $commonInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type]);//查看当前头部是否存在
396 $handleInfo = $this->handleCommonParam($html); 402 $handleInfo = $this->handleCommonParam($html);
@@ -465,8 +471,11 @@ class BTemplateLogic extends BaseLogic @@ -465,8 +471,11 @@ class BTemplateLogic extends BaseLogic
465 * @method :post 471 * @method :post
466 * @time :2023/10/21 17:29 472 * @time :2023/10/21 17:29
467 */ 473 */
468 - public function getType($source,$source_id){ 474 + public function getType($source,$source_id,$template_id){
469 $type = 1;//首页公共头部底部 475 $type = 1;//首页公共头部底部
  476 + if($template_id == 0){//保存上传的代码块时,默认为独立头部
  477 + $this->user['configuration']['is_head'] == 1;
  478 + }
470 //查看页面是否设置自定义头部底部 479 //查看页面是否设置自定义头部底部
471 if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) { 480 if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) {
472 $pageSettingModel = new PageSetting(); 481 $pageSettingModel = new PageSetting();
@@ -500,8 +509,16 @@ class BTemplateLogic extends BaseLogic @@ -500,8 +509,16 @@ class BTemplateLogic extends BaseLogic
500 'type'=>$type, 509 'type'=>$type,
501 'is_custom'=>$is_custom, 510 'is_custom'=>$is_custom,
502 'source'=>$source, 511 'source'=>$source,
503 - 'source_id'=>$source_id 512 + 'source_id'=>$source_id,
  513 + 'main_html' => characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s'),
  514 + 'main_css' => characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
  515 + 'head_html' => characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'),
  516 + 'footer_html' => characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'),
  517 + 'head_css' => characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'),
  518 + 'footer_css' => characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
504 ]; 519 ];
  520 + $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s'));
  521 + $data['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
505 $bTemplateLogModel = new BTemplateLog(); 522 $bTemplateLogModel = new BTemplateLog();
506 return $bTemplateLogModel->add($data); 523 return $bTemplateLogModel->add($data);
507 } 524 }