diff --git a/.gitignore b/.gitignore index d1c1aeeb..ae0771fd 100644 --- a/.gitignore +++ b/.gitignore @@ -372,3 +372,4 @@ buildNumber.properties m2repo/ /docs/product/ +WeChatProgram/project.private.config.json diff --git a/WeChatProgram/.eslintrc.js b/WeChatProgram/.eslintrc.js new file mode 100644 index 00000000..115cc02b --- /dev/null +++ b/WeChatProgram/.eslintrc.js @@ -0,0 +1,31 @@ +/* + * Eslint config file + * Documentation: https://eslint.org/docs/user-guide/configuring/ + * Install the Eslint extension before using this feature. + */ +module.exports = { + env: { + es6: true, + browser: true, + node: true, + }, + ecmaFeatures: { + modules: true, + }, + parserOptions: { + ecmaVersion: 2018, + sourceType: 'module', + }, + globals: { + wx: true, + App: true, + Page: true, + getCurrentPages: true, + getApp: true, + Component: true, + requirePlugin: true, + requireMiniProgram: true, + }, + // extends: 'eslint:recommended', + rules: {}, +} diff --git a/WeChatProgram/api/auth.js b/WeChatProgram/api/auth.js new file mode 100644 index 00000000..1f798d24 --- /dev/null +++ b/WeChatProgram/api/auth.js @@ -0,0 +1,58 @@ +const request = require('../utils/request') + +module.exports = { + sendVerificationCode(data) { + return request({ + url: '/user/send-verification-code', + method: 'POST', + data + }) + }, + + login(data) { + return request({ + url: '/user/login', + method: 'POST', + data + }) + }, + + phoneLogin(data) { + return request({ + url: '/user/phone-login', + method: 'POST', + data + }) + }, + + register(data) { + return request({ + url: '/user/register', + method: 'POST', + data + }) + }, + + logout() { + return request({ + url: '/user/logout', + method: 'POST' + }) + }, + + switchShop(data) { + return request({ + url: '/user/switch-shop', + method: 'POST', + data + }) + }, + + resetPasswordByPhone(data) { + return request({ + url: '/user/reset-password-by-phone', + method: 'POST', + data + }) + } +} diff --git a/WeChatProgram/api/cart.js b/WeChatProgram/api/cart.js new file mode 100644 index 00000000..4e781b55 --- /dev/null +++ b/WeChatProgram/api/cart.js @@ -0,0 +1,39 @@ +const request = require('../utils/request') + +module.exports = { + addToCart(data) { + return request({ + url: '/cart/add', + method: 'POST', + data + }) + }, + + removeFromCart(productId) { + return request({ + url: `/cart/remove/${productId}`, + method: 'DELETE' + }) + }, + + updateCartQuantity(data) { + return request({ + url: '/cart/update', + method: 'PUT', + data + }) + }, + + getCartList() { + return request({ + url: '/cart/list' + }) + }, + + clearCart() { + return request({ + url: '/cart/clear', + method: 'DELETE' + }) + } +} diff --git a/WeChatProgram/api/coupon.js b/WeChatProgram/api/coupon.js new file mode 100644 index 00000000..74ae6a59 --- /dev/null +++ b/WeChatProgram/api/coupon.js @@ -0,0 +1,23 @@ +const request = require('../utils/request') + +module.exports = { + listUserCoupons(status) { + return request({ + url: '/coupon/user/list', + params: { + status + } + }) + }, + + getAvailableCoupons(productTags, productPrice, shopId) { + return request({ + url: '/coupon/available', + params: { + productTags, + productPrice, + shopId + } + }) + } +} diff --git a/WeChatProgram/api/file.js b/WeChatProgram/api/file.js new file mode 100644 index 00000000..ce367e8b --- /dev/null +++ b/WeChatProgram/api/file.js @@ -0,0 +1,12 @@ +const request = require('../utils/request') + +module.exports = { + getSignedUrl(fileId, expiryTimeInMinutes) { + return request({ + url: `/file/get-signed-url/${fileId}`, + params: { + expiryTimeInMinutes + } + }) + } +} diff --git a/WeChatProgram/api/order.js b/WeChatProgram/api/order.js new file mode 100644 index 00000000..8a915364 --- /dev/null +++ b/WeChatProgram/api/order.js @@ -0,0 +1,24 @@ +const request = require('../utils/request') + +module.exports = { + createOrder(data) { + return request({ + url: '/order/create', + method: 'POST', + data + }) + }, + + getOrderList() { + return request({ + url: '/order/list' + }) + }, + + cancelOrder(orderId) { + return request({ + url: `/order/cancel/${orderId}`, + method: 'PUT' + }) + } +} diff --git a/WeChatProgram/api/product-like.js b/WeChatProgram/api/product-like.js new file mode 100644 index 00000000..c8ff0c9c --- /dev/null +++ b/WeChatProgram/api/product-like.js @@ -0,0 +1,23 @@ +const request = require('../utils/request') + +module.exports = { + likeProduct(productId) { + return request({ + url: `/product-like/like/${productId}`, + method: 'POST' + }) + }, + + unlikeProduct(productId) { + return request({ + url: `/product-like/unlike/${productId}`, + method: 'POST' + }) + }, + + checkLikeStatus(productId) { + return request({ + url: `/product-like/check/${productId}` + }) + } +} diff --git a/WeChatProgram/api/product.js b/WeChatProgram/api/product.js new file mode 100644 index 00000000..4ff93a73 --- /dev/null +++ b/WeChatProgram/api/product.js @@ -0,0 +1,30 @@ +const request = require('../utils/request') + +module.exports = { + getAllProducts() { + return request({ + url: '/product/list/all' + }) + }, + + getProductById(id) { + return request({ + url: `/product/get/${id}` + }) + }, + + getProductsByTag(tag) { + return request({ + url: `/product/list/tag/${encodeURIComponent(tag)}` + }) + }, + + searchProducts(keyword) { + return request({ + url: '/product/list/search', + params: { + keyword + } + }) + } +} diff --git a/WeChatProgram/api/shop.js b/WeChatProgram/api/shop.js new file mode 100644 index 00000000..8ccdf068 --- /dev/null +++ b/WeChatProgram/api/shop.js @@ -0,0 +1,21 @@ +const request = require('../utils/request') + +module.exports = { + getPublicShops() { + return request({ + url: '/shop/list/public' + }) + }, + + getShopsSimple() { + return request({ + url: '/shop/list/simple' + }) + }, + + getShopById(id) { + return request({ + url: `/shop/get/${id}` + }) + } +} diff --git a/WeChatProgram/api/tag.js b/WeChatProgram/api/tag.js new file mode 100644 index 00000000..f7927da0 --- /dev/null +++ b/WeChatProgram/api/tag.js @@ -0,0 +1,9 @@ +const request = require('../utils/request') + +module.exports = { + getAllTags() { + return request({ + url: '/tag/list/all' + }) + } +} diff --git a/WeChatProgram/api/user.js b/WeChatProgram/api/user.js new file mode 100644 index 00000000..c0eac509 --- /dev/null +++ b/WeChatProgram/api/user.js @@ -0,0 +1,63 @@ +const request = require('../utils/request') + +module.exports = { + getUserInfo() { + return request({ + url: '/user/info' + }) + }, + + updateUserInfo(data) { + return request({ + url: '/user/update', + method: 'PUT', + data + }) + }, + + updatePassword(data) { + return request({ + url: '/user/password', + method: 'PUT', + data + }) + }, + + checkAccountAvailability(account) { + return request({ + url: `/user/check/account/${encodeURIComponent(account)}` + }) + }, + + checkLoginAccountAvailability(account) { + return request({ + url: `/user/check/login-account/${encodeURIComponent(account)}` + }) + }, + + getLoginShopsByAccount(account) { + return request({ + url: `/user/check/login-shops/account/${encodeURIComponent(account)}` + }) + }, + + getLoginShopsByPhone(phone) { + return request({ + url: `/user/check/login-shops/phone/${encodeURIComponent(phone)}` + }) + }, + + checkPhoneAvailability(phone) { + return request({ + url: `/user/check/phone/${encodeURIComponent(phone)}` + }) + }, + + sendVerificationCode(data) { + return request({ + url: '/user/send-verification-code', + method: 'POST', + data + }) + } +} diff --git a/WeChatProgram/api/wishlist.js b/WeChatProgram/api/wishlist.js new file mode 100644 index 00000000..0cbcab94 --- /dev/null +++ b/WeChatProgram/api/wishlist.js @@ -0,0 +1,38 @@ +const request = require('../utils/request') + +module.exports = { + addToWishlist(productId) { + return request({ + url: '/wishlist/add', + method: 'POST', + data: { + productId + } + }) + }, + + removeFromWishlist(productId) { + return request({ + url: '/wishlist/remove', + method: 'POST', + data: { + productId + } + }) + }, + + checkWishlist(productId) { + return request({ + url: '/wishlist/check', + params: { + productId + } + }) + }, + + getWishlist() { + return request({ + url: '/wishlist/list' + }) + } +} diff --git a/WeChatProgram/app.js b/WeChatProgram/app.js new file mode 100644 index 00000000..deed6222 --- /dev/null +++ b/WeChatProgram/app.js @@ -0,0 +1,87 @@ +const auth = require('./utils/auth') +const cartApi = require('./api/cart') + +App({ + globalData: { + userInfo: null, + isLoggedIn: false, + cartCount: 0, + pendingProductFilter: null + }, + + onLaunch() { + this.bootstrapSession() + }, + + bootstrapSession() { + const userInfo = auth.getStoredUserInfo() + const isLoggedIn = auth.isLoggedIn() + this.globalData.userInfo = userInfo + this.globalData.isLoggedIn = isLoggedIn + + if (isLoggedIn) { + this.updateCartBadge() + return + } + + this.clearCartBadge() + }, + + setUserSession(payload) { + auth.setSession(payload) + this.globalData.userInfo = auth.getStoredUserInfo() + this.globalData.isLoggedIn = auth.isLoggedIn() + this.updateCartBadge() + }, + + refreshUserInfo(userInfo) { + auth.updateStoredUserInfo(userInfo) + this.globalData.userInfo = userInfo + this.globalData.isLoggedIn = auth.isLoggedIn() + }, + + clearUserSession() { + auth.clearSession() + this.globalData.userInfo = null + this.globalData.isLoggedIn = false + this.clearCartBadge() + }, + + async updateCartBadge() { + if (!auth.isLoggedIn()) { + this.clearCartBadge() + return 0 + } + + try { + const cartList = await cartApi.getCartList() + const count = Array.isArray(cartList) + ? cartList.reduce((sum, item) => sum + Number(item.quantity || 0), 0) + : 0 + + this.globalData.cartCount = count + + if (count > 0) { + wx.setTabBarBadge({ + index: 2, + text: count > 99 ? '99+' : String(count) + }) + } else { + wx.removeTabBarBadge({ index: 2 }) + } + + return count + } catch (error) { + this.clearCartBadge() + return 0 + } + }, + + clearCartBadge() { + this.globalData.cartCount = 0 + wx.removeTabBarBadge({ + index: 2, + fail() {} + }) + } +}) diff --git a/WeChatProgram/app.json b/WeChatProgram/app.json new file mode 100644 index 00000000..00c35001 --- /dev/null +++ b/WeChatProgram/app.json @@ -0,0 +1,70 @@ +{ + "pages": [ + "pages/index/index", + "pages/home/index", + "pages/products/index", + "pages/cart/index", + "pages/profile/index", + "pages/auth/index", + "pages/product-detail/index", + "pages/shop-detail/index", + "pages/orders/index", + "pages/wishlist/index", + "pages/coupons/index", + "pages/settings/index" + ], + "window": { + "navigationBarTextStyle": "black", + "navigationStyle": "custom", + "backgroundTextStyle": "light", + "backgroundColor": "#fff7f8" + }, + "tabBar": { + "color": "#8f7b83", + "selectedColor": "#c6597d", + "backgroundColor": "#fffaf9", + "borderStyle": "black", + "position": "bottom", + "list": [ + { + "pagePath": "pages/home/index", + "text": "\u9996\u9875", + "iconPath": "assets/tabbar/home.png", + "selectedIconPath": "assets/tabbar/home-active.png" + }, + { + "pagePath": "pages/products/index", + "text": "\u4f5c\u54c1", + "iconPath": "assets/tabbar/works.png", + "selectedIconPath": "assets/tabbar/works-active.png" + }, + { + "pagePath": "pages/cart/index", + "text": "\u8d2d\u7269\u8f66", + "iconPath": "assets/tabbar/cart.png", + "selectedIconPath": "assets/tabbar/cart-active.png" + }, + { + "pagePath": "pages/profile/index", + "text": "\u6211\u7684", + "iconPath": "assets/tabbar/profile.png", + "selectedIconPath": "assets/tabbar/profile-active.png" + } + ] + }, + "style": "v2", + "renderer": "skyline", + "rendererOptions": { + "skyline": { + "defaultDisplayBlock": true, + "defaultContentBox": true, + "tagNameStyleIsolation": "legacy", + "disableABTest": true, + "sdkVersionBegin": "3.0.0", + "sdkVersionEnd": "15.255.255" + } + }, + "componentFramework": "glass-easel", + "sitemapLocation": "sitemap.json", + "lazyCodeLoading": "requiredComponents" +} diff --git a/WeChatProgram/app.wxss b/WeChatProgram/app.wxss new file mode 100644 index 00000000..7af11a15 --- /dev/null +++ b/WeChatProgram/app.wxss @@ -0,0 +1,352 @@ +page { + min-height: 100%; + background: + radial-gradient(circle at top right, rgba(255, 205, 219, 0.38), transparent 32%), + linear-gradient(180deg, #fff7f8 0%, #fffdfc 100%); + color: #2d2430; + font-size: 28rpx; +} + +view, +text, +button, +input, +textarea, +scroll-view, +swiper, +swiper-item, +picker, +label, +image { + box-sizing: border-box; +} + +image { + display: block; +} + +button { + margin: 0; + padding: 0; + line-height: 1; + background: transparent; +} + +button::after { + border: 0; +} + +.page-shell { + min-height: 100vh; + padding-bottom: calc(env(safe-area-inset-bottom) + 48rpx); +} + +.page-content { + padding: 24rpx 24rpx 44rpx; +} + +.page-card { + overflow: hidden; + background: #ffffff; + border: 1rpx solid rgba(239, 216, 224, 0.86); + border-radius: 32rpx; + box-shadow: 0 22rpx 56rpx rgba(122, 67, 88, 0.1); +} + +.glass-card { + background: rgba(255, 255, 255, 0.8); + border: 1rpx solid rgba(255, 255, 255, 0.9); + border-radius: 32rpx; + box-shadow: 0 22rpx 56rpx rgba(122, 67, 88, 0.08); +} + +.page-hero { + overflow: hidden; + padding: 34rpx 30rpx; + border-radius: 36rpx; + background: linear-gradient(145deg, #fffdfd 0%, #fff1f5 56%, #ffe8ef 100%); + border: 1rpx solid rgba(244, 214, 224, 0.92); + box-shadow: 0 28rpx 64rpx rgba(122, 67, 88, 0.1); +} + +.hero-kicker { + display: block; + font-size: 22rpx; + font-weight: 700; + letter-spacing: 2rpx; + color: #c6597d; +} + +.hero-title { + display: block; + margin-top: 16rpx; + font-size: 46rpx; + line-height: 1.24; + font-weight: 800; + color: #2d2430; +} + +.hero-desc { + display: block; + margin-top: 16rpx; + font-size: 25rpx; + line-height: 1.8; + color: #7d6872; +} + +.hero-action-row { + display: flex; + flex-wrap: wrap; + gap: 16rpx; + margin-top: 28rpx; +} + +.hero-action { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 196rpx; + height: 76rpx; + padding: 0 28rpx; + border-radius: 999rpx; + font-size: 25rpx; + font-weight: 700; +} + +.hero-action.primary { + background: linear-gradient(135deg, #ff8cb0 0%, #c6597d 100%); + color: #ffffff; +} + +.hero-action.secondary { + background: rgba(255, 255, 255, 0.9); + color: #7a5262; +} + +.section-block { + margin-top: 32rpx; +} + +.section-head { + display: flex; + align-items: flex-end; + justify-content: space-between; + gap: 20rpx; + margin-bottom: 20rpx; +} + +.section-copy { + flex: 1; + min-width: 0; +} + +.section-kicker { + display: block; + font-size: 22rpx; + font-weight: 700; + letter-spacing: 2rpx; + color: #c6597d; +} + +.section-title { + display: block; + font-size: 34rpx; + font-weight: 700; + color: #2d2430; +} + +.section-subtitle { + display: block; + margin-top: 8rpx; + font-size: 24rpx; + line-height: 1.7; + color: #8d7a84; +} + +.section-link { + font-size: 24rpx; + color: #c6597d; + font-weight: 700; +} + +.summary-strip { + display: flex; + gap: 14rpx; + margin-top: 26rpx; +} + +.summary-metric { + flex: 1; + min-width: 0; + padding: 22rpx 20rpx; + border-radius: 24rpx; + background: rgba(255, 255, 255, 0.82); +} + +.summary-label { + display: block; + font-size: 22rpx; + color: #99858e; +} + +.summary-value { + display: block; + margin-top: 10rpx; + font-size: 30rpx; + line-height: 1.35; + font-weight: 800; + color: #2d2430; +} + +.summary-note { + display: block; + margin-top: 8rpx; + font-size: 21rpx; + line-height: 1.6; + color: #a6929b; +} + +.primary-btn { + display: flex; + align-items: center; + justify-content: center; + width: 100%; + height: 92rpx; + border-radius: 999rpx; + background: linear-gradient(135deg, #ff8cb0 0%, #c6597d 100%); + color: #ffffff; + font-size: 30rpx; + font-weight: 700; +} + +.secondary-btn { + display: flex; + align-items: center; + justify-content: center; + width: 100%; + height: 84rpx; + border-radius: 999rpx; + border: 2rpx solid #efd7df; + background: #ffffff; + color: #7a5262; + font-size: 28rpx; + font-weight: 600; +} + +.ghost-btn { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 120rpx; + height: 68rpx; + padding: 0 26rpx; + border-radius: 999rpx; + background: #fdf0f4; + color: #c6597d; + font-size: 24rpx; + font-weight: 600; +} + +.field-label { + display: block; + margin-bottom: 14rpx; + font-size: 26rpx; + color: #5d4b55; + font-weight: 600; +} + +.field-input, +.field-textarea, +.field-picker { + display: flex; + align-items: center; + width: 100%; + min-height: 92rpx; + padding: 0 28rpx; + border-radius: 24rpx; + background: #fbf5f7; + border: 1rpx solid rgba(239, 216, 224, 0.92); + color: #2d2430; + font-size: 28rpx; +} + +.field-textarea { + min-height: 180rpx; + padding: 24rpx 28rpx; +} + +.field-placeholder { + color: #b9a8af; +} + +.status-text { + display: block; + margin-top: 12rpx; + font-size: 22rpx; + line-height: 1.6; +} + +.status-text.success { + color: #2ea36f; +} + +.status-text.error { + color: #d5536f; +} + +.hint-card { + padding: 20rpx 22rpx; + border-radius: 22rpx; + background: #fff8ea; + color: #9b6900; + font-size: 24rpx; + line-height: 1.7; +} + +.empty-card { + display: flex; + flex-direction: column; + align-items: center; + gap: 18rpx; + padding: 68rpx 40rpx; + text-align: center; +} + +.empty-title { + font-size: 34rpx; + font-weight: 700; + color: #2d2430; +} + +.empty-desc { + font-size: 24rpx; + line-height: 1.8; + color: #8d7a84; +} + +.chip, +.soft-chip { + display: inline-flex; + align-items: center; + justify-content: center; + padding: 10rpx 20rpx; + border-radius: 999rpx; + font-size: 22rpx; + font-weight: 600; +} + +.chip { + background: #fce8ef; + color: #c6597d; +} + +.soft-chip { + background: #fbf5f7; + color: #8d7a84; +} + +.divider-line { + width: 100%; + height: 2rpx; + background: #f3e7eb; +} diff --git a/WeChatProgram/assets/tabbar/cart-active.png b/WeChatProgram/assets/tabbar/cart-active.png new file mode 100644 index 00000000..7bcecca6 Binary files /dev/null and b/WeChatProgram/assets/tabbar/cart-active.png differ diff --git a/WeChatProgram/assets/tabbar/cart.png b/WeChatProgram/assets/tabbar/cart.png new file mode 100644 index 00000000..40e96cf9 Binary files /dev/null and b/WeChatProgram/assets/tabbar/cart.png differ diff --git a/WeChatProgram/assets/tabbar/home-active.png b/WeChatProgram/assets/tabbar/home-active.png new file mode 100644 index 00000000..f9bf6807 Binary files /dev/null and b/WeChatProgram/assets/tabbar/home-active.png differ diff --git a/WeChatProgram/assets/tabbar/home.png b/WeChatProgram/assets/tabbar/home.png new file mode 100644 index 00000000..93ace6d6 Binary files /dev/null and b/WeChatProgram/assets/tabbar/home.png differ diff --git a/WeChatProgram/assets/tabbar/profile-active.png b/WeChatProgram/assets/tabbar/profile-active.png new file mode 100644 index 00000000..bcf33522 Binary files /dev/null and b/WeChatProgram/assets/tabbar/profile-active.png differ diff --git a/WeChatProgram/assets/tabbar/profile.png b/WeChatProgram/assets/tabbar/profile.png new file mode 100644 index 00000000..b995cb4f Binary files /dev/null and b/WeChatProgram/assets/tabbar/profile.png differ diff --git a/WeChatProgram/assets/tabbar/works-active.png b/WeChatProgram/assets/tabbar/works-active.png new file mode 100644 index 00000000..1d028ac9 Binary files /dev/null and b/WeChatProgram/assets/tabbar/works-active.png differ diff --git a/WeChatProgram/assets/tabbar/works.png b/WeChatProgram/assets/tabbar/works.png new file mode 100644 index 00000000..61b48e4d Binary files /dev/null and b/WeChatProgram/assets/tabbar/works.png differ diff --git a/WeChatProgram/components/navigation-bar/navigation-bar.js b/WeChatProgram/components/navigation-bar/navigation-bar.js new file mode 100644 index 00000000..bdda59de --- /dev/null +++ b/WeChatProgram/components/navigation-bar/navigation-bar.js @@ -0,0 +1,110 @@ +Component({ + options: { + multipleSlots: true // 在组件定义时的选项中启用多slot支持 + }, + /** + * 组件的属性列表 + */ + properties: { + extClass: { + type: String, + value: '' + }, + title: { + type: String, + value: '' + }, + background: { + type: String, + value: '' + }, + color: { + type: String, + value: '' + }, + back: { + type: Boolean, + value: true + }, + loading: { + type: Boolean, + value: false + }, + homeButton: { + type: Boolean, + value: false, + }, + animated: { + // 显示隐藏的时候opacity动画效果 + type: Boolean, + value: true + }, + show: { + // 显示隐藏导航,隐藏的时候navigation-bar的高度占位还在 + type: Boolean, + value: true, + observer: '_showChange' + }, + // back为true的时候,返回的页面深度 + delta: { + type: Number, + value: 1 + }, + }, + /** + * 组件的初始数据 + */ + data: { + displayStyle: '' + }, + lifetimes: { + attached() { + const rect = wx.getMenuButtonBoundingClientRect() + const platform = (wx.getDeviceInfo() || wx.getSystemInfoSync()).platform + const isAndroid = platform === 'android' + const isDevtools = platform === 'devtools' + const { windowWidth, safeArea: { top = 0, bottom = 0 } = {} } = wx.getWindowInfo() || wx.getSystemInfoSync() + this.setData({ + ios: !isAndroid, + innerPaddingRight: `padding-right: ${windowWidth - rect.left}px`, + leftWidth: `width: ${windowWidth - rect.left}px`, + safeAreaTop: isDevtools || isAndroid ? `height: calc(var(--height) + ${top}px); padding-top: ${top}px` : `` + }) + }, + }, + /** + * 组件的方法列表 + */ + methods: { + _showChange(show) { + const animated = this.data.animated + let displayStyle = '' + if (animated) { + displayStyle = `opacity: ${show ? '1' : '0' + };transition:opacity 0.5s;` + } else { + displayStyle = `display: ${show ? '' : 'none'}` + } + this.setData({ + displayStyle + }) + }, + back() { + const data = this.data + const pages = getCurrentPages() + if (data.delta && pages.length > data.delta) { + wx.navigateBack({ + delta: data.delta + }) + return + } + this.triggerEvent('back', { delta: data.delta }, {}) + }, + home() { + wx.switchTab({ + url: '/pages/home/index' + }) + this.triggerEvent('home', {}, {}) + } + }, +}) diff --git a/WeChatProgram/components/navigation-bar/navigation-bar.json b/WeChatProgram/components/navigation-bar/navigation-bar.json new file mode 100644 index 00000000..4a20f170 --- /dev/null +++ b/WeChatProgram/components/navigation-bar/navigation-bar.json @@ -0,0 +1,5 @@ +{ + "component": true, + "styleIsolation": "apply-shared", + "usingComponents": {} +} \ No newline at end of file diff --git a/WeChatProgram/components/navigation-bar/navigation-bar.wxml b/WeChatProgram/components/navigation-bar/navigation-bar.wxml new file mode 100644 index 00000000..be9a6637 --- /dev/null +++ b/WeChatProgram/components/navigation-bar/navigation-bar.wxml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{title}} + + + + + + + + + + + + diff --git a/WeChatProgram/components/navigation-bar/navigation-bar.wxss b/WeChatProgram/components/navigation-bar/navigation-bar.wxss new file mode 100644 index 00000000..e31640f5 --- /dev/null +++ b/WeChatProgram/components/navigation-bar/navigation-bar.wxss @@ -0,0 +1,99 @@ +.weui-navigation-bar { + --weui-FG-0:rgba(0,0,0,.9); + --height: 44px; + --left: 16px; +} +.weui-navigation-bar .android { + --height: 48px; +} + +.weui-navigation-bar { + overflow: hidden; + color: var(--weui-FG-0); + flex: none; + position: relative; + z-index: 20; +} + +.weui-navigation-bar__inner { + position: relative; + top: 0; + left: 0; + z-index: 1; + height: calc(var(--height) + env(safe-area-inset-top)); + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; + padding-top: env(safe-area-inset-top); + width: 100%; + box-sizing: border-box; +} + +.weui-navigation-bar__left { + position: relative; + padding-left: var(--left); + display: flex; + flex-direction: row; + align-items: flex-start; + height: 100%; + box-sizing: border-box; +} + +.weui-navigation-bar__btn_goback_wrapper { + padding: 11px 18px 11px 16px; + margin: -11px -18px -11px -16px; +} + +.weui-navigation-bar__btn_goback_wrapper.weui-active { + opacity: 0.5; +} + +.weui-navigation-bar__btn_goback { + font-size: 12px; + width: 12px; + height: 24px; + -webkit-mask: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E") no-repeat 50% 50%; + mask: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E") no-repeat 50% 50%; + -webkit-mask-size: cover; + mask-size: cover; + background-color: currentColor; +} + +.weui-navigation-bar__center { + font-size: 17px; + text-align: center; + position: relative; + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; + font-weight: bold; + flex: 1; + height: 100%; +} + +.weui-navigation-bar__loading { + margin-right: 4px; + align-items: center; +} + +.weui-loading { + font-size: 16px; + width: 16px; + height: 16px; + display: block; + background: transparent url("data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg width='80px' height='80px' viewBox='0 0 80 80' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Ctitle%3Eloading%3C/title%3E%3Cdefs%3E%3ClinearGradient x1='94.0869141%25' y1='0%25' x2='94.0869141%25' y2='90.559082%25' id='linearGradient-1'%3E%3Cstop stop-color='%23606060' stop-opacity='0' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3ClinearGradient x1='100%25' y1='8.67370605%25' x2='100%25' y2='90.6286621%25' id='linearGradient-2'%3E%3Cstop stop-color='%23606060' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3C/defs%3E%3Cg stroke='none' stroke-width='1' fill='none' fill-rule='evenodd' opacity='0.9'%3E%3Cg%3E%3Cpath d='M40,0 C62.09139,0 80,17.90861 80,40 C80,62.09139 62.09139,80 40,80 L40,73 C58.2253967,73 73,58.2253967 73,40 C73,21.7746033 58.2253967,7 40,7 L40,0 Z' fill='url(%23linearGradient-1)'%3E%3C/path%3E%3Cpath d='M40,0 L40,7 C21.7746033,7 7,21.7746033 7,40 C7,58.2253967 21.7746033,73 40,73 L40,80 C17.90861,80 0,62.09139 0,40 C0,17.90861 17.90861,0 40,0 Z' fill='url(%23linearGradient-2)'%3E%3C/path%3E%3Ccircle id='Oval' fill='%23606060' cx='40.5' cy='3.5' r='3.5'%3E%3C/circle%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A") no-repeat; + background-size: 100%; + margin-left: 0; + animation: loading linear infinite 1s; +} + +@keyframes loading { + from { + transform: rotate(0); + } + to { + transform: rotate(360deg); + } +} diff --git a/WeChatProgram/components/product-card/product-card.js b/WeChatProgram/components/product-card/product-card.js new file mode 100644 index 00000000..f3945dc6 --- /dev/null +++ b/WeChatProgram/components/product-card/product-card.js @@ -0,0 +1,22 @@ +Component({ + properties: { + item: { + type: Object, + value: {} + }, + showMeta: { + type: Boolean, + value: true + }, + showStats: { + type: Boolean, + value: false + } + }, + + methods: { + handleTap() { + this.triggerEvent('select', this.properties.item) + } + } +}) diff --git a/WeChatProgram/components/product-card/product-card.json b/WeChatProgram/components/product-card/product-card.json new file mode 100644 index 00000000..467ce294 --- /dev/null +++ b/WeChatProgram/components/product-card/product-card.json @@ -0,0 +1,3 @@ +{ + "component": true +} diff --git a/WeChatProgram/components/product-card/product-card.wxml b/WeChatProgram/components/product-card/product-card.wxml new file mode 100644 index 00000000..e61e7ffb --- /dev/null +++ b/WeChatProgram/components/product-card/product-card.wxml @@ -0,0 +1,21 @@ + + + + + {{item.metaText}} + + + {{item.displayTitle}} + {{item.metaText}} + + {{item}} + + + + {{item.priceText}} + {{item.statsText}} + + 查看 + + + diff --git a/WeChatProgram/components/product-card/product-card.wxss b/WeChatProgram/components/product-card/product-card.wxss new file mode 100644 index 00000000..c8430e7d --- /dev/null +++ b/WeChatProgram/components/product-card/product-card.wxss @@ -0,0 +1,119 @@ +.product-card { + display: flex; + flex-direction: column; + overflow: hidden; + border-radius: 30rpx; + background: #ffffff; + border: 1rpx solid rgba(239, 216, 224, 0.84); + box-shadow: 0 18rpx 42rpx rgba(122, 67, 88, 0.08); +} + +.product-cover-wrap { + position: relative; +} + +.product-cover { + width: 100%; + height: 300rpx; + background: #f7ecf0; +} + +.product-cover-shadow { + position: absolute; + left: 0; + right: 0; + bottom: 0; + height: 120rpx; + background: linear-gradient(180deg, rgba(28, 23, 26, 0), rgba(28, 23, 26, 0.28)); +} + +.product-meta-badge { + position: absolute; + left: 18rpx; + top: 18rpx; + max-width: calc(100% - 36rpx); + padding: 10rpx 16rpx; + border-radius: 999rpx; + background: rgba(255, 255, 255, 0.92); + color: #7a5262; + font-size: 20rpx; + font-weight: 700; +} + +.product-body { + display: flex; + flex-direction: column; + gap: 12rpx; + padding: 22rpx 22rpx 24rpx; +} + +.product-title { + font-size: 28rpx; + font-weight: 700; + line-height: 1.5; + color: #2d2430; +} + +.product-meta { + font-size: 24rpx; + color: #8d7a84; + line-height: 1.5; +} + +.product-tags { + display: flex; + flex-wrap: wrap; + gap: 10rpx; +} + +.tag-item { + display: inline-flex; + align-items: center; + justify-content: center; + padding: 8rpx 16rpx; + border-radius: 999rpx; + background: #fbecf1; + color: #c6597d; + font-size: 20rpx; +} + +.product-footer { + display: flex; + align-items: flex-end; + justify-content: space-between; + gap: 16rpx; + margin-top: 4rpx; +} + +.product-price-wrap { + flex: 1; + min-width: 0; +} + +.product-price { + display: block; + font-size: 30rpx; + font-weight: 700; + color: #d5536f; +} + +.product-stats { + display: block; + margin-top: 8rpx; + font-size: 22rpx; + color: #9d8a92; +} + +.product-arrow { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 96rpx; + height: 52rpx; + padding: 0 18rpx; + border-radius: 999rpx; + background: #fff1f5; + color: #c6597d; + font-size: 22rpx; + font-weight: 700; +} diff --git a/WeChatProgram/pages/auth/index.js b/WeChatProgram/pages/auth/index.js new file mode 100644 index 00000000..62a163d6 --- /dev/null +++ b/WeChatProgram/pages/auth/index.js @@ -0,0 +1,562 @@ +const authApi = require('../../api/auth') +const shopApi = require('../../api/shop') +const userApi = require('../../api/user') +const navigation = require('../../utils/navigation') +const { runWithLoading } = require('../../utils/loading') + +const phoneRegex = /^1[3-9]\d{9}$/ + +Page({ + data: { + redirect: '', + activeTab: 'login', + loginType: 'password', + loading: false, + shops: [], + registerShopIndex: -1, + registerShopDisplayName: '', + loginShops: [], + loginShopIndex: -1, + loginShopDisplayName: '', + allowLoginShopless: false, + loginShopMessage: '', + loginAccountStatusText: '', + loginAccountStatusType: '', + registerAccountStatusText: '', + registerAccountStatusType: '', + registerPhoneStatusText: '', + registerPhoneStatusType: '', + countdown: 0, + forgotCountdown: 0, + showResetPanel: false, + form: { + account: '', + password: '', + confirmPassword: '', + nickname: '', + phone: '', + verificationCode: '', + shopId: '', + rememberMe: true + }, + resetForm: { + phone: '', + verificationCode: '', + newPassword: '' + } + }, + + onLoad(options) { + this.setData({ + redirect: options && options.redirect ? options.redirect : '' + }) + this.loadShopOptions() + }, + + async loadShopOptions() { + try { + const shops = await shopApi.getShopsSimple() + this.setData({ + shops: Array.isArray(shops) ? shops : [] + }) + } catch (error) { + wx.showToast({ + title: '门店列表加载失败', + icon: 'none' + }) + } + }, + + handleTabChange(event) { + const tab = event.currentTarget.dataset.tab + this.setData({ + activeTab: tab, + showResetPanel: false, + loginAccountStatusText: '', + loginAccountStatusType: '', + registerAccountStatusText: '', + registerAccountStatusType: '', + registerPhoneStatusText: '', + registerPhoneStatusType: '' + }) + }, + + handleLoginTypeChange(event) { + const type = event.currentTarget.dataset.type + this.setData({ + loginType: type, + loginShops: [], + loginShopIndex: -1, + loginShopDisplayName: '', + allowLoginShopless: false, + loginShopMessage: '', + loginAccountStatusText: '', + loginAccountStatusType: '', + 'form.shopId': '' + }) + }, + + handleToggleResetPanel() { + this.setData({ + showResetPanel: !this.data.showResetPanel + }) + }, + + handleInputChange(event) { + const field = event.currentTarget.dataset.field + this.setData({ + [`form.${field}`]: event.detail.value + }) + }, + + handleResetInputChange(event) { + const field = event.currentTarget.dataset.field + this.setData({ + [`resetForm.${field}`]: event.detail.value + }) + }, + + handleRegisterShopChange(event) { + const index = Number(event.detail.value) + const shop = this.data.shops[index] + this.setData({ + registerShopIndex: index, + registerShopDisplayName: shop ? shop.shopName || shop.name || '' : '', + 'form.shopId': shop ? shop.id : '' + }) + }, + + handleLoginShopChange(event) { + const index = Number(event.detail.value) + const shop = this.data.loginShops[index] + this.setData({ + loginShopIndex: index, + loginShopDisplayName: shop ? shop.shopName || '' : '', + 'form.shopId': shop ? shop.id : '' + }) + }, + + async handleAccountBlur() { + const account = this.data.form.account.trim() + if (!account) { + return + } + + if (this.data.activeTab === 'register') { + await this.checkRegisterAccountAvailability() + return + } + + if (this.data.loginType !== 'password') { + return + } + + await Promise.all([ + this.checkLoginAccountAvailability(), + this.loadLoginShopsByAccount() + ]) + }, + + async handlePhoneBlur() { + const phone = this.data.form.phone.trim() + if (!phone) { + return + } + + if (this.data.activeTab === 'register') { + if (phoneRegex.test(phone)) { + await this.checkRegisterPhoneAvailability() + } + return + } + + if (this.data.loginType !== 'phone' || !phoneRegex.test(phone)) { + return + } + + await this.loadLoginShopsByPhone() + }, + + applyLoginShopSelection(selection) { + const shops = Array.isArray(selection && selection.shops) ? selection.shops : [] + const allowLoginShopless = Boolean(selection && selection.allowShoplessLogin) + let loginShopIndex = -1 + let loginShopDisplayName = '' + let shopId = '' + + if (!allowLoginShopless && shops.length === 1) { + loginShopIndex = 0 + loginShopDisplayName = shops[0].shopName || '' + shopId = shops[0].id + } + + this.setData({ + loginShops: shops, + allowLoginShopless, + loginShopMessage: (selection && selection.message) || '', + loginShopIndex, + loginShopDisplayName, + 'form.shopId': shopId + }) + }, + + async checkLoginAccountAvailability() { + try { + const result = await userApi.checkLoginAccountAvailability(this.data.form.account.trim()) + this.setData({ + loginAccountStatusText: result && result.message ? result.message : '', + loginAccountStatusType: result && result.exists ? 'success' : 'error' + }) + return Boolean(result && result.exists) + } catch (error) { + this.setData({ + loginAccountStatusText: '', + loginAccountStatusType: '' + }) + return false + } + }, + + async loadLoginShopsByAccount() { + try { + const result = await userApi.getLoginShopsByAccount(this.data.form.account.trim()) + this.applyLoginShopSelection(result) + } catch (error) { + this.applyLoginShopSelection({ + allowShoplessLogin: true, + message: '当前环境暂未开启门店预选,可直接登录', + shops: [] + }) + } + }, + + async loadLoginShopsByPhone() { + try { + const result = await userApi.getLoginShopsByPhone(this.data.form.phone.trim()) + this.applyLoginShopSelection(result) + } catch (error) { + this.applyLoginShopSelection({ + allowShoplessLogin: true, + message: '当前环境暂未开启门店预选,可直接登录', + shops: [] + }) + } + }, + + async checkRegisterAccountAvailability() { + try { + const result = await userApi.checkAccountAvailability(this.data.form.account.trim()) + this.setData({ + registerAccountStatusText: result && result.message ? result.message : '', + registerAccountStatusType: result && result.available ? 'success' : 'error' + }) + return Boolean(result && result.available) + } catch (error) { + this.setData({ + registerAccountStatusText: '', + registerAccountStatusType: '' + }) + return false + } + }, + + async checkRegisterPhoneAvailability() { + try { + const result = await userApi.checkPhoneAvailability(this.data.form.phone.trim()) + this.setData({ + registerPhoneStatusText: result && result.message ? result.message : '', + registerPhoneStatusType: result && result.available ? 'success' : 'error' + }) + return Boolean(result && result.available) + } catch (error) { + this.setData({ + registerPhoneStatusText: '', + registerPhoneStatusType: '' + }) + return false + } + }, + + startCountdown(fieldName) { + this.setData({ + [fieldName]: 60 + }) + + const timer = setInterval(() => { + const nextValue = this.data[fieldName] - 1 + this.setData({ + [fieldName]: nextValue + }) + + if (nextValue <= 0) { + clearInterval(timer) + } + }, 1000) + }, + + async handleSendCode() { + if (this.data.countdown > 0) { + return + } + + const phone = this.data.form.phone.trim() + if (!phoneRegex.test(phone)) { + wx.showToast({ + title: '请输入正确的手机号', + icon: 'none' + }) + return + } + + if (this.data.activeTab === 'register') { + const phoneAvailable = await this.checkRegisterPhoneAvailability() + if (!phoneAvailable) { + wx.showToast({ + title: this.data.registerPhoneStatusText || '该手机号已被注册', + icon: 'none' + }) + return + } + } + + try { + await runWithLoading(() => userApi.sendVerificationCode({ + phone + })) + wx.showToast({ + title: '验证码已发送', + icon: 'none' + }) + this.startCountdown('countdown') + } catch (error) { + wx.showToast({ + title: error.message || '验证码发送失败', + icon: 'none' + }) + } + }, + + async handleSendForgotCode() { + if (this.data.forgotCountdown > 0) { + return + } + + const phone = this.data.resetForm.phone.trim() + if (!phoneRegex.test(phone)) { + wx.showToast({ + title: '请输入正确的手机号', + icon: 'none' + }) + return + } + + try { + await runWithLoading(() => authApi.sendVerificationCode({ + phone + })) + wx.showToast({ + title: '验证码已发送', + icon: 'none' + }) + this.startCountdown('forgotCountdown') + } catch (error) { + wx.showToast({ + title: error.message || '验证码发送失败', + icon: 'none' + }) + } + }, + + validateLoginForm() { + const form = this.data.form + if (this.data.loginType === 'password') { + if (!form.account.trim() || !form.password) { + return '请输入账号和密码' + } + } else if (!phoneRegex.test(form.phone.trim()) || !form.verificationCode.trim()) { + return '请输入正确的手机号和验证码' + } + + if (!this.data.allowLoginShopless && this.data.loginShops.length && !form.shopId) { + return '请选择登录门店' + } + + return '' + }, + + async validateRegisterForm() { + const form = this.data.form + if (!form.nickname.trim()) { + return '请输入昵称' + } + if (!form.account.trim()) { + return '请输入账号' + } + if (!phoneRegex.test(form.phone.trim())) { + return '请输入正确的手机号' + } + if (!form.verificationCode.trim()) { + return '请输入验证码' + } + if (!form.password || form.password.length < 6) { + return '密码至少 6 位' + } + if (form.password !== form.confirmPassword) { + return '两次输入的密码不一致' + } + if (!form.shopId) { + return '请选择门店' + } + + const [accountAvailable, phoneAvailable] = await Promise.all([ + this.checkRegisterAccountAvailability(), + this.checkRegisterPhoneAvailability() + ]) + + if (!accountAvailable || !phoneAvailable) { + return '请先处理注册信息中的占用问题' + } + + return '' + }, + + async handleSubmit() { + this.setData({ + loading: true + }) + + try { + if (this.data.activeTab === 'login') { + const loginError = this.validateLoginForm() + if (loginError) { + throw new Error(loginError) + } + + let payload + await runWithLoading(async () => { + payload = this.data.loginType === 'phone' + ? await authApi.phoneLogin({ + phone: this.data.form.phone.trim(), + verificationCode: this.data.form.verificationCode.trim(), + shopId: this.data.form.shopId || undefined + }) + : await authApi.login({ + account: this.data.form.account.trim(), + password: this.data.form.password, + rememberMe: true, + shopId: this.data.form.shopId || undefined + }) + }) + + getApp().setUserSession(payload) + wx.showToast({ + title: '登录成功', + icon: 'none' + }) + + try { + await navigation.redirectAfterLogin(this.data.redirect) + } catch (redirectError) { + console.error('登录后跳转失败,已回退到首页:', redirectError) + await navigation.switchTab('/pages/home/index') + } + + return + } + + const registerError = await this.validateRegisterForm() + if (registerError) { + throw new Error(registerError) + } + + await runWithLoading(() => authApi.register({ + account: this.data.form.account.trim(), + password: this.data.form.password, + nickname: this.data.form.nickname.trim(), + phone: this.data.form.phone.trim(), + verificationCode: this.data.form.verificationCode.trim(), + shopId: this.data.form.shopId + })) + + wx.showToast({ + title: '注册成功,请登录', + icon: 'none' + }) + + this.setData({ + activeTab: 'login', + loginType: 'password', + 'form.password': '', + 'form.confirmPassword': '', + 'form.verificationCode': '' + }) + } catch (error) { + wx.showToast({ + title: error.message || (this.data.activeTab === 'login' ? '登录失败' : '注册失败'), + icon: 'none' + }) + } finally { + this.setData({ + loading: false + }) + } + }, + + async handleResetPassword() { + const form = this.data.resetForm + if (!phoneRegex.test(form.phone.trim())) { + wx.showToast({ + title: '请输入正确的手机号', + icon: 'none' + }) + return + } + if (!form.verificationCode.trim()) { + wx.showToast({ + title: '请输入验证码', + icon: 'none' + }) + return + } + if (!form.newPassword || form.newPassword.length < 6) { + wx.showToast({ + title: '新密码至少 6 位', + icon: 'none' + }) + return + } + + this.setData({ + loading: true + }) + + try { + await runWithLoading(() => authApi.resetPasswordByPhone({ + phone: form.phone.trim(), + verificationCode: form.verificationCode.trim(), + newPassword: form.newPassword + })) + wx.showToast({ + title: '密码已重置,请重新登录', + icon: 'none' + }) + this.setData({ + showResetPanel: false, + resetForm: { + phone: '', + verificationCode: '', + newPassword: '' + } + }) + } catch (error) { + wx.showToast({ + title: error.message || '密码重置失败', + icon: 'none' + }) + } finally { + this.setData({ + loading: false + }) + } + } +}) diff --git a/WeChatProgram/pages/auth/index.json b/WeChatProgram/pages/auth/index.json new file mode 100644 index 00000000..8632c9b0 --- /dev/null +++ b/WeChatProgram/pages/auth/index.json @@ -0,0 +1,5 @@ +{ + "usingComponents": { + "navigation-bar": "/components/navigation-bar/navigation-bar" + } +} diff --git a/WeChatProgram/pages/auth/index.wxml b/WeChatProgram/pages/auth/index.wxml new file mode 100644 index 00000000..1c4c0653 --- /dev/null +++ b/WeChatProgram/pages/auth/index.wxml @@ -0,0 +1,132 @@ + + + + + + YUMI NAIL + {{activeTab === 'login' ? '登录后继续预约与收藏' : '注册账号,开始你的美甲旅程'}} + 支持账号密码或手机验证码,绑定门店后,下单和查看记录都会更顺手。 + + + + 收藏同步 + 喜欢的作品随时可回看 + + + 预约顺手 + 登录后直接补全预约信息 + + + 门店绑定 + 注册时即可关联常用门店 + + + + + + + 登录 + 注册 + + + + 账号密码登录 + 验证码登录 + + + + {{activeTab === 'login' ? (loginType === 'password' ? '输入账号和密码即可登录。' : '手机号登录时会发送短信验证码。') : '注册前会实时检查账号和手机号是否已被占用。'}} + + + + + 昵称 + + + + + + 账号 + + {{loginAccountStatusText}} + {{registerAccountStatusText}} + + + + 手机号 + + {{registerPhoneStatusText}} + + + + 密码 + + + + + 验证码 + + + {{countdown > 0 ? countdown + 's' : '发送验证码'}} + + + + + 密码 + + + + + 确认密码 + + + + + 选择门店 + + {{registerShopDisplayName || '请选择门店'}} + + + + + 选择登录门店 + + {{loginShopDisplayName || '请选择登录门店'}} + + + + + + + 忘记密码? + + + {{activeTab === 'login' ? '立即登录' : '完成注册'}} + + + + 重置密码 + 使用手机验证码设置新的登录密码。 + + + 手机号 + + + + + 验证码 + + + {{forgotCountdown > 0 ? forgotCountdown + 's' : '发送验证码'}} + + + + + 新密码 + + + + 确认重置密码 + + + diff --git a/WeChatProgram/pages/auth/index.wxss b/WeChatProgram/pages/auth/index.wxss new file mode 100644 index 00000000..228f0e1a --- /dev/null +++ b/WeChatProgram/pages/auth/index.wxss @@ -0,0 +1,154 @@ +.auth-page { + background: + radial-gradient(circle at top right, rgba(255, 204, 219, 0.4), transparent 30%), + linear-gradient(180deg, #fff7f8 0%, #fffdfb 100%); +} + +.auth-content { + padding-top: 12rpx; +} + +.auth-hero { + background: + radial-gradient(circle at top right, rgba(255, 190, 209, 0.44), transparent 34%), + linear-gradient(145deg, #fffdfd 0%, #fff2f6 58%, #ffe8ef 100%); +} + +.auth-benefits { + display: flex; + gap: 14rpx; + margin-top: 28rpx; +} + +.auth-benefit { + flex: 1; + min-width: 0; + padding: 20rpx 18rpx; + border-radius: 24rpx; + background: rgba(255, 255, 255, 0.82); +} + +.auth-benefit-title { + display: block; + font-size: 24rpx; + font-weight: 700; + color: #2d2430; +} + +.auth-benefit-desc { + display: block; + margin-top: 10rpx; + font-size: 21rpx; + line-height: 1.6; + color: #8d7a84; +} + +.auth-card, +.reset-card { + padding: 28rpx; +} + +.auth-card { + margin-top: 24rpx; +} + +.reset-card { + margin-top: 24rpx; +} + +.tab-row, +.toggle-row { + display: flex; + align-items: center; + gap: 12rpx; +} + +.tab-row { + margin-bottom: 22rpx; +} + +.toggle-row { + margin-bottom: 18rpx; + padding: 10rpx; + border-radius: 999rpx; + background: #fbf5f7; +} + +.tab-item, +.toggle-item { + display: flex; + align-items: center; + justify-content: center; + flex: 1; + height: 76rpx; + border-radius: 999rpx; + color: #8d7a84; + font-size: 26rpx; + font-weight: 600; +} + +.tab-item.active, +.toggle-item.active { + background: #fde8ef; + color: #c6597d; +} + +.auth-helper { + margin-bottom: 10rpx; + font-size: 23rpx; + line-height: 1.7; + color: #8d7a84; +} + +.field-block { + margin-top: 18rpx; +} + +.code-row { + display: flex; + align-items: center; + gap: 14rpx; +} + +.code-input { + flex: 1; +} + +.code-btn { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 180rpx; + height: 92rpx; + padding: 0 18rpx; + border-radius: 24rpx; + background: #fde8ef; + color: #c6597d; + font-size: 24rpx; + font-weight: 700; +} + +.code-btn.disabled { + background: #f3e7eb; + color: #a998a0; +} + +.aux-row { + display: flex; + justify-content: flex-end; + margin-top: 20rpx; +} + +.aux-link { + font-size: 24rpx; + color: #c6597d; + font-weight: 600; +} + +.login-shop-tip { + margin-top: 18rpx; +} + +.submit-btn { + margin-top: 28rpx; +} diff --git a/WeChatProgram/pages/cart/index.js b/WeChatProgram/pages/cart/index.js new file mode 100644 index 00000000..46f635d3 --- /dev/null +++ b/WeChatProgram/pages/cart/index.js @@ -0,0 +1,496 @@ +const cartApi = require('../../api/cart') +const couponApi = require('../../api/coupon') +const orderApi = require('../../api/order') +const auth = require('../../utils/auth') +const navigation = require('../../utils/navigation') +const { resolveLegacyImage } = require('../../utils/file') +const { NO_COUPON_KEY } = require('../../utils/config') +const { runWithLoading } = require('../../utils/loading') +const { + buildAppointmentValue, + formatDateTime, + formatPrice, + getMinDateText, + isPastAppointment, + parseAppointmentParts +} = require('../../utils/format') + +function getCouponKey(coupon) { + return `${coupon.sourceType || 'USER_COUPON'}:${coupon.id}` +} + +function getCouponDisplay(coupon) { + if (Number(coupon.couponType) === 1) { + return `${coupon.couponName} ${coupon.discountValue} 折` + } + return `${coupon.couponName} 满 ${coupon.minAmount} 减 ${coupon.reduceAmount}` +} + +function calculateCouponDiscount(coupon, amount) { + if (!coupon || amount <= 0) { + return 0 + } + + if (Number(coupon.couponType) === 1) { + const discountValue = Number(coupon.discountValue || 0) + return discountValue ? amount - amount * discountValue / 10 : 0 + } + + if (Number(coupon.couponType) === 2) { + return Number(coupon.reduceAmount || 0) + } + + return 0 +} + +function buildCheckoutIssues(items) { + const issues = [] + const selectedItems = items.filter(item => item.selected) + + if (!selectedItems.length) { + issues.push('请先勾选要结算的作品') + return issues + } + + const missingArtist = selectedItems.find(item => !item.artistId) + if (missingArtist) { + issues.push(`请先为“${missingArtist.productTitle}”选择美甲师`) + } + + const missingTime = selectedItems.find(item => !item.appointmentValue) + if (missingTime) { + issues.push(`请先为“${missingTime.productTitle}”选择预约时间`) + } + + const expiredTime = selectedItems.find(item => item.appointmentValue && isPastAppointment(item.appointmentValue)) + if (expiredTime) { + issues.push(`“${expiredTime.productTitle}”的预约时间已过,请重新选择`) + } + + const shopIds = Array.from(new Set(selectedItems.map(item => item.shopId).filter(Boolean))) + if (shopIds.length > 1) { + issues.push('跨门店作品请分开结算') + } + + const artistIds = Array.from(new Set(selectedItems.map(item => item.artistId).filter(Boolean))) + if (artistIds.length > 1) { + issues.push('不同美甲师的项目请分开结算') + } + + return issues +} + +Page({ + data: { + isLoggedIn: false, + loading: false, + minDate: getMinDateText(), + cartItems: [], + availableCoupons: [], + selectedCouponKey: NO_COUPON_KEY, + selectedCount: 0, + totalQuantity: 0, + subtotalAmount: 0, + subtotalText: '¥0.00', + discountAmountText: '¥0.00', + totalAmountText: '¥0.00', + checkoutIssues: [] + }, + + onShow() { + this.loadCartItems() + }, + + async onPullDownRefresh() { + await this.loadCartItems() + wx.stopPullDownRefresh() + }, + + getSelectedItems() { + return this.data.cartItems.filter(item => item.selected) + }, + + getSelectedCoupon() { + return this.data.availableCoupons.find(item => item.key === this.data.selectedCouponKey) || null + }, + + refreshSummary() { + const selectedItems = this.getSelectedItems() + const selectedCoupon = this.getSelectedCoupon() + const selectedCount = selectedItems.length + const totalQuantity = selectedItems.reduce((sum, item) => sum + Number(item.quantity || 0), 0) + const subtotalAmount = selectedItems.reduce((sum, item) => sum + Number(item.price || 0) * Number(item.quantity || 0), 0) + const discountAmount = calculateCouponDiscount(selectedCoupon, subtotalAmount) + const totalAmount = Math.max(0, subtotalAmount - discountAmount) + const checkoutIssues = buildCheckoutIssues(this.data.cartItems) + + this.setData({ + selectedCount, + totalQuantity, + subtotalAmount, + subtotalText: `¥${formatPrice(subtotalAmount)}`, + discountAmountText: `¥${formatPrice(discountAmount)}`, + totalAmountText: `¥${formatPrice(totalAmount)}`, + checkoutIssues + }) + }, + + async loadCartItems() { + const isLoggedIn = auth.isLoggedIn() + this.setData({ + isLoggedIn, + loading: isLoggedIn + }) + + if (!isLoggedIn) { + this.setData({ + cartItems: [], + availableCoupons: [], + selectedCouponKey: NO_COUPON_KEY, + loading: false + }) + this.refreshSummary() + return + } + + try { + const cartItems = await cartApi.getCartList() + const list = Array.isArray(cartItems) ? cartItems : [] + const formattedItems = await Promise.all(list.map(async item => { + const appointmentParts = parseAppointmentParts(item.appointmentTime) + const productImageUrl = await resolveLegacyImage(item.productImage) + const availableArtists = Array.isArray(item.availableArtists) ? item.availableArtists.map(artist => ({ + id: artist.id, + name: artist.name, + avatar: artist.avatar + })) : [] + const artist = availableArtists.find(current => String(current.id) === String(item.artistId || '')) + + return { + ...item, + productImageUrl, + priceText: `¥${formatPrice(item.price)}`, + selected: true, + artistId: item.artistId || '', + artistName: artist ? artist.name : '', + availableArtists, + appointmentDate: appointmentParts.date, + appointmentClock: appointmentParts.clock, + appointmentValue: buildAppointmentValue(appointmentParts.date, appointmentParts.clock) + } + })) + + this.setData({ + cartItems: formattedItems, + selectedCouponKey: NO_COUPON_KEY + }) + await this.loadAvailableCoupons() + } catch (error) { + this.setData({ + cartItems: [] + }) + wx.showToast({ + title: error.message || '购物车加载失败', + icon: 'none' + }) + } finally { + this.setData({ + loading: false + }) + this.refreshSummary() + } + }, + + async loadAvailableCoupons() { + const selectedItems = this.getSelectedItems() + if (!selectedItems.length) { + this.setData({ + availableCoupons: [], + selectedCouponKey: NO_COUPON_KEY + }) + this.refreshSummary() + return + } + + const tags = new Set() + const subtotalAmount = selectedItems.reduce((sum, item) => sum + Number(item.price || 0) * Number(item.quantity || 0), 0) + selectedItems.forEach(item => { + String(item.tagNames || '') + .split(',') + .map(tag => tag.trim()) + .filter(Boolean) + .forEach(tag => tags.add(tag)) + }) + + try { + const coupons = await couponApi.getAvailableCoupons( + Array.from(tags).join(','), + subtotalAmount, + selectedItems[0].shopId + ) + + const list = Array.isArray(coupons) ? coupons.map(item => ({ + ...item, + key: getCouponKey(item), + displayText: getCouponDisplay(item) + })) : [] + + let selectedCouponKey = this.data.selectedCouponKey + if (selectedCouponKey !== NO_COUPON_KEY && !list.find(item => item.key === selectedCouponKey)) { + selectedCouponKey = NO_COUPON_KEY + } + + if (selectedCouponKey === NO_COUPON_KEY) { + const vipCoupons = list + .filter(item => item.sourceType === 'SYSTEM_VIP') + .sort((left, right) => calculateCouponDiscount(right, subtotalAmount) - calculateCouponDiscount(left, subtotalAmount)) + if (vipCoupons.length) { + selectedCouponKey = vipCoupons[0].key + } + } + + this.setData({ + availableCoupons: list, + selectedCouponKey + }) + } catch (error) { + this.setData({ + availableCoupons: [], + selectedCouponKey: NO_COUPON_KEY + }) + } finally { + this.refreshSummary() + } + }, + + handleOpenAuth() { + navigation.openAuth('/pages/cart/index') + }, + + handleBrowseProducts() { + navigation.switchTab('/pages/products/index') + }, + + async handleToggleSelect(event) { + const index = Number(event.currentTarget.dataset.index) + const cartItems = this.data.cartItems.slice() + const item = cartItems[index] + if (!item) { + return + } + item.selected = !item.selected + this.setData({ + cartItems + }) + + if (cartItems.some(current => current.selected)) { + await runWithLoading(() => this.loadAvailableCoupons()) + return + } + + await this.loadAvailableCoupons() + }, + + async handleChangeQuantity(event) { + const index = Number(event.currentTarget.dataset.index) + const delta = Number(event.currentTarget.dataset.delta) + const cartItems = this.data.cartItems.slice() + const item = cartItems[index] + if (!item) { + return + } + + const nextQuantity = Number(item.quantity || 0) + delta + if (nextQuantity < 1 || nextQuantity > 99) { + return + } + + item.quantity = nextQuantity + this.setData({ + cartItems + }) + this.refreshSummary() + + try { + await runWithLoading(async () => { + await cartApi.updateCartQuantity({ + productId: item.productId, + quantity: nextQuantity + }) + await this.loadAvailableCoupons() + }) + await getApp().updateCartBadge() + } catch (error) { + item.quantity -= delta + this.setData({ + cartItems + }) + this.refreshSummary() + wx.showToast({ + title: error.message || '数量更新失败', + icon: 'none' + }) + } + }, + + async handleRemoveItem(event) { + const index = Number(event.currentTarget.dataset.index) + const cartItems = this.data.cartItems.slice() + const item = cartItems[index] + if (!item) { + return + } + + const confirmed = await new Promise(resolve => { + wx.showModal({ + title: '移除作品', + content: '确认从购物车移除这件作品吗?', + success: res => resolve(Boolean(res.confirm)) + }) + }) + + if (!confirmed) { + return + } + + try { + await runWithLoading(() => cartApi.removeFromCart(item.productId)) + wx.showToast({ + title: '已移出购物车', + icon: 'none' + }) + await getApp().updateCartBadge() + this.loadCartItems() + } catch (error) { + wx.showToast({ + title: error.message || '移除失败', + icon: 'none' + }) + } + }, + + handleOpenProduct(event) { + const productId = event.currentTarget.dataset.productId + if (!productId) { + return + } + + navigation.navigate('/pages/product-detail/index', { + id: productId + }) + }, + + async handleChooseArtist(event) { + const index = Number(event.currentTarget.dataset.index) + const cartItems = this.data.cartItems.slice() + const item = cartItems[index] + if (!item) { + return + } + + if (!item.availableArtists.length) { + wx.showToast({ + title: '当前作品暂时没有可预约美甲师', + icon: 'none' + }) + return + } + + const tapIndex = await new Promise(resolve => { + wx.showActionSheet({ + itemList: item.availableArtists.map(artist => artist.name), + success: res => resolve(res.tapIndex), + fail: () => resolve(-1) + }) + }) + + if (tapIndex < 0 || tapIndex >= item.availableArtists.length) { + return + } + + const artist = item.availableArtists[tapIndex] + item.artistId = artist.id + item.artistName = artist.name + this.setData({ + cartItems + }) + this.refreshSummary() + }, + + handleDateChange(event) { + const index = Number(event.currentTarget.dataset.index) + const cartItems = this.data.cartItems.slice() + const item = cartItems[index] + if (!item) { + return + } + + item.appointmentDate = event.detail.value + item.appointmentValue = buildAppointmentValue(item.appointmentDate, item.appointmentClock) + this.setData({ + cartItems + }) + this.refreshSummary() + }, + + handleTimeChange(event) { + const index = Number(event.currentTarget.dataset.index) + const cartItems = this.data.cartItems.slice() + const item = cartItems[index] + if (!item) { + return + } + + item.appointmentClock = event.detail.value + item.appointmentValue = buildAppointmentValue(item.appointmentDate, item.appointmentClock) + this.setData({ + cartItems + }) + this.refreshSummary() + }, + + handleCouponChange(event) { + this.setData({ + selectedCouponKey: event.detail.value + }) + this.refreshSummary() + }, + + async handleCheckout() { + const selectedItems = this.getSelectedItems() + const checkoutIssues = buildCheckoutIssues(this.data.cartItems) + if (checkoutIssues.length) { + wx.showToast({ + title: checkoutIssues[0], + icon: 'none' + }) + return + } + + try { + const selectedCoupon = this.getSelectedCoupon() + await runWithLoading(() => orderApi.createOrder({ + couponId: selectedCoupon ? selectedCoupon.id : undefined, + couponSourceType: selectedCoupon ? selectedCoupon.sourceType : (this.data.selectedCouponKey === NO_COUPON_KEY ? NO_COUPON_KEY : undefined), + items: selectedItems.map(item => ({ + productId: item.productId, + quantity: item.quantity, + artistId: item.artistId, + appointmentTime: item.appointmentValue + })) + })) + wx.showToast({ + title: '订单创建成功', + icon: 'none' + }) + await getApp().updateCartBadge() + await this.loadCartItems() + navigation.navigate('/pages/orders/index') + } catch (error) { + wx.showToast({ + title: error.message || '订单创建失败', + icon: 'none' + }) + } + } +}) diff --git a/WeChatProgram/pages/cart/index.json b/WeChatProgram/pages/cart/index.json new file mode 100644 index 00000000..c1f072ae --- /dev/null +++ b/WeChatProgram/pages/cart/index.json @@ -0,0 +1,6 @@ +{ + "usingComponents": { + "navigation-bar": "/components/navigation-bar/navigation-bar" + }, + "enablePullDownRefresh": true +} diff --git a/WeChatProgram/pages/cart/index.wxml b/WeChatProgram/pages/cart/index.wxml new file mode 100644 index 00000000..e34d70f5 --- /dev/null +++ b/WeChatProgram/pages/cart/index.wxml @@ -0,0 +1,159 @@ + + + + + + 登录后查看购物车 + 把喜欢的作品加进购物车后,就能补全预约信息并提交订单。 + 去登录 + + + + + 结算准备 + 已选 {{selectedCount}} 个预约项目 + 先确认美甲师和预约时间,再统一提交订单,避免来回修改。 + + + + 选中项目 + {{selectedCount}} 项 + 可分批勾选结算 + + + 数量合计 + {{totalQuantity}} 件 + 支持直接增减数量 + + + 待支付 + {{totalAmountText}} + 已自动计算优惠 + + + + + + 下单前还需要完善 + {{index + 1}}. {{item}} + + + + + + + + + {{item.productTitle}} + {{item.priceText}} + + + {{item.selected ? '已选中' : '未选中'}} + 预计时长 {{item.approximateDuration}} + + + + + + + 美甲师 + {{item.artistName || '请选择美甲师'}} + + + + + + 日期 + {{item.appointmentDate || '选择日期'}} + + + + + + 时间 + {{item.appointmentClock || '选择时间'}} + + + + + + 当前预约:{{item.appointmentValue}} + + + + + + - + {{item.quantity}} + + + + 移除 + + + + + 优惠方式 + 系统会优先帮你匹配最合适的 VIP 自动折扣,普通优惠券仍可手动改选。 + + + + + + + + + + + 选中项目 + {{selectedCount}} 项 + + + 作品数量 + {{totalQuantity}} 件 + + + 小计 + {{subtotalText}} + + + 优惠 + -{{discountAmountText}} + + + 合计 + {{totalAmountText}} + + + + + + 正在加载购物车 + + + + 购物车还是空的 + 先把喜欢的作品加进来,再补充预约时间和美甲师。 + 去逛作品 + + + + + + {{totalAmountText}} + 已选 {{selectedCount}} 项 + + 提交订单 + + diff --git a/WeChatProgram/pages/cart/index.wxss b/WeChatProgram/pages/cart/index.wxss new file mode 100644 index 00000000..32d4e9b4 --- /dev/null +++ b/WeChatProgram/pages/cart/index.wxss @@ -0,0 +1,326 @@ +.cart-page { + padding-bottom: calc(env(safe-area-inset-bottom) + 150rpx); +} + +.cart-content { + padding-bottom: 20rpx; +} + +.cart-hero { + background: + radial-gradient(circle at top right, rgba(255, 192, 210, 0.42), transparent 34%), + linear-gradient(145deg, #fffdfd 0%, #fff2f6 56%, #ffe7ef 100%); +} + +.issue-card { + margin-top: 20rpx; + margin-bottom: 20rpx; + padding: 22rpx 24rpx; + border-radius: 24rpx; + background: #fff7e8; + color: #9b6900; +} + +.issue-title { + font-size: 28rpx; + font-weight: 700; +} + +.issue-item { + margin-top: 10rpx; + font-size: 24rpx; + line-height: 1.7; +} + +.cart-item-card + .cart-item-card, +.coupon-card, +.summary-card { + margin-top: 20rpx; +} + +.cart-item-card { + padding: 24rpx; +} + +.cart-item-top { + display: flex; + align-items: flex-start; + gap: 16rpx; +} + +.select-dot { + width: 34rpx; + height: 34rpx; + margin-top: 8rpx; + border-radius: 50%; + border: 4rpx solid #d8c4cc; +} + +.select-dot.active { + border-color: #c6597d; + background: #c6597d; +} + +.cart-thumb { + width: 140rpx; + height: 140rpx; + border-radius: 22rpx; + background: #f6edf1; +} + +.cart-main { + flex: 1; +} + +.cart-title-row { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 16rpx; +} + +.cart-title { + flex: 1; + min-width: 0; + font-size: 30rpx; + font-weight: 700; + line-height: 1.5; + color: #2d2430; +} + +.cart-price { + font-size: 30rpx; + font-weight: 700; + color: #d5536f; +} + +.cart-meta-row { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 12rpx; + margin-top: 12rpx; +} + +.meta-chip { + display: inline-flex; + align-items: center; + justify-content: center; + height: 42rpx; + padding: 0 16rpx; + border-radius: 999rpx; + background: #fff1f5; + color: #c6597d; + font-size: 20rpx; + font-weight: 700; +} + +.cart-meta { + font-size: 24rpx; + color: #8d7a84; +} + +.selector-group { + margin-top: 24rpx; +} + +.selector-row { + display: flex; + align-items: center; + justify-content: space-between; + min-height: 76rpx; + padding: 0 22rpx; + border-radius: 20rpx; + background: #fbf5f7; +} + +.selector-row.compact { + min-height: 72rpx; +} + +.selector-row.issue { + background: #fff7e8; +} + +.selector-label { + font-size: 24rpx; + color: #8d7a84; +} + +.selector-value { + font-size: 24rpx; + color: #2d2430; + font-weight: 600; +} + +.time-grid { + display: flex; + gap: 14rpx; + margin-top: 14rpx; +} + +.time-grid picker { + flex: 1; +} + +.appointment-preview { + margin-top: 14rpx; + font-size: 24rpx; + color: #8d7a84; +} + +.cart-item-foot { + display: flex; + align-items: center; + justify-content: space-between; + margin-top: 24rpx; +} + +.qty-box { + display: flex; + align-items: center; + gap: 16rpx; +} + +.qty-btn { + display: inline-flex; + align-items: center; + justify-content: center; + width: 56rpx; + height: 56rpx; + border-radius: 50%; + background: #fbf5f7; + color: #7a5262; + font-size: 34rpx; +} + +.qty-value { + min-width: 48rpx; + text-align: center; + font-size: 28rpx; + font-weight: 700; + color: #2d2430; +} + +.remove-btn { + font-size: 24rpx; + color: #d5536f; + font-weight: 700; +} + +.coupon-card, +.summary-card { + padding: 26rpx; +} + +.coupon-option { + display: flex; + align-items: center; + gap: 18rpx; + margin-top: 20rpx; + padding: 20rpx 0; + border-top: 2rpx solid #f6eaee; +} + +.coupon-option:first-child { + border-top: 0; + padding-top: 10rpx; +} + +.coupon-option.active { + color: #c6597d; +} + +.coupon-texts { + flex: 1; +} + +.coupon-name { + font-size: 26rpx; + font-weight: 700; + color: #2d2430; +} + +.coupon-desc { + margin-top: 8rpx; + font-size: 22rpx; + color: #8d7a84; +} + +.coupon-tag { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 92rpx; + height: 44rpx; + padding: 0 14rpx; + border-radius: 999rpx; + background: #fff1f5; + color: #c6597d; + font-size: 20rpx; + font-weight: 700; +} + +.summary-row { + display: flex; + align-items: center; + justify-content: space-between; + padding: 10rpx 0; + font-size: 26rpx; + color: #5d4b55; +} + +.summary-row.total { + margin-top: 10rpx; + padding-top: 18rpx; + border-top: 2rpx solid #f3e7eb; + font-size: 30rpx; + font-weight: 700; + color: #2d2430; +} + +.checkout-bar { + position: fixed; + left: 24rpx; + right: 24rpx; + bottom: calc(env(safe-area-inset-bottom) + 20rpx); + z-index: 20; + display: flex; + align-items: center; + justify-content: space-between; + gap: 20rpx; + padding: 18rpx 20rpx; + border-radius: 30rpx; + background: rgba(255, 255, 255, 0.98); + box-shadow: 0 18rpx 50rpx rgba(122, 67, 88, 0.12); +} + +.checkout-copy { + flex: 1; +} + +.checkout-total { + font-size: 36rpx; + font-weight: 800; + color: #d5536f; +} + +.checkout-meta { + margin-top: 8rpx; + font-size: 22rpx; + color: #8d7a84; +} + +.checkout-btn { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 220rpx; + height: 84rpx; + padding: 0 26rpx; + border-radius: 999rpx; + background: linear-gradient(135deg, #ff8cb0 0%, #c6597d 100%); + color: #ffffff; + font-size: 28rpx; + font-weight: 700; +} diff --git a/WeChatProgram/pages/coupons/index.js b/WeChatProgram/pages/coupons/index.js new file mode 100644 index 00000000..0815734a --- /dev/null +++ b/WeChatProgram/pages/coupons/index.js @@ -0,0 +1,72 @@ +const couponApi = require('../../api/coupon') +const auth = require('../../utils/auth') +const navigation = require('../../utils/navigation') + +function getBenefitText(coupon) { + if (Number(coupon.couponType) === 1) { + return `${coupon.discountValue} 折` + } + return `满 ${coupon.minAmount} 减 ${coupon.reduceAmount}` +} + +Page({ + data: { + loading: false, + isLoggedIn: false, + coupons: [] + }, + + onShow() { + this.loadCoupons() + }, + + async loadCoupons() { + const isLoggedIn = auth.isLoggedIn() + this.setData({ + isLoggedIn, + loading: isLoggedIn + }) + + if (!isLoggedIn) { + this.setData({ + coupons: [], + loading: false + }) + return + } + + try { + const coupons = await couponApi.listUserCoupons() + const list = Array.isArray(coupons) ? coupons.map(item => ({ + ...item, + benefitText: getBenefitText(item), + periodText: `${String(item.startTime || '').slice(0, 10)} - ${String(item.endTime || '').slice(0, 10)}`, + sourceText: item.sourceType === 'SYSTEM_VIP' ? 'VIP 自动匹配' : '用户优惠券' + })) : [] + + this.setData({ + coupons: list + }) + } catch (error) { + this.setData({ + coupons: [] + }) + wx.showToast({ + title: error.message || '优惠券加载失败', + icon: 'none' + }) + } finally { + this.setData({ + loading: false + }) + } + }, + + handleOpenAuth() { + navigation.openAuth('/pages/coupons/index') + }, + + handleBack() { + navigation.goBack('/pages/profile/index') + } +}) diff --git a/WeChatProgram/pages/coupons/index.json b/WeChatProgram/pages/coupons/index.json new file mode 100644 index 00000000..8632c9b0 --- /dev/null +++ b/WeChatProgram/pages/coupons/index.json @@ -0,0 +1,5 @@ +{ + "usingComponents": { + "navigation-bar": "/components/navigation-bar/navigation-bar" + } +} diff --git a/WeChatProgram/pages/coupons/index.wxml b/WeChatProgram/pages/coupons/index.wxml new file mode 100644 index 00000000..a6151abb --- /dev/null +++ b/WeChatProgram/pages/coupons/index.wxml @@ -0,0 +1,40 @@ + + + + + + 登录后查看优惠券 + 可用优惠、VIP 自动折扣都会统一展示在这里。 + 去登录 + + + + + 优惠资产 + 当前有 {{coupons.length}} 张可查看 + 普通优惠券和系统自动匹配的 VIP 折扣都会在结算前统一展示。 + + + + + + {{item.couponName}} + {{item.sourceText}} + + {{item.statusName || '待使用'}} + + {{item.benefitText}} + {{item.periodText}} + + + + + 正在加载优惠内容 + + + + 你还没有优惠券 + 下单前系统也会自动帮你匹配最合适的优惠方式。 + + + diff --git a/WeChatProgram/pages/coupons/index.wxss b/WeChatProgram/pages/coupons/index.wxss new file mode 100644 index 00000000..82421aee --- /dev/null +++ b/WeChatProgram/pages/coupons/index.wxss @@ -0,0 +1,58 @@ +.coupons-hero { + margin-bottom: 20rpx; +} + +.coupon-card + .coupon-card { + margin-top: 20rpx; +} + +.coupon-card { + padding: 26rpx 28rpx; + background: linear-gradient(135deg, #fff8fa 0%, #fff1f5 100%); +} + +.coupon-top { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 20rpx; +} + +.coupon-title { + font-size: 30rpx; + font-weight: 700; + color: #2d2430; +} + +.coupon-source { + margin-top: 10rpx; + font-size: 22rpx; + color: #8d7a84; +} + +.coupon-status { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 140rpx; + height: 52rpx; + padding: 0 18rpx; + border-radius: 999rpx; + background: rgba(255, 255, 255, 0.8); + color: #c6597d; + font-size: 22rpx; + font-weight: 700; +} + +.coupon-benefit { + margin-top: 26rpx; + font-size: 42rpx; + font-weight: 800; + color: #d5536f; +} + +.coupon-period { + margin-top: 18rpx; + font-size: 24rpx; + color: #8d7a84; +} diff --git a/WeChatProgram/pages/home/index.js b/WeChatProgram/pages/home/index.js new file mode 100644 index 00000000..ef83eac1 --- /dev/null +++ b/WeChatProgram/pages/home/index.js @@ -0,0 +1,223 @@ +const auth = require('../../utils/auth') +const navigation = require('../../utils/navigation') +const { buildProductCards } = require('../../utils/product') +const { resolveImageList } = require('../../utils/file') +const { DEFAULT_SHOP_IMAGE } = require('../../utils/config') +const productApi = require('../../api/product') +const shopApi = require('../../api/shop') +const userApi = require('../../api/user') + +Page({ + data: { + initialized: false, + loading: false, + isLoggedIn: false, + userInfo: null, + greeting: '欢迎来到 Yumi Nail', + displayName: '先看看门店和作品', + searchKeyword: '', + bannerImages: [], + featuredItems: [], + popularSource: [], + popularItems: [], + popularPage: 1, + pageSize: 6, + hasMore: false + }, + + onLoad() { + this.loadHomeData() + }, + + onShow() { + this.syncUserState() + if (this.data.initialized && this.data.isLoggedIn) { + this.loadUserProfile() + } + }, + + async onPullDownRefresh() { + await this.loadHomeData() + wx.stopPullDownRefresh() + }, + + onReachBottom() { + if (!this.data.hasMore) { + 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 + }) + }, + + syncUserState() { + const app = getApp() + const userInfo = auth.getStoredUserInfo() + const isLoggedIn = auth.isLoggedIn() + if (app) { + app.globalData.userInfo = userInfo + app.globalData.isLoggedIn = isLoggedIn + } + + this.setData({ + isLoggedIn, + userInfo, + greeting: isLoggedIn ? '欢迎回来' : '游客模式', + displayName: isLoggedIn + ? ((userInfo && userInfo.nickname) || 'Yumi 用户') + : '先逛逛喜欢的款式和门店' + }) + }, + + async loadUserProfile() { + if (!auth.isLoggedIn()) { + this.syncUserState() + return + } + + try { + const userInfo = await userApi.getUserInfo() + getApp().refreshUserInfo(userInfo) + this.syncUserState() + } catch (error) {} + }, + + async loadHomeData() { + this.setData({ loading: true }) + this.syncUserState() + + try { + await Promise.all([ + this.loadUserProfile(), + this.loadBannerImages(), + this.loadFeaturedProducts(), + this.loadPopularProducts() + ]) + + this.setData({ + initialized: true + }) + } catch (error) { + wx.showToast({ + title: error.message || '首页加载失败', + icon: 'none' + }) + } finally { + 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({ + id: `${shop.id}-${index}`, + shopId: shop.id, + shopName: shop.shopName, + businessHours: shop.businessHours || '欢迎到店体验', + imageUrl: urls[0] + }) + } + } + + 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) { + this.setData({ + searchKeyword: event.detail.value + }) + }, + + handleSearchConfirm() { + navigation.openProducts({ + keyword: this.data.searchKeyword.trim() + }) + }, + + handleBannerTap(event) { + const shopId = event.currentTarget.dataset.shopId + if (!shopId) { + return + } + + navigation.navigate('/pages/shop-detail/index', { + id: shopId, + returnTo: navigation.getCurrentPageUrl() + }) + }, + + handleProfileTap() { + if (this.data.isLoggedIn) { + navigation.switchTab('/pages/profile/index') + return + } + + navigation.openAuth() + }, + + handleProductSelect(event) { + const product = event.detail || {} + if (!product.id) { + return + } + + navigation.navigate('/pages/product-detail/index', { + id: product.id + }) + }, + + handleSeeAllFeatured() { + navigation.openProducts({ + tag: '精选' + }) + }, + + handleSeeAllPopular() { + navigation.openProducts({ + tag: '热门' + }) + } +}) diff --git a/WeChatProgram/pages/home/index.json b/WeChatProgram/pages/home/index.json new file mode 100644 index 00000000..67c0132a --- /dev/null +++ b/WeChatProgram/pages/home/index.json @@ -0,0 +1,7 @@ +{ + "usingComponents": { + "navigation-bar": "/components/navigation-bar/navigation-bar", + "product-card": "/components/product-card/product-card" + }, + "enablePullDownRefresh": true +} diff --git a/WeChatProgram/pages/home/index.wxml b/WeChatProgram/pages/home/index.wxml new file mode 100644 index 00000000..9345d350 --- /dev/null +++ b/WeChatProgram/pages/home/index.wxml @@ -0,0 +1,137 @@ + + + + + + + + {{isLoggedIn ? greeting : 'YUMI NAIL 小程序'}} + {{displayName}} + 先看门店氛围,再挑喜欢的作品,最后一站式完成收藏、加购和预约。 + + + {{isLoggedIn ? '进入个人中心' : '立即登录'}} + 看看热门作品 + + + + + 搜索 + + + + + 门店橱窗 + {{bannerImages.length ? bannerImages.length : 0}} 家 + 先看环境,再决定去哪家 + + + 精选作品 + {{featuredItems.length ? featuredItems.length : 0}} 款 + 适合快速找到灵感 + + + 热门推荐 + {{popularItems.length ? popularItems.length : 0}} 条 + 当前最受欢迎的预约款式 + + + + + 登录后可同步收藏、购物车和预约记录,切换设备也不会丢。 + + + + + + + 门店氛围 + 先看看线下环境 + 轮播展示门店图片和营业时间,帮助你快速判断想去的店。 + + + + + + + 门店内容正在补充中 + 可以先浏览精选作品,稍后再回来查看门店环境展示。 + + + + + + + 快速入门 + 精选作品 + 适合先快速逛一圈的热门款式,向右滑动查看更多。 + + 查看全部 + + + + + + + + + + + + + + 精选作品正在整理中 + 等门店补齐款式后,这里会优先展示最值得先看的内容。 + + + + + + + 热门预约 + 最近大家都在看 + 结合点赞和收藏热度展示当前最受欢迎的款式。 + + 查看全部 + + + + + + + + + + 正在加载首页内容 + + + + 还没有热门作品 + 当前门店还在补充作品数据,稍后再回来看看。 + + + + + + diff --git a/WeChatProgram/pages/home/index.wxss b/WeChatProgram/pages/home/index.wxss new file mode 100644 index 00000000..2dc99a89 --- /dev/null +++ b/WeChatProgram/pages/home/index.wxss @@ -0,0 +1,150 @@ +.home-page-root { + height: 100vh; + display: flex; + flex-direction: column; + overflow: hidden; +} + +.home-scroll { + flex: 1; + min-height: 0; +} + +.home-page { + min-height: 100%; + background: + radial-gradient(circle at top right, rgba(255, 196, 214, 0.4), transparent 36%), + linear-gradient(180deg, #fff7f8 0%, #fffdfb 100%); +} + +.home-hero { + background: + radial-gradient(circle at top right, rgba(255, 186, 207, 0.5), transparent 36%), + linear-gradient(145deg, #fffdfd 0%, #fff2f6 52%, #ffe8ef 100%); +} + +.search-box { + display: flex; + align-items: center; + gap: 16rpx; + margin-top: 30rpx; + padding: 10rpx; + border-radius: 999rpx; + background: rgba(255, 255, 255, 0.92); +} + +.search-input { + flex: 1; + height: 72rpx; + padding: 0 24rpx; + font-size: 28rpx; + color: #2d2430; +} + +.search-btn { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 150rpx; + height: 72rpx; + border-radius: 999rpx; + background: linear-gradient(135deg, #ff8cb0 0%, #c6597d 100%); + color: #ffffff; + font-size: 26rpx; + font-weight: 700; +} + +.guest-tip { + margin-top: 24rpx; + padding: 20rpx 24rpx; + border-radius: 22rpx; + background: rgba(255, 255, 255, 0.85); + color: #8d7a84; + font-size: 24rpx; + line-height: 1.7; +} + +.banner-box { + overflow: hidden; + border-radius: 34rpx; +} + +.banner-swiper, +.banner-item { + width: 100%; + height: 396rpx; +} + +.banner-item { + position: relative; +} + +.banner-image { + width: 100%; + height: 100%; +} + +.banner-mask { + position: absolute; + left: 24rpx; + right: 24rpx; + bottom: 24rpx; + padding: 22rpx 24rpx; + border-radius: 24rpx; + background: rgba(255, 255, 255, 0.9); +} + +.banner-badge { + display: inline-flex; + align-items: center; + justify-content: center; + padding: 8rpx 18rpx; + border-radius: 999rpx; + background: #fce8ef; + color: #c6597d; + font-size: 22rpx; + font-weight: 700; +} + +.banner-title { + margin-top: 14rpx; + font-size: 34rpx; + font-weight: 700; + color: #2d2430; +} + +.banner-desc { + margin-top: 8rpx; + font-size: 24rpx; + color: #8d7a84; +} + +.featured-panel { + padding: 2rpx 0 4rpx; +} + +.featured-scroll { + width: 100%; + white-space: nowrap; +} + +.featured-list { + display: inline-flex; + gap: 18rpx; + padding: 4rpx 2rpx 12rpx; +} + +.featured-card { + width: 332rpx; +} + +.popular-grid { + display: flex; + flex-wrap: wrap; + gap: 18rpx; + padding-top: 2rpx; +} + +.popular-card { + width: calc(50% - 9rpx); +} diff --git a/WeChatProgram/pages/index/index.js b/WeChatProgram/pages/index/index.js new file mode 100644 index 00000000..c479c1a1 --- /dev/null +++ b/WeChatProgram/pages/index/index.js @@ -0,0 +1,7 @@ +Page({ + onLoad() { + wx.switchTab({ + url: '/pages/home/index' + }) + } +}) diff --git a/WeChatProgram/pages/index/index.json b/WeChatProgram/pages/index/index.json new file mode 100644 index 00000000..aa3f1b02 --- /dev/null +++ b/WeChatProgram/pages/index/index.json @@ -0,0 +1,5 @@ +{ + "usingComponents": { + "navigation-bar": "/components/navigation-bar/navigation-bar" + } +} \ No newline at end of file diff --git a/WeChatProgram/pages/index/index.wxml b/WeChatProgram/pages/index/index.wxml new file mode 100644 index 00000000..c543ccf7 --- /dev/null +++ b/WeChatProgram/pages/index/index.wxml @@ -0,0 +1,7 @@ + + + + 正在进入首页 + 这个 `pages/index` 是初始化遗留页,当前实际首页是 `pages/home/index`。 + + diff --git a/WeChatProgram/pages/index/index.wxss b/WeChatProgram/pages/index/index.wxss new file mode 100644 index 00000000..79d4b2b4 --- /dev/null +++ b/WeChatProgram/pages/index/index.wxss @@ -0,0 +1,33 @@ +page { + height: 100vh; + background: #fff7f8; +} + +.redirect-page { + min-height: calc(100vh - 88rpx); + display: flex; + align-items: center; + justify-content: center; + padding: 32rpx; +} + +.redirect-card { + width: 100%; + padding: 40rpx 32rpx; + border-radius: 28rpx; + background: #ffffff; + box-shadow: 0 18rpx 50rpx rgba(122, 67, 88, 0.08); +} + +.redirect-title { + font-size: 34rpx; + font-weight: 700; + color: #2d2430; +} + +.redirect-desc { + margin-top: 18rpx; + font-size: 24rpx; + line-height: 1.7; + color: #8d7a84; +} diff --git a/WeChatProgram/pages/orders/index.js b/WeChatProgram/pages/orders/index.js new file mode 100644 index 00000000..9e41aa2b --- /dev/null +++ b/WeChatProgram/pages/orders/index.js @@ -0,0 +1,108 @@ +const orderApi = require('../../api/order') +const auth = require('../../utils/auth') +const navigation = require('../../utils/navigation') +const { resolveLegacyImage } = require('../../utils/file') +const { formatDateTime, formatPrice, getOrderStatusClass, getOrderStatusText } = require('../../utils/format') +const { runWithLoading } = require('../../utils/loading') + +Page({ + data: { + loading: false, + isLoggedIn: false, + orders: [] + }, + + onShow() { + this.loadOrders() + }, + + async loadOrders() { + const isLoggedIn = auth.isLoggedIn() + this.setData({ + isLoggedIn, + loading: isLoggedIn + }) + + if (!isLoggedIn) { + this.setData({ + orders: [], + loading: false + }) + return + } + + try { + const orders = await orderApi.getOrderList() + const list = Array.isArray(orders) ? orders : [] + const formattedOrders = await Promise.all(list.map(async order => ({ + ...order, + statusText: getOrderStatusText(order), + statusClass: getOrderStatusClass(order), + actualAmountText: `¥${formatPrice(order.actualAmount)}`, + items: await Promise.all((order.items || []).map(async item => ({ + ...item, + productImageUrl: await resolveLegacyImage(item.productImage), + priceText: `¥${formatPrice(item.price)}`, + appointmentText: formatDateTime(item.appointmentTime) + }))) + }))) + + this.setData({ + orders: formattedOrders + }) + } catch (error) { + this.setData({ + orders: [] + }) + wx.showToast({ + title: error.message || '订单列表加载失败', + icon: 'none' + }) + } finally { + this.setData({ + loading: false + }) + } + }, + + handleOpenAuth() { + navigation.openAuth('/pages/orders/index') + }, + + handleBack() { + navigation.goBack('/pages/profile/index') + }, + + async handleCancelOrder(event) { + const orderId = event.currentTarget.dataset.orderId + if (!orderId) { + 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' + }) + this.loadOrders() + } catch (error) { + wx.showToast({ + title: error.message || '取消订单失败', + icon: 'none' + }) + } + } +}) diff --git a/WeChatProgram/pages/orders/index.json b/WeChatProgram/pages/orders/index.json new file mode 100644 index 00000000..8632c9b0 --- /dev/null +++ b/WeChatProgram/pages/orders/index.json @@ -0,0 +1,5 @@ +{ + "usingComponents": { + "navigation-bar": "/components/navigation-bar/navigation-bar" + } +} diff --git a/WeChatProgram/pages/orders/index.wxml b/WeChatProgram/pages/orders/index.wxml new file mode 100644 index 00000000..d829ac08 --- /dev/null +++ b/WeChatProgram/pages/orders/index.wxml @@ -0,0 +1,53 @@ + + + + + + 登录后查看订单 + 预约状态、取消进度和服务记录都会展示在这里。 + 去登录 + + + + + 预约记录 + 共 {{orders.length}} 笔订单 + 这里展示每笔订单的状态、项目、预约时间以及取消入口。 + + + + + + 订单号 + {{item.orderNo}} + + {{item.statusText}} + + + + + + {{orderItem.productTitle}} + {{orderItem.priceText}} x {{orderItem.quantity}} + 美甲师:{{orderItem.artistName}} + 预约时间:{{orderItem.appointmentText}} + + + + + 总计:{{item.actualAmountText}} + 取消订单 + + + + + + 正在加载订单 + + + + 你还没有订单 + 选到喜欢的款式后,加入购物车即可发起预约。 + + + diff --git a/WeChatProgram/pages/orders/index.wxss b/WeChatProgram/pages/orders/index.wxss new file mode 100644 index 00000000..4b9c630b --- /dev/null +++ b/WeChatProgram/pages/orders/index.wxss @@ -0,0 +1,126 @@ +.orders-hero { + margin-bottom: 20rpx; +} + +.order-card + .order-card { + margin-top: 20rpx; +} + +.order-card { + padding: 26rpx; +} + +.order-head, +.order-foot { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 18rpx; +} + +.order-head { + padding-bottom: 18rpx; + border-bottom: 2rpx solid #f3e7eb; +} + +.order-head-copy { + flex: 1; + min-width: 0; +} + +.order-label { + display: block; + font-size: 22rpx; + color: #8d7a84; +} + +.order-no { + display: block; + margin-top: 10rpx; + font-size: 24rpx; + line-height: 1.6; + color: #5d4b55; +} + +.order-status { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 120rpx; + height: 48rpx; + padding: 0 16rpx; + border-radius: 999rpx; + font-size: 22rpx; + font-weight: 700; +} + +.order-status.pending { + background: #fff6e8; + color: #cb7b00; +} + +.order-status.completed { + background: #ecfbf3; + color: #2ea36f; +} + +.order-status.cancelled { + background: #fff1f5; + color: #d5536f; +} + +.order-item { + display: flex; + gap: 18rpx; + margin-top: 22rpx; +} + +.order-thumb { + width: 132rpx; + height: 132rpx; + border-radius: 20rpx; + background: #f6edf1; +} + +.order-main { + flex: 1; +} + +.order-title { + font-size: 28rpx; + font-weight: 700; + color: #2d2430; + line-height: 1.5; +} + +.order-line { + margin-top: 10rpx; + font-size: 24rpx; + color: #8d7a84; + line-height: 1.6; +} + +.order-foot { + margin-top: 24rpx; + align-items: center; +} + +.order-amount { + font-size: 28rpx; + font-weight: 700; + color: #2d2430; +} + +.cancel-btn { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 144rpx; + height: 60rpx; + padding: 0 18rpx; + border-radius: 999rpx; + background: #fff1f5; + color: #d5536f; + font-size: 24rpx; + font-weight: 700; +} diff --git a/WeChatProgram/pages/product-detail/index.js b/WeChatProgram/pages/product-detail/index.js new file mode 100644 index 00000000..228ef834 --- /dev/null +++ b/WeChatProgram/pages/product-detail/index.js @@ -0,0 +1,301 @@ +const cartApi = require('../../api/cart') +const productApi = require('../../api/product') +const productLikeApi = require('../../api/product-like') +const shopApi = require('../../api/shop') +const wishlistApi = require('../../api/wishlist') +const auth = require('../../utils/auth') +const navigation = require('../../utils/navigation') +const { resolveImageList } = require('../../utils/file') +const { DEFAULT_PRODUCT_IMAGE } = require('../../utils/config') +const { formatPrice, getProductTitle, splitCsv } = require('../../utils/format') +const { runWithLoading } = require('../../utils/loading') + +function parseTimeRange(businessHours) { + if (!businessHours) { + return null + } + + const matched = String(businessHours).replace(/\s+/g, '').match(/(\d{1,2}:\d{2}).*?(\d{1,2}:\d{2})/) + if (!matched) { + return null + } + + return { + start: matched[1], + end: matched[2] + } +} + +function estimateEarliestBookable(businessHours) { + const range = parseTimeRange(businessHours) + if (!range) { + return businessHours || '以门店安排为准' + } + + const next = new Date(Date.now() + 30 * 60 * 1000) + const openTime = new Date(next) + const closeTime = new Date(next) + const startParts = range.start.split(':').map(Number) + const endParts = range.end.split(':').map(Number) + + openTime.setHours(startParts[0], startParts[1], 0, 0) + closeTime.setHours(endParts[0], endParts[1], 0, 0) + + if (next <= openTime) { + return `今天 ${range.start}` + } + + if (next >= closeTime) { + return `明天 ${range.start}` + } + + const month = String(next.getMonth() + 1).padStart(2, '0') + const date = String(next.getDate()).padStart(2, '0') + const hour = String(next.getHours()).padStart(2, '0') + const minute = String(next.getMinutes()).padStart(2, '0') + return `${month}-${date} ${hour}:${minute}` +} + +Page({ + data: { + loading: true, + loadError: '', + productId: '', + product: null, + productImages: [], + shopInfo: null, + isFavorite: false, + isLiked: false, + artistCountText: '门店安排', + earliestBookableText: '以门店安排为准' + }, + + onLoad(options) { + this.setData({ + productId: options && options.id ? options.id : '' + }) + + this.loadProductDetail() + }, + + async onPullDownRefresh() { + await this.loadProductDetail() + wx.stopPullDownRefresh() + }, + + async loadProductDetail() { + const productId = this.data.productId + if (!productId) { + this.setData({ + loading: false, + loadError: '作品 ID 不存在' + }) + return + } + + this.setData({ + loading: true, + loadError: '' + }) + + try { + const product = await productApi.getProductById(productId) + const productImages = await resolveImageList(product.imageFileIds, DEFAULT_PRODUCT_IMAGE) + const shopInfo = product.shopId ? await shopApi.getShopById(product.shopId) : null + const artistCount = typeof product.availableBookableArtistCount === 'number' + ? product.availableBookableArtistCount + : splitCsv(product.bookableArtists).length + + const formattedProduct = { + ...product, + displayTitle: getProductTitle(product), + priceText: `¥${formatPrice(product.price)}`, + descriptionText: product.description || '店家还没有补充作品说明。' + } + + this.setData({ + product: formattedProduct, + productImages, + shopInfo, + artistCountText: artistCount > 0 ? `${artistCount} 位可预约` : (product.bookableArtistRestricted ? '暂时没有' : '门店安排'), + earliestBookableText: estimateEarliestBookable(shopInfo && shopInfo.businessHours) + }) + + if (auth.isLoggedIn()) { + this.loadInteractionStatus() + } else { + this.setData({ + isFavorite: false, + isLiked: false + }) + } + } catch (error) { + this.setData({ + loadError: error.message || '作品详情加载失败' + }) + } finally { + this.setData({ + loading: false + }) + } + }, + + async loadInteractionStatus() { + const product = this.data.product + if (!product || !product.id) { + return + } + + try { + const [isFavorite, isLiked] = await Promise.all([ + wishlistApi.checkWishlist(product.id), + productLikeApi.checkLikeStatus(product.id) + ]) + this.setData({ + isFavorite: Boolean(isFavorite), + isLiked: Boolean(isLiked) + }) + } catch (error) {} + }, + + handleBack() { + navigation.goBack('/pages/products/index') + }, + + handlePreviewImage(event) { + const current = event.currentTarget.dataset.url + if (!current) { + return + } + + wx.previewImage({ + current, + urls: this.data.productImages + }) + }, + + handleOpenShop() { + const shopInfo = this.data.shopInfo + if (!shopInfo || !shopInfo.id) { + return + } + + navigation.navigate('/pages/shop-detail/index', { + id: shopInfo.id, + returnTo: navigation.getCurrentPageUrl() + }) + }, + + async handleToggleFavorite() { + const product = this.data.product + if (!product || !product.id || !navigation.ensureLogin('收藏作品')) { + return + } + + 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 + } + + this.setData({ + isFavorite: nextFavorite, + product + }) + + wx.showToast({ + title: nextFavorite ? '已加入收藏' : '已取消收藏', + icon: 'none' + }) + } catch (error) { + wx.showToast({ + title: error.message || '收藏操作失败', + icon: 'none' + }) + } + }, + + async handleToggleLike() { + const product = this.data.product + if (!product || !product.id || !navigation.ensureLogin('点赞作品')) { + return + } + + 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 + } + + this.setData({ + isLiked: nextLiked, + product + }) + + wx.showToast({ + title: nextLiked ? '已点赞' : '已取消点赞', + icon: 'none' + }) + } catch (error) { + wx.showToast({ + title: error.message || '点赞操作失败', + icon: 'none' + }) + } + }, + + async handleAddToCart() { + const product = this.data.product + if (!product || !product.id || !navigation.ensureLogin('加购')) { + return + } + + try { + await runWithLoading(() => cartApi.addToCart({ + productId: product.id, + quantity: 1 + })) + await getApp().updateCartBadge() + wx.showToast({ + title: '已加入购物车', + icon: 'none' + }) + } catch (error) { + wx.showToast({ + title: error.message || '加入购物车失败', + icon: 'none' + }) + } + }, + + async handleBuyNow() { + const product = this.data.product + if (!product || !product.id || !navigation.ensureLogin('预约下单')) { + return + } + + try { + await runWithLoading(() => cartApi.addToCart({ + productId: product.id, + quantity: 1 + })) + await getApp().updateCartBadge() + wx.switchTab({ + url: '/pages/cart/index' + }) + } catch (error) { + wx.showToast({ + title: error.message || '操作失败', + icon: 'none' + }) + } + } +}) diff --git a/WeChatProgram/pages/product-detail/index.json b/WeChatProgram/pages/product-detail/index.json new file mode 100644 index 00000000..8632c9b0 --- /dev/null +++ b/WeChatProgram/pages/product-detail/index.json @@ -0,0 +1,5 @@ +{ + "usingComponents": { + "navigation-bar": "/components/navigation-bar/navigation-bar" + } +} diff --git a/WeChatProgram/pages/product-detail/index.wxml b/WeChatProgram/pages/product-detail/index.wxml new file mode 100644 index 00000000..6e3123a1 --- /dev/null +++ b/WeChatProgram/pages/product-detail/index.wxml @@ -0,0 +1,88 @@ + + + + + + 暂时无法查看作品详情 + {{loadError}} + 返回上一页 + + + + + + + + + + + + + {{product.approximateDuration || '时长待确认'}} + {{artistCountText}} + + + + + + + + 作品详情 + {{product.displayTitle}} + {{product.priceText}} + 适合先看作品风格、门店信息和可预约情况,再决定是否立即下单。 + + + + + 所属门店 + {{shopInfo ? shopInfo.shopName : '待绑定'}} + 点击查看门店详情 + + + 可约美甲师 + {{artistCountText}} + 预约前可在购物车继续选择 + + + 最早可约 + {{earliestBookableText}} + 以门店营业时间为准 + + + + + + {{shopInfo.shopName}} + 查看门店 + + {{shopInfo.address || '门店地址待补充'}} + {{shopInfo.businessHours || '营业时间待补充'}} + + + + + 点赞 {{product.likeCount || 0}} + + + 收藏 {{product.collectCount || 0}} + + + + + {{item.tagName}} + + + + 款式说明 + {{product.descriptionText}} + + + + + + 加入购物车 + 立即预约 + + + diff --git a/WeChatProgram/pages/product-detail/index.wxss b/WeChatProgram/pages/product-detail/index.wxss new file mode 100644 index 00000000..d1e30780 --- /dev/null +++ b/WeChatProgram/pages/product-detail/index.wxss @@ -0,0 +1,193 @@ +.detail-page { + padding-bottom: calc(env(safe-area-inset-bottom) + 160rpx); +} + +.media-box { + position: relative; + overflow: hidden; + border-radius: 0 0 40rpx 40rpx; +} + +.media-swiper, +.media-image { + width: 100%; + height: 640rpx; +} + +.media-mask { + position: absolute; + left: 24rpx; + right: 24rpx; + bottom: 28rpx; +} + +.media-badges { + display: flex; + flex-wrap: wrap; + gap: 12rpx; +} + +.detail-content { + margin-top: -48rpx; +} + +.info-card { + padding: 32rpx 30rpx; +} + +.detail-head { + padding-bottom: 10rpx; +} + +.product-title { + margin-top: 16rpx; + font-size: 42rpx; + font-weight: 700; + line-height: 1.4; + color: #2d2430; +} + +.product-price { + margin-top: 12rpx; + font-size: 38rpx; + font-weight: 700; + color: #d5536f; +} + +.product-brief { + margin-top: 14rpx; + font-size: 24rpx; + line-height: 1.8; + color: #8d7a84; +} + +.detail-summary { + margin-top: 24rpx; +} + +.detail-summary-value { + font-size: 26rpx; + line-height: 1.5; +} + +.shop-box { + margin-top: 28rpx; + padding: 24rpx; + border-radius: 24rpx; + background: linear-gradient(135deg, #fff8fa 0%, #fff1f5 100%); +} + +.shop-box-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 16rpx; +} + +.shop-name { + font-size: 30rpx; + font-weight: 700; + color: #2d2430; +} + +.shop-link { + font-size: 24rpx; + color: #c6597d; + font-weight: 700; +} + +.shop-meta { + margin-top: 10rpx; + font-size: 24rpx; + color: #8d7a84; + line-height: 1.7; +} + +.actions-row { + display: flex; + gap: 16rpx; + margin-top: 28rpx; +} + +.action-pill { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 180rpx; + height: 68rpx; + padding: 0 24rpx; + border-radius: 999rpx; + background: #fbf5f7; + color: #7a5262; + font-size: 24rpx; + font-weight: 600; +} + +.action-pill.active { + background: #fde8ef; + color: #c6597d; +} + +.tags-wrap { + display: flex; + flex-wrap: wrap; + gap: 12rpx; + margin-top: 24rpx; +} + +.tag-chip { + display: inline-flex; + align-items: center; + justify-content: center; + padding: 10rpx 18rpx; + border-radius: 999rpx; + background: #fbecf1; + color: #c6597d; + font-size: 22rpx; +} + +.desc-block { + margin-top: 28rpx; +} + +.desc-text { + margin-top: 16rpx; + font-size: 26rpx; + line-height: 1.8; + color: #5d4b55; +} + +.footer-bar { + position: fixed; + left: 24rpx; + right: 24rpx; + bottom: calc(env(safe-area-inset-bottom) + 20rpx); + z-index: 20; + display: flex; + gap: 16rpx; + padding: 18rpx; + border-radius: 30rpx; + background: rgba(255, 255, 255, 0.96); + box-shadow: 0 18rpx 50rpx rgba(122, 67, 88, 0.12); +} + +.footer-btn { + display: flex; + align-items: center; + justify-content: center; + flex: 1; + height: 88rpx; + border-radius: 999rpx; + font-size: 28rpx; + font-weight: 700; +} + +.footer-btn.secondary { + background: #fbf5f7; + color: #7a5262; +} + +.footer-btn.primary { + background: linear-gradient(135deg, #ff8cb0 0%, #c6597d 100%); + color: #ffffff; +} diff --git a/WeChatProgram/pages/products/index.js b/WeChatProgram/pages/products/index.js new file mode 100644 index 00000000..0289fc51 --- /dev/null +++ b/WeChatProgram/pages/products/index.js @@ -0,0 +1,174 @@ +const tagApi = require('../../api/tag') +const productApi = require('../../api/product') +const { buildProductCards } = require('../../utils/product') +const navigation = require('../../utils/navigation') +const { runWithLoading } = require('../../utils/loading') + +Page({ + data: { + initialized: false, + loading: false, + categories: ['全部'], + selectedCategory: '全部', + searchKeyword: '', + products: [], + activeBannerText: '' + }, + + onLoad(options) { + this.bootstrapPage(options || {}) + }, + + 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) + } + }, + + async onPullDownRefresh() { + await this.loadProducts() + wx.stopPullDownRefresh() + }, + + async bootstrapPage(options) { + this.setData({ + loading: true + }) + + try { + await this.loadTags() + await this.applyInitialFilter(options) + this.setData({ + initialized: true + }) + } catch (error) { + wx.showToast({ + title: error.message || '作品列表加载失败', + icon: 'none' + }) + } finally { + this.setData({ + loading: false + }) + } + }, + + async loadTags() { + const tags = await tagApi.getAllTags() + const names = Array.isArray(tags) ? tags.map(item => item.tagName).filter(Boolean) : [] + this.setData({ + categories: ['全部'].concat(names) + }) + }, + + async applyInitialFilter(options) { + const app = getApp() + const pendingFilter = app && app.globalData ? app.globalData.pendingProductFilter : null + if (pendingFilter && (pendingFilter.keyword || pendingFilter.tag)) { + if (app && app.globalData) { + app.globalData.pendingProductFilter = null + } + await this.applyFilter(pendingFilter) + return + } + + await this.applyFilter(options || {}) + }, + + async applyFilter(filter) { + const keyword = (filter.keyword || '').trim() + const tag = (filter.tag || '').trim() + this.setData({ + searchKeyword: keyword, + selectedCategory: tag && this.data.categories.includes(tag) ? tag : '全部' + }) + await this.loadProducts() + }, + + async loadProducts() { + this.setData({ + loading: 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 cards = await buildProductCards(products || []) + this.setData({ + products: cards, + activeBannerText: keyword + ? `正在显示“${keyword}”的搜索结果` + : (tag !== '全部' ? `当前按“${tag}”筛选` : '') + }) + } catch (error) { + this.setData({ + products: [], + activeBannerText: '' + }) + wx.showToast({ + title: error.message || '作品列表加载失败', + icon: 'none' + }) + } finally { + this.setData({ + loading: false + }) + } + }, + + handleSearchInput(event) { + this.setData({ + searchKeyword: event.detail.value + }) + }, + + async handleSearchConfirm() { + this.setData({ + selectedCategory: '全部' + }) + await runWithLoading(() => this.loadProducts()) + }, + + async handleSelectCategory(event) { + const category = event.currentTarget.dataset.category + this.setData({ + selectedCategory: category, + searchKeyword: '' + }) + await runWithLoading(() => this.loadProducts()) + }, + + async handleResetFilters() { + this.setData({ + selectedCategory: '全部', + searchKeyword: '' + }) + await runWithLoading(() => this.loadProducts()) + }, + + handleProductSelect(event) { + const product = event.detail || {} + if (!product.id) { + return + } + + navigation.navigate('/pages/product-detail/index', { + id: product.id + }) + } +}) diff --git a/WeChatProgram/pages/products/index.json b/WeChatProgram/pages/products/index.json new file mode 100644 index 00000000..67c0132a --- /dev/null +++ b/WeChatProgram/pages/products/index.json @@ -0,0 +1,7 @@ +{ + "usingComponents": { + "navigation-bar": "/components/navigation-bar/navigation-bar", + "product-card": "/components/product-card/product-card" + }, + "enablePullDownRefresh": true +} diff --git a/WeChatProgram/pages/products/index.wxml b/WeChatProgram/pages/products/index.wxml new file mode 100644 index 00000000..df48a933 --- /dev/null +++ b/WeChatProgram/pages/products/index.wxml @@ -0,0 +1,63 @@ + + + + + + 作品筛选 + {{selectedCategory !== '全部' ? selectedCategory : '找到适合你的美甲款式'}} + {{activeBannerText ? activeBannerText : '按标签筛选或输入关键词搜索,先缩小范围,再挑喜欢的作品。'}} + + + + + 搜索 + + + + + + {{item}} + + + + + + + + {{products.length ? products.length : 0}} 个结果 + 重置筛选 + + + {{activeBannerText}} + + + + + + + + + 正在加载作品 + + + + 暂时没有匹配的作品 + 可以换个关键词试试,或者先浏览全部作品。 + 查看全部 + + + diff --git a/WeChatProgram/pages/products/index.wxss b/WeChatProgram/pages/products/index.wxss new file mode 100644 index 00000000..f957e48b --- /dev/null +++ b/WeChatProgram/pages/products/index.wxss @@ -0,0 +1,117 @@ +.product-page { + background: + radial-gradient(circle at top left, rgba(255, 207, 220, 0.35), transparent 34%), + 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%); +} + +.search-card { + margin-top: 28rpx; + padding: 22rpx; + border-radius: 28rpx; + background: rgba(255, 255, 255, 0.78); +} + +.search-row { + display: flex; + align-items: center; + gap: 14rpx; +} + +.search-input { + flex: 1; + height: 76rpx; + padding: 0 24rpx; + border-radius: 999rpx; + background: #fbf5f7; + color: #2d2430; + font-size: 28rpx; +} + +.search-btn { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 132rpx; + height: 76rpx; + border-radius: 999rpx; + background: linear-gradient(135deg, #ff8cb0 0%, #c6597d 100%); + color: #ffffff; + font-size: 26rpx; + font-weight: 700; +} + +.category-scroll { + width: 100%; + margin-top: 24rpx; + white-space: nowrap; +} + +.category-list { + display: inline-flex; + gap: 16rpx; + padding-bottom: 8rpx; +} + +.category-item { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 120rpx; + height: 60rpx; + padding: 0 22rpx; + border-radius: 999rpx; + background: #f7edf1; + color: #8d7a84; + font-size: 24rpx; + font-weight: 600; +} + +.category-item.active { + background: #fde8ef; + color: #c6597d; +} + +.results-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 16rpx; + margin-top: 24rpx; +} + +.results-count { + font-size: 26rpx; + font-weight: 700; + color: #5d4b55; +} + +.results-reset { + min-width: 0; +} + +.filter-banner { + margin-top: 20rpx; + padding: 20rpx 24rpx; + border-radius: 22rpx; + background: #fff1f5; + color: #b45172; + font-size: 24rpx; + line-height: 1.7; +} + +.product-grid { + display: flex; + flex-wrap: wrap; + gap: 18rpx; + margin-top: 24rpx; +} + +.product-grid-item { + width: calc(50% - 9rpx); +} diff --git a/WeChatProgram/pages/profile/index.js b/WeChatProgram/pages/profile/index.js new file mode 100644 index 00000000..3a1fd694 --- /dev/null +++ b/WeChatProgram/pages/profile/index.js @@ -0,0 +1,190 @@ +const authApi = require('../../api/auth') +const couponApi = require('../../api/coupon') +const orderApi = require('../../api/order') +const userApi = require('../../api/user') +const wishlistApi = require('../../api/wishlist') +const auth = require('../../utils/auth') +const navigation = require('../../utils/navigation') +const { DEFAULT_AVATAR } = require('../../utils/config') +const { runWithLoading } = require('../../utils/loading') + +Page({ + data: { + isLoggedIn: false, + loading: false, + needSetPassword: false, + userInfo: null, + orderCount: 0, + couponCount: 0, + wishlistCount: 0, + defaultAvatar: DEFAULT_AVATAR + }, + + onShow() { + this.loadProfile() + }, + + async loadProfile() { + const isLoggedIn = auth.isLoggedIn() + this.setData({ + isLoggedIn, + needSetPassword: auth.getNeedSetPassword(), + loading: isLoggedIn + }) + + if (!isLoggedIn) { + this.setData({ + userInfo: null, + orderCount: 0, + couponCount: 0, + wishlistCount: 0, + loading: false + }) + return + } + + try { + const [userInfo, orders, coupons, wishlist] = await Promise.all([ + userApi.getUserInfo(), + orderApi.getOrderList(), + couponApi.listUserCoupons(), + wishlistApi.getWishlist() + ]) + + getApp().refreshUserInfo(userInfo) + this.setData({ + userInfo, + orderCount: Array.isArray(orders) ? orders.length : 0, + couponCount: Array.isArray(coupons) ? coupons.length : 0, + wishlistCount: Array.isArray(wishlist) ? wishlist.length : 0 + }) + } catch (error) { + wx.showToast({ + title: error.message || '个人中心加载失败', + icon: 'none' + }) + } finally { + this.setData({ + loading: false + }) + } + }, + + handleOpenAuth() { + navigation.openAuth('/pages/profile/index') + }, + + handleOpenSettings() { + if (!this.data.isLoggedIn) { + this.handleOpenAuth() + return + } + navigation.navigate('/pages/settings/index') + }, + + handleOpenOrders() { + if (!navigation.ensureLogin('查看订单')) { + return + } + navigation.navigate('/pages/orders/index') + }, + + handleOpenWishlist() { + if (!navigation.ensureLogin('查看收藏')) { + return + } + navigation.navigate('/pages/wishlist/index') + }, + + handleOpenCoupons() { + if (!navigation.ensureLogin('查看优惠券')) { + return + } + navigation.navigate('/pages/coupons/index') + }, + + 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' + }) + this.loadProfile() + } catch (error) { + wx.showToast({ + title: error.message || '门店切换失败', + icon: 'none' + }) + } + }, + + async handleLogout() { + if (!this.data.isLoggedIn) { + this.handleOpenAuth() + return + } + + const confirmed = await new Promise(resolve => { + wx.showModal({ + title: '退出登录', + content: '退出后需要重新登录才能查看订单和继续下单。', + success: res => resolve(Boolean(res.confirm)) + }) + }) + + if (!confirmed) { + return + } + + try { + await runWithLoading(() => authApi.logout()) + } catch (error) {} + + getApp().clearUserSession() + await this.loadProfile() + wx.showToast({ + title: '已退出登录', + icon: 'none' + }) + } +}) diff --git a/WeChatProgram/pages/profile/index.json b/WeChatProgram/pages/profile/index.json new file mode 100644 index 00000000..8632c9b0 --- /dev/null +++ b/WeChatProgram/pages/profile/index.json @@ -0,0 +1,5 @@ +{ + "usingComponents": { + "navigation-bar": "/components/navigation-bar/navigation-bar" + } +} diff --git a/WeChatProgram/pages/profile/index.wxml b/WeChatProgram/pages/profile/index.wxml new file mode 100644 index 00000000..116d4a8b --- /dev/null +++ b/WeChatProgram/pages/profile/index.wxml @@ -0,0 +1,87 @@ + + + + + + + + + + 还没有登录账号 + 登录后可以查看订单、收藏作品、领取和使用优惠。 + 去登录 + + + + + + + + {{userInfo.nickname || 'Yumi 用户'}} + + {{userInfo.signature}} + + + + + + 订单 + {{orderCount}} + 查看预约记录 + + + 收藏 + {{wishlistCount}} + 回看喜欢的作品 + + + 优惠券 + {{couponCount}} + 结算前可直接使用 + + + + + + 当前登录门店 + {{userInfo.shopName || '暂未选择门店'}} + + {{(userInfo.shopIds && userInfo.shopIds.length > 1) ? '切换' : '查看'}} + + + + 建议尽快补充登录密码,之后切换设备会更方便。 + + + 编辑资料与设置 + + + + 常用入口 + 订单、收藏、优惠券和账号设置都集中在这里。 + + 我的订单 + > + + + 我的收藏 + > + + + 我的优惠券 + > + + + 设置中心 + > + + + 退出登录 + > + + + + + + + diff --git a/WeChatProgram/pages/profile/index.wxss b/WeChatProgram/pages/profile/index.wxss new file mode 100644 index 00000000..d69d2f80 --- /dev/null +++ b/WeChatProgram/pages/profile/index.wxss @@ -0,0 +1,175 @@ +.profile-page-root { + height: 100vh; + display: flex; + flex-direction: column; + overflow: hidden; +} + +.profile-scroll { + flex: 1; + min-height: 0; +} + +.profile-page { + min-height: 100%; + background: linear-gradient(180deg, #d66c90 0%, #fff8fa 260rpx, #fffdfc 100%); +} + +.profile-bg { + position: fixed; + top: 0; + left: 0; + right: 0; + height: 280rpx; + background: linear-gradient(135deg, #d66c90 0%, #9a4f6d 100%); +} + +.profile-content { + position: relative; + z-index: 1; + padding-top: 120rpx; +} + +.guest-card, +.profile-card, +.menu-card { + padding: 28rpx; +} + +.guest-card { + display: flex; + flex-direction: column; + align-items: center; + gap: 18rpx; + text-align: center; +} + +.guest-avatar { + width: 120rpx; + height: 120rpx; + border-radius: 50%; +} + +.guest-title { + font-size: 34rpx; + font-weight: 700; + color: #2d2430; +} + +.guest-desc { + font-size: 24rpx; + line-height: 1.7; + color: #8d7a84; +} + +.profile-top { + display: flex; + gap: 20rpx; +} + +.avatar { + width: 120rpx; + height: 120rpx; + border-radius: 50%; + background: #f7edf1; +} + +.profile-copy { + flex: 1; +} + +.nickname { + font-size: 38rpx; + font-weight: 700; + color: #2d2430; +} + +.account, +.signature { + margin-top: 10rpx; + font-size: 24rpx; + color: #8d7a84; + line-height: 1.6; +} + +.profile-stats { + margin-top: 26rpx; +} + +.shop-box { + display: flex; + align-items: center; + justify-content: space-between; + gap: 18rpx; + margin-top: 26rpx; + padding: 22rpx 24rpx; + border-radius: 24rpx; + background: #fff1f5; +} + +.shop-label { + font-size: 22rpx; + color: #8d7a84; +} + +.shop-name { + margin-top: 10rpx; + font-size: 28rpx; + font-weight: 700; + color: #2d2430; +} + +.shop-link { + font-size: 24rpx; + color: #c6597d; + font-weight: 700; +} + +.password-tip { + margin-top: 22rpx; + padding: 20rpx 24rpx; + border-radius: 20rpx; + background: #fff7e8; + color: #9b6900; + font-size: 24rpx; + line-height: 1.7; +} + +.edit-btn { + margin-top: 24rpx; +} + +.menu-card { + margin-top: 20rpx; +} + +.menu-item { + display: flex; + align-items: center; + justify-content: space-between; + height: 92rpx; + border-bottom: 2rpx solid #f3e7eb; + font-size: 28rpx; + color: #2d2430; +} + +.menu-item:first-of-type { + margin-top: 18rpx; +} + +.menu-item:last-child { + border-bottom: 0; +} + +.menu-arrow { + color: #c3aab4; +} + +.logout-item { + color: #d5536f; + font-weight: 700; +} + +.logout-item .menu-arrow { + color: #e0a7b5; +} diff --git a/WeChatProgram/pages/settings/index.js b/WeChatProgram/pages/settings/index.js new file mode 100644 index 00000000..ec074340 --- /dev/null +++ b/WeChatProgram/pages/settings/index.js @@ -0,0 +1,244 @@ +const authApi = require('../../api/auth') +const userApi = require('../../api/user') +const auth = require('../../utils/auth') +const navigation = require('../../utils/navigation') +const { DEFAULT_AVATAR } = require('../../utils/config') +const { runWithLoading } = require('../../utils/loading') + +Page({ + data: { + isLoggedIn: false, + loading: false, + savingProfile: false, + updatingPassword: false, + countdown: 0, + userInfo: null, + defaultAvatar: DEFAULT_AVATAR, + form: { + nickname: '', + signature: '' + }, + passwordForm: { + verificationCode: '', + password: '' + } + }, + + onShow() { + this.loadSettings() + }, + + async loadSettings() { + const isLoggedIn = auth.isLoggedIn() + this.setData({ + isLoggedIn, + loading: isLoggedIn + }) + + if (!isLoggedIn) { + this.setData({ + userInfo: null, + loading: false + }) + return + } + + try { + const userInfo = await userApi.getUserInfo() + getApp().refreshUserInfo(userInfo) + this.setData({ + userInfo, + 'form.nickname': userInfo.nickname || '', + 'form.signature': userInfo.signature || '' + }) + } catch (error) { + wx.showToast({ + title: error.message || '设置页加载失败', + icon: 'none' + }) + } finally { + this.setData({ + loading: false + }) + } + }, + + handleBack() { + navigation.goBack('/pages/profile/index') + }, + + handleOpenAuth() { + navigation.openAuth('/pages/settings/index') + }, + + handleFormInput(event) { + const field = event.currentTarget.dataset.field + this.setData({ + [`form.${field}`]: event.detail.value + }) + }, + + handlePasswordInput(event) { + const field = event.currentTarget.dataset.field + this.setData({ + [`passwordForm.${field}`]: event.detail.value + }) + }, + + async handleSaveProfile() { + if (!this.data.form.nickname.trim()) { + wx.showToast({ + title: '请输入昵称', + icon: 'none' + }) + return + } + + this.setData({ + savingProfile: true + }) + + try { + await runWithLoading(() => userApi.updateUserInfo({ + nickname: this.data.form.nickname.trim(), + signature: this.data.form.signature.trim() + })) + wx.showToast({ + title: '资料已更新', + icon: 'none' + }) + this.loadSettings() + } catch (error) { + wx.showToast({ + title: error.message || '资料更新失败', + icon: 'none' + }) + } finally { + this.setData({ + savingProfile: false + }) + } + }, + + startCountdown() { + this.setData({ + countdown: 60 + }) + + const timer = setInterval(() => { + const next = this.data.countdown - 1 + this.setData({ + countdown: next + }) + if (next <= 0) { + clearInterval(timer) + } + }, 1000) + }, + + async handleSendPasswordCode() { + if (this.data.countdown > 0) { + return + } + + const userInfo = this.data.userInfo + if (!userInfo || !userInfo.phone) { + wx.showToast({ + title: '当前账号未绑定手机号', + icon: 'none' + }) + return + } + + try { + await runWithLoading(() => authApi.sendVerificationCode({ + phone: userInfo.phone + })) + wx.showToast({ + title: '验证码已发送', + icon: 'none' + }) + this.startCountdown() + } catch (error) { + wx.showToast({ + title: error.message || '验证码发送失败', + icon: 'none' + }) + } + }, + + async handleUpdatePassword() { + if (!this.data.passwordForm.verificationCode.trim()) { + wx.showToast({ + title: '请输入验证码', + icon: 'none' + }) + return + } + if (!this.data.passwordForm.password || this.data.passwordForm.password.length < 6) { + wx.showToast({ + title: '新密码至少 6 位', + icon: 'none' + }) + return + } + + this.setData({ + updatingPassword: true + }) + + try { + await runWithLoading(() => userApi.updatePassword({ + password: this.data.passwordForm.password, + verificationCode: this.data.passwordForm.verificationCode.trim() + })) + auth.setNeedSetPassword(false) + wx.showToast({ + title: '密码已更新', + icon: 'none' + }) + this.setData({ + passwordForm: { + verificationCode: '', + password: '' + } + }) + } catch (error) { + wx.showToast({ + title: error.message || '密码更新失败', + icon: 'none' + }) + } finally { + this.setData({ + updatingPassword: false + }) + } + }, + + async handleLogout() { + const confirmed = await new Promise(resolve => { + wx.showModal({ + title: '退出登录', + content: '退出后需要重新登录才能查看订单和继续下单。', + success: res => resolve(Boolean(res.confirm)) + }) + }) + + if (!confirmed) { + return + } + + try { + await runWithLoading(() => authApi.logout()) + } catch (error) {} + + getApp().clearUserSession() + wx.showToast({ + title: '已退出登录', + icon: 'none' + }) + wx.switchTab({ + url: '/pages/home/index' + }) + } +}) diff --git a/WeChatProgram/pages/settings/index.json b/WeChatProgram/pages/settings/index.json new file mode 100644 index 00000000..8632c9b0 --- /dev/null +++ b/WeChatProgram/pages/settings/index.json @@ -0,0 +1,5 @@ +{ + "usingComponents": { + "navigation-bar": "/components/navigation-bar/navigation-bar" + } +} diff --git a/WeChatProgram/pages/settings/index.wxml b/WeChatProgram/pages/settings/index.wxml new file mode 100644 index 00000000..debcccd6 --- /dev/null +++ b/WeChatProgram/pages/settings/index.wxml @@ -0,0 +1,68 @@ + + + + + + + + 登录后进入设置中心 + 这里可以修改昵称、个性签名和登录密码。 + 去登录 + + + + + 个人设置 + 维护你的资料与登录信息 + 资料会同步到小程序端展示区域,密码更新后下次登录立即生效。 + + + + 个人资料 + + + + {{userInfo.nickname || 'Yumi 用户'}} + {{userInfo.phone || '未绑定手机号'}} + + + + + 昵称 + + + + + 个性签名 + + + + {{savingProfile ? '保存中...' : '保存资料'}} + + + + 登录密码 + 向已绑定手机号发送验证码后更新登录密码。 + + + 验证码 + + + {{countdown > 0 ? countdown + 's' : '发送验证码'}} + + + + + 新密码 + + + + {{updatingPassword ? '更新中...' : '更新密码'}} + + + 退出登录 + + + + + diff --git a/WeChatProgram/pages/settings/index.wxss b/WeChatProgram/pages/settings/index.wxss new file mode 100644 index 00000000..ba065693 --- /dev/null +++ b/WeChatProgram/pages/settings/index.wxss @@ -0,0 +1,111 @@ +.settings-page-root { + height: 100vh; + display: flex; + flex-direction: column; + overflow: hidden; +} + +.settings-scroll { + flex: 1; + min-height: 0; +} + +.settings-page-shell { + min-height: 100%; +} + +.settings-hero { + margin-bottom: 20rpx; +} + +.settings-card + .settings-card { + margin-top: 20rpx; +} + +.settings-card { + padding: 28rpx; +} + +.profile-preview { + display: flex; + align-items: center; + gap: 18rpx; + margin-top: 22rpx; +} + +.avatar { + width: 110rpx; + height: 110rpx; + border-radius: 50%; + background: #f7edf1; +} + +.profile-preview-copy { + flex: 1; +} + +.preview-name { + font-size: 32rpx; + font-weight: 700; + color: #2d2430; +} + +.preview-phone { + margin-top: 10rpx; + font-size: 24rpx; + color: #8d7a84; +} + +.field-block { + margin-top: 20rpx; +} + +.save-btn { + margin-top: 26rpx; +} + +.password-card { + margin-top: 20rpx; +} + +.code-row { + display: flex; + align-items: center; + gap: 14rpx; +} + +.code-input { + flex: 1; +} + +.code-btn { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 180rpx; + height: 92rpx; + padding: 0 18rpx; + border-radius: 24rpx; + background: #fde8ef; + color: #c6597d; + font-size: 24rpx; + font-weight: 700; +} + +.code-btn.disabled { + background: #f3e7eb; + color: #a998a0; +} + +.logout-btn { + display: flex; + align-items: center; + justify-content: center; + height: 92rpx; + margin-top: 24rpx; + border-radius: 999rpx; + background: #fff1f5; + color: #d5536f; + font-size: 28rpx; + font-weight: 700; +} diff --git a/WeChatProgram/pages/shop-detail/index.js b/WeChatProgram/pages/shop-detail/index.js new file mode 100644 index 00000000..3fdb1398 --- /dev/null +++ b/WeChatProgram/pages/shop-detail/index.js @@ -0,0 +1,98 @@ +const shopApi = require('../../api/shop') +const navigation = require('../../utils/navigation') +const { resolveImageList } = require('../../utils/file') +const { DEFAULT_SHOP_IMAGE } = require('../../utils/config') + +Page({ + data: { + loading: true, + loadError: '', + shopId: '', + returnTo: '/pages/home/index', + shopInfo: null, + shopImages: [] + }, + + onLoad(options) { + this.setData({ + shopId: options && options.id ? options.id : '', + returnTo: options && options.returnTo ? decodeURIComponent(options.returnTo) : '/pages/home/index' + }) + this.loadShopDetail() + }, + + async onPullDownRefresh() { + await this.loadShopDetail() + wx.stopPullDownRefresh() + }, + + async loadShopDetail() { + if (!this.data.shopId) { + this.setData({ + loading: false, + loadError: '门店 ID 不存在' + }) + return + } + + this.setData({ + loading: true, + loadError: '' + }) + + try { + const shopInfo = await shopApi.getShopById(this.data.shopId) + const shopImages = await resolveImageList(shopInfo.imageFileIds || shopInfo.coverImageFileId, DEFAULT_SHOP_IMAGE) + this.setData({ + shopInfo, + shopImages + }) + } catch (error) { + this.setData({ + loadError: error.message || '门店详情加载失败' + }) + } finally { + this.setData({ + loading: false + }) + } + }, + + handleBack() { + navigation.goBack(this.data.returnTo || '/pages/home/index') + }, + + handlePreviewImage(event) { + const url = event.currentTarget.dataset.url + if (!url) { + return + } + + wx.previewImage({ + current: url, + urls: this.data.shopImages + }) + }, + + handleCopyName() { + const shopInfo = this.data.shopInfo + if (!shopInfo || !shopInfo.shopName) { + return + } + + wx.setClipboardData({ + data: shopInfo.shopName + }) + }, + + handleCopyAddress() { + const shopInfo = this.data.shopInfo + if (!shopInfo || !shopInfo.address) { + return + } + + wx.setClipboardData({ + data: shopInfo.address + }) + } +}) diff --git a/WeChatProgram/pages/shop-detail/index.json b/WeChatProgram/pages/shop-detail/index.json new file mode 100644 index 00000000..8632c9b0 --- /dev/null +++ b/WeChatProgram/pages/shop-detail/index.json @@ -0,0 +1,5 @@ +{ + "usingComponents": { + "navigation-bar": "/components/navigation-bar/navigation-bar" + } +} diff --git a/WeChatProgram/pages/shop-detail/index.wxml b/WeChatProgram/pages/shop-detail/index.wxml new file mode 100644 index 00000000..6b631ca6 --- /dev/null +++ b/WeChatProgram/pages/shop-detail/index.wxml @@ -0,0 +1,74 @@ + + + + + + + + + + + 暂时无法查看门店详情 + {{loadError}} + 返回上一页 + + + + + + 门店详情 + {{shopInfo.shopName}} + {{shopInfo.address || '门店地址待补充'}} + + + + 营业时间 + {{shopInfo.businessHours || '待补充'}} + 以到店服务时间为准 + + + 环境图片 + {{shopImages.length ? shopImages.length : 0}} 张 + 支持点击放大查看 + + + + + 营业时间 + {{shopInfo.businessHours || '待补充'}} + + + + 门店介绍 + {{shopInfo.description || '门店介绍待补充'}} + + + + 复制门店名 + 复制地址 + + + + + + + 实景展示 + 门店环境图 + 点击图片可以放大查看,更直观地感受门店氛围。 + + + + + + + + + diff --git a/WeChatProgram/pages/shop-detail/index.wxss b/WeChatProgram/pages/shop-detail/index.wxss new file mode 100644 index 00000000..56baa0b3 --- /dev/null +++ b/WeChatProgram/pages/shop-detail/index.wxss @@ -0,0 +1,91 @@ +.shop-page { + background: linear-gradient(180deg, #f4dbe3 0%, #fff8fa 220rpx, #fffdfc 100%); +} + +.shop-hero { + position: fixed; + top: 0; + left: 0; + right: 0; + height: 320rpx; + background: linear-gradient(135deg, #c6597d 0%, #8d4763 100%); +} + +.shop-hero-image { + width: 100%; + height: 100%; +} + +.shop-hero-mask { + position: absolute; + inset: 0; + background: linear-gradient(180deg, rgba(34, 21, 27, 0.12), rgba(34, 21, 27, 0.42)); +} + +.shop-content { + position: relative; + z-index: 1; + padding-top: 160rpx; +} + +.shop-card { + padding: 30rpx; +} + +.shop-title { + font-size: 42rpx; + font-weight: 700; + line-height: 1.4; + color: #2d2430; +} + +.shop-address { + margin-top: 16rpx; + font-size: 26rpx; + color: #8d7a84; + line-height: 1.7; +} + +.shop-summary { + margin-top: 24rpx; +} + +.shop-summary-value { + font-size: 26rpx; + line-height: 1.6; +} + +.detail-group { + margin-top: 24rpx; +} + +.detail-label { + font-size: 24rpx; + color: #8d7a84; +} + +.detail-value { + margin-top: 12rpx; + font-size: 28rpx; + color: #2d2430; + line-height: 1.8; +} + +.copy-row { + display: flex; + gap: 16rpx; + margin-top: 26rpx; +} + +.gallery-list { + display: flex; + flex-wrap: wrap; + gap: 18rpx; +} + +.gallery-image { + width: calc(50% - 9rpx); + height: 240rpx; + border-radius: 24rpx; + background: #f6edf1; +} diff --git a/WeChatProgram/pages/wishlist/index.js b/WeChatProgram/pages/wishlist/index.js new file mode 100644 index 00000000..6b5f59d6 --- /dev/null +++ b/WeChatProgram/pages/wishlist/index.js @@ -0,0 +1,97 @@ +const wishlistApi = require('../../api/wishlist') +const auth = require('../../utils/auth') +const navigation = require('../../utils/navigation') +const { buildProductCard } = require('../../utils/product') +const { runWithLoading } = require('../../utils/loading') + +Page({ + data: { + loading: false, + isLoggedIn: false, + wishlist: [] + }, + + onShow() { + this.loadWishlist() + }, + + async loadWishlist() { + const isLoggedIn = auth.isLoggedIn() + this.setData({ + isLoggedIn, + loading: isLoggedIn + }) + + if (!isLoggedIn) { + this.setData({ + wishlist: [], + loading: false + }) + return + } + + try { + const wishlist = await wishlistApi.getWishlist() + const list = Array.isArray(wishlist) ? wishlist : [] + const cards = await Promise.all(list.map(async item => ({ + id: item.id, + productId: item.productId, + productCard: await buildProductCard(item.product || {}) + }))) + this.setData({ + wishlist: cards + }) + } catch (error) { + this.setData({ + wishlist: [] + }) + wx.showToast({ + title: error.message || '收藏列表加载失败', + icon: 'none' + }) + } finally { + this.setData({ + loading: false + }) + } + }, + + handleOpenAuth() { + navigation.openAuth('/pages/wishlist/index') + }, + + handleProductSelect(event) { + const product = event.detail || {} + if (!product.id) { + return + } + navigation.navigate('/pages/product-detail/index', { + id: product.id + }) + }, + + async handleRemove(event) { + const productId = event.currentTarget.dataset.productId + if (!productId) { + return + } + + try { + await runWithLoading(() => wishlistApi.removeFromWishlist(productId)) + wx.showToast({ + title: '已取消收藏', + icon: 'none' + }) + this.loadWishlist() + } catch (error) { + wx.showToast({ + title: error.message || '取消收藏失败', + icon: 'none' + }) + } + }, + + handleBack() { + navigation.goBack('/pages/profile/index') + } +}) diff --git a/WeChatProgram/pages/wishlist/index.json b/WeChatProgram/pages/wishlist/index.json new file mode 100644 index 00000000..406275c1 --- /dev/null +++ b/WeChatProgram/pages/wishlist/index.json @@ -0,0 +1,6 @@ +{ + "usingComponents": { + "navigation-bar": "/components/navigation-bar/navigation-bar", + "product-card": "/components/product-card/product-card" + } +} diff --git a/WeChatProgram/pages/wishlist/index.wxml b/WeChatProgram/pages/wishlist/index.wxml new file mode 100644 index 00000000..9c336900 --- /dev/null +++ b/WeChatProgram/pages/wishlist/index.wxml @@ -0,0 +1,34 @@ + + + + + + 登录后查看收藏 + 你收藏过的作品会保存在这里,方便之后快速回看。 + 去登录 + + + + + 收藏夹 + 已收藏 {{wishlist.length}} 个作品 + 遇到喜欢的款式先放进收藏,之后再决定是否预约会更从容。 + + + + + 取消收藏 + + + + + 正在加载收藏内容 + + + + 你还没有收藏作品 + 遇到喜欢的款式先收藏,之后再决定要不要预约。 + 去逛作品 + + + diff --git a/WeChatProgram/pages/wishlist/index.wxss b/WeChatProgram/pages/wishlist/index.wxss new file mode 100644 index 00000000..962814c4 --- /dev/null +++ b/WeChatProgram/pages/wishlist/index.wxss @@ -0,0 +1,20 @@ +.wishlist-hero { + margin-bottom: 20rpx; +} + +.wishlist-item + .wishlist-item { + margin-top: 22rpx; +} + +.wishlist-action { + display: flex; + align-items: center; + justify-content: center; + height: 74rpx; + margin-top: 12rpx; + border-radius: 20rpx; + background: #fff1f5; + color: #c6597d; + font-size: 26rpx; + font-weight: 600; +} diff --git a/WeChatProgram/project.config.json b/WeChatProgram/project.config.json new file mode 100644 index 00000000..38f44398 --- /dev/null +++ b/WeChatProgram/project.config.json @@ -0,0 +1,25 @@ +{ + "setting": { + "es6": true, + "postcss": true, + "minified": true, + "uglifyFileName": false, + "enhance": true, + "packNpmRelationList": [], + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + }, + "useCompilerPlugins": false, + "minifyWXML": true + }, + "compileType": "miniprogram", + "simulatorPluginLibVersion": {}, + "packOptions": { + "ignore": [], + "include": [] + }, + "appid": "wxf76dd2d292d5e31c", + "editorSetting": {} +} \ No newline at end of file diff --git a/WeChatProgram/sitemap.json b/WeChatProgram/sitemap.json new file mode 100644 index 00000000..cd24f350 --- /dev/null +++ b/WeChatProgram/sitemap.json @@ -0,0 +1,7 @@ +{ + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", + "rules": [{ + "action": "allow", + "page": "*" + }] +} \ No newline at end of file diff --git a/WeChatProgram/utils/auth.js b/WeChatProgram/utils/auth.js new file mode 100644 index 00000000..e0beb476 --- /dev/null +++ b/WeChatProgram/utils/auth.js @@ -0,0 +1,77 @@ +const { STORAGE_KEYS, getStorage, removeStorage, setStorage } = require('./storage') + +function getAccessToken() { + return getStorage(STORAGE_KEYS.ACCESS_TOKEN, '') +} + +function getRefreshToken() { + return getStorage(STORAGE_KEYS.REFRESH_TOKEN, '') +} + +function getStoredUserInfo() { + return getStorage(STORAGE_KEYS.USER_INFO, null) +} + +function getNeedSetPassword() { + return Boolean(getStorage(STORAGE_KEYS.NEED_SET_PASSWORD, false)) +} + +function isLoggedIn() { + return Boolean(getAccessToken()) +} + +function setSession(payload) { + if (!payload || !payload.accessToken || !payload.refreshToken) { + return + } + + setStorage(STORAGE_KEYS.ACCESS_TOKEN, payload.accessToken) + setStorage(STORAGE_KEYS.REFRESH_TOKEN, payload.refreshToken) + + if (payload.userInfo) { + setStorage(STORAGE_KEYS.USER_INFO, payload.userInfo) + } + + if (payload.needSetPassword) { + setStorage(STORAGE_KEYS.NEED_SET_PASSWORD, true) + } else { + removeStorage(STORAGE_KEYS.NEED_SET_PASSWORD) + } +} + +function updateStoredUserInfo(userInfo) { + if (!userInfo) { + removeStorage(STORAGE_KEYS.USER_INFO) + return + } + + setStorage(STORAGE_KEYS.USER_INFO, userInfo) +} + +function setNeedSetPassword(value) { + if (value) { + setStorage(STORAGE_KEYS.NEED_SET_PASSWORD, true) + return + } + + removeStorage(STORAGE_KEYS.NEED_SET_PASSWORD) +} + +function clearSession() { + removeStorage(STORAGE_KEYS.ACCESS_TOKEN) + removeStorage(STORAGE_KEYS.REFRESH_TOKEN) + removeStorage(STORAGE_KEYS.USER_INFO) + removeStorage(STORAGE_KEYS.NEED_SET_PASSWORD) +} + +module.exports = { + getAccessToken, + getRefreshToken, + getStoredUserInfo, + getNeedSetPassword, + isLoggedIn, + setSession, + updateStoredUserInfo, + setNeedSetPassword, + clearSession +} diff --git a/WeChatProgram/utils/config.js b/WeChatProgram/utils/config.js new file mode 100644 index 00000000..8ab7992a --- /dev/null +++ b/WeChatProgram/utils/config.js @@ -0,0 +1,79 @@ +function getEnvVersion() { + if (typeof wx === 'undefined') { + return 'develop' + } + + try { + if (typeof wx.getAccountInfoSync === 'function') { + const accountInfo = wx.getAccountInfoSync() + const miniProgram = accountInfo && accountInfo.miniProgram + if (miniProgram && miniProgram.envVersion) { + return miniProgram.envVersion + } + } + } catch (error) {} + + try { + if (typeof __wxConfig !== 'undefined' && __wxConfig && __wxConfig.envVersion) { + return __wxConfig.envVersion + } + } catch (error) {} + + return 'develop' +} + +function getRuntimePlatform() { + if (typeof wx === 'undefined') { + return 'devtools' + } + + try { + if (typeof wx.getDeviceInfo === 'function') { + const deviceInfo = wx.getDeviceInfo() + if (deviceInfo && deviceInfo.platform) { + return deviceInfo.platform + } + } + } catch (error) {} + + try { + if (typeof wx.getSystemInfoSync === 'function') { + const systemInfo = wx.getSystemInfoSync() + if (systemInfo && systemInfo.platform) { + return systemInfo.platform + } + } + } catch (error) {} + + return 'unknown' +} + +const ENV_VERSION = getEnvVersion() +const RUNTIME_PLATFORM = getRuntimePlatform() +const IS_DEVTOOLS = RUNTIME_PLATFORM === 'devtools' + +const LOCAL_API_DOMAIN = 'http://127.0.0.1:80' +const REMOTE_API_DOMAIN = 'https://yunail.art' +const USE_LOCAL_API = ENV_VERSION === 'develop' && IS_DEVTOOLS +const API_DOMAIN = USE_LOCAL_API ? LOCAL_API_DOMAIN : REMOTE_API_DOMAIN + +module.exports = { + ENV_VERSION, + RUNTIME_PLATFORM, + IS_DEVTOOLS, + USE_LOCAL_API, + API_DOMAIN, + API_BASE_URL: `${API_DOMAIN}/api`, + IS_DEV_ENV: ENV_VERSION === 'develop', + REQUEST_TIMEOUT: 10000, + DEFAULT_AVATAR: 'https://api.dicebear.com/7.x/avataaars/svg?seed=default', + DEFAULT_PRODUCT_IMAGE: 'https://via.placeholder.com/200x200?text=Product', + DEFAULT_SHOP_IMAGE: 'https://via.placeholder.com/200x200?text=Shop', + NO_COUPON_KEY: 'NONE', + TAB_PAGES: [ + '/pages/home/index', + '/pages/products/index', + '/pages/cart/index', + '/pages/profile/index' + ] +} diff --git a/WeChatProgram/utils/file.js b/WeChatProgram/utils/file.js new file mode 100644 index 00000000..33fc55ea --- /dev/null +++ b/WeChatProgram/utils/file.js @@ -0,0 +1,67 @@ +const fileApi = require('../api/file') +const { DEFAULT_PRODUCT_IMAGE } = require('./config') +const { splitCsv } = require('./format') + +const urlCache = {} + +async function getSignedUrl(fileId) { + const key = String(fileId || '') + if (!key) { + return '' + } + + if (!urlCache[key]) { + urlCache[key] = await fileApi.getSignedUrl(key) + } + + return urlCache[key] || '' +} + +function extractLegacyFileId(value) { + const match = String(value || '') + .replace(/<[^>]*>/g, '') + .match(/\/api\/file\/get\/(\d+)/) + + return match && match[1] ? match[1] : '' +} + +async function resolveImageList(fileIds, fallbackImage) { + const ids = Array.isArray(fileIds) ? fileIds : splitCsv(fileIds) + if (!ids.length) { + return [fallbackImage || DEFAULT_PRODUCT_IMAGE] + } + + const urls = [] + for (let index = 0; index < ids.length; index += 1) { + const fileId = ids[index] + try { + const url = await getSignedUrl(fileId) + if (url) { + urls.push(url) + } + } catch (error) {} + } + + return urls.length ? urls : [fallbackImage || DEFAULT_PRODUCT_IMAGE] +} + +async function resolveLegacyImage(value, fallbackImage) { + const fileId = extractLegacyFileId(value) + if (!fileId) { + return fallbackImage || DEFAULT_PRODUCT_IMAGE + } + + try { + const url = await getSignedUrl(fileId) + return url || fallbackImage || DEFAULT_PRODUCT_IMAGE + } catch (error) { + return fallbackImage || DEFAULT_PRODUCT_IMAGE + } +} + +module.exports = { + getSignedUrl, + extractLegacyFileId, + resolveImageList, + resolveLegacyImage +} diff --git a/WeChatProgram/utils/format.js b/WeChatProgram/utils/format.js new file mode 100644 index 00000000..c3ff1dbe --- /dev/null +++ b/WeChatProgram/utils/format.js @@ -0,0 +1,103 @@ +function formatPrice(value) { + return Number(value || 0).toFixed(2) +} + +function getProductTitle(product) { + return (product && (product.title || product.name)) || '未命名作品' +} + +function splitCsv(value) { + return String(value || '') + .split(',') + .map(item => item.trim()) + .filter(Boolean) +} + +function sameId(left, right) { + return String(left || '') === String(right || '') +} + +function formatDateTime(value) { + if (!value) { + return '' + } + return String(value).replace('T', ' ').slice(0, 16) +} + +function parseAppointmentParts(value) { + const text = formatDateTime(value) + if (!text) { + return { + date: '', + clock: '' + } + } + + const parts = text.split(' ') + return { + date: parts[0] || '', + clock: parts[1] || '' + } +} + +function buildAppointmentValue(date, clock) { + if (!date || !clock) { + return '' + } + return `${date} ${clock}:00` +} + +function isPastAppointment(value) { + if (!value) { + return false + } + return new Date(String(value).replace(' ', 'T')).getTime() < Date.now() + 5 * 60 * 1000 +} + +function getMinDateText() { + const now = new Date() + const year = now.getFullYear() + const month = String(now.getMonth() + 1).padStart(2, '0') + const date = String(now.getDate()).padStart(2, '0') + return `${year}-${month}-${date}` +} + +function getOrderStatusText(order) { + if (order && order.statusText) { + return order.statusText + } + + const status = Number(order && order.status) + if (status === 1) { + return '待服务' + } + if (status === 2) { + return '已完成' + } + return '已取消' +} + +function getOrderStatusClass(order) { + const status = Number(order && order.status) + if (status === 1) { + return 'pending' + } + if (status === 2) { + return 'completed' + } + return 'cancelled' +} + +module.exports = { + formatPrice, + getProductTitle, + splitCsv, + sameId, + formatDateTime, + parseAppointmentParts, + buildAppointmentValue, + isPastAppointment, + getMinDateText, + getOrderStatusText, + getOrderStatusClass +} diff --git a/WeChatProgram/utils/loading.js b/WeChatProgram/utils/loading.js new file mode 100644 index 00000000..217aa0b5 --- /dev/null +++ b/WeChatProgram/utils/loading.js @@ -0,0 +1,51 @@ +let activeLoadingCount = 0 + +function showLoading(options) { + const config = options || {} + activeLoadingCount += 1 + + if (activeLoadingCount > 1) { + return + } + + wx.showLoading({ + title: config.title || '\u52a0\u8f7d\u4e2d', + mask: config.mask !== false + }) +} + +function hideLoading() { + activeLoadingCount = Math.max(0, activeLoadingCount - 1) + + if (activeLoadingCount > 0) { + return + } + + wx.hideLoading({ + fail() {} + }) +} + +function resetLoading() { + activeLoadingCount = 0 + wx.hideLoading({ + fail() {} + }) +} + +function runWithLoading(task, options) { + showLoading(options) + + return Promise.resolve() + .then(() => task()) + .finally(() => { + hideLoading() + }) +} + +module.exports = { + showLoading, + hideLoading, + resetLoading, + runWithLoading +} diff --git a/WeChatProgram/utils/navigation.js b/WeChatProgram/utils/navigation.js new file mode 100644 index 00000000..95892f39 --- /dev/null +++ b/WeChatProgram/utils/navigation.js @@ -0,0 +1,168 @@ +const auth = require('./auth') +const { TAB_PAGES } = require('./config') + +function buildUrl(path, params) { + const query = Object.keys(params || {}) + .filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '') + .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`) + .join('&') + + return query ? `${path}?${query}` : path +} + +function getCurrentPageUrl() { + const pages = getCurrentPages() + const current = pages[pages.length - 1] + if (!current) { + return '/pages/home/index' + } + + return buildUrl(`/${current.route}`, current.options || {}) +} + +function isTabPage(path) { + const purePath = String(path || '').split('?')[0] + return TAB_PAGES.includes(purePath) +} + +function navigate(path, params) { + return new Promise((resolve, reject) => { + wx.navigateTo({ + url: buildUrl(path, params), + success: resolve, + fail: reject + }) + }) +} + +function switchTab(path) { + return new Promise((resolve, reject) => { + wx.switchTab({ + url: path, + success: resolve, + fail: reject + }) + }) +} + +function goBack(fallbackPath) { + const pages = getCurrentPages() + if (pages.length > 1) { + wx.navigateBack() + return + } + + if (isTabPage(fallbackPath || '/pages/home/index')) { + wx.switchTab({ + url: fallbackPath || '/pages/home/index' + }) + return + } + + wx.redirectTo({ + url: fallbackPath || '/pages/home/index' + }) +} + +function parseQuery(url) { + const queryString = String(url || '').split('?')[1] || '' + if (!queryString) { + return {} + } + + return queryString.split('&').reduce((result, item) => { + const parts = item.split('=') + const key = decodeURIComponent(parts[0] || '') + const value = decodeURIComponent(parts[1] || '') + if (key) { + result[key] = value + } + return result + }, {}) +} + +function decodeRedirectValue(value) { + let current = String(value || '') + + for (let index = 0; index < 3; index += 1) { + try { + const decoded = decodeURIComponent(current) + if (decoded === current) { + return decoded + } + current = decoded + } catch (error) { + return current + } + } + + return current +} + +function redirectAfterLogin(redirect) { + const target = redirect ? decodeRedirectValue(redirect) : '' + if (!target) { + return switchTab('/pages/home/index') + } + + const purePath = target.split('?')[0] + if (purePath === '/pages/products/index') { + const app = getApp() + app.globalData.pendingProductFilter = parseQuery(target) + return switchTab('/pages/products/index') + } + + if (isTabPage(target)) { + return switchTab(purePath) + } + + return new Promise((resolve, reject) => { + wx.redirectTo({ + url: target, + success: resolve, + fail: reject + }) + }) +} + +function openAuth(redirect) { + return navigate('/pages/auth/index', { + redirect: redirect || getCurrentPageUrl() + }) +} + +function ensureLogin(actionText) { + if (auth.isLoggedIn()) { + return true + } + + wx.showToast({ + title: `${actionText || '继续操作'}前请先登录`, + icon: 'none' + }) + + setTimeout(() => { + openAuth() + }, 120) + + return false +} + +function openProducts(filter) { + const app = getApp() + app.globalData.pendingProductFilter = filter || {} + return switchTab('/pages/products/index') +} + +module.exports = { + buildUrl, + getCurrentPageUrl, + isTabPage, + navigate, + switchTab, + goBack, + redirectAfterLogin, + openAuth, + ensureLogin, + openProducts +} diff --git a/WeChatProgram/utils/product.js b/WeChatProgram/utils/product.js new file mode 100644 index 00000000..eb0e25e1 --- /dev/null +++ b/WeChatProgram/utils/product.js @@ -0,0 +1,38 @@ +const { formatPrice, getProductTitle } = require('./format') +const { resolveImageList } = require('./file') +const { DEFAULT_PRODUCT_IMAGE } = require('./config') + +function getProductTags(product) { + if (Array.isArray(product && product.tagInfos)) { + return product.tagInfos + .map(tag => tag && tag.tagName) + .filter(Boolean) + .slice(0, 3) + } + + return [] +} + +async function buildProductCard(product) { + const images = await resolveImageList(product && product.imageFileIds, DEFAULT_PRODUCT_IMAGE) + return { + ...product, + displayTitle: getProductTitle(product), + priceText: `¥${formatPrice(product && product.price)}`, + metaText: (product && (product.approximateDuration || product.shopName)) || '支持预约', + coverUrl: images[0], + imageUrls: images, + tagsPreview: getProductTags(product), + statsText: `${Number(product && product.likeCount || 0)}赞 · ${Number(product && product.collectCount || 0)}藏` + } +} + +async function buildProductCards(products) { + const list = Array.isArray(products) ? products : [] + return Promise.all(list.map(item => buildProductCard(item))) +} + +module.exports = { + buildProductCard, + buildProductCards +} diff --git a/WeChatProgram/utils/request.js b/WeChatProgram/utils/request.js new file mode 100644 index 00000000..4f464856 --- /dev/null +++ b/WeChatProgram/utils/request.js @@ -0,0 +1,247 @@ +const auth = require('./auth') +const { API_BASE_URL, REQUEST_TIMEOUT } = require('./config') + +let isRefreshing = false +let requestQueue = [] +let redirectingToAuth = false + +function buildRequestUrl(url, params) { + const query = Object.keys(params || {}) + .filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '') + .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`) + .join('&') + + const target = `${API_BASE_URL}${url}` + return query ? `${target}${target.includes('?') ? '&' : '?'}${query}` : target +} + +function isWhitelistedPath(url) { + return [ + '/user/login', + '/user/register', + '/user/check/', + '/user/refresh-token', + '/user/send-verification-code', + '/user/phone-login', + '/user/reset-password-by-phone', + '/product/get/', + '/product/list/', + '/shop/get/', + '/shop/list/public', + '/shop/list/simple', + '/tag/list/all', + '/file/get-signed-url/' + ].some(path => String(url || '').includes(path)) +} + +function normalizeError(message, statusCode, raw) { + const error = new Error(message || '请求失败') + error.statusCode = statusCode + error.raw = raw + return error +} + +function rawRequest(options) { + return new Promise((resolve, reject) => { + wx.request({ + ...options, + success: resolve, + fail: reject + }) + }) +} + +function queueRequest(retry) { + return new Promise((resolve, reject) => { + requestQueue.push({ + resolve, + reject, + retry + }) + }) +} + +function flushQueue(error) { + const queue = requestQueue.slice() + requestQueue = [] + + queue.forEach(item => { + if (error) { + item.reject(error) + return + } + + item.retry().then(item.resolve).catch(item.reject) + }) +} + +function redirectToAuth() { + if (redirectingToAuth) { + return + } + + redirectingToAuth = true + const pages = getCurrentPages() + const current = pages[pages.length - 1] + const currentPath = current ? `/${current.route}` : '/pages/home/index' + const currentQuery = current && current.options ? current.options : {} + const queryString = Object.keys(currentQuery) + .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(currentQuery[key])}`) + .join('&') + const redirect = queryString ? `${currentPath}?${queryString}` : currentPath + + wx.showToast({ + title: '登录已过期,请重新登录', + icon: 'none' + }) + + setTimeout(() => { + wx.reLaunch({ + url: `/pages/auth/index?redirect=${encodeURIComponent(redirect)}`, + complete() { + redirectingToAuth = false + } + }) + }, 300) +} + +async function refreshToken() { + const refreshTokenValue = auth.getRefreshToken() + if (!refreshTokenValue) { + throw normalizeError('缺少刷新令牌', 401) + } + + const response = await rawRequest({ + url: `${API_BASE_URL}/user/refresh-token`, + method: 'POST', + timeout: REQUEST_TIMEOUT, + header: { + 'Content-Type': 'application/json' + }, + data: { + refreshToken: refreshTokenValue + } + }) + + if (response.statusCode === 200 && response.data && response.data.code === 200 && response.data.data) { + auth.setSession(response.data.data) + const app = getApp() + if (app && typeof app.bootstrapSession === 'function') { + app.bootstrapSession() + } + return response.data.data + } + + throw normalizeError( + (response.data && response.data.message) || '刷新登录态失败', + response.statusCode, + response + ) +} + +async function handleUnauthorized(options) { + if (options._retry || isWhitelistedPath(options.url)) { + auth.clearSession() + const app = getApp() + if (app && typeof app.clearUserSession === 'function') { + app.clearUserSession() + } + redirectToAuth() + throw normalizeError('登录已过期,请重新登录', 401) + } + + if (isRefreshing) { + return queueRequest(() => request({ + ...options, + _retry: true + })) + } + + isRefreshing = true + try { + await refreshToken() + flushQueue(null) + return await request({ + ...options, + _retry: true + }) + } catch (error) { + flushQueue(error) + auth.clearSession() + const app = getApp() + if (app && typeof app.clearUserSession === 'function') { + app.clearUserSession() + } + redirectToAuth() + throw error + } finally { + isRefreshing = false + } +} + +function unwrapResponse(res, options) { + if (res.statusCode === 401) { + return handleUnauthorized(options) + } + + if (res.statusCode >= 400) { + throw normalizeError( + (res.data && res.data.message) || '网络请求失败', + res.statusCode, + res + ) + } + + const payload = res.data + if (payload && typeof payload === 'object' && Object.prototype.hasOwnProperty.call(payload, 'code')) { + if (payload.code === 200) { + return payload.data + } + + throw normalizeError(payload.message || '请求失败', payload.code, payload) + } + + return payload +} + +function request(options) { + const method = (options.method || 'GET').toUpperCase() + const header = { + 'Content-Type': 'application/json', + ...(options.header || {}) + } + + const accessToken = auth.getAccessToken() + if (accessToken) { + header.Authorization = `Bearer ${accessToken}` + } + + const requestOptions = { + ...options, + method, + header + } + + return new Promise((resolve, reject) => { + wx.request({ + url: buildRequestUrl(options.url, method === 'GET' ? options.params : undefined), + method, + timeout: options.timeout || REQUEST_TIMEOUT, + header, + data: method === 'GET' ? undefined : options.data, + success: async res => { + try { + const data = await unwrapResponse(res, requestOptions) + resolve(data) + } catch (error) { + reject(error) + } + }, + fail: error => { + reject(normalizeError(error.errMsg || '网络异常,请稍后重试', 0, error)) + } + }) + }) +} + +module.exports = request diff --git a/WeChatProgram/utils/storage.js b/WeChatProgram/utils/storage.js new file mode 100644 index 00000000..b963ea3a --- /dev/null +++ b/WeChatProgram/utils/storage.js @@ -0,0 +1,30 @@ +const STORAGE_KEYS = { + ACCESS_TOKEN: 'accessToken', + REFRESH_TOKEN: 'refreshToken', + USER_INFO: 'userInfo', + NEED_SET_PASSWORD: 'needSetPassword' +} + +function getStorage(key, defaultValue) { + try { + const value = wx.getStorageSync(key) + return value === '' || value === undefined ? defaultValue : value + } catch (error) { + return defaultValue + } +} + +function setStorage(key, value) { + wx.setStorageSync(key, value) +} + +function removeStorage(key) { + wx.removeStorageSync(key) +} + +module.exports = { + STORAGE_KEYS, + getStorage, + setStorage, + removeStorage +} diff --git a/docs/changes/2026-04-01-小程序页面设计优化.md b/docs/changes/2026-04-01-小程序页面设计优化.md new file mode 100644 index 00000000..acb0a145 --- /dev/null +++ b/docs/changes/2026-04-01-小程序页面设计优化.md @@ -0,0 +1,113 @@ +# 2026-04-01 小程序页面设计优化记录 + +## 本轮目标 + +本轮聚焦 `WeChatProgram` 小程序端的页面设计优化,不改后端接口和核心业务流程,重点解决以下问题: + +- 页面层级偏弱,首页到下单链路缺少统一视觉语言 +- 高价值页面过于“卡片堆叠”,首屏信息不够明确 +- 空状态、筛选区、吸底操作区和个人中心缺少产品感 +- 收藏、优惠券、设置等辅助页面风格与主链路不够统一 + +## 视觉方向 + +- 统一为轻盈奶油感、粉白渐变、留白更明确的视觉基调 +- 强化首屏海报感,让首页、作品列表、登录页、购物车都有明确的主信息区 +- 提升关键操作的可发现性,让“搜索、筛选、收藏、加购、预约、提交订单”都有更清晰的视觉重心 + +## 主要改动 + +### 1. 公共设计体系升级 + +- 更新 [app.wxss](/E:/code/xiaowang/WeChatProgram/app.wxss) +- 更新 [product-card.wxml](/E:/code/xiaowang/WeChatProgram/components/product-card/product-card.wxml) +- 更新 [product-card.wxss](/E:/code/xiaowang/WeChatProgram/components/product-card/product-card.wxss) + +本轮统一补充了: + +- 通用 `page-hero` 首屏容器 +- 通用 `section-*` 区块标题体系 +- 通用 `summary-strip` 信息摘要区 +- 更轻盈的 `page-card`、按钮、输入框和空状态样式 +- 作品卡片的图片层次、价格区和动作引导 + +### 2. 主链路页面重做 + +- 首页: + - [index.wxml](/E:/code/xiaowang/WeChatProgram/pages/home/index.wxml) + - [index.wxss](/E:/code/xiaowang/WeChatProgram/pages/home/index.wxss) +- 作品列表: + - [index.wxml](/E:/code/xiaowang/WeChatProgram/pages/products/index.wxml) + - [index.wxss](/E:/code/xiaowang/WeChatProgram/pages/products/index.wxss) +- 作品详情: + - [index.wxml](/E:/code/xiaowang/WeChatProgram/pages/product-detail/index.wxml) + - [index.wxss](/E:/code/xiaowang/WeChatProgram/pages/product-detail/index.wxss) +- 购物车: + - [index.wxml](/E:/code/xiaowang/WeChatProgram/pages/cart/index.wxml) + - [index.wxss](/E:/code/xiaowang/WeChatProgram/pages/cart/index.wxss) + +优化重点: + +- 首页改成“首屏引导 + 门店轮播 + 精选作品 + 热门作品”的更清晰结构 +- 作品列表强化搜索与标签筛选区,补足结果反馈和重置入口 +- 作品详情改成大图主导,补齐门店、可约信息和底部操作重心 +- 购物车补了结算摘要、预约信息层级和优惠方式展示 + +### 3. 账号与个人中心统一 + +- 登录注册: + - [index.wxml](/E:/code/xiaowang/WeChatProgram/pages/auth/index.wxml) + - [index.wxss](/E:/code/xiaowang/WeChatProgram/pages/auth/index.wxss) +- 个人中心: + - [index.wxml](/E:/code/xiaowang/WeChatProgram/pages/profile/index.wxml) + - [index.wxss](/E:/code/xiaowang/WeChatProgram/pages/profile/index.wxss) +- 设置中心: + - [index.wxml](/E:/code/xiaowang/WeChatProgram/pages/settings/index.wxml) + - [index.wxss](/E:/code/xiaowang/WeChatProgram/pages/settings/index.wxss) + +优化重点: + +- 登录页增加更完整的品牌首屏与权益说明 +- 个人中心把统计、门店、资料入口收拢到一张主卡里 +- 设置中心改成“资料维护 + 密码维护”两段式结构 + +### 4. 辅助页面统一风格 + +- 订单页: + - [index.wxml](/E:/code/xiaowang/WeChatProgram/pages/orders/index.wxml) + - [index.wxss](/E:/code/xiaowang/WeChatProgram/pages/orders/index.wxss) +- 门店详情: + - [index.wxml](/E:/code/xiaowang/WeChatProgram/pages/shop-detail/index.wxml) + - [index.wxss](/E:/code/xiaowang/WeChatProgram/pages/shop-detail/index.wxss) +- 收藏页: + - [index.wxml](/E:/code/xiaowang/WeChatProgram/pages/wishlist/index.wxml) + - [index.wxss](/E:/code/xiaowang/WeChatProgram/pages/wishlist/index.wxss) +- 优惠券页: + - [index.wxml](/E:/code/xiaowang/WeChatProgram/pages/coupons/index.wxml) + - [index.wxss](/E:/code/xiaowang/WeChatProgram/pages/coupons/index.wxss) + +优化重点: + +- 订单页增加订单总览首屏,弱化“长列表直接开始”的压迫感 +- 门店详情改成头图 + 信息摘要 + 图库的更完整结构 +- 收藏、优惠券页面补了首屏说明,避免纯列表显得单薄 + +## 影响范围 + +- 仅涉及小程序端 `WeChatProgram` 展示层文件 +- 未新增数据库变更 +- 未改后端接口协议 +- 未改下单、登录、收藏、购物车等核心业务逻辑 + +## 自检说明 + +本轮已完成以下自检: + +- 复核主要页面 WXML 结构,确认新模板已替换生效 +- 复核旧类名是否仍残留在核心页面中,避免新旧样式混用 +- 确认这次改动主要集中在 `WXML/WXSS`,没有引入额外接口依赖 + +## 备注 + +- 本轮未产生 SQL 变更 +- 本轮未更新整体架构分析文档,因为没有模块边界或数据流调整