VideoTempController.php
5.98 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
<?php
namespace App\Admin\Controllers;
use App\Admin\Renderable\FontTable;
use App\Models\Font;
use App\Models\VideoTemp;
use App\Models\Component;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Widgets\Table;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
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('bg_music')->bool();
$grid->column('bgm_url')->display(function ($url){
if ($this->bg_music == 0)
return '暂无';
elseif (Str::of($url)->contains('.mp3'))
return "<a target='_blank' href='". $url ."'>查看</a>";
else
return "<a target='_blank' href='". $url ."'>下载后查看</a>";
});
$grid->column('','组件信息')
->display('展开')
->expand(function (){
$th = ['id','模板id','名称','位置','字号','文字颜色','文字效果','fade时间','背景色','透明度','背景厚度'];
return Table::make($th, $this->componentsTable->toArray())->withBorder();
});
$grid->column('state')->switch();
$grid->column('created_at');
$grid->column('updated_at')->sortable();
});
}
/**
* 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 form()
{
return Form::make(VideoTemp::with('components'), function (Form $form) {
$form->display('id');
$form->block(7, function (Form\BlockForm $form) {
// 设置标题
$form->title('基本设置');
// 显示底部提交按钮
$form->showFooter();
// 设置字段宽度
$form->width(8, 3);
$form->text('title');
$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->hasMany('components','组件', function (Form\NestedForm $form) {
$form->select('name','组件名称')->options([
'one_poem_with_annotate' => '一言带注解组件',
'one_poem' => '一言组件',
'weather' => '天气组件',
'date' => '日期组件',
'feel' => '临境有感组件',
]);
$form->select('position','组件位置')->options(VideoTemp::POSITION_OPTIONS)->addElementClass('position');
$form->selectTable('font_file','字体')
->title('字体选择')
->from(FontTable::make())
->model(Font::class,'file','name');
$form->number('font_size', '字号')->default(24)->min(12);
$form->color('text_color', '字体颜色')->default('#f5f5f5')->addElementClass('text_color');
$form->radio('draw', '文字效果')
->options(['fade'=>'淡入淡出', 'fix'=>'固定显示'])->default('fade')
->when('fade',function (Form\NestedForm $form){
$form->number('fade_time', 'fade时间')->default(1500);
})
->when('fix',function (Form\NestedForm $form){
$form->color('text_bg_color', '背景色')->default('#5c6bc6')->addElementClass('text_bg_color');
$form->number('opacity', '透明度')->min(0)->max(100)
->addElementClass('opacity')->default(100)
->help('范围为0-100,100表示不透明,0表示完全透明');
$form->number('text_bg_box', '背景厚度')->default(0)
->addElementClass('text_bg_box')->help('设置背景块边缘厚度(用于在背景块边缘用背景色填充一圈),默认为0');
});
});
$form->hidden('state')->default(1)
->saving(function ($v) {
return $v;
});
});
$form->block(5, function (Form\BlockForm $form) {
$form->html(view('admin.form.phone'));
});
$form->display('created_at');
$form->display('updated_at');
});
}
}