功能:收口小程序前后台安全与防重复提交

This commit is contained in:
xiaowang
2026-04-20 16:02:57 +08:00
parent eb1c209d79
commit a3df262fae
237 changed files with 14068 additions and 728 deletions
+8 -7
View File
@@ -2,6 +2,7 @@ const authApi = require('../../api/auth')
const shopApi = require('../../api/shop')
const userApi = require('../../api/user')
const authStore = require('../../utils/auth')
const actionGuard = require('../../utils/action-guard')
const navigation = require('../../utils/navigation')
const { runWithLoading } = require('../../utils/loading')
@@ -86,14 +87,14 @@ Page({
const systemInfo = wx.getSystemInfoSync()
if (systemInfo && systemInfo.platform === 'devtools') {
supported = false
disabledReason = '开发者工具暂不支持微信手机号一键登录,请使用真机调试或传统登录。'
disabledReason = '开发者工具暂不支持一键登录,请用真机或其他方式登录'
}
} catch (error) {
supported = false
}
if (!supported && !disabledReason) {
disabledReason = '当前微信环境暂不支持手机号一键登录,请使用账号密码或验证码登录。'
disabledReason = '当前环境暂不支持一键登录,请使用其他方式登录'
}
this.setData({
@@ -385,7 +386,7 @@ Page({
} catch (error) {
this.applyLoginShopSelection({
allowShoplessLogin: true,
message: '当前暂无法预加载可登录门店,可直接尝试登录。',
message: '暂时无法加载门店,可直接登录',
shops: []
})
}
@@ -398,7 +399,7 @@ Page({
} catch (error) {
this.applyLoginShopSelection({
allowShoplessLogin: true,
message: '当前暂无法预加载可登录门店,可直接尝试登录。',
message: '暂时无法加载门店,可直接登录',
shops: []
})
}
@@ -907,11 +908,11 @@ Page({
buildAuthHelperText(activeTab, loginType) {
if (activeTab === 'register') {
return '注册前会检查账号和手机号是否可用,并要求先选择门店。'
return '注册前请先选门店'
}
if (loginType === 'phone') {
return '验证码登录时,若手机号未注册,会先选择门店后自动注册。'
return '未注册手机号会先选门店'
}
return '若账号绑定了多家门店,登录前需要先选择本次门店。'
return '多门店账号需先选门店'
}
})
+9 -9
View File
@@ -12,7 +12,7 @@
<view class="wechat-login-panel">
<view class="wechat-login-copy">
<text class="wechat-login-title">微信手机号一键登录</text>
<text class="wechat-login-desc">最快的登录方式,首次授权也能自动注册。</text>
<text class="wechat-login-desc">更快登录</text>
</view>
<button
@@ -34,22 +34,22 @@
微信手机号一键登录
</button>
<text class="wechat-login-hint">{{wechatMiniSupported ? '若只绑定一家可用门店,会直接登录。' : wechatMiniDisabledReason}}</text>
<text class="wechat-login-hint">{{wechatMiniSupported ? '单门店可直接登录' : wechatMiniDisabledReason}}</text>
</view>
<view wx:if="{{miniShopTicket && !showMiniShopSelector}}" class="hint-card mini-login-resume">
<text class="mini-login-resume-text">微信身份已识别完成,还差一步门店确认即可登录。</text>
<text class="mini-login-resume-text">请选择登录门店</text>
<view class="ghost-btn mini-login-resume-btn" bindtap="handleResumeMiniShopSelector">继续选择门店</view>
</view>
<view wx:if="{{!traditionalLoginExpanded}}" class="traditional-entry">
<view class="secondary-btn traditional-entry-btn" bindtap="handleShowTraditionalLogin">使用账号密码或验证码登录</view>
<view class="secondary-btn traditional-entry-btn" bindtap="handleShowTraditionalLogin">其他登录方式</view>
</view>
<view wx:if="{{traditionalLoginExpanded}}" class="traditional-login-panel">
<view class="login-divider">
<view class="divider-line"></view>
<text class="login-divider-text">传统登录方式</text>
<text class="login-divider-text">其他方式</text>
<view class="divider-line"></view>
</view>
@@ -130,7 +130,7 @@
<view wx:if="{{showResetPanel}}" class="page-card reset-card">
<view class="section-title">重置密码</view>
<view class="section-subtitle">使用短信验证码设置新的登录密码。</view>
<view class="section-subtitle">短信验证后重置密码</view>
<view class="field-block">
<text class="field-label">手机号</text>
@@ -157,8 +157,8 @@
<view wx:if="{{showMiniShopSelector}}" class="mini-shop-mask" catchtouchmove="noop">
<view class="page-card mini-shop-modal">
<text class="mini-shop-kicker">{{miniShopNewUser ? '首次微信登录' : '确认本次登录门店'}}</text>
<text class="mini-shop-title">{{miniShopNewUser ? '先选一家门店,我们会自动注册并登录' : '该账号绑定了多家门店,请先选择本次登录门店'}}</text>
<text class="mini-shop-desc">{{miniShopMessage || '选择后将继续完成登录。'}}</text>
<text class="mini-shop-title">{{miniShopNewUser ? '先选门店' : '选择登录门店'}}</text>
<text class="mini-shop-desc">{{miniShopMessage || '选择后继续登录'}}</text>
<view class="field-block mini-shop-field">
<text class="field-label">登录门店</text>
@@ -167,7 +167,7 @@
</picker>
</view>
<view wx:if="{{miniShopNewUser}}" class="hint-card mini-shop-note">首次通过微信手机号登录时,会自动创建账号、绑定手机号,并将当前门店作为本次登录门店。</view>
<view wx:if="{{miniShopNewUser}}" class="hint-card mini-shop-note">首次登录会自动注册并绑定手机号。</view>
<view class="mini-shop-actions">
<view class="secondary-btn mini-shop-action" bindtap="handleCloseMiniShopSelector">稍后再选</view>
+8 -8
View File
@@ -4,7 +4,7 @@
<view class="page-content cart-content">
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
<text class="empty-title">登录后查看购物车</text>
<text class="empty-desc">把喜欢的作品加进购物车后,就能补全预约信息并提交订单。</text>
<text class="empty-desc">登录后管理预约内容。</text>
<view class="ghost-btn" bindtap="handleOpenAuth">去登录</view>
</view>
@@ -12,23 +12,23 @@
<view class="page-hero cart-hero">
<text class="hero-kicker">结算准备</text>
<text class="hero-title">已选 {{selectedCount}} 个预约项目</text>
<text class="hero-desc">先确认美甲师和预约时间,再统一提交订单,避免来回修改。</text>
<text class="hero-desc">确认美甲师和时间后再下单。</text>
<view class="summary-strip">
<view class="summary-metric">
<text class="summary-label">选中项目</text>
<text class="summary-value">{{selectedCount}} 项</text>
<text class="summary-note">可分批勾选结算</text>
<text class="summary-note">可分批结算</text>
</view>
<view class="summary-metric">
<text class="summary-label">数量合计</text>
<text class="summary-value">{{totalQuantity}} 件</text>
<text class="summary-note">支持直接增减数量</text>
<text class="summary-note">可改数量</text>
</view>
<view class="summary-metric">
<text class="summary-label">待支付</text>
<text class="summary-value">{{totalAmountText}}</text>
<text class="summary-note">已自动计算优惠</text>
<text class="summary-note">已算优惠</text>
</view>
</view>
</view>
@@ -41,7 +41,7 @@
<view wx:for="{{cartItems}}" wx:key="id" class="page-card cart-item-card">
<view class="cart-item-top">
<view class="select-dot {{item.selected ? 'active' : ''}}" data-index="{{index}}" bindtap="handleToggleSelect"></view>
<image class="cart-thumb" src="{{item.productImageUrl}}" mode="aspectFill" data-product-id="{{item.productId}}" bindtap="handleOpenProduct"></image>
<image class="cart-thumb" src="{{item.productImageUrl}}" mode="aspectFill" data-product-id="{{item.productId}}" bindtap="handleOpenProduct" lazy-load="{{true}}"></image>
<view class="cart-main">
<view class="cart-title-row">
<view class="cart-title" data-product-id="{{item.productId}}" bindtap="handleOpenProduct">{{item.productTitle}}</view>
@@ -93,7 +93,7 @@
<view wx:if="{{selectedCount}}" class="page-card coupon-card">
<view class="section-title">优惠方式</view>
<view class="section-subtitle">系统会优先帮你匹配最合适的 VIP 自动折扣,普通优惠券仍可手动改选。</view>
<view class="section-subtitle">系统会优先匹配 VIP 优惠。</view>
<radio-group bindchange="handleCouponChange">
<label class="coupon-option">
@@ -144,7 +144,7 @@
<view wx:else class="page-card empty-card">
<text class="empty-title">购物车还是空的</text>
<text class="empty-desc">先把喜欢的作品加进来,再补充预约时间和美甲师。</text>
<text class="empty-desc">先加购,再预约。</text>
<view class="ghost-btn" bindtap="handleBrowseProducts">去逛作品</view>
</view>
</view>
+41 -2
View File
@@ -13,7 +13,15 @@ Page({
data: {
loading: false,
isLoggedIn: false,
coupons: []
coupons: [],
filteredCoupons: [],
activeFilter: 'all',
filterOptions: [
{ value: 'all', label: '全部' },
{ value: 'available', label: '未使用' },
{ value: 'used', label: '已使用' },
{ value: 'expired', label: '已过期' }
]
},
onShow() {
@@ -30,6 +38,8 @@ Page({
if (!isLoggedIn) {
this.setData({
coupons: [],
filteredCoupons: [],
activeFilter: 'all',
loading: false
})
return
@@ -47,9 +57,11 @@ Page({
this.setData({
coupons: list
})
this.applyFilter(this.data.activeFilter, list)
} catch (error) {
this.setData({
coupons: []
coupons: [],
filteredCoupons: []
})
wx.showToast({
title: error.message || '优惠券加载失败',
@@ -62,6 +74,33 @@ Page({
}
},
applyFilter(filterValue, sourceCoupons) {
const activeFilter = filterValue || 'all'
const coupons = Array.isArray(sourceCoupons) ? sourceCoupons : this.data.coupons
let filteredCoupons = coupons
if (activeFilter === 'available') {
filteredCoupons = coupons.filter(item => Number(item.status) === 1)
} else if (activeFilter === 'used') {
filteredCoupons = coupons.filter(item => Number(item.status) === 2)
} else if (activeFilter === 'expired') {
filteredCoupons = coupons.filter(item => Number(item.status) === 3)
}
this.setData({
activeFilter,
filteredCoupons
})
},
handleFilterChange(event) {
const value = event.currentTarget.dataset.value
if (!value || value === this.data.activeFilter) {
return
}
this.applyFilter(value)
},
handleOpenAuth() {
navigation.openAuth('/pages/coupons/index')
},
+32 -13
View File
@@ -4,27 +4,46 @@
<view class="page-content">
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
<text class="empty-title">登录后查看优惠券</text>
<text class="empty-desc">可用优惠、VIP 自动折扣都会统一展示在这里。</text>
<text class="empty-desc">登录后查看可用优惠。</text>
<view class="ghost-btn" bindtap="handleOpenAuth">去登录</view>
</view>
<block wx:elif="{{coupons.length}}">
<view class="page-hero coupons-hero">
<text class="hero-kicker">优惠资产</text>
<text class="hero-title">当前有 {{coupons.length}} 张可查看</text>
<text class="hero-desc">普通优惠券和系统自动匹配的 VIP 折扣都会在结算前统一展示。</text>
<text class="hero-title">当前有 {{coupons.length}} 张</text>
<text class="hero-desc">下单前可查看可用优惠。</text>
</view>
<view wx:for="{{coupons}}" wx:key="id" class="page-card coupon-card">
<view class="coupon-top">
<view>
<view class="coupon-title">{{item.couponName}}</view>
<view class="coupon-source">{{item.sourceText}}</view>
</view>
<view class="coupon-status">{{item.statusName || '待使用'}}</view>
<view class="coupon-filter-row">
<view
wx:for="{{filterOptions}}"
wx:key="value"
class="coupon-filter-chip {{activeFilter === item.value ? 'active' : ''}}"
data-value="{{item.value}}"
bindtap="handleFilterChange"
>
{{item.label}}
</view>
<view class="coupon-benefit">{{item.benefitText}}</view>
<view class="coupon-period">{{item.periodText}}</view>
</view>
<block wx:if="{{filteredCoupons.length}}">
<view wx:for="{{filteredCoupons}}" wx:key="id" class="page-card coupon-card">
<view class="coupon-top">
<view>
<view class="coupon-title">{{item.couponName}}</view>
<view class="coupon-source">{{item.sourceText}}</view>
</view>
<view class="coupon-status">{{item.statusName || '待使用'}}</view>
</view>
<view class="coupon-benefit">{{item.benefitText}}</view>
<view class="coupon-period">{{item.periodText}}</view>
</view>
</block>
<view wx:else class="page-card empty-card">
<text class="empty-title">当前筛选下暂无优惠券</text>
<text class="empty-desc">换个筛选试试。</text>
</view>
</block>
@@ -34,7 +53,7 @@
<view wx:else class="page-card empty-card">
<text class="empty-title">你还没有优惠券</text>
<text class="empty-desc">下单前系统也会自动帮你匹配最合适的优惠方式。</text>
<text class="empty-desc">下单前会自动匹配可用优惠。</text>
</view>
</view>
</view>
+26
View File
@@ -2,6 +2,32 @@
margin-bottom: 20rpx;
}
.coupon-filter-row {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
margin-bottom: 20rpx;
}
.coupon-filter-chip {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 120rpx;
height: 60rpx;
padding: 0 24rpx;
border-radius: 999rpx;
background: rgba(255, 255, 255, 0.78);
color: #8d7a84;
font-size: 24rpx;
font-weight: 600;
}
.coupon-filter-chip.active {
background: linear-gradient(135deg, #ff8cb0 0%, #c6597d 100%);
color: #ffffff;
}
.coupon-card + .coupon-card {
margin-top: 20rpx;
}
+94 -62
View File
@@ -1,8 +1,9 @@
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const cache = require('../../utils/cache')
const { buildProductCards } = require('../../utils/product')
const { resolveImageList } = require('../../utils/file')
const { DEFAULT_SHOP_IMAGE } = require('../../utils/config')
const { DEFAULT_SHOP_IMAGE, CACHE_TTL } = require('../../utils/config')
const productApi = require('../../api/product')
const shopApi = require('../../api/shop')
const userApi = require('../../api/user')
@@ -11,6 +12,7 @@ Page({
data: {
initialized: false,
loading: false,
loadingMore: false,
isLoggedIn: false,
userInfo: null,
greeting: '欢迎来到 Yumi Nail',
@@ -18,14 +20,15 @@ Page({
searchKeyword: '',
bannerImages: [],
featuredItems: [],
popularSource: [],
popularItems: [],
popularPage: 1,
pageSize: 6,
hasMore: false
hasMore: false,
popularTotal: 0
},
onLoad() {
this.homeRequestId = 0
this.loadHomeData()
},
@@ -37,22 +40,16 @@ Page({
},
async onPullDownRefresh() {
cache.removeByPrefix('home:')
await this.loadHomeData()
wx.stopPullDownRefresh()
},
onReachBottom() {
if (!this.data.hasMore) {
if (!this.data.hasMore || this.data.loadingMore) {
return
}
const nextPage = this.data.popularPage + 1
const nextItems = this.data.popularSource.slice(0, nextPage * this.data.pageSize)
this.setData({
popularPage: nextPage,
popularItems: nextItems,
hasMore: nextItems.length < this.data.popularSource.length
})
this.loadPopularProducts(false)
},
syncUserState() {
@@ -88,81 +85,116 @@ Page({
},
async loadHomeData() {
const requestId = ++this.homeRequestId
this.setData({ loading: true })
this.syncUserState()
try {
await Promise.all([
this.loadUserProfile(),
this.loadBannerImages(),
this.loadFeaturedProducts(),
this.loadPopularProducts()
this.loadBannerImages(requestId),
this.loadFeaturedProducts(requestId),
this.loadPopularProducts(true, requestId)
])
this.setData({
initialized: true
})
if (requestId === this.homeRequestId) {
this.setData({
initialized: true
})
}
} catch (error) {
wx.showToast({
title: error.message || '首页加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
if (requestId === this.homeRequestId) {
this.setData({ loading: false })
}
}
},
async loadBannerImages() {
const shops = await shopApi.getPublicShops()
const list = Array.isArray(shops) ? shops : []
const banners = []
for (let index = 0; index < list.length; index += 1) {
const shop = list[index]
const imageIds = shop.coverImageFileId || shop.imageFileIds
const urls = await resolveImageList(imageIds, DEFAULT_SHOP_IMAGE)
if (urls[0]) {
banners.push({
async loadBannerImages(requestId) {
const banners = await cache.remember('home:banners', CACHE_TTL.banner, async () => {
const shops = await shopApi.getPublicShops()
const list = Array.isArray(shops) ? shops : []
const resolved = await Promise.all(list.slice(0, 6).map(async (shop, index) => {
const imageIds = shop.coverImageFileId || shop.imageFileIds
const urls = await resolveImageList(imageIds, DEFAULT_SHOP_IMAGE)
return {
id: `${shop.id}-${index}`,
shopId: shop.id,
shopName: shop.shopName,
businessHours: shop.businessHours || '欢迎到店体验',
imageUrl: urls[0]
}
}))
return resolved.filter(item => item.imageUrl)
})
if (requestId === this.homeRequestId) {
this.setData({
bannerImages: Array.isArray(banners) ? banners : []
})
}
},
async loadFeaturedProducts(requestId) {
const items = await cache.remember('home:featured', CACHE_TTL.homeList, async () => {
const result = await productApi.getProductPage({
page: 1,
size: 6,
tag: '精选'
})
return buildProductCards(result && result.list ? result.list : [])
})
if (requestId === this.homeRequestId) {
this.setData({
featuredItems: Array.isArray(items) ? items : []
})
}
},
async loadPopularProducts(reset, requestId) {
const currentRequestId = requestId || this.homeRequestId
const nextPage = reset ? 1 : this.data.popularPage + 1
const loadingState = reset ? { loading: true } : { loadingMore: true }
this.setData(loadingState)
try {
const result = await productApi.getProductPage({
page: nextPage,
size: this.data.pageSize,
tag: '热门'
})
const cards = await buildProductCards(result && result.list ? result.list : [])
if (currentRequestId !== this.homeRequestId) {
return
}
const mergedItems = reset ? cards : this.data.popularItems.concat(cards)
const total = Number(result && result.total) || 0
this.setData({
popularItems: mergedItems,
popularPage: nextPage,
popularTotal: total,
hasMore: mergedItems.length < total
})
} catch (error) {
if (currentRequestId !== this.homeRequestId) {
return
}
wx.showToast({
title: error.message || '热门作品加载失败',
icon: 'none'
})
} finally {
if (currentRequestId === this.homeRequestId) {
this.setData({
loadingMore: false
})
}
}
this.setData({
bannerImages: banners.slice(0, 6)
})
},
async loadFeaturedProducts() {
let products = await productApi.getProductsByTag('精选')
if (!Array.isArray(products) || !products.length) {
products = await productApi.getAllProducts()
}
const cards = await buildProductCards((products || []).slice(0, 6))
this.setData({
featuredItems: cards
})
},
async loadPopularProducts() {
let products = await productApi.getProductsByTag('热门')
if (!Array.isArray(products) || !products.length) {
products = await productApi.getAllProducts()
}
const cards = await buildProductCards(products || [])
const initialItems = cards.slice(0, this.data.pageSize)
this.setData({
popularSource: cards,
popularItems: initialItems,
popularPage: 1,
hasMore: initialItems.length < cards.length
})
},
handleSearchInput(event) {
+15 -12
View File
@@ -7,7 +7,7 @@
<view class="page-hero home-hero">
<text class="hero-kicker">{{isLoggedIn ? greeting : 'YUMI NAIL 小程序'}}</text>
<text class="hero-title">{{displayName}}</text>
<text class="hero-desc">先看门店氛围,再挑喜欢的作品,最后一站式完成收藏、加购和预约。</text>
<text class="hero-desc">先选喜欢的作品。</text>
<view class="hero-action-row">
<view class="hero-action primary" bindtap="handleProfileTap">{{isLoggedIn ? '进入个人中心' : '立即登录'}}</view>
@@ -31,22 +31,22 @@
<view class="summary-metric">
<text class="summary-label">门店橱窗</text>
<text class="summary-value">{{bannerImages.length ? bannerImages.length : 0}} 家</text>
<text class="summary-note">先看环境,再决定去哪家</text>
<text class="summary-note">看环境</text>
</view>
<view class="summary-metric">
<text class="summary-label">精选作品</text>
<text class="summary-value">{{featuredItems.length ? featuredItems.length : 0}} 款</text>
<text class="summary-note">适合快速找到灵感</text>
<text class="summary-note">找灵感</text>
</view>
<view class="summary-metric">
<text class="summary-label">热门推荐</text>
<text class="summary-value">{{popularItems.length ? popularItems.length : 0}} 条</text>
<text class="summary-note">当前最受欢迎的预约款式</text>
<text class="summary-note">热门款</text>
</view>
</view>
<view wx:if="{{!isLoggedIn}}" class="guest-tip">
登录后可同步收藏、购物车和预约记录,切换设备也不会丢。
登录后可同步收藏和预约记录。
</view>
</view>
@@ -55,7 +55,7 @@
<view class="section-copy">
<text class="section-kicker">门店氛围</text>
<text class="section-title">先看看线下环境</text>
<text class="section-subtitle">轮播展示门店图片和营业时间,帮助你快速判断想去的店。</text>
<text class="section-subtitle">看店铺环境</text>
</view>
</view>
@@ -63,7 +63,7 @@
<swiper class="banner-swiper" indicator-dots autoplay circular interval="3200">
<swiper-item wx:for="{{bannerImages}}" wx:key="id">
<view class="banner-item" data-shop-id="{{item.shopId}}" bindtap="handleBannerTap">
<image class="banner-image" src="{{item.imageUrl}}" mode="aspectFill"></image>
<image class="banner-image" src="{{item.imageUrl}}" mode="aspectFill" lazy-load="{{true}}"></image>
<view class="banner-mask">
<view class="banner-badge">门店实拍</view>
<view class="banner-title">{{item.shopName}}</view>
@@ -76,7 +76,7 @@
<view wx:else class="page-card empty-card">
<text class="empty-title">门店内容正在补充中</text>
<text class="empty-desc">可以先浏览精选作品,稍后再回来查看门店环境展示。</text>
<text class="empty-desc">先看看作品。</text>
</view>
</view>
@@ -85,7 +85,7 @@
<view class="section-copy">
<text class="section-kicker">快速入门</text>
<text class="section-title">精选作品</text>
<text class="section-subtitle">适合先快速逛一圈的热门款式,向右滑动查看更多。</text>
<text class="section-subtitle">先看热门款</text>
</view>
<view class="section-link" bindtap="handleSeeAllFeatured">查看全部</view>
</view>
@@ -102,7 +102,7 @@
<view wx:else class="page-card empty-card">
<text class="empty-title">精选作品正在整理中</text>
<text class="empty-desc">等门店补齐款式后,这里会优先展示最值得先看的内容。</text>
<text class="empty-desc">稍后再来看看。</text>
</view>
</view>
@@ -111,7 +111,7 @@
<view class="section-copy">
<text class="section-kicker">热门预约</text>
<text class="section-title">最近大家都在看</text>
<text class="section-subtitle">结合点赞和收藏热度展示当前最受欢迎的款式。</text>
<text class="section-subtitle">热门款式</text>
</view>
<view class="section-link" bindtap="handleSeeAllPopular">查看全部</view>
</view>
@@ -121,6 +121,9 @@
<product-card item="{{item}}" show-stats="{{true}}" bindselect="handleProductSelect"></product-card>
</view>
</view>
<view wx:if="{{popularItems.length && (loadingMore || !hasMore)}}" class="section-load-state">
<text class="section-load-text">{{loadingMore ? '正在加载更多热门作品...' : '已经到底了'}}</text>
</view>
<view wx:elif="{{loading}}" class="page-card empty-card">
<text class="empty-title">正在加载首页内容</text>
@@ -128,7 +131,7 @@
<view wx:else class="page-card empty-card">
<text class="empty-title">还没有热门作品</text>
<text class="empty-desc">当前门店还在补充作品数据,稍后再回来看看。</text>
<text class="empty-desc">稍后再来看看。</text>
</view>
</view>
</view>
+11
View File
@@ -148,3 +148,14 @@
.popular-card {
width: calc(50% - 9rpx);
}
.section-load-state {
display: flex;
justify-content: center;
padding-top: 18rpx;
}
.section-load-text {
font-size: 22rpx;
color: #8d7a84;
}
+1 -1
View File
@@ -2,6 +2,6 @@
<view class="redirect-page">
<view class="redirect-card">
<view class="redirect-title">正在进入首页</view>
<view class="redirect-desc">这个 `pages/index` 是初始化遗留页,当前实际首页是 `pages/home/index`。</view>
<view class="redirect-desc">即将进入首页</view>
</view>
</view>
+29 -21
View File
@@ -1,6 +1,7 @@
const orderApi = require('../../api/order')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const actionGuard = require('../../utils/action-guard')
const { resolveLegacyImage } = require('../../utils/file')
const { formatDateTime, formatPrice, getOrderStatusClass, getOrderStatusText } = require('../../utils/format')
const { runWithLoading } = require('../../utils/loading')
@@ -38,11 +39,11 @@ Page({
...order,
statusText: getOrderStatusText(order),
statusClass: getOrderStatusClass(order),
actualAmountText: `¥${formatPrice(order.actualAmount)}`,
actualAmountText: `\u00a5${formatPrice(order.actualAmount)}`,
items: await Promise.all((order.items || []).map(async item => ({
...item,
productImageUrl: await resolveLegacyImage(item.productImage),
priceText: `¥${formatPrice(item.price)}`,
priceText: `\u00a5${formatPrice(item.price)}`,
appointmentText: formatDateTime(item.appointmentTime)
})))
})))
@@ -55,7 +56,7 @@ Page({
orders: []
})
wx.showToast({
title: error.message || '订单列表加载失败',
title: error.message || '\u8ba2\u5355\u5217\u8868\u52a0\u8f7d\u5931\u8d25',
icon: 'none'
})
} finally {
@@ -79,28 +80,35 @@ Page({
return
}
const result = await new Promise(resolve => {
wx.showModal({
title: '取消订单',
content: '确认取消这笔订单吗?',
success: modalRes => resolve(Boolean(modalRes.confirm))
})
})
if (!result) {
return
}
try {
await runWithLoading(() => orderApi.cancelOrder(orderId))
wx.showToast({
title: '订单已取消',
icon: 'none'
await actionGuard.run(this, `order:cancel:${orderId}`, async () => {
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '\u53d6\u6d88\u8ba2\u5355',
content: '\u786e\u8ba4\u53d6\u6d88\u8fd9\u7b14\u8ba2\u5355\u5417\uff1f',
success: modalRes => resolve(Boolean(modalRes.confirm))
})
})
if (!confirmed) {
return
}
await runWithLoading(() => orderApi.cancelOrder(orderId))
wx.showToast({
title: '\u8ba2\u5355\u5df2\u53d6\u6d88',
icon: 'none'
})
await this.loadOrders()
}, {
message: '\u64cd\u4f5c\u8fdb\u884c\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u70b9\u51fb'
})
this.loadOrders()
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '取消订单失败',
title: error.message || '\u53d6\u6d88\u8ba2\u5355\u5931\u8d25',
icon: 'none'
})
}
+4 -4
View File
@@ -4,7 +4,7 @@
<view class="page-content">
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
<text class="empty-title">登录后查看订单</text>
<text class="empty-desc">预约状态、取消进度和服务记录都会展示在这里。</text>
<text class="empty-desc">登录后查看预约记录。</text>
<view class="ghost-btn" bindtap="handleOpenAuth">去登录</view>
</view>
@@ -12,7 +12,7 @@
<view class="page-hero orders-hero">
<text class="hero-kicker">预约记录</text>
<text class="hero-title">共 {{orders.length}} 笔订单</text>
<text class="hero-desc">这里展示每笔订单的状态、项目、预约时间以及取消入口。</text>
<text class="hero-desc">查看订单状态和预约时间。</text>
</view>
<view wx:for="{{orders}}" wx:key="id" class="page-card order-card">
@@ -25,7 +25,7 @@
</view>
<view wx:for="{{item.items}}" wx:key="id" wx:for-item="orderItem" class="order-item">
<image class="order-thumb" src="{{orderItem.productImageUrl}}" mode="aspectFill"></image>
<image class="order-thumb" src="{{orderItem.productImageUrl}}" mode="aspectFill" lazy-load="{{true}}"></image>
<view class="order-main">
<view class="order-title">{{orderItem.productTitle}}</view>
<view class="order-line">{{orderItem.priceText}} x {{orderItem.quantity}}</view>
@@ -47,7 +47,7 @@
<view wx:else class="page-card empty-card">
<text class="empty-title">你还没有订单</text>
<text class="empty-desc">选到喜欢的款式后,加入购物车即可发起预约。</text>
<text class="empty-desc">先去预约喜欢的款式。</text>
</view>
</view>
</view>
+60 -35
View File
@@ -3,6 +3,7 @@ const productApi = require('../../api/product')
const productLikeApi = require('../../api/product-like')
const shopApi = require('../../api/shop')
const wishlistApi = require('../../api/wishlist')
const actionGuard = require('../../utils/action-guard')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const { resolveImageList } = require('../../utils/file')
@@ -110,7 +111,7 @@ Page({
...product,
displayTitle: getProductTitle(product),
priceText: `¥${formatPrice(product.price)}`,
descriptionText: product.description || '店家还没有补充作品说明。'
descriptionText: product.description || '商家还没有补充作品说明。'
}
this.setData({
@@ -193,25 +194,32 @@ Page({
}
try {
const nextFavorite = !this.data.isFavorite
if (this.data.isFavorite) {
await runWithLoading(() => wishlistApi.removeFromWishlist(product.id))
product.collectCount = Math.max(0, Number(product.collectCount || 0) - 1)
} else {
await runWithLoading(() => wishlistApi.addToWishlist(product.id))
product.collectCount = Number(product.collectCount || 0) + 1
}
await actionGuard.run(this, `wishlist:toggle:${product.id}`, async () => {
const nextFavorite = !this.data.isFavorite
if (this.data.isFavorite) {
await runWithLoading(() => wishlistApi.removeFromWishlist(product.id))
product.collectCount = Math.max(0, Number(product.collectCount || 0) - 1)
} else {
await runWithLoading(() => wishlistApi.addToWishlist(product.id))
product.collectCount = Number(product.collectCount || 0) + 1
}
this.setData({
isFavorite: nextFavorite,
product
})
this.setData({
isFavorite: nextFavorite,
product
})
wx.showToast({
title: nextFavorite ? '已加入收藏' : '已取消收藏',
icon: 'none'
wx.showToast({
title: nextFavorite ? '已加入收藏' : '已取消收藏',
icon: 'none'
})
}, {
message: '操作进行中,请勿重复点击'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '收藏操作失败',
icon: 'none'
@@ -226,25 +234,32 @@ Page({
}
try {
const nextLiked = !this.data.isLiked
if (this.data.isLiked) {
await runWithLoading(() => productLikeApi.unlikeProduct(product.id))
product.likeCount = Math.max(0, Number(product.likeCount || 0) - 1)
} else {
await runWithLoading(() => productLikeApi.likeProduct(product.id))
product.likeCount = Number(product.likeCount || 0) + 1
}
await actionGuard.run(this, `like:toggle:${product.id}`, async () => {
const nextLiked = !this.data.isLiked
if (this.data.isLiked) {
await runWithLoading(() => productLikeApi.unlikeProduct(product.id))
product.likeCount = Math.max(0, Number(product.likeCount || 0) - 1)
} else {
await runWithLoading(() => productLikeApi.likeProduct(product.id))
product.likeCount = Number(product.likeCount || 0) + 1
}
this.setData({
isLiked: nextLiked,
product
})
this.setData({
isLiked: nextLiked,
product
})
wx.showToast({
title: nextLiked ? '已点赞' : '已取消点赞',
icon: 'none'
wx.showToast({
title: nextLiked ? '已点赞' : '已取消点赞',
icon: 'none'
})
}, {
message: '操作进行中,请勿重复点击'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '点赞操作失败',
icon: 'none'
@@ -259,16 +274,21 @@ Page({
}
try {
await runWithLoading(() => cartApi.addToCart({
await actionGuard.run(this, `cart:add:${product.id}`, () => runWithLoading(() => cartApi.addToCart({
productId: product.id,
quantity: 1
}))
})), {
message: '购物车处理中,请勿重复操作'
})
await getApp().updateCartBadge()
wx.showToast({
title: '已加入购物车',
icon: 'none'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '加入购物车失败',
icon: 'none'
@@ -283,15 +303,20 @@ Page({
}
try {
await runWithLoading(() => cartApi.addToCart({
await actionGuard.run(this, `cart:buy-now:${product.id}`, () => runWithLoading(() => cartApi.addToCart({
productId: product.id,
quantity: 1
}))
})), {
message: '操作进行中,请勿重复点击'
})
await getApp().updateCartBadge()
wx.switchTab({
url: '/pages/cart/index'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '操作失败',
icon: 'none'
@@ -13,7 +13,7 @@
<view class="media-box">
<swiper class="media-swiper" indicator-dots autoplay circular>
<swiper-item wx:for="{{productImages}}" wx:key="*this">
<image class="media-image" src="{{item}}" mode="aspectFill" data-url="{{item}}" bindtap="handlePreviewImage"></image>
<image class="media-image" src="{{item}}" mode="aspectFill" data-url="{{item}}" bindtap="handlePreviewImage" lazy-load="{{true}}"></image>
</swiper-item>
</swiper>
<view class="media-mask">
@@ -30,24 +30,24 @@
<text class="section-kicker">作品详情</text>
<view class="product-title">{{product.displayTitle}}</view>
<view class="product-price">{{product.priceText}}</view>
<view class="product-brief">适合先看作品风格、门店信息和可预约情况,再决定是否立即下单。</view>
<view class="product-brief">查看作品、门店和可预约信息。</view>
</view>
<view class="summary-strip detail-summary">
<view class="summary-metric" bindtap="handleOpenShop">
<text class="summary-label">所属门店</text>
<text class="summary-value detail-summary-value">{{shopInfo ? shopInfo.shopName : '待绑定'}}</text>
<text class="summary-note">点击查看门店详情</text>
<text class="summary-note">查看门店</text>
</view>
<view class="summary-metric">
<text class="summary-label">可约美甲师</text>
<text class="summary-value detail-summary-value">{{artistCountText}}</text>
<text class="summary-note">预约前可在购物车继续选择</text>
<text class="summary-note">可继续选择</text>
</view>
<view class="summary-metric">
<text class="summary-label">最早可约</text>
<text class="summary-value detail-summary-value">{{earliestBookableText}}</text>
<text class="summary-note">以门店营业时间为准</text>
<text class="summary-note">以营业时间为准</text>
</view>
</view>
+268 -54
View File
@@ -1,40 +1,68 @@
const auth = require('../../utils/auth')
const cache = require('../../utils/cache')
const tagApi = require('../../api/tag')
const productApi = require('../../api/product')
const cartApi = require('../../api/cart')
const actionGuard = require('../../utils/action-guard')
const { buildProductCards } = require('../../utils/product')
const navigation = require('../../utils/navigation')
const { runWithLoading } = require('../../utils/loading')
const { CACHE_TTL } = require('../../utils/config')
const ALL_CATEGORY = '\u5168\u90e8'
const FILTER_BUSY_MESSAGE = '\u7b5b\u9009\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
const CART_BUSY_MESSAGE = '\u8d2d\u7269\u8f66\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
Page({
data: {
initialized: false,
loading: false,
categories: ['全部'],
selectedCategory: '全部',
loadingMore: false,
categories: [ALL_CATEGORY],
selectedCategory: ALL_CATEGORY,
searchKeyword: '',
products: [],
activeBannerText: ''
filterSummaryText: '',
page: 1,
pageSize: 10,
total: 0,
hasMore: false
},
onLoad(options) {
this.filterRequestId = 0
this.bootstrapPage(options || {})
},
onShow() {
async onShow() {
const app = getApp()
const pendingFilter = app && app.globalData ? app.globalData.pendingProductFilter : null
if (this.data.initialized && pendingFilter && (pendingFilter.keyword || pendingFilter.tag)) {
if (app && app.globalData) {
app.globalData.pendingProductFilter = null
}
this.applyFilter(pendingFilter)
await this.applyFilter(pendingFilter)
return
}
if (this.data.initialized) {
await this.syncProductCartState()
}
},
async onPullDownRefresh() {
await this.loadProducts()
await this.loadProducts(true)
wx.stopPullDownRefresh()
},
onReachBottom() {
if (!this.data.hasMore || this.data.loadingMore) {
return
}
this.loadProducts(false)
},
async bootstrapPage(options) {
this.setData({
loading: true
@@ -48,7 +76,7 @@ Page({
})
} catch (error) {
wx.showToast({
title: error.message || '作品列表加载失败',
title: error.message || '\u4f5c\u54c1\u5217\u8868\u52a0\u8f7d\u5931\u8d25',
icon: 'none'
})
} finally {
@@ -59,10 +87,10 @@ Page({
},
async loadTags() {
const tags = await tagApi.getAllTags()
const tags = await cache.remember('tags:all', CACHE_TTL.tags, () => tagApi.getAllTags())
const names = Array.isArray(tags) ? tags.map(item => item.tagName).filter(Boolean) : []
this.setData({
categories: ['全部'].concat(names)
categories: [ALL_CATEGORY].concat(names)
})
},
@@ -81,56 +109,154 @@ Page({
},
async applyFilter(filter) {
const keyword = (filter.keyword || '').trim()
const tag = (filter.tag || '').trim()
const keyword = String(filter.keyword || '').trim()
const tag = String(filter.tag || '').trim()
this.setData({
searchKeyword: keyword,
selectedCategory: tag && this.data.categories.includes(tag) ? tag : '全部'
selectedCategory: tag && this.data.categories.includes(tag) ? tag : ALL_CATEGORY,
page: 1,
total: 0,
hasMore: false
})
await this.loadProducts()
await this.loadProducts(true)
},
async loadProducts() {
this.setData({
loading: true
})
async loadProducts(reset) {
const requestId = ++this.filterRequestId
const nextPage = reset ? 1 : this.data.page + 1
this.setData(reset ? { loading: true } : { loadingMore: true })
try {
let products = []
const keyword = this.data.searchKeyword.trim()
const tag = this.data.selectedCategory
if (keyword) {
products = await productApi.searchProducts(keyword)
} else if (tag !== '全部') {
products = await productApi.getProductsByTag(tag)
} else {
products = await productApi.getAllProducts()
const keyword = String(this.data.searchKeyword || '').trim()
const tag = this.data.selectedCategory === ALL_CATEGORY ? '' : this.data.selectedCategory
const result = await productApi.getProductPage({
page: nextPage,
size: this.data.pageSize,
keyword: keyword || undefined,
tag: tag || undefined
})
const cards = await buildProductCards(result && result.list ? result.list : [])
const displayCards = await this.attachCartState(cards)
if (requestId !== this.filterRequestId) {
return
}
const cards = await buildProductCards(products || [])
const merged = reset ? displayCards : this.data.products.concat(displayCards)
const total = Number(result && result.total) || 0
this.setData({
products: cards,
activeBannerText: keyword
? `正在显示“${keyword}”的搜索结果`
: (tag !== '全部' ? `当前按“${tag}”筛选` : '')
products: merged,
page: nextPage,
total,
hasMore: merged.length < total,
filterSummaryText: this.buildFilterSummary(keyword, tag, total)
})
} catch (error) {
this.setData({
products: [],
activeBannerText: ''
})
if (requestId !== this.filterRequestId) {
return
}
if (reset) {
this.setData({
products: [],
total: 0,
hasMore: false,
filterSummaryText: ''
})
}
wx.showToast({
title: error.message || '作品列表加载失败',
title: error.message || '\u4f5c\u54c1\u5217\u8868\u52a0\u8f7d\u5931\u8d25',
icon: 'none'
})
} finally {
this.setData({
loading: false
})
if (requestId === this.filterRequestId) {
this.setData({
loading: false,
loadingMore: false
})
}
}
},
buildFilterSummary(keyword, tag, total) {
const chips = []
if (tag) {
chips.push(tag)
}
if (keyword) {
chips.push(`\u641c\u7d22\uff1a${keyword}`)
}
chips.push(`\u5171 ${Number(total || 0)} \u4e2a`)
return chips.join(' \u00b7 ')
},
normalizeId(value) {
return value === undefined || value === null ? '' : String(value)
},
async fetchCartProductIdSet() {
if (!auth.isLoggedIn()) {
this.cartProductIdSet = new Set()
return this.cartProductIdSet
}
try {
const cartList = await cartApi.getCartList()
const idSet = new Set(
(Array.isArray(cartList) ? cartList : [])
.map(item => this.normalizeId(item && item.productId))
.filter(Boolean)
)
this.cartProductIdSet = idSet
return idSet
} catch (error) {
this.cartProductIdSet = new Set()
return this.cartProductIdSet
}
},
async attachCartState(cards) {
const idSet = await this.fetchCartProductIdSet()
return this.markCardsInCart(cards, idSet)
},
markCardsInCart(cards, idSet) {
const productIdSet = idSet || new Set()
return (Array.isArray(cards) ? cards : []).map(item => ({
...item,
inCart: productIdSet.has(this.normalizeId(item && item.id))
}))
},
async syncProductCartState() {
const idSet = await this.fetchCartProductIdSet()
this.setData({
products: this.markCardsInCart(this.data.products, idSet)
})
},
markProductInCart(productId) {
const normalizedId = this.normalizeId(productId)
if (!normalizedId) {
return
}
this.cartProductIdSet = this.cartProductIdSet || new Set()
this.cartProductIdSet.add(normalizedId)
this.setData({
products: this.data.products.map(item => (
this.normalizeId(item && item.id) === normalizedId
? {
...item,
inCart: true
}
: item
))
})
},
handleSearchInput(event) {
this.setData({
searchKeyword: event.detail.value
@@ -138,27 +264,72 @@ Page({
},
async handleSearchConfirm() {
this.setData({
selectedCategory: '全部'
})
await runWithLoading(() => this.loadProducts())
try {
await actionGuard.run(this, 'products:search', async () => {
this.setData({
selectedCategory: ALL_CATEGORY,
page: 1
})
await runWithLoading(() => this.loadProducts(true))
}, {
message: FILTER_BUSY_MESSAGE
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '\u7b5b\u9009\u5931\u8d25',
icon: 'none'
})
}
},
async handleSelectCategory(event) {
const category = event.currentTarget.dataset.category
this.setData({
selectedCategory: category,
searchKeyword: ''
})
await runWithLoading(() => this.loadProducts())
try {
await actionGuard.run(this, `products:category:${category}`, async () => {
this.setData({
selectedCategory: category,
searchKeyword: '',
page: 1
})
await runWithLoading(() => this.loadProducts(true))
}, {
message: FILTER_BUSY_MESSAGE
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '\u7b5b\u9009\u5931\u8d25',
icon: 'none'
})
}
},
async handleResetFilters() {
this.setData({
selectedCategory: '全部',
searchKeyword: ''
})
await runWithLoading(() => this.loadProducts())
try {
await actionGuard.run(this, 'products:reset', async () => {
this.setData({
selectedCategory: ALL_CATEGORY,
searchKeyword: '',
page: 1
})
await runWithLoading(() => this.loadProducts(true))
}, {
message: FILTER_BUSY_MESSAGE
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '\u7b5b\u9009\u5931\u8d25',
icon: 'none'
})
}
},
handleProductSelect(event) {
@@ -170,5 +341,48 @@ Page({
navigation.navigate('/pages/product-detail/index', {
id: product.id
})
},
async handleQuickAdd(event) {
const product = event.detail || {}
const productId = this.normalizeId(product.id)
if (!productId) {
return
}
if (!navigation.ensureLogin('\u52a0\u5165\u8d2d\u7269\u8f66')) {
return
}
if (this.cartProductIdSet && this.cartProductIdSet.has(productId)) {
wx.showToast({
title: '\u8d2d\u7269\u8f66\u5df2\u6709',
icon: 'none'
})
return
}
try {
await actionGuard.run(this, `cart:add:${productId}`, () => runWithLoading(() => cartApi.addToCart({
productId,
quantity: 1
})), {
message: CART_BUSY_MESSAGE
})
this.markProductInCart(productId)
await getApp().updateCartBadge()
wx.showToast({
title: '\u5df2\u52a0\u5165\u8d2d\u7269\u8f66',
icon: 'none'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '\u52a0\u5165\u8d2d\u7269\u8f66\u5931\u8d25',
icon: 'none'
})
}
}
})
+25 -18
View File
@@ -1,17 +1,13 @@
<navigation-bar title="作品库" back="{{false}}" color="#2d2430" background="#fff7f8"></navigation-bar>
<view class="page-shell product-page">
<view class="page-content">
<view class="page-hero product-hero">
<text class="hero-kicker">作品筛选</text>
<text class="hero-title">{{selectedCategory !== '全部' ? selectedCategory : '找到适合你的美甲款式'}}</text>
<text class="hero-desc">{{activeBannerText ? activeBannerText : '按标签筛选或输入关键词搜索,先缩小范围,再挑喜欢的作品。'}}</text>
<view class="search-card">
<view class="page-content product-page-content">
<view class="sticky-filter-bar">
<view class="filter-surface">
<view class="search-row">
<input
class="search-input"
placeholder="搜索作品名称或关键词"
placeholder="搜索标题、标签或描述"
placeholder-class="field-placeholder"
value="{{searchKeyword}}"
bindinput="handleSearchInput"
@@ -21,7 +17,7 @@
<view class="search-btn" bindtap="handleSearchConfirm">搜索</view>
</view>
<scroll-view class="category-scroll" scroll-x enable-flex>
<scroll-view class="category-scroll" scroll-x enable-flex show-scrollbar="false">
<view class="category-list">
<view
wx:for="{{categories}}"
@@ -34,21 +30,32 @@
</view>
</view>
</scroll-view>
<view class="results-head">
<view class="results-meta">
<view class="results-count">{{products.length ? products.length : 0}} 个</view>
<view wx:if="{{filterSummaryText}}" class="filter-summary-chip">{{filterSummaryText}}</view>
</view>
<view wx:if="{{searchKeyword || selectedCategory !== '全部'}}" class="ghost-btn results-reset" bindtap="handleResetFilters">重置</view>
</view>
</view>
</view>
<view class="results-head">
<view class="results-count">{{products.length ? products.length : 0}} 个结果</view>
<view wx:if="{{searchKeyword || selectedCategory !== '全部'}}" class="ghost-btn results-reset" bindtap="handleResetFilters">重置筛选</view>
</view>
<view wx:if="{{activeBannerText}}" class="filter-banner">{{activeBannerText}}</view>
<view wx:if="{{products.length}}" class="product-grid">
<view wx:for="{{products}}" wx:key="id" class="product-grid-item">
<product-card item="{{item}}" show-stats="{{true}}" bindselect="handleProductSelect"></product-card>
<product-card
item="{{item}}"
show-stats="{{true}}"
show-quick-add="{{true}}"
in-cart="{{item.inCart}}"
bindselect="handleProductSelect"
bindquickadd="handleQuickAdd"
></product-card>
</view>
</view>
<view wx:if="{{products.length && (loadingMore || !hasMore)}}" class="load-state">
<text class="load-state-text">{{loadingMore ? '正在加载更多作品...' : '已经到底了'}}</text>
</view>
<view wx:elif="{{loading}}" class="page-card empty-card">
<text class="empty-title">正在加载作品</text>
@@ -56,7 +63,7 @@
<view wx:else class="page-card empty-card">
<text class="empty-title">暂时没有匹配的作品</text>
<text class="empty-desc">可以换个关键词试试,或者先浏览全部作品。</text>
<text class="empty-desc">换个关键词试试。</text>
<view class="ghost-btn" bindtap="handleResetFilters">查看全部</view>
</view>
</view>
+82 -43
View File
@@ -4,64 +4,71 @@
linear-gradient(180deg, #fff8fa 0%, #fffdfc 100%);
}
.product-hero {
background:
radial-gradient(circle at top right, rgba(255, 194, 211, 0.42), transparent 34%),
linear-gradient(145deg, #fffdfd 0%, #fff3f7 56%, #ffe7ef 100%);
.product-page-content {
padding-top: 10rpx;
}
.search-card {
margin-top: 28rpx;
display: flex;
flex-direction: column;
gap: 24rpx;
padding: 22rpx 22rpx 24rpx;
border-radius: 28rpx;
background: rgba(255, 255, 255, 0.78);
.sticky-filter-bar {
position: sticky;
top: 0;
z-index: 12;
padding: 6rpx 0 16rpx;
background:
linear-gradient(180deg, rgba(255, 248, 250, 0.98) 0%, rgba(255, 252, 251, 0.94) 76%, rgba(255, 252, 251, 0) 100%);
}
.filter-surface {
padding: 16rpx 16rpx 14rpx;
border-radius: 24rpx;
border: 1rpx solid rgba(239, 216, 224, 0.86);
background: rgba(255, 255, 255, 0.92);
box-shadow: 0 18rpx 40rpx rgba(122, 67, 88, 0.08);
}
.search-row {
display: flex;
align-items: center;
gap: 14rpx;
gap: 12rpx;
}
.search-input {
flex: 1;
height: 76rpx;
padding: 0 24rpx;
height: 68rpx;
padding: 0 22rpx;
border-radius: 999rpx;
background: #fbf5f7;
color: #2d2430;
font-size: 28rpx;
font-size: 26rpx;
}
.search-btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 132rpx;
height: 76rpx;
min-width: 112rpx;
height: 68rpx;
padding: 0 28rpx;
border-radius: 999rpx;
background: linear-gradient(135deg, #ff8cb0 0%, #c6597d 100%);
color: #ffffff;
font-size: 26rpx;
font-size: 24rpx;
font-weight: 700;
}
.category-scroll {
margin-top: 14rpx;
width: 100%;
height: 68rpx;
min-height: 68rpx;
height: 56rpx;
min-height: 56rpx;
white-space: nowrap;
}
.category-list {
display: inline-flex;
align-items: center;
gap: 16rpx;
min-height: 68rpx;
padding-right: 8rpx;
gap: 12rpx;
min-height: 56rpx;
padding-right: 4rpx;
}
.category-item {
@@ -69,13 +76,13 @@
align-items: center;
justify-content: center;
flex-shrink: 0;
min-width: 120rpx;
height: 60rpx;
padding: 0 22rpx;
min-width: 88rpx;
height: 50rpx;
padding: 0 20rpx;
border-radius: 999rpx;
background: #f7edf1;
color: #8d7a84;
font-size: 24rpx;
font-size: 22rpx;
font-weight: 600;
}
@@ -88,37 +95,69 @@
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
margin-top: 24rpx;
gap: 12rpx;
margin-top: 14rpx;
}
.results-meta {
display: flex;
align-items: center;
gap: 12rpx;
min-width: 0;
}
.results-count {
font-size: 26rpx;
flex-shrink: 0;
font-size: 24rpx;
font-weight: 700;
color: #5d4b55;
}
.results-reset {
.filter-summary-chip {
display: inline-flex;
align-items: center;
min-width: 0;
max-width: 360rpx;
height: 46rpx;
padding: 0 18rpx;
border-radius: 999rpx;
background: #fdeff4;
color: #c6597d;
font-size: 22rpx;
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.filter-banner {
margin-top: 20rpx;
padding: 20rpx 24rpx;
border-radius: 22rpx;
background: #fff1f5;
color: #b45172;
font-size: 24rpx;
line-height: 1.7;
.results-reset {
flex-shrink: 0;
height: 52rpx;
padding: 0 20rpx;
min-width: 0;
font-size: 22rpx;
}
.product-grid {
display: flex;
flex-wrap: wrap;
gap: 18rpx;
margin-top: 24rpx;
gap: 14rpx;
margin-top: 18rpx;
}
.product-grid-item {
width: calc(50% - 9rpx);
min-width: 0;
width: calc(50% - 7rpx);
}
.load-state {
display: flex;
align-items: center;
justify-content: center;
padding: 20rpx 0 10rpx;
}
.load-state-text {
font-size: 22rpx;
color: #8d7a84;
}
+97 -44
View File
@@ -3,6 +3,7 @@ const couponApi = require('../../api/coupon')
const orderApi = require('../../api/order')
const userApi = require('../../api/user')
const wishlistApi = require('../../api/wishlist')
const actionGuard = require('../../utils/action-guard')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const { DEFAULT_AVATAR } = require('../../utils/config')
@@ -25,6 +26,7 @@ Page({
},
async loadProfile() {
this._avatarReloadSource = ''
const isLoggedIn = auth.isLoggedIn()
this.setData({
isLoggedIn,
@@ -60,7 +62,7 @@ Page({
})
} catch (error) {
wx.showToast({
title: error.message || '个人中心加载失败',
title: error.message || '\u4e2a\u4eba\u4e2d\u5fc3\u52a0\u8f7d\u5931\u8d25',
icon: 'none'
})
} finally {
@@ -83,28 +85,28 @@ Page({
},
handleOpenOrders() {
if (!navigation.ensureLogin('查看订单')) {
if (!navigation.ensureLogin('\u67e5\u770b\u8ba2\u5355')) {
return
}
navigation.navigate('/pages/orders/index')
},
handleOpenWishlist() {
if (!navigation.ensureLogin('查看收藏')) {
if (!navigation.ensureLogin('\u67e5\u770b\u6536\u85cf')) {
return
}
navigation.navigate('/pages/wishlist/index')
},
handleOpenCoupons() {
if (!navigation.ensureLogin('查看优惠券')) {
if (!navigation.ensureLogin('\u67e5\u770b\u4f18\u60e0\u5238')) {
return
}
navigation.navigate('/pages/coupons/index')
},
async handleSwitchShop() {
if (!navigation.ensureLogin('切换门店')) {
if (!navigation.ensureLogin('\u5207\u6362\u95e8\u5e97')) {
return
}
@@ -114,7 +116,7 @@ Page({
if (!shopIds.length) {
wx.showToast({
title: '当前账号还没有可用门店',
title: '\u5f53\u524d\u8d26\u53f7\u8fd8\u6ca1\u6709\u53ef\u7528\u95e8\u5e97',
icon: 'none'
})
return
@@ -128,31 +130,38 @@ Page({
return
}
const selection = await new Promise(resolve => {
wx.showActionSheet({
itemList: shopNames.map((name, index) => name || `门店 ${shopIds[index]}`),
success: res => resolve(res.tapIndex),
fail: () => resolve(-1)
})
})
if (selection < 0 || selection >= shopIds.length) {
return
}
try {
const payload = await runWithLoading(() => authApi.switchShop({
shopId: shopIds[selection]
}))
getApp().setUserSession(payload)
wx.showToast({
title: '门店已切换',
icon: 'none'
await actionGuard.run(this, 'user:switch-shop', async () => {
const selection = await new Promise(resolve => {
wx.showActionSheet({
itemList: shopNames.map((name, index) => name || `\u95e8\u5e97 ${shopIds[index]}`),
success: res => resolve(res.tapIndex),
fail: () => resolve(-1)
})
})
if (selection < 0 || selection >= shopIds.length) {
return
}
const payload = await runWithLoading(() => authApi.switchShop({
shopId: shopIds[selection]
}))
getApp().setUserSession(payload)
wx.showToast({
title: '\u95e8\u5e97\u5df2\u5207\u6362',
icon: 'none'
})
await this.loadProfile()
}, {
message: '\u95e8\u5e97\u5207\u6362\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
})
this.loadProfile()
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '门店切换失败',
title: error.message || '\u95e8\u5e97\u5207\u6362\u5931\u8d25',
icon: 'none'
})
}
@@ -164,27 +173,71 @@ Page({
return
}
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '退出登录',
content: '退出后需要重新登录才能查看订单和继续下单。',
success: res => resolve(Boolean(res.confirm))
})
})
try {
await actionGuard.run(this, 'auth:logout', async () => {
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '\u9000\u51fa\u767b\u5f55',
content: '\u9000\u51fa\u540e\u9700\u8981\u91cd\u65b0\u767b\u5f55\u624d\u80fd\u67e5\u770b\u8ba2\u5355\u548c\u7ee7\u7eed\u4e0b\u5355\u3002',
success: res => resolve(Boolean(res.confirm))
})
})
if (!confirmed) {
if (!confirmed) {
return
}
try {
await runWithLoading(() => authApi.logout())
} catch (error) {}
getApp().clearUserSession()
await this.loadProfile()
wx.showToast({
title: '\u5df2\u9000\u51fa\u767b\u5f55',
icon: 'none'
})
}, {
message: '\u9000\u51fa\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
})
} catch (error) {
if (!actionGuard.isGuardError(error)) {
throw error
}
}
},
async handleAvatarError() {
const currentAvatar = this.data.userInfo && this.data.userInfo.avatar
if (!currentAvatar) {
return
}
try {
await runWithLoading(() => authApi.logout())
} catch (error) {}
if (this._avatarReloadSource === currentAvatar) {
this.setData({
'userInfo.avatar': ''
})
return
}
getApp().clearUserSession()
await this.loadProfile()
wx.showToast({
title: '已退出登录',
icon: 'none'
})
this._avatarReloadSource = currentAvatar
try {
const userInfo = await userApi.getUserInfo()
getApp().refreshUserInfo(userInfo)
if (!userInfo || !userInfo.avatar || userInfo.avatar === currentAvatar) {
this.setData({
'userInfo.avatar': ''
})
return
}
this.setData({
userInfo
})
} catch (error) {
this.setData({
'userInfo.avatar': ''
})
}
}
})
+5 -9
View File
@@ -6,16 +6,16 @@
<view class="page-shell profile-page">
<view class="page-content profile-content">
<view wx:if="{{!isLoggedIn}}" class="page-card guest-card">
<image class="guest-avatar" src="{{defaultAvatar}}" mode="aspectFill"></image>
<image class="guest-avatar" src="{{defaultAvatar}}" mode="aspectFill" lazy-load="{{true}}"></image>
<view class="guest-title">还没有登录账号</view>
<view class="guest-desc">登录后可以查看订单、收藏作品、领取和使用优惠。</view>
<view class="guest-desc">登录后查看订单、收藏和优惠券。</view>
<view class="primary-btn" bindtap="handleOpenAuth">去登录</view>
</view>
<block wx:elif="{{userInfo}}">
<view class="page-card profile-card">
<view class="profile-top">
<image class="avatar" src="{{userInfo.avatar || defaultAvatar}}" mode="aspectFill"></image>
<image class="avatar" src="{{userInfo.avatar || defaultAvatar}}" mode="aspectFill" lazy-load="{{true}}" binderror="handleAvatarError"></image>
<view class="profile-copy">
<view class="nickname">{{userInfo.nickname || 'Yumi 用户'}}</view>
<view class="account">{{userInfo.account}}</view>
@@ -27,17 +27,14 @@
<view class="summary-metric" bindtap="handleOpenOrders">
<text class="summary-label">订单</text>
<text class="summary-value">{{orderCount}}</text>
<text class="summary-note">查看预约记录</text>
</view>
<view class="summary-metric" bindtap="handleOpenWishlist">
<text class="summary-label">收藏</text>
<text class="summary-value">{{wishlistCount}}</text>
<text class="summary-note">回看喜欢的作品</text>
</view>
<view class="summary-metric" bindtap="handleOpenCoupons">
<text class="summary-label">优惠券</text>
<text class="summary-value">{{couponCount}}</text>
<text class="summary-note">结算前可直接使用</text>
</view>
</view>
@@ -50,15 +47,14 @@
</view>
<view wx:if="{{needSetPassword}}" class="password-tip">
建议尽快补充登录密码,之后切换设备会更方便。
建议尽快设置登录密码。
</view>
<view class="secondary-btn edit-btn" bindtap="handleOpenSettings">编辑资料与设置</view>
<view class="secondary-btn edit-btn" bindtap="handleOpenSettings">资料与设置</view>
</view>
<view class="page-card menu-card">
<view class="section-title">常用入口</view>
<view class="section-subtitle">订单、收藏、优惠券和账号设置都集中在这里。</view>
<view class="menu-item" bindtap="handleOpenOrders">
<text>我的订单</text>
<text class="menu-arrow">></text>
+601 -31
View File
@@ -3,24 +3,74 @@ const userApi = require('../../api/user')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const { DEFAULT_AVATAR } = require('../../utils/config')
const { getDraftValue, clearDraft, scheduleDraftSave, clearDraftTimer } = require('../../utils/form-draft')
const { runWithLoading } = require('../../utils/loading')
const phoneRegex = /^1[3-9]\d{9}$/
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/
const SETTINGS_DRAFT_KEY = 'user-settings'
const placeholderEntries = [
{
key: 'notifications',
title: '消息通知'
},
{
key: 'message-push',
title: '消息推送'
},
{
key: 'theme',
title: '主题设置'
},
{
key: 'privacy',
title: '隐私政策'
},
{
key: 'about',
title: '关于我们'
},
{
key: 'help',
title: '帮助中心'
},
{
key: 'clear-cache',
title: '缓存清理'
}
]
Page({
data: {
isLoggedIn: false,
loading: false,
savingProfile: false,
uploadingAvatar: false,
updatingPhone: false,
updatingPassword: false,
deactivating: false,
countdown: 0,
needSetPassword: false,
activeSecurityPanel: '',
userInfo: null,
defaultAvatar: DEFAULT_AVATAR,
placeholderEntries,
form: {
nickname: '',
signature: ''
},
bindPhoneForm: {
phone: '',
verificationCode: ''
},
changePhoneForm: {
newPhone: '',
verificationCode: ''
},
passwordForm: {
verificationCode: '',
password: ''
password: '',
confirmPassword: ''
}
},
@@ -28,16 +78,107 @@ Page({
this.loadSettings()
},
onHide() {
this.clearCountdown()
clearDraftTimer(this)
},
onUnload() {
this.clearCountdown()
clearDraftTimer(this)
},
clearCountdown() {
if (this.countdownTimer) {
clearInterval(this.countdownTimer)
this.countdownTimer = null
}
},
resetSecurityForms() {
this.setData({
bindPhoneForm: {
phone: '',
verificationCode: ''
},
changePhoneForm: {
newPhone: '',
verificationCode: ''
},
passwordForm: {
verificationCode: '',
password: '',
confirmPassword: ''
}
})
},
restoreDraftValues() {
const draft = getDraftValue(SETTINGS_DRAFT_KEY, null)
if (!draft || typeof draft !== 'object') {
return
}
this.setData({
activeSecurityPanel: draft.activeSecurityPanel || '',
'form.nickname': draft.form && draft.form.nickname !== undefined ? draft.form.nickname : this.data.form.nickname,
'form.signature': draft.form && draft.form.signature !== undefined ? draft.form.signature : this.data.form.signature,
'bindPhoneForm.phone': draft.bindPhoneForm && draft.bindPhoneForm.phone ? draft.bindPhoneForm.phone : '',
'changePhoneForm.newPhone': draft.changePhoneForm && draft.changePhoneForm.newPhone ? draft.changePhoneForm.newPhone : ''
})
},
scheduleSettingsDraft() {
scheduleDraftSave(this, SETTINGS_DRAFT_KEY, () => ({
activeSecurityPanel: this.data.activeSecurityPanel,
form: {
nickname: this.data.form.nickname,
signature: this.data.form.signature
},
bindPhoneForm: {
phone: this.data.bindPhoneForm.phone
},
changePhoneForm: {
newPhone: this.data.changePhoneForm.newPhone
}
}))
},
startCountdown() {
this.clearCountdown()
this.setData({
countdown: 60
})
this.countdownTimer = setInterval(() => {
const next = this.data.countdown - 1
if (next <= 0) {
this.clearCountdown()
this.setData({
countdown: 0
})
return
}
this.setData({
countdown: next
})
}, 1000)
},
async loadSettings() {
this._avatarReloadSource = ''
const isLoggedIn = auth.isLoggedIn()
this.setData({
isLoggedIn,
needSetPassword: auth.getNeedSetPassword(),
loading: isLoggedIn
})
if (!isLoggedIn) {
this.clearCountdown()
this.setData({
userInfo: null,
activeSecurityPanel: '',
loading: false
})
return
@@ -49,8 +190,10 @@ Page({
this.setData({
userInfo,
'form.nickname': userInfo.nickname || '',
'form.signature': userInfo.signature || ''
'form.signature': userInfo.signature || '',
needSetPassword: auth.getNeedSetPassword()
})
this.restoreDraftValues()
} catch (error) {
wx.showToast({
title: error.message || '设置页加载失败',
@@ -76,6 +219,27 @@ Page({
this.setData({
[`form.${field}`]: event.detail.value
})
this.scheduleSettingsDraft()
},
handleBindPhoneInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`bindPhoneForm.${field}`]: event.detail.value
})
if (field === 'phone') {
this.scheduleSettingsDraft()
}
},
handleChangePhoneInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`changePhoneForm.${field}`]: event.detail.value
})
if (field === 'newPhone') {
this.scheduleSettingsDraft()
}
},
handlePasswordInput(event) {
@@ -85,6 +249,28 @@ Page({
})
},
handleToggleSecurityPanel(event) {
const panel = event.currentTarget.dataset.panel
const nextPanel = this.data.activeSecurityPanel === panel ? '' : panel
this.clearCountdown()
this.resetSecurityForms()
this.setData({
activeSecurityPanel: nextPanel,
countdown: 0
})
this.scheduleSettingsDraft()
},
handleCloseSecurityPanel() {
this.resetSecurityForms()
this.clearCountdown()
this.setData({
activeSecurityPanel: '',
countdown: 0
})
this.scheduleSettingsDraft()
},
async handleSaveProfile() {
if (!this.data.form.nickname.trim()) {
wx.showToast({
@@ -107,7 +293,8 @@ Page({
title: '资料已更新',
icon: 'none'
})
this.loadSettings()
clearDraft(SETTINGS_DRAFT_KEY)
await this.loadSettings()
} catch (error) {
wx.showToast({
title: error.message || '资料更新失败',
@@ -120,20 +307,298 @@ Page({
}
},
startCountdown() {
this.setData({
countdown: 60
handleChooseAvatar() {
if (this.data.uploadingAvatar) {
return
}
wx.chooseImage({
count: 1,
sizeType: ['compressed', 'original'],
sourceType: ['album', 'camera'],
success: async res => {
const filePath = Array.isArray(res.tempFilePaths) ? res.tempFilePaths[0] : ''
if (!filePath) {
return
}
this.setData({
uploadingAvatar: true
})
try {
await runWithLoading(() => userApi.uploadAvatar(filePath))
wx.showToast({
title: '头像已更新',
icon: 'none'
})
await this.loadSettings()
} catch (error) {
wx.showToast({
title: error.message || '头像上传失败',
icon: 'none'
})
} finally {
this.setData({
uploadingAvatar: false
})
}
}
})
},
async handleDeleteAvatar() {
if (!this.data.userInfo || !this.data.userInfo.avatar) {
return
}
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '删除头像',
content: '删除后会恢复为默认头像。',
success: res => resolve(Boolean(res.confirm))
})
})
const timer = setInterval(() => {
const next = this.data.countdown - 1
this.setData({
countdown: next
if (!confirmed) {
return
}
try {
await runWithLoading(() => userApi.updateUserInfo({
avatar: ''
}))
wx.showToast({
title: '头像已删除',
icon: 'none'
})
if (next <= 0) {
clearInterval(timer)
}
}, 1000)
await this.loadSettings()
} catch (error) {
wx.showToast({
title: error.message || '头像删除失败',
icon: 'none'
})
}
},
async handleSwitchShop() {
if (!navigation.ensureLogin('查看门店')) {
return
}
const userInfo = this.data.userInfo
const shopIds = userInfo && Array.isArray(userInfo.shopIds) ? userInfo.shopIds : []
const shopNames = userInfo && Array.isArray(userInfo.shopNames) ? userInfo.shopNames : []
if (!shopIds.length) {
wx.showToast({
title: '当前账号还没有可用门店',
icon: 'none'
})
return
}
if (shopIds.length === 1) {
navigation.navigate('/pages/shop-detail/index', {
id: shopIds[0],
returnTo: navigation.getCurrentPageUrl()
})
return
}
const selection = await new Promise(resolve => {
wx.showActionSheet({
itemList: shopNames.map((name, index) => name || `门店 ${shopIds[index]}`),
success: res => resolve(res.tapIndex),
fail: () => resolve(-1)
})
})
if (selection < 0 || selection >= shopIds.length) {
return
}
try {
const payload = await runWithLoading(() => authApi.switchShop({
shopId: shopIds[selection]
}))
getApp().setUserSession(payload)
wx.showToast({
title: '门店已切换',
icon: 'none'
})
await this.loadSettings()
} catch (error) {
wx.showToast({
title: error.message || '门店切换失败',
icon: 'none'
})
}
},
async handleSendBindPhoneCode() {
if (this.data.countdown > 0) {
return
}
const phone = String(this.data.bindPhoneForm.phone || '').trim()
if (!phoneRegex.test(phone)) {
wx.showToast({
title: '请输入正确的手机号',
icon: 'none'
})
return
}
try {
await runWithLoading(() => userApi.sendVerificationCode({ phone }))
wx.showToast({
title: '验证码已发送',
icon: 'none'
})
this.startCountdown()
} catch (error) {
wx.showToast({
title: error.message || '验证码发送失败',
icon: 'none'
})
}
},
async handleBindPhoneSubmit() {
const phone = String(this.data.bindPhoneForm.phone || '').trim()
const verificationCode = String(this.data.bindPhoneForm.verificationCode || '').trim()
if (!phoneRegex.test(phone)) {
wx.showToast({
title: '请输入正确的手机号',
icon: 'none'
})
return
}
if (!verificationCode) {
wx.showToast({
title: '请输入验证码',
icon: 'none'
})
return
}
this.setData({
updatingPhone: true
})
try {
await runWithLoading(() => userApi.bindPhone({
phone,
verificationCode
}))
wx.showToast({
title: '手机号绑定成功',
icon: 'none'
})
this.handleCloseSecurityPanel()
clearDraft(SETTINGS_DRAFT_KEY)
await this.loadSettings()
} catch (error) {
wx.showToast({
title: error.message || '手机号绑定失败',
icon: 'none'
})
} finally {
this.setData({
updatingPhone: false
})
}
},
async handleSendChangePhoneCode() {
if (this.data.countdown > 0) {
return
}
const newPhone = String(this.data.changePhoneForm.newPhone || '').trim()
if (!phoneRegex.test(newPhone)) {
wx.showToast({
title: '请输入正确的新手机号',
icon: 'none'
})
return
}
try {
await runWithLoading(() => userApi.sendVerificationCode({ phone: newPhone }))
wx.showToast({
title: '验证码已发送',
icon: 'none'
})
this.startCountdown()
} catch (error) {
wx.showToast({
title: error.message || '验证码发送失败',
icon: 'none'
})
}
},
async handleChangePhoneSubmit() {
const userInfo = this.data.userInfo || {}
const oldPhone = String(userInfo.phone || '').trim()
const newPhone = String(this.data.changePhoneForm.newPhone || '').trim()
const verificationCode = String(this.data.changePhoneForm.verificationCode || '').trim()
if (!oldPhone) {
wx.showToast({
title: '请先绑定手机号',
icon: 'none'
})
return
}
if (!phoneRegex.test(newPhone)) {
wx.showToast({
title: '请输入正确的新手机号',
icon: 'none'
})
return
}
if (!verificationCode) {
wx.showToast({
title: '请输入验证码',
icon: 'none'
})
return
}
this.setData({
updatingPhone: true
})
try {
await runWithLoading(() => userApi.updatePhone({
oldPhone,
newPhone,
verificationCode
}))
wx.showToast({
title: '手机号修改成功',
icon: 'none'
})
this.handleCloseSecurityPanel()
clearDraft(SETTINGS_DRAFT_KEY)
await this.loadSettings()
} catch (error) {
wx.showToast({
title: error.message || '手机号修改失败',
icon: 'none'
})
} finally {
this.setData({
updatingPhone: false
})
}
},
async handleSendPasswordCode() {
@@ -141,19 +606,18 @@ Page({
return
}
const userInfo = this.data.userInfo
if (!userInfo || !userInfo.phone) {
const userInfo = this.data.userInfo || {}
const phone = String(userInfo.phone || '').trim()
if (!phone) {
wx.showToast({
title: '当前账号未绑定手机号',
title: '请先绑定手机号',
icon: 'none'
})
return
}
try {
await runWithLoading(() => authApi.sendVerificationCode({
phone: userInfo.phone
}))
await runWithLoading(() => authApi.sendVerificationCode({ phone }))
wx.showToast({
title: '验证码已发送',
icon: 'none'
@@ -168,16 +632,38 @@ Page({
},
async handleUpdatePassword() {
if (!this.data.passwordForm.verificationCode.trim()) {
const verificationCode = String(this.data.passwordForm.verificationCode || '').trim()
const password = String(this.data.passwordForm.password || '')
const confirmPassword = String(this.data.passwordForm.confirmPassword || '')
const userInfo = this.data.userInfo || {}
if (!userInfo.phone) {
wx.showToast({
title: '请先绑定手机号',
icon: 'none'
})
return
}
if (!verificationCode) {
wx.showToast({
title: '请输入验证码',
icon: 'none'
})
return
}
if (!this.data.passwordForm.password || this.data.passwordForm.password.length < 6) {
if (!passwordRegex.test(password)) {
wx.showToast({
title: '新密码至少 6 位',
title: '密码需至少8位且包含字母和数字',
icon: 'none'
})
return
}
if (password !== confirmPassword) {
wx.showToast({
title: '两次输入的密码不一致',
icon: 'none'
})
return
@@ -189,20 +675,17 @@ Page({
try {
await runWithLoading(() => userApi.updatePassword({
password: this.data.passwordForm.password,
verificationCode: this.data.passwordForm.verificationCode.trim()
password,
verificationCode
}))
auth.setNeedSetPassword(false)
wx.showToast({
title: '密码已更新',
icon: 'none'
})
this.setData({
passwordForm: {
verificationCode: '',
password: ''
}
})
this.handleCloseSecurityPanel()
clearDraft(SETTINGS_DRAFT_KEY)
await this.loadSettings()
} catch (error) {
wx.showToast({
title: error.message || '密码更新失败',
@@ -215,6 +698,58 @@ Page({
}
},
handleComingSoon() {
wx.showToast({
title: '该功能暂未开放',
icon: 'none'
})
},
async handleDeactivateAccount() {
if (this.data.deactivating) {
return
}
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '注销账号',
content: '注销后当前账号将不可继续登录,请确认是否继续。',
confirmColor: '#d5536f',
success: res => resolve(Boolean(res.confirm))
})
})
if (!confirmed) {
return
}
this.setData({
deactivating: true
})
try {
await runWithLoading(() => userApi.deactivateAccount())
clearDraft(SETTINGS_DRAFT_KEY)
getApp().clearUserSession()
wx.showToast({
title: '账号已注销',
icon: 'none'
})
wx.switchTab({
url: '/pages/home/index'
})
} catch (error) {
wx.showToast({
title: error.message || '账号注销失败',
icon: 'none'
})
} finally {
this.setData({
deactivating: false
})
}
},
async handleLogout() {
const confirmed = await new Promise(resolve => {
wx.showModal({
@@ -232,6 +767,7 @@ Page({
await runWithLoading(() => authApi.logout())
} catch (error) {}
clearDraft(SETTINGS_DRAFT_KEY)
getApp().clearUserSession()
wx.showToast({
title: '已退出登录',
@@ -240,5 +776,39 @@ Page({
wx.switchTab({
url: '/pages/home/index'
})
},
async handleAvatarError() {
const currentAvatar = this.data.userInfo && this.data.userInfo.avatar
if (!currentAvatar) {
return
}
if (this._avatarReloadSource === currentAvatar) {
this.setData({
'userInfo.avatar': ''
})
return
}
this._avatarReloadSource = currentAvatar
try {
const userInfo = await userApi.getUserInfo()
getApp().refreshUserInfo(userInfo)
if (!userInfo || !userInfo.avatar || userInfo.avatar === currentAvatar) {
this.setData({
'userInfo.avatar': ''
})
return
}
this.setData({
userInfo
})
} catch (error) {
this.setData({
'userInfo.avatar': ''
})
}
}
})
+131 -18
View File
@@ -6,27 +6,37 @@
<view class="page-content">
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
<text class="empty-title">登录后进入设置中心</text>
<text class="empty-desc">这里可以修改昵称、个性签名和登录密码。</text>
<text class="empty-desc">登录后管理资料和安全设置。</text>
<view class="ghost-btn" bindtap="handleOpenAuth">去登录</view>
</view>
<block wx:elif="{{userInfo}}">
<view class="page-hero settings-hero">
<text class="hero-kicker">个人设置</text>
<text class="hero-title">维护你的资料与登录信息</text>
<text class="hero-desc">资料会同步到小程序端展示区域,密码更新后下次登录立即生效。</text>
<text class="hero-kicker">账号设置</text>
<text class="hero-title">资料与安全</text>
<text class="hero-desc">常用设置都在这里</text>
</view>
<view class="page-card settings-card">
<view class="section-title">个人资料</view>
<view class="profile-preview">
<image class="avatar" src="{{userInfo.avatar || defaultAvatar}}" mode="aspectFill"></image>
<image class="avatar" src="{{userInfo.avatar || defaultAvatar}}" mode="aspectFill" lazy-load="{{true}}" binderror="handleAvatarError"></image>
<view class="profile-preview-copy">
<view class="preview-name">{{userInfo.nickname || 'Yumi 用户'}}</view>
<view class="preview-account">{{userInfo.account}}</view>
<view class="preview-phone">{{userInfo.phone || '未绑定手机号'}}</view>
</view>
</view>
<view class="avatar-actions">
<view class="ghost-btn avatar-action" bindtap="handleChooseAvatar">{{uploadingAvatar ? '头像上传中...' : '更换头像'}}</view>
<view wx:if="{{userInfo.avatar}}" class="text-action" bindtap="handleDeleteAvatar">删除头像</view>
</view>
<view wx:if="{{needSetPassword}}" class="hint-card password-hint">
当前账号未设置登录密码。
</view>
<view class="field-block">
<text class="field-label">昵称</text>
<input class="field-input" placeholder="请输入昵称" placeholder-class="field-placeholder" value="{{form.nickname}}" data-field="nickname" bindinput="handleFormInput"></input>
@@ -34,30 +44,133 @@
<view class="field-block">
<text class="field-label">个性签名</text>
<textarea class="field-textarea" placeholder="写一句想让客人认识你的话" placeholder-class="field-placeholder" value="{{form.signature}}" data-field="signature" bindinput="handleFormInput"></textarea>
<textarea class="field-textarea" placeholder="请输入个性签名" placeholder-class="field-placeholder" value="{{form.signature}}" data-field="signature" bindinput="handleFormInput"></textarea>
</view>
<view class="primary-btn save-btn" bindtap="handleSaveProfile">{{savingProfile ? '保存中...' : '保存资料'}}</view>
</view>
<view class="page-card settings-card password-card">
<view class="section-title">登录密码</view>
<view class="section-subtitle">向已绑定手机号发送验证码后更新登录密码。</view>
<view class="page-card settings-card security-card">
<view class="section-title">账号与安全</view>
<view class="field-block">
<text class="field-label">验证码</text>
<view class="code-row">
<input class="field-input code-input" type="number" placeholder="请输入验证码" placeholder-class="field-placeholder" value="{{passwordForm.verificationCode}}" data-field="verificationCode" bindinput="handlePasswordInput"></input>
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendPasswordCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
<view class="setting-row" bindtap="handleSwitchShop">
<view class="setting-main">
<view class="setting-name">当前登录门店</view>
<view class="setting-desc">{{userInfo.shopName || '当前暂无可用门店'}}</view>
</view>
<view class="setting-action">{{(userInfo.shopIds && userInfo.shopIds.length > 1) ? '切换' : '查看'}}</view>
</view>
<view wx:if="{{!userInfo.phone}}" class="setting-row" data-panel="bindPhone" bindtap="handleToggleSecurityPanel">
<view class="setting-main">
<view class="setting-name">绑定手机号</view>
<view class="setting-desc">绑定后可设置密码</view>
</view>
<view class="setting-action">{{activeSecurityPanel === 'bindPhone' ? '收起' : '去绑定'}}</view>
</view>
<view wx:if="{{userInfo.phone}}" class="setting-row" data-panel="changePhone" bindtap="handleToggleSecurityPanel">
<view class="setting-main">
<view class="setting-name">修改手机号</view>
<view class="setting-desc">{{userInfo.phone}}</view>
</view>
<view class="setting-action">{{activeSecurityPanel === 'changePhone' ? '收起' : '修改'}}</view>
</view>
<view class="setting-row" data-panel="password" bindtap="handleToggleSecurityPanel">
<view class="setting-main">
<view class="setting-name">{{needSetPassword ? '设置登录密码' : '修改登录密码'}}</view>
<view class="setting-desc">{{userInfo.phone ? '短信验证后修改' : '请先绑定手机号'}}</view>
</view>
<view class="setting-action">{{activeSecurityPanel === 'password' ? '收起' : (needSetPassword ? '去设置' : '修改')}}</view>
</view>
<view wx:if="{{activeSecurityPanel === 'bindPhone'}}" class="security-panel">
<view class="section-subtitle">输入后完成绑定</view>
<view class="field-block">
<text class="field-label">手机号</text>
<input class="field-input" type="number" placeholder="请输入手机号" placeholder-class="field-placeholder" value="{{bindPhoneForm.phone}}" data-field="phone" bindinput="handleBindPhoneInput"></input>
</view>
<view class="field-block">
<text class="field-label">验证码</text>
<view class="code-row">
<input class="field-input code-input" type="number" placeholder="请输入验证码" placeholder-class="field-placeholder" value="{{bindPhoneForm.verificationCode}}" data-field="verificationCode" bindinput="handleBindPhoneInput"></input>
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendBindPhoneCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
</view>
</view>
<view class="panel-actions">
<view class="secondary-btn panel-btn" bindtap="handleCloseSecurityPanel">取消</view>
<view class="primary-btn panel-btn" bindtap="handleBindPhoneSubmit">{{updatingPhone ? '绑定中...' : '确认绑定'}}</view>
</view>
</view>
<view class="field-block">
<text class="field-label">新密码</text>
<input class="field-input" password placeholder="请输入新密码" placeholder-class="field-placeholder" value="{{passwordForm.password}}" data-field="password" bindinput="handlePasswordInput"></input>
<view wx:if="{{activeSecurityPanel === 'changePhone'}}" class="security-panel">
<view class="section-subtitle">验证后更新手机号</view>
<view class="field-block">
<text class="field-label">当前手机号</text>
<view class="field-static">{{userInfo.phone}}</view>
</view>
<view class="field-block">
<text class="field-label">新手机号</text>
<input class="field-input" type="number" placeholder="请输入新的手机号" placeholder-class="field-placeholder" value="{{changePhoneForm.newPhone}}" data-field="newPhone" bindinput="handleChangePhoneInput"></input>
</view>
<view class="field-block">
<text class="field-label">验证码</text>
<view class="code-row">
<input class="field-input code-input" type="number" placeholder="请输入验证码" placeholder-class="field-placeholder" value="{{changePhoneForm.verificationCode}}" data-field="verificationCode" bindinput="handleChangePhoneInput"></input>
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendChangePhoneCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
</view>
</view>
<view class="panel-actions">
<view class="secondary-btn panel-btn" bindtap="handleCloseSecurityPanel">取消</view>
<view class="primary-btn panel-btn" bindtap="handleChangePhoneSubmit">{{updatingPhone ? '提交中...' : '确认修改'}}</view>
</view>
</view>
<view class="secondary-btn save-btn" bindtap="handleUpdatePassword">{{updatingPassword ? '更新中...' : '更新密码'}}</view>
<view wx:if="{{activeSecurityPanel === 'password'}}" class="security-panel">
<view wx:if="{{!userInfo.phone}}" class="hint-card password-hint">请先绑定手机号,再通过验证码设置或修改登录密码。</view>
<block wx:else>
<view class="section-subtitle">密码需包含字母和数字</view>
<view class="field-block">
<text class="field-label">验证码</text>
<view class="code-row">
<input class="field-input code-input" type="number" placeholder="请输入验证码" placeholder-class="field-placeholder" value="{{passwordForm.verificationCode}}" data-field="verificationCode" bindinput="handlePasswordInput"></input>
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendPasswordCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
</view>
</view>
<view class="field-block">
<text class="field-label">新密码</text>
<input class="field-input" password placeholder="请输入新密码" placeholder-class="field-placeholder" value="{{passwordForm.password}}" data-field="password" bindinput="handlePasswordInput"></input>
</view>
<view class="field-block">
<text class="field-label">确认密码</text>
<input class="field-input" password placeholder="请再次输入新密码" placeholder-class="field-placeholder" value="{{passwordForm.confirmPassword}}" data-field="confirmPassword" bindinput="handlePasswordInput"></input>
</view>
<view class="panel-actions">
<view class="secondary-btn panel-btn" bindtap="handleCloseSecurityPanel">取消</view>
<view class="primary-btn panel-btn" bindtap="handleUpdatePassword">{{updatingPassword ? '提交中...' : '确认保存'}}</view>
</view>
</block>
</view>
<view class="setting-row danger-row" bindtap="handleDeactivateAccount">
<view class="setting-main">
<view class="setting-name">注销账号</view>
<view class="setting-desc">注销后不可继续登录</view>
</view>
<view class="setting-action danger-text">{{deactivating ? '处理中' : '注销'}}</view>
</view>
</view>
<view class="page-card settings-card more-card">
<view class="section-title">更多功能</view>
<view wx:for="{{placeholderEntries}}" wx:key="key" class="setting-row" bindtap="handleComingSoon">
<view class="setting-main">
<view class="setting-name">{{item.title}}</view>
</view>
<view class="placeholder-tag">暂未开放</view>
</view>
</view>
<view class="logout-btn" bindtap="handleLogout">退出登录</view>
+118 -2
View File
@@ -29,7 +29,7 @@
.profile-preview {
display: flex;
align-items: center;
gap: 18rpx;
gap: 20rpx;
margin-top: 22rpx;
}
@@ -42,6 +42,7 @@
.profile-preview-copy {
flex: 1;
min-width: 0;
}
.preview-name {
@@ -50,10 +51,31 @@
color: #2d2430;
}
.preview-account,
.preview-phone {
margin-top: 10rpx;
font-size: 24rpx;
color: #8d7a84;
word-break: break-all;
}
.avatar-actions {
display: flex;
align-items: center;
gap: 18rpx;
margin-top: 22rpx;
}
.avatar-action {
width: auto;
min-width: 220rpx;
padding: 0 28rpx;
}
.text-action {
font-size: 24rpx;
font-weight: 600;
color: #c6597d;
}
.field-block {
@@ -64,10 +86,76 @@
margin-top: 26rpx;
}
.password-card {
.password-hint {
margin-top: 20rpx;
}
.security-card,
.more-card {
margin-top: 20rpx;
}
.setting-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18rpx;
padding: 24rpx 0;
border-bottom: 1rpx solid rgba(239, 216, 224, 0.92);
}
.setting-row:first-of-type {
margin-top: 8rpx;
}
.setting-row:last-child {
border-bottom: 0;
padding-bottom: 0;
}
.setting-main {
flex: 1;
min-width: 0;
}
.setting-name {
font-size: 28rpx;
font-weight: 700;
color: #2d2430;
}
.setting-desc {
margin-top: 10rpx;
font-size: 24rpx;
line-height: 1.7;
color: #8d7a84;
}
.setting-action {
flex-shrink: 0;
font-size: 24rpx;
font-weight: 700;
color: #c6597d;
}
.security-panel {
margin-top: 6rpx;
padding: 26rpx 24rpx;
border-radius: 28rpx;
background: #fff7f8;
}
.field-static {
display: flex;
align-items: center;
min-height: 92rpx;
padding: 0 28rpx;
border-radius: 24rpx;
background: #f5edf0;
color: #5d4b55;
font-size: 28rpx;
}
.code-row {
display: flex;
align-items: center;
@@ -97,6 +185,34 @@
color: #a998a0;
}
.panel-actions {
display: flex;
gap: 14rpx;
margin-top: 24rpx;
}
.panel-btn {
flex: 1;
}
.placeholder-tag {
flex-shrink: 0;
padding: 12rpx 18rpx;
border-radius: 999rpx;
background: #fdf0f4;
color: #c6597d;
font-size: 22rpx;
font-weight: 700;
}
.danger-row {
margin-top: 8rpx;
}
.danger-text {
color: #d5536f;
}
.logout-btn {
display: flex;
align-items: center;
+2 -1
View File
@@ -2,7 +2,7 @@
<view class="page-shell shop-page">
<view class="shop-hero">
<image wx:if="{{shopImages.length}}" class="shop-hero-image" src="{{shopImages[0]}}" mode="aspectFill"></image>
<image wx:if="{{shopImages.length}}" class="shop-hero-image" src="{{shopImages[0]}}" mode="aspectFill" lazy-load="{{true}}"></image>
<view class="shop-hero-mask"></view>
</view>
@@ -67,6 +67,7 @@
mode="aspectFill"
data-url="{{item}}"
bindtap="handlePreviewImage"
lazy-load="{{true}}"
></image>
</view>
</view>
+113 -6
View File
@@ -1,4 +1,6 @@
const wishlistApi = require('../../api/wishlist')
const cartApi = require('../../api/cart')
const actionGuard = require('../../utils/action-guard')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const { buildProductCard } = require('../../utils/product')
@@ -23,6 +25,7 @@ Page({
})
if (!isLoggedIn) {
this.cartProductIdSet = new Set()
this.setData({
wishlist: [],
loading: false
@@ -33,10 +36,14 @@ Page({
try {
const wishlist = await wishlistApi.getWishlist()
const list = Array.isArray(wishlist) ? wishlist : []
const cartProductIdSet = await this.fetchCartProductIdSet()
const cards = await Promise.all(list.map(async item => ({
id: item.id,
productId: item.productId,
productCard: await buildProductCard(item.product || {})
productCard: this.markCardInCart(
await buildProductCard(item.product || {}),
cartProductIdSet
)
})))
this.setData({
wishlist: cards
@@ -46,7 +53,7 @@ Page({
wishlist: []
})
wx.showToast({
title: error.message || '收藏列表加载失败',
title: error.message || '\u6536\u85cf\u5217\u8868\u52a0\u8f7d\u5931\u8d25',
icon: 'none'
})
} finally {
@@ -56,6 +63,57 @@ Page({
}
},
normalizeId(value) {
return value === undefined || value === null ? '' : String(value)
},
async fetchCartProductIdSet() {
try {
const cartList = await cartApi.getCartList()
const idSet = new Set(
(Array.isArray(cartList) ? cartList : [])
.map(item => this.normalizeId(item && item.productId))
.filter(Boolean)
)
this.cartProductIdSet = idSet
return idSet
} catch (error) {
this.cartProductIdSet = new Set()
return this.cartProductIdSet
}
},
markCardInCart(card, idSet) {
return {
...card,
inCart: (idSet || new Set()).has(this.normalizeId(card && card.id))
}
},
markWishlistProductInCart(productId) {
const normalizedId = this.normalizeId(productId)
if (!normalizedId) {
return
}
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
}
}
: item
))
})
},
handleOpenAuth() {
navigation.openAuth('/pages/wishlist/index')
},
@@ -65,11 +123,55 @@ Page({
if (!product.id) {
return
}
navigation.navigate('/pages/product-detail/index', {
id: product.id
})
},
async handleQuickAdd(event) {
const product = event.detail || {}
const productId = this.normalizeId(product.id)
if (!productId) {
return
}
if (!navigation.ensureLogin('\u52a0\u5165\u8d2d\u7269\u8f66')) {
return
}
if (this.cartProductIdSet && this.cartProductIdSet.has(productId)) {
wx.showToast({
title: '\u8d2d\u7269\u8f66\u5df2\u6709',
icon: 'none'
})
return
}
try {
await actionGuard.run(this, `cart:add:${productId}`, () => runWithLoading(() => cartApi.addToCart({
productId,
quantity: 1
})), {
message: '\u8d2d\u7269\u8f66\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
})
this.markWishlistProductInCart(productId)
await getApp().updateCartBadge()
wx.showToast({
title: '\u5df2\u52a0\u5165\u8d2d\u7269\u8f66',
icon: 'none'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '\u52a0\u5165\u8d2d\u7269\u8f66\u5931\u8d25',
icon: 'none'
})
}
},
async handleRemove(event) {
const productId = event.currentTarget.dataset.productId
if (!productId) {
@@ -77,15 +179,20 @@ Page({
}
try {
await runWithLoading(() => wishlistApi.removeFromWishlist(productId))
await actionGuard.run(this, `wishlist:remove:${productId}`, () => runWithLoading(() => wishlistApi.removeFromWishlist(productId)), {
message: '\u64cd\u4f5c\u8fdb\u884c\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u70b9\u51fb'
})
wx.showToast({
title: '已取消收藏',
title: '\u5df2\u53d6\u6d88\u6536\u85cf',
icon: 'none'
})
this.loadWishlist()
await this.loadWishlist()
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '取消收藏失败',
title: error.message || '\u53d6\u6d88\u6536\u85cf\u5931\u8d25',
icon: 'none'
})
}
+13 -5
View File
@@ -4,7 +4,7 @@
<view class="page-content">
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
<text class="empty-title">登录后查看收藏</text>
<text class="empty-desc">你收藏过的作品会保存在这里,方便之后快速回看。</text>
<text class="empty-desc">登录后查看收藏作品。</text>
<view class="ghost-btn" bindtap="handleOpenAuth">去登录</view>
</view>
@@ -12,12 +12,20 @@
<view class="page-hero wishlist-hero">
<text class="hero-kicker">收藏夹</text>
<text class="hero-title">已收藏 {{wishlist.length}} 个作品</text>
<text class="hero-desc">遇到喜欢的款式先放进收藏,之后再决定是否预约会更从容。</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>
<product-card
item="{{item.productCard}}"
show-quick-add="{{true}}"
in-cart="{{item.productCard.inCart}}"
bindselect="handleProductSelect"
bindquickadd="handleQuickAdd"
></product-card>
<view class="wishlist-actions">
<view class="wishlist-action wishlist-action--secondary" data-product-id="{{item.productId}}" bindtap="handleRemove">取消收藏</view>
</view>
</view>
</block>
@@ -27,7 +35,7 @@
<view wx:else class="page-card empty-card">
<text class="empty-title">你还没有收藏作品</text>
<text class="empty-desc">遇到喜欢的款式先收藏,之后再决定要不要预约。</text>
<text class="empty-desc">先去逛逛作品。</text>
<view class="ghost-btn" bindtap="handleBack">去逛作品</view>
</view>
</view>
+12 -1
View File
@@ -6,15 +6,26 @@
margin-top: 22rpx;
}
.wishlist-actions {
display: flex;
gap: 16rpx;
margin-top: 12rpx;
}
.wishlist-action {
display: flex;
align-items: center;
justify-content: center;
height: 74rpx;
margin-top: 12rpx;
flex: 1;
border-radius: 20rpx;
background: #fff1f5;
color: #c6597d;
font-size: 26rpx;
font-weight: 600;
}
.wishlist-action--secondary {
background: #fff1f5;
color: #c6597d;
}