更新 UI 一致性規範與公共事業費樣式
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-20 10:41:35 +08:00
parent 32c2612a5f
commit c1d302f03e
6 changed files with 233 additions and 84 deletions

View File

@@ -732,6 +732,51 @@ import { SearchableSelect } from "@/Components/ui/searchable-select";
--- ---
## 11.5 輸入框尺寸 (Input Sizes)
為確保介面整齊與統一,所有表單輸入元件標準高度應為 **`h-9`** (36px),與標準按鈕尺寸對齊。
- **Input**: 預設即為 `h-9` (由 `py-1``text-sm` 組合而成)
- **Select / SearchableSelect**: 必須確保 Trigger 按鈕高度為 `h-9`
- **禁止使用**: 除非有特殊設計需求,否則避免使用 `h-10` (40px) 或其他非標準高度。
## 11.6 日期輸入框樣式 (Date Input Style)
日期輸入框應採用「**左側裝飾圖示 + 右側原生操作**」的配置,以保持視覺一致性並保留瀏覽器原生便利性。
**樣式規格**
1. **容器**: 使用 `relative` 定位。
2. **圖標**: 使用 `Calendar` 圖標,放置於絕對位置 `absolute left-2.5 top-2.5`,顏色 `text-gray-400`,並設定 `pointer-events-none` 避免干擾點擊。
3. **輸入框**: 設定 `pl-9` (左內距) 以避開圖示,並使用原生 `type="date"``type="datetime-local"`
```tsx
import { Calendar } from "lucide-react";
import { Input } from "@/Components/ui/input";
<div className="relative">
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
className="pl-9 block w-full"
value={date}
onChange={(e) => setDate(e.target.value)}
/>
</div>
```
## 11.7 搜尋選單樣式 (SearchableSelect Style)
`SearchableSelect` 元件在表單或篩選列中使用時,高度必須設定為 `h-9` 以與輸入框對齊。
```tsx
<SearchableSelect
className="h-9" // 確保高度一致
// ...other props
/>
```
---
## 12. 檢查清單 ## 12. 檢查清單
在開發或審查頁面時,請確認以下項目: 在開發或審查頁面時,請確認以下項目:

View File

@@ -36,9 +36,14 @@ class UtilityFeeController extends Controller
} }
// Sorting // Sorting
$sortField = $request->input('sort_field', 'transaction_date'); $sortField = $request->input('sort_field');
$sortDirection = $request->input('sort_direction', 'desc'); $sortDirection = $request->input('sort_direction');
$query->orderBy($sortField, $sortDirection);
if ($sortField && $sortDirection) {
$query->orderBy($sortField, $sortDirection);
} else {
$query->orderBy('transaction_date', 'desc');
}
$fees = $query->paginate($request->input('per_page', 15))->withQueryString(); $fees = $query->paginate($request->input('per_page', 15))->withQueryString();

View File

