组件抽象

This commit is contained in:
Jerry Yan 2022-07-30 11:20:13 +08:00
parent 0d238c29af
commit b9a46390e0
9 changed files with 206 additions and 123 deletions

View File

@ -0,0 +1,34 @@
<?php
namespace App\View\Components;
use App\Models\ProgramAppends;
use Illuminate\View\Component;
class Append extends Component
{
/**
* @var ProgramAppends
*/
public $append;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct(ProgramAppends $append)
{
$this->append = $append;
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.append');
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace App\View\Components\Links;
use Illuminate\View\Component;
class UserLink extends Component
{
/**
* @var int|null
*/
public $plt_id;
/**
* @var string|null
*/
public $mid;
/**
* @var string
*/
public $name;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct(string $name, $pltId, $mid)
{
$this->plt_id = $pltId;
$this->mid = $mid;
$this->name = $name;
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.links.user_link');
}
}

View File

@ -0,0 +1,57 @@
<?php
namespace App\View\Components\Links;
use Carbon\Exceptions\InvalidFormatException;
use Illuminate\Support\Carbon;
use Illuminate\View\Component;
class VideoLink extends Component
{
/**
* @var string
*/
public $bvid;
/**
* @var int|string
*/
public $part;
/**
* @var string|null
*/
public $time;
/**
* @var int|string|null
*/
public $sec;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct(string $bvid, $part = 1, $time = null, $sec=null)
{
$this->bvid = $bvid;
$this->part = $part;
if ($sec == null) {
try {
$sec = Carbon::createFromFormat("H:i:s", $time)->secondsSinceMidnight();
} catch (InvalidFormatException $ex) {
$time = null;
}
}
$this->time = $time;
$this->sec = $sec;
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.links.video_link');
}
}

View File

@ -0,0 +1,19 @@
@if($append->is_original)
<div>
<x-links.user_link :name="$append->from" :plt-id="$append->platform_id" :mid="$append->from_mid"></x-links.user_link>
老板点播
<span title="一分10块">{{$append->price}}</span>
@if($append->append)
<span>{{$append->append}}</span>
@endif
</div>
@else
<div class="my-2">
<x-links.user_link :name="$append->from" :plt-id="$append->platform_id" :mid="$append->from_mid"></x-links.user_link>
老板追加@if($append->broadcast!=0)常驻留言@endif{{$append->name}}
<span title="一分10块">{{$append->price}}</span>
@if($append->append)
<span>{{$append->append}}</span>
@endif
</div>
@endif

View File

@ -0,0 +1,27 @@
<span>
@switch($plt_id)
@case(1)
<img class="w-4 h-4 inline-block" src="https://cdn.jerryyan.net/luboimg/bilibili.ico" alt="B站">
@isset($mid)
<a class="underline" href="https://space.bilibili.com/{{$mid}}" target="_blank">{{$name}}</a>
@else
{{$name}}
@endisset
@break
@case(2)
<img class="w-4 h-4 inline-block" src="https://cdn.jerryyan.net/luboimg/ixigua.ico" alt="西瓜视频">
@isset($mid)
<a class="underline" href="https://www.ixigua.com/home/{{$mid}}/" target="_blank">{{$name}}</a>
@else
{{$name}}
@endisset
@break
@case(3)
<img class="w-4 h-4 inline-block" src="https://cdn.jerryyan.net/luboimg/douyin.ico" alt="抖音">
{{$name}}
@break
@default
{{$name}}
@break
@endswitch
</span>

View File

@ -0,0 +1,7 @@
<a class="block"
target="_blank"
href="https://www.bilibili.com/video/{{$bvid}}?p={{$part}}@if($time)&t={{$sec}}@endif"
title="P{{$part}}@if($time)#{{$time}}@endif"
>
{{ $slot }}
</a>

View File

@ -28,23 +28,7 @@
@foreach($danmakus as $danmaku)
<tr>
<td class="border">
@switch($danmaku->platform_id)
@case(1)
<img class="w-4 h-4 inline-block" src="https://cdn.jerryyan.net/luboimg/bilibili.ico" alt="B站">
<a class="underline" href="https://space.bilibili.com/{{$danmaku->from_mid}}" target="_blank">{{$danmaku->from}}</a>
@break
@case(2)
<img class="w-4 h-4 inline-block" src="https://cdn.jerryyan.net/luboimg/ixigua.ico" alt="西瓜视频">
<a class="underline" href="https://www.ixigua.com/home/{{$danmaku->from_mid}}/" target="_blank">{{$danmaku->from}}</a>
@break
@case(3)
<img class="w-4 h-4 inline-block" src="https://cdn.jerryyan.net/luboimg/douyin.ico" alt="抖音">
{{$danmaku->from}}
@break
@default
{{$danmaku->from}}
@break
@endswitch
<x-links.user_link :name="$danmaku->from" :plt-id="$danmaku->platform_id" :mid="$danmaku->from_mid"></x-links.user_link>
</td>
<td class="border">{{$danmaku->content}}</td>
<td class="border text-sm">{{$danmaku->created_at}}</td>

View File

@ -22,63 +22,36 @@
<td>
<a href="{{route("program.construct.edit", ["program"=>$program->id])}}">编辑</a>
<span title="节目">{{$program->name}}</span>
<span title="难度">{{$program->difficulty}}</span>
<span title="要求">{{$program->desc}}</span>
</td>
<td>
@foreach($program->appends as $append)
@if($append->is_original)
<div>
@if($append->from_mid)
<a target="_blank"
href="https://space.bilibili.com/{{$append->from_mid}}">{{$append->from}}</a>
@else
{{$append->from}}
@endif
老板点播
<span title="一分10块">{{$append->price}}</span>
@if($append->append)
<span>{{$append->append}}</span>
@endif
</div>
@else
<div>
@if($append->from_mid)
<a target="_blank"
href="https://space.bilibili.com/{{$append->from_mid}}">{{$append->from}}</a>
@else
{{$append->from}}
@endif
老板追加:{{$append->name}}
<span title="一分10块">{{$append->price}}</span>
@if($append->append)
<span>{{$append->append}}</span>
@endif
</div>
@endif
<x-append :append="$append"></x-append>
@endforeach
</td>
<td>
@foreach($program->video_pivots as $video_pivot)
<a
target="_blank"
href="https://www.bilibili.com/video/{{$video_pivot->video_bvid}}?p={{$video_pivot->start_part}}&t={{$video_pivot->start_sec}}"
title="P{{$video_pivot->start_part}}#{{$video_pivot->start_time}}"
>
<x-links.video_link :bvid="$video_pivot->video_bvid" :part="$video_pivot->start_part" :time="$video_pivot->start_time">
<div>{{$video_pivot->created_at}} P{{$video_pivot->start_part}}#{{$video_pivot->start_time}}</div>
@if($video_pivot->start_image)
<img width="300" src="{{$video_pivot->start_image}}" alt="开始时的画面">
@else
节目开始位置
@endif
</a>
</x-links.video_link>
@endforeach
</td>
<td>
@foreach($program->video_pivots as $video_pivot)
@if($video_pivot->stop_image)
<img width="300" src="{{$video_pivot->stop_image}}" alt="结束时的画面">
@else
<div>暂无</div>
@endif
<x-links.video_link :bvid="$video_pivot->video_bvid" :part="$video_pivot->stop_part" :time="$video_pivot->stop_time">
<div>P{{$video_pivot->stop_part}}#{{$video_pivot->stop_time}}</div>
@if($video_pivot->start_image)
<img width="300" src="{{$video_pivot->stop_image}}" alt="结束时的画面">
@else
节目结束位置
@endif
</x-links.video_link>
@endforeach
</td>
</tr>

View File

@ -34,92 +34,31 @@
</td>
<td class="border align-top">
@foreach($program->appends as $append)
@if($append->is_original)
<div>
@switch($append->platform_id)
@case(1)
<img class="w-4 h-4 inline-block" src="https://cdn.jerryyan.net/luboimg/bilibili.ico" alt="B站">
<a class="underline" href="https://space.bilibili.com/{{$append->from_mid}}" target="_blank">{{$append->from}}</a>
@break
@case(2)
<img class="w-4 h-4 inline-block" src="https://cdn.jerryyan.net/luboimg/ixigua.ico" alt="西瓜视频">
<a class="underline" href="https://www.ixigua.com/home/{{$append->from_mid}}/" target="_blank">{{$append->from}}</a>
@break
@case(3)
<img class="w-4 h-4 inline-block" src="https://cdn.jerryyan.net/luboimg/douyin.ico" alt="抖音">
{{$append->from}}
@break
@default
{{$append->from}}
@break
@endswitch
老板点播
<span title="一分10块">{{$append->price}}</span>
@if($append->append)
<span>{{$append->append}}</span>
@endif
</div>
@else
<div class="my-2">
@switch($append->platform_id)
@case(1)
<img class="w-4 h-4 inline-block" src="https://cdn.jerryyan.net/luboimg/bilibili.ico" alt="B站">
<a class="underline" href="https://space.bilibili.com/{{$append->from_mid}}" target="_blank">{{$append->from}}</a>
@break
@case(2)
<img class="w-4 h-4 inline-block" src="https://cdn.jerryyan.net/luboimg/ixigua.ico" alt="西瓜视频">
<a class="underline" href="https://www.ixigua.com/home/{{$append->from_mid}}/" target="_blank">{{$append->from}}</a>
@break
@case(3)
<img class="w-4 h-4 inline-block" src="https://cdn.jerryyan.net/luboimg/douyin.ico" alt="抖音">
{{$append->from}}
@break
@default
{{$append->from}}
@break
@endswitch
老板追加:{{$append->name}}
<span title="一分10块">{{$append->price}}</span>
@if($append->append)
<span>{{$append->append}}</span>
@endif
</div>
@endif
<x-append :append="$append"></x-append>
@endforeach
@if(sizeof($program->appends) === 0)
<a href="{{route('program.construct.append.list', ['program'=>$program->id])}}">去建设</a>
@endif
</td>
<td class="border align-top hidden lg:table-cell">
@foreach($program->video_pivots as $video_pivot)
<a class="block"
target="_blank"
href="https://www.bilibili.com/video/{{$video_pivot->video_bvid}}?p={{$video_pivot->start_part}}&t={{$video_pivot->start_sec}}"
title="P{{$video_pivot->start_part}}#{{$video_pivot->start_time}}"
>
<x-links.video_link :bvid="$video_pivot->video_bvid" :part="$video_pivot->start_part" :time="$video_pivot->start_time">
<div>{{$video_pivot->created_at}} P{{$video_pivot->start_part}}#{{$video_pivot->start_time}}</div>
@if($video_pivot->start_image)
<img width="300" src="{{$video_pivot->start_image}}" alt="开始时的画面">
@else
节目开始位置
@endif
</a>
</x-links.video_link>
@endforeach
</td>
<td class="border align-top hidden lg:table-cell">
@foreach($program->video_pivots as $video_pivot)
<a class="block"
target="_blank"
href="https://www.bilibili.com/video/{{$video_pivot->video_bvid}}?p={{$video_pivot->stop_part}}&t={{$video_pivot->stop_sec}}"
title="P{{$video_pivot->stop_part}}#{{$video_pivot->stop_time}}"
>
<x-links.video_link :bvid="$video_pivot->video_bvid" :part="$video_pivot->stop_part" :time="$video_pivot->stop_time">
<div>P{{$video_pivot->stop_part}}#{{$video_pivot->stop_time}}</div>
@if($video_pivot->start_image)
<img width="300" src="{{$video_pivot->stop_image}}" alt="结束时的画面">
@else
节目结束位置
@endif
</a>
</x-links.video_link>
@endforeach
</td>
</tr>