优化:个人信息改为独立页面

This commit is contained in:
2026-10-10 17:32:26 +08:00
parent 72bfcffc25
commit 804c69c296
12 changed files with 226 additions and 326 deletions
+1
View File
@@ -15,6 +15,7 @@
"pages/leave-management/index",
"pages/color-setting/index",
"pages/profile/index",
"pages/profile-edit/index",
"pages/account-settings/index",
"pages/shop-settings/index",
"pages/export/index",
+4 -2
View File
@@ -3,6 +3,7 @@ const dateUtil = require('../../utils/date')
const userApi = require('../../api/user')
const auth = require('../../utils/auth')
const { uploadProfileImage } = require('../../utils/upload')
const { normalizeAvatar } = require('../../utils/profile-card')
function canCreateAppointment() {
const app = getApp()
@@ -117,11 +118,12 @@ Page({
const today = dateUtil.formatDate(new Date())
const dismissed = wx.getStorageSync(auth.PHONE_BANNER_DISMISSED_KEY)
const missingNickname = !String(profile.nickname || '').trim() || String(profile.nickname).startsWith('微信用户')
const avatar = normalizeAvatar(profile.avatar)
const skipped = wx.getStorageSync(auth.PROFILE_PROMPT_SKIPPED_KEY) === '1'
this.setData({
phoneBannerVisible: Number(profile.phoneVerified) !== 1 && dismissed !== today,
profilePromptVisible: !skipped && (missingNickname || !profile.avatar),
profileForm: { nickname: missingNickname ? '' : profile.nickname, avatar: profile.avatar || '' }
profilePromptVisible: !skipped && (missingNickname || !avatar),
profileForm: { nickname: missingNickname ? '' : profile.nickname, avatar }
})
} catch (error) {
// 资料提醒失败不影响规划数据。
+140
View File
@@ -0,0 +1,140 @@
const userApi = require('../../api/user')
const auth = require('../../utils/auth')
const { chooseImageFilePath, uploadProfileImage } = require('../../utils/upload')
const { buildProfileCard, normalizeAvatar } = require('../../utils/profile-card')
const { BRAND_CONFIG } = require('../../utils/config')
function resolveRoleText(type) {
const role = Number(type)
if (role === 2) return '店长'
if (role === 3) return '美甲师'
if (role === 4) return '管理员'
return '管理端'
}
function buildPageState(profile, fallbackShopName) {
const source = profile || {}
const card = buildProfileCard(source, fallbackShopName)
return {
profile: source,
avatarText: card.avatarText,
roleText: resolveRoleText(source.type),
shopName: card.shopName,
form: {
nickname: source.nickname || '',
avatar: normalizeAvatar(source.avatar),
contactPhone: source.contactPhone || '',
wechatId: source.wechatId || '',
signature: source.signature || ''
}
}
}
Page({
data: {
loading: true,
saving: false,
avatarUploading: false,
profile: {},
avatarText: '用',
roleText: '管理端',
shopName: BRAND_CONFIG.defaultShopName,
form: { nickname: '', avatar: '', contactPhone: '', wechatId: '', signature: '' }
},
onLoad() {
const app = getApp()
const state = buildPageState(app.globalData.userInfo || {}, app.globalData.shopName || BRAND_CONFIG.defaultShopName)
this.setData(state)
},
onShow() {
this.loadProfile()
},
async loadProfile() {
this.setData({ loading: true })
try {
const profile = await userApi.info()
this.syncProfileToSession(profile)
} catch (error) {
wx.showToast({ title: error.message || '个人信息加载失败', icon: 'none' })
} finally {
this.setData({ loading: false })
}
},
syncProfileToSession(profile) {
const app = getApp()
const session = auth.getSession()
const current = session.userInfo || app.globalData.userInfo || {}
const next = {
...current,
...profile,
nickname: profile.nickname || '',
avatar: profile.avatar || '',
contactPhone: profile.contactPhone || '',
wechatId: profile.wechatId || '',
signature: profile.signature || '',
shopName: profile.shopName || current.shopName || session.shopName || app.globalData.shopName || ''
}
app.setSession({ ...session, shopName: next.shopName || session.shopName, userInfo: next })
this.setData(buildPageState(next, app.globalData.shopName || BRAND_CONFIG.defaultShopName))
},
onInput(event) {
this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value })
},
async chooseAvatar() {
if (this.data.avatarUploading || this.data.saving) return
try {
const filePath = await chooseImageFilePath()
if (!filePath) return
this.setData({ avatarUploading: true })
const avatar = await uploadProfileImage(filePath)
this.setData({ 'form.avatar': avatar })
} catch (error) {
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
} finally {
this.setData({ avatarUploading: false })
}
},
removeAvatar() {
if (!this.data.avatarUploading && !this.data.saving) this.setData({ 'form.avatar': '' })
},
async save() {
if (this.data.saving || this.data.avatarUploading) return
const form = this.data.form
const nickname = String(form.nickname || '').trim()
const contactPhone = String(form.contactPhone || '').trim()
if (!nickname) {
wx.showToast({ title: '请填写昵称', icon: 'none' })
return
}
if (contactPhone && !/^1[3-9]\d{9}$/.test(contactPhone)) {
wx.showToast({ title: '请输入正确联系电话', icon: 'none' })
return
}
this.setData({ saving: true })
try {
await userApi.updateInfo({
nickname,
avatar: form.avatar || '',
contactPhone,
wechatId: String(form.wechatId || '').trim(),
signature: String(form.signature || '').trim()
})
const profile = await userApi.info()
this.syncProfileToSession(profile)
wx.showToast({ title: '已保存', icon: 'success' })
setTimeout(() => wx.navigateBack(), 350)
} catch (error) {
wx.showToast({ title: error.message || '保存失败', icon: 'none' })
} finally {
this.setData({ saving: false })
}
}
})
@@ -0,0 +1,3 @@
{
"navigationBarTitleText": "个人信息"
}
@@ -0,0 +1,33 @@
<view class="page no-tab profile-edit-page">
<view wx:if="{{loading}}" class="loading-line">正在加载个人信息...</view>
<view class="card avatar-card">
<view class="avatar-preview">
<image wx:if="{{form.avatar}}" src="{{form.avatar}}" mode="aspectFill"></image>
<text wx:else>{{avatarText}}</text>
</view>
<view class="avatar-copy">
<text class="avatar-title">个人头像</text>
<text class="avatar-desc">上传清晰头像,方便门店成员识别</text>
</view>
<button class="avatar-action" loading="{{avatarUploading}}" disabled="{{saving}}" bindtap="chooseAvatar">{{form.avatar ? '更换' : '上传'}}</button>
</view>
<button wx:if="{{form.avatar}}" class="remove-avatar" disabled="{{saving || avatarUploading}}" bindtap="removeAvatar">移除当前头像</button>
<view class="section-title">基本资料</view>
<view class="card form-card">
<view class="field"><text class="field-label required">昵称</text><input value="{{form.nickname}}" data-field="nickname" bindinput="onInput" maxlength="30" placeholder="请输入昵称" /></view>
<view class="field"><text class="field-label">联系电话</text><input value="{{form.contactPhone}}" data-field="contactPhone" bindinput="onInput" type="number" maxlength="11" placeholder="请输入联系电话" /></view>
<view class="field"><text class="field-label">微信号</text><input value="{{form.wechatId}}" data-field="wechatId" bindinput="onInput" maxlength="50" placeholder="请输入微信号" /></view>
<view class="field signature-field"><text class="field-label">个性签名</text><textarea value="{{form.signature}}" data-field="signature" bindinput="onInput" maxlength="200" placeholder="请输入个人签名" /></view>
</view>
<view class="section-title account-title">账号信息</view>
<view class="card readonly-card">
<view class="readonly-row"><text>登录账号</text><text>{{profile.account || '未设置'}}</text></view>
<view class="readonly-row"><text>所属门店</text><text>{{shopName}}</text></view>
<view class="readonly-row"><text>身份</text><text>{{roleText}}</text></view>
</view>
<view class="fixed-bottom"><button class="primary-btn" loading="{{saving}}" disabled="{{loading || avatarUploading}}" bindtap="save">保存个人信息</button></view>
</view>
@@ -0,0 +1,23 @@
.profile-edit-page { padding-top:24rpx; }
.loading-line { margin-bottom:16rpx; color:#8e9c94; font-size:22rpx; text-align:center; }
.avatar-card { display:flex; align-items:center; padding:26rpx; }
.avatar-preview { display:flex; width:104rpx; height:104rpx; flex:none; align-items:center; justify-content:center; overflow:hidden; border-radius:26rpx; background:#6f8f83; color:#fff; font-size:40rpx; font-weight:900; }
.avatar-preview image { width:100%; height:100%; }
.avatar-copy { display:flex; min-width:0; flex:1; flex-direction:column; margin-left:20rpx; }
.avatar-title { color:#30483c; font-size:28rpx; font-weight:800; }
.avatar-desc { margin-top:8rpx; color:#8a9a91; font-size:21rpx; line-height:1.5; }
.avatar-action { min-width:112rpx; height:60rpx; margin-left:16rpx; padding:0 20rpx; border-radius:999rpx; background:#e5eee9; color:#4e7165; font-size:23rpx; font-weight:800; line-height:60rpx; }
.remove-avatar { width:auto; margin:14rpx 6rpx 0 auto; color:#a36b5d; font-size:22rpx; }
.section-title { margin:30rpx 4rpx 14rpx; }
.form-card { padding:0 24rpx; }
.field-label { width:170rpx; }
.field input,.field textarea { text-align:right; }
.signature-field { align-items:flex-start; }
.signature-field .field-label { padding-top:34rpx; }
.signature-field textarea { text-align:left; }
.account-title { margin-top:26rpx; }
.readonly-card { padding:0 24rpx; }
.readonly-row { display:flex; min-height:92rpx; align-items:center; justify-content:space-between; gap:30rpx; border-bottom:1rpx solid #eee8df; font-size:25rpx; }
.readonly-row:last-child { border-bottom:0; }
.readonly-row text:first-child { color:#625c55; font-weight:700; }
.readonly-row text:last-child { min-width:0; color:#8a837b; text-align:right; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
+1 -106
View File
@@ -1,7 +1,6 @@
const { BRAND_CONFIG } = require('../../utils/config')
const userApi = require('../../api/user')
const auth = require('../../utils/auth')
const { chooseImageFilePath, uploadProfileImage } = require('../../utils/upload')
const planningApi = require('../../api/planning')
const employeesApi = require('../../api/employees')
const shopApi = require('../../api/shop')
@@ -19,18 +18,7 @@ function resolveRoleText(type) {
Page({
data: {
roleText: '管理端',
userInfo: {},
profileCard: buildProfileCard({}, BRAND_CONFIG.defaultShopName),
editModalVisible: false,
profileSaving: false,
avatarUploading: false,
profileForm: {
nickname: '',
avatar: '',
contactPhone: '',
wechatId: '',
signature: ''
},
overviewLoading: false,
overview: {
date: '',
@@ -43,7 +31,7 @@ Page({
shopStatus: '营业中'
},
menus: [
{ title: '个人信息', action: 'editProfile' },
{ title: '个人信息', url: '/pages/profile-edit/index' },
{ title: '账号设置', url: '/pages/account-settings/index' },
{ title: '店铺设置', url: '/pages/shop-settings/index' },
{ title: '数据导出', url: '/pages/export/index' },
@@ -112,17 +100,11 @@ Page({
const fallbackShopName = app.globalData.shopName || BRAND_CONFIG.defaultShopName
this.setData({
roleText: resolveRoleText(userInfo.type),
userInfo,
profileCard: buildProfileCard(userInfo, fallbackShopName)
})
},
go(event) {
const action = event.currentTarget.dataset.action
if (action === 'editProfile') {
this.openEditProfile()
return
}
wx.navigateTo({ url: event.currentTarget.dataset.url })
},
@@ -161,95 +143,8 @@ Page({
userInfo: nextUserInfo
})
this.setData({
userInfo: nextUserInfo,
roleText: resolveRoleText(nextUserInfo.type),
profileCard: buildProfileCard(nextUserInfo, BRAND_CONFIG.defaultShopName)
})
},
openEditProfile() {
const userInfo = this.data.userInfo || {}
this.setData({
editModalVisible: true,
profileForm: {
nickname: userInfo.nickname || '',
avatar: userInfo.avatar || '',
contactPhone: userInfo.contactPhone || '',
wechatId: userInfo.wechatId || '',
signature: userInfo.signature || ''
}
})
},
closeEditProfile() {
if (this.data.profileSaving || this.data.avatarUploading) {
return
}
this.setData({ editModalVisible: false })
},
stopTap() {
},
onProfileInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`profileForm.${field}`]: event.detail.value
})
},
async chooseProfileAvatar() {
if (this.data.avatarUploading || this.data.profileSaving) {
return
}
try {
const filePath = await chooseImageFilePath()
if (!filePath) {
return
}
this.setData({ avatarUploading: true })
const avatar = await uploadProfileImage(filePath)
this.setData({ 'profileForm.avatar': avatar })
} catch (error) {
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
} finally {
this.setData({ avatarUploading: false })
}
},
removeProfileAvatar() {
this.setData({ 'profileForm.avatar': '' })
},
async saveProfile() {
const form = this.data.profileForm
const nickname = String(form.nickname || '').trim()
const contactPhone = String(form.contactPhone || '').trim()
if (contactPhone && !/^1[3-9]\d{9}$/.test(contactPhone)) {
wx.showToast({ title: '请输入正确联系电话', icon: 'none' })
return
}
if (!nickname) {
wx.showToast({ title: '请填写昵称', icon: 'none' })
return
}
this.setData({ profileSaving: true })
try {
await userApi.updateInfo({
nickname,
avatar: form.avatar || '',
contactPhone,
wechatId: String(form.wechatId || '').trim(),
signature: String(form.signature || '').trim()
})
const profile = await userApi.info()
this.syncProfileToSession(profile)
this.setData({ editModalVisible: false })
wx.showToast({ title: '已保存', icon: 'success' })
} catch (error) {
wx.showToast({ title: error.message || '保存失败', icon: 'none' })
} finally {
this.setData({ profileSaving: false })
}
}
})
+1 -46
View File
@@ -49,55 +49,10 @@
</view>
<view class="section menu-list card">
<view wx:for="{{menus}}" wx:key="title" class="menu-row" data-url="{{item.url}}" data-action="{{item.action}}" bindtap="go">
<view wx:for="{{menus}}" wx:key="title" class="menu-row" data-url="{{item.url}}" bindtap="go">
<text>{{item.title}}</text>
<text class="arrow">›</text>
</view>
</view>
<view wx:if="{{editModalVisible}}" class="modal-mask" bindtap="closeEditProfile">
<view class="profile-modal" catchtap="stopTap">
<view class="modal-head">
<text class="modal-title">个人信息</text>
<view class="modal-close" bindtap="closeEditProfile">×</view>
</view>
<view class="profile-avatar-row">
<view wx:if="{{profileForm.avatar}}" class="profile-avatar image-avatar">
<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>
<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" maxlength="11" placeholder="请输入联系电话" />
</view>
<view class="modal-field">
<text>微信号</text>
<input value="{{profileForm.wechatId}}" data-field="wechatId" bindinput="onProfileInput" placeholder="请输入微信号" />
</view>
<view class="modal-field">
<text>签名</text>
<textarea value="{{profileForm.signature}}" data-field="signature" bindinput="onProfileInput" placeholder="请输入个人签名" />
</view>
<button class="primary-btn modal-submit" loading="{{profileSaving}}" bindtap="saveProfile">保存个人信息</button>
</view>
</view>
</view>
-169
View File
@@ -177,172 +177,3 @@
color: #b0a79e;
font-size: 44rpx;
}
.modal-mask {
position: fixed;
inset: 0;
z-index: 80;
display: flex;
align-items: flex-end;
justify-content: center;
background: rgba(18, 15, 12, 0.48);
animation: maskIn 180ms ease both;
}
.profile-modal {
width: 100%;
max-height: 88vh;
overflow-y: auto;
padding: 28rpx 28rpx calc(28rpx + env(safe-area-inset-bottom));
border-radius: 28rpx 28rpx 0 0;
background: #fffaf4;
box-shadow: 0 -18rpx 40rpx rgba(41, 31, 23, 0.16);
animation: modalUp 220ms ease both;
}
.modal-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20rpx;
margin-bottom: 20rpx;
}
.modal-title {
color: #27211d;
font-size: 34rpx;
font-weight: 900;
}
.modal-close {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 48rpx;
min-width: 48rpx;
height: 48rpx;
border-radius: 50%;
border: 1rpx solid #e4d8ca;
background: #fffaf4;
color: transparent;
font-size: 0;
line-height: 0;
}
.modal-close::before,
.modal-close::after {
content: "";
position: absolute;
width: 22rpx;
height: 3rpx;
border-radius: 999rpx;
background: #61554c;
}
.modal-close::before {
transform: rotate(45deg);
}
.modal-close::after {
transform: rotate(-45deg);
}
.profile-avatar-row {
display: flex;
align-items: center;
gap: 16rpx;
margin-bottom: 18rpx;
padding: 18rpx;
border-radius: 18rpx;
background: #f7efe7;
}
.profile-avatar {
display: flex;
align-items: center;
justify-content: center;
flex: 0 0 auto;
width: 92rpx;
height: 92rpx;
overflow: hidden;
border-radius: 50%;
background: #6f8f83;
color: #fff;
font-size: 24rpx;
font-weight: 900;
}
.profile-avatar image {
width: 100%;
height: 100%;
}
.avatar-btn {
flex: 1;
min-width: 0;
max-width: none;
}
.avatar-remove {
flex: 0 0 auto;
}
.modal-field {
margin-bottom: 16rpx;
padding: 16rpx 18rpx;
border-radius: 18rpx;
background: #f7efe7;
}
.modal-field text {
display: block;
margin-bottom: 8rpx;
color: #6c5f54;
font-size: 24rpx;
font-weight: 800;
}
.modal-field input,
.modal-field textarea,
.readonly-field view {
width: 100%;
color: #2c2722;
font-size: 28rpx;
}
.modal-field input,
.readonly-field view {
min-height: 58rpx;
line-height: 58rpx;
}
.modal-field textarea {
min-height: 120rpx;
}
.readonly-field view {
color: #7f756b;
}
.modal-submit {
margin-top: 22rpx;
}
@keyframes maskIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes modalUp {
from {
transform: translateY(40rpx);
}
to {
transform: translateY(0);
}
}
+9 -2
View File
@@ -1,18 +1,25 @@
const DEFAULT_AVATAR_URL = 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'
function cleanText(value) {
return String(value || '').trim()
}
function normalizeAvatar(value) {
const avatar = cleanText(value)
return avatar === DEFAULT_AVATAR_URL ? '' : avatar
}
function buildProfileCard(userInfo, fallbackShopName) {
const user = userInfo || {}
const nickname = cleanText(user.nickname) || cleanText(user.account) || '未设置昵称'
const shopName = cleanText(user.shopName) || cleanText(fallbackShopName) || '未设置门店'
return {
avatar: cleanText(user.avatar),
avatar: normalizeAvatar(user.avatar),
avatarText: Array.from(nickname)[0] || '用',
nickname,
shopName
}
}
module.exports = { buildProfileCard }
module.exports = { DEFAULT_AVATAR_URL, buildProfileCard, normalizeAvatar }
+4 -1
View File
@@ -1,6 +1,6 @@
const assert = require('assert')
const { buildProfileCard } = require('./profile-card')
const { DEFAULT_AVATAR_URL, buildProfileCard, normalizeAvatar } = require('./profile-card')
assert.deepStrictEqual(buildProfileCard({
nickname: '小屿',
@@ -26,3 +26,6 @@ assert.deepStrictEqual(buildProfileCard({}, ''), {
nickname: '未设置昵称',
shopName: '未设置门店'
})
assert.strictEqual(normalizeAvatar(DEFAULT_AVATAR_URL), '')
assert.strictEqual(buildProfileCard({ nickname: '小屿', avatar: DEFAULT_AVATAR_URL }, '中心店').avatar, '')
+7
View File
@@ -1,5 +1,12 @@
# 项目变更记录
## 2026-10-10 Salon 小程序个人信息独立页面
- 新增独立“个人信息”页面,页面结构与账号设置统一,承载头像、昵称、联系电话、微信号和个性签名编辑,以及账号、门店和身份只读信息。
- “我的”页面个人信息入口改为页面导航,删除原有底部弹窗、表单状态、上传保存方法和冗余样式。
- 保存后同步本机会话并返回“我的”页面,顶部账号卡可立即刷新。
- 将后端通用外链默认头像识别为未设置头像,“我的”和“个人信息”页面统一使用昵称首字兜底,首页资料完善提示仍会正确引导上传真实头像。
## 2026-10-10 Salon 小程序“我的”页面账号卡优化
- “我的”页面顶部卡片改为展示当前账号头像、昵称、所属门店和角色,不再展示固定品牌图标与“店长端”占位信息。