@@ -22,6 +22,7 @@ export function storeCategoryTags(
|
||||
tags?: unknown;
|
||||
categoryId?: string | null;
|
||||
category?: StoreCategoryLike | null;
|
||||
categories?: StoreCategoryLike[] | null;
|
||||
},
|
||||
tree: StoreCategoryTreeNode[] = [],
|
||||
): string[] {
|
||||
@@ -30,24 +31,125 @@ export function storeCategoryTags(
|
||||
: [];
|
||||
if (fromJson.length) return fromJson;
|
||||
|
||||
const names: string[] = [];
|
||||
const childName = String(store.category?.name || '').trim();
|
||||
const parentName = String(store.category?.parent?.name || '').trim();
|
||||
if (parentName) names.push(parentName);
|
||||
if (childName && childName !== parentName) names.push(childName);
|
||||
const multi = Array.isArray(store.categories) ? store.categories : [];
|
||||
if (multi.length) {
|
||||
return groupCategoryTags(multi, tree);
|
||||
}
|
||||
|
||||
const storeCatId = String(store.categoryId || store.category?.id || '');
|
||||
const storeParentId = String(store.category?.parentId || '');
|
||||
for (const root of tree) {
|
||||
if (root.id === storeParentId || root.id === storeCatId) {
|
||||
if (root.name && !names.includes(root.name)) names.unshift(root.name);
|
||||
}
|
||||
for (const child of root.children ?? []) {
|
||||
if (child.id === storeCatId) {
|
||||
if (root.name && !names.includes(root.name)) names.unshift(root.name);
|
||||
if (child.name && !names.includes(child.name)) names.push(child.name);
|
||||
if (store.category || store.categoryId) {
|
||||
const grouped = groupCategoryTags(
|
||||
store.category ? [store.category] : [],
|
||||
tree,
|
||||
store.categoryId,
|
||||
);
|
||||
if (grouped.length) return grouped;
|
||||
}
|
||||
|
||||
const storeCatId = String(store.categoryId || '');
|
||||
if (storeCatId) {
|
||||
for (const root of tree) {
|
||||
for (const child of root.children ?? []) {
|
||||
if (child.id === storeCatId) {
|
||||
return [`${root.name}|${child.name}`];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return names;
|
||||
return [];
|
||||
}
|
||||
|
||||
/** 按大类分组:餐饮|火锅·江浙菜、娱乐|KTV */
|
||||
function groupCategoryTags(
|
||||
categories: StoreCategoryLike[],
|
||||
tree: StoreCategoryTreeNode[] = [],
|
||||
fallbackCategoryId?: string | null,
|
||||
): string[] {
|
||||
if (!categories.length && fallbackCategoryId) {
|
||||
return groupCategoryTags([{ id: String(fallbackCategoryId) }], tree);
|
||||
}
|
||||
|
||||
const groups = new Map<string, { parentName: string; children: string[] }>();
|
||||
const order: string[] = [];
|
||||
|
||||
for (const cat of categories) {
|
||||
const resolved = resolveCategoryParts(cat, tree);
|
||||
if (!resolved) continue;
|
||||
const { parentKey, parentName, childName } = resolved;
|
||||
if (!groups.has(parentKey)) {
|
||||
groups.set(parentKey, { parentName, children: [] });
|
||||
order.push(parentKey);
|
||||
}
|
||||
const group = groups.get(parentKey)!;
|
||||
if (childName && childName !== parentName && !group.children.includes(childName)) {
|
||||
group.children.push(childName);
|
||||
}
|
||||
}
|
||||
|
||||
return order
|
||||
.map((key) => {
|
||||
const group = groups.get(key)!;
|
||||
if (group.parentName && group.children.length) {
|
||||
return `${group.parentName}|${group.children.join('·')}`;
|
||||
}
|
||||
if (group.children.length) return group.children.join('·');
|
||||
return group.parentName;
|
||||
})
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function resolveCategoryParts(
|
||||
cat: StoreCategoryLike,
|
||||
tree: StoreCategoryTreeNode[] = [],
|
||||
): { parentKey: string; parentName: string; childName: string } | null {
|
||||
const childName = String(cat.name || '').trim();
|
||||
let parentName = String(cat.parent?.name || '').trim();
|
||||
const catId = String(cat.id || '');
|
||||
const parentId = String(cat.parentId || '');
|
||||
|
||||
if (!parentName && (parentId || catId)) {
|
||||
for (const root of tree) {
|
||||
if (parentId && root.id === parentId) {
|
||||
parentName = root.name;
|
||||
break;
|
||||
}
|
||||
for (const child of root.children ?? []) {
|
||||
if (catId && child.id === catId) {
|
||||
parentName = root.name;
|
||||
if (!childName) return { parentKey: root.id, parentName, childName: child.name };
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!childName && !parentName) return null;
|
||||
|
||||
const parentKey = parentId || parentName || catId;
|
||||
if (!parentName && catId) {
|
||||
for (const root of tree) {
|
||||
for (const child of root.children ?? []) {
|
||||
if (child.id === catId) {
|
||||
return { parentKey: root.id, parentName: root.name, childName: child.name };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
parentKey,
|
||||
parentName: parentName || childName,
|
||||
childName: childName || parentName,
|
||||
};
|
||||
}
|
||||
|
||||
export function storeLeafCategoryIds(store: {
|
||||
categoryId?: string | null;
|
||||
category?: StoreCategoryLike | null;
|
||||
categories?: StoreCategoryLike[] | null;
|
||||
}): string[] {
|
||||
if (Array.isArray(store.categories) && store.categories.length) {
|
||||
return store.categories.map((c) => String(c.id || '')).filter(Boolean);
|
||||
}
|
||||
const id = String(store.categoryId || store.category?.id || '');
|
||||
return id ? [id] : [];
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ type StoresSession = {
|
||||
cache: StoresListCache | null;
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'dukang_stores_session_v2';
|
||||
const STORAGE_KEY = 'dukang_stores_session_v3';
|
||||
|
||||
let memory: StoresSession | null = null;
|
||||
|
||||
|
||||
@@ -79,6 +79,12 @@ type Store = {
|
||||
parentId?: string | null;
|
||||
parent?: { name?: string } | null;
|
||||
} | null;
|
||||
categories?: {
|
||||
id?: string;
|
||||
name?: string;
|
||||
parentId?: string | null;
|
||||
parent?: { name?: string } | null;
|
||||
}[] | null;
|
||||
};
|
||||
|
||||
type RecentRedeem = {
|
||||
@@ -406,12 +412,15 @@ export default function StoreDetailPage() {
|
||||
|
||||
<View className="store-detail-title-row">
|
||||
<Text className="store-detail-name">{store.name}</Text>
|
||||
{storeCategoryTags(store, categoryTree).map((tag) => (
|
||||
<Text key={tag} className="store-detail-tag">
|
||||
{tag}
|
||||
</Text>
|
||||
))}
|
||||
</View>
|
||||
{(() => {
|
||||
const categoryLabels = storeCategoryTags(store, categoryTree);
|
||||
return categoryLabels.length ? (
|
||||
<View className="store-detail-tags-row">
|
||||
<Text className="store-detail-category-line">{categoryLabels.join('、')}</Text>
|
||||
</View>
|
||||
) : null;
|
||||
})()}
|
||||
<View className="store-detail-rating-row">
|
||||
<View className="store-detail-stars">
|
||||
{[1, 2, 3, 4, 5].map((n) => (
|
||||
|
||||
@@ -42,7 +42,7 @@ import {
|
||||
toWeappShareTimeline,
|
||||
} from '../../lib/wechat-share';
|
||||
import BenefitSloganBar from '../../components/BenefitSloganBar';
|
||||
import { storeCategoryTags, storeStarCount } from '../../lib/store-display';
|
||||
import { storeCategoryTags, storeLeafCategoryIds, storeStarCount } from '../../lib/store-display';
|
||||
import openBadgeImg from '../../assets/icons/store-open-badge.png';
|
||||
|
||||
type Store = {
|
||||
@@ -66,6 +66,12 @@ type Store = {
|
||||
parentId?: string | null;
|
||||
parent?: { name?: string } | null;
|
||||
} | null;
|
||||
categories?: {
|
||||
id?: string;
|
||||
name?: string;
|
||||
parentId?: string | null;
|
||||
parent?: { name?: string } | null;
|
||||
}[] | null;
|
||||
tags?: unknown;
|
||||
rating?: number | string | null;
|
||||
latitude?: number | string | null;
|
||||
@@ -288,14 +294,21 @@ export default function StoresPage() {
|
||||
|
||||
function matchesCategory(store: Store): boolean {
|
||||
if (!category.parentId) return true;
|
||||
const storeCatId = String(store.categoryId || store.category?.id || '');
|
||||
const storeParentId = String(store.category?.parentId || '');
|
||||
if (category.childId) {
|
||||
return storeCatId === category.childId;
|
||||
const leafIds = storeLeafCategoryIds(store);
|
||||
const parentIds = new Set<string>();
|
||||
if (Array.isArray(store.categories)) {
|
||||
for (const cat of store.categories) {
|
||||
if (cat.parentId) parentIds.add(String(cat.parentId));
|
||||
}
|
||||
}
|
||||
if (storeParentId && storeParentId === category.parentId) return true;
|
||||
const legacyParent = String(store.category?.parentId || '');
|
||||
if (legacyParent) parentIds.add(legacyParent);
|
||||
if (category.childId) {
|
||||
return leafIds.includes(category.childId);
|
||||
}
|
||||
if ([...parentIds].some((id) => id === category.parentId)) return true;
|
||||
const siblings = childIdsByParent.get(category.parentId) ?? [];
|
||||
return siblings.includes(storeCatId);
|
||||
return leafIds.some((id) => siblings.includes(id));
|
||||
}
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
@@ -461,14 +474,10 @@ export default function StoresPage() {
|
||||
<Text className="store-card-name">{s.name}</Text>
|
||||
</View>
|
||||
{(() => {
|
||||
const tags = storeCategoryTags(s, categoryTree);
|
||||
return tags.length ? (
|
||||
<View className="store-card-tags">
|
||||
{tags.map((tag) => (
|
||||
<Text key={tag} className="store-card-tag">
|
||||
{tag}
|
||||
</Text>
|
||||
))}
|
||||
const categoryLabels = storeCategoryTags(s, categoryTree);
|
||||
return categoryLabels.length ? (
|
||||
<View className="store-card-category-wrap">
|
||||
<Text className="store-card-category-text">{categoryLabels.join('、')}</Text>
|
||||
</View>
|
||||
) : null;
|
||||
})()}
|
||||
|
||||
@@ -100,6 +100,12 @@
|
||||
}
|
||||
|
||||
.store-detail-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.store-detail-tags-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
@@ -107,6 +113,20 @@
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.store-detail-category-line {
|
||||
display: inline-block;
|
||||
max-width: 100%;
|
||||
padding: 2px 8px;
|
||||
border-radius: 6px;
|
||||
background: rgba(166, 29, 36, 0.1);
|
||||
box-sizing: border-box;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
line-height: 16px;
|
||||
color: var(--color-heritage-red);
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.store-detail-name {
|
||||
font-family: var(--font-headline);
|
||||
font-size: 20px;
|
||||
|
||||
@@ -215,13 +215,32 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.store-card-category-wrap {
|
||||
align-self: flex-start;
|
||||
max-width: 100%;
|
||||
padding: 0 6px;
|
||||
border-radius: 4px;
|
||||
background: rgba(166, 29, 36, 0.1);
|
||||
box-sizing: border-box;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.store-card-category-text {
|
||||
font-size: 10px;
|
||||
font-weight: 500;
|
||||
line-height: 14px;
|
||||
color: var(--color-heritage-red);
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.store-card-tags {
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
margin-top: 2px;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.store-card-tag {
|
||||
|
||||
Reference in New Issue
Block a user