优化和平小店商品列表界面

This commit is contained in:
yml2213
2026-08-08 18:01:10 +08:00
parent 395096e229
commit 06ad1498da
5 changed files with 125 additions and 30 deletions
@@ -1,4 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue'
import { useProducts } from '@/composables/useProducts' import { useProducts } from '@/composables/useProducts'
import { useActivity } from '@/composables/useActivity' import { useActivity } from '@/composables/useActivity'
import ProductSearch from '@/components/product/ProductSearch.vue' import ProductSearch from '@/components/product/ProductSearch.vue'
@@ -11,6 +12,7 @@ defineProps<{
const { loadProducts, productInfo, filteredProducts, loading } = useProducts() const { loadProducts, productInfo, filteredProducts, loading } = useProducts()
const { activities, currentActivity, switching, switchActivity } = useActivity() const { activities, currentActivity, switching, switchActivity } = useActivity()
const isXiaodian = computed(() => currentActivity.value?.id === 'xiaodian')
const onSwitchActivity = async (e: Event) => { const onSwitchActivity = async (e: Event) => {
const id = (e.target as HTMLSelectElement).value const id = (e.target as HTMLSelectElement).value
@@ -69,9 +71,9 @@ const onSwitchActivity = async (e: Event) => {
<div class="product-meta" :class="{ good: productInfo && !productInfo.stale, warn: productInfo?.stale }"> <div class="product-meta" :class="{ good: productInfo && !productInfo.stale, warn: productInfo?.stale }">
<template v-if="productInfo?.fetchedAt"> <template v-if="productInfo?.fetchedAt">
实时库存 {{ filteredProducts.length }} 个,刷新于 {{ productInfo.fetchedAt }} {{ isXiaodian ? '商品' : '实时库存' }} {{ filteredProducts.length }} 个,刷新于 {{ productInfo.fetchedAt }}
</template> </template>
<template v-else>库存未刷新</template> <template v-else>{{ isXiaodian ? '商品未刷新' : '库存未刷新' }}</template>
</div> </div>
</div> </div>
@@ -194,6 +196,9 @@ const onSwitchActivity = async (e: Event) => {
font-size: 11px; font-size: 11px;
color: var(--muted); color: var(--muted);
padding: 0 2px; padding: 0 2px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
} }
.product-meta.good { .product-meta.good {
@@ -5,7 +5,13 @@ import { useActivity } from '@/composables/useActivity'
const { selectedProductId, selectedProductName, selectedProduct } = useProducts() const { selectedProductId, selectedProductName, selectedProduct } = useProducts()
const { currentActivity } = useActivity() const { currentActivity } = useActivity()
const priceLabel = computed(() => currentActivity.value?.id === 'xiaodian' ? '点券' : '积分') const isXiaodian = computed(() => currentActivity.value?.id === 'xiaodian')
const priceLabel = computed(() => isXiaodian.value ? '点券' : '积分')
const stockText = computed(() => {
if (!selectedProduct.value) return ''
if (isXiaodian.value && selectedProduct.value.count < 0) return '库存未公开'
return `库存 ${selectedProduct.value.count}`
})
</script> </script>
<template> <template>
@@ -15,8 +21,8 @@ const priceLabel = computed(() => currentActivity.value?.id === 'xiaodian' ? '
<div class="selected-product-meta"> <div class="selected-product-meta">
<template v-if="selectedProduct"> <template v-if="selectedProduct">
<span class="chip chip-score">{{ selectedProduct.score }} {{ priceLabel }}</span> <span class="chip chip-score">{{ selectedProduct.score }} {{ priceLabel }}</span>
<span class="chip chip-stock" :class="{ low: selectedProduct.count < 500 }"> <span class="chip chip-stock" :class="{ low: selectedProduct.count >= 0 && selectedProduct.count < 500 }">
库存 {{ selectedProduct.count }} {{ stockText }}
</span> </span>
</template> </template>
<template v-else-if="selectedProductId"> <template v-else-if="selectedProductId">
@@ -56,7 +62,11 @@ const priceLabel = computed(() => currentActivity.value?.id === 'xiaodian' ? '
color: var(--text-strong); color: var(--text-strong);
font-weight: 600; font-weight: 600;
line-height: 1.4; line-height: 1.4;
word-break: break-all; overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
word-break: break-word;
} }
.selected-product-meta { .selected-product-meta {
+81 -22
View File
@@ -6,15 +6,18 @@ import { useActivity } from '@/composables/useActivity'
const { filteredProducts, selectedProductId, selectProduct, searchQuery } = useProducts() const { filteredProducts, selectedProductId, selectProduct, searchQuery } = useProducts()
const { currentActivity } = useActivity() const { currentActivity } = useActivity()
const priceLabel = computed(() => currentActivity.value?.id === 'xiaodian' ? '点券' : '积分') const isXiaodian = computed(() => currentActivity.value?.id === 'xiaodian')
const priceLabel = computed(() => isXiaodian.value ? '点券' : '积分')
const stockText = (count: number) => isXiaodian.value && count < 0 ? '库存未公开' : `库存 ${count}`
const parentRef = ref<HTMLElement | null>(null) const parentRef = ref<HTMLElement | null>(null)
const itemSize = 72
const virtualizer = useVirtualizer( const virtualizer = useVirtualizer(
computed(() => ({ computed(() => ({
count: filteredProducts.value.length, count: filteredProducts.value.length,
getScrollElement: () => parentRef.value, getScrollElement: () => parentRef.value,
estimateSize: () => 58, estimateSize: () => itemSize,
overscan: 5 overscan: 5
})) }))
) )
@@ -52,19 +55,31 @@ const handleSelect = (commodityId: string, commodityName: string) => {
}" }"
@click="handleSelect(filteredProducts[item.index].commodityId, filteredProducts[item.index].commodityName)" @click="handleSelect(filteredProducts[item.index].commodityId, filteredProducts[item.index].commodityName)"
> >
<img <div class="thumb">
:src="filteredProducts[item.index].pic" <span class="thumb-fallback" aria-hidden="true">礼</span>
@error="($event.target as HTMLImageElement).style.display = 'none'" <img
> :src="filteredProducts[item.index].pic"
loading="lazy"
alt=""
@error="($event.target as HTMLImageElement).style.display = 'none'"
>
</div>
<div class="pinfo"> <div class="pinfo">
<div class="pname">{{ filteredProducts[item.index].commodityName }}</div> <div
class="pname"
:title="filteredProducts[item.index].commodityName"
>{{ filteredProducts[item.index].commodityName }}</div>
<div class="pmeta"> <div class="pmeta">
<span class="chip chip-score">{{ filteredProducts[item.index].score }} {{ priceLabel }}</span> <span
class="chip chip-score"
:title="`${filteredProducts[item.index].score} ${priceLabel}`"
>{{ filteredProducts[item.index].score }} {{ priceLabel }}</span>
<span <span
class="chip chip-stock" class="chip chip-stock"
:class="{ low: filteredProducts[item.index].count < 500 }" :class="{ low: filteredProducts[item.index].count >= 0 && filteredProducts[item.index].count < 500 }"
:title="stockText(filteredProducts[item.index].count)"
> >
库存 {{ filteredProducts[item.index].count }} {{ stockText(filteredProducts[item.index].count) }}
</span> </span>
</div> </div>
</div> </div>
@@ -77,7 +92,7 @@ const handleSelect = (commodityId: string, commodityName: string) => {
.product-list { .product-list {
flex: 1; flex: 1;
overflow-y: auto; overflow-y: auto;
padding: 6px 8px 12px; padding: 8px 8px 14px;
min-height: 0; min-height: 0;
} }
@@ -87,14 +102,16 @@ const handleSelect = (commodityId: string, commodityName: string) => {
.prod-item { .prod-item {
display: grid; display: grid;
grid-template-columns: 40px minmax(0, 1fr); grid-template-columns: 42px minmax(0, 1fr);
gap: 10px; gap: 10px;
padding: 8px 10px; height: 72px;
margin: 2px 0; padding: 9px 10px;
margin: 3px 0;
border-radius: var(--radius-sm); border-radius: var(--radius-sm);
cursor: pointer; cursor: pointer;
border: 1px solid transparent; border: 1px solid transparent;
transition: .12s; transition: .12s;
overflow: hidden;
} }
.prod-item:hover { .prod-item:hover {
@@ -106,31 +123,57 @@ const handleSelect = (commodityId: string, commodityName: string) => {
border-color: var(--accent-border); border-color: var(--accent-border);
} }
.prod-item img { .thumb {
width: 40px; position: relative;
height: 40px; width: 42px;
height: 42px;
align-self: center;
overflow: hidden;
border-radius: var(--radius-sm); border-radius: var(--radius-sm);
object-fit: cover;
background: var(--field); background: var(--field);
border: 1px solid var(--line); border: 1px solid var(--line);
} }
.thumb-fallback {
position: absolute;
inset: 0;
display: grid;
place-items: center;
color: var(--muted-2);
font-size: 16px;
font-weight: 600;
}
.thumb img {
position: relative;
z-index: 1;
display: block;
width: 100%;
height: 100%;
border-radius: var(--radius-sm);
object-fit: cover;
}
.pinfo { .pinfo {
min-width: 0; min-width: 0;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
gap: 4px; gap: 5px;
overflow: hidden;
} }
.pname { .pname {
font-size: 12.5px; font-size: 12.5px;
font-weight: 500; font-weight: 500;
color: var(--text-strong); color: var(--text-strong);
white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
line-height: 1.3; line-height: 1.35;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
word-break: break-word;
} }
.pmeta { .pmeta {
@@ -138,6 +181,22 @@ const handleSelect = (commodityId: string, commodityName: string) => {
color: var(--muted); color: var(--muted);
display: flex; display: flex;
gap: 6px; gap: 6px;
flex-wrap: wrap; min-width: 0;
flex-wrap: nowrap;
overflow: hidden;
}
.pmeta .chip {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
}
.pmeta .chip-score {
flex: 0 1 auto;
}
.pmeta .chip-stock {
flex: 0 1 auto;
} }
</style> </style>
@@ -1,9 +1,14 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch } from 'vue' import { computed, ref, watch } from 'vue'
import { useProducts } from '@/composables/useProducts' import { useProducts } from '@/composables/useProducts'
import { useActivity } from '@/composables/useActivity'
const { searchQuery, setSearch, clearSearch } = useProducts() const { searchQuery, setSearch, clearSearch } = useProducts()
const { currentActivity } = useActivity()
const inputValue = ref(searchQuery.value) const inputValue = ref(searchQuery.value)
const searchPlaceholder = computed(() => currentActivity.value?.id === 'xiaodian'
? '搜索商品名 / ID / 点券 / 库存'
: '搜索商品名 / ID / 积分 / 库存')
// 防抖处理 // 防抖处理
let debounceTimer: number | null = null let debounceTimer: number | null = null
@@ -28,7 +33,7 @@ const handleClear = () => {
<input <input
v-model="inputValue" v-model="inputValue"
type="search" type="search"
placeholder="搜索商品名 / ID / 积分 / 库存" :placeholder="searchPlaceholder"
autocomplete="off" autocomplete="off"
> >
<button <button
+16
View File
@@ -148,6 +148,15 @@ func TestProductsAutomaticallyResolvesXiaodianRoleAndPaginates(t *testing.T) {
t.Errorf("_act_id = %q", got) t.Errorf("_act_id = %q", got)
} }
_, _ = w.Write([]byte(`var info = {"gameOpenId":"openid","roleId":1192083858,"type":"qq","area":1};`)) _, _ = w.Write([]byte(`var info = {"gameOpenId":"openid","roleId":1192083858,"type":"qq","area":1};`))
case "/role/":
switch r.URL.Query().Get("_jsvar") {
case "banlanceInfo":
_, _ = w.Write([]byte(`var banlanceInfo={"balance":8800};`))
case "jbInfos":
_, _ = w.Write([]byte(`var jbInfos={"jb2":"36"};`))
default:
http.Error(w, "unknown asset query", http.StatusBadRequest)
}
case "/goods": case "/goods":
offset := r.URL.Query().Get("page_begin") offset := r.URL.Query().Get("page_begin")
goodsOffsets = append(goodsOffsets, offset) goodsOffsets = append(goodsOffsets, offset)
@@ -204,6 +213,13 @@ func TestProductsAutomaticallyResolvesXiaodianRoleAndPaginates(t *testing.T) {
if got := strings.Join(goodsOffsets, ","); got != strings.Join([]string{"0", strconv.Itoa(2), strconv.Itoa(4)}, ",") { if got := strings.Join(goodsOffsets, ","); got != strings.Join([]string{"0", strconv.Itoa(2), strconv.Itoa(4)}, ",") {
t.Fatalf("分页偏移 = %s", got) t.Fatalf("分页偏移 = %s", got)
} }
assets, err := cli.XiaodianAssets("acf_uid=uid; acf_stk=stk; acf_ltkid=ltkid")
if err != nil {
t.Fatalf("XiaodianAssets() error = %v", err)
}
if assets.Coupons != 8800 || assets.Fragments != 36 {
t.Fatalf("资产 = %#v", assets)
}
} }
func testCTNClient(t *testing.T, ctnURL string) *DouyuClient { func testCTNClient(t *testing.T, ctnURL string) *DouyuClient {