From 8bac24a9ef09f56034e5fc7a68154abb6700c3cd Mon Sep 17 00:00:00 2001 From: wangli Date: Wed, 4 Feb 2026 00:32:18 +0800 Subject: [PATCH] init --- src/api/accounts.ts | 12 +++++----- src/api/items.ts | 4 ++-- src/pages/items/Items.tsx | 50 +++++++++++++++++++-------------------- src/types/index.ts | 23 +++++++----------- vite.config.ts | 2 +- 5 files changed, 43 insertions(+), 48 deletions(-) diff --git a/src/api/accounts.ts b/src/api/accounts.ts index 489fa6c..0a364eb 100644 --- a/src/api/accounts.ts +++ b/src/api/accounts.ts @@ -17,7 +17,7 @@ export const getAccounts = async (): Promise => { pause_duration?: number show_browser?: boolean } - const data = await get('/cookies') + const data = await get('/goofish/accounts') // 后端返回的是完整账号对象数组,转换为前端Account格式 return data.map(item => ({ id: item.id, @@ -43,7 +43,7 @@ export const getAccountDetails = async (): Promise => { login_password?: string show_browser?: boolean } - const data = await get('/goofish/details') + const data = await get('/goofish/accounts') // 后端返回 value 字段,前端使用 cookie 字段 return data.map((item) => ({ id: item.id, @@ -64,7 +64,7 @@ export const getAccountDetails = async (): Promise => { // 添加账号 export const addAccount = (data: { id: string; cookie: string }): Promise => { // 后端需要 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 => { - return put(`/goofish/cookies/${id}/status`, { enabled }) + return put(`/goofish/account/${id}/status`, { enabled }) } // 更新账号备注 export const updateAccountRemark = (id: string, remark: string): Promise => { - 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 => { - return del(`/goofish/cookies/${id}`) + return del(`/goofish/account/${id}`) } // 获取账号二维码登录 diff --git a/src/api/items.ts b/src/api/items.ts index f9aff98..9b265d3 100644 --- a/src/api/items.ts +++ b/src/api/items.ts @@ -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 || []) diff --git a/src/pages/items/Items.tsx b/src/pages/items/Items.tsx index 80c980e..9af274c 100644 --- a/src/pages/items/Items.tsx +++ b/src/pages/items/Items.tsx @@ -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() { )} - {item.cookie_id} + {item.goofish_id} - {item.item_id} + {item.goofish_product_id}
- {item.item_title || item.title || '-'} + {item.product_title || '-'}
- {(item.item_detail || item.desc) && ( + {(item.product_detail || item.product_description) && (
- {item.item_detail || item.desc} + {item.product_detail || item.product_description}
)} - {item.item_price || (item.price ? `¥${item.price}` : '-')} + {item.product_price || (item.product_price ? `¥${item.product_price}` : '-')} @@ -444,7 +444,7 @@ export function Items() { @@ -453,7 +453,7 @@ export function Items() { diff --git a/src/types/index.ts b/src/types/index.ts index db9f500..b1d48fc 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -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 } diff --git a/vite.config.ts b/vite.config.ts index 0cc7716..e6b8827 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -184,7 +184,7 @@ export default defineConfig(({ command }) => ({ changeOrigin: true, }, // 商品管理 - 前端有 /items 路由,需要区分浏览器访问和 API 请求 - '/items': { + '/products': { target: 'http://localhost:8080', changeOrigin: true, bypass: (req) => {