diff --git a/WeChatProgram/api/product.js b/WeChatProgram/api/product.js
index 4ff93a73..d80eb67a 100644
--- a/WeChatProgram/api/product.js
+++ b/WeChatProgram/api/product.js
@@ -1,6 +1,13 @@
const request = require('../utils/request')
module.exports = {
+ getProductPage(params) {
+ return request({
+ url: '/product/list/page',
+ params
+ })
+ },
+
getAllProducts() {
return request({
url: '/product/list/all'
diff --git a/WeChatProgram/api/user.js b/WeChatProgram/api/user.js
index c0eac509..72ad07cd 100644
--- a/WeChatProgram/api/user.js
+++ b/WeChatProgram/api/user.js
@@ -1,4 +1,36 @@
const request = require('../utils/request')
+const actionGuard = require('../utils/action-guard')
+const { API_BASE_URL, REQUEST_TIMEOUT } = require('../utils/config')
+
+function normalizeUploadResponse(response) {
+ if (!response) {
+ throw new Error('头像上传失败')
+ }
+
+ if (response.statusCode === 401) {
+ throw new Error('登录已过期,请重新登录')
+ }
+
+ if (response.statusCode >= 400) {
+ throw new Error('头像上传失败')
+ }
+
+ let payload = response.data
+ if (typeof payload === 'string') {
+ try {
+ payload = JSON.parse(payload)
+ } catch (error) {}
+ }
+
+ if (payload && typeof payload === 'object' && Object.prototype.hasOwnProperty.call(payload, 'code')) {
+ if (payload.code === 200) {
+ return payload.data
+ }
+ throw new Error(payload.message || '头像上传失败')
+ }
+
+ return payload
+}
module.exports = {
getUserInfo() {
@@ -23,6 +55,59 @@ module.exports = {
})
},
+ bindPhone(data) {
+ return request({
+ url: '/user/bind-phone',
+ method: 'POST',
+ data
+ })
+ },
+
+ updatePhone(data) {
+ return request({
+ url: '/user/phone',
+ method: 'PUT',
+ data
+ })
+ },
+
+ deactivateAccount() {
+ return request({
+ url: '/user/deactivate',
+ method: 'DELETE'
+ })
+ },
+
+ uploadAvatar(filePath) {
+ const signedHeaders = request.buildSignatureHeaders({
+ url: '/user/upload-avatar',
+ method: 'POST',
+ formData: {}
+ })
+
+ return actionGuard.run(null, `POST:/user/upload-avatar:${filePath || ''}`, () => new Promise((resolve, reject) => {
+ wx.uploadFile({
+ url: `${API_BASE_URL}/user/upload-avatar`,
+ filePath,
+ name: 'file',
+ timeout: REQUEST_TIMEOUT,
+ header: signedHeaders,
+ success: response => {
+ try {
+ resolve(normalizeUploadResponse(response))
+ } catch (error) {
+ reject(error)
+ }
+ },
+ fail: error => {
+ reject(new Error(error.errMsg || '头像上传失败'))
+ }
+ })
+ }), {
+ message: '上传处理中,请勿重复操作'
+ })
+ },
+
checkAccountAvailability(account) {
return request({
url: `/user/check/account/${encodeURIComponent(account)}`
diff --git a/WeChatProgram/app.js b/WeChatProgram/app.js
index f9213977..5b796396 100644
--- a/WeChatProgram/app.js
+++ b/WeChatProgram/app.js
@@ -1,6 +1,9 @@
const authApi = require('./api/auth')
const cartApi = require('./api/cart')
+const userApi = require('./api/user')
const auth = require('./utils/auth')
+const idleSession = require('./utils/idle-session')
+const { IDLE_TIMEOUT_MS, IDLE_WARNING_MS } = require('./utils/config')
App({
globalData: {
@@ -13,12 +16,26 @@ App({
},
onLaunch() {
+ idleSession.init({
+ timeoutMs: IDLE_TIMEOUT_MS,
+ warningMs: IDLE_WARNING_MS,
+ isLoggedIn: () => auth.isLoggedIn(),
+ onLogout: () => this.handleIdleLogout()
+ })
this.bootstrapSession()
if (!auth.isLoggedIn()) {
this.tryWechatMiniAutoLogin()
}
},
+ onShow() {
+ idleSession.onAppShow()
+ },
+
+ onHide() {
+ idleSession.onAppHide()
+ },
+
bootstrapSession() {
const userInfo = auth.getStoredUserInfo()
const isLoggedIn = auth.isLoggedIn()
@@ -30,6 +47,7 @@ App({
}
if (isLoggedIn) {
+ this.refreshSessionUserInfo()
this.updateCartBadge()
return
}
@@ -168,6 +186,35 @@ App({
this.clearCartBadge()
},
+ async refreshSessionUserInfo() {
+ if (!auth.isLoggedIn()) {
+ return
+ }
+ try {
+ const userInfo = await userApi.getUserInfo()
+ this.refreshUserInfo(userInfo)
+ } catch (error) {}
+ },
+
+ async handleIdleLogout() {
+ if (!auth.isLoggedIn()) {
+ return
+ }
+ try {
+ await authApi.logout()
+ } catch (error) {}
+ this.clearUserSession()
+ wx.showToast({
+ title: '长时间未操作,已退出登录',
+ icon: 'none'
+ })
+ setTimeout(() => {
+ wx.reLaunch({
+ url: '/pages/auth/index'
+ })
+ }, 260)
+ },
+
async updateCartBadge() {
if (!auth.isLoggedIn()) {
this.clearCartBadge()
diff --git a/WeChatProgram/components/product-card/product-card.js b/WeChatProgram/components/product-card/product-card.js
index f3945dc6..c0b219e8 100644
--- a/WeChatProgram/components/product-card/product-card.js
+++ b/WeChatProgram/components/product-card/product-card.js
@@ -11,12 +11,24 @@ Component({
showStats: {
type: Boolean,
value: false
+ },
+ showQuickAdd: {
+ type: Boolean,
+ value: false
+ },
+ inCart: {
+ type: Boolean,
+ value: false
}
},
methods: {
handleTap() {
this.triggerEvent('select', this.properties.item)
+ },
+
+ handleQuickAdd() {
+ this.triggerEvent('quickadd', this.properties.item)
}
}
})
diff --git a/WeChatProgram/components/product-card/product-card.wxml b/WeChatProgram/components/product-card/product-card.wxml
index e61e7ffb..7013ef40 100644
--- a/WeChatProgram/components/product-card/product-card.wxml
+++ b/WeChatProgram/components/product-card/product-card.wxml
@@ -1,6 +1,6 @@
-
+
{{item.metaText}}
@@ -15,7 +15,19 @@
{{item.priceText}}
{{item.statsText}}
- 查看
+
+
+
+
+
+
+
+
+
+
+
+ 购物车已有
+
diff --git a/WeChatProgram/components/product-card/product-card.wxss b/WeChatProgram/components/product-card/product-card.wxss
index c8430e7d..04208aa2 100644
--- a/WeChatProgram/components/product-card/product-card.wxss
+++ b/WeChatProgram/components/product-card/product-card.wxss
@@ -1,8 +1,9 @@
.product-card {
display: flex;
flex-direction: column;
+ min-width: 0;
overflow: hidden;
- border-radius: 30rpx;
+ border-radius: 28rpx;
background: #ffffff;
border: 1rpx solid rgba(239, 216, 224, 0.84);
box-shadow: 0 18rpx 42rpx rgba(122, 67, 88, 0.08);
@@ -14,7 +15,7 @@
.product-cover {
width: 100%;
- height: 300rpx;
+ height: 288rpx;
background: #f7ecf0;
}
@@ -29,60 +30,72 @@
.product-meta-badge {
position: absolute;
- left: 18rpx;
- top: 18rpx;
- max-width: calc(100% - 36rpx);
- padding: 10rpx 16rpx;
+ left: 16rpx;
+ top: 16rpx;
+ max-width: calc(100% - 32rpx);
+ padding: 8rpx 14rpx;
border-radius: 999rpx;
background: rgba(255, 255, 255, 0.92);
color: #7a5262;
- font-size: 20rpx;
+ font-size: 19rpx;
font-weight: 700;
}
.product-body {
display: flex;
flex-direction: column;
- gap: 12rpx;
- padding: 22rpx 22rpx 24rpx;
+ gap: 10rpx;
+ min-height: 220rpx;
+ padding: 20rpx 20rpx 22rpx;
}
.product-title {
- font-size: 28rpx;
+ min-height: 74rpx;
+ font-size: 27rpx;
font-weight: 700;
- line-height: 1.5;
+ line-height: 1.38;
color: #2d2430;
+ word-break: break-all;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
}
.product-meta {
- font-size: 24rpx;
+ font-size: 22rpx;
color: #8d7a84;
- line-height: 1.5;
+ line-height: 1.4;
}
.product-tags {
display: flex;
flex-wrap: wrap;
- gap: 10rpx;
+ gap: 8rpx;
}
.tag-item {
display: inline-flex;
align-items: center;
justify-content: center;
- padding: 8rpx 16rpx;
+ max-width: 100%;
+ padding: 6rpx 14rpx;
border-radius: 999rpx;
background: #fbecf1;
color: #c6597d;
- font-size: 20rpx;
+ font-size: 18rpx;
+ line-height: 1;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
}
.product-footer {
display: flex;
align-items: flex-end;
- justify-content: space-between;
- gap: 16rpx;
- margin-top: 4rpx;
+ gap: 14rpx;
+ margin-top: auto;
}
.product-price-wrap {
@@ -90,30 +103,115 @@
min-width: 0;
}
+.product-actions {
+ display: flex;
+ align-items: center;
+ flex-shrink: 0;
+}
+
.product-price {
display: block;
- font-size: 30rpx;
- font-weight: 700;
+ font-size: 34rpx;
+ line-height: 1.12;
+ font-weight: 800;
color: #d5536f;
}
.product-stats {
display: block;
- margin-top: 8rpx;
- font-size: 22rpx;
+ margin-top: 6rpx;
+ font-size: 20rpx;
+ line-height: 1.4;
color: #9d8a92;
}
-.product-arrow {
+.product-quick-add {
display: inline-flex;
align-items: center;
justify-content: center;
- min-width: 96rpx;
- height: 52rpx;
+ width: 64rpx;
+ height: 64rpx;
+ border-radius: 22rpx;
+ background: linear-gradient(135deg, #ff8cb0 0%, #c6597d 100%);
+ box-shadow: 0 14rpx 30rpx rgba(198, 89, 125, 0.22);
+}
+
+.product-quick-add-icon {
+ position: relative;
+ width: 32rpx;
+ height: 28rpx;
+}
+
+.product-quick-add-handle {
+ position: absolute;
+ left: 2rpx;
+ top: 2rpx;
+ width: 12rpx;
+ height: 4rpx;
+ border-radius: 999rpx;
+ background: #ffffff;
+ transform: rotate(20deg);
+ transform-origin: left center;
+}
+
+.product-quick-add-basket {
+ position: absolute;
+ left: 6rpx;
+ top: 8rpx;
+ width: 18rpx;
+ height: 11rpx;
+ border: 3rpx solid #ffffff;
+ border-top: 0;
+ border-radius: 0 0 6rpx 6rpx;
+}
+
+.product-quick-add-wheel {
+ position: absolute;
+ top: 22rpx;
+ width: 6rpx;
+ height: 6rpx;
+ border-radius: 50%;
+ background: #ffffff;
+}
+
+.product-quick-add-wheel--left {
+ left: 10rpx;
+}
+
+.product-quick-add-wheel--right {
+ left: 22rpx;
+}
+
+.product-quick-add-plus {
+ position: absolute;
+ border-radius: 999rpx;
+ background: #ffffff;
+}
+
+.product-quick-add-plus--horizontal {
+ top: 2rpx;
+ right: 0;
+ width: 10rpx;
+ height: 3rpx;
+}
+
+.product-quick-add-plus--vertical {
+ top: -1rpx;
+ right: 4rpx;
+ width: 3rpx;
+ height: 10rpx;
+}
+
+.product-in-cart {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ height: 56rpx;
padding: 0 18rpx;
border-radius: 999rpx;
- background: #fff1f5;
- color: #c6597d;
- font-size: 22rpx;
+ background: #f8eef1;
+ color: #8f6e7a;
+ font-size: 20rpx;
font-weight: 700;
+ white-space: nowrap;
}
diff --git a/WeChatProgram/pages/auth/index.js b/WeChatProgram/pages/auth/index.js
index ed19c070..4315a8c1 100644
--- a/WeChatProgram/pages/auth/index.js
+++ b/WeChatProgram/pages/auth/index.js
@@ -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 '多门店账号需先选门店'
}
})
diff --git a/WeChatProgram/pages/auth/index.wxml b/WeChatProgram/pages/auth/index.wxml
index 368132e4..0ce20078 100644
--- a/WeChatProgram/pages/auth/index.wxml
+++ b/WeChatProgram/pages/auth/index.wxml
@@ -12,7 +12,7 @@
微信手机号一键登录
- 最快的登录方式,首次授权也能自动注册。
+ 更快登录
- 微信身份已识别完成,还差一步门店确认即可登录。
+ 请选择登录门店
继续选择门店
- 使用账号密码或验证码登录
+ 其他登录方式
- 传统登录方式
+ 其他方式
@@ -130,7 +130,7 @@
重置密码
- 使用短信验证码设置新的登录密码。
+ 短信验证后重置密码
手机号
@@ -157,8 +157,8 @@
{{miniShopNewUser ? '首次微信登录' : '确认本次登录门店'}}
- {{miniShopNewUser ? '先选一家门店,我们会自动注册并登录' : '该账号绑定了多家门店,请先选择本次登录门店'}}
- {{miniShopMessage || '选择后将继续完成登录。'}}
+ {{miniShopNewUser ? '先选门店' : '选择登录门店'}}
+ {{miniShopMessage || '选择后继续登录'}}
登录门店
@@ -167,7 +167,7 @@
- 首次通过微信手机号登录时,会自动创建账号、绑定手机号,并将当前门店作为本次登录门店。
+ 首次登录会自动注册并绑定手机号。
稍后再选
diff --git a/WeChatProgram/pages/cart/index.wxml b/WeChatProgram/pages/cart/index.wxml
index e34d70f5..12212b69 100644
--- a/WeChatProgram/pages/cart/index.wxml
+++ b/WeChatProgram/pages/cart/index.wxml
@@ -4,7 +4,7 @@
登录后查看购物车
- 把喜欢的作品加进购物车后,就能补全预约信息并提交订单。
+ 登录后管理预约内容。
去登录
@@ -12,23 +12,23 @@
结算准备
已选 {{selectedCount}} 个预约项目
- 先确认美甲师和预约时间,再统一提交订单,避免来回修改。
+ 确认美甲师和时间后再下单。
选中项目
{{selectedCount}} 项
- 可分批勾选结算
+ 可分批结算
数量合计
{{totalQuantity}} 件
- 支持直接增减数量
+ 可改数量
待支付
{{totalAmountText}}
- 已自动计算优惠
+ 已算优惠
@@ -41,7 +41,7 @@
-
+
{{item.productTitle}}
@@ -93,7 +93,7 @@
优惠方式
- 系统会优先帮你匹配最合适的 VIP 自动折扣,普通优惠券仍可手动改选。
+ 系统会优先匹配 VIP 优惠。
diff --git a/WeChatProgram/pages/coupons/index.js b/WeChatProgram/pages/coupons/index.js
index 0815734a..804f3e1d 100644
--- a/WeChatProgram/pages/coupons/index.js
+++ b/WeChatProgram/pages/coupons/index.js
@@ -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')
},
diff --git a/WeChatProgram/pages/coupons/index.wxml b/WeChatProgram/pages/coupons/index.wxml
index a6151abb..52fd3004 100644
--- a/WeChatProgram/pages/coupons/index.wxml
+++ b/WeChatProgram/pages/coupons/index.wxml
@@ -4,27 +4,46 @@
登录后查看优惠券
- 可用优惠、VIP 自动折扣都会统一展示在这里。
+ 登录后查看可用优惠。
去登录
优惠资产
- 当前有 {{coupons.length}} 张可查看
- 普通优惠券和系统自动匹配的 VIP 折扣都会在结算前统一展示。
+ 当前有 {{coupons.length}} 张
+ 下单前可查看可用优惠。
-
-
-
- {{item.couponName}}
- {{item.sourceText}}
-
- {{item.statusName || '待使用'}}
+
+
+ {{item.label}}
- {{item.benefitText}}
- {{item.periodText}}
+
+
+
+
+
+
+ {{item.couponName}}
+ {{item.sourceText}}
+
+ {{item.statusName || '待使用'}}
+
+ {{item.benefitText}}
+ {{item.periodText}}
+
+
+
+
+ 当前筛选下暂无优惠券
+ 换个筛选试试。
@@ -34,7 +53,7 @@
你还没有优惠券
- 下单前系统也会自动帮你匹配最合适的优惠方式。
+ 下单前会自动匹配可用优惠。
diff --git a/WeChatProgram/pages/coupons/index.wxss b/WeChatProgram/pages/coupons/index.wxss
index 82421aee..da5db6dc 100644
--- a/WeChatProgram/pages/coupons/index.wxss
+++ b/WeChatProgram/pages/coupons/index.wxss
@@ -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;
}
diff --git a/WeChatProgram/pages/home/index.js b/WeChatProgram/pages/home/index.js
index ef83eac1..f3260d3d 100644
--- a/WeChatProgram/pages/home/index.js
+++ b/WeChatProgram/pages/home/index.js
@@ -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) {
diff --git a/WeChatProgram/pages/home/index.wxml b/WeChatProgram/pages/home/index.wxml
index 9345d350..146ecacd 100644
--- a/WeChatProgram/pages/home/index.wxml
+++ b/WeChatProgram/pages/home/index.wxml
@@ -7,7 +7,7 @@
{{isLoggedIn ? greeting : 'YUMI NAIL 小程序'}}
{{displayName}}
- 先看门店氛围,再挑喜欢的作品,最后一站式完成收藏、加购和预约。
+ 先选喜欢的作品。
{{isLoggedIn ? '进入个人中心' : '立即登录'}}
@@ -31,22 +31,22 @@
门店橱窗
{{bannerImages.length ? bannerImages.length : 0}} 家
- 先看环境,再决定去哪家
+ 看环境
精选作品
{{featuredItems.length ? featuredItems.length : 0}} 款
- 适合快速找到灵感
+ 找灵感
热门推荐
{{popularItems.length ? popularItems.length : 0}} 条
- 当前最受欢迎的预约款式
+ 热门款
- 登录后可同步收藏、购物车和预约记录,切换设备也不会丢。
+ 登录后可同步收藏和预约记录。
@@ -55,7 +55,7 @@
门店氛围
先看看线下环境
- 轮播展示门店图片和营业时间,帮助你快速判断想去的店。
+ 看店铺环境
@@ -63,7 +63,7 @@
-
+
门店实拍
{{item.shopName}}
@@ -76,7 +76,7 @@
门店内容正在补充中
- 可以先浏览精选作品,稍后再回来查看门店环境展示。
+ 先看看作品。
@@ -85,7 +85,7 @@
快速入门
精选作品
- 适合先快速逛一圈的热门款式,向右滑动查看更多。
+ 先看热门款
查看全部
@@ -102,7 +102,7 @@
精选作品正在整理中
- 等门店补齐款式后,这里会优先展示最值得先看的内容。
+ 稍后再来看看。
@@ -111,7 +111,7 @@
热门预约
最近大家都在看
- 结合点赞和收藏热度展示当前最受欢迎的款式。
+ 热门款式
查看全部
@@ -121,6 +121,9 @@
+
+ {{loadingMore ? '正在加载更多热门作品...' : '已经到底了'}}
+
正在加载首页内容
@@ -128,7 +131,7 @@
还没有热门作品
- 当前门店还在补充作品数据,稍后再回来看看。
+ 稍后再来看看。
diff --git a/WeChatProgram/pages/home/index.wxss b/WeChatProgram/pages/home/index.wxss
index 2dc99a89..2713d921 100644
--- a/WeChatProgram/pages/home/index.wxss
+++ b/WeChatProgram/pages/home/index.wxss
@@ -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;
+}
diff --git a/WeChatProgram/pages/index/index.wxml b/WeChatProgram/pages/index/index.wxml
index c543ccf7..6b545c2f 100644
--- a/WeChatProgram/pages/index/index.wxml
+++ b/WeChatProgram/pages/index/index.wxml
@@ -2,6 +2,6 @@
正在进入首页
- 这个 `pages/index` 是初始化遗留页,当前实际首页是 `pages/home/index`。
+ 即将进入首页
diff --git a/WeChatProgram/pages/orders/index.js b/WeChatProgram/pages/orders/index.js
index 9e41aa2b..344b0c14 100644
--- a/WeChatProgram/pages/orders/index.js
+++ b/WeChatProgram/pages/orders/index.js
@@ -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'
})
}
diff --git a/WeChatProgram/pages/orders/index.wxml b/WeChatProgram/pages/orders/index.wxml
index d829ac08..e9f9d3cb 100644
--- a/WeChatProgram/pages/orders/index.wxml
+++ b/WeChatProgram/pages/orders/index.wxml
@@ -4,7 +4,7 @@
登录后查看订单
- 预约状态、取消进度和服务记录都会展示在这里。
+ 登录后查看预约记录。
去登录
@@ -12,7 +12,7 @@
预约记录
共 {{orders.length}} 笔订单
- 这里展示每笔订单的状态、项目、预约时间以及取消入口。
+ 查看订单状态和预约时间。
@@ -25,7 +25,7 @@
-
+
{{orderItem.productTitle}}
{{orderItem.priceText}} x {{orderItem.quantity}}
@@ -47,7 +47,7 @@
你还没有订单
- 选到喜欢的款式后,加入购物车即可发起预约。
+ 先去预约喜欢的款式。
diff --git a/WeChatProgram/pages/product-detail/index.js b/WeChatProgram/pages/product-detail/index.js
index 228ef834..a646a996 100644
--- a/WeChatProgram/pages/product-detail/index.js
+++ b/WeChatProgram/pages/product-detail/index.js
@@ -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'
diff --git a/WeChatProgram/pages/product-detail/index.wxml b/WeChatProgram/pages/product-detail/index.wxml
index 6e3123a1..fc168b51 100644
--- a/WeChatProgram/pages/product-detail/index.wxml
+++ b/WeChatProgram/pages/product-detail/index.wxml
@@ -13,7 +13,7 @@
-
+
@@ -30,24 +30,24 @@
作品详情
{{product.displayTitle}}
{{product.priceText}}
- 适合先看作品风格、门店信息和可预约情况,再决定是否立即下单。
+ 查看作品、门店和可预约信息。
所属门店
{{shopInfo ? shopInfo.shopName : '待绑定'}}
- 点击查看门店详情
+ 查看门店
可约美甲师
{{artistCountText}}
- 预约前可在购物车继续选择
+ 可继续选择
最早可约
{{earliestBookableText}}
- 以门店营业时间为准
+ 以营业时间为准
diff --git a/WeChatProgram/pages/products/index.js b/WeChatProgram/pages/products/index.js
index 0289fc51..1c66aa65 100644
--- a/WeChatProgram/pages/products/index.js
+++ b/WeChatProgram/pages/products/index.js
@@ -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'
+ })
+ }
}
})
diff --git a/WeChatProgram/pages/products/index.wxml b/WeChatProgram/pages/products/index.wxml
index df48a933..76ee2ff1 100644
--- a/WeChatProgram/pages/products/index.wxml
+++ b/WeChatProgram/pages/products/index.wxml
@@ -1,17 +1,13 @@
-
-
- 作品筛选
- {{selectedCategory !== '全部' ? selectedCategory : '找到适合你的美甲款式'}}
- {{activeBannerText ? activeBannerText : '按标签筛选或输入关键词搜索,先缩小范围,再挑喜欢的作品。'}}
-
-
+
+
+
搜索
-
+
+
+
+
+ {{products.length ? products.length : 0}} 个
+ {{filterSummaryText}}
+
+ 重置
+
-
- {{products.length ? products.length : 0}} 个结果
- 重置筛选
-
-
- {{activeBannerText}}
-
-
+
+
+ {{loadingMore ? '正在加载更多作品...' : '已经到底了'}}
+
正在加载作品
@@ -56,7 +63,7 @@
暂时没有匹配的作品
- 可以换个关键词试试,或者先浏览全部作品。
+ 换个关键词试试。
查看全部
diff --git a/WeChatProgram/pages/products/index.wxss b/WeChatProgram/pages/products/index.wxss
index cc17df70..18b6ca24 100644
--- a/WeChatProgram/pages/products/index.wxss
+++ b/WeChatProgram/pages/products/index.wxss
@@ -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;
}
diff --git a/WeChatProgram/pages/profile/index.js b/WeChatProgram/pages/profile/index.js
index 3a1fd694..c367b9a9 100644
--- a/WeChatProgram/pages/profile/index.js
+++ b/WeChatProgram/pages/profile/index.js
@@ -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': ''
+ })
+ }
}
})
diff --git a/WeChatProgram/pages/profile/index.wxml b/WeChatProgram/pages/profile/index.wxml
index 116d4a8b..1204f80e 100644
--- a/WeChatProgram/pages/profile/index.wxml
+++ b/WeChatProgram/pages/profile/index.wxml
@@ -6,16 +6,16 @@
-
+
还没有登录账号
- 登录后可以查看订单、收藏作品、领取和使用优惠。
+ 登录后查看订单、收藏和优惠券。
去登录
-
+
{{userInfo.nickname || 'Yumi 用户'}}
{{userInfo.account}}
@@ -27,17 +27,14 @@
订单
{{orderCount}}
- 查看预约记录
收藏
{{wishlistCount}}
- 回看喜欢的作品
优惠券
{{couponCount}}
- 结算前可直接使用
@@ -50,15 +47,14 @@
- 建议尽快补充登录密码,之后切换设备会更方便。
+ 建议尽快设置登录密码。
- 编辑资料与设置
+ 资料与设置