From f87310e707827c35e1a6a565c62fa796da333122 Mon Sep 17 00:00:00 2001 From: sky121113 Date: Mon, 2 Feb 2026 15:07:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E5=95=86=E5=93=81?= =?UTF-8?q?=E4=BB=A3=E8=99=9F=E9=A9=97=E8=AD=89=E8=A6=8F=E5=89=87=E7=82=BA?= =?UTF-8?q?=202-8=20=E7=A2=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. ProductImport.php: 匯入規則調整 2. ProductController.php: 新增/編輯 API 規則調整 3. UI: 匯入與編輯視窗提示更新 --- .../Inventory/Controllers/ProductController.php | 12 ++++++------ app/Modules/Inventory/Imports/ProductImport.php | 2 +- resources/js/Components/Product/ProductDialog.tsx | 4 ++-- .../js/Components/Product/ProductImportDialog.tsx | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/Modules/Inventory/Controllers/ProductController.php b/app/Modules/Inventory/Controllers/ProductController.php index 71650be..ee67217 100644 --- a/app/Modules/Inventory/Controllers/ProductController.php +++ b/app/Modules/Inventory/Controllers/ProductController.php @@ -114,7 +114,7 @@ class ProductController extends Controller public function store(Request $request) { $validated = $request->validate([ - 'code' => 'required|string|min:1|max:5|unique:products,code', + 'code' => 'required|string|min:2|max:8|unique:products,code', 'barcode' => 'required|string|unique:products,barcode', 'name' => 'required|string|max:255', 'category_id' => 'required|exists:categories,id', @@ -127,8 +127,8 @@ class ProductController extends Controller 'purchase_unit_id' => 'nullable|exists:units,id', ], [ 'code.required' => '商品代號為必填', - 'code.max' => '商品代號最多 5 碼', - 'code.min' => '商品代號最少 1 碼', + 'code.max' => '商品代號最多 8 碼', + 'code.min' => '商品代號最少 2 碼', 'code.unique' => '商品代號已存在', 'barcode.required' => '條碼編號為必填', 'barcode.unique' => '條碼編號已存在', @@ -153,7 +153,7 @@ class ProductController extends Controller public function update(Request $request, Product $product) { $validated = $request->validate([ - 'code' => 'required|string|min:1|max:5|unique:products,code,' . $product->id, + 'code' => 'required|string|min:2|max:8|unique:products,code,' . $product->id, 'barcode' => 'required|string|unique:products,barcode,' . $product->id, 'name' => 'required|string|max:255', 'category_id' => 'required|exists:categories,id', @@ -165,8 +165,8 @@ class ProductController extends Controller 'purchase_unit_id' => 'nullable|exists:units,id', ], [ 'code.required' => '商品代號為必填', - 'code.max' => '商品代號最多 5 碼', - 'code.min' => '商品代號最少 1 碼', + 'code.max' => '商品代號最多 8 碼', + 'code.min' => '商品代號最少 2 碼', 'code.unique' => '商品代號已存在', 'barcode.required' => '條碼編號為必填', 'barcode.unique' => '條碼編號已存在', diff --git a/app/Modules/Inventory/Imports/ProductImport.php b/app/Modules/Inventory/Imports/ProductImport.php index cfc62a8..8f7e7dc 100644 --- a/app/Modules/Inventory/Imports/ProductImport.php +++ b/app/Modules/Inventory/Imports/ProductImport.php @@ -80,7 +80,7 @@ class ProductImport implements ToModel, WithHeadingRow, WithValidation, WithMapp public function rules(): array { return [ - '商品代號' => ['required', 'string', 'min:1', 'max:5', 'unique:products,code'], + '商品代號' => ['required', 'string', 'min:2', 'max:8', 'unique:products,code'], '條碼' => ['required', 'string', 'unique:products,barcode'], '商品名稱' => ['required', 'string'], '類別名稱' => ['required', function($attribute, $value, $fail) { diff --git a/resources/js/Components/Product/ProductDialog.tsx b/resources/js/Components/Product/ProductDialog.tsx index 2dc998f..d0ce95e 100644 --- a/resources/js/Components/Product/ProductDialog.tsx +++ b/resources/js/Components/Product/ProductDialog.tsx @@ -160,8 +160,8 @@ export default function ProductDialog({ id="code" value={data.code} onChange={(e) => setData("code", e.target.value)} - placeholder="例:A1 (最多2碼)" - maxLength={2} + placeholder="例:A1 (2-8碼)" + maxLength={8} className={errors.code ? "border-red-500" : ""} /> {errors.code &&

{errors.code}

} diff --git a/resources/js/Components/Product/ProductImportDialog.tsx b/resources/js/Components/Product/ProductImportDialog.tsx index eab852b..cc66e07 100644 --- a/resources/js/Components/Product/ProductImportDialog.tsx +++ b/resources/js/Components/Product/ProductImportDialog.tsx @@ -111,7 +111,7 @@ export default function ProductImportDialog({ open, onOpenChange }: ProductImpor
    -
  • 必填欄位:商品代號 (1-5 碼)、條碼、商品名稱、類別名稱、基本單位。
  • +
  • 必填欄位:商品代號 (2-8 碼)、條碼、商品名稱、類別名稱、基本單位。
  • 唯一性:商品代號與條碼不可與現有資料重複。
  • 自動關聯:類別與單位請填寫系統當前存在的「名稱」(如:飲品、瓶)。
  • 大單位:若填寫大單位,則「換算率」為必填(需大於 0)。