TemplateController.php
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace App\Http\Controllers\Bside;
use App\Models\Template\ATemplate;
use App\Models\Template\BSetting;
use App\Models\Template\BTemplateData;
/**
* 模板
* @author:dc
* @time 2023/5/9 14:00
* Class TemplateController
* @package App\Http\Controllers\Bside
*/
class TemplateController extends BaseController
{
/**
* 模板列表
* @return \Illuminate\Http\JsonResponse
* @author:dc
* @time 2023/5/9 14:20
*/
public function index(){
$limit = intval($this->param['limit']??20);
// 读取列表
$data = ATemplate::_bAll($limit)->toArray();
return $this->success($data);
}
/**
* 当前使用的模板
* @author:dc
* @time 2023/5/9 15:19
*/
public function info(){
// 保存更新
if($this->isPost()){
$template_id = intval($this->param['template_id']??0);
// 是否存在模板
if($template_id && ATemplate::_bFind($template_id)){
BSetting::_save($this->user['project_id'],$template_id);
}else{
return $this->response('无法使用不存在的模板','B_TEMPLATE_NOTFOUND');
}
}
// 读取我的模板
$conf = BSetting::_get($this->user['project_id']);
// 读取模板信息
$data = ATemplate::_bFind($conf['template_id']);
return $this->success([
'template_id' => $data['id']??0,
'name' => $data['name']??'',
'thumb' => $data['thumb']??'',
'time' => $conf['time']
]);
}
/**
* 保存模板
* @author:dc
* @time 2023/5/10 10:53
*/
public function save(){
$html = '<header id="globalso-header" class="web_head sticky-top py-1 py-md-0" style="background-color: #318fff;">asdf</header>';
// 替换 header
$html = preg_replace("/<header(.*)id=\"globalso-header\"(.*)>([\s\S]*)<\/header>/iU",'',$html);
$html = preg_replace("/<main(.*)id=\"globalso-main\"(.*)>([\s\S]*)<\/main>/iU",'',$html);
$html = preg_replace("/<footer(.*)id=\"globalso-footer\"(.*)>([\s\S]*)<\/footer>/iU",'',$html);
}
/**
* 自定义块
* @author:dc
* @time 2023/5/10 14:55
*/
public function customChunk(){
$html = $this->param['html']??[];
if(!is_array($html)){
return $this->response('参数异常','B_CUSTOM_CHUNK_PARAMS');
}
$data = BTemplateData::_insert();
}
}