VideoTempController.php
9.05 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
<?php
namespace App\Admin\Controllers;
use App\Models\VideoTemp;
use App\Models\Component;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Widgets\Table;
use Illuminate\Support\Facades\DB;
class VideoTempController extends AdminController
{
protected $title = '临境模板';
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
return Grid::make(new VideoTemp(), function (Grid $grid) {
$grid->model()->with('components');
// 设置自定义视图
$grid->setActionClass(Grid\Displayers\Actions::class);
$grid->column('id',__('ID'))->sortable();
$grid->column('title');
$grid->column('','组件信息')
->display('展开')
->expand(function (){
$th = ['id','模板id','名称','位置','字号','字体颜色','背景色','透明度','创建时间','修改时间'];
return Table::make($th, $this->components->toArray())->withBorder();
});
// $grid->column('type');
// $grid->column('bg_type');
// $grid->column('bg_url')->image('/storage/');
// $grid->column('bg_music');
$grid->column('state')->switch();
// $grid->column('sn');
// $grid->column('top');
// $grid->column('left');
// $grid->column('font_size');
$grid->column('created_at');
$grid->column('updated_at')->sortable();
//
// $grid->filter(function (Grid\Filter $filter) {
// $filter->equal('id');
//
// });
});
}
/**
* Make a show builder.
*
* @param mixed $id
*
* @return Show
*/
protected function detail($id)
{
return Show::make($id, new VideoTemp(), function (Show $show) {
$show->field('id');
$show->field('title');
$show->field('type');
$show->field('bg_type');
$show->field('bg_url');
$show->field('bg_music');
$show->field('state');
$show->field('sn');
$show->field('top');
$show->field('left');
$show->field('font_size');
$show->field('created_at');
$show->field('updated_at');
});
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form2()
{
return Form::make(new VideoTemp(), function (Form $form) {
$form->display('id');
$form->block(8, function (Form\BlockForm $form) {
// 设置标题
$form->title('基本设置');
// 显示底部提交按钮
$form->showFooter();
// 设置字段宽度
$form->width(8, 3);
$form->text('title');
$form->radio('type')->addElementClass('type')
->options([1=>'图文音频',2=>'视频'])->default(1);
$form->radio('bg_type')
->options([1=>'视频', 2=>'图片'])
->when(1,function (Form\BlockForm $form){
$form->file('bg_url')
->accept('mp4')
->autoUpload()
->uniqueName()
->addElementClass('bg_video_url');
})
->when(2,function (Form\BlockForm $form){
$form->multipleImage('bg_url')
->limit(5)
->uniqueName()
->addElementClass('bg_img_url');
})
->default(1);
$form->radio('bg_music')
->options(['无', '有'])
->when(1,function (Form\BlockForm $form){
$form->file('bgm_url')
->accept('mp3,aac,wav')
->autoUpload()
->uniqueName()
->addElementClass('bgm_url');
})
->default(0);
$form->number('top');
$form->number('left');
$form->number('font_size');
$form->color('text_color')->default('#f5f5f5')
->addElementClass('text_color');
$form->color('text_bg_color')->addElementClass('text_bg_color');
$form->number('opacity')->min(0)->max(100)
->addElementClass('opacity')->default(90)
->help('范围为0-100,100表示不透明,0表示完全透明');
$form->number('sn');
$form->radio('state')->options(['不显示', '显示'])->default(0);
});
$form->block(4, function (Form\BlockForm $form) {
$form->html(view('admin.form.phone'));
});
$form->display('created_at');
$form->display('updated_at');
});
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
return Form::make(new VideoTemp(), function (Form $form) {
$form->display('id');
$form->block(8, function (Form\BlockForm $form) {
// 设置标题
$form->title('基本设置');
// 显示底部提交按钮
$form->showFooter();
// 设置字段宽度
$form->width(8, 3);
$form->text('title');
$form->checkbox('components','组件')
->when('every_poem', function (Form\BlockForm $form) {
$form->select('pos_every_poem', '每日位置')->options([
'topLeft'=>'上左','topMiddle'=>'上中','topRight'=>'上右',
]);
$form->divider();
})
->when('one_poem', function (Form\BlockForm $form) {
$form->select('pos_one_poem', '一言位置')->options([
'topLeft'=>'上左','topMiddle'=>'上中','topRight'=>'上右',
]);
$form->divider();
})
->when('weather', function (Form\BlockForm $form) {
$form->select('pos_weather', '天气位置')->options([
'topLeft'=>'上左','topMiddle'=>'上中','topRight'=>'上右',
]);
$form->divider();
})
->when('date', function (Form\BlockForm $form) {
$form->select('pos_date', '日期位置')->options([
'topLeft'=>'上左','topMiddle'=>'上中','topRight'=>'上右',
]);
$form->divider();
})
->when('feel', function (Form\BlockForm $form) {
$form->select('pos_feel', '日期位置')->options([
'topLeft'=>'上左','topMiddle'=>'上中','topRight'=>'上右',
]);
$form->divider();
})
->default(['one_poem','weather','date'])
->options([
'every_poem' => '每日一言组件',
'one_poem' => '一言组件',
'weather' => '天气组件',
'date' => '日期组件',
'feel' => '临境有感组件',
]);
$form->hidden('state')
->saving(function ($v) {
return $v;
});
});
// $form->block(4, function (Form\BlockForm $form) {
// $form->html(view('admin.form.phone'));
// });
$form->display('created_at');
$form->display('updated_at');
});
}
public function store()
{
$all = \request()->all();
dd($all);
try{
DB::transaction(function ()use ($all){
$vide_temp = VideoTemp::query()->create([
'title' => $all['title'],
'state' => 1,
]);
foreach ($all['components'] as $component) {
if ($component !== null){
Component::query()->create([
'temp_id' => $vide_temp->id,
'name' => $component,
'position' => $all['pos_' . $component]
]);
}
}
});
}catch (\Exception $exception){
return $this->form()->response()->error($exception->getMessage());
}
return $this->form()->response()->refresh()->success(trans('admin.save_succeeded'));
}
}