diff --git a/frontend/src/pages/items/Items.tsx b/frontend/src/pages/items/Items.tsx index ee59ec8..dcbcf41 100644 --- a/frontend/src/pages/items/Items.tsx +++ b/frontend/src/pages/items/Items.tsx @@ -1,12 +1,12 @@ -import { useState, useEffect } from 'react' -import { Package, RefreshCw, Search, Trash2, Download, CheckSquare, Square, Loader2, ExternalLink } from 'lucide-react' -import { getItems, deleteItem, fetchItemsFromAccount, batchDeleteItems, updateItemMultiQuantityDelivery, updateItemMultiSpec } from '@/api/items' +import { useEffect, useState } from 'react' +import { CheckSquare, Download, Edit2, ExternalLink, Loader2, Package, RefreshCw, Search, Square, Trash2, X } from 'lucide-react' +import { batchDeleteItems, deleteItem, fetchItemsFromAccount, getItems, updateItem, updateItemMultiQuantityDelivery, updateItemMultiSpec } from '@/api/items' import { getAccounts } from '@/api/accounts' import { useUIStore } from '@/store/uiStore' import { PageLoading } from '@/components/common/Loading' import { useAuthStore } from '@/store/authStore' import { Select } from '@/components/common/Select' -import type { Item, Account } from '@/types' +import type { Account, Item } from '@/types' export function Items() { const { addToast } = useUIStore() @@ -20,6 +20,11 @@ export function Items() { const [fetching, setFetching] = useState(false) const [fetchProgress, setFetchProgress] = useState({ current: 0, total: 0 }) + // 编辑弹窗状态 + const [editingItem, setEditingItem] = useState(null) + const [editDetail, setEditDetail] = useState('') + const [editSaving, setEditSaving] = useState(false) + const loadItems = async () => { if (!_hasHydrated || !isAuthenticated || !token) { return @@ -54,7 +59,7 @@ export function Items() { while (hasMore) { setFetchProgress({ current: page, total: page }) const result = await fetchItemsFromAccount(selectedAccount, page) - + if (result.success) { const fetchedCount = (result as { count?: number }).count || 0 totalFetched += fetchedCount @@ -177,6 +182,30 @@ export function Items() { } } + // 打开编辑弹窗 + const handleEdit = (item: Item) => { + setEditingItem(item) + setEditDetail(item.item_detail || item.desc || '') + } + + // 保存编辑 + const handleSaveEdit = async () => { + if (!editingItem) return + setEditSaving(true) + try { + await updateItem(editingItem.cookie_id, editingItem.item_id, { + item_detail: editDetail, + }) + addToast({ type: 'success', message: '商品详情已更新' }) + setEditingItem(null) + loadItems() + } catch { + addToast({ type: 'error', message: '更新失败' }) + } finally { + setEditSaving(false) + } + } + const filteredItems = items.filter((item) => { if (!searchKeyword) return true const keyword = searchKeyword.toLowerCase() @@ -208,8 +237,8 @@ export function Items() { 删除选中 ({selectedIds.size}) )} - + +
+
+ + +
+
+ + +
+
+ +