From 1d5bc6844406051bf867beacc9066b019657ad7f Mon Sep 17 00:00:00 2001 From: sky121113 Date: Thu, 5 Feb 2026 16:01:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(product):=20=E5=84=AA=E5=8C=96=E7=B7=A8?= =?UTF-8?q?=E8=BC=AF=E5=BE=8C=E7=9A=84=E8=B7=B3=E8=BD=89=E9=82=8F=E8=BC=AF?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8F=B4=E4=BE=9D=E4=BE=86=E6=BA=90=E5=9B=9E?= =?UTF-8?q?=E5=82=B3=E8=A9=B3=E6=83=85=E9=A0=81=E6=88=96=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Modules/Inventory/Controllers/ProductController.php | 4 ++++ resources/js/Components/Product/ProductForm.tsx | 4 +++- resources/js/Pages/Product/Edit.tsx | 9 +++++++-- resources/js/Pages/Product/Show.tsx | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/Modules/Inventory/Controllers/ProductController.php b/app/Modules/Inventory/Controllers/ProductController.php index cbd349b..ec0a41c 100644 --- a/app/Modules/Inventory/Controllers/ProductController.php +++ b/app/Modules/Inventory/Controllers/ProductController.php @@ -260,6 +260,10 @@ class ProductController extends Controller $product->update($validated); + if ($request->input('from') === 'show') { + return redirect()->route('products.show', $product->id)->with('success', '商品已更新'); + } + return redirect()->route('products.index')->with('success', '商品已更新'); } diff --git a/resources/js/Components/Product/ProductForm.tsx b/resources/js/Components/Product/ProductForm.tsx index 1a7779c..a30cef4 100644 --- a/resources/js/Components/Product/ProductForm.tsx +++ b/resources/js/Components/Product/ProductForm.tsx @@ -22,6 +22,8 @@ export default function ProductForm({ units, }: ProductFormProps) { const isEdit = !!initialData; + const urlParams = new URLSearchParams(window.location.search); + const from = urlParams.get('from'); const { data, setData, post, put, processing, errors } = useForm({ code: initialData?.code || "", @@ -45,7 +47,7 @@ export default function ProductForm({ e.preventDefault(); if (isEdit) { - put(route("products.update", initialData.id), { + put(route("products.update", { product: initialData.id, from }), { onSuccess: () => toast.success("商品已更新"), onError: () => toast.error("更新失敗,請檢查輸入資料"), }); diff --git a/resources/js/Pages/Product/Edit.tsx b/resources/js/Pages/Product/Edit.tsx index cdc3eed..ca64520 100644 --- a/resources/js/Pages/Product/Edit.tsx +++ b/resources/js/Pages/Product/Edit.tsx @@ -14,6 +14,11 @@ interface Props { } export default function Edit({ product, categories, units }: Props) { + const urlParams = new URLSearchParams(window.location.search); + const from = urlParams.get('from'); + const backUrl = from === 'show' ? route('products.show', product.id) : route('products.index'); + const backText = from === 'show' ? "返回商品詳情" : "返回商品列表"; + return ( {/* Header */}
- + diff --git a/resources/js/Pages/Product/Show.tsx b/resources/js/Pages/Product/Show.tsx index 6f6272c..f7cd1bf 100644 --- a/resources/js/Pages/Product/Show.tsx +++ b/resources/js/Pages/Product/Show.tsx @@ -67,7 +67,7 @@ export default function ProductShow({ product }: Props) {
- +