chore(config): 更新项目名称为 xinlong-taro
- 修改 config/index.ts 中的 projectName 字段 - 更新 package.json 的 name 字段 - 调整 project.config.json 中 description 和 projectname 为新名称 - 修改 README.md 中项目目录名称为 xinlong-taro
This commit is contained in:
@@ -50,7 +50,7 @@ const CategoryPage: React.FC = () => {
|
||||
const list = await listShopGoodsCategory()
|
||||
if (list) {
|
||||
// 只保留 status=1 的分类(不限是否有子分类,因为右侧直接展示商品)
|
||||
const filtered = list.filter(cat => cat.status === 1)
|
||||
const filtered = list.filter(cat => cat.status === 0)
|
||||
setCategories(filtered)
|
||||
if (filtered.length > 0) setActiveId(filtered[0].categoryId)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useState, useEffect, useCallback, useRef } from 'react'
|
||||
import { View, Text, ScrollView, Image } from '@tarojs/components'
|
||||
import { View, Text, ScrollView, Image, Input } from '@tarojs/components'
|
||||
import Taro from '@tarojs/taro'
|
||||
import { listShopGoodsCategory } from '@/api/shop/shopGoodsCategory'
|
||||
import { pageShopGoods } from '@/api/shop/shopGoods'
|
||||
@@ -47,6 +47,10 @@ const ShopPage: React.FC = () => {
|
||||
const [sortKey, setSortKey] = useState<SortKey>('default')
|
||||
const [priceAsc, setPriceAsc] = useState(true)
|
||||
|
||||
// 搜索
|
||||
const [keyword, setKeyword] = useState('')
|
||||
const searchTimerRef = useRef<any>(null)
|
||||
|
||||
useEffect(() => {
|
||||
loadCategories()
|
||||
}, [])
|
||||
@@ -55,7 +59,7 @@ const ShopPage: React.FC = () => {
|
||||
try {
|
||||
const list = await listShopGoodsCategory()
|
||||
if (list && list.length > 0) {
|
||||
const filtered = list.filter((c: any) => c.status === 1)
|
||||
const filtered = list.filter((c: any) => c.status === 0)
|
||||
setCategoryList([...PRESET_CATEGORIES, ...filtered])
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
@@ -78,6 +82,7 @@ const ShopPage: React.FC = () => {
|
||||
const params: ShopGoodsParam = { page: p, limit: 10, status: 0, ...buildSortParams() }
|
||||
if (activeCategory > 0) params.categoryId = activeCategory
|
||||
if (activeCategory === -1) params.recommend = 1
|
||||
if (keyword.trim()) params.keywords = keyword.trim()
|
||||
const res = await pageShopGoods(params)
|
||||
const newList = res?.list || []
|
||||
if (p === 1) {
|
||||
@@ -90,7 +95,7 @@ const ShopPage: React.FC = () => {
|
||||
} catch { /* ignore */ }
|
||||
loadingRef.current = false
|
||||
setLoading(false)
|
||||
}, [activeCategory, buildSortParams])
|
||||
}, [activeCategory, buildSortParams, keyword])
|
||||
|
||||
// 分类或排序变化时重新加载
|
||||
useEffect(() => {
|
||||
@@ -140,13 +145,64 @@ const ShopPage: React.FC = () => {
|
||||
})
|
||||
}
|
||||
|
||||
/** 搜索输入(防抖 500ms) */
|
||||
const handleSearchInput = (e: any) => {
|
||||
const val = e.detail.value
|
||||
setKeyword(val)
|
||||
if (searchTimerRef.current) clearTimeout(searchTimerRef.current)
|
||||
searchTimerRef.current = setTimeout(() => {
|
||||
setGoodsList([])
|
||||
setFinished(false)
|
||||
setPage(1)
|
||||
loadGoods(1)
|
||||
}, 500)
|
||||
}
|
||||
|
||||
/** 跳转商品详情 */
|
||||
const goDetail = (product: ShopGoods) => {
|
||||
Taro.navigateTo({ url: `/pages/shop/product-detail?id=${product.goodsId}` })
|
||||
}
|
||||
|
||||
return (
|
||||
<View className='flex min-h-screen bg-gray-50'>
|
||||
<View className='flex flex-col h-screen bg-gray-50'>
|
||||
{/* 顶部搜索栏 */}
|
||||
<View className='bg-white px-3 py-2 flex-shrink-0 border-b border-gray-100'>
|
||||
<View className='flex items-center bg-gray-100 rounded-full px-3 py-1.5'>
|
||||
<Text className='text-gray-400 text-sm mr-1'>🔍</Text>
|
||||
<Input
|
||||
type='text'
|
||||
value={keyword}
|
||||
placeholder='搜索商品'
|
||||
placeholderClass='text-gray-400'
|
||||
confirmType='search'
|
||||
className='flex-1 text-sm text-gray-700'
|
||||
onInput={handleSearchInput}
|
||||
onConfirm={() => {
|
||||
setGoodsList([])
|
||||
setFinished(false)
|
||||
setPage(1)
|
||||
loadGoods(1)
|
||||
}}
|
||||
/>
|
||||
{keyword ? (
|
||||
<Text
|
||||
className='text-gray-400 text-sm pl-1'
|
||||
onClick={() => {
|
||||
setKeyword('')
|
||||
setGoodsList([])
|
||||
setFinished(false)
|
||||
setPage(1)
|
||||
loadGoods(1)
|
||||
}}
|
||||
>
|
||||
✕
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* 左右分栏 */}
|
||||
<View className='flex flex-1 min-h-0'>
|
||||
{/* 左侧分类栏 */}
|
||||
<ScrollView scrollY className='w-20 bg-gray-100 h-screen flex-shrink-0'>
|
||||
{categoryList.map(cat => (
|
||||
@@ -283,6 +339,7 @@ const ShopPage: React.FC = () => {
|
||||
</ScrollView>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user