feat: 新增租戶品牌客製化系統(Logo、主色系)、修正 hardcoded 顏色為 CSS 變數
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 47s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped

This commit is contained in:
2026-01-16 14:36:24 +08:00
parent a2c99e3a36
commit 55272d5d43
36 changed files with 568 additions and 70 deletions

View File

@@ -92,6 +92,26 @@ class TenantController extends Controller
]);
}
/**
* 顯示租戶樣式管理頁面
*/
public function showBranding(Tenant $tenant)
{
$logoUrl = null;
if (isset($tenant->branding['logo_path'])) {
$logoUrl = \Storage::url($tenant->branding['logo_path']);
}
return Inertia::render('Landlord/Tenant/Branding', [
'tenant' => [
'id' => $tenant->id,
'name' => $tenant->name ?? $tenant->id,
'branding' => $tenant->branding ?? [],
],
'logo_url' => $logoUrl,
]);
}
/**
* 顯示編輯租戶表單
*/
@@ -171,4 +191,44 @@ class TenantController extends Controller
return back()->with('success', "域名 {$domainName} 已移除!");
}
/**
* 更新租戶品牌樣式設定
*/
public function updateBranding(Request $request, Tenant $tenant)
{
$validated = $request->validate([
'logo' => 'nullable|image|max:2048',
'primary_color' => 'required|regex:/^#[0-9A-Fa-f]{6}$/',
'text_color' => 'nullable|regex:/^#[0-9A-Fa-f]{6}$/',
]);
$branding = $tenant->branding ?? [];
// 處理 Logo 上傳
if ($request->hasFile('logo')) {
// 刪除舊 Logo
if (isset($branding['logo_path'])) {
\Storage::disk('public')->delete($branding['logo_path']);
}
// 儲存新 Logo
$path = $request->file('logo')->store('tenant-logos', 'public');
$branding['logo_path'] = $path;
}
// 更新主色系
$branding['primary_color'] = $validated['primary_color'];
// 如果有傳入字體顏色則更新,否則保留原值(或預設值)
if (isset($validated['text_color'])) {
$branding['text_color'] = $validated['text_color'];
} elseif (!isset($branding['text_color'])) {
$branding['text_color'] = '#1a1a1a';
}
$tenant->update(['branding' => $branding]);
return redirect()->back()->with('success', '樣式設定已更新');
}
}

View File

@@ -55,6 +55,23 @@ class HandleInertiaRequests extends Middleware
'success' => $request->session()->get('success'),
'error' => $request->session()->get('error'),
],
'branding' => function () {
$tenant = tenancy()->tenant;
if (!$tenant) {
return null;
}
$logoUrl = null;
if (isset($tenant->branding['logo_path'])) {
$logoUrl = \Storage::url($tenant->branding['logo_path']);
}
return [
'logo_url' => $logoUrl,
'primary_color' => $tenant->branding['primary_color'] ?? '#01ab83',
'text_color' => $tenant->branding['text_color'] ?? '#1a1a1a',
];
},
];
}
}