This commit is contained in:
wangli 2026-02-04 00:32:18 +08:00
parent 29d76f2224
commit 8bac24a9ef
5 changed files with 43 additions and 48 deletions

View File

@ -17,7 +17,7 @@ export const getAccounts = async (): Promise<Account[]> => {
pause_duration?: number
show_browser?: boolean
}
const data = await get<BackendAccount[]>('/cookies')
const data = await get<BackendAccount[]>('/goofish/accounts')
// 后端返回的是完整账号对象数组转换为前端Account格式
return data.map(item => ({
id: item.id,
@ -43,7 +43,7 @@ export const getAccountDetails = async (): Promise<AccountDetail[]> => {
login_password?: string
show_browser?: boolean
}
const data = await get<BackendAccountDetail[]>('/goofish/details')
const data = await get<BackendAccountDetail[]>('/goofish/accounts')
// 后端返回 value 字段,前端使用 cookie 字段
return data.map((item) => ({
id: item.id,
@ -64,7 +64,7 @@ export const getAccountDetails = async (): Promise<AccountDetail[]> => {
// 添加账号
export const addAccount = (data: { id: string; cookie: string }): Promise<ApiResponse> => {
// 后端需要 id 和 value 字段
return post('/goofish/cookies', { id: data.id, value: data.cookie })
return post('/goofish/login-by-cookie', { id: data.id, value: data.cookie })
}
// 更新账号 Cookie 值
@ -74,12 +74,12 @@ export const updateAccountCookie = (id: string, value: string): Promise<ApiRespo
// 更新账号启用/禁用状态
export const updateAccountStatus = (id: string, enabled: boolean): Promise<ApiResponse> => {
return put(`/goofish/cookies/${id}/status`, { enabled })
return put(`/goofish/account/${id}/status`, { enabled })
}
// 更新账号备注
export const updateAccountRemark = (id: string, remark: string): Promise<ApiResponse> => {
return put(`/goofish/cookies/${id}/remark`, { remark })
return put(`/goofish/account/${id}/remark`, { remark })
}
// 更新账号自动确认设置
@ -103,7 +103,7 @@ export const updateAccountLoginInfo = (id: string, data: {
// 删除账号
export const deleteAccount = (id: string): Promise<ApiResponse> => {
return del(`/goofish/cookies/${id}`)
return del(`/goofish/account/${id}`)
}
// 获取账号二维码登录

View File

@ -2,8 +2,8 @@ import { get, post, put, del } from '@/utils/request'
import type { Item, ItemReply, ApiResponse } from '@/types'
// 获取商品列表
export const getItems = async (cookieId?: string): Promise<{ success: boolean; data: Item[] }> => {
const url = cookieId ? `/items/cookie/${cookieId}` : '/items'
export const getItems = async (goofishId?: string): Promise<{ success: boolean; data: Item[] }> => {
const url = goofishId ? `/products/account/${goofishId}` : '/products'
const result = await get<{ items?: Item[] } | Item[]>(url)
// 后端返回 { items: [...] } 或直接返回数组
const items = Array.isArray(result) ? result : (result.items || [])

View File

@ -94,7 +94,7 @@ export function Items() {
const handleDelete = async (item: Item) => {
if (!confirm('确定要删除这个商品吗?')) return
try {
await deleteItem(item.cookie_id, item.item_id)
await deleteItem(item.goofish_id, item.goofish_product_id)
addToast({ type: 'success', message: '删除成功' })
loadItems()
} catch {
@ -133,7 +133,7 @@ export function Items() {
// 将选中的 ID 转换为 { cookie_id, item_id } 格式
const itemsToDelete = items
.filter((item) => selectedIds.has(item.id))
.map((item) => ({ cookie_id: item.cookie_id, item_id: item.item_id }))
.map((item) => ({ cookie_id: item.goofish_id, item_id: item.goofish_product_id }))
await batchDeleteItems(itemsToDelete)
addToast({ type: 'success', message: `成功删除 ${selectedIds.size} 个商品` })
setSelectedIds(new Set())
@ -147,7 +147,7 @@ export function Items() {
const handleToggleMultiQuantity = async (item: Item) => {
try {
const newStatus = !item.multi_quantity_delivery
await updateItemMultiQuantityDelivery(item.cookie_id, item.item_id, newStatus)
await updateItemMultiQuantityDelivery(item.goofish_id, item.goofish_product_id, newStatus)
addToast({ type: 'success', message: `多数量发货已${newStatus ? '开启' : '关闭'}` })
loadItems()
} catch {
@ -158,8 +158,8 @@ export function Items() {
// 切换多规格状态
const handleToggleMultiSpec = async (item: Item) => {
try {
const newStatus = !(item.is_multi_spec || item.has_sku)
await updateItemMultiSpec(item.cookie_id, item.item_id, newStatus)
const newStatus = !(item.is_multi_spec)
await updateItemMultiSpec(item.goofish_id, item.goofish_product_id, newStatus)
addToast({ type: 'success', message: `多规格已${newStatus ? '开启' : '关闭'}` })
loadItems()
} catch {
@ -170,7 +170,7 @@ export function Items() {
// 打开编辑弹窗
const handleEdit = (item: Item) => {
setEditingItem(item)
setEditDetail(item.item_detail || item.desc || '')
setEditDetail(item.product_detail || '')
}
// 保存编辑
@ -178,8 +178,8 @@ export function Items() {
if (!editingItem) return
setEditSaving(true)
try {
await updateItem(editingItem.cookie_id, editingItem.item_id, {
item_detail: editDetail,
await updateItem(editingItem.goofish_id, editingItem.goofish_product_id, {
product_detail: editDetail,
})
addToast({ type: 'success', message: '商品详情已更新' })
setEditingItem(null)
@ -194,12 +194,12 @@ export function Items() {
const filteredItems = items.filter((item) => {
if (!searchKeyword) return true
const keyword = searchKeyword.toLowerCase()
const title = item.item_title || item.title || ''
const desc = item.item_detail || item.desc || ''
const title = item.product_title || ''
const desc = item.product_detail || ''
return (
title.toLowerCase().includes(keyword) ||
desc.toLowerCase().includes(keyword) ||
item.item_id?.includes(keyword)
item.goofish_product_id?.includes(keyword)
)
})
@ -343,48 +343,48 @@ export function Items() {
)}
</button>
</td>
<td className="font-medium text-blue-600 dark:text-blue-400">{item.cookie_id}</td>
<td className="font-medium text-blue-600 dark:text-blue-400">{item.goofish_id}</td>
<td className="text-xs text-gray-500">
<a
href={`https://www.goofish.com/item?id=${item.item_id}`}
href={`https://www.goofish.com/item?id=${item.goofish_product_id}`}
target="_blank"
rel="noopener noreferrer"
className="hover:text-blue-500 flex items-center gap-1"
>
{item.item_id}
{item.goofish_product_id}
<ExternalLink className="w-3 h-3" />
</a>
</td>
<td className="max-w-[280px]">
<div
className="font-medium line-clamp-2 cursor-help"
title={item.item_title || item.title || '-'}
title={item.product_title || '-'}
>
{item.item_title || item.title || '-'}
{item.product_title || '-'}
</div>
{(item.item_detail || item.desc) && (
{(item.product_detail || item.product_description) && (
<div
className="text-xs text-gray-400 line-clamp-1 mt-0.5 cursor-help"
title={item.item_detail || item.desc}
title={item.product_detail || item.product_description}
>
{item.item_detail || item.desc}
{item.product_detail || item.product_description}
</div>
)}
</td>
<td className="text-amber-600 font-medium">
{item.item_price || (item.price ? `¥${item.price}` : '-')}
{item.product_price || (item.product_price ? `¥${item.product_price}` : '-')}
</td>
<td>
<button
onClick={() => handleToggleMultiSpec(item)}
className={`px-2 py-1 rounded text-xs font-medium transition-colors ${
(item.is_multi_spec || item.has_sku)
(item.is_multi_spec)
? 'bg-green-100 text-green-700 hover:bg-green-200 dark:bg-green-900/30 dark:text-green-400'
: 'bg-gray-100 text-gray-500 hover:bg-gray-200 dark:bg-gray-800 dark:text-gray-400'
}`}
title={(item.is_multi_spec || item.has_sku) ? '点击关闭多规格' : '点击开启多规格'}
title={(item.is_multi_spec ) ? '点击关闭多规格' : '点击开启多规格'}
>
{(item.is_multi_spec || item.has_sku) ? '已开启' : '已关闭'}
{(item.is_multi_spec ) ? '已开启' : '已关闭'}
</button>
</td>
<td>
@ -444,7 +444,7 @@ export function Items() {
<label className="input-label">ID</label>
<input
type="text"
value={editingItem.item_id}
value={editingItem.goofish_product_id}
disabled
className="input-ios bg-slate-100 dark:bg-slate-700"
/>
@ -453,7 +453,7 @@ export function Items() {
<label className="input-label"></label>
<input
type="text"
value={editingItem.item_title || editingItem.title || ''}
value={editingItem.product_title || ''}
disabled
className="input-ios bg-slate-100 dark:bg-slate-700"
/>

View File

@ -62,20 +62,15 @@ export interface Keyword {
// 商品相关类型
export interface Item {
id: string | number
cookie_id: string
item_id: string
title?: string
item_title?: string
desc?: string
item_description?: string
item_detail?: string
item_category?: string
price?: string
item_price?: string
has_sku?: boolean
is_multi_spec?: number | boolean
multi_delivery?: boolean
multi_quantity_delivery?: number | boolean
goofish_id: string
goofish_product_id: string
product_title: string
product_description: string
product_category: string
product_price: string
product_detail: string
is_multi_spec: boolean
multi_quantity_delivery: boolean
created_at?: string
updated_at?: string
}

View File

@ -184,7 +184,7 @@ export default defineConfig(({ command }) => ({
changeOrigin: true,
},
// 商品管理 - 前端有 /items 路由,需要区分浏览器访问和 API 请求
'/items': {
'/products': {
target: 'http://localhost:8080',
changeOrigin: true,
bypass: (req) => {