作者 lyh

gx

@@ -46,7 +46,7 @@ class VisualizationLogic extends BaseLogic @@ -46,7 +46,7 @@ class VisualizationLogic extends BaseLogic
46 $source = $data['source']; 46 $source = $data['source'];
47 $source_id = $data['source_id']; 47 $source_id = $data['source_id'];
48 $type = $this->getType($source,$source_id); 48 $type = $this->getType($source,$source_id);
49 - $typeArray = [1,3,5,7];//单页数据 49 + $typeArray = [BTemplate::TYPE_ONE,BTemplate::TYPE_THREE,BTemplate::TYPE_FIVE,BTemplate::TYPE_SEVEN];//单页数据
50 if(in_array($type,$typeArray)){ 50 if(in_array($type,$typeArray)){
51 $bTemplateModel = new BTemplate(); 51 $bTemplateModel = new BTemplate();
52 $info = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]); 52 $info = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]);
@@ -54,7 +54,7 @@ class VisualizationLogic extends BaseLogic @@ -54,7 +54,7 @@ class VisualizationLogic extends BaseLogic
54 $html = ''; 54 $html = '';
55 }else{ 55 }else{
56 $html = $info['html']; 56 $html = $info['html'];
57 - } 57 + }
58 }else{//模块数据 58 }else{//模块数据
59 $bTemplateMainModel = new BTemplateMain(); 59 $bTemplateMainModel = new BTemplateMain();
60 $info = $bTemplateMainModel->read(['type'=>$type]); 60 $info = $bTemplateMainModel->read(['type'=>$type]);
@@ -67,6 +67,13 @@ class VisualizationLogic extends BaseLogic @@ -67,6 +67,13 @@ class VisualizationLogic extends BaseLogic
67 return $this->success(['html'=>$html]); 67 return $this->success(['html'=>$html]);
68 } 68 }
69 69
  70 + /**
  71 + * @remark :根据type获取source类型
  72 + * @name :getSource
  73 + * @author :lyh
  74 + * @method :post
  75 + * @time :2023/12/6 11:25
  76 + */
