功能:新增微信小程序界面

This commit is contained in:
xiaowang
2026-04-01 15:18:35 +08:00
parent bb2d8c4410
commit 7fa67d0511
92 changed files with 7463 additions and 0 deletions
+97
View File
@@ -0,0 +1,97 @@
const wishlistApi = require('../../api/wishlist')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const { buildProductCard } = require('../../utils/product')
const { runWithLoading } = require('../../utils/loading')
Page({
data: {
loading: false,
isLoggedIn: false,
wishlist: []
},
onShow() {
this.loadWishlist()
},
async loadWishlist() {
const isLoggedIn = auth.isLoggedIn()
this.setData({
isLoggedIn,
loading: isLoggedIn
})
if (!isLoggedIn) {
this.setData({
wishlist: [],
loading: false
})
return
}
try {
const wishlist = await wishlistApi.getWishlist()
const list = Array.isArray(wishlist) ? wishlist : []
const cards = await Promise.all(list.map(async item => ({
id: item.id,
productId: item.productId,
productCard: await buildProductCard(item.product || {})
})))
this.setData({
wishlist: cards
})
} catch (error) {
this.setData({
wishlist: []
})
wx.showToast({
title: error.message || '收藏列表加载失败',
icon: 'none'
})
} finally {
this.setData({
loading: false
})
}
},
handleOpenAuth() {
navigation.openAuth('/pages/wishlist/index')
},
handleProductSelect(event) {
const product = event.detail || {}
if (!product.id) {
return
}
navigation.navigate('/pages/product-detail/index', {
id: product.id
})
},
async handleRemove(event) {
const productId = event.currentTarget.dataset.productId
if (!productId) {
return
}
try {
await runWithLoading(() => wishlistApi.removeFromWishlist(productId))
wx.showToast({
title: '已取消收藏',
icon: 'none'
})
this.loadWishlist()
} catch (error) {
wx.showToast({
title: error.message || '取消收藏失败',
icon: 'none'
})
}
},
handleBack() {
navigation.goBack('/pages/profile/index')
}
})
+6
View File
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar",
"product-card": "/components/product-card/product-card"
}
}
+34
View File
@@ -0,0 +1,34 @@
<navigation-bar title="我的收藏" color="#2d2430" background="#fff7f8" bindback="handleBack"></navigation-bar>
<view class="page-shell wishlist-page">
<view class="page-content">
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
<text class="empty-title">登录后查看收藏</text>
<text class="empty-desc">你收藏过的作品会保存在这里,方便之后快速回看。</text>
<view class="ghost-btn" bindtap="handleOpenAuth">去登录</view>
</view>
<block wx:elif="{{wishlist.length}}">
<view class="page-hero wishlist-hero">
<text class="hero-kicker">收藏夹</text>
<text class="hero-title">已收藏 {{wishlist.length}} 个作品</text>
<text class="hero-desc">遇到喜欢的款式先放进收藏,之后再决定是否预约会更从容。</text>
</view>
<view wx:for="{{wishlist}}" wx:key="id" class="wishlist-item">
<product-card item="{{item.productCard}}" bindselect="handleProductSelect"></product-card>
<view class="wishlist-action" data-product-id="{{item.productId}}" bindtap="handleRemove">取消收藏</view>
</view>
</block>
<view wx:elif="{{loading}}" class="page-card empty-card">
<text class="empty-title">正在加载收藏内容</text>
</view>
<view wx:else class="page-card empty-card">
<text class="empty-title">你还没有收藏作品</text>
<text class="empty-desc">遇到喜欢的款式先收藏,之后再决定要不要预约。</text>
<view class="ghost-btn" bindtap="handleBack">去逛作品</view>
</view>
</view>
</view>
+20
View File
@@ -0,0 +1,20 @@
.wishlist-hero {
margin-bottom: 20rpx;
}
.wishlist-item + .wishlist-item {
margin-top: 22rpx;
}
.wishlist-action {
display: flex;
align-items: center;
justify-content: center;
height: 74rpx;
margin-top: 12rpx;
border-radius: 20rpx;
background: #fff1f5;
color: #c6597d;
font-size: 26rpx;
font-weight: 600;
}