|
@@ -6,16 +6,54 @@ import TDesignSearch from '@/components/tdesign/search'
|
|
|
import GoodsList from '@/components/goods-list'
|
|
import GoodsList from '@/components/goods-list'
|
|
|
import { GoodsData } from '@/components/goods-card'
|
|
import { GoodsData } from '@/components/goods-card'
|
|
|
import { goodsClient, advertisementClient } from '@/api'
|
|
import { goodsClient, advertisementClient } from '@/api'
|
|
|
-import { InferResponseType } from 'hono'
|
|
|
|
|
import './index.css'
|
|
import './index.css'
|
|
|
import { useAuth } from '@/utils/auth'
|
|
import { useAuth } from '@/utils/auth'
|
|
|
import { useCart } from '@/contexts/CartContext'
|
|
import { useCart } from '@/contexts/CartContext'
|
|
|
import { Navbar } from '@/components/ui/navbar'
|
|
import { Navbar } from '@/components/ui/navbar'
|
|
|
import { Carousel } from '@/components/ui/carousel'
|
|
import { Carousel } from '@/components/ui/carousel'
|
|
|
-import Taro, { usePullDownRefresh, useShareAppMessage } from '@tarojs/taro'
|
|
|
|
|
|
|
+import Taro, { useShareAppMessage } from '@tarojs/taro'
|
|
|
|
|
|
|
|
-type GoodsResponse = InferResponseType<typeof goodsClient.$get, 200>
|
|
|
|
|
-type Goods = GoodsResponse['data'][0]
|
|
|
|
|
|
|
+// 商品类型定义(根据 PublicGoodsSchema)
|
|
|
|
|
+interface Goods {
|
|
|
|
|
+ id: number
|
|
|
|
|
+ name: string
|
|
|
|
|
+ price: number
|
|
|
|
|
+ costPrice?: number
|
|
|
|
|
+ salesNum: number
|
|
|
|
|
+ clickNum?: number
|
|
|
|
|
+ categoryId1: number
|
|
|
|
|
+ categoryId2: number
|
|
|
|
|
+ categoryId3: number
|
|
|
|
|
+ goodsType: number
|
|
|
|
|
+ supplierId?: number
|
|
|
|
|
+ merchantId?: number
|
|
|
|
|
+ imageFileId?: number
|
|
|
|
|
+ detail?: string
|
|
|
|
|
+ instructions?: string
|
|
|
|
|
+ sort: number
|
|
|
|
|
+ state: number
|
|
|
|
|
+ stock: number
|
|
|
|
|
+ spuId: number
|
|
|
|
|
+ lowestBuy: number
|
|
|
|
|
+ category1?: any
|
|
|
|
|
+ category2?: any
|
|
|
|
|
+ category3?: any
|
|
|
|
|
+ supplier?: any
|
|
|
|
|
+ merchant?: any
|
|
|
|
|
+ imageFile?: {
|
|
|
|
|
+ id: number
|
|
|
|
|
+ fullUrl: string
|
|
|
|
|
+ name?: string
|
|
|
|
|
+ type?: string
|
|
|
|
|
+ }
|
|
|
|
|
+ slideImages?: Array<{
|
|
|
|
|
+ id: number
|
|
|
|
|
+ fullUrl: string
|
|
|
|
|
+ }>
|
|
|
|
|
+ childGoodsIds?: number[]
|
|
|
|
|
+ createdAt?: Date
|
|
|
|
|
+ updatedAt?: Date
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
const HomePage: React.FC = () => {
|
|
const HomePage: React.FC = () => {
|
|
|
const { isLoggedIn } = useAuth();
|
|
const { isLoggedIn } = useAuth();
|
|
@@ -30,11 +68,13 @@ const HomePage: React.FC = () => {
|
|
|
} = useQuery({
|
|
} = useQuery({
|
|
|
queryKey: ['home-advertisements'],
|
|
queryKey: ['home-advertisements'],
|
|
|
queryFn: async () => {
|
|
queryFn: async () => {
|
|
|
- const response = await advertisementClient.$get({
|
|
|
|
|
|
|
+ // 使用类型断言绕过 RPC 客户端类型推断问题
|
|
|
|
|
+ const response = await (advertisementClient.$get as any)({
|
|
|
query: {
|
|
query: {
|
|
|
- filters: JSON.stringify({ status: 1, typeId: 1 }), // 过滤启用的首页轮播广告
|
|
|
|
|
- sortBy: 'sort', // 按sort字段排序
|
|
|
|
|
- sortOrder: 'ASC'
|
|
|
|
|
|
|
+ typeId: 1, // 首页轮播广告类型
|
|
|
|
|
+ code: 'testg01', // 广告代码筛选
|
|
|
|
|
+ page: 1,
|
|
|
|
|
+ pageSize: 100
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
if (response.status !== 200) {
|
|
if (response.status !== 200) {
|
|
@@ -57,11 +97,12 @@ const HomePage: React.FC = () => {
|
|
|
queryKey: ['home-goods-infinite'],
|
|
queryKey: ['home-goods-infinite'],
|
|
|
queryFn: async ({ pageParam = 1 }) => {
|
|
queryFn: async ({ pageParam = 1 }) => {
|
|
|
// console.debug('请求商品数据,页码:', pageParam)
|
|
// console.debug('请求商品数据,页码:', pageParam)
|
|
|
- const response = await goodsClient.$get({
|
|
|
|
|
|
|
+ // 使用类型断言绕过 RPC 客户端类型推断问题
|
|
|
|
|
+ const response = await (goodsClient.$get as any)({
|
|
|
query: {
|
|
query: {
|
|
|
page: pageParam,
|
|
page: pageParam,
|
|
|
- pageSize: 10,
|
|
|
|
|
- filters: JSON.stringify({ state: 1 }), // 只显示可用的商品
|
|
|
|
|
|
|
+ limit: 10,
|
|
|
|
|
+ state: 1, // 只显示可用的商品
|
|
|
sortBy: 'sort', // 按sort字段排序
|
|
sortBy: 'sort', // 按sort字段排序
|
|
|
sortOrder: 'DESC' // 倒序排列
|
|
sortOrder: 'DESC' // 倒序排列
|
|
|
}
|
|
}
|
|
@@ -100,7 +141,7 @@ const HomePage: React.FC = () => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
// 合并所有分页数据
|
|
// 合并所有分页数据
|
|
|
- const allGoods = data?.pages.flatMap(page => page.data) || []
|
|
|
|
|
|
|
+ const allGoods: Goods[] = data?.pages.flatMap(page => page.data) || []
|
|
|
|
|
|
|
|
// 数据转换:将API返回的商品数据转换为GoodsData接口格式
|
|
// 数据转换:将API返回的商品数据转换为GoodsData接口格式
|
|
|
const convertToGoodsData = (goods: Goods): GoodsData => {
|
|
const convertToGoodsData = (goods: Goods): GoodsData => {
|