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

This commit is contained in:
xiaowang
2026-04-01 15:18:35 +08:00
parent bb2d8c4410
commit 7fa67d0511
92 changed files with 7463 additions and 0 deletions
+190
View File
@@ -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'
})
}
})
+5
View File
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
+87
View File
@@ -0,0 +1,87 @@
<view class="profile-page-root">
<navigation-bar title="个人中心" back="{{false}}" color="#ffffff" background="transparent"></navigation-bar>
<view class="profile-bg"></view>
<scroll-view class="profile-scroll" scroll-y enable-flex enhanced show-scrollbar="false">
<view class="page-shell profile-page">
<view class="page-content profile-content">
<view wx:if="{{!isLoggedIn}}" class="page-card guest-card">
<image class="guest-avatar" src="{{defaultAvatar}}" mode="aspectFill"></image>
<view class="guest-title">还没有登录账号</view>
<view class="guest-desc">登录后可以查看订单、收藏作品、领取和使用优惠。</view>
<view class="primary-btn" bindtap="handleOpenAuth">去登录</view>
</view>
<block wx:elif="{{userInfo}}">
<view class="page-card profile-card">
<view class="profile-top">
<image class="avatar" src="{{userInfo.avatar || defaultAvatar}}" mode="aspectFill"></image>
<view class="profile-copy">
<view class="nickname">{{userInfo.nickname || 'Yumi 用户'}}</view>
<view class="account">{{userInfo.account}}</view>
<view wx:if="{{userInfo.signature}}" class="signature">{{userInfo.signature}}</view>
</view>
</view>
<view class="summary-strip profile-stats">
<view class="summary-metric" bindtap="handleOpenOrders">
<text class="summary-label">订单</text>
<text class="summary-value">{{orderCount}}</text>
<text class="summary-note">查看预约记录</text>
</view>
<view class="summary-metric" bindtap="handleOpenWishlist">
<text class="summary-label">收藏</text>
<text class="summary-value">{{wishlistCount}}</text>
<text class="summary-note">回看喜欢的作品</text>
</view>
<view class="summary-metric" bindtap="handleOpenCoupons">
<text class="summary-label">优惠券</text>
<text class="summary-value">{{couponCount}}</text>
<text class="summary-note">结算前可直接使用</text>
</view>
</view>
<view class="shop-box" bindtap="handleSwitchShop">
<view>
<view class="shop-label">当前登录门店</view>
<view class="shop-name">{{userInfo.shopName || '暂未选择门店'}}</view>
</view>
<view class="shop-link">{{(userInfo.shopIds && userInfo.shopIds.length > 1) ? '切换' : '查看'}}</view>
</view>
<view wx:if="{{needSetPassword}}" class="password-tip">
建议尽快补充登录密码,之后切换设备会更方便。
</view>
<view class="secondary-btn edit-btn" bindtap="handleOpenSettings">编辑资料与设置</view>
</view>
<view class="page-card menu-card">
<view class="section-title">常用入口</view>
<view class="section-subtitle">订单、收藏、优惠券和账号设置都集中在这里。</view>
<view class="menu-item" bindtap="handleOpenOrders">
<text>我的订单</text>
<text class="menu-arrow">></text>
</view>
<view class="menu-item" bindtap="handleOpenWishlist">
<text>我的收藏</text>
<text class="menu-arrow">></text>
</view>
<view class="menu-item" bindtap="handleOpenCoupons">
<text>我的优惠券</text>
<text class="menu-arrow">></text>
</view>
<view class="menu-item" bindtap="handleOpenSettings">
<text>设置中心</text>
<text class="menu-arrow">></text>
</view>
<view class="menu-item logout-item" bindtap="handleLogout">
<text>退出登录</text>
<text class="menu-arrow">></text>
</view>
</view>
</block>
</view>
</view>
</scroll-view>
</view>
+175
View File
@@ -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;
}