增加和平小店商品分类展示

This commit is contained in:
yml2213
2026-08-08 18:29:31 +08:00
parent 06ad1498da
commit 51e91b0483
7 changed files with 168 additions and 52 deletions
+19 -4
View File
@@ -1,10 +1,12 @@
import { ref, computed } from 'vue'
import { useToast } from './useToast'
import { useActivity } from './useActivity'
import { LoadProducts } from '@wails/go/app/App'
export interface Product {
commodityId: string
commodityName: string
category: string
score: number
count: number
pic: string
@@ -32,18 +34,25 @@ const selectedProductId = ref<string | null>(null)
const selectedProductName = ref('')
const searchQuery = ref('')
const loading = ref(false)
export type XiaodianTab = 'all' | 'discount' | 'hot'
const xiaodianTab = ref<XiaodianTab>('all')
export function useProducts() {
const { showToast } = useToast()
const { currentActivity } = useActivity()
const filteredProducts = computed(() => {
const keyword = searchQuery.value.toLowerCase().trim()
if (!keyword) return products.value
return products.value.filter(p =>
[p.commodityName, p.commodityId, p.score, p.count].some(
return products.value.filter(p => {
const matchesTab = currentActivity.value?.id !== 'xiaodian' || xiaodianTab.value === 'all'
|| (xiaodianTab.value === 'discount' && p.category === '45')
|| (xiaodianTab.value === 'hot' && p.category === '76')
if (!matchesTab) return false
if (!keyword) return true
return [p.commodityName, p.commodityId, p.score, p.count].some(
v => String(v ?? '').toLowerCase().includes(keyword)
)
)
})
})
const selectedProduct = computed(() =>
@@ -97,6 +106,10 @@ export function useProducts() {
searchQuery.value = ''
}
const setXiaodianTab = (tab: XiaodianTab) => {
xiaodianTab.value = tab
}
const restoreSelection = () => {
const savedId = localStorage.getItem('selProd')
const savedName = localStorage.getItem('selProdName')
@@ -115,11 +128,13 @@ export function useProducts() {
searchQuery,
filteredProducts,
loading,
xiaodianTab,
loadProducts,
selectProduct,
clearSelection,
setSearch,
clearSearch,
setXiaodianTab,
restoreSelection
}
}