Backup project on 2026-03-27
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import { useNavigate, useLocation } from 'react-router-dom'
|
||||
import {
|
||||
Table, Button, Modal, Form, Input, Select, message, Space, Tag, Card,
|
||||
Row, Col, Statistic, TreeSelect, Image, Popconfirm, Tabs, Empty, Spin, InputNumber,
|
||||
@@ -43,6 +44,12 @@ interface Product {
|
||||
|
||||
// ==================== 组件 ====================
|
||||
const ProductPage: React.FC = () => {
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
|
||||
// 从 location state 中获取返回路径
|
||||
const returnTo = (location.state as { returnTo?: string })?.returnTo
|
||||
|
||||
// 商品列表状态
|
||||
const [products, setProducts] = useState<Product[]>([])
|
||||
const [loading, setLoading] = useState(false)
|
||||
@@ -227,6 +234,13 @@ const ProductPage: React.FC = () => {
|
||||
setProductModalVisible(true)
|
||||
}
|
||||
|
||||
// 如果是从采购申请页面跳转过来的,自动打开新增商品弹窗
|
||||
useEffect(() => {
|
||||
if (returnTo && (location.state as { openAddModal?: boolean })?.openAddModal) {
|
||||
handleAddProduct()
|
||||
}
|
||||
}, [returnTo, location.state])
|
||||
|
||||
// 打开编辑商品弹窗
|
||||
const handleEditProduct = (product: Product) => {
|
||||
setEditingProduct(product)
|
||||
@@ -279,6 +293,19 @@ const ProductPage: React.FC = () => {
|
||||
setProductModalVisible(false)
|
||||
fetchProducts()
|
||||
fetchCategories() // 刷新分类
|
||||
|
||||
// 如果是从采购申请页面跳转过来的,创建成功后返回
|
||||
if (returnTo && !editingProduct) {
|
||||
// 延迟导航,确保状态更新
|
||||
setTimeout(() => {
|
||||
navigate(returnTo, {
|
||||
state: {
|
||||
productCreated: true,
|
||||
fromPurchaseRequest: true
|
||||
}
|
||||
})
|
||||
}, 100)
|
||||
}
|
||||
} else {
|
||||
message.error(data.error || '操作失败')
|
||||
}
|
||||
@@ -861,7 +888,20 @@ const ProductPage: React.FC = () => {
|
||||
title={editingProduct ? '编辑商品' : '新增商品'}
|
||||
open={productModalVisible}
|
||||
onOk={handleSaveProduct}
|
||||
onCancel={() => setProductModalVisible(false)}
|
||||
onCancel={() => {
|
||||
setProductModalVisible(false)
|
||||
// 如果是从采购申请页面跳转过来的,取消后返回
|
||||
if (returnTo) {
|
||||
// 延迟导航,确保状态更新
|
||||
setTimeout(() => {
|
||||
navigate(returnTo, {
|
||||
state: {
|
||||
fromPurchaseRequest: true
|
||||
}
|
||||
})
|
||||
}, 100)
|
||||
}
|
||||
}}
|
||||
width={600}
|
||||
okText="保存"
|
||||
cancelText="取消"
|
||||
|
||||
Reference in New Issue
Block a user