功能(小程序):同步用户体验流程到小程序

This commit is contained in:
xiaowang
2026-05-23 21:56:52 +08:00
parent 861eea933b
commit b67dae502f
38 changed files with 2163 additions and 126 deletions
+63 -15
View File
@@ -39,7 +39,10 @@ Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: false,
isLoggedIn: false,
wishlist: []
wishlist: [],
visibleWishlist: [],
groups: [],
activeGroupId: ''
}),
/**
@@ -65,29 +68,42 @@ Page({
this.cartProductIdSet = new Set()
this.setData({
wishlist: [],
visibleWishlist: [],
groups: [],
activeGroupId: '',
loading: false
})
return
}
try {
const wishlist = await wishlistApi.getWishlist()
const [wishlist, groups] = await Promise.all([
wishlistApi.getWishlist(),
wishlistApi.getGroups()
])
const list = Array.isArray(wishlist) ? wishlist : []
const groupList = Array.isArray(groups) ? groups : []
const cartProductIdSet = await this.fetchCartProductIdSet()
const cards = await Promise.all(list.map(async item => ({
id: item.id,
productId: item.productId,
groupId: this.normalizeId(item.groupId),
groupName: item.groupName || '\u6700\u8fd1\u60f3\u505a',
note: item.note || '',
productCard: this.markCardInCart(
await buildProductCard(item.product || {}),
cartProductIdSet
)
})))
this.setData({
wishlist: cards
wishlist: cards,
groups: this.buildGroupTabs(groupList, this.data.activeGroupId),
visibleWishlist: this.filterWishlist(cards, this.data.activeGroupId)
})
} catch (error) {
this.setData({
wishlist: []
wishlist: [],
visibleWishlist: []
})
wx.showToast({
title: error.message || '\u6536\u85cf\u5217\u8868\u52a0\u8f7d\u5931\u8d25',
@@ -108,6 +124,36 @@ Page({
return value === undefined || value === null ? '' : String(value)
},
filterWishlist(list, groupId) {
const normalizedGroupId = this.normalizeId(groupId)
if (!normalizedGroupId) {
return list
}
return list.filter(item => this.normalizeId(item && item.groupId) === normalizedGroupId)
},
buildGroupTabs(groups, activeGroupId) {
const normalizedActiveGroupId = this.normalizeId(activeGroupId)
return (Array.isArray(groups) ? groups : []).map(group => {
const id = this.normalizeId(group && group.id)
return {
id,
name: group.name,
itemCount: group.itemCount || 0,
active: id === normalizedActiveGroupId
}
})
},
handleGroupSelect(event) {
const groupId = this.normalizeId(event.currentTarget.dataset.groupId)
this.setData({
activeGroupId: groupId,
groups: this.buildGroupTabs(this.data.groups, groupId),
visibleWishlist: this.filterWishlist(this.data.wishlist, groupId)
})
},
async fetchCartProductIdSet() {
try {
const cartList = await cartApi.getCartList()
@@ -152,18 +198,20 @@ Page({
this.cartProductIdSet = this.cartProductIdSet || new Set()
this.cartProductIdSet.add(normalizedId)
this.setData({
wishlist: this.data.wishlist.map(item => (
this.normalizeId(item && item.productId) === normalizedId
? {
...item,
productCard: {
...item.productCard,
inCart: true
}
const nextWishlist = this.data.wishlist.map(item => (
this.normalizeId(item && item.productId) === normalizedId
? {
...item,
productCard: {
...item.productCard,
inCart: true
}
: item
))
}
: item
))
this.setData({
wishlist: nextWishlist,
visibleWishlist: this.filterWishlist(nextWishlist, this.data.activeGroupId)
})
},