調整包廂Status 功能介面改維護 20250729

This commit is contained in:
allen.yan 2025-07-29 13:46:41 +08:00
parent eb465425f7
commit 04c9f016bf
17 changed files with 70 additions and 63 deletions

View File

@ -21,7 +21,7 @@ class CheckRoomOnlineStatus extends Command
$threshold = $now->subMinutes(10); $threshold = $now->subMinutes(10);
// 所有房間 // 所有房間
$rooms = Room::with('branch')->where('is_online',1)->get(); $rooms = Room::with('branch')->get();
foreach ($rooms as $room) { foreach ($rooms as $room) {
$branch = optional($room->branch); $branch = optional($room->branch);

View File

@ -8,7 +8,7 @@ use App\Enums\Traits\HasLabels;
* @OA\Schema( * @OA\Schema(
* schema="RoomStatus", * schema="RoomStatus",
* type="string", * type="string",
* enum={"active", "closed", "fire", "maintenance"}, * enum={"active", "closed", "fire", "maintain", "error"},
* example="error" * example="error"
* ) * )
*/ */
@ -18,6 +18,7 @@ enum RoomStatus: string {
case Active = 'active'; case Active = 'active';
case Closed = 'closed'; case Closed = 'closed';
case Fire ='fire'; case Fire ='fire';
case Maintain ='maintain';
case Error = 'error'; case Error = 'error';
// 返回對應的顯示文字 // 返回對應的顯示文字
@ -27,6 +28,7 @@ enum RoomStatus: string {
self::Active => __('enums.room.status.Active'), self::Active => __('enums.room.status.Active'),
self::Closed => __('enums.room.status.Closed'), self::Closed => __('enums.room.status.Closed'),
self::Fire => __('enums.room.status.Fire'), self::Fire => __('enums.room.status.Fire'),
self::Maintain => __('enums.room.status.Maintain'),
self::Error => __('enums.room.status.Error'), self::Error => __('enums.room.status.Error'),
}; };
} }

View File

@ -264,6 +264,7 @@ class RoomControlController extends Controller
$suffix = substr($room->name, -3) ?: $room->name; $suffix = substr($room->name, -3) ?: $room->name;
$signal = match ($validated['command']) { $signal = match ($validated['command']) {
'maintain' => 'O',
'active' => 'O', 'active' => 'O',
'closed' => 'X', 'closed' => 'X',
'fire' => 'F', 'fire' => 'F',

View File

@ -10,7 +10,7 @@ use Illuminate\Foundation\Http\FormRequest;
* required={"branch_name", "room_name", "command"}, * required={"branch_name", "room_name", "command"},
* @OA\Property(property="branch_name", type="string", example="測試"), * @OA\Property(property="branch_name", type="string", example="測試"),
* @OA\Property(property="room_name", type="string", example="pc102"), * @OA\Property(property="room_name", type="string", example="pc102"),
* @OA\Property(property="command", type="string", enum={"active", "closed", "fire", "maintenance"}, example="active"), * @OA\Property(property="command", type="string", enum={"active", "closed", "fire", "maintain"}, example="active"),
* @OA\Property(property="started_at", type="string", nullable=true, example="2025-05-19 09:31:00"), * @OA\Property(property="started_at", type="string", nullable=true, example="2025-05-19 09:31:00"),
* @OA\Property(property="ended_at", type="string", nullable=true, example="2025-05-19 09:31:00") * @OA\Property(property="ended_at", type="string", nullable=true, example="2025-05-19 09:31:00")
* ) * )
@ -27,7 +27,7 @@ class SendRoomSwitchCommandRequest extends ApiRequest
return [ return [
'branch_name' =>'required|string|exists:branches,name', 'branch_name' =>'required|string|exists:branches,name',
'room_name' => 'required|string', 'room_name' => 'required|string',
'command' => 'required|string', 'command' => 'required|in:active,closed,fire,maintain,error',
'started_at' => 'nullable|date_format:Y-m-d H:i:s', 'started_at' => 'nullable|date_format:Y-m-d H:i:s',
'ended_at' => 'nullable|date_format:Y-m-d H:i:s', 'ended_at' => 'nullable|date_format:Y-m-d H:i:s',
]; ];

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Livewire\Forms; namespace App\Livewire\Grids;
use App\Models\Room; use App\Models\Room;
use App\Models\Branch; use App\Models\Branch;
@ -11,7 +11,7 @@ use Illuminate\Database\Eloquent\Collection;
class RoomGridForm extends Component class RoomGrid extends Component
{ {
public $branchName=""; public $branchName="";
public array $roomTypes; public array $roomTypes;
@ -35,7 +35,7 @@ class RoomGridForm extends Component
$floors = $rooms->pluck('floor')->unique()->sort()->values()->toArray(); $floors = $rooms->pluck('floor')->unique()->sort()->values()->toArray();
} }
return view('livewire.forms.room-grid-form', [ return view('livewire.grids.room-grid', [
'rooms' => $rooms, 'rooms' => $rooms,
'floors' => $floors, 'floors' => $floors,
]); ]);

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Livewire\Forms\Modals; namespace App\Livewire\Modals;
use App\Models\Room; use App\Models\Room;
use App\Models\Branch; use App\Models\Branch;
@ -37,7 +37,7 @@ class RoomDetailModal extends Component
} }
public function startNotify() public function startNotify()
{ {
$data = $this->buildNotifyData('active', now(), null); $data = $this->buildNotifyData('maintain', null, null);
$this->send($data); $this->send($data);
} }
@ -86,7 +86,7 @@ class RoomDetailModal extends Component
$this->sendErrorNotification('api', 'API token is missing.'); $this->sendErrorNotification('api', 'API token is missing.');
return false; return false;
} }
$apiClient = new ApiClient($this->branch->external_ip,$token); $apiClient = new ApiClient(config('app.url'),$token);
$response = $apiClient->post('/api/room/sendSwitch', $data); $response = $apiClient->post('/api/room/sendSwitch', $data);
if ($response->failed()) { if ($response->failed()) {
$this->sendErrorNotification('api', 'API request failed: ' . $response->body()); $this->sendErrorNotification('api', 'API request failed: ' . $response->body());
@ -113,6 +113,6 @@ class RoomDetailModal extends Component
public function render() public function render()
{ {
return view('livewire.forms.modals.room-detail-modal'); return view('livewire.modals.room-detail-modal');
} }
} }

