From ee985abb2e0915cadeed2d29b11906f27f7a7694 Mon Sep 17 00:00:00 2001 From: sky121113 Date: Wed, 15 Apr 2026 11:51:23 +0800 Subject: [PATCH] =?UTF-8?q?[STYLE]=20=E5=84=AA=E5=8C=96=E6=A9=9F=E5=8F=B0?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E9=A0=81=E9=9D=A2=E8=BC=89=E5=85=A5=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=88=87=20AJAX=20=E4=BA=92=E5=8B=95=E9=AB=94?= =?UTF-8?q?=E9=A9=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 新增全站頂部進度條觸發機制,在搜尋或分頁時提供視覺反饋。 2. 為機台設定頁面新增奢華風 Spinner 載入遮罩,替代原本抖動的骨架屏。 3. 優化分頁與搜尋的 AJAX 回傳邏輯,載入時降低背景透明度以維持版面穩定。 4. 新增多語系翻譯字串:Failed to load tab content。 --- .../MachineSettingController.php | 98 ++-- lang/en.json | 3 +- lang/ja.json | 3 +- lang/zh_TW.json | 3 +- .../basic-settings/machines/index.blade.php | 549 ++++++------------ .../machines/partials/tab-machines.blade.php | 166 ++++++ .../machines/partials/tab-models.blade.php | 115 ++++ .../partials/tab-permissions.blade.php | 130 +++++ 8 files changed, 648 insertions(+), 419 deletions(-) create mode 100644 resources/views/admin/basic-settings/machines/partials/tab-machines.blade.php create mode 100644 resources/views/admin/basic-settings/machines/partials/tab-models.blade.php create mode 100644 resources/views/admin/basic-settings/machines/partials/tab-permissions.blade.php diff --git a/app/Http/Controllers/Admin/BasicSettings/MachineSettingController.php b/app/Http/Controllers/Admin/BasicSettings/MachineSettingController.php index 8d20bf9..9d4f922 100644 --- a/app/Http/Controllers/Admin/BasicSettings/MachineSettingController.php +++ b/app/Http/Controllers/Admin/BasicSettings/MachineSettingController.php @@ -22,51 +22,83 @@ class MachineSettingController extends AdminController /** * 顯示機台與型號設定列表 (採用標籤頁整合) */ - public function index(Request $request): View + public function index(Request $request): View|\Illuminate\Http\Response { $tab = $request->input('tab', 'machines'); $per_page = $request->input('per_page', 10); $search = $request->input('search'); + $isAjax = $request->boolean('_ajax'); - // 1. 處理機台清單 (Machines Tab) - $machineQuery = Machine::query()->with(['machineModel', 'paymentConfig', 'company']); - if ($tab === 'machines' && $search) { - $machineQuery->where(function ($q) use ($search) { - $q->where('name', 'like', "%{$search}%") - ->orWhere('serial_no', 'like', "%{$search}%"); - }); - } - $machines = $machineQuery->latest()->paginate($per_page)->withQueryString(); + // AJAX 模式:只查當前 Tab 的搜尋/分頁結果 + if ($isAjax) { + $machines = null; + $models_list = null; + $users_list = null; - // 2. 處理型號清單 (Models Tab) - $modelQuery = MachineModel::query()->withCount('machines'); - if ($tab === 'models' && $search) { - $modelQuery->where('name', 'like', "%{$search}%"); - } - $models_list = $modelQuery->latest()->paginate($per_page)->withQueryString(); + switch ($tab) { + case 'machines': + $machineQuery = Machine::query()->with(['machineModel', 'paymentConfig', 'company']); + if ($search) { + $machineQuery->where(function ($q) use ($search) { + $q->where('name', 'like', "%{$search}%") + ->orWhere('serial_no', 'like', "%{$search}%"); + }); + } + $machines = $machineQuery->latest()->paginate($per_page)->withQueryString(); + break; - // 3. 處理機台權限 (Permissions Tab) - 僅顯示 is_admin 帳號 - $users_list = null; - if ($tab === 'permissions') { - $userQuery = \App\Models\System\User::query() - ->where('is_admin', true) - ->with(['company', 'machines']); - - if ($search) { - $userQuery->where(function($q) use ($search) { - $q->where('name', 'like', "%{$search}%") - ->orWhere('username', 'like', "%{$search}%"); - }); + case 'models': + $modelQuery = MachineModel::query()->withCount('machines'); + if ($search) { + $modelQuery->where('name', 'like', "%{$search}%"); + } + $models_list = $modelQuery->latest()->paginate($per_page)->withQueryString(); + break; + + case 'permissions': + $userQuery = \App\Models\System\User::query() + ->where('is_admin', true) + ->with(['company', 'machines']); + if ($search) { + $userQuery->where(function($q) use ($search) { + $q->where('name', 'like', "%{$search}%") + ->orWhere('username', 'like', "%{$search}%"); + }); + } + if ($request->filled('company_id')) { + $userQuery->where('company_id', $request->company_id); + } + $users_list = $userQuery->latest()->paginate($per_page)->withQueryString(); + break; } - if ($request->filled('company_id')) { - $userQuery->where('company_id', $request->company_id); - } + $companies = \App\Models\System\Company::select('id', 'name', 'code')->get(); - $users_list = $userQuery->latest()->paginate($per_page)->withQueryString(); + $tabView = match($tab) { + 'models' => 'admin.basic-settings.machines.partials.tab-models', + 'permissions' => 'admin.basic-settings.machines.partials.tab-permissions', + default => 'admin.basic-settings.machines.partials.tab-machines', + }; + return response()->view($tabView, compact( + 'machines', 'models_list', 'users_list', 'companies', 'tab' + )); } - // 4. 基礎下拉資料 (用於新增/編輯機台的彈窗) + // SSR 模式:一次查好全部三個 Tab 的首頁資料(供 x-show 即時切換) + $machines = Machine::query() + ->with(['machineModel', 'paymentConfig', 'company']) + ->latest()->paginate($per_page)->withQueryString(); + + $models_list = MachineModel::query() + ->withCount('machines') + ->latest()->paginate($per_page)->withQueryString(); + + $userQuery = \App\Models\System\User::query() + ->where('is_admin', true) + ->with(['company', 'machines']); + $users_list = $userQuery->latest()->paginate($per_page)->withQueryString(); + + // 基礎下拉資料 (用於新增/編輯機台的彈窗) $models = MachineModel::select('id', 'name')->get(); $paymentConfigs = PaymentConfig::select('id', 'name')->get(); $companies = \App\Models\System\Company::select('id', 'name', 'code')->get(); diff --git a/lang/en.json b/lang/en.json index b8ff430..b7dc3be 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1153,5 +1153,6 @@ "Waiting": "Waiting", "Publish Time": "Publish Time", "Expired Time": "Expired Time", - "Inventory synced with machine": "Inventory synced with machine" + "Inventory synced with machine": "Inventory synced with machine", + "Failed to load tab content": "Failed to load tab content" } \ No newline at end of file diff --git a/lang/ja.json b/lang/ja.json index b449490..3831844 100644 --- a/lang/ja.json +++ b/lang/ja.json @@ -1152,5 +1152,6 @@ "Waiting": "待機中", "Publish Time": "公開時間", "Expired Time": "終了時間", - "Inventory synced with machine": "在庫が機体と同期されました" + "Inventory synced with machine": "在庫が機体と同期されました", + "Failed to load tab content": "タブコンテンツの読み込みに失敗しました" } \ No newline at end of file diff --git a/lang/zh_TW.json b/lang/zh_TW.json index a0a0518..fbced3a 100644 --- a/lang/zh_TW.json +++ b/lang/zh_TW.json @@ -1158,5 +1158,6 @@ "Waiting": "等待中", "Publish Time": "發布時間", "Expired Time": "下架時間", - "Inventory synced with machine": "庫存已與機台同步" + "Inventory synced with machine": "庫存已與機台同步", + "Failed to load tab content": "載入分頁內容失敗" } \ No newline at end of file diff --git a/resources/views/admin/basic-settings/machines/index.blade.php b/resources/views/admin/basic-settings/machines/index.blade.php index 5bd1ef3..72b1cde 100644 --- a/resources/views/admin/basic-settings/machines/index.blade.php +++ b/resources/views/admin/basic-settings/machines/index.blade.php @@ -3,6 +3,11 @@ @section('content')
@@ -197,417 +311,86 @@

{{ __('Management of operational parameters and models') }}

- @if($tab === 'machines') - - @elseif($tab === 'models') - - @endif
- + + +
-
- -
-
-
- - - - - - - - -
- - @if($tab === 'permissions' && auth()->user()->isSystemAdmin()) -
-
- - - - +
+ +
+
+
+
+
+ + +
- @endif
+

{{ __('Loading Data') }}...

- @if($tab === 'machines') - -
- - - - - - - - - - - - - @forelse($machines as $machine) - - - - - - - - - @empty - - - - @endforelse - -
- {{ __('Machine Info') }} - {{ __('Machine Model') }} - {{ __('Status') }} - {{ __('Card Reader') }} - {{ __('Owner') }} - {{ __('Action') }}
-
-
- @if(isset($machine->image_urls[0])) - - @else - - - - @endif -
-
-
- {{ $machine->name }}
-
- {{ - $machine->serial_no }} -
-
-
-
- - {{ $machine->machineModel->name ?? '--' }} - - - @php - $isOnline = $machine->last_heartbeat_at && $machine->last_heartbeat_at->diffInSeconds() < 30; - @endphp
-
- @if($isOnline) - - - @else - - @endif -
- - {{ $isOnline ? __('Online') : __('Offline') }} - -
-
-
- {{ $machine->card_reader_seconds ?? 0 }}s / No.{{ - $machine->card_reader_no ?? '--' }} +
+ +
+
+ @include('admin.basic-settings.machines.partials.tab-machines') +
-
- - {{ $machine->company->name ?? __('System') }} - - - - - - - - - - -
- {{ __('No data available') }} -
-
-
- {{ $machines->appends(['tab' => 'machines'])->links('vendor.pagination.luxury') }} -
- @elseif($tab === 'permissions') - -
- - - - - - - - - - - @forelse($users_list as $user) - - - - - - - @empty - - - - @endforelse - -
- {{ __('Account Info') }} - {{ __('Company Name') }} - {{ __('Authorized Machines') }} - {{ __('Action') }}
-
-
- - - -
-
- {{ - $user->name }} - {{ - $user->username }} -
-
-
- - {{ $user->company->name ?? __('System') }} - - -
- @forelse($user->machines as $m) -
- {{ - $m->name }} - {{ - $m->serial_no }} -
- @empty -
- -- - {{ __('None') }} -- -
- @endforelse -
-
- -
-
- - - -

{{ __('No accounts found') }}

-
-
-
-
- @if($users_list) - {{ $users_list->appends(['tab' => 'permissions'])->links('vendor.pagination.luxury') }} - @endif -
+ +
+
+ @include('admin.basic-settings.machines.partials.tab-models') +
+
- @else - -
- - - - - - - - - - - @forelse($models_list as $model) - - - - - - - @empty - - - - @endforelse - -
- {{ __('Model Name') }} - {{ __('Machine Count') }} - {{ __('Last Updated') }} - {{ __('Action') }}
-
-
- - - -
-
- {{ $model->name }}
-
-
- - {{ $model->machines_count ?? 0 }} {{ __('Items') }} - - -
- {{ $model->updated_at->format('Y/m/d H:i') }} -
-
-
- - -
- @csrf - @method('DELETE') - -
-
-
- {{ __('No data available') }} -
+ +
+
+ @include('admin.basic-settings.machines.partials.tab-permissions') +
+
+
-
- {{ $models_list->appends(['tab' => 'models'])->links('vendor.pagination.luxury') }} -
- @endif -
diff --git a/resources/views/admin/basic-settings/machines/partials/tab-machines.blade.php b/resources/views/admin/basic-settings/machines/partials/tab-machines.blade.php new file mode 100644 index 0000000..7587b19 --- /dev/null +++ b/resources/views/admin/basic-settings/machines/partials/tab-machines.blade.php @@ -0,0 +1,166 @@ +{{-- Machines Tab Content (Partial) --}} +{{-- 此檔案被 index.blade.php 的 @include 和 AJAX 模式共用 --}} + +{{-- Toolbar 區:搜尋框 --}} +
+
+
+ + + + + + + +
+
+
+ +{{-- Machine Table --}} +
+ + + + + + + + + + + + + @forelse($machines as $machine) + + + + + + + + + @empty + + + + @endforelse + +
+ {{ __('Machine Info') }} + {{ __('Machine Model') }} + {{ __('Status') }} + {{ __('Card Reader') }} + {{ __('Owner') }} + {{ __('Action') }}
+
+
+ @if(isset($machine->image_urls[0])) + + @else + + + + @endif +
+
+
+ {{ $machine->name }}
+
+ {{ + $machine->serial_no }} +
+
+
+
+ + {{ $machine->machineModel->name ?? '--' }} + + + @php + $isOnline = $machine->last_heartbeat_at && $machine->last_heartbeat_at->diffInSeconds() < 30; + @endphp
+
+ @if($isOnline) + + + @else + + @endif +
+ + {{ $isOnline ? __('Online') : __('Offline') }} + +
+
+
+ {{ $machine->card_reader_seconds ?? 0 }}s / No.{{ + $machine->card_reader_no ?? '--' }} +
+
+ + {{ $machine->company->name ?? __('System') }} + + + + + + + + + + +
+ {{ __('No data available') }} +
+
+
+ {{ $machines->appends(['tab' => 'machines'])->links('vendor.pagination.luxury') }} +
diff --git a/resources/views/admin/basic-settings/machines/partials/tab-models.blade.php b/resources/views/admin/basic-settings/machines/partials/tab-models.blade.php new file mode 100644 index 0000000..efc47b8 --- /dev/null +++ b/resources/views/admin/basic-settings/machines/partials/tab-models.blade.php @@ -0,0 +1,115 @@ +{{-- Models Tab Content (Partial) --}} +{{-- 此檔案被 index.blade.php 的 @include 和 AJAX 模式共用 --}} + +{{-- Toolbar 區:搜尋框 --}} +
+
+
+ + + + + + + +
+
+
+ +{{-- Model Table --}} +
+ + + + + + + + + + + @forelse($models_list as $model) + + + + + + + @empty + + + + @endforelse + +
+ {{ __('Model Name') }} + {{ __('Machine Count') }} + {{ __('Last Updated') }} + {{ __('Action') }}
+
+
+ + + +
+
+ {{ $model->name }}
+
+
+ + {{ $model->machines_count ?? 0 }} {{ __('Items') }} + + +
+ {{ $model->updated_at->format('Y/m/d H:i') }} +
+
+
+ + +
+ @csrf + @method('DELETE') + +
+
+
+ {{ __('No data available') }} +
+
+
+ {{ $models_list->appends(['tab' => 'models'])->links('vendor.pagination.luxury') }} +
diff --git a/resources/views/admin/basic-settings/machines/partials/tab-permissions.blade.php b/resources/views/admin/basic-settings/machines/partials/tab-permissions.blade.php new file mode 100644 index 0000000..0899913 --- /dev/null +++ b/resources/views/admin/basic-settings/machines/partials/tab-permissions.blade.php @@ -0,0 +1,130 @@ +{{-- Permissions Tab Content (Partial) --}} +{{-- 此檔案被 index.blade.php 的 @include 和 AJAX 模式共用 --}} + +{{-- Toolbar 區:搜尋框 + 公司篩選 --}} +
+
+
+ + + + + + + +
+ + @if(auth()->user()->isSystemAdmin()) +
+ +
+ @endif +
+
+ +{{-- Permissions Table --}} +
+ + + + + + + + + + + @forelse($users_list ?? [] as $user) + + + + + + + @empty + + + + @endforelse + +
+ {{ __('Account Info') }} + {{ __('Company Name') }} + {{ __('Authorized Machines') }} + {{ __('Action') }}
+
+
+ + + +
+
+ {{ + $user->name }} + {{ + $user->username }} +
+
+
+ + {{ $user->company->name ?? __('System') }} + + +
+ @forelse($user->machines as $m) +
+ {{ + $m->name }} + {{ + $m->serial_no }} +
+ @empty +
+ -- + {{ __('None') }} -- +
+ @endforelse +
+
+ +
+
+ + + +

{{ __('No accounts found') }}

+
+
+
+
+ @if($users_list) + {{ $users_list->appends(['tab' => 'permissions'])->links('vendor.pagination.luxury') }} + @endif +