@@ -14,6 +14,7 @@ import { Textarea } from "@/Components/ui/textarea";
import { SearchableSelect } from "@/Components/ui/searchable-select"; import { SearchableSelect } from "@/Components/ui/searchable-select";
import { useForm } from "@inertiajs/react"; import { useForm } from "@inertiajs/react";
import { toast } from "sonner"; import { toast } from "sonner";
import { Calendar } from "lucide-react";
export interface UtilityFee { export interface UtilityFee {
id: number; id: number;
@@ -65,7 +66,7 @@ export default function UtilityFeeDialog({
clearErrors(); clearErrors();
if (fee) { if (fee) {
setData({ setData({
transaction_date: fee.transaction_date, transaction_date: fee.transaction_date.split("T")[0].split(" ")[0],
category: fee.category, category: fee.category,
amount: fee.amount.toString(), amount: fee.amount.toString(),
invoice_number: fee.invoice_number || "", invoice_number: fee.invoice_number || "",
@@ -122,14 +123,17 @@ export default function UtilityFeeDialog({
<Label htmlFor="transaction_date"> <Label htmlFor="transaction_date">
<span className="text-red-500">*</span> <span className="text-red-500">*</span>
</Label> </Label>
<Input <div className="relative">
id="transaction_date" <Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
type="date" <Input
value={data.transaction_date} id="transaction_date"
onChange={(e) => setData("transaction_date", e.target.value)} type="date"
className={errors.transaction_date ? "border-red-500" : ""} value={data.transaction_date}
required onChange={(e) => setData("transaction_date", e.target.value)}
/> className={`pl-9 ${errors.transaction_date ? "border-red-500" : ""}`}
required
/>
</div>
{errors.transaction_date && <p className="text-sm text-red-500">{errors.transaction_date}</p>} {errors.transaction_date && <p className="text-sm text-red-500">{errors.transaction_date}</p>}
</div> </div>
@@ -172,9 +176,26 @@ export default function UtilityFeeDialog({
<Input <Input
id="invoice_number" id="invoice_number"
value={data.invoice_number} value={data.invoice_number}
onChange={(e) => setData("invoice_number", e.target.value)} onChange={(e) => {
placeholder="例AB12345678" let value = e.target.value.toUpperCase();
// Remove non-alphanumeric chars
const raw = value.replace(/[^A-Z0-9]/g, '');
// Auto-insert hyphen after 2 chars if we have length > 2
if (raw.length > 2) {
value = `${raw.slice(0, 2)}-${raw.slice(2)}`;
} else {
value = raw;
}
// Limit max length (2 letters + 8 digits + 1 hyphen = 11 chars)
if (value.length > 11) value = value.slice(0, 11);
setData("invoice_number", value);
}}
placeholder="例AB-12345678"
/> />
<p className="text-xs text-gray-500">AB-12345678 ()</p>
{errors.invoice_number && <p className="text-sm text-red-500">{errors.invoice_number}</p>} {errors.invoice_number && <p className="text-sm text-red-500">{errors.invoice_number}</p>}
</div> </div>

View File

@@ -10,7 +10,10 @@ import {
Trash2, Trash2,
FileText, FileText,
Calendar, Calendar,
Filter Filter,
ArrowUpDown,
ArrowUp,
ArrowDown
} from 'lucide-react'; } from 'lucide-react';
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout"; import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
import { Head, router } from "@inertiajs/react"; import { Head, router } from "@inertiajs/react";
@@ -23,6 +26,7 @@ import {
TableHeader, TableHeader,
TableRow, TableRow,
} from "@/Components/ui/table"; } from "@/Components/ui/table";
import { Badge } from "@/Components/ui/badge";
import { toast } from "sonner"; import { toast } from "sonner";
import UtilityFeeDialog, { UtilityFee } from "@/Components/UtilityFee/UtilityFeeDialog"; import UtilityFeeDialog, { UtilityFee } from "@/Components/UtilityFee/UtilityFeeDialog";
import { import {
@@ -35,6 +39,8 @@ import {
AlertDialogHeader, AlertDialogHeader,
AlertDialogTitle, AlertDialogTitle,
} from "@/Components/ui/alert-dialog"; } from "@/Components/ui/alert-dialog";
import { Can } from "@/Components/Permission/Can";
import { formatDateWithDayOfWeek, formatInvoiceNumber } from "@/utils/format";
interface PageProps { interface PageProps {
fees: { fees: {
@@ -53,8 +59,8 @@ interface PageProps {
category?: string; category?: string;
date_start?: string; date_start?: string;
date_end?: string; date_end?: string;
sort_field?: string; sort_field?: string | null;
sort_direction?: string; sort_direction?: "asc" | "desc" | null;
per_page?: string; per_page?: string;
}; };
} }
@@ -71,8 +77,8 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }:
const [deletingFeeId, setDeletingFeeId] = useState<number | null>(null); const [deletingFeeId, setDeletingFeeId] = useState<number | null>(null);
// Sorting // Sorting
const [sortField, setSortField] = useState(filters.sort_field || 'transaction_date'); const [sortField, setSortField] = useState<string | null>(filters.sort_field || 'transaction_date');
const [sortDirection, setSortDirection] = useState(filters.sort_direction || 'desc'); const [sortDirection, setSortDirection] = useState<"asc" | "desc" | null>(filters.sort_direction as "asc" | "desc" || 'desc');
const handleSearch = () => { const handleSearch = () => {
router.get( router.get(
@@ -98,9 +104,21 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }:
}; };
const handleSort = (field: string) => { const handleSort = (field: string) => {
const newDirection = sortField === field && sortDirection === 'asc' ? 'desc' : 'asc'; let newField: string | null = field;
setSortField(field); let newDirection: "asc" | "desc" | null = "asc";
if (sortField === field) {
if (sortDirection === "asc") {
newDirection = "desc";
} else {
newDirection = null;
newField = null;
}
}
setSortField(newField);
setSortDirection(newDirection); setSortDirection(newDirection);
router.get( router.get(
route("utility-fees.index"), route("utility-fees.index"),
{ {
@@ -108,7 +126,7 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }:
category: categoryFilter, category: categoryFilter,
date_start: dateStart, date_start: dateStart,
date_end: dateEnd, date_end: dateEnd,
sort_field: field, sort_field: newField,
sort_direction: newDirection, sort_direction: newDirection,
}, },
{ preserveState: true } { preserveState: true }
@@ -141,6 +159,19 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }:
} }
}; };
const SortIcon = ({ field }: { field: string }) => {
if (sortField !== field) {
return <ArrowUpDown className="h-4 w-4 text-muted-foreground ml-1" />;
}
if (sortDirection === "asc") {
return <ArrowUp className="h-4 w-4 text-primary ml-1" />;
}
if (sortDirection === "desc") {
return <ArrowDown className="h-4 w-4 text-primary ml-1" />;
}
return <ArrowUpDown className="h-4 w-4 text-muted-foreground ml-1" />;
};
return ( return (
<AuthenticatedLayout breadcrumbs={[{ label: "財務管理", href: "#" }, { label: "公共事業費", href: route("utility-fees.index") }]}> <AuthenticatedLayout breadcrumbs={[{ label: "財務管理", href: "#" }, { label: "公共事業費", href: route("utility-fees.index") }]}>
<Head title="公共事業費管理" /> <Head title="公共事業費管理" />
@@ -155,12 +186,14 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }:
<p className="text-gray-500 mt-1"></p> <p className="text-gray-500 mt-1"></p>
</div> </div>
<Button <Can permission="utility_fees.create">
onClick={openAddDialog} <Button
className="button-filled-primary gap-2" onClick={openAddDialog}
> className="button-filled-primary gap-2"
<Plus className="h-4 w-4" /> >
</Button> <Plus className="h-4 w-4" />
</Button>
</Can>
</div> </div>
{/* Toolbar */} {/* Toolbar */}
@@ -174,7 +207,7 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }:
value={searchTerm} value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)} onChange={(e) => setSearchTerm(e.target.value)}
onKeyDown={(e) => e.key === "Enter" && handleSearch()} onKeyDown={(e) => e.key === "Enter" && handleSearch()}
className="pl-10 h-10" className="pl-10"
/> />
{searchTerm && ( {searchTerm && (
<button <button
@@ -195,29 +228,28 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }:
...availableCategories.map(c => ({ label: c, value: c })) ...availableCategories.map(c => ({ label: c, value: c }))
]} ]}
placeholder="篩選類別" placeholder="篩選類別"
className="h-10"
/> />
{/* Date Range Start */} {/* Date Range Start */}
<div className="relative"> <div className="relative">
<Calendar className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4 pointer-events-none" /> <Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
<Input <Input
type="date" type="date"
value={dateStart} value={dateStart}
onChange={(e) => setDateStart(e.target.value)} onChange={(e) => setDateStart(e.target.value)}
className="pl-10 h-10" className="pl-9 bg-white block w-full"
placeholder="開始日期" placeholder="開始日期"
/> />
</div> </div>
{/* Date Range End */} {/* Date Range End */}
<div className="relative"> <div className="relative">
<Calendar className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4 pointer-events-none" /> <Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
<Input <Input
type="date" type="date"
value={dateEnd} value={dateEnd}
onChange={(e) => setDateEnd(e.target.value)} onChange={(e) => setDateEnd(e.target.value)}
className="pl-10 h-10" className="pl-9 bg-white block w-full"
placeholder="結束日期" placeholder="結束日期"
/> />
</div> </div>
@@ -243,82 +275,102 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }:
{/* Table */} {/* Table */}
<div className="bg-white rounded-lg shadow-sm border overflow-hidden"> <div className="bg-white rounded-lg shadow-sm border overflow-hidden">
<Table> <Table>
<TableHeader className="bg-gray-50 text-gray-600 font-bold uppercase tracking-wider text-xs"> <TableHeader>
<TableRow> <TableRow>
<TableHead <TableHead className="w-[50px] text-center">#</TableHead>
className="cursor-pointer hover:text-primary transition-colors py-4 px-4 text-center" <TableHead className="w-[120px]">
onClick={() => handleSort('transaction_date')} <button
> onClick={() => handleSort('transaction_date')}
{sortField === 'transaction_date' && (sortDirection === 'asc' ? '↑' : '↓')} className="flex items-center hover:text-gray-900"
>
<SortIcon field="transaction_date" />
</button>
</TableHead> </TableHead>
<TableHead <TableHead>
className="cursor-pointer hover:text-primary transition-colors py-4 px-4" <button
onClick={() => handleSort('category')} onClick={() => handleSort('category')}
> className="flex items-center hover:text-gray-900"
{sortField === 'category' && (sortDirection === 'asc' ? '↑' : '↓')} >
<SortIcon field="category" />
</button>
</TableHead> </TableHead>
<TableHead <TableHead className="text-right">
className="cursor-pointer hover:text-primary transition-colors py-4 px-4 text-right" <div className="flex justify-end">
onClick={() => handleSort('amount')} <button
> onClick={() => handleSort('amount')}
{sortField === 'amount' && (sortDirection === 'asc' ? '↑' : '↓')} className="flex items-center hover:text-gray-900"
>
<SortIcon field="amount" />
</button>
</div>
</TableHead> </TableHead>
<TableHead <TableHead>
className="cursor-pointer hover:text-primary transition-colors py-4 px-4" <button
onClick={() => handleSort('invoice_number')} onClick={() => handleSort('invoice_number')}
> className="flex items-center hover:text-gray-900"
{sortField === 'invoice_number' && (sortDirection === 'asc' ? '↑' : '↓')} >
<SortIcon field="invoice_number" />
</button>
</TableHead> </TableHead>
<TableHead className="py-4 px-4"> / </TableHead> <TableHead> / </TableHead>
<TableHead className="py-4 px-4 text-center w-[120px]"></TableHead> <TableHead className="text-center w-[120px]"></TableHead>
</TableRow> </TableRow>
</TableHeader> </TableHeader>
<TableBody> <TableBody>
{fees.data.length === 0 ? ( {fees.data.length === 0 ? (
<TableRow> <TableRow>
<TableCell colSpan={6} className="h-48 text-center text-gray-500"> <TableCell colSpan={7}>
<div className="flex flex-col items-center justify-center space-y-2"> <div className="flex flex-col items-center justify-center space-y-2 py-8">
<FileText className="h-8 w-8 text-gray-300" /> <FileText className="h-8 w-8 text-gray-300" />
<p></p> <p className="text-gray-500"></p>
</div> </div>
</TableCell> </TableCell>
</TableRow> </TableRow>
) : ( ) : (
fees.data.map((fee) => ( fees.data.map((fee, index) => (
<TableRow key={fee.id} className="hover:bg-gray-50/50 transition-colors"> <TableRow key={fee.id}>
<TableCell className="text-center font-medium">{fee.transaction_date}</TableCell> <TableCell className="text-gray-500 font-medium text-center">
{fees.from + index}
</TableCell>
<TableCell className="font-medium text-gray-700">
{formatDateWithDayOfWeek(fee.transaction_date)}
</TableCell>
<TableCell> <TableCell>
<span className="px-2.5 py-0.5 rounded-full text-xs font-semibold bg-primary/10 text-primary"> <Badge variant="outline">
{fee.category} {fee.category}
</span> </Badge>
</TableCell> </TableCell>
<TableCell className="text-right font-bold text-gray-900"> <TableCell className="text-right font-bold text-gray-900">
$ {Number(fee.amount).toLocaleString()} $ {Number(fee.amount).toLocaleString()}
</TableCell> </TableCell>
<TableCell className="font-mono text-sm text-gray-600"> <TableCell className="font-mono text-sm text-gray-600">
{fee.invoice_number || '-'} {formatInvoiceNumber(fee.invoice_number)}
</TableCell> </TableCell>
<TableCell className="max-w-xs truncate text-gray-600" title={fee.description}> <TableCell className="max-w-xs truncate text-gray-600" title={fee.description}>
{fee.description || '-'} {fee.description || '-'}
</TableCell> </TableCell>
<TableCell> <TableCell>
<div className="flex items-center justify-center gap-2"> <div className="flex items-center justify-center gap-2">
<Button <Can permission="utility_fees.edit">
variant="outline" <Button
size="sm" variant="outline"
className="button-outlined-primary h-8 w-8 p-0" size="sm"
onClick={() => openEditDialog(fee)} className="button-outlined-primary"
> onClick={() => openEditDialog(fee)}
<Pencil className="h-4 w-4" /> >
</Button> <Pencil className="h-4 w-4" />
<Button </Button>
variant="outline" </Can>
size="sm" <Can permission="utility_fees.delete">
className="button-outlined-error h-8 w-8 p-0" <Button
onClick={() => confirmDelete(fee.id)} variant="outline"
> size="sm"
<Trash2 className="h-4 w-4" /> className="button-outlined-error"
</Button> onClick={() => confirmDelete(fee.id)}
>
<Trash2 className="h-4 w-4" />
</Button>
</Can>
</div> </div>
</TableCell> </TableCell>
</TableRow> </TableRow>

View File

@@ -223,14 +223,14 @@ export default function AddInventoryPage({ warehouse, products }: Props) {
<span className="text-red-500">*</span> <span className="text-red-500">*</span>
</Label> </Label>
<div className="relative"> <div className="relative">
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400 pointer-events-none" />
<Input <Input
id="inbound-date" id="inbound-date"
type="datetime-local" type="datetime-local"
value={inboundDate} value={inboundDate}
onChange={(e) => setInboundDate(e.target.value)} onChange={(e) => setInboundDate(e.target.value)}
className="border-gray-300 pr-10" className="border-gray-300 pl-9"
/> />
<Calendar className="absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
</div> </div>
</div> </div>

View File

@@ -24,6 +24,32 @@ export const formatDate = (date: string): string => {
return new Date(date).toLocaleDateString("zh-TW"); return new Date(date).toLocaleDateString("zh-TW");
}; };
/**
* 格式化日期並包含星期
*/
export const formatDateWithDayOfWeek = (date: string): string => {
if (!date) return "-";
return new Date(date).toLocaleDateString("zh-TW", {
year: "numeric",
month: "2-digit",
day: "2-digit",
weekday: "short",
});
};
/**
* 格式化發票號碼
* 例如AB12345678 -> AB-12345678
*/
export const formatInvoiceNumber = (invoice: string | null | undefined): string => {
if (!invoice) return "-";
const cleanInvoice = invoice.replace(/-/g, "");
if (/^[a-zA-Z]{2}\d+$/.test(cleanInvoice)) {
return `${cleanInvoice.slice(0, 2).toUpperCase()}-${cleanInvoice.slice(2)}`;
}
return invoice;
};
/** /**
* 獲取當前日期YYYY-MM-DD 格式) * 獲取當前日期YYYY-MM-DD 格式)
*/ */