优化店务小程序店铺设置和表单体验

This commit is contained in:
2026-07-22 15:41:12 +08:00
parent 492cbab0fd
commit b9989f8344
14 changed files with 543 additions and 44 deletions
+28
View File
@@ -1,5 +1,6 @@
const { BRAND_CONFIG } = require('../../utils/config')
const userApi = require('../../api/user')
const shopApi = require('../../api/shop')
const authApi = require('../../api/auth')
const auth = require('../../utils/auth')
const { chooseImageFilePath, uploadAvatar } = require('../../utils/upload')
@@ -27,9 +28,17 @@ function resolveDisplayAvatar(avatar) {
return value
}
function resolveShopCoverImage(settings) {
if (!settings || !Array.isArray(settings.coverImageUrls)) {
return ''
}
return String(settings.coverImageUrls[0] || '').trim()
}
Page({
data: {
shopName: BRAND_CONFIG.defaultShopName,
shopCoverImage: '',
phone: '店长端',
roleText: '管理端',
userInfo: {},
@@ -56,6 +65,7 @@ Page({
onShow() {
this.refreshFromSession()
this.loadShopHeader()
this.loadProfile()
},
@@ -65,6 +75,7 @@ Page({
const displayAvatar = resolveDisplayAvatar(userInfo.avatar)
this.setData({
shopName: app.globalData.shopName || BRAND_CONFIG.appName,
shopCoverImage: app.globalData.shopCoverImage || '',
phone: userInfo.contactPhone || userInfo.phone || userInfo.account || '店长端',
roleText: resolveRoleText(userInfo.type),
userInfo: {
@@ -74,6 +85,23 @@ Page({
})
},
async loadShopHeader() {
try {
const settings = await shopApi.settings()
const app = getApp()
const shopName = settings.shopName || settings.name || app.globalData.shopName || BRAND_CONFIG.appName
const shopCoverImage = resolveShopCoverImage(settings)
app.globalData.shopName = shopName
app.globalData.shopCoverImage = shopCoverImage
this.setData({
shopName,
shopCoverImage
})
} catch (error) {
wx.showToast({ title: error.message || '店铺信息加载失败', icon: 'none' })
}
},
go(event) {
const action = event.currentTarget.dataset.action
if (action === 'editProfile') {
+28 -18
View File
@@ -1,10 +1,10 @@
<view class="page">
<view class="card profile-card">
<view class="profile-main">
<view wx:if="{{userInfo.displayAvatar}}" class="shop-logo image-avatar">
<image src="{{userInfo.displayAvatar}}" mode="aspectFill"></image>
<view wx:if="{{shopCoverImage || userInfo.displayAvatar}}" class="shop-logo image-avatar">
<image src="{{shopCoverImage || userInfo.displayAvatar}}" mode="aspectFill"></image>
</view>
<view wx:else class="shop-logo">指</view>
<view wx:else class="shop-logo">店</view>
<view class="profile-copy">
<text class="shop-name">{{shopName}}</text>
<text class="phone">{{phone}}</text>
@@ -20,7 +20,7 @@
</view>
</view>
<view wx:if="{{editModalVisible}}" class="modal-mask" bindtap="closeEditProfile">
<view wx:if="{{editModalVisible}}" class="modal-mask" catchtap="stopTap">
<view class="profile-modal" catchtap="stopTap">
<view class="modal-head">
<text class="modal-title">个人信息</text>
@@ -31,25 +31,35 @@
<image src="{{profileForm.avatar}}" mode="aspectFill"></image>
</view>
<view wx:else class="profile-avatar">头像</view>
<button class="secondary-btn avatar-btn" loading="{{avatarUploading}}" bindtap="chooseProfileAvatar">上传头像</button>
<button wx:if="{{profileForm.avatar}}" class="text-btn avatar-remove" bindtap="removeProfileAvatar">移除</button>
<view class="profile-avatar-copy">
<text class="profile-avatar-name">{{profileForm.nickname || userInfo.nickname || '个人头像'}}</text>
<text class="profile-avatar-desc">这里只修改个人资料头像</text>
</view>
<button class="avatar-btn" loading="{{avatarUploading}}" bindtap="chooseProfileAvatar">上传</button>
<button wx:if="{{profileForm.avatar}}" class="avatar-remove" bindtap="removeProfileAvatar">移除</button>
</view>
<view class="profile-info-grid">
<view class="profile-info-item">
<text>登录账号</text>
<view>{{userInfo.account || '未设置'}}</view>
</view>
<view class="profile-info-item">
<text>身份</text>
<view>{{roleText}}</view>
</view>
<view class="profile-info-item">
<text>登录手机号</text>
<view>{{userInfo.phone || '未绑定'}}</view>
</view>
<view class="profile-info-item">
<text>当前店铺</text>
<view>{{shopName}}</view>
</view>
</view>
<view class="modal-field">
<text class="required-label">昵称</text>
<input value="{{profileForm.nickname}}" data-field="nickname" bindinput="onProfileInput" placeholder="请输入昵称" />
</view>
<view class="modal-field readonly-field">
<text>登录账号</text>
<view>{{userInfo.account || '未设置'}}</view>
</view>
<view class="modal-field readonly-field">
<text>身份</text>
<view>{{roleText}}</view>
</view>
<view class="modal-field readonly-field">
<text>登录手机号</text>
<view>{{userInfo.phone || '未绑定'}}</view>
</view>
<view class="modal-field">
<text>联系电话</text>
<input value="{{profileForm.contactPhone}}" data-field="contactPhone" bindinput="onProfileInput" type="number" placeholder="请输入联系电话" />
+96 -8
View File
@@ -112,7 +112,7 @@
width: 100%;
max-height: 88vh;
overflow-y: auto;
padding: 28rpx 28rpx calc(28rpx + env(safe-area-inset-bottom));
padding: 28rpx 28rpx calc(30rpx + env(safe-area-inset-bottom));
border-radius: 28rpx 28rpx 0 0;
background: #fffaf4;
box-shadow: 0 -18rpx 40rpx rgba(41, 31, 23, 0.16);
@@ -170,10 +170,10 @@
.profile-avatar-row {
display: flex;
align-items: center;
gap: 16rpx;
gap: 18rpx;
margin-bottom: 18rpx;
padding: 18rpx;
border-radius: 18rpx;
border-radius: 20rpx;
background: #f7efe7;
}
@@ -197,14 +197,96 @@
height: 100%;
}
.avatar-btn {
flex: 1;
.profile-avatar-copy {
min-width: 0;
max-width: none;
flex: 1;
}
.profile-avatar-name,
.profile-avatar-desc {
display: block;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.profile-avatar-name {
color: #29241f;
font-size: 28rpx;
font-weight: 900;
}
.profile-avatar-desc {
margin-top: 8rpx;
color: #8a7f75;
font-size: 22rpx;
}
.avatar-btn {
display: flex;
align-items: center;
justify-content: center;
flex: 0 0 auto;
min-width: 104rpx;
min-height: 58rpx;
padding: 0 18rpx;
border-radius: 16rpx;
background: #fffdf8;
color: #72553b;
font-size: 24rpx;
font-weight: 900;
}
.avatar-remove {
display: flex;
align-items: center;
justify-content: center;
flex: 0 0 auto;
min-width: 76rpx;
min-height: 58rpx;
padding: 0 16rpx;
border-radius: 16rpx;
background: #f0e5dc;
color: #9a5f43;
font-size: 24rpx;
font-weight: 900;
}
.profile-info-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 14rpx;
margin-bottom: 18rpx;
}
.profile-info-item {
min-width: 0;
padding: 16rpx;
border-radius: 18rpx;
background: #f7efe7;
}
.profile-info-item text,
.profile-info-item view {
display: block;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.profile-info-item text {
color: #8a7f75;
font-size: 22rpx;
font-weight: 800;
}
.profile-info-item view {
margin-top: 8rpx;
color: #2c2722;
font-size: 25rpx;
font-weight: 900;
}
.modal-field {
@@ -226,18 +308,24 @@
.modal-field textarea,
.readonly-field view {
width: 100%;
padding: 0 18rpx;
border: 1rpx solid #eadfd2;
border-radius: 16rpx;
background: #fffdf8;
color: #2c2722;
font-size: 28rpx;
}
.modal-field input,
.readonly-field view {
min-height: 58rpx;
line-height: 58rpx;
min-height: 70rpx;
line-height: 70rpx;
}
.modal-field textarea {
min-height: 120rpx;
padding-top: 18rpx;
padding-bottom: 18rpx;
}
.readonly-field view {