TemplateController.php
8.6 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?php
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\TemplateLogic;
use App\Http\Requests\Bside\TemplateRequest;
use App\Models\Template\ATemplate;
use App\Models\Template\ATemplateHtml;
use App\Models\Template\BSetting;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateData;
use Illuminate\Validation\Rule;
/**
* 模板
* @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('无法使用不存在的模板',Code::SYSTEM_ERROR);
}
}
// 读取我的模板
$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);
}
/**
* 数据源
* @return \Illuminate\Http\JsonResponse
* @author:dc
* @time 2023/5/11 10:47
*/
public function get_type(){
return $this->success(ATemplateHtml::$sourceMap);
}
/**
* 获取 编辑html
* @author:dc
* @time 2023/5/11 9:33
*/
public function get_html(){
$source = $this->param['source']??'';
$source_id = $this->param['source_id']??0;
$data = TemplateLogic::instance()->first($source,$source_id);
$def = '<div class=" d-flex align-items-center justify-content-between py-md-4">
<div class="logo w-25 w-sm-auto"><a href="#"><img class="img-fluid" src="img/logo.png" alt=""></a></div>
<nav class="navbar navbar-expand-md navbar-dark flex-fill justify-content-end mx-2 pe-md-5">
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#navMenu"
aria-controls="navMenu">
<span class="navbar-toggler-icon"></span>
</button>
<ul class="nav column-gap-5 justify-content-end text-white d-none d-md-flex">
<li><a href="#">Home</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-bs-toggle="dropdown">Products</a>
<ul class="dropdown-menu fs-6 text-body shadow-sm border-0">
<li><a href="#" class="dropdown-item py-2">Product Information</a></li>
<li><a href="#" class="dropdown-item py-2">Change of Insurance</a></li>
<li><a href="#" class="dropdown-item py-2">Traveling Oxygen Program</a></li>
<li><a href="#" class="dropdown-item py-2">Contact</a></li>
</ul>
</li>
<li><a href="#">News</a></li>
<li><a href="#">Download</a></li>
<li><a href="#">FAQ</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<div class="d-flex align-items-center justify-content-end">
<div class="search">
<button type="button" class="btn border-0" data-bs-toggle="dropdown">
<svg viewBox="0 0 24 24" width="18" height="18" stroke="#ffffff" stroke-width="2"
fill="none" stroke-linecap="round" stroke-linejoin="round" class="css-i6dzq1">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
</button>
<div class="dropdown-menu p-3 shadow-sm border-0">
<form action="">
<div class="d-flex mb-2">
<input type="text" class="form-control" name="search" placeholder="Start Typing...">
<button class="btn btn-search border-0" type="submit">
<svg viewBox="0 0 24 24" width="18" height="18" stroke="#333333"
stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"
class="css-i6dzq1">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
</button>
</div>
<p class="search-attr">Hit enter to search or ESC to close</p>
</form>
</div>
</div>
<div class="change-language ms-md-4">
<div role="button" class="dropdown-toggle text-white d-flex align-items-center"
data-bs-toggle="dropdown">
<b class="country-flag language-flag-en"></b> <span>English</span>
</div>
<div class="dropdown-menu shadow-sm border-0">
<div class="d-flex flex-wrap p-3 text-body">
<a href="#" class="col-4 mb-3 pe-2 d-flex align-items-center" title="English">
<b class="country-flag language-flag-en"></b>
<span>English</span>
</a>
<a href="#" class="col-4 mb-3 pe-2 d-flex align-items-center" title="Françai">
<b class="country-flag language-flag-fr"></b>
<span>Françai</span>
</a>
<a href="#" class="col-4 mb-3 pe-2 d-flex align-items-center" title="Español">
<b class="country-flag language-flag-es"></b>
<span>Español</span>
</a>
<a href="#" class="col-4 mb-3 pe-2 d-flex align-items-center" title="Deutsch">
<b class="country-flag language-flag-de"></b>
<span>Deutsch</span>
</a>
<a href="#" class="col-4 mb-3 pe-2 d-flex align-items-center" title="Română">
<b class="country-flag language-flag-ro"></b>
<span>Română</span>
</a>
</div>
</div>
</div>
</div>
</div>';
return $this->response('',Code::SUCCESS,$data?$data['html']:$def);
}
/**
* 保存
* @author:dc
* @time 2023/5/11 11:00
*/
public function save_html(TemplateRequest $request){
$data = $request->validated();
$data['data_source'] = $data['source'];
$data['data_source_id'] = $data['source_id'];
unset($data['source']);
unset($data['source_id']);
TemplateLogic::instance()->save($data);
return $this->response('保存成功');
}
/**
* 状态修改
* @param TemplateRequest $request
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
* @author:dc
* @time 2023/5/15 14:43
*/
public function status(TemplateRequest $request){
$data = $request->validated();
TemplateLogic::instance()->status($data['source'],$data['source_id'],$data['status']);
return $this->response('保存成功');
}
/**
* 自定义块
* @author:dc
* @time 2023/5/10 14:55
*/
public function customChunk(){
//
// $html = $this->param['html']??[];
// // 那个页面 的
// $type = $this->param['type']??'';
//
// if(!is_array($html)){
// return $this->response('参数异常',Code::SYSTEM_ERROR);
// }
//
// // 项目id
// $project_id = $this->user['project_id'];
// // 当前模板
// $template_id = BSetting::_get($project_id)['template_id'];
//
// // 验证这个模板是否存在
// if(!$type || !ATemplateHtml::_typeExist($template_id,$type)){
// return $this->response('页面类型错误',Code::SYSTEM_ERROR);
// }
//
//
// $html = view("template.{$template_id}.{$type}")->render();
//
//
// return $this->response('',Code::SUCCESS,$html);
//// $data = BTemplateData::_insert();
//
//
}
}