View File

@ -224,7 +224,7 @@ final class RoomTable extends PowerGridComponent
->slot('包廂設定') ->slot('包廂設定')
->icon('solid-cog') ->icon('solid-cog')
->class('inline-flex items-center gap-1 px-3 py-1 rounded ') ->class('inline-flex items-center gap-1 px-3 py-1 rounded ')
->dispatchTo('forms.modals.room-detail-modal', 'openModal', ['roomId' => $row->id]); ->dispatchTo('modals.room-detail-modal', 'openModal', ['roomId' => $row->id]);
} }
return $actions; return $actions;
} }

View File

@ -72,7 +72,10 @@ class ApiClient
protected function withDefaultHeaders(): PendingRequest protected function withDefaultHeaders(): PendingRequest
{ {
$request = Http::connectTimeout($this->connectTimeout) $request = Http::withOptions([
'verify' => false, // ✅ 關閉憑證驗證
])
->connectTimeout($this->connectTimeout)
->timeout($this->timeout) ->timeout($this->timeout)
->withHeaders([ ->withHeaders([
'Accept' => 'application/json', 'Accept' => 'application/json',
@ -95,7 +98,7 @@ class ApiClient
} }
public function requestWithCatch(callable $fn) public function requestWithCatch(callable $fn)
{ {
try { try {
return $fn(); return $fn();
} catch (RequestException $e) { } catch (RequestException $e) {
@ -132,7 +135,7 @@ class ApiClient
return ApiResponse::error('API 請求失敗: ' . $e->getMessage(), 'HTTP_CLIENT_ERROR',$status ?? 400); return ApiResponse::error('API 請求失敗: ' . $e->getMessage(), 'HTTP_CLIENT_ERROR',$status ?? 400);
} }
} }
public function get(string $endpoint, array $query = []) public function get(string $endpoint, array $query = [])
{ {

View File

@ -20,7 +20,7 @@ return new class extends Migration
$table->string('internal_ip')->nullable()->comment('內部 IP'); $table->string('internal_ip')->nullable()->comment('內部 IP');
$table->unsignedSmallInteger('port')->nullable()->comment('通訊 Port'); $table->unsignedSmallInteger('port')->nullable()->comment('通訊 Port');
$table->tinyInteger('is_online')->default(0)->comment('連線狀態'); $table->tinyInteger('is_online')->default(0)->comment('連線狀態');
$table->enum('status', ['active', 'closed','fire', 'error'])->default('error')->comment('狀態'); // :啟用中 / 已結束 $table->enum('status', ['active', 'closed','fire', 'error','maintain'])->default('error')->comment('狀態'); // :啟用中 / 已結束
$table->dateTime('started_at')->nullable()->comment('開始時間'); // $table->dateTime('started_at')->nullable()->comment('開始時間'); //
$table->dateTime('ended_at')->nullable()->comment('結束時間'); // $table->dateTime('ended_at')->nullable()->comment('結束時間'); //
$table->timestamps(); $table->timestamps();

View File

@ -15,7 +15,7 @@ return new class extends Migration
$table->id(); $table->id();
$table->foreignId('room_id')->nullable(); $table->foreignId('room_id')->nullable();
$table->foreignId('user_id')->nullable(); // 操作者,可為 null系統 $table->foreignId('user_id')->nullable(); // 操作者,可為 null系統
$table->enum('status', ['active', 'closed','fire', 'error', 'maintenance']); $table->enum('status', ['active', 'closed','fire', 'error', 'maintain']);
$table->text('message')->nullable(); // 可填異常原因或操作說明 $table->text('message')->nullable(); // 可填異常原因或操作說明
$table->timestamps(); $table->timestamps();
}); });

View File

@ -13,5 +13,6 @@ return [
'room.status.Active' => '已占用', 'room.status.Active' => '已占用',
'room.status.Closed' => '可用', 'room.status.Closed' => '可用',
'room.status.Fire' => '火災', 'room.status.Fire' => '火災',
'room.status.Error' => '維修', 'room.status.Maintain' => '維護',
'room.status.Error' => '異常',
]; ];

View File

@ -18,7 +18,7 @@ return [
'ended_at' =>'結束於', 'ended_at' =>'結束於',
'created_at' =>'建立於', 'created_at' =>'建立於',
'active' => '正常', 'active' => '正常',
'error' => '維修', 'error' => '關機',
'select_type' =>'選擇型別', 'select_type' =>'選擇型別',

View File

@ -3,12 +3,12 @@
$statusColors = [ $statusColors = [
RoomStatus::Active->value => 'green-600', RoomStatus::Active->value => 'green-600',
RoomStatus::Closed->value => 'gray-600', RoomStatus::Closed->value => 'gray-600',
RoomStatus::Error->value => 'red-600', RoomStatus::Maintain->value => 'red-600',
]; ];
@endphp @endphp
<div class="border p-2 rounded shadow-md h-32 relative cursor-pointer bg-amber-50" <div class="border p-2 rounded shadow-md h-32 relative cursor-pointer bg-amber-50"
wire:click="$dispatchTo('forms.modals.room-detail-modal','openModal', { roomId: {{ $room->id }} })"> wire:click="$dispatchTo('modals.room-detail-modal','openModal', { roomId: {{ $room->id }} })">
{{-- 房間名稱 + 線上狀態圓點 --}} {{-- 房間名稱 + 線上狀態圓點 --}}
<div class="font-bold flex items-center gap-1"> <div class="font-bold flex items-center gap-1">
<span class="w-2.5 h-2.5 rounded-full inline-block <span class="w-2.5 h-2.5 rounded-full inline-block

View File

@ -1,4 +1,4 @@
<x-layouts.admin> <x-layouts.admin>
<livewire:forms.room-grid-form /> <livewire:grids.room-grid />
</x-layouts.admin> </x-layouts.admin>

View File

@ -3,5 +3,5 @@
<x-wireui:notifications/> <x-wireui:notifications/>
<livewire:tables.room-table/> <livewire:tables.room-table/>
<livewire:forms.room-form /> <livewire:forms.room-form />
<livewire:forms.modals.room-detail-modal /> <livewire:modals.room-detail-modal />
</x-layouts.admin> </x-layouts.admin>

View File

@ -46,5 +46,5 @@
</div> </div>
</div> </div>
<x-wireui:notifications/> <x-wireui:notifications/>
<livewire:forms.modals.room-detail-modal /> <livewire:modals.room-detail-modal />
</x-wireui:card> </x-wireui:card>