first commit
This commit is contained in:
11
source-code/ERP(A-b)-倉庫管理/README.md
Normal file
11
source-code/ERP(A-b)-倉庫管理/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
# ERP(A-b)-倉庫管理
|
||||
|
||||
This is a code bundle for ERP(A-b)-倉庫管理. The original project is available at https://www.figma.com/design/ia7MO4y26gKo4vQmK4bO8C/ERP-A-b--%E5%80%89%E5%BA%AB%E7%AE%A1%E7%90%86.
|
||||
|
||||
## Running the code
|
||||
|
||||
Run `npm i` to install the dependencies.
|
||||
|
||||
Run `npm run dev` to start the development server.
|
||||
|
||||
BIN
source-code/ERP(A-b)-倉庫管理/README.md:Zone.Identifier
Normal file
BIN
source-code/ERP(A-b)-倉庫管理/README.md:Zone.Identifier
Normal file
Binary file not shown.
15
source-code/ERP(A-b)-倉庫管理/index.html
Normal file
15
source-code/ERP(A-b)-倉庫管理/index.html
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>ERP(A-b)-倉庫管理</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
BIN
source-code/ERP(A-b)-倉庫管理/index.html:Zone.Identifier
Normal file
BIN
source-code/ERP(A-b)-倉庫管理/index.html:Zone.Identifier
Normal file
Binary file not shown.
59
source-code/ERP(A-b)-倉庫管理/package.json
Normal file
59
source-code/ERP(A-b)-倉庫管理/package.json
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
{
|
||||
"name": "ERP(A-b)-倉庫管理",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@radix-ui/react-accordion": "^1.2.3",
|
||||
"@radix-ui/react-alert-dialog": "^1.1.6",
|
||||
"@radix-ui/react-aspect-ratio": "^1.1.2",
|
||||
"@radix-ui/react-avatar": "^1.1.3",
|
||||
"@radix-ui/react-checkbox": "^1.1.4",
|
||||
"@radix-ui/react-collapsible": "^1.1.3",
|
||||
"@radix-ui/react-context-menu": "^2.2.6",
|
||||
"@radix-ui/react-dialog": "^1.1.6",
|
||||
"@radix-ui/react-dropdown-menu": "^2.1.6",
|
||||
"@radix-ui/react-hover-card": "^1.1.6",
|
||||
"@radix-ui/react-label": "^2.1.2",
|
||||
"@radix-ui/react-menubar": "^1.1.6",
|
||||
"@radix-ui/react-navigation-menu": "^1.2.5",
|
||||
"@radix-ui/react-popover": "^1.1.6",
|
||||
"@radix-ui/react-progress": "^1.1.2",
|
||||
"@radix-ui/react-radio-group": "^1.2.3",
|
||||
"@radix-ui/react-scroll-area": "^1.2.3",
|
||||
"@radix-ui/react-select": "^2.1.6",
|
||||
"@radix-ui/react-separator": "^1.1.2",
|
||||
"@radix-ui/react-slider": "^1.2.3",
|
||||
"@radix-ui/react-slot": "^1.1.2",
|
||||
"@radix-ui/react-switch": "^1.1.3",
|
||||
"@radix-ui/react-tabs": "^1.1.3",
|
||||
"@radix-ui/react-toggle": "^1.1.2",
|
||||
"@radix-ui/react-toggle-group": "^1.1.2",
|
||||
"@radix-ui/react-tooltip": "^1.1.8",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "*",
|
||||
"cmdk": "^1.1.1",
|
||||
"embla-carousel-react": "^8.6.0",
|
||||
"input-otp": "^1.4.2",
|
||||
"lucide-react": "^0.487.0",
|
||||
"next-themes": "^0.4.6",
|
||||
"react": "^18.3.1",
|
||||
"react-day-picker": "^8.10.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-hook-form": "^7.55.0",
|
||||
"react-resizable-panels": "^2.1.7",
|
||||
"recharts": "^2.15.2",
|
||||
"sonner": "^2.0.3",
|
||||
"tailwind-merge": "*",
|
||||
"vaul": "^1.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.10.0",
|
||||
"@vitejs/plugin-react-swc": "^3.10.2",
|
||||
"vite": "6.3.5"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build"
|
||||
}
|
||||
}
|
||||
BIN
source-code/ERP(A-b)-倉庫管理/package.json:Zone.Identifier
Normal file
BIN
source-code/ERP(A-b)-倉庫管理/package.json:Zone.Identifier
Normal file
Binary file not shown.
723
source-code/ERP(A-b)-倉庫管理/src/App.tsx
Normal file
723
source-code/ERP(A-b)-倉庫管理/src/App.tsx
Normal file
@@ -0,0 +1,723 @@
|
||||
import { useState } from "react";
|
||||
import NavigationSidebar from "./components/NavigationSidebar";
|
||||
import WarehouseManagement from "./components/WarehouseManagement";
|
||||
import WarehouseInventoryPage from "./components/WarehouseInventoryPage";
|
||||
import AddInventoryPage from "./components/AddInventoryPage";
|
||||
import EditInventoryPage from "./components/EditInventoryPage";
|
||||
import SafetyStockPage from "./components/SafetyStockPage";
|
||||
import { Toaster } from "./components/ui/sonner";
|
||||
import { WarehouseInventory, Warehouse, InventoryTransaction, InboundItem, InboundReason, SafetyStockSetting } from "./types/warehouse";
|
||||
import { toast } from "sonner@2.0.3";
|
||||
import { generateId } from "./utils/format";
|
||||
|
||||
interface PageState {
|
||||
page: string;
|
||||
params?: {
|
||||
warehouseId?: string;
|
||||
inventoryId?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [currentPage, setCurrentPage] = useState<PageState>({
|
||||
page: "warehouse-management",
|
||||
});
|
||||
|
||||
// Shared inventory state
|
||||
const [inventories, setInventories] = useState<WarehouseInventory[]>([
|
||||
// ===== 中央倉(id=1)- 原物料庫存 =====
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "101",
|
||||
productName: "二砂糖",
|
||||
quantity: 50,
|
||||
batchNumber: "SG20251201",
|
||||
expiryDate: "2026-12-01",
|
||||
lastInboundDate: "2025-12-01",
|
||||
lastOutboundDate: "2025-12-10",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "101",
|
||||
productName: "二砂糖",
|
||||
quantity: 45,
|
||||
batchNumber: "SG20251115",
|
||||
expiryDate: "2026-11-15",
|
||||
lastInboundDate: "2025-11-15",
|
||||
lastOutboundDate: "2025-12-08",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "102",
|
||||
productName: "黑糖",
|
||||
quantity: 30,
|
||||
batchNumber: "BS20251205",
|
||||
expiryDate: "2026-06-05",
|
||||
lastInboundDate: "2025-12-05",
|
||||
lastOutboundDate: "2025-12-09",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "103",
|
||||
productName: "冰糖",
|
||||
quantity: 25,
|
||||
batchNumber: "RS20251203",
|
||||
expiryDate: "2026-12-03",
|
||||
lastInboundDate: "2025-12-03",
|
||||
lastOutboundDate: "2025-12-07",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "104",
|
||||
productName: "奶精粉",
|
||||
quantity: 18,
|
||||
batchNumber: "CR20251208",
|
||||
expiryDate: "2026-03-08",
|
||||
lastInboundDate: "2025-12-08",
|
||||
lastOutboundDate: "2025-12-10",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "105",
|
||||
productName: "鮮奶油",
|
||||
quantity: 12,
|
||||
batchNumber: "FC20251210",
|
||||
expiryDate: "2025-12-25",
|
||||
lastInboundDate: "2025-12-10",
|
||||
lastOutboundDate: "2025-12-11",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "106",
|
||||
productName: "紅豆(生)",
|
||||
quantity: 40,
|
||||
batchNumber: "RBR20251202",
|
||||
expiryDate: "2026-06-02",
|
||||
lastInboundDate: "2025-12-02",
|
||||
lastOutboundDate: "2025-12-09",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "107",
|
||||
productName: "綠豆(生)",
|
||||
quantity: 35,
|
||||
batchNumber: "GBR20251204",
|
||||
expiryDate: "2026-06-04",
|
||||
lastInboundDate: "2025-12-04",
|
||||
lastOutboundDate: "2025-12-10",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "108",
|
||||
productName: "芋頭(生)",
|
||||
quantity: 28,
|
||||
batchNumber: "TR20251206",
|
||||
expiryDate: "2026-01-06",
|
||||
lastInboundDate: "2025-12-06",
|
||||
lastOutboundDate: "2025-12-09",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "109",
|
||||
productName: "地瓜(生)",
|
||||
quantity: 32,
|
||||
batchNumber: "SPR20251207",
|
||||
expiryDate: "2026-01-07",
|
||||
lastInboundDate: "2025-12-07",
|
||||
lastOutboundDate: "2025-12-10",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "110",
|
||||
productName: "仙草乾",
|
||||
quantity: 20,
|
||||
batchNumber: "GD20251205",
|
||||
expiryDate: "2026-12-05",
|
||||
lastInboundDate: "2025-12-05",
|
||||
lastOutboundDate: "2025-12-08",
|
||||
},
|
||||
|
||||
// ===== 中央倉(id=1)- 半成品庫存 =====
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "1",
|
||||
productName: "粉粿原漿",
|
||||
quantity: 25,
|
||||
batchNumber: "PG20251201",
|
||||
expiryDate: "2025-12-15",
|
||||
lastInboundDate: "2025-12-01",
|
||||
lastOutboundDate: "2025-12-08",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "1",
|
||||
productName: "粉粿原漿",
|
||||
quantity: 30,
|
||||
batchNumber: "PG20251128",
|
||||
expiryDate: "2025-12-12",
|
||||
lastInboundDate: "2025-11-28",
|
||||
lastOutboundDate: "2025-12-06",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "2",
|
||||
productName: "黑糖粉圓(未加糖)",
|
||||
quantity: 8,
|
||||
batchNumber: "BT20251203",
|
||||
expiryDate: "2025-12-10",
|
||||
lastInboundDate: "2025-12-03",
|
||||
lastOutboundDate: "2025-12-09",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "2",
|
||||
productName: "黑糖粉圓(未加糖)",
|
||||
quantity: 15,
|
||||
batchNumber: "BT20251130",
|
||||
expiryDate: "2025-12-07",
|
||||
lastInboundDate: "2025-11-30",
|
||||
lastOutboundDate: "2025-12-05",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "3",
|
||||
productName: "熟紅豆(未加糖)",
|
||||
quantity: 12,
|
||||
batchNumber: "RB20251205",
|
||||
expiryDate: "2025-12-12",
|
||||
lastInboundDate: "2025-12-05",
|
||||
lastOutboundDate: "2025-12-10",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "3",
|
||||
productName: "熟紅豆(未加糖)",
|
||||
quantity: 18,
|
||||
batchNumber: "RB20251202",
|
||||
expiryDate: "2025-12-09",
|
||||
lastInboundDate: "2025-12-02",
|
||||
lastOutboundDate: "2025-12-07",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "4",
|
||||
productName: "熟綠豆(未加糖)",
|
||||
quantity: 10,
|
||||
batchNumber: "GB20251204",
|
||||
expiryDate: "2025-12-11",
|
||||
lastInboundDate: "2025-12-04",
|
||||
lastOutboundDate: "2025-12-09",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "4",
|
||||
productName: "熟綠豆(未加糖)",
|
||||
quantity: 14,
|
||||
batchNumber: "GB20251201",
|
||||
expiryDate: "2025-12-08",
|
||||
lastInboundDate: "2025-12-01",
|
||||
lastOutboundDate: "2025-12-06",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "5",
|
||||
productName: "芋頭泥(無調味)",
|
||||
quantity: 20,
|
||||
batchNumber: "TM20251206",
|
||||
expiryDate: "2025-12-20",
|
||||
lastInboundDate: "2025-12-06",
|
||||
lastOutboundDate: "2025-12-10",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "5",
|
||||
productName: "芋頭泥(無調味)",
|
||||
quantity: 25,
|
||||
batchNumber: "TM20251203",
|
||||
expiryDate: "2025-12-17",
|
||||
lastInboundDate: "2025-12-03",
|
||||
lastOutboundDate: "2025-12-08",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "6",
|
||||
productName: "地瓜泥(無調味)",
|
||||
quantity: 18,
|
||||
batchNumber: "SM20251207",
|
||||
expiryDate: "2025-12-21",
|
||||
lastInboundDate: "2025-12-07",
|
||||
lastOutboundDate: "2025-12-10",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "6",
|
||||
productName: "地瓜泥(無調味)",
|
||||
quantity: 22,
|
||||
batchNumber: "SM20251204",
|
||||
expiryDate: "2025-12-18",
|
||||
lastInboundDate: "2025-12-04",
|
||||
lastOutboundDate: "2025-12-09",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "7",
|
||||
productName: "仙草原凍(整塊)",
|
||||
quantity: 16,
|
||||
batchNumber: "GJ20251208",
|
||||
expiryDate: "2025-12-22",
|
||||
lastInboundDate: "2025-12-08",
|
||||
lastOutboundDate: "2025-12-10",
|
||||
},
|
||||
{
|
||||
warehouseId: "1",
|
||||
productId: "7",
|
||||
productName: "仙草原凍(整塊)",
|
||||
quantity: 20,
|
||||
batchNumber: "GJ20251205",
|
||||
expiryDate: "2025-12-19",
|
||||
lastInboundDate: "2025-12-05",
|
||||
lastOutboundDate: "2025-12-09",
|
||||
},
|
||||
|
||||
// ===== 門市冷藏庫(id=2)- 半成品庫存 =====
|
||||
{
|
||||
warehouseId: "2",
|
||||
productId: "1",
|
||||
productName: "粉粿原漿",
|
||||
quantity: 8,
|
||||
batchNumber: "PG20251209",
|
||||
expiryDate: "2025-12-16",
|
||||
lastInboundDate: "2025-12-09",
|
||||
lastOutboundDate: "2025-12-11",
|
||||
},
|
||||
{
|
||||
warehouseId: "2",
|
||||
productId: "2",
|
||||
productName: "黑糖粉圓(未加糖)",
|
||||
quantity: 6,
|
||||
batchNumber: "BT20251208",
|
||||
expiryDate: "2025-12-13",
|
||||
lastInboundDate: "2025-12-08",
|
||||
lastOutboundDate: "2025-12-11",
|
||||
},
|
||||
{
|
||||
warehouseId: "2",
|
||||
productId: "3",
|
||||
productName: "熟紅豆(未加糖)",
|
||||
quantity: 5,
|
||||
batchNumber: "RB20251209",
|
||||
expiryDate: "2025-12-14",
|
||||
lastInboundDate: "2025-12-09",
|
||||
lastOutboundDate: "2025-12-11",
|
||||
},
|
||||
{
|
||||
warehouseId: "2",
|
||||
productId: "4",
|
||||
productName: "熟綠豆(未加糖)",
|
||||
quantity: 4,
|
||||
batchNumber: "GB20251210",
|
||||
expiryDate: "2025-12-15",
|
||||
lastInboundDate: "2025-12-10",
|
||||
lastOutboundDate: "2025-12-11",
|
||||
},
|
||||
{
|
||||
warehouseId: "2",
|
||||
productId: "5",
|
||||
productName: "芋頭泥(無調味)",
|
||||
quantity: 10,
|
||||
batchNumber: "TM20251210",
|
||||
expiryDate: "2025-12-24",
|
||||
lastInboundDate: "2025-12-10",
|
||||
lastOutboundDate: "2025-12-11",
|
||||
},
|
||||
{
|
||||
warehouseId: "2",
|
||||
productId: "6",
|
||||
productName: "地瓜泥(無調味)",
|
||||
quantity: 9,
|
||||
batchNumber: "SM20251209",
|
||||
expiryDate: "2025-12-23",
|
||||
lastInboundDate: "2025-12-09",
|
||||
lastOutboundDate: "2025-12-11",
|
||||
},
|
||||
{
|
||||
warehouseId: "2",
|
||||
productId: "7",
|
||||
productName: "仙草原凍(整塊)",
|
||||
quantity: 7,
|
||||
batchNumber: "GJ20251210",
|
||||
expiryDate: "2025-12-24",
|
||||
lastInboundDate: "2025-12-10",
|
||||
lastOutboundDate: "2025-12-11",
|
||||
},
|
||||
]);
|
||||
|
||||
const [warehouses] = useState([
|
||||
{
|
||||
id: "1",
|
||||
name: "中央倉",
|
||||
address: "台北市信義區信義路五段7號",
|
||||
manager: "張經理",
|
||||
phone: "02-1234-5678",
|
||||
description: "主要原物料儲存倉庫",
|
||||
createdAt: "2025-11-01",
|
||||
type: "中央倉庫" as const,
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
name: "門市冷藏庫",
|
||||
address: "台北市大安區敦化南路一段100號",
|
||||
manager: "李主管",
|
||||
phone: "02-8765-4321",
|
||||
description: "門市專用冷藏倉庫",
|
||||
createdAt: "2025-11-10",
|
||||
type: "門市" as const,
|
||||
},
|
||||
]);
|
||||
|
||||
// Shared inventory transactions state
|
||||
const [transactions, setTransactions] = useState<InventoryTransaction[]>([]);
|
||||
|
||||
// Safety stock settings state
|
||||
const [safetyStockSettings, setSafetyStockSettings] = useState<SafetyStockSetting[]>([]);
|
||||
|
||||
const handleNavigate = (path: string, params?: { warehouseId?: string }) => {
|
||||
setCurrentPage({ page: path, params });
|
||||
};
|
||||
|
||||
const handleNavigateToInventory = (warehouseId: string) => {
|
||||
setCurrentPage({ page: "warehouse-inventory", params: { warehouseId } });
|
||||
};
|
||||
|
||||
const handleBackFromInventory = () => {
|
||||
setCurrentPage({ page: "warehouse-management" });
|
||||
};
|
||||
|
||||
const handleSaveInventory = (
|
||||
warehouseId: string,
|
||||
updatedInventories: WarehouseInventory[]
|
||||
) => {
|
||||
// Remove old inventories for this warehouse
|
||||
const otherInventories = inventories.filter(
|
||||
(inv) => inv.warehouseId !== warehouseId
|
||||
);
|
||||
// Add updated inventories
|
||||
setInventories([...otherInventories, ...updatedInventories]);
|
||||
};
|
||||
|
||||
const handleNavigateToEditInventory = (warehouseId: string, inventoryId: string) => {
|
||||
setCurrentPage({ page: "edit-inventory", params: { warehouseId, inventoryId } });
|
||||
};
|
||||
|
||||
const handleBackFromEditInventory = (warehouseId: string) => {
|
||||
setCurrentPage({ page: "warehouse-inventory", params: { warehouseId } });
|
||||
};
|
||||
|
||||
const handleUpdateInventory = (
|
||||
warehouseId: string,
|
||||
updatedInventory: WarehouseInventory & { inventoryId: string }
|
||||
) => {
|
||||
// 從 inventoryId 解析出索引
|
||||
const inventoryIdParts = updatedInventory.inventoryId.split('-');
|
||||
const index = parseInt(inventoryIdParts[inventoryIdParts.length - 1], 10);
|
||||
|
||||
// 找出該倉庫的所有庫存及其索引
|
||||
const warehouseInventories = inventories.filter((inv) => inv.warehouseId === warehouseId);
|
||||
const otherInventories = inventories.filter((inv) => inv.warehouseId !== warehouseId);
|
||||
|
||||
// 更新特定索引的庫存項目
|
||||
const updatedWarehouseInventories = warehouseInventories.map((inv, idx) => {
|
||||
return idx === index ? updatedInventory : inv;
|
||||
});
|
||||
|
||||
setInventories([...otherInventories, ...updatedWarehouseInventories]);
|
||||
handleBackFromEditInventory(warehouseId);
|
||||
};
|
||||
|
||||
const handleDeleteInventory = (warehouseId: string, inventoryId: string) => {
|
||||
// 從 inventoryId 解析出索引
|
||||
const inventoryIdParts = inventoryId.split('-');
|
||||
const index = parseInt(inventoryIdParts[inventoryIdParts.length - 1], 10);
|
||||
|
||||
// 找出該倉庫的所有庫存
|
||||
const warehouseInventories = inventories.filter((inv) => inv.warehouseId === warehouseId);
|
||||
const otherInventories = inventories.filter((inv) => inv.warehouseId !== warehouseId);
|
||||
|
||||
// 刪除特定索引的庫存項目
|
||||
const updatedWarehouseInventories = warehouseInventories.filter((_, idx) => idx !== index);
|
||||
|
||||
setInventories([...otherInventories, ...updatedWarehouseInventories]);
|
||||
handleBackFromEditInventory(warehouseId);
|
||||
};
|
||||
|
||||
const handleNavigateToAddInventory = (warehouseId: string) => {
|
||||
setCurrentPage({ page: "add-inventory", params: { warehouseId } });
|
||||
};
|
||||
|
||||
const handleBackFromAddInventory = (warehouseId: string) => {
|
||||
setCurrentPage({ page: "warehouse-inventory", params: { warehouseId } });
|
||||
};
|
||||
|
||||
const handleNavigateToSafetyStock = (warehouseId: string) => {
|
||||
setCurrentPage({ page: "safety-stock", params: { warehouseId } });
|
||||
};
|
||||
|
||||
const handleBackFromSafetyStock = (warehouseId: string) => {
|
||||
setCurrentPage({ page: "warehouse-inventory", params: { warehouseId } });
|
||||
};
|
||||
|
||||
const handleSaveSafetyStockSettings = (
|
||||
warehouseId: string,
|
||||
settings: SafetyStockSetting[]
|
||||
) => {
|
||||
// 移除該倉庫舊的設定
|
||||
const otherSettings = safetyStockSettings.filter(
|
||||
(s) => s.warehouseId !== warehouseId
|
||||
);
|
||||
// 添加新的設定
|
||||
setSafetyStockSettings([...otherSettings, ...settings]);
|
||||
};
|
||||
|
||||
const handleSaveInbound = (
|
||||
warehouseId: string,
|
||||
data: {
|
||||
inboundDate: string;
|
||||
reason: InboundReason;
|
||||
notes: string;
|
||||
items: InboundItem[];
|
||||
}
|
||||
) => {
|
||||
const now = new Date().toISOString();
|
||||
const warehouse = warehouses.find((w) => w.id === warehouseId);
|
||||
const warehouseName = warehouse?.name || "";
|
||||
|
||||
const currentInventories = inventories.filter((inv) => inv.warehouseId === warehouseId);
|
||||
const updatedInventories = [...currentInventories];
|
||||
|
||||
// 處理每一筆入庫明細
|
||||
data.items.forEach((inboundItem) => {
|
||||
// 檢查是否已存在相同商品和批號的庫存
|
||||
const existingIndex = updatedInventories.findIndex(
|
||||
(item) =>
|
||||
item.productId === inboundItem.productId &&
|
||||
item.batchNumber === inboundItem.batchNumber
|
||||
);
|
||||
|
||||
if (existingIndex !== -1) {
|
||||
// 更新既有庫存數量
|
||||
updatedInventories[existingIndex] = {
|
||||
...updatedInventories[existingIndex],
|
||||
quantity: updatedInventories[existingIndex].quantity + inboundItem.quantity,
|
||||
lastInboundDate: data.inboundDate,
|
||||
};
|
||||
} else {
|
||||
// 新增庫存項目
|
||||
const newItem: WarehouseInventory = {
|
||||
warehouseId,
|
||||
productId: inboundItem.productId,
|
||||
productName: inboundItem.productName,
|
||||
quantity: inboundItem.quantity,
|
||||
batchNumber: inboundItem.batchNumber,
|
||||
expiryDate: inboundItem.expiryDate,
|
||||
lastInboundDate: data.inboundDate,
|
||||
};
|
||||
updatedInventories.push(newItem);
|
||||
}
|
||||
|
||||
// 建立庫存異動記錄
|
||||
const transaction: InventoryTransaction = {
|
||||
id: generateId(),
|
||||
warehouseId,
|
||||
warehouseName,
|
||||
productId: inboundItem.productId,
|
||||
productName: inboundItem.productName,
|
||||
batchNumber: inboundItem.batchNumber,
|
||||
quantity: inboundItem.quantity,
|
||||
transactionType: "手動入庫",
|
||||
reason: data.reason,
|
||||
notes: data.notes,
|
||||
expiryDate: inboundItem.expiryDate,
|
||||
operatorName: "系統使用者",
|
||||
createdAt: now,
|
||||
};
|
||||
setTransactions([...transactions, transaction]);
|
||||
});
|
||||
|
||||
// 更新庫存
|
||||
handleSaveInventory(warehouseId, updatedInventories);
|
||||
|
||||
const totalInboundQty = data.items.reduce((sum, item) => sum + item.quantity, 0);
|
||||
toast.success(`入庫成功!共 ${data.items.length} 項商品,總數量 ${totalInboundQty}`);
|
||||
|
||||
// 返回庫存管理頁面
|
||||
handleBackFromAddInventory(warehouseId);
|
||||
};
|
||||
|
||||
const renderPage = () => {
|
||||
switch (currentPage.page) {
|
||||
case "warehouse-management":
|
||||
return (
|
||||
<WarehouseManagement
|
||||
onNavigateToInventory={handleNavigateToInventory}
|
||||
inventories={inventories}
|
||||
onUpdateInventories={setInventories}
|
||||
safetyStockSettings={safetyStockSettings}
|
||||
/>
|
||||
);
|
||||
case "warehouse-inventory": {
|
||||
const warehouseId = currentPage.params?.warehouseId;
|
||||
const warehouse = warehouses.find((w) => w.id === warehouseId);
|
||||
if (!warehouse) {
|
||||
// Fallback to warehouse management if warehouse not found
|
||||
return (
|
||||
<WarehouseManagement
|
||||
onNavigateToInventory={handleNavigateToInventory}
|
||||
inventories={inventories}
|
||||
onUpdateInventories={setInventories}
|
||||
safetyStockSettings={safetyStockSettings}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<WarehouseInventoryPage
|
||||
warehouseId={warehouse.id}
|
||||
warehouseName={warehouse.name}
|
||||
inventories={inventories.filter(
|
||||
(inv) => inv.warehouseId === warehouse.id
|
||||
)}
|
||||
safetyStockSettings={safetyStockSettings.filter(
|
||||
(s) => s.warehouseId === warehouse.id
|
||||
)}
|
||||
onBack={handleBackFromInventory}
|
||||
onNavigateToAddInventory={() => handleNavigateToAddInventory(warehouse.id)}
|
||||
onNavigateToEditInventory={(inventoryId) =>
|
||||
handleNavigateToEditInventory(warehouse.id, inventoryId)
|
||||
}
|
||||
onNavigateToSafetyStock={() => handleNavigateToSafetyStock(warehouse.id)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
case "add-inventory": {
|
||||
const warehouseId = currentPage.params?.warehouseId;
|
||||
const warehouse = warehouses.find((w) => w.id === warehouseId);
|
||||
if (!warehouse) {
|
||||
return (
|
||||
<WarehouseManagement
|
||||
onNavigateToInventory={handleNavigateToInventory}
|
||||
inventories={inventories}
|
||||
onUpdateInventories={setInventories}
|
||||
safetyStockSettings={safetyStockSettings}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<AddInventoryPage
|
||||
warehouseId={warehouse.id}
|
||||
warehouseName={warehouse.name}
|
||||
onBack={() => handleBackFromAddInventory(warehouse.id)}
|
||||
onSave={(data) => handleSaveInbound(warehouse.id, data)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
case "edit-inventory": {
|
||||
const warehouseId = currentPage.params?.warehouseId;
|
||||
const inventoryId = currentPage.params?.inventoryId;
|
||||
const warehouse = warehouses.find((w) => w.id === warehouseId);
|
||||
|
||||
if (!warehouse || !inventoryId) {
|
||||
return (
|
||||
<WarehouseManagement
|
||||
onNavigateToInventory={handleNavigateToInventory}
|
||||
inventories={inventories}
|
||||
onUpdateInventories={setInventories}
|
||||
safetyStockSettings={safetyStockSettings}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
// 找出對應的庫存項目
|
||||
const warehouseInventories = inventories.filter((inv) => inv.warehouseId === warehouseId);
|
||||
const inventoryIdParts = inventoryId.split('-');
|
||||
const index = parseInt(inventoryIdParts[inventoryIdParts.length - 1], 10);
|
||||
const inventory = warehouseInventories[index];
|
||||
|
||||
if (!inventory) {
|
||||
return (
|
||||
<WarehouseManagement
|
||||
onNavigateToInventory={handleNavigateToInventory}
|
||||
inventories={inventories}
|
||||
onUpdateInventories={setInventories}
|
||||
safetyStockSettings={safetyStockSettings}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<EditInventoryPage
|
||||
inventory={{ ...inventory, inventoryId }}
|
||||
warehouseName={warehouse.name}
|
||||
onBack={() => handleBackFromEditInventory(warehouse.id)}
|
||||
onSave={(updatedInventory) => handleUpdateInventory(warehouse.id, updatedInventory)}
|
||||
onDelete={(invId) => handleDeleteInventory(warehouse.id, invId)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
case "safety-stock": {
|
||||
const warehouseId = currentPage.params?.warehouseId;
|
||||
const warehouse = warehouses.find((w) => w.id === warehouseId);
|
||||
|
||||
if (!warehouse) {
|
||||
return (
|
||||
<WarehouseManagement
|
||||
onNavigateToInventory={handleNavigateToInventory}
|
||||
inventories={inventories}
|
||||
onUpdateInventories={setInventories}
|
||||
safetyStockSettings={safetyStockSettings}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
// 找出該倉庫的所有庫存
|
||||
const warehouseInventories = inventories.filter((inv) => inv.warehouseId === warehouseId);
|
||||
|
||||
return (
|
||||
<SafetyStockPage
|
||||
warehouseId={warehouse.id}
|
||||
warehouseName={warehouse.name}
|
||||
safetyStockSettings={safetyStockSettings.filter((s) => s.warehouseId === warehouseId)}
|
||||
inventories={warehouseInventories}
|
||||
onBack={() => handleBackFromSafetyStock(warehouse.id)}
|
||||
onSave={(settings) => handleSaveSafetyStockSettings(warehouse.id, settings)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
default:
|
||||
// Default to warehouse management
|
||||
return (
|
||||
<WarehouseManagement
|
||||
onNavigateToInventory={handleNavigateToInventory}
|
||||
inventories={inventories}
|
||||
onUpdateInventories={setInventories}
|
||||
safetyStockSettings={safetyStockSettings}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen bg-background">
|
||||
{/* Sidebar Navigation */}
|
||||
<NavigationSidebar
|
||||
currentPath={currentPage.page}
|
||||
onNavigate={handleNavigate}
|
||||
/>
|
||||
|
||||
{/* Main Content */}
|
||||
<main className="flex-1 overflow-auto">
|
||||
{renderPage()}
|
||||
</main>
|
||||
|
||||
<Toaster />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
BIN
source-code/ERP(A-b)-倉庫管理/src/App.tsx:Zone.Identifier
Normal file
BIN
source-code/ERP(A-b)-倉庫管理/src/App.tsx:Zone.Identifier
Normal file
Binary file not shown.
3
source-code/ERP(A-b)-倉庫管理/src/Attributions.md
Normal file
3
source-code/ERP(A-b)-倉庫管理/src/Attributions.md
Normal file
@@ -0,0 +1,3 @@
|
||||
This Figma Make file includes components from [shadcn/ui](https://ui.shadcn.com/) used under [MIT license](https://github.com/shadcn-ui/ui/blob/main/LICENSE.md).
|
||||
|
||||
This Figma Make file includes photos from [Unsplash](https://unsplash.com) used under [license](https://unsplash.com/license).
|
||||
BIN
source-code/ERP(A-b)-倉庫管理/src/Attributions.md:Zone.Identifier
Normal file
BIN
source-code/ERP(A-b)-倉庫管理/src/Attributions.md:Zone.Identifier
Normal file
Binary file not shown.
442
source-code/ERP(A-b)-倉庫管理/src/components/AddInventoryPage.tsx
Normal file
442
source-code/ERP(A-b)-倉庫管理/src/components/AddInventoryPage.tsx
Normal file
@@ -0,0 +1,442 @@
|
||||
/**
|
||||
* 新增庫存頁面(手動入庫)
|
||||
* 用於單一倉庫的手動入庫作業
|
||||
*/
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { Plus, Trash2, Calendar, ArrowLeft, Save } from "lucide-react";
|
||||
import { Button } from "./ui/button";
|
||||
import { Input } from "./ui/input";
|
||||
import { Label } from "./ui/label";
|
||||
import { Textarea } from "./ui/textarea";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "./ui/select";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "./ui/table";
|
||||
import { InboundItem, InboundReason } from "../types/warehouse";
|
||||
import { AVAILABLE_PRODUCTS } from "../constants/products";
|
||||
import { generateBatchNumber, getCurrentDateTime } from "../utils/format";
|
||||
import { toast } from "sonner@2.0.3";
|
||||
|
||||
interface AddInventoryPageProps {
|
||||
warehouseId: string;
|
||||
warehouseName: string;
|
||||
onBack: () => void;
|
||||
onSave: (data: {
|
||||
inboundDate: string;
|
||||
reason: InboundReason;
|
||||
notes: string;
|
||||
items: InboundItem[];
|
||||
}) => void;
|
||||
}
|
||||
|
||||
const INBOUND_REASONS: InboundReason[] = [
|
||||
"期初建檔",
|
||||
"盤點調整",
|
||||
"實際入庫未走採購流程",
|
||||
"生產加工成品入庫",
|
||||
"其他",
|
||||
];
|
||||
|
||||
const PRODUCT_UNITS: Record<string, string> = {
|
||||
"1": "袋",
|
||||
"2": "盆",
|
||||
"3": "盆",
|
||||
"4": "盆",
|
||||
"5": "盒",
|
||||
"6": "盒",
|
||||
"7": "盆",
|
||||
};
|
||||
|
||||
export default function AddInventoryPage({
|
||||
warehouseId,
|
||||
warehouseName,
|
||||
onBack,
|
||||
onSave,
|
||||
}: AddInventoryPageProps) {
|
||||
const [inboundDate, setInboundDate] = useState(getCurrentDateTime());
|
||||
const [reason, setReason] = useState<InboundReason>("期初建檔");
|
||||
const [notes, setNotes] = useState("");
|
||||
const [items, setItems] = useState<InboundItem[]>([]);
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
|
||||
// 新增明細行
|
||||
const handleAddItem = () => {
|
||||
const newItem: InboundItem = {
|
||||
tempId: `temp-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
||||
productId: AVAILABLE_PRODUCTS[0]?.id || "",
|
||||
productName: AVAILABLE_PRODUCTS[0]?.name || "",
|
||||
quantity: 0,
|
||||
unit: PRODUCT_UNITS[AVAILABLE_PRODUCTS[0]?.id] || "kg",
|
||||
expiryDate: "",
|
||||
batchNumber: generateBatchNumber(warehouseId, inboundDate.split("T")[0]),
|
||||
autoGeneratedBatch: true,
|
||||
};
|
||||
setItems([...items, newItem]);
|
||||
};
|
||||
|
||||
// 刪除明細行
|
||||
const handleRemoveItem = (tempId: string) => {
|
||||
setItems(items.filter((item) => item.tempId !== tempId));
|
||||
};
|
||||
|
||||
// 更新明細行
|
||||
const handleUpdateItem = (tempId: string, updates: Partial<InboundItem>) => {
|
||||
setItems(
|
||||
items.map((item) =>
|
||||
item.tempId === tempId ? { ...item, ...updates } : item
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
// 處理商品變更
|
||||
const handleProductChange = (tempId: string, productId: string) => {
|
||||
const product = AVAILABLE_PRODUCTS.find((p) => p.id === productId);
|
||||
if (product) {
|
||||
handleUpdateItem(tempId, {
|
||||
productId,
|
||||
productName: product.name,
|
||||
unit: PRODUCT_UNITS[productId] || "kg",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 處理批號變更
|
||||
const handleBatchNumberChange = (tempId: string, value: string) => {
|
||||
handleUpdateItem(tempId, {
|
||||
batchNumber: value,
|
||||
autoGeneratedBatch: false,
|
||||
});
|
||||
};
|
||||
|
||||
// 驗證表單
|
||||
const validateForm = (): boolean => {
|
||||
const newErrors: Record<string, string> = {};
|
||||
|
||||
if (!reason) {
|
||||
newErrors.reason = "請選擇入庫原因";
|
||||
}
|
||||
|
||||
if (reason === "其他" && !notes.trim()) {
|
||||
newErrors.notes = "原因為「其他」時,備註為必填";
|
||||
}
|
||||
|
||||
if (items.length === 0) {
|
||||
newErrors.items = "請至少新增一筆庫存明細";
|
||||
}
|
||||
|
||||
items.forEach((item, index) => {
|
||||
if (!item.productId) {
|
||||
newErrors[`item-${index}-product`] = "請選擇商品";
|
||||
}
|
||||
if (item.quantity <= 0) {
|
||||
newErrors[`item-${index}-quantity`] = "數量必須大於 0";
|
||||
}
|
||||
if (!item.batchNumber.trim()) {
|
||||
newErrors[`item-${index}-batch`] = "批號不可為空";
|
||||
}
|
||||
});
|
||||
|
||||
setErrors(newErrors);
|
||||
return Object.keys(newErrors).length === 0;
|
||||
};
|
||||
|
||||
// 處理儲存
|
||||
const handleSave = () => {
|
||||
if (!validateForm()) {
|
||||
toast.error("請檢查表單內容");
|
||||
return;
|
||||
}
|
||||
|
||||
onSave({
|
||||
inboundDate,
|
||||
reason,
|
||||
notes,
|
||||
items,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
{/* 頁面標題與麵包屑 */}
|
||||
<div className="mb-6">
|
||||
<Button
|
||||
onClick={onBack}
|
||||
variant="ghost"
|
||||
className="mb-4 -ml-2 hover:bg-background-light"
|
||||
>
|
||||
<ArrowLeft className="mr-2 h-4 w-4" />
|
||||
返回庫存管理
|
||||
</Button>
|
||||
|
||||
<div className="flex items-center gap-2 text-sm text-grey-2 mb-2">
|
||||
<span>商品與庫存管理</span>
|
||||
<span>/</span>
|
||||
<span>倉庫管理</span>
|
||||
<span>/</span>
|
||||
<span>庫存管理</span>
|
||||
<span>/</span>
|
||||
<span className="text-grey-0">新增庫存</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="mb-2">新增庫存(手動入庫)</h1>
|
||||
<p className="text-gray-600">
|
||||
為 <span className="font-medium">{warehouseName}</span> 新增庫存記錄
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleSave}
|
||||
className="button-filled-primary"
|
||||
>
|
||||
<Save className="mr-2 h-4 w-4" />
|
||||
儲存
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 表單內容 */}
|
||||
<div className="space-y-6">
|
||||
{/* 基本資訊區塊 */}
|
||||
<div className="bg-white rounded-lg shadow-sm border p-6 space-y-4">
|
||||
<h3 className="font-medium">基本資訊</h3>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
{/* 倉庫 */}
|
||||
<div className="space-y-2">
|
||||
<Label>倉庫</Label>
|
||||
<Input
|
||||
value={warehouseName}
|
||||
disabled
|
||||
className="bg-muted"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 日期時間 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="inbound-date">日期時間</Label>
|
||||
<div className="relative">
|
||||
<Input
|
||||
id="inbound-date"
|
||||
type="datetime-local"
|
||||
value={inboundDate}
|
||||
onChange={(e) => setInboundDate(e.target.value)}
|
||||
className="border-gray-300 pr-10"
|
||||
/>
|
||||
<Calendar className="absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 入庫原因 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="reason">
|
||||
入庫原因 <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Select value={reason} onValueChange={(value) => setReason(value as InboundReason)}>
|
||||
<SelectTrigger id="reason" className="border-gray-300">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{INBOUND_REASONS.map((r) => (
|
||||
<SelectItem key={r} value={r}>
|
||||
{r}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{errors.reason && (
|
||||
<p className="text-sm text-destructive">{errors.reason}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 備註 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="notes">
|
||||
備註 {reason === "其他" && <span className="text-destructive">*</span>}
|
||||
</Label>
|
||||
<Textarea
|
||||
id="notes"
|
||||
value={notes}
|
||||
onChange={(e) => setNotes(e.target.value)}
|
||||
placeholder="請輸入備註說明..."
|
||||
className="border-gray-300 resize-none"
|
||||
rows={3}
|
||||
/>
|
||||
{errors.notes && (
|
||||
<p className="text-sm text-destructive">{errors.notes}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 庫存明細區塊 */}
|
||||
<div className="bg-white rounded-lg shadow-sm border p-6 space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h3 className="font-medium">庫存明細</h3>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
請新增要入庫的商品明細
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleAddItem}
|
||||
className="button-outlined-primary"
|
||||
>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增明細
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{errors.items && (
|
||||
<p className="text-sm text-destructive">{errors.items}</p>
|
||||
)}
|
||||
|
||||
{items.length > 0 ? (
|
||||
<div className="border rounded-lg overflow-hidden">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-[200px]">
|
||||
商品 <span className="text-destructive">*</span>
|
||||
</TableHead>
|
||||
<TableHead className="w-[120px]">
|
||||
數量 <span className="text-destructive">*</span>
|
||||
</TableHead>
|
||||
<TableHead className="w-[80px]">單位</TableHead>
|
||||
<TableHead className="w-[160px]">效期</TableHead>
|
||||
<TableHead className="w-[180px]">進貨編號(自動產生)</TableHead>
|
||||
<TableHead className="w-[60px]"></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{items.map((item, index) => (
|
||||
<TableRow key={item.tempId}>
|
||||
{/* 商品 */}
|
||||
<TableCell>
|
||||
<Select
|
||||
value={item.productId}
|
||||
onValueChange={(value) =>
|
||||
handleProductChange(item.tempId, value)
|
||||
}
|
||||
>
|
||||
<SelectTrigger className="border-gray-300">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{AVAILABLE_PRODUCTS.map((product) => (
|
||||
<SelectItem key={product.id} value={product.id}>
|
||||
{product.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{errors[`item-${index}-product`] && (
|
||||
<p className="text-xs text-destructive mt-1">
|
||||
{errors[`item-${index}-product`]}
|
||||
</p>
|
||||
)}
|
||||
</TableCell>
|
||||
|
||||
{/* 數量 */}
|
||||
<TableCell>
|
||||
<Input
|
||||
type="number"
|
||||
min="1"
|
||||
value={item.quantity || ""}
|
||||
onChange={(e) =>
|
||||
handleUpdateItem(item.tempId, {
|
||||
quantity: parseInt(e.target.value) || 0,
|
||||
})
|
||||
}
|
||||
className="border-gray-300"
|
||||
/>
|
||||
{errors[`item-${index}-quantity`] && (
|
||||
<p className="text-xs text-destructive mt-1">
|
||||
{errors[`item-${index}-quantity`]}
|
||||
</p>
|
||||
)}
|
||||
</TableCell>
|
||||
|
||||
{/* 單位 */}
|
||||
<TableCell>
|
||||
<Input
|
||||
value={item.unit}
|
||||
disabled
|
||||
className="bg-muted"
|
||||
/>
|
||||
</TableCell>
|
||||
|
||||
{/* 效期 */}
|
||||
<TableCell>
|
||||
<div className="relative">
|
||||
<Input
|
||||
type="date"
|
||||
value={item.expiryDate}
|
||||
onChange={(e) =>
|
||||
handleUpdateItem(item.tempId, {
|
||||
expiryDate: e.target.value,
|
||||
})
|
||||
}
|
||||
className="border-gray-300 pr-10 [&::-webkit-calendar-picker-indicator]:opacity-0 [&::-webkit-calendar-picker-indicator]:absolute [&::-webkit-calendar-picker-indicator]:right-0 [&::-webkit-calendar-picker-indicator]:w-10 [&::-webkit-calendar-picker-indicator]:h-full [&::-webkit-calendar-picker-indicator]:cursor-pointer"
|
||||
/>
|
||||
<Calendar className="absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-primary pointer-events-none" />
|
||||
</div>
|
||||
</TableCell>
|
||||
|
||||
{/* 批號 */}
|
||||
<TableCell>
|
||||
<Input
|
||||
value={item.batchNumber}
|
||||
onChange={(e) =>
|
||||
handleBatchNumberChange(item.tempId, e.target.value)
|
||||
}
|
||||
className="border-gray-300"
|
||||
placeholder="系統自動生成"
|
||||
/>
|
||||
{errors[`item-${index}-batch`] && (
|
||||
<p className="text-xs text-destructive mt-1">
|
||||
{errors[`item-${index}-batch`]}
|
||||
</p>
|
||||
)}
|
||||
</TableCell>
|
||||
|
||||
{/* 刪除按鈕 */}
|
||||
<TableCell>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => handleRemoveItem(item.tempId)}
|
||||
className="hover:bg-red-50 hover:text-red-600"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
) : (
|
||||
<div className="border border-dashed rounded-lg p-8 text-center text-muted-foreground">
|
||||
<p>尚無明細,請點擊「新增明細」按鈕加入商品</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
248
source-code/ERP(A-b)-倉庫管理/src/components/EditInventoryPage.tsx
Normal file
248
source-code/ERP(A-b)-倉庫管理/src/components/EditInventoryPage.tsx
Normal file
@@ -0,0 +1,248 @@
|
||||
/**
|
||||
* 編輯庫存頁面
|
||||
* 用於編輯單一庫存品項的詳細資訊
|
||||
*/
|
||||
|
||||
import { useState } from "react";
|
||||
import { ArrowLeft, Save, Trash2, AlertTriangle } from "lucide-react";
|
||||
import { Button } from "./ui/button";
|
||||
import { Input } from "./ui/input";
|
||||
import { Label } from "./ui/label";
|
||||
import { WarehouseInventory } from "../types/warehouse";
|
||||
import { toast } from "sonner@2.0.3";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "./ui/alert-dialog";
|
||||
|
||||
interface EditInventoryPageProps {
|
||||
inventory: WarehouseInventory & { inventoryId: string };
|
||||
warehouseName: string;
|
||||
onBack: () => void;
|
||||
onSave: (inventory: WarehouseInventory & { inventoryId: string }) => void;
|
||||
onDelete: (inventoryId: string) => void;
|
||||
}
|
||||
|
||||
export default function EditInventoryPage({
|
||||
inventory,
|
||||
warehouseName,
|
||||
onBack,
|
||||
onSave,
|
||||
onDelete,
|
||||
}: EditInventoryPageProps) {
|
||||
const [formData, setFormData] = useState(inventory);
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
||||
|
||||
const handleChange = (field: keyof WarehouseInventory, value: any) => {
|
||||
setFormData((prev) => ({ ...prev, [field]: value }));
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
// 驗證必填欄位
|
||||
if (!formData.productName) {
|
||||
toast.error("商品名稱不可為空");
|
||||
return;
|
||||
}
|
||||
if (formData.quantity < 0) {
|
||||
toast.error("庫存數量不可為負數");
|
||||
return;
|
||||
}
|
||||
|
||||
onSave(formData);
|
||||
toast.success("庫存資料已更新");
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
onDelete(formData.inventoryId);
|
||||
toast.success("庫存品項已刪除");
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="container mx-auto p-6 max-w-4xl">
|
||||
{/* 頁面標題與麵包屑 */}
|
||||
<div className="mb-6">
|
||||
<Button
|
||||
onClick={onBack}
|
||||
variant="ghost"
|
||||
className="mb-4 -ml-2 hover:bg-background-light"
|
||||
>
|
||||
<ArrowLeft className="mr-2 h-4 w-4" />
|
||||
返回庫存管理
|
||||
</Button>
|
||||
|
||||
<div className="flex items-center gap-2 text-sm text-grey-2 mb-2">
|
||||
<span>商品與庫存管理</span>
|
||||
<span>/</span>
|
||||
<span>倉庫管理</span>
|
||||
<span>/</span>
|
||||
<span>庫存管理</span>
|
||||
<span>/</span>
|
||||
<span className="text-grey-0">編輯庫存品項</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="mb-2">編輯庫存品項</h1>
|
||||
<p className="text-gray-600">
|
||||
倉庫:<span className="font-medium">{warehouseName}</span>
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<Button
|
||||
onClick={() => setShowDeleteDialog(true)}
|
||||
variant="outline"
|
||||
className="group border-destructive text-destructive hover:bg-destructive hover:text-white"
|
||||
>
|
||||
<Trash2 className="mr-2 h-4 w-4 group-hover:text-white" />
|
||||
刪除品項
|
||||
</Button>
|
||||
<Button onClick={handleSave} className="button-filled-primary">
|
||||
<Save className="mr-2 h-4 w-4" />
|
||||
儲存變更
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 表單內容 */}
|
||||
<div className="bg-white rounded-lg shadow-sm border p-6">
|
||||
<div className="space-y-6">
|
||||
{/* 商品基本資訊 */}
|
||||
<div className="space-y-4">
|
||||
<h3 className="font-medium border-b pb-2">商品基本資訊</h3>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="productName">
|
||||
商品名稱 <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="productName"
|
||||
value={formData.productName}
|
||||
disabled
|
||||
className="bg-muted"
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
商品名稱無法修改
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="batchNumber">批號</Label>
|
||||
<Input
|
||||
id="batchNumber"
|
||||
type="text"
|
||||
value={formData.batchNumber}
|
||||
onChange={(e) => handleChange("batchNumber", e.target.value)}
|
||||
placeholder="例:FL20251101"
|
||||
className="button-outlined-primary"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 庫存數量 */}
|
||||
<div className="space-y-4">
|
||||
<h3 className="font-medium border-b pb-2">庫存數量</h3>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="quantity">
|
||||
庫存數量 <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="quantity"
|
||||
type="number"
|
||||
min="0"
|
||||
value={formData.quantity}
|
||||
onChange={(e) =>
|
||||
handleChange("quantity", parseInt(e.target.value) || 0)
|
||||
}
|
||||
placeholder="0"
|
||||
className="button-outlined-primary"
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
批號層級的庫存數量,安全庫存請至「安全庫存設定」頁面進行商品層級設定
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 日期資訊 */}
|
||||
<div className="space-y-4">
|
||||
<h3 className="font-medium border-b pb-2">日期資訊</h3>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="expiryDate">保存期限</Label>
|
||||
<Input
|
||||
id="expiryDate"
|
||||
type="date"
|
||||
value={formData.expiryDate}
|
||||
onChange={(e) => handleChange("expiryDate", e.target.value)}
|
||||
className="button-outlined-primary"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="lastInboundDate">最新入庫時間</Label>
|
||||
<Input
|
||||
id="lastInboundDate"
|
||||
type="date"
|
||||
value={formData.lastInboundDate}
|
||||
onChange={(e) =>
|
||||
handleChange("lastInboundDate", e.target.value)
|
||||
}
|
||||
className="button-outlined-primary"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="lastOutboundDate">最新出庫時間</Label>
|
||||
<Input
|
||||
id="lastOutboundDate"
|
||||
type="date"
|
||||
value={formData.lastOutboundDate}
|
||||
onChange={(e) =>
|
||||
handleChange("lastOutboundDate", e.target.value)
|
||||
}
|
||||
className="button-outlined-primary"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 刪除確認對話框 */}
|
||||
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確認刪除庫存品項</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
您確定要刪除「{formData.productName}」(批號:
|
||||
{formData.batchNumber || "無"})嗎?此操作無法復原。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel className="button-outlined-primary">
|
||||
取消
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDelete}
|
||||
className="bg-destructive text-white hover:bg-destructive/90"
|
||||
>
|
||||
確認刪除
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
126
source-code/ERP(A-b)-倉庫管理/src/components/NavigationSidebar.tsx
Normal file
126
source-code/ERP(A-b)-倉庫管理/src/components/NavigationSidebar.tsx
Normal file
@@ -0,0 +1,126 @@
|
||||
import { ChevronDown, ChevronRight, Package, Warehouse } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { cn } from "./ui/utils";
|
||||
|
||||
interface MenuItem {
|
||||
id: string;
|
||||
label: string;
|
||||
icon?: React.ReactNode;
|
||||
children?: MenuItem[];
|
||||
}
|
||||
|
||||
interface NavigationSidebarProps {
|
||||
currentPath: string;
|
||||
onNavigate: (path: string) => void;
|
||||
}
|
||||
|
||||
export default function NavigationSidebar({
|
||||
currentPath,
|
||||
onNavigate,
|
||||
}: NavigationSidebarProps) {
|
||||
const [expandedItems, setExpandedItems] = useState<string[]>([
|
||||
"inventory-management",
|
||||
]);
|
||||
|
||||
const menuItems: MenuItem[] = [
|
||||
{
|
||||
id: "inventory-management",
|
||||
label: "商品與庫存管理",
|
||||
icon: <Package className="h-5 w-5" />,
|
||||
children: [
|
||||
{
|
||||
id: "warehouse-management",
|
||||
label: "倉庫管理",
|
||||
icon: <Warehouse className="h-4 w-4" />,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const toggleExpand = (itemId: string) => {
|
||||
setExpandedItems((prev) =>
|
||||
prev.includes(itemId)
|
||||
? prev.filter((id) => id !== itemId)
|
||||
: [...prev, itemId]
|
||||
);
|
||||
};
|
||||
|
||||
const renderMenuItem = (item: MenuItem, level: number = 0) => {
|
||||
const hasChildren = item.children && item.children.length > 0;
|
||||
const isExpanded = expandedItems.includes(item.id);
|
||||
const isActive = currentPath === item.id;
|
||||
|
||||
return (
|
||||
<div key={item.id}>
|
||||
<button
|
||||
onClick={() => {
|
||||
if (hasChildren) {
|
||||
toggleExpand(item.id);
|
||||
} else {
|
||||
onNavigate(item.id);
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
"w-full flex items-center gap-3 px-4 py-3 transition-all rounded-md mx-2",
|
||||
level === 0 && "hover:bg-background-light",
|
||||
level > 0 && "hover:bg-background-light-grey pl-10",
|
||||
isActive && "bg-primary-light/20 font-medium"
|
||||
)}
|
||||
>
|
||||
{hasChildren && (
|
||||
<span className="flex-shrink-0">
|
||||
{isExpanded ? (
|
||||
<ChevronDown className="h-4 w-4 text-grey-1" />
|
||||
) : (
|
||||
<ChevronRight className="h-4 w-4 text-grey-1" />
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
{!hasChildren && level > 0 && <span className="w-4" />}
|
||||
{item.icon && (
|
||||
<span
|
||||
className={cn(
|
||||
"flex-shrink-0",
|
||||
isActive ? "text-primary-main" : "text-grey-1"
|
||||
)}
|
||||
>
|
||||
{item.icon}
|
||||
</span>
|
||||
)}
|
||||
<span
|
||||
className={cn(
|
||||
"transition-colors",
|
||||
isActive ? "text-primary-main" : "text-grey-0"
|
||||
)}
|
||||
>
|
||||
{item.label}
|
||||
</span>
|
||||
</button>
|
||||
{hasChildren && isExpanded && (
|
||||
<div>
|
||||
{item.children?.map((child) => renderMenuItem(child, level + 1))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<aside className="w-64 bg-card border-r border-border h-screen flex flex-col">
|
||||
{/* Header */}
|
||||
<div className="p-6 border-b border-border">
|
||||
<h2 className="text-primary-main">甜點店 ERP 系統</h2>
|
||||
</div>
|
||||
|
||||
{/* Navigation Menu */}
|
||||
<nav className="flex-1 overflow-y-auto py-4">
|
||||
{menuItems.map((item) => renderMenuItem(item))}
|
||||
</nav>
|
||||
|
||||
{/* Footer */}
|
||||
<div className="p-4 border-t border-border">
|
||||
<p className="caption text-muted-foreground">版本 1.0.0</p>
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
127
source-code/ERP(A-b)-倉庫管理/src/components/SafetyStockPage.tsx
Normal file
127
source-code/ERP(A-b)-倉庫管理/src/components/SafetyStockPage.tsx
Normal file
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* 安全庫存設定頁面
|
||||
*/
|
||||
|
||||
import { useState } from "react";
|
||||
import { ArrowLeft, Plus, Shield } from "lucide-react";
|
||||
import { Button } from "./ui/button";
|
||||
import { SafetyStockSetting, WarehouseInventory } from "../types/warehouse";
|
||||
import { AVAILABLE_PRODUCTS } from "../constants/products";
|
||||
import SafetyStockList from "./safety-stock/SafetyStockList";
|
||||
import AddSafetyStockDialog from "./safety-stock/AddSafetyStockDialog";
|
||||
import EditSafetyStockDialog from "./safety-stock/EditSafetyStockDialog";
|
||||
|
||||
interface SafetyStockPageProps {
|
||||
warehouseId: string;
|
||||
warehouseName: string;
|
||||
safetyStockSettings: SafetyStockSetting[];
|
||||
inventories: WarehouseInventory[];
|
||||
onBack: () => void;
|
||||
onSave: (settings: SafetyStockSetting[]) => void;
|
||||
}
|
||||
|
||||
export default function SafetyStockPage({
|
||||
warehouseId,
|
||||
warehouseName,
|
||||
safetyStockSettings,
|
||||
inventories,
|
||||
onBack,
|
||||
onSave,
|
||||
}: SafetyStockPageProps) {
|
||||
const [settings, setSettings] = useState<SafetyStockSetting[]>(safetyStockSettings);
|
||||
const [showAddDialog, setShowAddDialog] = useState(false);
|
||||
const [editingSetting, setEditingSetting] = useState<SafetyStockSetting | null>(null);
|
||||
|
||||
const handleAdd = (newSettings: SafetyStockSetting[]) => {
|
||||
const updatedSettings = [...settings, ...newSettings];
|
||||
setSettings(updatedSettings);
|
||||
onSave(updatedSettings);
|
||||
setShowAddDialog(false);
|
||||
};
|
||||
|
||||
const handleEdit = (updatedSetting: SafetyStockSetting) => {
|
||||
const updatedSettings = settings.map((s) =>
|
||||
s.id === updatedSetting.id ? updatedSetting : s
|
||||
);
|
||||
setSettings(updatedSettings);
|
||||
onSave(updatedSettings);
|
||||
setEditingSetting(null);
|
||||
};
|
||||
|
||||
const handleDelete = (id: string) => {
|
||||
const updatedSettings = settings.filter((s) => s.id !== id);
|
||||
setSettings(updatedSettings);
|
||||
onSave(updatedSettings);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
{/* 頁面標題與麵包屑 */}
|
||||
<div className="mb-6">
|
||||
<Button
|
||||
onClick={onBack}
|
||||
variant="ghost"
|
||||
className="mb-4 -ml-2 hover:bg-background-light"
|
||||
>
|
||||
<ArrowLeft className="mr-2 h-4 w-4" />
|
||||
返回庫存管理
|
||||
</Button>
|
||||
|
||||
<div className="flex items-center gap-2 text-sm text-grey-2 mb-2">
|
||||
<span>商品與庫存管理</span>
|
||||
<span>/</span>
|
||||
<span>倉庫管理</span>
|
||||
<span>/</span>
|
||||
<span>庫存管理</span>
|
||||
<span>/</span>
|
||||
<span className="text-grey-0">安全庫存設定</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<div className="flex items-center gap-3 mb-2">
|
||||
<Shield className="h-8 w-8 text-primary" />
|
||||
<h1>安全庫存設定 - {warehouseName}</h1>
|
||||
</div>
|
||||
<p className="text-gray-600">設定商品的安全庫存量,當庫存低於安全值時將發出警告</p>
|
||||
</div>
|
||||
<Button
|
||||
onClick={() => setShowAddDialog(true)}
|
||||
className="button-filled-primary"
|
||||
>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增安全庫存
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 安全庫存列表 */}
|
||||
<SafetyStockList
|
||||
settings={settings}
|
||||
inventories={inventories}
|
||||
onEdit={setEditingSetting}
|
||||
onDelete={handleDelete}
|
||||
/>
|
||||
|
||||
{/* 新增對話框 */}
|
||||
<AddSafetyStockDialog
|
||||
open={showAddDialog}
|
||||
onOpenChange={setShowAddDialog}
|
||||
warehouseId={warehouseId}
|
||||
existingSettings={settings}
|
||||
availableProducts={AVAILABLE_PRODUCTS}
|
||||
onAdd={handleAdd}
|
||||
/>
|
||||
|
||||
{/* 編輯對話框 */}
|
||||
{editingSetting && (
|
||||
<EditSafetyStockDialog
|
||||
open={!!editingSetting}
|
||||
onOpenChange={(open) => !open && setEditingSetting(null)}
|
||||
setting={editingSetting}
|
||||
onSave={handleEdit}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
375
source-code/ERP(A-b)-倉庫管理/src/components/TransferOrderDialog.tsx
Normal file
375
source-code/ERP(A-b)-倉庫管理/src/components/TransferOrderDialog.tsx
Normal file
@@ -0,0 +1,375 @@
|
||||
/**
|
||||
* 撥補單對話框元件
|
||||
* 重構後:加入驗證邏輯模組化
|
||||
*/
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "./ui/dialog";
|
||||
import { Label } from "./ui/label";
|
||||
import { Input } from "./ui/input";
|
||||
import { Button } from "./ui/button";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "./ui/select";
|
||||
import { Textarea } from "./ui/textarea";
|
||||
import { toast } from "sonner@2.0.3";
|
||||
import { Warehouse, WarehouseInventory, TransferOrder, TransferOrderStatus } from "../types/warehouse";
|
||||
import { validateTransferOrder, validateTransferQuantity } from "../utils/validation";
|
||||
|
||||
export type { TransferOrder };
|
||||
|
||||
interface TransferOrderDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
order: TransferOrder | null;
|
||||
warehouses: Warehouse[];
|
||||
inventories: WarehouseInventory[];
|
||||
onSave: (order: Omit<TransferOrder, "id" | "createdAt" | "orderNumber">) => void;
|
||||
}
|
||||
|
||||
interface AvailableProduct {
|
||||
productId: string;
|
||||
productName: string;
|
||||
batchNumber: string;
|
||||
availableQty: number;
|
||||
}
|
||||
|
||||
export default function TransferOrderDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
order,
|
||||
warehouses,
|
||||
inventories,
|
||||
onSave,
|
||||
}: TransferOrderDialogProps) {
|
||||
const [formData, setFormData] = useState({
|
||||
sourceWarehouseId: "",
|
||||
targetWarehouseId: "",
|
||||
productId: "",
|
||||
productName: "",
|
||||
batchNumber: "",
|
||||
quantity: 0,
|
||||
transferDate: new Date().toISOString().split("T")[0],
|
||||
status: "待處理" as TransferOrderStatus,
|
||||
notes: "",
|
||||
});
|
||||
|
||||
const [availableProducts, setAvailableProducts] = useState<AvailableProduct[]>([]);
|
||||
|
||||
// 當對話框開啟或訂單變更時,重置表單
|
||||
useEffect(() => {
|
||||
if (order) {
|
||||
setFormData({
|
||||
sourceWarehouseId: order.sourceWarehouseId,
|
||||
targetWarehouseId: order.targetWarehouseId,
|
||||
productId: order.productId,
|
||||
productName: order.productName,
|
||||
batchNumber: order.batchNumber,
|
||||
quantity: order.quantity,
|
||||
transferDate: order.transferDate,
|
||||
status: order.status,
|
||||
notes: order.notes || "",
|
||||
});
|
||||
} else {
|
||||
setFormData({
|
||||
sourceWarehouseId: "",
|
||||
targetWarehouseId: "",
|
||||
productId: "",
|
||||
productName: "",
|
||||
batchNumber: "",
|
||||
quantity: 0,
|
||||
transferDate: new Date().toISOString().split("T")[0],
|
||||
status: "待處理",
|
||||
notes: "",
|
||||
});
|
||||
}
|
||||
}, [order, open]);
|
||||
|
||||
// 當來源倉庫變更時,更新可用商品列表
|
||||
useEffect(() => {
|
||||
if (formData.sourceWarehouseId) {
|
||||
const products = inventories
|
||||
.filter(
|
||||
(inv) => inv.warehouseId === formData.sourceWarehouseId && inv.quantity > 0
|
||||
)
|
||||
.map((inv) => ({
|
||||
productId: inv.productId,
|
||||
productName: inv.productName,
|
||||
batchNumber: inv.batchNumber,
|
||||
availableQty: inv.quantity,
|
||||
}));
|
||||
setAvailableProducts(products);
|
||||
} else {
|
||||
setAvailableProducts([]);
|
||||
}
|
||||
}, [formData.sourceWarehouseId, inventories]);
|
||||
|
||||
const handleSubmit = () => {
|
||||
// 基本驗證
|
||||
const validation = validateTransferOrder(formData);
|
||||
if (!validation.isValid) {
|
||||
toast.error(validation.error);
|
||||
return;
|
||||
}
|
||||
|
||||
// 檢查可用數量
|
||||
const selectedProduct = availableProducts.find(
|
||||
(p) => p.productId === formData.productId && p.batchNumber === formData.batchNumber
|
||||
);
|
||||
|
||||
if (selectedProduct) {
|
||||
const quantityValidation = validateTransferQuantity(
|
||||
formData.quantity,
|
||||
selectedProduct.availableQty
|
||||
);
|
||||
if (!quantityValidation.isValid) {
|
||||
toast.error(quantityValidation.error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const sourceWarehouse = warehouses.find((w) => w.id === formData.sourceWarehouseId);
|
||||
const targetWarehouse = warehouses.find((w) => w.id === formData.targetWarehouseId);
|
||||
|
||||
onSave({
|
||||
sourceWarehouseId: formData.sourceWarehouseId,
|
||||
sourceWarehouseName: sourceWarehouse?.name || "",
|
||||
targetWarehouseId: formData.targetWarehouseId,
|
||||
targetWarehouseName: targetWarehouse?.name || "",
|
||||
productId: formData.productId,
|
||||
productName: formData.productName,
|
||||
batchNumber: formData.batchNumber,
|
||||
quantity: formData.quantity,
|
||||
transferDate: formData.transferDate,
|
||||
status: formData.status,
|
||||
notes: formData.notes,
|
||||
});
|
||||
};
|
||||
|
||||
const handleProductChange = (productKey: string) => {
|
||||
const [productId, batchNumber] = productKey.split("|||");
|
||||
const product = availableProducts.find(
|
||||
(p) => p.productId === productId && p.batchNumber === batchNumber
|
||||
);
|
||||
if (product) {
|
||||
setFormData({
|
||||
...formData,
|
||||
productId: product.productId,
|
||||
productName: product.productName,
|
||||
batchNumber: product.batchNumber,
|
||||
quantity: 0,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const selectedProduct = availableProducts.find(
|
||||
(p) => p.productId === formData.productId && p.batchNumber === formData.batchNumber
|
||||
);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-2xl max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{order ? "編輯撥補單" : "新增撥補單"}</DialogTitle>
|
||||
<DialogDescription>填寫撥補單資訊</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4 py-4">
|
||||
{/* 來源倉庫和目標倉庫 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="sourceWarehouse">
|
||||
來源倉庫 <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
<Select
|
||||
value={formData.sourceWarehouseId}
|
||||
onValueChange={(value) =>
|
||||
setFormData({
|
||||
...formData,
|
||||
sourceWarehouseId: value,
|
||||
productId: "",
|
||||
productName: "",
|
||||
batchNumber: "",
|
||||
quantity: 0,
|
||||
})
|
||||
}
|
||||
disabled={!!order}
|
||||
>
|
||||
<SelectTrigger id="sourceWarehouse">
|
||||
<SelectValue placeholder="選擇來源倉庫" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{warehouses.map((warehouse) => (
|
||||
<SelectItem key={warehouse.id} value={warehouse.id}>
|
||||
{warehouse.name} ({warehouse.type})
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="targetWarehouse">
|
||||
目標倉庫 <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
<Select
|
||||
value={formData.targetWarehouseId}
|
||||
onValueChange={(value) =>
|
||||
setFormData({ ...formData, targetWarehouseId: value })
|
||||
}
|
||||
disabled={!!order}
|
||||
>
|
||||
<SelectTrigger id="targetWarehouse">
|
||||
<SelectValue placeholder="選擇目標倉庫" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{warehouses
|
||||
.filter((w) => w.id !== formData.sourceWarehouseId)
|
||||
.map((warehouse) => (
|
||||
<SelectItem key={warehouse.id} value={warehouse.id}>
|
||||
{warehouse.name} ({warehouse.type})
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 商品選擇 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="product">
|
||||
撥補商品 <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
<Select
|
||||
value={
|
||||
formData.productId && formData.batchNumber
|
||||
? `${formData.productId}|||${formData.batchNumber}`
|
||||
: ""
|
||||
}
|
||||
onValueChange={handleProductChange}
|
||||
disabled={!formData.sourceWarehouseId || !!order}
|
||||
>
|
||||
<SelectTrigger id="product">
|
||||
<SelectValue placeholder="選擇商品與批號" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{availableProducts.length === 0 ? (
|
||||
<div className="p-2 text-sm text-gray-500 text-center">
|
||||
{formData.sourceWarehouseId ? "該倉庫無可用庫存" : "請先選擇來源倉庫"}
|
||||
</div>
|
||||
) : (
|
||||
availableProducts.map((product) => (
|
||||
<SelectItem
|
||||
key={`${product.productId}|||${product.batchNumber}`}
|
||||
value={`${product.productId}|||${product.batchNumber}`}
|
||||
>
|
||||
{product.productName} - 批號: {product.batchNumber} (庫存:{" "}
|
||||
{product.availableQty})
|
||||
</SelectItem>
|
||||
))
|
||||
)}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* 數量和日期 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="quantity">
|
||||
撥補數量 <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="quantity"
|
||||
type="number"
|
||||
min="0"
|
||||
max={selectedProduct?.availableQty || 0}
|
||||
value={formData.quantity}
|
||||
onChange={(e) =>
|
||||
setFormData({ ...formData, quantity: Number(e.target.value) })
|
||||
}
|
||||
/>
|
||||
{selectedProduct && (
|
||||
<p className="text-sm text-gray-500">
|
||||
可用庫存: {selectedProduct.availableQty}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="transferDate">
|
||||
撥補日期 <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="transferDate"
|
||||
type="date"
|
||||
value={formData.transferDate}
|
||||
onChange={(e) =>
|
||||
setFormData({ ...formData, transferDate: e.target.value })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 狀態(僅編輯時顯示) */}
|
||||
{order && (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="status">狀態</Label>
|
||||
<Select
|
||||
value={formData.status}
|
||||
onValueChange={(value) =>
|
||||
setFormData({ ...formData, status: value as TransferOrderStatus })
|
||||
}
|
||||
>
|
||||
<SelectTrigger id="status">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="待處理">待處理</SelectItem>
|
||||
<SelectItem value="處理中">處理中</SelectItem>
|
||||
<SelectItem value="已完成">已完成</SelectItem>
|
||||
<SelectItem value="已取消">已取消</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 備註 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="notes">備註</Label>
|
||||
<Textarea
|
||||
id="notes"
|
||||
placeholder="請輸入備註(選填)"
|
||||
value={formData.notes}
|
||||
onChange={(e) => setFormData({ ...formData, notes: e.target.value })}
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => onOpenChange(false)}
|
||||
className="button-outlined-primary"
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button onClick={handleSubmit} className="button-filled-primary">
|
||||
{order ? "更新" : "新增"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
347
source-code/ERP(A-b)-倉庫管理/src/components/WarehouseDialog.tsx
Normal file
347
source-code/ERP(A-b)-倉庫管理/src/components/WarehouseDialog.tsx
Normal file
@@ -0,0 +1,347 @@
|
||||
/**
|
||||
* 倉庫對話框元件
|
||||
* 重構後:加入驗證邏輯
|
||||
*/
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "./ui/dialog";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "./ui/alert-dialog";
|
||||
import { Input } from "./ui/input";
|
||||
import { Label } from "./ui/label";
|
||||
import { Textarea } from "./ui/textarea";
|
||||
import { Button } from "./ui/button";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "./ui/select";
|
||||
import { Trash2 } from "lucide-react";
|
||||
import { Warehouse, WarehouseType, Store } from "../types/warehouse";
|
||||
import { validateWarehouse } from "../utils/validation";
|
||||
import { toast } from "sonner@2.0.3";
|
||||
|
||||
interface WarehouseDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
warehouse: Warehouse | null;
|
||||
onSave: (warehouse: Omit<Warehouse, "id" | "createdAt">) => void;
|
||||
onDelete?: (warehouseId: string) => void;
|
||||
stores?: Store[]; // 門市列表
|
||||
}
|
||||
|
||||
export default function WarehouseDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
warehouse,
|
||||
onSave,
|
||||
onDelete,
|
||||
stores = [], // 預設為空陣列
|
||||
}: WarehouseDialogProps) {
|
||||
const [formData, setFormData] = useState<{
|
||||
name: string;
|
||||
address: string;
|
||||
manager: string;
|
||||
phone: string;
|
||||
description: string;
|
||||
type: WarehouseType;
|
||||
storeId?: string;
|
||||
storeName?: string;
|
||||
}>({
|
||||
name: "",
|
||||
address: "",
|
||||
manager: "",
|
||||
phone: "",
|
||||
description: "",
|
||||
type: "中央倉庫",
|
||||
storeId: undefined,
|
||||
storeName: undefined,
|
||||
});
|
||||
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (warehouse) {
|
||||
setFormData({
|
||||
name: warehouse.name,
|
||||
address: warehouse.address,
|
||||
manager: warehouse.manager,
|
||||
phone: warehouse.phone,
|
||||
description: warehouse.description,
|
||||
type: warehouse.type,
|
||||
storeId: warehouse.storeId,
|
||||
storeName: warehouse.storeName,
|
||||
});
|
||||
} else {
|
||||
setFormData({
|
||||
name: "",
|
||||
address: "",
|
||||
manager: "",
|
||||
phone: "",
|
||||
description: "",
|
||||
type: "中央倉庫",
|
||||
storeId: undefined,
|
||||
storeName: undefined,
|
||||
});
|
||||
}
|
||||
}, [warehouse, open]);
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
const validation = validateWarehouse(formData);
|
||||
if (!validation.isValid) {
|
||||
toast.error(validation.error);
|
||||
return;
|
||||
}
|
||||
|
||||
onSave(formData);
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (warehouse && onDelete) {
|
||||
onDelete(warehouse.id);
|
||||
setShowDeleteDialog(false);
|
||||
onOpenChange(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-2xl max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{warehouse ? "編輯倉庫" : "新增倉庫"}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{warehouse ? "修改倉庫資訊" : "建立新的倉庫資訊"}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className="space-y-6 py-4">
|
||||
{/* 區塊 A:基本資訊 */}
|
||||
<div className="space-y-4">
|
||||
<div className="border-b pb-2">
|
||||
<h4 className="text-sm text-gray-700">基本資訊</h4>
|
||||
</div>
|
||||
|
||||
{/* 倉庫名稱 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="name">
|
||||
倉庫名稱 <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="name"
|
||||
value={formData.name}
|
||||
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
|
||||
placeholder="例:中央倉庫"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 倉庫類型 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="type">
|
||||
倉庫類型 <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
<Select
|
||||
value={formData.type}
|
||||
onValueChange={(value) => {
|
||||
const newType = value as WarehouseType;
|
||||
setFormData({
|
||||
...formData,
|
||||
type: newType,
|
||||
// 切換到中央倉庫時清空門市綁定
|
||||
storeId: newType === "中央倉庫" ? undefined : formData.storeId,
|
||||
storeName: newType === "中央倉庫" ? undefined : formData.storeName,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<SelectTrigger id="type">
|
||||
<SelectValue placeholder="選擇倉庫類型">{formData.type}</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="中央倉庫">中央倉庫</SelectItem>
|
||||
<SelectItem value="門市">門市</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* 綁定門市 - 僅當類型為門市時顯示 */}
|
||||
{formData.type === "門市" && (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="store">綁定門市</Label>
|
||||
<Select
|
||||
value={formData.storeId || ""}
|
||||
onValueChange={(value) => {
|
||||
const selectedStore = stores.find((s) => s.id === value);
|
||||
setFormData({
|
||||
...formData,
|
||||
storeId: value,
|
||||
storeName: selectedStore?.name,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<SelectTrigger id="store">
|
||||
<SelectValue placeholder="選擇門市">
|
||||
{formData.storeName || "請選擇門市"}
|
||||
</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{stores.length === 0 ? (
|
||||
<div className="px-2 py-1.5 text-sm text-gray-500">
|
||||
目前沒有可用的門市
|
||||
</div>
|
||||
) : (
|
||||
stores.map((store) => (
|
||||
<SelectItem key={store.id} value={store.id}>
|
||||
{store.name}
|
||||
</SelectItem>
|
||||
))
|
||||
)}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{formData.storeId && (
|
||||
<p className="text-sm text-gray-500">
|
||||
{stores.find((s) => s.id === formData.storeId)?.address}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 區塊 B:位置 */}
|
||||
<div className="space-y-4">
|
||||
<div className="border-b pb-2">
|
||||
<h4 className="text-sm text-gray-700">位置</h4>
|
||||
</div>
|
||||
|
||||
{/* 倉庫地址 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="address">
|
||||
倉庫地址 <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="address"
|
||||
value={formData.address}
|
||||
onChange={(e) => setFormData({ ...formData, address: e.target.value })}
|
||||
placeholder="例:台北市信義區信義路五段7號"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 區塊 C:聯絡資訊 */}
|
||||
<div className="space-y-4">
|
||||
<div className="border-b pb-2">
|
||||
<h4 className="text-sm text-gray-700">聯絡資訊</h4>
|
||||
</div>
|
||||
|
||||
{/* 負責人和聯絡電話 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="manager">負責人</Label>
|
||||
<Input
|
||||
id="manager"
|
||||
value={formData.manager}
|
||||
onChange={(e) =>
|
||||
setFormData({ ...formData, manager: e.target.value })
|
||||
}
|
||||
placeholder="例:張經理"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="phone">聯絡電話</Label>
|
||||
<Input
|
||||
id="phone"
|
||||
value={formData.phone}
|
||||
onChange={(e) => setFormData({ ...formData, phone: e.target.value })}
|
||||
placeholder="例:02-1234-5678"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 備註說明 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="description">備註說明</Label>
|
||||
<Textarea
|
||||
id="description"
|
||||
value={formData.description}
|
||||
onChange={(e) =>
|
||||
setFormData({ ...formData, description: e.target.value })
|
||||
}
|
||||
placeholder="其他說明"
|
||||
rows={2}
|
||||
className="resize-none"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter className="gap-2">
|
||||
{warehouse && onDelete && (
|
||||
<Button
|
||||
type="button"
|
||||
onClick={() => setShowDeleteDialog(true)}
|
||||
variant="outline"
|
||||
className="group mr-auto border-destructive text-destructive hover:bg-destructive hover:text-white"
|
||||
>
|
||||
<Trash2 className="mr-2 h-4 w-4 group-hover:text-white" />
|
||||
刪除倉庫
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
type="button"
|
||||
onClick={() => onOpenChange(false)}
|
||||
className="button-outlined-primary"
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button type="submit" className="button-filled-primary">
|
||||
{warehouse ? "更新" : "新增"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* 刪除確認對話框 */}
|
||||
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確認刪除倉庫</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
確定要刪除「{warehouse?.name}」嗎?此操作無法復原。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDelete}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
確認刪除
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,230 @@
|
||||
/**
|
||||
* 倉庫庫存頁面元件
|
||||
* 重構後:邏輯更清晰,元件更模組化
|
||||
*/
|
||||
|
||||
import { useState, useMemo, useEffect } from "react";
|
||||
import { ArrowLeft, PackagePlus, AlertTriangle, Shield } from "lucide-react";
|
||||
import { Button } from "./ui/button";
|
||||
import { WarehouseInventory, SafetyStockSetting } from "../types/warehouse";
|
||||
import InventoryStats from "./inventory/InventoryStats";
|
||||
import InventoryToolbar from "./inventory/InventoryToolbar";
|
||||
import InventoryTable, { InventoryItemWithId, ProductGroup } from "./inventory/InventoryTable";
|
||||
import { AVAILABLE_PRODUCTS } from "../constants/products";
|
||||
import { useInventoryFilter } from "../hooks/useInventoryFilter";
|
||||
import { calculateLowStockCount } from "../utils/inventory";
|
||||
|
||||
interface WarehouseInventoryPageProps {
|
||||
warehouseId: string;
|
||||
warehouseName: string;
|
||||
inventories: WarehouseInventory[];
|
||||
safetyStockSettings: SafetyStockSetting[];
|
||||
onBack: () => void;
|
||||
onNavigateToAddInventory: () => void;
|
||||
onNavigateToEditInventory: (inventoryId: string) => void;
|
||||
onNavigateToSafetyStock: () => void;
|
||||
}
|
||||
|
||||
export default function WarehouseInventoryPage({
|
||||
warehouseId,
|
||||
warehouseName,
|
||||
inventories,
|
||||
safetyStockSettings,
|
||||
onBack,
|
||||
onNavigateToAddInventory,
|
||||
onNavigateToEditInventory,
|
||||
onNavigateToSafetyStock,
|
||||
}: WarehouseInventoryPageProps) {
|
||||
// 初始化庫存項目(加入唯一 ID)
|
||||
const initializeItems = (items: WarehouseInventory[]): InventoryItemWithId[] => {
|
||||
return items.map((item, index) => ({
|
||||
...item,
|
||||
inventoryId: `inv-${Date.now()}-${index}`,
|
||||
}));
|
||||
};
|
||||
|
||||
const [items, setItems] = useState<InventoryItemWithId[]>(
|
||||
initializeItems(inventories)
|
||||
);
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const [typeFilter, setTypeFilter] = useState<string>("all");
|
||||
|
||||
// 合併有庫存的商品和只有安全庫存設定的商品
|
||||
const mergedProductGroups = useMemo(() => {
|
||||
const productGroups: ProductGroup[] = [];
|
||||
|
||||
// 取得該倉庫的安全庫存設定
|
||||
const warehouseSettings = safetyStockSettings.filter(
|
||||
(s) => s.warehouseId === warehouseId
|
||||
);
|
||||
|
||||
// 建立商品 ID 到商品資訊的映射
|
||||
const processedProductIds = new Set<string>();
|
||||
|
||||
// 先處理有庫存的商品
|
||||
const groupedByProduct: { [productId: string]: InventoryItemWithId[] } = {};
|
||||
items.forEach((item) => {
|
||||
if (!groupedByProduct[item.productId]) {
|
||||
groupedByProduct[item.productId] = [];
|
||||
}
|
||||
groupedByProduct[item.productId].push(item);
|
||||
});
|
||||
|
||||
Object.entries(groupedByProduct).forEach(([productId, productItems]) => {
|
||||
const safetySetting = warehouseSettings.find((s) => s.productId === productId);
|
||||
productGroups.push({
|
||||
productId,
|
||||
productName: productItems[0].productName,
|
||||
items: productItems,
|
||||
safetySetting,
|
||||
});
|
||||
processedProductIds.add(productId);
|
||||
});
|
||||
|
||||
// 再處理沒有庫存但有安全庫存設定的商品
|
||||
warehouseSettings.forEach((setting) => {
|
||||
if (!processedProductIds.has(setting.productId)) {
|
||||
productGroups.push({
|
||||
productId: setting.productId,
|
||||
productName: setting.productName,
|
||||
items: [], // 沒有任何批號
|
||||
safetySetting: setting,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return productGroups;
|
||||
}, [items, safetyStockSettings, warehouseId]);
|
||||
|
||||
// 使用篩選 Hook
|
||||
const filteredItems = useInventoryFilter(items, searchTerm, typeFilter);
|
||||
|
||||
// 篩選合併後的商品群組
|
||||
const filteredProductGroups = useMemo(() => {
|
||||
if (!searchTerm && typeFilter === "all") {
|
||||
return mergedProductGroups;
|
||||
}
|
||||
|
||||
return mergedProductGroups.filter((group) => {
|
||||
// 搜尋條件
|
||||
const matchesSearch = !searchTerm ||
|
||||
group.productName.toLowerCase().includes(searchTerm.toLowerCase());
|
||||
|
||||
// 類型篩選
|
||||
const matchesType = typeFilter === "all" ||
|
||||
(group.safetySetting && group.safetySetting.productType === typeFilter);
|
||||
|
||||
return matchesSearch && matchesType;
|
||||
});
|
||||
}, [mergedProductGroups, searchTerm, typeFilter]);
|
||||
|
||||
// 計算統計資訊
|
||||
const totalItems = items.length;
|
||||
const totalQuantity = items.reduce((sum, item) => sum + item.quantity, 0);
|
||||
const lowStockItems = calculateLowStockCount(items, warehouseId, safetyStockSettings);
|
||||
|
||||
// 獲取當前庫存中的商品列表(用於篩選器)
|
||||
const productsInInventory = useMemo(() => {
|
||||
const uniqueProductIds = Array.from(new Set(items.map((item) => item.productId)));
|
||||
return uniqueProductIds
|
||||
.map((productId) => AVAILABLE_PRODUCTS.find((p) => p.id === productId))
|
||||
.filter((p) => p !== undefined);
|
||||
}, [items]);
|
||||
|
||||
// 同步更新本地狀態
|
||||
useEffect(() => {
|
||||
setItems(initializeItems(inventories));
|
||||
}, [inventories]);
|
||||
|
||||
return (
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
{/* 頁面標題與麵包屑 */}
|
||||
<div className="mb-6">
|
||||
<Button
|
||||
onClick={onBack}
|
||||
variant="ghost"
|
||||
className="mb-4 -ml-2 hover:bg-background-light"
|
||||
>
|
||||
<ArrowLeft className="mr-2 h-4 w-4" />
|
||||
返回倉庫列表
|
||||
</Button>
|
||||
|
||||
<div className="flex items-center gap-2 text-sm text-grey-2 mb-2">
|
||||
<span>商品與庫存管理</span>
|
||||
<span>/</span>
|
||||
<span>倉庫管理</span>
|
||||
<span>/</span>
|
||||
<span className="text-grey-0">庫存管理</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="mb-2">庫存管理 - {warehouseName}</h1>
|
||||
<p className="text-gray-600">設定此倉庫內的商品庫存數量與存放位置</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
{/* 安全庫存設定按鈕 */}
|
||||
<Button
|
||||
onClick={onNavigateToSafetyStock}
|
||||
variant="outline"
|
||||
className="button-outlined-primary"
|
||||
>
|
||||
<Shield className="mr-2 h-4 w-4" />
|
||||
安全庫存設定
|
||||
</Button>
|
||||
|
||||
{/* 庫存警告按鈕 */}
|
||||
<Button
|
||||
variant="outline"
|
||||
className={`button-outlined-primary ${
|
||||
lowStockItems > 0
|
||||
? "border-red-500 text-red-600 hover:bg-red-50"
|
||||
: "border-green-500 text-green-600 hover:bg-green-50"
|
||||
}`}
|
||||
>
|
||||
<AlertTriangle className="mr-2 h-4 w-4" />
|
||||
庫存警告:{lowStockItems} 項
|
||||
</Button>
|
||||
|
||||
{/* 新增庫存按鈕 */}
|
||||
<Button
|
||||
onClick={onNavigateToAddInventory}
|
||||
className="button-filled-primary"
|
||||
>
|
||||
<PackagePlus className="mr-2 h-4 w-4" />
|
||||
新增庫存
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 篩選工具列 */}
|
||||
{(items.length > 0 || safetyStockSettings.some(s => s.warehouseId === warehouseId)) && (
|
||||
<div className="mb-4">
|
||||
<InventoryToolbar
|
||||
searchTerm={searchTerm}
|
||||
onSearchChange={setSearchTerm}
|
||||
typeFilter={typeFilter}
|
||||
onTypeFilterChange={setTypeFilter}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 庫存表格 */}
|
||||
<div className="bg-white rounded-lg shadow-sm border overflow-hidden">
|
||||
{mergedProductGroups.length === 0 ? (
|
||||
<div className="text-center py-12 text-gray-400">
|
||||
<p>尚無庫存品項或安全庫存設定</p>
|
||||
<p className="text-sm mt-1">點擊「新增庫存」或「安全庫存設定」開始設定</p>
|
||||
</div>
|
||||
) : (
|
||||
<InventoryTable
|
||||
productGroups={filteredProductGroups}
|
||||
onEdit={onNavigateToEditInventory}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
301
source-code/ERP(A-b)-倉庫管理/src/components/WarehouseManagement.tsx
Normal file
301
source-code/ERP(A-b)-倉庫管理/src/components/WarehouseManagement.tsx
Normal file
@@ -0,0 +1,301 @@
|
||||
/**
|
||||
* 倉庫管理主元件
|
||||
* 重構後:職責更清晰,邏輯更模組化
|
||||
*/
|
||||
|
||||
import { useState } from "react";
|
||||
import { Plus, ArrowRightLeft } from "lucide-react";
|
||||
import { Button } from "./ui/button";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "./ui/alert-dialog";
|
||||
import { toast } from "sonner@2.0.3";
|
||||
import WarehouseDialog from "./WarehouseDialog";
|
||||
import TransferOrderDialog, { TransferOrder } from "./TransferOrderDialog";
|
||||
import SearchToolbar from "./shared/SearchToolbar";
|
||||
import WarehouseFilter from "./warehouse/WarehouseFilter";
|
||||
import WarehouseCard from "./warehouse/WarehouseCard";
|
||||
import WarehouseEmptyState from "./warehouse/WarehouseEmptyState";
|
||||
import { Warehouse, WarehouseInventory, Store, SafetyStockSetting } from "../types/warehouse";
|
||||
import { useWarehouseFilter } from "../hooks/useWarehouseFilter";
|
||||
import { calculateWarehouseStats, hasWarehouseWarning } from "../utils/inventory";
|
||||
import { generateId, getCurrentDate, generateOrderNumber } from "../utils/format";
|
||||
|
||||
export type { Warehouse, WarehouseInventory };
|
||||
|
||||
interface WarehouseManagementProps {
|
||||
onNavigateToInventory: (warehouseId: string) => void;
|
||||
inventories: WarehouseInventory[];
|
||||
onUpdateInventories: (inventories: WarehouseInventory[]) => void;
|
||||
safetyStockSettings: SafetyStockSetting[];
|
||||
}
|
||||
|
||||
export default function WarehouseManagement({
|
||||
onNavigateToInventory,
|
||||
inventories,
|
||||
onUpdateInventories,
|
||||
safetyStockSettings,
|
||||
}: WarehouseManagementProps) {
|
||||
// 門市列表(Mock 資料)
|
||||
const [stores] = useState<Store[]>([
|
||||
{
|
||||
id: "store-1",
|
||||
name: "信義門市",
|
||||
address: "台北市信義區信義路五段10號",
|
||||
},
|
||||
{
|
||||
id: "store-2",
|
||||
name: "敦化門市",
|
||||
address: "台北市大安區敦化南路一段100號",
|
||||
},
|
||||
{
|
||||
id: "store-3",
|
||||
name: "南京門市",
|
||||
address: "台北市松山區南京東路三段256號",
|
||||
},
|
||||
]);
|
||||
|
||||
// 倉庫狀態
|
||||
const [warehouses, setWarehouses] = useState<Warehouse[]>([
|
||||
{
|
||||
id: "1",
|
||||
name: "中央倉庫",
|
||||
address: "台北市信義區信義路五段7號",
|
||||
manager: "張經理",
|
||||
phone: "02-1234-5678",
|
||||
description: "主要原物料儲存倉庫",
|
||||
createdAt: "2025-11-01",
|
||||
type: "中央倉庫",
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
name: "門市冷藏庫",
|
||||
address: "台北市大安區敦化南路一段100號",
|
||||
manager: "李主管",
|
||||
phone: "02-8765-4321",
|
||||
description: "門市專用冷藏倉庫",
|
||||
createdAt: "2025-11-10",
|
||||
type: "門市",
|
||||
storeId: "store-2",
|
||||
storeName: "敦化門市",
|
||||
},
|
||||
]);
|
||||
|
||||
// 篩選狀態
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const [typeFilter, setTypeFilter] = useState<string>("all");
|
||||
|
||||
// 對話框狀態
|
||||
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
||||
const [editingWarehouse, setEditingWarehouse] = useState<Warehouse | null>(null);
|
||||
const [transferOrderDialogOpen, setTransferOrderDialogOpen] = useState(false);
|
||||
const [editingTransferOrder, setEditingTransferOrder] = useState<TransferOrder | null>(null);
|
||||
const [transferOrders, setTransferOrders] = useState<TransferOrder[]>([]);
|
||||
|
||||
// 使用篩選 Hook
|
||||
const filteredWarehouses = useWarehouseFilter(warehouses, searchTerm, typeFilter);
|
||||
|
||||
// 倉庫操作處理函式
|
||||
const handleAddWarehouse = () => {
|
||||
setEditingWarehouse(null);
|
||||
setIsDialogOpen(true);
|
||||
};
|
||||
|
||||
const handleEditWarehouse = (warehouse: Warehouse) => {
|
||||
setEditingWarehouse(warehouse);
|
||||
setIsDialogOpen(true);
|
||||
};
|
||||
|
||||
const handleSaveWarehouse = (warehouse: Omit<Warehouse, "id" | "createdAt">) => {
|
||||
if (editingWarehouse) {
|
||||
setWarehouses(
|
||||
warehouses.map((w) =>
|
||||
w.id === editingWarehouse.id ? { ...w, ...warehouse } : w
|
||||
)
|
||||
);
|
||||
toast.success("倉庫資料已更新");
|
||||
} else {
|
||||
const newWarehouse: Warehouse = {
|
||||
id: generateId(),
|
||||
...warehouse,
|
||||
createdAt: getCurrentDate(),
|
||||
};
|
||||
setWarehouses([...warehouses, newWarehouse]);
|
||||
toast.success("倉庫已新增");
|
||||
}
|
||||
setIsDialogOpen(false);
|
||||
setEditingWarehouse(null);
|
||||
};
|
||||
|
||||
const handleDeleteWarehouse = (id: string) => {
|
||||
setWarehouses(warehouses.filter((w) => w.id !== id));
|
||||
onUpdateInventories(
|
||||
inventories.filter((inv) => inv.warehouseId !== id)
|
||||
);
|
||||
toast.success("倉庫已刪除");
|
||||
};
|
||||
|
||||
// 撥補單操作處理函式
|
||||
const handleAddTransferOrder = () => {
|
||||
setEditingTransferOrder(null);
|
||||
setTransferOrderDialogOpen(true);
|
||||
};
|
||||
|
||||
const handleSaveTransferOrder = (
|
||||
orderData: Omit<TransferOrder, "id" | "createdAt" | "orderNumber">
|
||||
) => {
|
||||
const newOrder: TransferOrder = {
|
||||
id: generateId(),
|
||||
orderNumber: generateOrderNumber(),
|
||||
...orderData,
|
||||
createdAt: getCurrentDate(),
|
||||
};
|
||||
setTransferOrders([...transferOrders, newOrder]);
|
||||
|
||||
// 更新庫存
|
||||
const updatedInventories = [...inventories];
|
||||
|
||||
// 尋找來源倉庫庫存
|
||||
const sourceIndex = updatedInventories.findIndex(
|
||||
(inv) =>
|
||||
inv.warehouseId === orderData.sourceWarehouseId &&
|
||||
inv.productId === orderData.productId &&
|
||||
inv.batchNumber === orderData.batchNumber
|
||||
);
|
||||
|
||||
if (sourceIndex !== -1) {
|
||||
// 減少來源倉庫數量
|
||||
updatedInventories[sourceIndex] = {
|
||||
...updatedInventories[sourceIndex],
|
||||
quantity: updatedInventories[sourceIndex].quantity - orderData.quantity,
|
||||
};
|
||||
|
||||
// 尋找或建立目標倉庫庫存
|
||||
const targetIndex = updatedInventories.findIndex(
|
||||
(inv) =>
|
||||
inv.warehouseId === orderData.targetWarehouseId &&
|
||||
inv.productId === orderData.productId &&
|
||||
inv.batchNumber === orderData.batchNumber
|
||||
);
|
||||
|
||||
if (targetIndex !== -1) {
|
||||
// 更新既有目標倉庫數量
|
||||
updatedInventories[targetIndex] = {
|
||||
...updatedInventories[targetIndex],
|
||||
quantity: updatedInventories[targetIndex].quantity + orderData.quantity,
|
||||
};
|
||||
} else {
|
||||
// 建立新的目標倉庫庫存項目
|
||||
const sourceItem = updatedInventories[sourceIndex];
|
||||
updatedInventories.push({
|
||||
warehouseId: orderData.targetWarehouseId,
|
||||
productId: orderData.productId,
|
||||
productName: orderData.productName,
|
||||
quantity: orderData.quantity,
|
||||
batchNumber: orderData.batchNumber,
|
||||
expiryDate: sourceItem.expiryDate,
|
||||
});
|
||||
}
|
||||
|
||||
onUpdateInventories(updatedInventories);
|
||||
}
|
||||
|
||||
toast.success(`撥補單 ${newOrder.orderNumber} 已新增並完成庫存調整`);
|
||||
setTransferOrderDialogOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
{/* 頁面標題 */}
|
||||
<div className="mb-6">
|
||||
<h1 className="mb-2">倉庫管理</h1>
|
||||
<p className="text-gray-600">管理倉庫資訊與庫存配置</p>
|
||||
</div>
|
||||
|
||||
{/* 工具列 */}
|
||||
<div className="bg-white rounded-lg shadow-sm border p-4 mb-6">
|
||||
<div className="flex flex-col md:flex-row gap-4 items-start md:items-center justify-between">
|
||||
<div className="flex flex-col sm:flex-row gap-4 flex-1 w-full">
|
||||
{/* 搜尋框 */}
|
||||
<SearchToolbar
|
||||
value={searchTerm}
|
||||
onChange={setSearchTerm}
|
||||
placeholder="搜尋倉庫名稱..."
|
||||
className="flex-1 w-full md:max-w-md"
|
||||
/>
|
||||
|
||||
{/* 類別篩選 */}
|
||||
<WarehouseFilter
|
||||
value={typeFilter}
|
||||
onChange={setTypeFilter}
|
||||
className="w-full sm:w-48"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 操作按鈕 */}
|
||||
<div className="flex gap-2 w-full md:w-auto">
|
||||
<Button
|
||||
onClick={handleAddTransferOrder}
|
||||
className="flex-1 md:flex-initial button-outlined-primary"
|
||||
>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增撥補單
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleAddWarehouse}
|
||||
className="flex-1 md:flex-initial button-filled-primary"
|
||||
>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增倉庫
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 倉庫卡片列表 */}
|
||||
{filteredWarehouses.length === 0 ? (
|
||||
<WarehouseEmptyState />
|
||||
) : (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{filteredWarehouses.map((warehouse) => (
|
||||
<WarehouseCard
|
||||
key={warehouse.id}
|
||||
warehouse={warehouse}
|
||||
stats={calculateWarehouseStats(inventories, warehouse.id, safetyStockSettings)}
|
||||
hasWarning={hasWarehouseWarning(inventories, warehouse.id, safetyStockSettings)}
|
||||
onViewInventory={onNavigateToInventory}
|
||||
onEdit={handleEditWarehouse}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 倉庫對話框 */}
|
||||
<WarehouseDialog
|
||||
open={isDialogOpen}
|
||||
onOpenChange={setIsDialogOpen}
|
||||
warehouse={editingWarehouse}
|
||||
onSave={handleSaveWarehouse}
|
||||
onDelete={handleDeleteWarehouse}
|
||||
stores={stores}
|
||||
/>
|
||||
|
||||
{/* 撥補單對話框 */}
|
||||
<TransferOrderDialog
|
||||
open={transferOrderDialogOpen}
|
||||
onOpenChange={setTransferOrderDialogOpen}
|
||||
order={editingTransferOrder}
|
||||
onSave={handleSaveTransferOrder}
|
||||
warehouses={warehouses}
|
||||
inventories={inventories}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,27 @@
|
||||
import React, { useState } from 'react'
|
||||
|
||||
const ERROR_IMG_SRC =
|
||||
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iODgiIGhlaWdodD0iODgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjMDAwIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBvcGFjaXR5PSIuMyIgZmlsbD0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIzLjciPjxyZWN0IHg9IjE2IiB5PSIxNiIgd2lkdGg9IjU2IiBoZWlnaHQ9IjU2IiByeD0iNiIvPjxwYXRoIGQ9Im0xNiA1OCAxNi0xOCAzMiAzMiIvPjxjaXJjbGUgY3g9IjUzIiBjeT0iMzUiIHI9IjciLz48L3N2Zz4KCg=='
|
||||
|
||||
export function ImageWithFallback(props: React.ImgHTMLAttributes<HTMLImageElement>) {
|
||||
const [didError, setDidError] = useState(false)
|
||||
|
||||
const handleError = () => {
|
||||
setDidError(true)
|
||||
}
|
||||
|
||||
const { src, alt, style, className, ...rest } = props
|
||||
|
||||
return didError ? (
|
||||
<div
|
||||
className={`inline-block bg-gray-100 text-center align-middle ${className ?? ''}`}
|
||||
style={style}
|
||||
>
|
||||
<div className="flex items-center justify-center w-full h-full">
|
||||
<img src={ERROR_IMG_SRC} alt="Error loading image" {...rest} data-original-url={src} />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<img src={src} alt={alt} className={className} style={style} {...rest} onError={handleError} />
|
||||
)
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 庫存統計元件
|
||||
* 顯示庫存總覽統計資訊
|
||||
*/
|
||||
|
||||
import { AlertTriangle } from "lucide-react";
|
||||
import StatsCard from "../shared/StatsCard";
|
||||
|
||||
interface InventoryStatsProps {
|
||||
totalItems: number;
|
||||
totalQuantity: number;
|
||||
lowStockItems: number;
|
||||
}
|
||||
|
||||
export default function InventoryStats({
|
||||
totalItems,
|
||||
totalQuantity,
|
||||
lowStockItems,
|
||||
}: InventoryStatsProps) {
|
||||
return (
|
||||
<div className="max-w-sm">
|
||||
<StatsCard
|
||||
label="庫存警告"
|
||||
value={`${lowStockItems} 項`}
|
||||
icon={AlertTriangle}
|
||||
valueClassName={lowStockItems > 0 ? "text-red-600" : "text-green-600"}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,244 @@
|
||||
/**
|
||||
* 庫存表格元件
|
||||
* 顯示庫存項目列表(依商品分類並支援折疊)
|
||||
*/
|
||||
|
||||
import { useState } from "react";
|
||||
import { AlertTriangle, Edit, ChevronDown, ChevronRight, CheckCircle, Package } from "lucide-react";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "../ui/table";
|
||||
import { Button } from "../ui/button";
|
||||
import { Badge } from "../ui/badge";
|
||||
import {
|
||||
Collapsible,
|
||||
CollapsibleContent,
|
||||
CollapsibleTrigger,
|
||||
} from "../ui/collapsible";
|
||||
import { WarehouseInventory, SafetyStockSetting } from "../../types/warehouse";
|
||||
import { calculateProductTotalStock, getSafetyStockStatus } from "../../utils/inventory";
|
||||
import { formatDate } from "../../utils/format";
|
||||
|
||||
export type InventoryItemWithId = WarehouseInventory & { inventoryId: string };
|
||||
|
||||
// 商品群組型別(包含有庫存和沒庫存的情況)
|
||||
export interface ProductGroup {
|
||||
productId: string;
|
||||
productName: string;
|
||||
items: InventoryItemWithId[]; // 可能是空陣列(沒有庫存)
|
||||
safetySetting?: SafetyStockSetting;
|
||||
}
|
||||
|
||||
interface InventoryTableProps {
|
||||
productGroups: ProductGroup[];
|
||||
onEdit: (inventoryId: string) => void;
|
||||
}
|
||||
|
||||
export default function InventoryTable({
|
||||
productGroups,
|
||||
onEdit,
|
||||
}: InventoryTableProps) {
|
||||
// 每個商品的展開/折疊狀態
|
||||
const [expandedProducts, setExpandedProducts] = useState<Set<string>>(new Set());
|
||||
|
||||
if (productGroups.length === 0) {
|
||||
return (
|
||||
<div className="text-center py-12 text-gray-400">
|
||||
<p>無符合條件的品項</p>
|
||||
<p className="text-sm mt-1">請調整搜尋或篩選條件</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 按商品名稱排序
|
||||
const sortedProductGroups = [...productGroups].sort((a, b) =>
|
||||
a.productName.localeCompare(b.productName, "zh-TW")
|
||||
);
|
||||
|
||||
const toggleProduct = (productId: string) => {
|
||||
setExpandedProducts((prev) => {
|
||||
const newSet = new Set(prev);
|
||||
if (newSet.has(productId)) {
|
||||
newSet.delete(productId);
|
||||
} else {
|
||||
newSet.add(productId);
|
||||
}
|
||||
return newSet;
|
||||
});
|
||||
};
|
||||
|
||||
// 獲取狀態徽章
|
||||
const getStatusBadge = (status: string) => {
|
||||
switch (status) {
|
||||
case "正常":
|
||||
return (
|
||||
<Badge className="bg-green-100 text-green-700 border-green-300">
|
||||
<CheckCircle className="mr-1 h-3 w-3" />
|
||||
正常
|
||||
</Badge>
|
||||
);
|
||||
case "接近":
|
||||
return (
|
||||
<Badge className="bg-yellow-100 text-yellow-700 border-yellow-300">
|
||||
<AlertTriangle className="mr-1 h-3 w-3" />
|
||||
接近
|
||||
</Badge>
|
||||
);
|
||||
case "低於":
|
||||
return (
|
||||
<Badge className="bg-red-100 text-red-700 border-red-300">
|
||||
<AlertTriangle className="mr-1 h-3 w-3" />
|
||||
低於
|
||||
</Badge>
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4 p-4">
|
||||
{sortedProductGroups.map((group) => {
|
||||
const totalQuantity = group.items.reduce(
|
||||
(sum, item) => sum + item.quantity,
|
||||
0
|
||||
);
|
||||
|
||||
// 計算安全庫存狀態
|
||||
const status = group.safetySetting
|
||||
? getSafetyStockStatus(totalQuantity, group.safetySetting.safetyStock)
|
||||
: null;
|
||||
|
||||
const isLowStock = status === "低於";
|
||||
const isExpanded = expandedProducts.has(group.productId);
|
||||
const hasInventory = group.items.length > 0;
|
||||
|
||||
return (
|
||||
<Collapsible
|
||||
key={group.productId}
|
||||
open={isExpanded}
|
||||
onOpenChange={() => toggleProduct(group.productId)}
|
||||
>
|
||||
<div className="border rounded-lg overflow-hidden">
|
||||
{/* 商品標題 - 可點擊折疊 */}
|
||||
<CollapsibleTrigger asChild>
|
||||
<div
|
||||
className={`px-4 py-3 border-b cursor-pointer hover:bg-gray-100 transition-colors ${
|
||||
isLowStock ? "bg-red-50" : "bg-gray-50"
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
{/* 折疊圖示 */}
|
||||
{isExpanded ? (
|
||||
<ChevronDown className="h-5 w-5 text-gray-600" />
|
||||
) : (
|
||||
<ChevronRight className="h-5 w-5 text-gray-600" />
|
||||
)}
|
||||
<h3 className="font-semibold text-gray-900">{group.productName}</h3>
|
||||
<span className="text-sm text-gray-500">
|
||||
{hasInventory ? `${group.items.length} 個批號` : '無庫存'}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="text-sm">
|
||||
<span className="text-gray-600">
|
||||
總庫存:<span className={`font-medium ${isLowStock ? "text-red-600" : "text-gray-900"}`}>{totalQuantity} 個</span>
|
||||
</span>
|
||||
</div>
|
||||
{group.safetySetting && (
|
||||
<>
|
||||
<div className="text-sm">
|
||||
<span className="text-gray-600">
|
||||
安全庫存:<span className="font-medium text-gray-900">{group.safetySetting.safetyStock} 個</span>
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
{status && getStatusBadge(status)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{!group.safetySetting && (
|
||||
<Badge variant="outline" className="text-gray-500">
|
||||
未設定
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CollapsibleTrigger>
|
||||
|
||||
{/* 商品表格 - 可折疊內容 */}
|
||||
<CollapsibleContent>
|
||||
{hasInventory ? (
|
||||
<div className="overflow-x-auto">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-[5%]">#</TableHead>
|
||||
<TableHead className="w-[12%]">批號</TableHead>
|
||||
<TableHead className="w-[12%]">庫存數量</TableHead>
|
||||
<TableHead className="w-[15%]">進貨編號</TableHead>
|
||||
<TableHead className="w-[14%]">保存期限</TableHead>
|
||||
<TableHead className="w-[14%]">最新入庫</TableHead>
|
||||
<TableHead className="w-[14%]">最新出庫</TableHead>
|
||||
<TableHead className="w-[8%] text-right">操作</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{group.items.map((item, index) => {
|
||||
return (
|
||||
<TableRow key={item.inventoryId}>
|
||||
<TableCell className="text-grey-2">{index + 1}</TableCell>
|
||||
<TableCell>{item.batchNumber || "-"}</TableCell>
|
||||
<TableCell>
|
||||
<span>{item.quantity}</span>
|
||||
</TableCell>
|
||||
<TableCell>{item.batchNumber || "-"}</TableCell>
|
||||
<TableCell>
|
||||
{item.expiryDate ? formatDate(item.expiryDate) : "-"}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{item.lastInboundDate ? formatDate(item.lastInboundDate) : "-"}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{item.lastOutboundDate ? formatDate(item.lastOutboundDate) : "-"}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => onEdit(item.inventoryId)}
|
||||
className="hover:bg-primary/10 hover:text-primary"
|
||||
>
|
||||
<Edit className="h-4 w-4 mr-1" />
|
||||
編輯
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
) : (
|
||||
<div className="px-4 py-8 text-center text-gray-400 bg-gray-50">
|
||||
<Package className="h-8 w-8 mx-auto mb-2 opacity-50" />
|
||||
<p className="text-sm">此商品尚無庫存批號</p>
|
||||
<p className="text-xs mt-1">請點擊「新增庫存」進行入庫</p>
|
||||
</div>
|
||||
)}
|
||||
</CollapsibleContent>
|
||||
</div>
|
||||
</Collapsible>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* 庫存工具列元件
|
||||
* 包含搜尋和篩選功能
|
||||
*/
|
||||
|
||||
import { Filter } from "lucide-react";
|
||||
import SearchToolbar from "../shared/SearchToolbar";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "../ui/select";
|
||||
|
||||
interface InventoryToolbarProps {
|
||||
searchTerm: string;
|
||||
onSearchChange: (value: string) => void;
|
||||
typeFilter: string;
|
||||
onTypeFilterChange: (value: string) => void;
|
||||
}
|
||||
|
||||
export default function InventoryToolbar({
|
||||
searchTerm,
|
||||
onSearchChange,
|
||||
typeFilter,
|
||||
onTypeFilterChange,
|
||||
}: InventoryToolbarProps) {
|
||||
return (
|
||||
<div className="bg-white rounded-lg shadow-sm border p-4">
|
||||
<div className="flex flex-col sm:flex-row gap-4">
|
||||
{/* 搜尋框 */}
|
||||
<SearchToolbar
|
||||
value={searchTerm}
|
||||
onChange={onSearchChange}
|
||||
placeholder="搜尋商品名稱或批號..."
|
||||
className="flex-1"
|
||||
/>
|
||||
|
||||
{/* 類型篩選 */}
|
||||
<div className="w-full sm:w-56">
|
||||
<Select value={typeFilter} onValueChange={onTypeFilterChange}>
|
||||
<SelectTrigger className="border-gray-300">
|
||||
<div className="flex items-center gap-2">
|
||||
<Filter className="h-4 w-4 text-gray-400" />
|
||||
<SelectValue placeholder="篩選類型" />
|
||||
</div>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">全部類型</SelectItem>
|
||||
<SelectItem value="原物料">原物料</SelectItem>
|
||||
<SelectItem value="半成品">半成品</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,281 @@
|
||||
/**
|
||||
* 新增安全庫存對話框(兩步驟)
|
||||
*/
|
||||
|
||||
import { useState } from "react";
|
||||
import { Search, ChevronRight, ChevronLeft } from "lucide-react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogFooter,
|
||||
DialogDescription,
|
||||
} from "../ui/dialog";
|
||||
import { Button } from "../ui/button";
|
||||
import { Input } from "../ui/input";
|
||||
import { Label } from "../ui/label";
|
||||
import { Checkbox } from "../ui/checkbox";
|
||||
import { SafetyStockSetting, Product } from "../../types/warehouse";
|
||||
import { generateId } from "../../utils/format";
|
||||
import { toast } from "sonner@2.0.3";
|
||||
import { Badge } from "../ui/badge";
|
||||
|
||||
interface AddSafetyStockDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
warehouseId: string;
|
||||
existingSettings: SafetyStockSetting[];
|
||||
availableProducts: Product[];
|
||||
onAdd: (settings: SafetyStockSetting[]) => void;
|
||||
}
|
||||
|
||||
interface ProductWithQuantity {
|
||||
product: Product;
|
||||
safetyStock: number;
|
||||
}
|
||||
|
||||
export default function AddSafetyStockDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
warehouseId,
|
||||
existingSettings,
|
||||
availableProducts,
|
||||
onAdd,
|
||||
}: AddSafetyStockDialogProps) {
|
||||
const [step, setStep] = useState<1 | 2>(1);
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const [selectedProducts, setSelectedProducts] = useState<Set<string>>(new Set());
|
||||
const [productQuantities, setProductQuantities] = useState<Map<string, number>>(new Map());
|
||||
|
||||
// 重置對話框
|
||||
const resetDialog = () => {
|
||||
setStep(1);
|
||||
setSearchTerm("");
|
||||
setSelectedProducts(new Set());
|
||||
setProductQuantities(new Map());
|
||||
};
|
||||
|
||||
// 關閉對話框
|
||||
const handleClose = () => {
|
||||
resetDialog();
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
// 已設定的商品 ID
|
||||
const existingProductIds = new Set(existingSettings.map((s) => s.productId));
|
||||
|
||||
// 可選擇的商品(排除已設定的)
|
||||
const selectableProducts = availableProducts.filter(
|
||||
(p) => !existingProductIds.has(p.id)
|
||||
);
|
||||
|
||||
// 篩選後的商品
|
||||
const filteredProducts = selectableProducts.filter(
|
||||
(p) =>
|
||||
p.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||
p.type.includes(searchTerm)
|
||||
);
|
||||
|
||||
// 切換商品選擇
|
||||
const toggleProduct = (productId: string) => {
|
||||
const newSet = new Set(selectedProducts);
|
||||
if (newSet.has(productId)) {
|
||||
newSet.delete(productId);
|
||||
// 同時移除數量設定
|
||||
const newQuantities = new Map(productQuantities);
|
||||
newQuantities.delete(productId);
|
||||
setProductQuantities(newQuantities);
|
||||
} else {
|
||||
newSet.add(productId);
|
||||
}
|
||||
setSelectedProducts(newSet);
|
||||
};
|
||||
|
||||
// 更新商品安全庫存量
|
||||
const updateQuantity = (productId: string, value: number) => {
|
||||
const newQuantities = new Map(productQuantities);
|
||||
newQuantities.set(productId, value);
|
||||
setProductQuantities(newQuantities);
|
||||
};
|
||||
|
||||
// 前往步驟 2
|
||||
const goToStep2 = () => {
|
||||
if (selectedProducts.size === 0) {
|
||||
toast.error("請至少選擇一個商品");
|
||||
return;
|
||||
}
|
||||
setStep(2);
|
||||
};
|
||||
|
||||
// 提交
|
||||
const handleSubmit = () => {
|
||||
// 驗證所有商品都已輸入數量
|
||||
const missingQuantity = Array.from(selectedProducts).some(
|
||||
(productId) => !productQuantities.has(productId) || (productQuantities.get(productId) || 0) <= 0
|
||||
);
|
||||
|
||||
if (missingQuantity) {
|
||||
toast.error("請為所有商品設定安全庫存量");
|
||||
return;
|
||||
}
|
||||
|
||||
// 創建安全庫存設定
|
||||
const newSettings: SafetyStockSetting[] = Array.from(selectedProducts).map((productId) => {
|
||||
const product = availableProducts.find((p) => p.id === productId)!;
|
||||
return {
|
||||
id: generateId(),
|
||||
warehouseId,
|
||||
productId,
|
||||
productName: product.name,
|
||||
productType: product.type,
|
||||
safetyStock: productQuantities.get(productId) || 0,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
});
|
||||
|
||||
onAdd(newSettings);
|
||||
toast.success(`成功新增 ${newSettings.length} 項安全庫存設定`);
|
||||
handleClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleClose}>
|
||||
<DialogContent className="max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
新增安全庫存 - 步驟 {step}/2
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
請選擇商品並設定安全庫存量。
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
{step === 1 ? (
|
||||
// 步驟 1:選擇商品
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label>選擇商品(可多選)</Label>
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
placeholder="搜尋商品名稱或類型..."
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
className="pl-10"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border rounded-lg max-h-96 overflow-y-auto">
|
||||
{filteredProducts.length === 0 ? (
|
||||
<div className="p-8 text-center text-gray-400">
|
||||
{selectableProducts.length === 0
|
||||
? "所有商品都已設定安全庫存"
|
||||
: "無符合條件的商品"}
|
||||
</div>
|
||||
) : (
|
||||
<div className="divide-y">
|
||||
{filteredProducts.map((product) => {
|
||||
const isSelected = selectedProducts.has(product.id);
|
||||
return (
|
||||
<div
|
||||
key={product.id}
|
||||
className={`p-4 flex items-center gap-3 hover:bg-gray-50 cursor-pointer transition-colors ${
|
||||
isSelected ? "bg-blue-50" : ""
|
||||
}`}
|
||||
onClick={() => toggleProduct(product.id)}
|
||||
>
|
||||
<Checkbox
|
||||
checked={isSelected}
|
||||
onCheckedChange={() => toggleProduct(product.id)}
|
||||
/>
|
||||
<div className="flex-1">
|
||||
<div className="font-medium">{product.name}</div>
|
||||
</div>
|
||||
<Badge variant="outline">{product.type}</Badge>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="text-sm text-gray-600">
|
||||
已選擇 {selectedProducts.size} 項商品
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
// 步驟 2:設定安全庫存量
|
||||
<div className="space-y-4">
|
||||
<p className="text-sm text-gray-600">
|
||||
為每個商品設定安全庫存量(共 {selectedProducts.size} 項)
|
||||
</p>
|
||||
|
||||
<div className="border rounded-lg max-h-96 overflow-y-auto">
|
||||
<div className="divide-y">
|
||||
{Array.from(selectedProducts).map((productId) => {
|
||||
const product = availableProducts.find((p) => p.id === productId)!;
|
||||
const quantity = productQuantities.get(productId) || 0;
|
||||
|
||||
return (
|
||||
<div key={productId} className="p-4 space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-medium">{product.name}</span>
|
||||
<Badge variant="outline">{product.type}</Badge>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24">安全庫存</Label>
|
||||
<Input
|
||||
type="number"
|
||||
min="1"
|
||||
value={quantity || ""}
|
||||
onChange={(e) =>
|
||||
updateQuantity(productId, parseInt(e.target.value) || 0)
|
||||
}
|
||||
placeholder="請輸入數量"
|
||||
className="flex-1"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<DialogFooter>
|
||||
{step === 1 ? (
|
||||
<>
|
||||
<Button variant="outline" onClick={handleClose}>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
onClick={goToStep2}
|
||||
disabled={selectedProducts.size === 0}
|
||||
className="button-filled-primary"
|
||||
>
|
||||
下一步
|
||||
<ChevronRight className="ml-2 h-4 w-4" />
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Button variant="outline" onClick={() => setStep(1)}>
|
||||
<ChevronLeft className="mr-2 h-4 w-4" />
|
||||
上一步
|
||||
</Button>
|
||||
<Button onClick={handleSubmit} className="button-filled-primary">
|
||||
確認新增
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* 編輯安全庫存對話框
|
||||
*/
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogFooter,
|
||||
DialogDescription,
|
||||
} from "../ui/dialog";
|
||||
import { Button } from "../ui/button";
|
||||
import { Input } from "../ui/input";
|
||||
import { Label } from "../ui/label";
|
||||
import { SafetyStockSetting } from "../../types/warehouse";
|
||||
import { toast } from "sonner@2.0.3";
|
||||
import { Badge } from "../ui/badge";
|
||||
|
||||
interface EditSafetyStockDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
setting: SafetyStockSetting;
|
||||
onSave: (setting: SafetyStockSetting) => void;
|
||||
}
|
||||
|
||||
export default function EditSafetyStockDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
setting,
|
||||
onSave,
|
||||
}: EditSafetyStockDialogProps) {
|
||||
const [safetyStock, setSafetyStock] = useState(setting.safetyStock);
|
||||
|
||||
useEffect(() => {
|
||||
setSafetyStock(setting.safetyStock);
|
||||
}, [setting]);
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (safetyStock <= 0) {
|
||||
toast.error("安全庫存量必須大於 0");
|
||||
return;
|
||||
}
|
||||
|
||||
const updatedSetting: SafetyStockSetting = {
|
||||
...setting,
|
||||
safetyStock,
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
onSave(updatedSetting);
|
||||
toast.success("安全庫存設定已更新");
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>編輯安全庫存</DialogTitle>
|
||||
<DialogDescription>請輸入新的安全庫存量。</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label>商品名稱</Label>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-medium">{setting.productName}</span>
|
||||
<Badge variant="outline">{setting.productType}</Badge>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="safetyStock">
|
||||
安全庫存量 <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="safetyStock"
|
||||
type="number"
|
||||
min="1"
|
||||
value={safetyStock}
|
||||
onChange={(e) => setSafetyStock(parseInt(e.target.value) || 0)}
|
||||
placeholder="請輸入安全庫存量"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||
取消
|
||||
</Button>
|
||||
<Button onClick={handleSubmit} className="button-filled-primary">
|
||||
儲存
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
* 安全庫存列表組件
|
||||
*/
|
||||
|
||||
import { Edit, Trash2, AlertCircle, CheckCircle, AlertTriangle } from "lucide-react";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "../ui/table";
|
||||
import { Button } from "../ui/button";
|
||||
import { SafetyStockSetting, WarehouseInventory, SafetyStockStatus } from "../../types/warehouse";
|
||||
import { Badge } from "../ui/badge";
|
||||
|
||||
interface SafetyStockListProps {
|
||||
settings: SafetyStockSetting[];
|
||||
inventories: WarehouseInventory[];
|
||||
onEdit: (setting: SafetyStockSetting) => void;
|
||||
onDelete: (id: string) => void;
|
||||
}
|
||||
|
||||
// 計算安全庫存狀態
|
||||
function getSafetyStockStatus(
|
||||
currentStock: number,
|
||||
safetyStock: number
|
||||
): SafetyStockStatus {
|
||||
const ratio = currentStock / safetyStock;
|
||||
if (ratio >= 1.2) return "正常";
|
||||
if (ratio >= 1.0) return "接近";
|
||||
return "低於";
|
||||
}
|
||||
|
||||
// 獲取狀態徽章
|
||||
function getStatusBadge(status: SafetyStockStatus) {
|
||||
switch (status) {
|
||||
case "正常":
|
||||
return (
|
||||
<Badge className="bg-green-100 text-green-700 border-green-300">
|
||||
<CheckCircle className="mr-1 h-3 w-3" />
|
||||
正常
|
||||
</Badge>
|
||||
);
|
||||
case "接近":
|
||||
return (
|
||||
<Badge className="bg-yellow-100 text-yellow-700 border-yellow-300">
|
||||
<AlertTriangle className="mr-1 h-3 w-3" />
|
||||
接近
|
||||
</Badge>
|
||||
);
|
||||
case "低於":
|
||||
return (
|
||||
<Badge className="bg-red-100 text-red-700 border-red-300">
|
||||
<AlertCircle className="mr-1 h-3 w-3" />
|
||||
低於
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default function SafetyStockList({
|
||||
settings,
|
||||
inventories,
|
||||
onEdit,
|
||||
onDelete,
|
||||
}: SafetyStockListProps) {
|
||||
if (settings.length === 0) {
|
||||
return (
|
||||
<div className="bg-white rounded-lg shadow-sm border p-12 text-center text-gray-400">
|
||||
<p>尚未設定任何安全庫存</p>
|
||||
<p className="text-sm mt-1">點擊「新增安全庫存」開始設定</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 計算每個商品的目前總庫存
|
||||
const getCurrentStock = (productId: string): number => {
|
||||
return inventories
|
||||
.filter((inv) => inv.productId === productId)
|
||||
.reduce((sum, inv) => sum + inv.quantity, 0);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-lg shadow-sm border overflow-hidden">
|
||||
<div className="overflow-x-auto">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-[5%]">#</TableHead>
|
||||
<TableHead className="w-[25%]">商品名稱</TableHead>
|
||||
<TableHead className="w-[12%]">商品類型</TableHead>
|
||||
<TableHead className="w-[12%]">目前庫存</TableHead>
|
||||
<TableHead className="w-[12%]">安全庫存</TableHead>
|
||||
<TableHead className="w-[15%]">狀態</TableHead>
|
||||
<TableHead className="w-[12%] text-right">操作</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{settings.map((setting, index) => {
|
||||
const currentStock = getCurrentStock(setting.productId);
|
||||
const status = getSafetyStockStatus(currentStock, setting.safetyStock);
|
||||
const isLowStock = status === "低於";
|
||||
|
||||
return (
|
||||
<TableRow key={setting.id} className={isLowStock ? "bg-red-50" : ""}>
|
||||
<TableCell className="text-grey-2">{index + 1}</TableCell>
|
||||
<TableCell className="font-medium">{setting.productName}</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant="outline">{setting.productType}</Badge>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span className={isLowStock ? "text-red-600 font-medium" : ""}>
|
||||
{currentStock}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell>{setting.safetyStock}</TableCell>
|
||||
<TableCell>{getStatusBadge(status)}</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => onEdit(setting)}
|
||||
className="hover:bg-primary/10 hover:text-primary"
|
||||
>
|
||||
<Edit className="h-4 w-4 mr-1" />
|
||||
編輯
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => onDelete(setting.id)}
|
||||
className="hover:bg-red-50 hover:text-red-600"
|
||||
>
|
||||
<Trash2 className="h-4 w-4 mr-1" />
|
||||
移除
|
||||
</Button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 搜尋工具列元件
|
||||
* 提供搜尋輸入框功能
|
||||
*/
|
||||
|
||||
import { Search } from "lucide-react";
|
||||
import { Input } from "../ui/input";
|
||||
|
||||
interface SearchToolbarProps {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
placeholder?: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export default function SearchToolbar({
|
||||
value,
|
||||
onChange,
|
||||
placeholder = "搜尋...",
|
||||
className = "",
|
||||
}: SearchToolbarProps) {
|
||||
return (
|
||||
<div className={`relative ${className}`}>
|
||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
type="text"
|
||||
placeholder={placeholder}
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className="pl-10"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 統計卡片元件
|
||||
* 用於顯示各種統計資訊
|
||||
*/
|
||||
|
||||
import { LucideIcon } from "lucide-react";
|
||||
|
||||
interface StatsCardProps {
|
||||
label: string;
|
||||
value: string | number;
|
||||
icon?: LucideIcon;
|
||||
valueClassName?: string;
|
||||
}
|
||||
|
||||
export default function StatsCard({
|
||||
label,
|
||||
value,
|
||||
icon: Icon,
|
||||
valueClassName = "text-primary-main",
|
||||
}: StatsCardProps) {
|
||||
return (
|
||||
<div className="bg-white rounded-lg shadow-sm border p-5">
|
||||
<div className="flex items-center gap-2 text-grey-2 mb-1">
|
||||
{Icon && <Icon className="h-4 w-4" />}
|
||||
<span>{label}</span>
|
||||
</div>
|
||||
<div className={valueClassName}>{value}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
66
source-code/ERP(A-b)-倉庫管理/src/components/ui/accordion.tsx
Normal file
66
source-code/ERP(A-b)-倉庫管理/src/components/ui/accordion.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as AccordionPrimitive from "@radix-ui/react-accordion@1.2.3";
|
||||
import { ChevronDownIcon } from "lucide-react@0.487.0";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function Accordion({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Root>) {
|
||||
return <AccordionPrimitive.Root data-slot="accordion" {...props} />;
|
||||
}
|
||||
|
||||
function AccordionItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Item>) {
|
||||
return (
|
||||
<AccordionPrimitive.Item
|
||||
data-slot="accordion-item"
|
||||
className={cn("border-b last:border-b-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AccordionTrigger({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Trigger>) {
|
||||
return (
|
||||
<AccordionPrimitive.Header className="flex">
|
||||
<AccordionPrimitive.Trigger
|
||||
data-slot="accordion-trigger"
|
||||
className={cn(
|
||||
"focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronDownIcon className="text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200" />
|
||||
</AccordionPrimitive.Trigger>
|
||||
</AccordionPrimitive.Header>
|
||||
);
|
||||
}
|
||||
|
||||
function AccordionContent({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Content>) {
|
||||
return (
|
||||
<AccordionPrimitive.Content
|
||||
data-slot="accordion-content"
|
||||
className="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm"
|
||||
{...props}
|
||||
>
|
||||
<div className={cn("pt-0 pb-4", className)}>{children}</div>
|
||||
</AccordionPrimitive.Content>
|
||||
);
|
||||
}
|
||||
|
||||
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };
|
||||
Binary file not shown.
159
source-code/ERP(A-b)-倉庫管理/src/components/ui/alert-dialog.tsx
Normal file
159
source-code/ERP(A-b)-倉庫管理/src/components/ui/alert-dialog.tsx
Normal file
@@ -0,0 +1,159 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog@1.1.6";
|
||||
|
||||
import { cn } from "./utils";
|
||||
import { buttonVariants } from "./button";
|
||||
|
||||
function AlertDialog({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
|
||||
return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />;
|
||||
}
|
||||
|
||||
function AlertDialogTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
const AlertDialogOverlay = React.forwardRef<
|
||||
React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => {
|
||||
return (
|
||||
<AlertDialogPrimitive.Overlay
|
||||
ref={ref}
|
||||
data-slot="alert-dialog-overlay"
|
||||
className={cn(
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName;
|
||||
|
||||
function AlertDialogContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Content>) {
|
||||
return (
|
||||
<AlertDialogPortal>
|
||||
<AlertDialogOverlay />
|
||||
<AlertDialogPrimitive.Content
|
||||
data-slot="alert-dialog-content"
|
||||
className={cn(
|
||||
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</AlertDialogPortal>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogHeader({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert-dialog-header"
|
||||
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogFooter({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert-dialog-footer"
|
||||
className={cn(
|
||||
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Title
|
||||
data-slot="alert-dialog-title"
|
||||
className={cn("text-lg font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Description
|
||||
data-slot="alert-dialog-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogAction({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Action>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Action
|
||||
className={cn(buttonVariants(), className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogCancel({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Cancel>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Cancel
|
||||
className={cn(buttonVariants({ variant: "outline" }), className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
AlertDialog,
|
||||
AlertDialogPortal,
|
||||
AlertDialogOverlay,
|
||||
AlertDialogTrigger,
|
||||
AlertDialogContent,
|
||||
AlertDialogHeader,
|
||||
AlertDialogFooter,
|
||||
AlertDialogTitle,
|
||||
AlertDialogDescription,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
};
|
||||
Binary file not shown.
66
source-code/ERP(A-b)-倉庫管理/src/components/ui/alert.tsx
Normal file
66
source-code/ERP(A-b)-倉庫管理/src/components/ui/alert.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
import * as React from "react";
|
||||
import { cva, type VariantProps } from "class-variance-authority@0.7.1";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
const alertVariants = cva(
|
||||
"relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-card text-card-foreground",
|
||||
destructive:
|
||||
"text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
function Alert({
|
||||
className,
|
||||
variant,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert"
|
||||
role="alert"
|
||||
className={cn(alertVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert-title"
|
||||
className={cn(
|
||||
"col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert-description"
|
||||
className={cn(
|
||||
"text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Alert, AlertTitle, AlertDescription };
|
||||
Binary file not shown.
11
source-code/ERP(A-b)-倉庫管理/src/components/ui/aspect-ratio.tsx
Normal file
11
source-code/ERP(A-b)-倉庫管理/src/components/ui/aspect-ratio.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import * as AspectRatioPrimitive from "@radix-ui/react-aspect-ratio@1.1.2";
|
||||
|
||||
function AspectRatio({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AspectRatioPrimitive.Root>) {
|
||||
return <AspectRatioPrimitive.Root data-slot="aspect-ratio" {...props} />;
|
||||
}
|
||||
|
||||
export { AspectRatio };
|
||||
Binary file not shown.
53
source-code/ERP(A-b)-倉庫管理/src/components/ui/avatar.tsx
Normal file
53
source-code/ERP(A-b)-倉庫管理/src/components/ui/avatar.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as AvatarPrimitive from "@radix-ui/react-avatar@1.1.3";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function Avatar({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Root>) {
|
||||
return (
|
||||
<AvatarPrimitive.Root
|
||||
data-slot="avatar"
|
||||
className={cn(
|
||||
"relative flex size-10 shrink-0 overflow-hidden rounded-full",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AvatarImage({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Image>) {
|
||||
return (
|
||||
<AvatarPrimitive.Image
|
||||
data-slot="avatar-image"
|
||||
className={cn("aspect-square size-full", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AvatarFallback({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
|
||||
return (
|
||||
<AvatarPrimitive.Fallback
|
||||
data-slot="avatar-fallback"
|
||||
className={cn(
|
||||
"bg-muted flex size-full items-center justify-center rounded-full",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Avatar, AvatarImage, AvatarFallback };
|
||||
Binary file not shown.
46
source-code/ERP(A-b)-倉庫管理/src/components/ui/badge.tsx
Normal file
46
source-code/ERP(A-b)-倉庫管理/src/components/ui/badge.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot@1.1.2";
|
||||
import { cva, type VariantProps } from "class-variance-authority@0.7.1";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
const badgeVariants = cva(
|
||||
"inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
||||
secondary:
|
||||
"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
||||
destructive:
|
||||
"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||
outline:
|
||||
"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
function Badge({
|
||||
className,
|
||||
variant,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"span"> &
|
||||
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "span";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="badge"
|
||||
className={cn(badgeVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants };
|
||||
Binary file not shown.
109
source-code/ERP(A-b)-倉庫管理/src/components/ui/breadcrumb.tsx
Normal file
109
source-code/ERP(A-b)-倉庫管理/src/components/ui/breadcrumb.tsx
Normal file
@@ -0,0 +1,109 @@
|
||||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot@1.1.2";
|
||||
import { ChevronRight, MoreHorizontal } from "lucide-react@0.487.0";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function Breadcrumb({ ...props }: React.ComponentProps<"nav">) {
|
||||
return <nav aria-label="breadcrumb" data-slot="breadcrumb" {...props} />;
|
||||
}
|
||||
|
||||
function BreadcrumbList({ className, ...props }: React.ComponentProps<"ol">) {
|
||||
return (
|
||||
<ol
|
||||
data-slot="breadcrumb-list"
|
||||
className={cn(
|
||||
"text-muted-foreground flex flex-wrap items-center gap-1.5 text-sm break-words sm:gap-2.5",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function BreadcrumbItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
data-slot="breadcrumb-item"
|
||||
className={cn("inline-flex items-center gap-1.5", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function BreadcrumbLink({
|
||||
asChild,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"a"> & {
|
||||
asChild?: boolean;
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "a";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="breadcrumb-link"
|
||||
className={cn("hover:text-foreground transition-colors", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function BreadcrumbPage({ className, ...props }: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="breadcrumb-page"
|
||||
role="link"
|
||||
aria-disabled="true"
|
||||
aria-current="page"
|
||||
className={cn("text-foreground font-normal", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function BreadcrumbSeparator({
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
data-slot="breadcrumb-separator"
|
||||
role="presentation"
|
||||
aria-hidden="true"
|
||||
className={cn("[&>svg]:size-3.5", className)}
|
||||
{...props}
|
||||
>
|
||||
{children ?? <ChevronRight />}
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
function BreadcrumbEllipsis({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="breadcrumb-ellipsis"
|
||||
role="presentation"
|
||||
aria-hidden="true"
|
||||
className={cn("flex size-9 items-center justify-center", className)}
|
||||
{...props}
|
||||
>
|
||||
<MoreHorizontal className="size-4" />
|
||||
<span className="sr-only">More</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Breadcrumb,
|
||||
BreadcrumbList,
|
||||
BreadcrumbItem,
|
||||
BreadcrumbLink,
|
||||
BreadcrumbPage,
|
||||
BreadcrumbSeparator,
|
||||
BreadcrumbEllipsis,
|
||||
};
|
||||
Binary file not shown.
58
source-code/ERP(A-b)-倉庫管理/src/components/ui/button.tsx
Normal file
58
source-code/ERP(A-b)-倉庫管理/src/components/ui/button.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot@1.1.2";
|
||||
import { cva, type VariantProps } from "class-variance-authority@0.7.1";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||
destructive:
|
||||
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||
outline:
|
||||
"border-2 border-grey-3 bg-background text-foreground hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
||||
secondary:
|
||||
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||
ghost:
|
||||
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
||||
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
||||
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
||||
icon: "size-9 rounded-md",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const Button = React.forwardRef<
|
||||
HTMLButtonElement,
|
||||
React.ComponentProps<"button"> &
|
||||
VariantProps<typeof buttonVariants> & {
|
||||
asChild?: boolean;
|
||||
}
|
||||
>(({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||
const Comp = asChild ? Slot : "button";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="button"
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
Button.displayName = "Button";
|
||||
|
||||
export { Button, buttonVariants };
|
||||
Binary file not shown.
75
source-code/ERP(A-b)-倉庫管理/src/components/ui/calendar.tsx
Normal file
75
source-code/ERP(A-b)-倉庫管理/src/components/ui/calendar.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { ChevronLeft, ChevronRight } from "lucide-react@0.487.0";
|
||||
import { DayPicker } from "react-day-picker@8.10.1";
|
||||
|
||||
import { cn } from "./utils";
|
||||
import { buttonVariants } from "./button";
|
||||
|
||||
function Calendar({
|
||||
className,
|
||||
classNames,
|
||||
showOutsideDays = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DayPicker>) {
|
||||
return (
|
||||
<DayPicker
|
||||
showOutsideDays={showOutsideDays}
|
||||
className={cn("p-3", className)}
|
||||
classNames={{
|
||||
months: "flex flex-col sm:flex-row gap-2",
|
||||
month: "flex flex-col gap-4",
|
||||
caption: "flex justify-center pt-1 relative items-center w-full",
|
||||
caption_label: "text-sm font-medium",
|
||||
nav: "flex items-center gap-1",
|
||||
nav_button: cn(
|
||||
buttonVariants({ variant: "outline" }),
|
||||
"size-7 bg-transparent p-0 opacity-50 hover:opacity-100",
|
||||
),
|
||||
nav_button_previous: "absolute left-1",
|
||||
nav_button_next: "absolute right-1",
|
||||
table: "w-full border-collapse space-x-1",
|
||||
head_row: "flex",
|
||||
head_cell:
|
||||
"text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]",
|
||||
row: "flex w-full mt-2",
|
||||
cell: cn(
|
||||
"relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-range-end)]:rounded-r-md",
|
||||
props.mode === "range"
|
||||
? "[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md"
|
||||
: "[&:has([aria-selected])]:rounded-md",
|
||||
),
|
||||
day: cn(
|
||||
buttonVariants({ variant: "ghost" }),
|
||||
"size-8 p-0 font-normal aria-selected:opacity-100",
|
||||
),
|
||||
day_range_start:
|
||||
"day-range-start aria-selected:bg-primary aria-selected:text-primary-foreground",
|
||||
day_range_end:
|
||||
"day-range-end aria-selected:bg-primary aria-selected:text-primary-foreground",
|
||||
day_selected:
|
||||
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",
|
||||
day_today: "bg-accent text-accent-foreground",
|
||||
day_outside:
|
||||
"day-outside text-muted-foreground aria-selected:text-muted-foreground",
|
||||
day_disabled: "text-muted-foreground opacity-50",
|
||||
day_range_middle:
|
||||
"aria-selected:bg-accent aria-selected:text-accent-foreground",
|
||||
day_hidden: "invisible",
|
||||
...classNames,
|
||||
}}
|
||||
components={{
|
||||
IconLeft: ({ className, ...props }) => (
|
||||
<ChevronLeft className={cn("size-4", className)} {...props} />
|
||||
),
|
||||
IconRight: ({ className, ...props }) => (
|
||||
<ChevronRight className={cn("size-4", className)} {...props} />
|
||||
),
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Calendar };
|
||||
Binary file not shown.
92
source-code/ERP(A-b)-倉庫管理/src/components/ui/card.tsx
Normal file
92
source-code/ERP(A-b)-倉庫管理/src/components/ui/card.tsx
Normal file
@@ -0,0 +1,92 @@
|
||||
import * as React from "react";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card"
|
||||
className={cn(
|
||||
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-header"
|
||||
className={cn(
|
||||
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 pt-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<h4
|
||||
data-slot="card-title"
|
||||
className={cn("leading-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<p
|
||||
data-slot="card-description"
|
||||
className={cn("text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-action"
|
||||
className={cn(
|
||||
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-content"
|
||||
className={cn("px-6 [&:last-child]:pb-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-footer"
|
||||
className={cn("flex items-center px-6 pb-6 [.border-t]:pt-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Card,
|
||||
CardHeader,
|
||||
CardFooter,
|
||||
CardTitle,
|
||||
CardAction,
|
||||
CardDescription,
|
||||
CardContent,
|
||||
};
|
||||
Binary file not shown.
241
source-code/ERP(A-b)-倉庫管理/src/components/ui/carousel.tsx
Normal file
241
source-code/ERP(A-b)-倉庫管理/src/components/ui/carousel.tsx
Normal file
@@ -0,0 +1,241 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import useEmblaCarousel, {
|
||||
type UseEmblaCarouselType,
|
||||
} from "embla-carousel-react@8.6.0";
|
||||
import { ArrowLeft, ArrowRight } from "lucide-react@0.487.0";
|
||||
|
||||
import { cn } from "./utils";
|
||||
import { Button } from "./button";
|
||||
|
||||
type CarouselApi = UseEmblaCarouselType[1];
|
||||
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;
|
||||
type CarouselOptions = UseCarouselParameters[0];
|
||||
type CarouselPlugin = UseCarouselParameters[1];
|
||||
|
||||
type CarouselProps = {
|
||||
opts?: CarouselOptions;
|
||||
plugins?: CarouselPlugin;
|
||||
orientation?: "horizontal" | "vertical";
|
||||
setApi?: (api: CarouselApi) => void;
|
||||
};
|
||||
|
||||
type CarouselContextProps = {
|
||||
carouselRef: ReturnType<typeof useEmblaCarousel>[0];
|
||||
api: ReturnType<typeof useEmblaCarousel>[1];
|
||||
scrollPrev: () => void;
|
||||
scrollNext: () => void;
|
||||
canScrollPrev: boolean;
|
||||
canScrollNext: boolean;
|
||||
} & CarouselProps;
|
||||
|
||||
const CarouselContext = React.createContext<CarouselContextProps | null>(null);
|
||||
|
||||
function useCarousel() {
|
||||
const context = React.useContext(CarouselContext);
|
||||
|
||||
if (!context) {
|
||||
throw new Error("useCarousel must be used within a <Carousel />");
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
function Carousel({
|
||||
orientation = "horizontal",
|
||||
opts,
|
||||
setApi,
|
||||
plugins,
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & CarouselProps) {
|
||||
const [carouselRef, api] = useEmblaCarousel(
|
||||
{
|
||||
...opts,
|
||||
axis: orientation === "horizontal" ? "x" : "y",
|
||||
},
|
||||
plugins,
|
||||
);
|
||||
const [canScrollPrev, setCanScrollPrev] = React.useState(false);
|
||||
const [canScrollNext, setCanScrollNext] = React.useState(false);
|
||||
|
||||
const onSelect = React.useCallback((api: CarouselApi) => {
|
||||
if (!api) return;
|
||||
setCanScrollPrev(api.canScrollPrev());
|
||||
setCanScrollNext(api.canScrollNext());
|
||||
}, []);
|
||||
|
||||
const scrollPrev = React.useCallback(() => {
|
||||
api?.scrollPrev();
|
||||
}, [api]);
|
||||
|
||||
const scrollNext = React.useCallback(() => {
|
||||
api?.scrollNext();
|
||||
}, [api]);
|
||||
|
||||
const handleKeyDown = React.useCallback(
|
||||
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
||||
if (event.key === "ArrowLeft") {
|
||||
event.preventDefault();
|
||||
scrollPrev();
|
||||
} else if (event.key === "ArrowRight") {
|
||||
event.preventDefault();
|
||||
scrollNext();
|
||||
}
|
||||
},
|
||||
[scrollPrev, scrollNext],
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!api || !setApi) return;
|
||||
setApi(api);
|
||||
}, [api, setApi]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!api) return;
|
||||
onSelect(api);
|
||||
api.on("reInit", onSelect);
|
||||
api.on("select", onSelect);
|
||||
|
||||
return () => {
|
||||
api?.off("select", onSelect);
|
||||
};
|
||||
}, [api, onSelect]);
|
||||
|
||||
return (
|
||||
<CarouselContext.Provider
|
||||
value={{
|
||||
carouselRef,
|
||||
api: api,
|
||||
opts,
|
||||
orientation:
|
||||
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
||||
scrollPrev,
|
||||
scrollNext,
|
||||
canScrollPrev,
|
||||
canScrollNext,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
onKeyDownCapture={handleKeyDown}
|
||||
className={cn("relative", className)}
|
||||
role="region"
|
||||
aria-roledescription="carousel"
|
||||
data-slot="carousel"
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</CarouselContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
function CarouselContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
const { carouselRef, orientation } = useCarousel();
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={carouselRef}
|
||||
className="overflow-hidden"
|
||||
data-slot="carousel-content"
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"flex",
|
||||
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
|
||||
const { orientation } = useCarousel();
|
||||
|
||||
return (
|
||||
<div
|
||||
role="group"
|
||||
aria-roledescription="slide"
|
||||
data-slot="carousel-item"
|
||||
className={cn(
|
||||
"min-w-0 shrink-0 grow-0 basis-full",
|
||||
orientation === "horizontal" ? "pl-4" : "pt-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CarouselPrevious({
|
||||
className,
|
||||
variant = "outline",
|
||||
size = "icon",
|
||||
...props
|
||||
}: React.ComponentProps<typeof Button>) {
|
||||
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
||||
|
||||
return (
|
||||
<Button
|
||||
data-slot="carousel-previous"
|
||||
variant={variant}
|
||||
size={size}
|
||||
className={cn(
|
||||
"absolute size-8 rounded-full",
|
||||
orientation === "horizontal"
|
||||
? "top-1/2 -left-12 -translate-y-1/2"
|
||||
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
||||
className,
|
||||
)}
|
||||
disabled={!canScrollPrev}
|
||||
onClick={scrollPrev}
|
||||
{...props}
|
||||
>
|
||||
<ArrowLeft />
|
||||
<span className="sr-only">Previous slide</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
function CarouselNext({
|
||||
className,
|
||||
variant = "outline",
|
||||
size = "icon",
|
||||
...props
|
||||
}: React.ComponentProps<typeof Button>) {
|
||||
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
||||
|
||||
return (
|
||||
<Button
|
||||
data-slot="carousel-next"
|
||||
variant={variant}
|
||||
size={size}
|
||||
className={cn(
|
||||
"absolute size-8 rounded-full",
|
||||
orientation === "horizontal"
|
||||
? "top-1/2 -right-12 -translate-y-1/2"
|
||||
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
||||
className,
|
||||
)}
|
||||
disabled={!canScrollNext}
|
||||
onClick={scrollNext}
|
||||
{...props}
|
||||
>
|
||||
<ArrowRight />
|
||||
<span className="sr-only">Next slide</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
type CarouselApi,
|
||||
Carousel,
|
||||
CarouselContent,
|
||||
CarouselItem,
|
||||
CarouselPrevious,
|
||||
CarouselNext,
|
||||
};
|
||||
Binary file not shown.
353
source-code/ERP(A-b)-倉庫管理/src/components/ui/chart.tsx
Normal file
353
source-code/ERP(A-b)-倉庫管理/src/components/ui/chart.tsx
Normal file
@@ -0,0 +1,353 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as RechartsPrimitive from "recharts@2.15.2";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
// Format: { THEME_NAME: CSS_SELECTOR }
|
||||
const THEMES = { light: "", dark: ".dark" } as const;
|
||||
|
||||
export type ChartConfig = {
|
||||
[k in string]: {
|
||||
label?: React.ReactNode;
|
||||
icon?: React.ComponentType;
|
||||
} & (
|
||||
| { color?: string; theme?: never }
|
||||
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
||||
);
|
||||
};
|
||||
|
||||
type ChartContextProps = {
|
||||
config: ChartConfig;
|
||||
};
|
||||
|
||||
const ChartContext = React.createContext<ChartContextProps | null>(null);
|
||||
|
||||
function useChart() {
|
||||
const context = React.useContext(ChartContext);
|
||||
|
||||
if (!context) {
|
||||
throw new Error("useChart must be used within a <ChartContainer />");
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
function ChartContainer({
|
||||
id,
|
||||
className,
|
||||
children,
|
||||
config,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
config: ChartConfig;
|
||||
children: React.ComponentProps<
|
||||
typeof RechartsPrimitive.ResponsiveContainer
|
||||
>["children"];
|
||||
}) {
|
||||
const uniqueId = React.useId();
|
||||
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`;
|
||||
|
||||
return (
|
||||
<ChartContext.Provider value={{ config }}>
|
||||
<div
|
||||
data-slot="chart"
|
||||
data-chart={chartId}
|
||||
className={cn(
|
||||
"[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChartStyle id={chartId} config={config} />
|
||||
<RechartsPrimitive.ResponsiveContainer>
|
||||
{children}
|
||||
</RechartsPrimitive.ResponsiveContainer>
|
||||
</div>
|
||||
</ChartContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
||||
const colorConfig = Object.entries(config).filter(
|
||||
([, config]) => config.theme || config.color,
|
||||
);
|
||||
|
||||
if (!colorConfig.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<style
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: Object.entries(THEMES)
|
||||
.map(
|
||||
([theme, prefix]) => `
|
||||
${prefix} [data-chart=${id}] {
|
||||
${colorConfig
|
||||
.map(([key, itemConfig]) => {
|
||||
const color =
|
||||
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
|
||||
itemConfig.color;
|
||||
return color ? ` --color-${key}: ${color};` : null;
|
||||
})
|
||||
.join("\n")}
|
||||
}
|
||||
`,
|
||||
)
|
||||
.join("\n"),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const ChartTooltip = RechartsPrimitive.Tooltip;
|
||||
|
||||
function ChartTooltipContent({
|
||||
active,
|
||||
payload,
|
||||
className,
|
||||
indicator = "dot",
|
||||
hideLabel = false,
|
||||
hideIndicator = false,
|
||||
label,
|
||||
labelFormatter,
|
||||
labelClassName,
|
||||
formatter,
|
||||
color,
|
||||
nameKey,
|
||||
labelKey,
|
||||
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
|
||||
React.ComponentProps<"div"> & {
|
||||
hideLabel?: boolean;
|
||||
hideIndicator?: boolean;
|
||||
indicator?: "line" | "dot" | "dashed";
|
||||
nameKey?: string;
|
||||
labelKey?: string;
|
||||
}) {
|
||||
const { config } = useChart();
|
||||
|
||||
const tooltipLabel = React.useMemo(() => {
|
||||
if (hideLabel || !payload?.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const [item] = payload;
|
||||
const key = `${labelKey || item?.dataKey || item?.name || "value"}`;
|
||||
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
||||
const value =
|
||||
!labelKey && typeof label === "string"
|
||||
? config[label as keyof typeof config]?.label || label
|
||||
: itemConfig?.label;
|
||||
|
||||
if (labelFormatter) {
|
||||
return (
|
||||
<div className={cn("font-medium", labelClassName)}>
|
||||
{labelFormatter(value, payload)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <div className={cn("font-medium", labelClassName)}>{value}</div>;
|
||||
}, [
|
||||
label,
|
||||
labelFormatter,
|
||||
payload,
|
||||
hideLabel,
|
||||
labelClassName,
|
||||
config,
|
||||
labelKey,
|
||||
]);
|
||||
|
||||
if (!active || !payload?.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const nestLabel = payload.length === 1 && indicator !== "dot";
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{!nestLabel ? tooltipLabel : null}
|
||||
<div className="grid gap-1.5">
|
||||
{payload.map((item, index) => {
|
||||
const key = `${nameKey || item.name || item.dataKey || "value"}`;
|
||||
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
||||
const indicatorColor = color || item.payload.fill || item.color;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={item.dataKey}
|
||||
className={cn(
|
||||
"[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",
|
||||
indicator === "dot" && "items-center",
|
||||
)}
|
||||
>
|
||||
{formatter && item?.value !== undefined && item.name ? (
|
||||
formatter(item.value, item.name, item, index, item.payload)
|
||||
) : (
|
||||
<>
|
||||
{itemConfig?.icon ? (
|
||||
<itemConfig.icon />
|
||||
) : (
|
||||
!hideIndicator && (
|
||||
<div
|
||||
className={cn(
|
||||
"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
|
||||
{
|
||||
"h-2.5 w-2.5": indicator === "dot",
|
||||
"w-1": indicator === "line",
|
||||
"w-0 border-[1.5px] border-dashed bg-transparent":
|
||||
indicator === "dashed",
|
||||
"my-0.5": nestLabel && indicator === "dashed",
|
||||
},
|
||||
)}
|
||||
style={
|
||||
{
|
||||
"--color-bg": indicatorColor,
|
||||
"--color-border": indicatorColor,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-1 justify-between leading-none",
|
||||
nestLabel ? "items-end" : "items-center",
|
||||
)}
|
||||
>
|
||||
<div className="grid gap-1.5">
|
||||
{nestLabel ? tooltipLabel : null}
|
||||
<span className="text-muted-foreground">
|
||||
{itemConfig?.label || item.name}
|
||||
</span>
|
||||
</div>
|
||||
{item.value && (
|
||||
<span className="text-foreground font-mono font-medium tabular-nums">
|
||||
{item.value.toLocaleString()}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const ChartLegend = RechartsPrimitive.Legend;
|
||||
|
||||
function ChartLegendContent({
|
||||
className,
|
||||
hideIcon = false,
|
||||
payload,
|
||||
verticalAlign = "bottom",
|
||||
nameKey,
|
||||
}: React.ComponentProps<"div"> &
|
||||
Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
|
||||
hideIcon?: boolean;
|
||||
nameKey?: string;
|
||||
}) {
|
||||
const { config } = useChart();
|
||||
|
||||
if (!payload?.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center justify-center gap-4",
|
||||
verticalAlign === "top" ? "pb-3" : "pt-3",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{payload.map((item) => {
|
||||
const key = `${nameKey || item.dataKey || "value"}`;
|
||||
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
||||
|
||||
return (
|
||||
<div
|
||||
key={item.value}
|
||||
className={cn(
|
||||
"[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3",
|
||||
)}
|
||||
>
|
||||
{itemConfig?.icon && !hideIcon ? (
|
||||
<itemConfig.icon />
|
||||
) : (
|
||||
<div
|
||||
className="h-2 w-2 shrink-0 rounded-[2px]"
|
||||
style={{
|
||||
backgroundColor: item.color,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{itemConfig?.label}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Helper to extract item config from a payload.
|
||||
function getPayloadConfigFromPayload(
|
||||
config: ChartConfig,
|
||||
payload: unknown,
|
||||
key: string,
|
||||
) {
|
||||
if (typeof payload !== "object" || payload === null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const payloadPayload =
|
||||
"payload" in payload &&
|
||||
typeof payload.payload === "object" &&
|
||||
payload.payload !== null
|
||||
? payload.payload
|
||||
: undefined;
|
||||
|
||||
let configLabelKey: string = key;
|
||||
|
||||
if (
|
||||
key in payload &&
|
||||
typeof payload[key as keyof typeof payload] === "string"
|
||||
) {
|
||||
configLabelKey = payload[key as keyof typeof payload] as string;
|
||||
} else if (
|
||||
payloadPayload &&
|
||||
key in payloadPayload &&
|
||||
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
||||
) {
|
||||
configLabelKey = payloadPayload[
|
||||
key as keyof typeof payloadPayload
|
||||
] as string;
|
||||
}
|
||||
|
||||
return configLabelKey in config
|
||||
? config[configLabelKey]
|
||||
: config[key as keyof typeof config];
|
||||
}
|
||||
|
||||
export {
|
||||
ChartContainer,
|
||||
ChartTooltip,
|
||||
ChartTooltipContent,
|
||||
ChartLegend,
|
||||
ChartLegendContent,
|
||||
ChartStyle,
|
||||
};
|
||||
Binary file not shown.
32
source-code/ERP(A-b)-倉庫管理/src/components/ui/checkbox.tsx
Normal file
32
source-code/ERP(A-b)-倉庫管理/src/components/ui/checkbox.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as CheckboxPrimitive from "@radix-ui/react-checkbox@1.1.4";
|
||||
import { CheckIcon } from "lucide-react@0.487.0";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function Checkbox({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
||||
return (
|
||||
<CheckboxPrimitive.Root
|
||||
data-slot="checkbox"
|
||||
className={cn(
|
||||
"peer border bg-input-background dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<CheckboxPrimitive.Indicator
|
||||
data-slot="checkbox-indicator"
|
||||
className="flex items-center justify-center text-current transition-none"
|
||||
>
|
||||
<CheckIcon className="size-3.5" />
|
||||
</CheckboxPrimitive.Indicator>
|
||||
</CheckboxPrimitive.Root>
|
||||
);
|
||||
}
|
||||
|
||||
export { Checkbox };
|
||||
Binary file not shown.
33
source-code/ERP(A-b)-倉庫管理/src/components/ui/collapsible.tsx
Normal file
33
source-code/ERP(A-b)-倉庫管理/src/components/ui/collapsible.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
"use client";
|
||||
|
||||
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible@1.1.3";
|
||||
|
||||
function Collapsible({
|
||||
...props
|
||||
}: React.ComponentProps<typeof CollapsiblePrimitive.Root>) {
|
||||
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />;
|
||||
}
|
||||
|
||||
function CollapsibleTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleTrigger>) {
|
||||
return (
|
||||
<CollapsiblePrimitive.CollapsibleTrigger
|
||||
data-slot="collapsible-trigger"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CollapsibleContent({
|
||||
...props
|
||||
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleContent>) {
|
||||
return (
|
||||
<CollapsiblePrimitive.CollapsibleContent
|
||||
data-slot="collapsible-content"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Collapsible, CollapsibleTrigger, CollapsibleContent };
|
||||
Binary file not shown.
177
source-code/ERP(A-b)-倉庫管理/src/components/ui/command.tsx
Normal file
177
source-code/ERP(A-b)-倉庫管理/src/components/ui/command.tsx
Normal file
@@ -0,0 +1,177 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { Command as CommandPrimitive } from "cmdk@1.1.1";
|
||||
import { SearchIcon } from "lucide-react@0.487.0";
|
||||
|
||||
import { cn } from "./utils";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "./dialog";
|
||||
|
||||
function Command({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive>) {
|
||||
return (
|
||||
<CommandPrimitive
|
||||
data-slot="command"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CommandDialog({
|
||||
title = "Command Palette",
|
||||
description = "Search for a command to run...",
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Dialog> & {
|
||||
title?: string;
|
||||
description?: string;
|
||||
}) {
|
||||
return (
|
||||
<Dialog {...props}>
|
||||
<DialogHeader className="sr-only">
|
||||
<DialogTitle>{title}</DialogTitle>
|
||||
<DialogDescription>{description}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogContent className="overflow-hidden p-0">
|
||||
<Command className="[&_[cmdk-group-heading]]:text-muted-foreground **:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
|
||||
{children}
|
||||
</Command>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
function CommandInput({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Input>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="command-input-wrapper"
|
||||
className="flex h-9 items-center gap-2 border-b px-3"
|
||||
>
|
||||
<SearchIcon className="size-4 shrink-0 opacity-50" />
|
||||
<CommandPrimitive.Input
|
||||
data-slot="command-input"
|
||||
className={cn(
|
||||
"placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function CommandList({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.List>) {
|
||||
return (
|
||||
<CommandPrimitive.List
|
||||
data-slot="command-list"
|
||||
className={cn(
|
||||
"max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CommandEmpty({
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Empty>) {
|
||||
return (
|
||||
<CommandPrimitive.Empty
|
||||
data-slot="command-empty"
|
||||
className="py-6 text-center text-sm"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CommandGroup({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Group>) {
|
||||
return (
|
||||
<CommandPrimitive.Group
|
||||
data-slot="command-group"
|
||||
className={cn(
|
||||
"text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CommandSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Separator>) {
|
||||
return (
|
||||
<CommandPrimitive.Separator
|
||||
data-slot="command-separator"
|
||||
className={cn("bg-border -mx-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CommandItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Item>) {
|
||||
return (
|
||||
<CommandPrimitive.Item
|
||||
data-slot="command-item"
|
||||
className={cn(
|
||||
"data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CommandShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="command-shortcut"
|
||||
className={cn(
|
||||
"text-muted-foreground ml-auto text-xs tracking-widest",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Command,
|
||||
CommandDialog,
|
||||
CommandInput,
|
||||
CommandList,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandItem,
|
||||
CommandShortcut,
|
||||
CommandSeparator,
|
||||
};
|
||||
Binary file not shown.
252
source-code/ERP(A-b)-倉庫管理/src/components/ui/context-menu.tsx
Normal file
252
source-code/ERP(A-b)-倉庫管理/src/components/ui/context-menu.tsx
Normal file
@@ -0,0 +1,252 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as ContextMenuPrimitive from "@radix-ui/react-context-menu@2.2.6";
|
||||
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react@0.487.0";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function ContextMenu({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Root>) {
|
||||
return <ContextMenuPrimitive.Root data-slot="context-menu" {...props} />;
|
||||
}
|
||||
|
||||
function ContextMenuTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Trigger>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Trigger data-slot="context-menu-trigger" {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
function ContextMenuGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Group>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Group data-slot="context-menu-group" {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
function ContextMenuPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Portal>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Portal data-slot="context-menu-portal" {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
function ContextMenuSub({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Sub>) {
|
||||
return <ContextMenuPrimitive.Sub data-slot="context-menu-sub" {...props} />;
|
||||
}
|
||||
|
||||
function ContextMenuRadioGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.RadioGroup>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.RadioGroup
|
||||
data-slot="context-menu-radio-group"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function ContextMenuSubTrigger({
|
||||
className,
|
||||
inset,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<ContextMenuPrimitive.SubTrigger
|
||||
data-slot="context-menu-sub-trigger"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRightIcon className="ml-auto" />
|
||||
</ContextMenuPrimitive.SubTrigger>
|
||||
);
|
||||
}
|
||||
|
||||
function ContextMenuSubContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.SubContent>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.SubContent
|
||||
data-slot="context-menu-sub-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function ContextMenuContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Content>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Portal>
|
||||
<ContextMenuPrimitive.Content
|
||||
data-slot="context-menu-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-context-menu-content-available-height) min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</ContextMenuPrimitive.Portal>
|
||||
);
|
||||
}
|
||||
|
||||
function ContextMenuItem({
|
||||
className,
|
||||
inset,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Item> & {
|
||||
inset?: boolean;
|
||||
variant?: "default" | "destructive";
|
||||
}) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Item
|
||||
data-slot="context-menu-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function ContextMenuCheckboxItem({
|
||||
className,
|
||||
children,
|
||||
checked,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.CheckboxItem>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.CheckboxItem
|
||||
data-slot="context-menu-checkbox-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<ContextMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon className="size-4" />
|
||||
</ContextMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</ContextMenuPrimitive.CheckboxItem>
|
||||
);
|
||||
}
|
||||
|
||||
function ContextMenuRadioItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.RadioItem>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.RadioItem
|
||||
data-slot="context-menu-radio-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<ContextMenuPrimitive.ItemIndicator>
|
||||
<CircleIcon className="size-2 fill-current" />
|
||||
</ContextMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</ContextMenuPrimitive.RadioItem>
|
||||
);
|
||||
}
|
||||
|
||||
function ContextMenuLabel({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Label> & {
|
||||
inset?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Label
|
||||
data-slot="context-menu-label"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"text-foreground px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function ContextMenuSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Separator>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Separator
|
||||
data-slot="context-menu-separator"
|
||||
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function ContextMenuShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="context-menu-shortcut"
|
||||
className={cn(
|
||||
"text-muted-foreground ml-auto text-xs tracking-widest",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
ContextMenu,
|
||||
ContextMenuTrigger,
|
||||
ContextMenuContent,
|
||||
ContextMenuItem,
|
||||
ContextMenuCheckboxItem,
|
||||
ContextMenuRadioItem,
|
||||
ContextMenuLabel,
|
||||
ContextMenuSeparator,
|
||||
ContextMenuShortcut,
|
||||
ContextMenuGroup,
|
||||
ContextMenuPortal,
|
||||
ContextMenuSub,
|
||||
ContextMenuSubContent,
|
||||
ContextMenuSubTrigger,
|
||||
ContextMenuRadioGroup,
|
||||
};
|
||||
Binary file not shown.
137
source-code/ERP(A-b)-倉庫管理/src/components/ui/dialog.tsx
Normal file
137
source-code/ERP(A-b)-倉庫管理/src/components/ui/dialog.tsx
Normal file
@@ -0,0 +1,137 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog@1.1.6";
|
||||
import { XIcon } from "lucide-react@0.487.0";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function Dialog({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
||||
return <DialogPrimitive.Root data-slot="dialog" {...props} />;
|
||||
}
|
||||
|
||||
function DialogTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
||||
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function DialogPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
||||
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
|
||||
}
|
||||
|
||||
function DialogClose({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
||||
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
|
||||
}
|
||||
|
||||
const DialogOverlay = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => {
|
||||
return (
|
||||
<DialogPrimitive.Overlay
|
||||
ref={ref}
|
||||
data-slot="dialog-overlay"
|
||||
className={cn(
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
||||
|
||||
function DialogContent({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Content>) {
|
||||
return (
|
||||
<DialogPortal data-slot="dialog-portal">
|
||||
<DialogOverlay />
|
||||
<DialogPrimitive.Content
|
||||
data-slot="dialog-content"
|
||||
className={cn(
|
||||
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<DialogPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4">
|
||||
<XIcon />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
</DialogPrimitive.Content>
|
||||
</DialogPortal>
|
||||
);
|
||||
}
|
||||
|
||||
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="dialog-header"
|
||||
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="dialog-footer"
|
||||
className={cn(
|
||||
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DialogTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
||||
return (
|
||||
<DialogPrimitive.Title
|
||||
data-slot="dialog-title"
|
||||
className={cn("text-lg leading-none font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DialogDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
||||
return (
|
||||
<DialogPrimitive.Description
|
||||
data-slot="dialog-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogOverlay,
|
||||
DialogPortal,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
};
|
||||
Binary file not shown.
132
source-code/ERP(A-b)-倉庫管理/src/components/ui/drawer.tsx
Normal file
132
source-code/ERP(A-b)-倉庫管理/src/components/ui/drawer.tsx
Normal file
@@ -0,0 +1,132 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { Drawer as DrawerPrimitive } from "vaul@1.1.2";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function Drawer({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Root>) {
|
||||
return <DrawerPrimitive.Root data-slot="drawer" {...props} />;
|
||||
}
|
||||
|
||||
function DrawerTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Trigger>) {
|
||||
return <DrawerPrimitive.Trigger data-slot="drawer-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function DrawerPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Portal>) {
|
||||
return <DrawerPrimitive.Portal data-slot="drawer-portal" {...props} />;
|
||||
}
|
||||
|
||||
function DrawerClose({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Close>) {
|
||||
return <DrawerPrimitive.Close data-slot="drawer-close" {...props} />;
|
||||
}
|
||||
|
||||
function DrawerOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Overlay>) {
|
||||
return (
|
||||
<DrawerPrimitive.Overlay
|
||||
data-slot="drawer-overlay"
|
||||
className={cn(
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DrawerContent({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Content>) {
|
||||
return (
|
||||
<DrawerPortal data-slot="drawer-portal">
|
||||
<DrawerOverlay />
|
||||
<DrawerPrimitive.Content
|
||||
data-slot="drawer-content"
|
||||
className={cn(
|
||||
"group/drawer-content bg-background fixed z-50 flex h-auto flex-col",
|
||||
"data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=top]:rounded-b-lg data-[vaul-drawer-direction=top]:border-b",
|
||||
"data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=bottom]:rounded-t-lg data-[vaul-drawer-direction=bottom]:border-t",
|
||||
"data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:border-l data-[vaul-drawer-direction=right]:sm:max-w-sm",
|
||||
"data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:border-r data-[vaul-drawer-direction=left]:sm:max-w-sm",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div className="bg-muted mx-auto mt-4 hidden h-2 w-[100px] shrink-0 rounded-full group-data-[vaul-drawer-direction=bottom]/drawer-content:block" />
|
||||
{children}
|
||||
</DrawerPrimitive.Content>
|
||||
</DrawerPortal>
|
||||
);
|
||||
}
|
||||
|
||||
function DrawerHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="drawer-header"
|
||||
className={cn("flex flex-col gap-1.5 p-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DrawerFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="drawer-footer"
|
||||
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DrawerTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Title>) {
|
||||
return (
|
||||
<DrawerPrimitive.Title
|
||||
data-slot="drawer-title"
|
||||
className={cn("text-foreground font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DrawerDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Description>) {
|
||||
return (
|
||||
<DrawerPrimitive.Description
|
||||
data-slot="drawer-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Drawer,
|
||||
DrawerPortal,
|
||||
DrawerOverlay,
|
||||
DrawerTrigger,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerHeader,
|
||||
DrawerFooter,
|
||||
DrawerTitle,
|
||||
DrawerDescription,
|
||||
};
|
||||
Binary file not shown.
257
source-code/ERP(A-b)-倉庫管理/src/components/ui/dropdown-menu.tsx
Normal file
257
source-code/ERP(A-b)-倉庫管理/src/components/ui/dropdown-menu.tsx
Normal file
@@ -0,0 +1,257 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu@2.1.6";
|
||||
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react@0.487.0";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function DropdownMenu({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
||||
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />;
|
||||
}
|
||||
|
||||
function DropdownMenuPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Trigger
|
||||
data-slot="dropdown-menu-trigger"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuContent({
|
||||
className,
|
||||
sideOffset = 4,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Portal>
|
||||
<DropdownMenuPrimitive.Content
|
||||
data-slot="dropdown-menu-content"
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</DropdownMenuPrimitive.Portal>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuItem({
|
||||
className,
|
||||
inset,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
||||
inset?: boolean;
|
||||
variant?: "default" | "destructive";
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Item
|
||||
data-slot="dropdown-menu-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuCheckboxItem({
|
||||
className,
|
||||
children,
|
||||
checked,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.CheckboxItem
|
||||
data-slot="dropdown-menu-checkbox-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon className="size-4" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.CheckboxItem>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuRadioGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.RadioGroup
|
||||
data-slot="dropdown-menu-radio-group"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuRadioItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.RadioItem
|
||||
data-slot="dropdown-menu-radio-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CircleIcon className="size-2 fill-current" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.RadioItem>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuLabel({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
||||
inset?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Label
|
||||
data-slot="dropdown-menu-label"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Separator
|
||||
data-slot="dropdown-menu-separator"
|
||||
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="dropdown-menu-shortcut"
|
||||
className={cn(
|
||||
"text-muted-foreground ml-auto text-xs tracking-widest",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuSub({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
||||
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />;
|
||||
}
|
||||
|
||||
function DropdownMenuSubTrigger({
|
||||
className,
|
||||
inset,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubTrigger
|
||||
data-slot="dropdown-menu-sub-trigger"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRightIcon className="ml-auto size-4" />
|
||||
</DropdownMenuPrimitive.SubTrigger>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuSubContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubContent
|
||||
data-slot="dropdown-menu-sub-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
DropdownMenu,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuSubContent,
|
||||
};
|
||||
Binary file not shown.
168
source-code/ERP(A-b)-倉庫管理/src/components/ui/form.tsx
Normal file
168
source-code/ERP(A-b)-倉庫管理/src/components/ui/form.tsx
Normal file
@@ -0,0 +1,168 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as LabelPrimitive from "@radix-ui/react-label@2.1.2";
|
||||
import { Slot } from "@radix-ui/react-slot@1.1.2";
|
||||
import {
|
||||
Controller,
|
||||
FormProvider,
|
||||
useFormContext,
|
||||
useFormState,
|
||||
type ControllerProps,
|
||||
type FieldPath,
|
||||
type FieldValues,
|
||||
} from "react-hook-form@7.55.0";
|
||||
|
||||
import { cn } from "./utils";
|
||||
import { Label } from "./label";
|
||||
|
||||
const Form = FormProvider;
|
||||
|
||||
type FormFieldContextValue<
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||
> = {
|
||||
name: TName;
|
||||
};
|
||||
|
||||
const FormFieldContext = React.createContext<FormFieldContextValue>(
|
||||
{} as FormFieldContextValue,
|
||||
);
|
||||
|
||||
const FormField = <
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||
>({
|
||||
...props
|
||||
}: ControllerProps<TFieldValues, TName>) => {
|
||||
return (
|
||||
<FormFieldContext.Provider value={{ name: props.name }}>
|
||||
<Controller {...props} />
|
||||
</FormFieldContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
const useFormField = () => {
|
||||
const fieldContext = React.useContext(FormFieldContext);
|
||||
const itemContext = React.useContext(FormItemContext);
|
||||
const { getFieldState } = useFormContext();
|
||||
const formState = useFormState({ name: fieldContext.name });
|
||||
const fieldState = getFieldState(fieldContext.name, formState);
|
||||
|
||||
if (!fieldContext) {
|
||||
throw new Error("useFormField should be used within <FormField>");
|
||||
}
|
||||
|
||||
const { id } = itemContext;
|
||||
|
||||
return {
|
||||
id,
|
||||
name: fieldContext.name,
|
||||
formItemId: `${id}-form-item`,
|
||||
formDescriptionId: `${id}-form-item-description`,
|
||||
formMessageId: `${id}-form-item-message`,
|
||||
...fieldState,
|
||||
};
|
||||
};
|
||||
|
||||
type FormItemContextValue = {
|
||||
id: string;
|
||||
};
|
||||
|
||||
const FormItemContext = React.createContext<FormItemContextValue>(
|
||||
{} as FormItemContextValue,
|
||||
);
|
||||
|
||||
function FormItem({ className, ...props }: React.ComponentProps<"div">) {
|
||||
const id = React.useId();
|
||||
|
||||
return (
|
||||
<FormItemContext.Provider value={{ id }}>
|
||||
<div
|
||||
data-slot="form-item"
|
||||
className={cn("grid gap-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
</FormItemContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
function FormLabel({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||
const { error, formItemId } = useFormField();
|
||||
|
||||
return (
|
||||
<Label
|
||||
data-slot="form-label"
|
||||
data-error={!!error}
|
||||
className={cn("data-[error=true]:text-destructive", className)}
|
||||
htmlFor={formItemId}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function FormControl({ ...props }: React.ComponentProps<typeof Slot>) {
|
||||
const { error, formItemId, formDescriptionId, formMessageId } =
|
||||
useFormField();
|
||||
|
||||
return (
|
||||
<Slot
|
||||
data-slot="form-control"
|
||||
id={formItemId}
|
||||
aria-describedby={
|
||||
!error
|
||||
? `${formDescriptionId}`
|
||||
: `${formDescriptionId} ${formMessageId}`
|
||||
}
|
||||
aria-invalid={!!error}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
|
||||
const { formDescriptionId } = useFormField();
|
||||
|
||||
return (
|
||||
<p
|
||||
data-slot="form-description"
|
||||
id={formDescriptionId}
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
|
||||
const { error, formMessageId } = useFormField();
|
||||
const body = error ? String(error?.message ?? "") : props.children;
|
||||
|
||||
if (!body) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<p
|
||||
data-slot="form-message"
|
||||
id={formMessageId}
|
||||
className={cn("text-destructive text-sm", className)}
|
||||
{...props}
|
||||
>
|
||||
{body}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
useFormField,
|
||||
Form,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormControl,
|
||||
FormDescription,
|
||||
FormMessage,
|
||||
FormField,
|
||||
};
|
||||
Binary file not shown.
44
source-code/ERP(A-b)-倉庫管理/src/components/ui/hover-card.tsx
Normal file
44
source-code/ERP(A-b)-倉庫管理/src/components/ui/hover-card.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as HoverCardPrimitive from "@radix-ui/react-hover-card@1.1.6";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function HoverCard({
|
||||
...props
|
||||
}: React.ComponentProps<typeof HoverCardPrimitive.Root>) {
|
||||
return <HoverCardPrimitive.Root data-slot="hover-card" {...props} />;
|
||||
}
|
||||
|
||||
function HoverCardTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof HoverCardPrimitive.Trigger>) {
|
||||
return (
|
||||
<HoverCardPrimitive.Trigger data-slot="hover-card-trigger" {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
function HoverCardContent({
|
||||
className,
|
||||
align = "center",
|
||||
sideOffset = 4,
|
||||
...props
|
||||
}: React.ComponentProps<typeof HoverCardPrimitive.Content>) {
|
||||
return (
|
||||
<HoverCardPrimitive.Portal data-slot="hover-card-portal">
|
||||
<HoverCardPrimitive.Content
|
||||
data-slot="hover-card-content"
|
||||
align={align}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-64 origin-(--radix-hover-card-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</HoverCardPrimitive.Portal>
|
||||
);
|
||||
}
|
||||
|
||||
export { HoverCard, HoverCardTrigger, HoverCardContent };
|
||||
Binary file not shown.
77
source-code/ERP(A-b)-倉庫管理/src/components/ui/input-otp.tsx
Normal file
77
source-code/ERP(A-b)-倉庫管理/src/components/ui/input-otp.tsx
Normal file
@@ -0,0 +1,77 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { OTPInput, OTPInputContext } from "input-otp@1.4.2";
|
||||
import { MinusIcon } from "lucide-react@0.487.0";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function InputOTP({
|
||||
className,
|
||||
containerClassName,
|
||||
...props
|
||||
}: React.ComponentProps<typeof OTPInput> & {
|
||||
containerClassName?: string;
|
||||
}) {
|
||||
return (
|
||||
<OTPInput
|
||||
data-slot="input-otp"
|
||||
containerClassName={cn(
|
||||
"flex items-center gap-2 has-disabled:opacity-50",
|
||||
containerClassName,
|
||||
)}
|
||||
className={cn("disabled:cursor-not-allowed", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function InputOTPGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="input-otp-group"
|
||||
className={cn("flex items-center gap-1", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function InputOTPSlot({
|
||||
index,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
index: number;
|
||||
}) {
|
||||
const inputOTPContext = React.useContext(OTPInputContext);
|
||||
const { char, hasFakeCaret, isActive } = inputOTPContext?.slots[index] ?? {};
|
||||
|
||||
return (
|
||||
<div
|
||||
data-slot="input-otp-slot"
|
||||
data-active={isActive}
|
||||
className={cn(
|
||||
"data-[active=true]:border-ring data-[active=true]:ring-ring/50 data-[active=true]:aria-invalid:ring-destructive/20 dark:data-[active=true]:aria-invalid:ring-destructive/40 aria-invalid:border-destructive data-[active=true]:aria-invalid:border-destructive dark:bg-input/30 border-input relative flex h-9 w-9 items-center justify-center border-y border-r text-sm bg-input-background transition-all outline-none first:rounded-l-md first:border-l last:rounded-r-md data-[active=true]:z-10 data-[active=true]:ring-[3px]",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{char}
|
||||
{hasFakeCaret && (
|
||||
<div className="pointer-events-none absolute inset-0 flex items-center justify-center">
|
||||
<div className="animate-caret-blink bg-foreground h-4 w-px duration-1000" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function InputOTPSeparator({ ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div data-slot="input-otp-separator" role="separator" {...props}>
|
||||
<MinusIcon />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator };
|
||||
Binary file not shown.
21
source-code/ERP(A-b)-倉庫管理/src/components/ui/input.tsx
Normal file
21
source-code/ERP(A-b)-倉庫管理/src/components/ui/input.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import * as React from "react";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
data-slot="input"
|
||||
className={cn(
|
||||
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 flex h-9 w-full min-w-0 rounded-md border-2 border-grey-3 px-3 py-1 text-base bg-input-background transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||
"focus-visible:border-primary focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
||||
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive aria-invalid:border-2",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Input };
|
||||
Binary file not shown.
24
source-code/ERP(A-b)-倉庫管理/src/components/ui/label.tsx
Normal file
24
source-code/ERP(A-b)-倉庫管理/src/components/ui/label.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as LabelPrimitive from "@radix-ui/react-label@2.1.2";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function Label({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||
return (
|
||||
<LabelPrimitive.Root
|
||||
data-slot="label"
|
||||
className={cn(
|
||||
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Label };
|
||||
Binary file not shown.
276
source-code/ERP(A-b)-倉庫管理/src/components/ui/menubar.tsx
Normal file
276
source-code/ERP(A-b)-倉庫管理/src/components/ui/menubar.tsx
Normal file
@@ -0,0 +1,276 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as MenubarPrimitive from "@radix-ui/react-menubar@1.1.6";
|
||||
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react@0.487.0";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function Menubar({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Root>) {
|
||||
return (
|
||||
<MenubarPrimitive.Root
|
||||
data-slot="menubar"
|
||||
className={cn(
|
||||
"bg-background flex h-9 items-center gap-1 rounded-md border p-1 shadow-xs",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function MenubarMenu({
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Menu>) {
|
||||
return <MenubarPrimitive.Menu data-slot="menubar-menu" {...props} />;
|
||||
}
|
||||
|
||||
function MenubarGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Group>) {
|
||||
return <MenubarPrimitive.Group data-slot="menubar-group" {...props} />;
|
||||
}
|
||||
|
||||
function MenubarPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Portal>) {
|
||||
return <MenubarPrimitive.Portal data-slot="menubar-portal" {...props} />;
|
||||
}
|
||||
|
||||
function MenubarRadioGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.RadioGroup>) {
|
||||
return (
|
||||
<MenubarPrimitive.RadioGroup data-slot="menubar-radio-group" {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
function MenubarTrigger({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Trigger>) {
|
||||
return (
|
||||
<MenubarPrimitive.Trigger
|
||||
data-slot="menubar-trigger"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex items-center rounded-sm px-2 py-1 text-sm font-medium outline-hidden select-none",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function MenubarContent({
|
||||
className,
|
||||
align = "start",
|
||||
alignOffset = -4,
|
||||
sideOffset = 8,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Content>) {
|
||||
return (
|
||||
<MenubarPortal>
|
||||
<MenubarPrimitive.Content
|
||||
data-slot="menubar-content"
|
||||
align={align}
|
||||
alignOffset={alignOffset}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[12rem] origin-(--radix-menubar-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-md",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</MenubarPortal>
|
||||
);
|
||||
}
|
||||
|
||||
function MenubarItem({
|
||||
className,
|
||||
inset,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Item> & {
|
||||
inset?: boolean;
|
||||
variant?: "default" | "destructive";
|
||||
}) {
|
||||
return (
|
||||
<MenubarPrimitive.Item
|
||||
data-slot="menubar-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function MenubarCheckboxItem({
|
||||
className,
|
||||
children,
|
||||
checked,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.CheckboxItem>) {
|
||||
return (
|
||||
<MenubarPrimitive.CheckboxItem
|
||||
data-slot="menubar-checkbox-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-xs py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<MenubarPrimitive.ItemIndicator>
|
||||
<CheckIcon className="size-4" />
|
||||
</MenubarPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</MenubarPrimitive.CheckboxItem>
|
||||
);
|
||||
}
|
||||
|
||||
function MenubarRadioItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.RadioItem>) {
|
||||
return (
|
||||
<MenubarPrimitive.RadioItem
|
||||
data-slot="menubar-radio-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-xs py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<MenubarPrimitive.ItemIndicator>
|
||||
<CircleIcon className="size-2 fill-current" />
|
||||
</MenubarPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</MenubarPrimitive.RadioItem>
|
||||
);
|
||||
}
|
||||
|
||||
function MenubarLabel({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Label> & {
|
||||
inset?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<MenubarPrimitive.Label
|
||||
data-slot="menubar-label"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function MenubarSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Separator>) {
|
||||
return (
|
||||
<MenubarPrimitive.Separator
|
||||
data-slot="menubar-separator"
|
||||
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function MenubarShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="menubar-shortcut"
|
||||
className={cn(
|
||||
"text-muted-foreground ml-auto text-xs tracking-widest",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function MenubarSub({
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Sub>) {
|
||||
return <MenubarPrimitive.Sub data-slot="menubar-sub" {...props} />;
|
||||
}
|
||||
|
||||
function MenubarSubTrigger({
|
||||
className,
|
||||
inset,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.SubTrigger> & {
|
||||
inset?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<MenubarPrimitive.SubTrigger
|
||||
data-slot="menubar-sub-trigger"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none data-[inset]:pl-8",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRightIcon className="ml-auto h-4 w-4" />
|
||||
</MenubarPrimitive.SubTrigger>
|
||||
);
|
||||
}
|
||||
|
||||
function MenubarSubContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.SubContent>) {
|
||||
return (
|
||||
<MenubarPrimitive.SubContent
|
||||
data-slot="menubar-sub-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-menubar-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Menubar,
|
||||
MenubarPortal,
|
||||
MenubarMenu,
|
||||
MenubarTrigger,
|
||||
MenubarContent,
|
||||
MenubarGroup,
|
||||
MenubarSeparator,
|
||||
MenubarLabel,
|
||||
MenubarItem,
|
||||
MenubarShortcut,
|
||||
MenubarCheckboxItem,
|
||||
MenubarRadioGroup,
|
||||
MenubarRadioItem,
|
||||
MenubarSub,
|
||||
MenubarSubTrigger,
|
||||
MenubarSubContent,
|
||||
};
|
||||
Binary file not shown.
168
source-code/ERP(A-b)-倉庫管理/src/components/ui/navigation-menu.tsx
Normal file
168
source-code/ERP(A-b)-倉庫管理/src/components/ui/navigation-menu.tsx
Normal file
@@ -0,0 +1,168 @@
|
||||
import * as React from "react";
|
||||
import * as NavigationMenuPrimitive from "@radix-ui/react-navigation-menu@1.2.5";
|
||||
import { cva } from "class-variance-authority@0.7.1";
|
||||
import { ChevronDownIcon } from "lucide-react@0.487.0";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function NavigationMenu({
|
||||
className,
|
||||
children,
|
||||
viewport = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.Root> & {
|
||||
viewport?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<NavigationMenuPrimitive.Root
|
||||
data-slot="navigation-menu"
|
||||
data-viewport={viewport}
|
||||
className={cn(
|
||||
"group/navigation-menu relative flex max-w-max flex-1 items-center justify-center",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{viewport && <NavigationMenuViewport />}
|
||||
</NavigationMenuPrimitive.Root>
|
||||
);
|
||||
}
|
||||
|
||||
function NavigationMenuList({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.List>) {
|
||||
return (
|
||||
<NavigationMenuPrimitive.List
|
||||
data-slot="navigation-menu-list"
|
||||
className={cn(
|
||||
"group flex flex-1 list-none items-center justify-center gap-1",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function NavigationMenuItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.Item>) {
|
||||
return (
|
||||
<NavigationMenuPrimitive.Item
|
||||
data-slot="navigation-menu-item"
|
||||
className={cn("relative", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const navigationMenuTriggerStyle = cva(
|
||||
"group inline-flex h-9 w-max items-center justify-center rounded-md bg-background px-4 py-2 text-sm font-medium hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=open]:hover:bg-accent data-[state=open]:text-accent-foreground data-[state=open]:focus:bg-accent data-[state=open]:bg-accent/50 focus-visible:ring-ring/50 outline-none transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1",
|
||||
);
|
||||
|
||||
function NavigationMenuTrigger({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.Trigger>) {
|
||||
return (
|
||||
<NavigationMenuPrimitive.Trigger
|
||||
data-slot="navigation-menu-trigger"
|
||||
className={cn(navigationMenuTriggerStyle(), "group", className)}
|
||||
{...props}
|
||||
>
|
||||
{children}{" "}
|
||||
<ChevronDownIcon
|
||||
className="relative top-[1px] ml-1 size-3 transition duration-300 group-data-[state=open]:rotate-180"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</NavigationMenuPrimitive.Trigger>
|
||||
);
|
||||
}
|
||||
|
||||
function NavigationMenuContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.Content>) {
|
||||
return (
|
||||
<NavigationMenuPrimitive.Content
|
||||
data-slot="navigation-menu-content"
|
||||
className={cn(
|
||||
"data-[motion^=from-]:animate-in data-[motion^=to-]:animate-out data-[motion^=from-]:fade-in data-[motion^=to-]:fade-out data-[motion=from-end]:slide-in-from-right-52 data-[motion=from-start]:slide-in-from-left-52 data-[motion=to-end]:slide-out-to-right-52 data-[motion=to-start]:slide-out-to-left-52 top-0 left-0 w-full p-2 pr-2.5 md:absolute md:w-auto",
|
||||
"group-data-[viewport=false]/navigation-menu:bg-popover group-data-[viewport=false]/navigation-menu:text-popover-foreground group-data-[viewport=false]/navigation-menu:data-[state=open]:animate-in group-data-[viewport=false]/navigation-menu:data-[state=closed]:animate-out group-data-[viewport=false]/navigation-menu:data-[state=closed]:zoom-out-95 group-data-[viewport=false]/navigation-menu:data-[state=open]:zoom-in-95 group-data-[viewport=false]/navigation-menu:data-[state=open]:fade-in-0 group-data-[viewport=false]/navigation-menu:data-[state=closed]:fade-out-0 group-data-[viewport=false]/navigation-menu:top-full group-data-[viewport=false]/navigation-menu:mt-1.5 group-data-[viewport=false]/navigation-menu:overflow-hidden group-data-[viewport=false]/navigation-menu:rounded-md group-data-[viewport=false]/navigation-menu:border group-data-[viewport=false]/navigation-menu:shadow group-data-[viewport=false]/navigation-menu:duration-200 **:data-[slot=navigation-menu-link]:focus:ring-0 **:data-[slot=navigation-menu-link]:focus:outline-none",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function NavigationMenuViewport({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.Viewport>) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"absolute top-full left-0 isolate z-50 flex justify-center",
|
||||
)}
|
||||
>
|
||||
<NavigationMenuPrimitive.Viewport
|
||||
data-slot="navigation-menu-viewport"
|
||||
className={cn(
|
||||
"origin-top-center bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-90 relative mt-1.5 h-[var(--radix-navigation-menu-viewport-height)] w-full overflow-hidden rounded-md border shadow md:w-[var(--radix-navigation-menu-viewport-width)]",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function NavigationMenuLink({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.Link>) {
|
||||
return (
|
||||
<NavigationMenuPrimitive.Link
|
||||
data-slot="navigation-menu-link"
|
||||
className={cn(
|
||||
"data-[active=true]:focus:bg-accent data-[active=true]:hover:bg-accent data-[active=true]:bg-accent/50 data-[active=true]:text-accent-foreground hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus-visible:ring-ring/50 [&_svg:not([class*='text-'])]:text-muted-foreground flex flex-col gap-1 rounded-sm p-2 text-sm transition-all outline-none focus-visible:ring-[3px] focus-visible:outline-1 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function NavigationMenuIndicator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.Indicator>) {
|
||||
return (
|
||||
<NavigationMenuPrimitive.Indicator
|
||||
data-slot="navigation-menu-indicator"
|
||||
className={cn(
|
||||
"data-[state=visible]:animate-in data-[state=hidden]:animate-out data-[state=hidden]:fade-out data-[state=visible]:fade-in top-full z-[1] flex h-1.5 items-end justify-center overflow-hidden",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div className="bg-border relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm shadow-md" />
|
||||
</NavigationMenuPrimitive.Indicator>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
NavigationMenu,
|
||||
NavigationMenuList,
|
||||
NavigationMenuItem,
|
||||
NavigationMenuContent,
|
||||
NavigationMenuTrigger,
|
||||
NavigationMenuLink,
|
||||
NavigationMenuIndicator,
|
||||
NavigationMenuViewport,
|
||||
navigationMenuTriggerStyle,
|
||||
};
|
||||
Binary file not shown.
127
source-code/ERP(A-b)-倉庫管理/src/components/ui/pagination.tsx
Normal file
127
source-code/ERP(A-b)-倉庫管理/src/components/ui/pagination.tsx
Normal file
@@ -0,0 +1,127 @@
|
||||
import * as React from "react";
|
||||
import {
|
||||
ChevronLeftIcon,
|
||||
ChevronRightIcon,
|
||||
MoreHorizontalIcon,
|
||||
} from "lucide-react@0.487.0";
|
||||
|
||||
import { cn } from "./utils";
|
||||
import { Button, buttonVariants } from "./button";
|
||||
|
||||
function Pagination({ className, ...props }: React.ComponentProps<"nav">) {
|
||||
return (
|
||||
<nav
|
||||
role="navigation"
|
||||
aria-label="pagination"
|
||||
data-slot="pagination"
|
||||
className={cn("mx-auto flex w-full justify-center", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function PaginationContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"ul">) {
|
||||
return (
|
||||
<ul
|
||||
data-slot="pagination-content"
|
||||
className={cn("flex flex-row items-center gap-1", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function PaginationItem({ ...props }: React.ComponentProps<"li">) {
|
||||
return <li data-slot="pagination-item" {...props} />;
|
||||
}
|
||||
|
||||
type PaginationLinkProps = {
|
||||
isActive?: boolean;
|
||||
} & Pick<React.ComponentProps<typeof Button>, "size"> &
|
||||
React.ComponentProps<"a">;
|
||||
|
||||
function PaginationLink({
|
||||
className,
|
||||
isActive,
|
||||
size = "icon",
|
||||
...props
|
||||
}: PaginationLinkProps) {
|
||||
return (
|
||||
<a
|
||||
aria-current={isActive ? "page" : undefined}
|
||||
data-slot="pagination-link"
|
||||
data-active={isActive}
|
||||
className={cn(
|
||||
buttonVariants({
|
||||
variant: isActive ? "outline" : "ghost",
|
||||
size,
|
||||
}),
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function PaginationPrevious({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof PaginationLink>) {
|
||||
return (
|
||||
<PaginationLink
|
||||
aria-label="Go to previous page"
|
||||
size="default"
|
||||
className={cn("gap-1 px-2.5 sm:pl-2.5", className)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronLeftIcon />
|
||||
<span className="hidden sm:block">Previous</span>
|
||||
</PaginationLink>
|
||||
);
|
||||
}
|
||||
|
||||
function PaginationNext({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof PaginationLink>) {
|
||||
return (
|
||||
<PaginationLink
|
||||
aria-label="Go to next page"
|
||||
size="default"
|
||||
className={cn("gap-1 px-2.5 sm:pr-2.5", className)}
|
||||
{...props}
|
||||
>
|
||||
<span className="hidden sm:block">Next</span>
|
||||
<ChevronRightIcon />
|
||||
</PaginationLink>
|
||||
);
|
||||
}
|
||||
|
||||
function PaginationEllipsis({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
aria-hidden
|
||||
data-slot="pagination-ellipsis"
|
||||
className={cn("flex size-9 items-center justify-center", className)}
|
||||
{...props}
|
||||
>
|
||||
<MoreHorizontalIcon className="size-4" />
|
||||
<span className="sr-only">More pages</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationLink,
|
||||
PaginationItem,
|
||||
PaginationPrevious,
|
||||
PaginationNext,
|
||||
PaginationEllipsis,
|
||||
};
|
||||
Binary file not shown.
48
source-code/ERP(A-b)-倉庫管理/src/components/ui/popover.tsx
Normal file
48
source-code/ERP(A-b)-倉庫管理/src/components/ui/popover.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as PopoverPrimitive from "@radix-ui/react-popover@1.1.6";
|
||||
|
||||
import { cn } from "./utils";
|
||||
|
||||
function Popover({
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Root>) {
|
||||
return <PopoverPrimitive.Root data-slot="popover" {...props} />;
|
||||
}
|
||||
|
||||
function PopoverTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {
|
||||
return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function PopoverContent({
|
||||
className,
|
||||
align = "center",
|
||||
sideOffset = 4,
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Content>) {
|
||||
return (
|
||||
<PopoverPrimitive.Portal>
|
||||
<PopoverPrimitive.Content
|
||||
data-slot="popover-content"
|
||||
align={align}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</PopoverPrimitive.Portal>
|
||||
);
|
||||
}
|
||||
|
||||
function PopoverAnchor({
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Anchor>) {
|
||||
return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />;
|
||||
}
|
||||
|
||||
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor };
|
||||
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user