70 public function getSource($type){ 77 public function getSource($type){
71 $source_id = 0; 78 $source_id = 0;
72 if ($type == 2){$source = 2;$source_id = 1; 79 if ($type == 2){$source = 2;$source_id = 1;
@@ -98,10 +105,8 @@ class VisualizationLogic extends BaseLogic @@ -98,10 +105,8 @@ class VisualizationLogic extends BaseLogic
98 $templateInfo = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]); 105 $templateInfo = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]);
99 if($templateInfo === false){ 106 if($templateInfo === false){
100 $data = [ 107 $data = [
101 - 'html'=>$this->param['html'],  
102 - 'project_id'=>$this->user['project_id'],  
103 - 'source'=>$source,  
104 - 'source_id'=>$source_id, 108 + 'html'=>$this->param['html'], 'project_id'=>$this->user['project_id'],
  109 + 'source'=>$source, 'source_id'=>$source_id,
105 ]; 110 ];
106 $bTemplateModel->add($data); 111 $bTemplateModel->add($data);
107 }else{ 112 }else{
@@ -139,51 +144,83 @@ class VisualizationLogic extends BaseLogic @@ -139,51 +144,83 @@ class VisualizationLogic extends BaseLogic
139 $page_array = (array)$this->user['is_visualization']->page_array;//获取定制界面 144 $page_array = (array)$this->user['is_visualization']->page_array;//获取定制界面
140 //查看当前类型是否是定制界面 145 //查看当前类型是否是定制界面
141 if(in_array($type,$page_array)){//是定制界面 146 if(in_array($type,$page_array)){//是定制界面
142 - if(in_array($type,[1,3,5,7])){//单页  
143 - $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前定制单页是否有代码块  
144 - if($templateInfo === false){ 147 + return $this->getVisualizationHtml($type);
  148 + }else{//非定制界面
  149 + return $this->getTemplateHtml();
  150 + }
  151 + }
  152 +
  153 + /**
  154 + * @remark :定制界面获取html
  155 + * @name :getVisualizationHtml
  156 + * @author :lyh
  157 + * @method :post
  158 + * @time :2023/12/6 11:47
  159 + */
  160 + public function getVisualizationHtml($type){
  161 + if(in_array($type,[1,3,5,7])){//单页
  162 + $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前定制单页是否有代码块
  163 + if($templateInfo === false){
  164 + $this->fail('请先上传定制代码块');
  165 + }
  166 + return ['html'=>$templateInfo['html']];
  167 + }else{//模块页
  168 + $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前页面是否可视化
  169 + if($templateInfo === false){//获取代码块
  170 + $bTemplateMainModel = new BTemplateMain();
  171 + $mainInfo = $bTemplateMainModel->read(['type'=>$type]);
  172 + if($mainInfo === false){
145 $this->fail('请先上传定制代码块'); 173 $this->fail('请先上传定制代码块');
146 } 174 }
147 - return ['html'=>$templateInfo['html']];  
148 - }else{//模块页  
149 - $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前页面是否可视化  
150 - if($templateInfo === false){//获取代码块  
151 - $bTemplateMainModel = new BTemplateMain();  
152 - $mainInfo = $bTemplateMainModel->read(['type'=>$type]);  
153 - if($mainInfo === false){  
154 - $this->fail('请先上传定制代码块');  
155 - }  
156 - return ['html'=>$mainInfo['main_html']];  
157 - }  
158 - return ['html'=>$templateInfo['html']]; 175 + return ['html'=>$mainInfo['main_html']];
159 } 176 }
160 - }else{//非定制界面  
161 - $bSettingModel = new Setting();  
162 - $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);  
163 - if($settingInfo === false){  
164 - $this->fail('请先选择模版'); 177 + //替换为公共头部和底部
  178 + $templateCommonModel = new BTemplateCommon();
  179 + $headerFooterHtml = $templateCommonModel->read(['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
  180 + $html = $templateInfo['html'];
  181 + if($headerFooterHtml !== false){
  182 + $html = preg_replace('/<header\b[^>]*>(.*?)<\/header>/s', $headerFooterHtml['head_html'], $html);
  183 + $html = preg_replace('/<footer\b[^>]*>(.*?)<\/footer>/s', $headerFooterHtml['footer_html'], $html);
  184 + $html = preg_replace('/<style id="globalsojs-header">(.*?)<\/style>/s', $headerFooterHtml['head_css'], $html);
  185 + $html = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', $headerFooterHtml['footer_css'], $html);
165 } 186 }
166 - $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);//查看当前页面是否可视化  
167 - if($templateInfo === false){  
168 - //根据类型在获取中间部分  
169 - $mainData = $this->getCommonMain($this->param['source'],$this->param['source_id']);  
170 - }else{  
171 - $mainData = [  
172 - 'main_html'=>$templateInfo['main_html'],  
173 - 'main_css'=>$templateInfo['main_css']  
174 - ];  
175 - }  
176 - //获取公共头部底部  
177 - $commonInfo = $this->getCommonPage($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);  
178 - //拼接数据  
179 - $html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other'].  
180 - $commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html'];  
181 - $html = $this->getHeadFooter($html);  
182 - return ['html'=>$html,'template_id'=>$settingInfo['template_id']]; 187 + return ['html'=>$html];
183 } 188 }
184 } 189 }
185 190
186 /** 191 /**
  192 + * @remark :非定制项目获取html
  193 + * @name :getTemplateHtml
  194 + * @author :lyh
  195 + * @method :post
  196 + * @time :2023/12/6 11:44
  197 + */
  198 + public function getTemplateHtml(){
  199 + $bSettingModel = new Setting();
  200 + $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
  201 + if($settingInfo === false){
  202 + $this->fail('请先选择模版');
  203 + }
  204 + $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);//查看当前页面是否可视化
  205 + if($templateInfo === false){
  206 + //根据类型在获取中间部分
  207 + $mainData = $this->getCommonMain($this->param['source'],$this->param['source_id']);
  208 + }else{
  209 + $mainData = [
  210 + 'main_html'=>$templateInfo['main_html'],
  211 + 'main_css'=>$templateInfo['main_css']
  212 + ];
  213 + }
  214 + //获取公共头部底部
  215 + $commonInfo = $this->getCommonPage($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);
  216 + //拼接数据
  217 + $html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
  218 + $commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html'];
  219 + $html = $this->getHeadFooter($html);
  220 + return $this->success(['html'=>$html,'template_id'=>$settingInfo['template_id']]);
  221 + }
  222 +
  223 + /**
187 * @remark :拼接获取公共头部底部 224 * @remark :拼接获取公共头部底部
188 * @name :getHeadFooter 225 * @name :getHeadFooter
189 * @author :lyh 226 * @author :lyh
@@ -226,7 +263,7 @@ class VisualizationLogic extends BaseLogic @@ -226,7 +263,7 @@ class VisualizationLogic extends BaseLogic
226 } 263 }
227 264
228 /** 265 /**
229 - * @remark :获取类型 266 + * @remark :定制界面根据source+source_id获取type类型
230 * @name :getType 267 * @name :getType
231 * @author :lyh 268 * @author :lyh
232 * @method :post 269 * @method :post
@@ -247,7 +284,7 @@ class VisualizationLogic extends BaseLogic @@ -247,7 +284,7 @@ class VisualizationLogic extends BaseLogic
247 } 284 }
248 285
249 /** 286 /**
250 - * @remark :获取设置的类型 287 + * @remark :非定制获取设置头部底部的类型
251 * @name :getType 288 * @name :getType
252 * @author :lyh 289 * @author :lyh
253 * @method :post 290 * @method :post
@@ -284,7 +321,7 @@ class VisualizationLogic extends BaseLogic @@ -284,7 +321,7 @@ class VisualizationLogic extends BaseLogic
284 $type = $this->getType($this->param['source'],$this->param['source_id']); 321 $type = $this->getType($this->param['source'],$this->param['source_id']);
285 try { 322 try {
286 if(in_array($type,$page_array)){//定制页面 323 if(in_array($type,$page_array)){//定制页面
287 - $this->saveVisualizationHtml(); 324 + $this->saveVisualizationHtml($type);
288 }else{ 325 }else{
289 $this->saveTemplateHtml(); 326 $this->saveTemplateHtml();
290 } 327 }
@@ -301,23 +338,53 @@ class VisualizationLogic extends BaseLogic @@ -301,23 +338,53 @@ class VisualizationLogic extends BaseLogic
301 * @method :post 338 * @method :post
302 * @time :2023/12/5 15:42 339 * @time :2023/12/5 15:42
303 */ 340 */
304 - public function saveVisualizationHtml(){ 341 + public function saveVisualizationHtml($type){
305 $bTemplateModel = new BTemplate(); 342 $bTemplateModel = new BTemplate();
306 $templateInfo = $bTemplateModel->read([ 343 $templateInfo = $bTemplateModel->read([
307 'source'=>$this->param['source'], 'project_id'=>$this->user['project_id'], 344 'source'=>$this->param['source'], 'project_id'=>$this->user['project_id'],
308 'source_id'=>$this->param['source_id'], 'template_id'=>0 345 'source_id'=>$this->param['source_id'], 'template_id'=>0
309 ]); 346 ]);
310 - if($templateInfo === false){  
311 - $this->param['project_id'] = $this->user['project_id'];  
312 - $this->param['template_id'] = 0;  
313 -// $this->param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');  
314 -// $this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');  
315 - $bTemplateModel->add($this->param); 347 + try {
  348 + //更新头部底部
  349 + $this->visualizationSaveHeaderFooter($type);
  350 + if($templateInfo === false){
  351 + $this->param['project_id'] = $this->user['project_id'];
  352 + $this->param['template_id'] = 0;
  353 + $bTemplateModel->add($this->param);
  354 + }else{
  355 + $param['html'] = $this->param['html'];
  356 + $bTemplateModel->edit($param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id'],'template_id'=>0]);
  357 + }
  358 + }catch (\Exception $e){
  359 + $this->fail('系统错误,请联系管理员');
  360 + }
  361 + return $this->success();
  362 + }
  363 +
  364 + /**
  365 + * @remark :定制界面保存头部底部
  366 + * @name :visualizationSaveHeaderFooter
  367 + * @author :lyh
  368 + * @method :post
  369 + * @time :2023/12/6 10:41
  370 + */
  371 + public function visualizationSaveHeaderFooter($type){
  372 + //更新头部底部代码
  373 + $header_footer = [
  374 + 'head_html'=>characterTruncation($this->param['html'],'/<header\b[^>]*>(.*?)<\/header>/s'),
  375 + 'head_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s'),
  376 + 'footer_html'=>characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s'),
  377 + 'footer_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
  378 + ];
  379 + $templateCommonModel = new BTemplateCommon();
  380 + $info = $templateCommonModel->read(['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
  381 + if($info === false){
  382 + $header_footer['template_id'] = 0;
  383 + $header_footer['project_id'] = $this->user['project_id'];
  384 + $header_footer['type'] = $type;
  385 + $templateCommonModel->add($header_footer);
316 }else{ 386 }else{
317 -// $param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');  
318 -// $param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');  
319 - $param['html'] = $this->param['html'];  
320 - $bTemplateModel->edit($param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id'],'template_id'=>0]); 387 + $templateCommonModel->edit($header_footer,['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
321 } 388 }
322 return $this->success(); 389 return $this->success();
323 } 390 }