全面优化:小程序 + 后台管理
## 小程序优化 1. 我的页面: - 头像点击获取微信头像(button open-type="chooseAvatar") - 昵称点击直接修改 - 去掉"创业伙伴"图标 - ID优先显示微信号 2. 设置页面: - 一键获取微信手机号 - 微信号/支付宝绑定优化 ## 后台管理优化 1. 内容管理: - 章节编辑增加"免费章节"开关 - 保存时自动去重标题(如#1.2重复) 2. 用户管理: - 修复绑定关系显示(优先查referral_bindings表)
This commit is contained in:
@@ -102,138 +102,41 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
// 编辑用户资料(头像和昵称)
|
||||
editProfile() {
|
||||
wx.showActionSheet({
|
||||
itemList: ['获取微信头像', '获取微信昵称', '从相册选择头像', '手动输入昵称'],
|
||||
success: (res) => {
|
||||
if (res.tapIndex === 0) {
|
||||
this.getWechatAvatar()
|
||||
} else if (res.tapIndex === 1) {
|
||||
this.getWechatNickname()
|
||||
} else if (res.tapIndex === 2) {
|
||||
this.chooseAvatar()
|
||||
} else if (res.tapIndex === 3) {
|
||||
this.editNickname()
|
||||
}
|
||||
}
|
||||
})
|
||||
// 微信头像选择回调(button open-type="chooseAvatar")
|
||||
async onChooseAvatar(e) {
|
||||
const avatarUrl = e.detail.avatarUrl
|
||||
if (!avatarUrl) return
|
||||
|
||||
wx.showLoading({ title: '更新中...', mask: true })
|
||||
|
||||
try {
|
||||
// 更新本地显示
|
||||
const userInfo = this.data.userInfo
|
||||
userInfo.avatar = avatarUrl
|
||||
this.setData({ userInfo })
|
||||
app.globalData.userInfo = userInfo
|
||||
wx.setStorageSync('userInfo', userInfo)
|
||||
|
||||
// 同步到服务器
|
||||
await app.request('/api/user/update', {
|
||||
method: 'POST',
|
||||
data: { userId: userInfo.id, avatar: avatarUrl }
|
||||
})
|
||||
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '头像已更新', icon: 'success' })
|
||||
} catch (e) {
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '更新失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
// 获取微信头像(原生能力)
|
||||
getWechatAvatar() {
|
||||
// 使用chooseAvatar API(微信原生头像选择)
|
||||
wx.chooseAvatar({
|
||||
success: async (res) => {
|
||||
const avatarUrl = res.avatarUrl
|
||||
wx.showLoading({ title: '更新中...', mask: true })
|
||||
|
||||
try {
|
||||
// 更新本地显示
|
||||
const userInfo = this.data.userInfo
|
||||
userInfo.avatar = avatarUrl
|
||||
this.setData({ userInfo })
|
||||
app.globalData.userInfo = userInfo
|
||||
wx.setStorageSync('userInfo', userInfo)
|
||||
|
||||
// 同步到服务器
|
||||
await app.request('/api/user/update', {
|
||||
method: 'POST',
|
||||
data: { userId: userInfo.id, avatar: avatarUrl }
|
||||
})
|
||||
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '头像已更新', icon: 'success' })
|
||||
} catch (e) {
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '更新失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
wx.showToast({ title: '取消选择', icon: 'none' })
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 获取微信昵称(原生能力)
|
||||
getWechatNickname() {
|
||||
// 引导用户在弹窗中输入微信昵称
|
||||
wx.showModal({
|
||||
title: '获取微信昵称',
|
||||
content: '请在下方输入您的微信昵称',
|
||||
editable: true,
|
||||
placeholderText: '请输入微信昵称',
|
||||
success: async (res) => {
|
||||
if (res.confirm && res.content) {
|
||||
const nickname = res.content.trim()
|
||||
if (nickname.length < 1 || nickname.length > 20) {
|
||||
wx.showToast({ title: '昵称1-20个字符', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 更新本地
|
||||
const userInfo = this.data.userInfo
|
||||
userInfo.nickname = nickname
|
||||
this.setData({ userInfo })
|
||||
app.globalData.userInfo = userInfo
|
||||
wx.setStorageSync('userInfo', userInfo)
|
||||
|
||||
// 同步到服务器
|
||||
try {
|
||||
await app.request('/api/user/update', {
|
||||
method: 'POST',
|
||||
data: { userId: userInfo.id, nickname }
|
||||
})
|
||||
} catch (e) {
|
||||
console.log('同步昵称到服务器失败', e)
|
||||
}
|
||||
|
||||
wx.showToast({ title: '昵称已更新', icon: 'success' })
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 从相册选择头像
|
||||
chooseAvatar() {
|
||||
wx.chooseMedia({
|
||||
count: 1,
|
||||
mediaType: ['image'],
|
||||
sourceType: ['album', 'camera'],
|
||||
success: async (res) => {
|
||||
const tempFilePath = res.tempFiles[0].tempFilePath
|
||||
wx.showLoading({ title: '上传中...', mask: true })
|
||||
|
||||
try {
|
||||
// 更新本地显示
|
||||
const userInfo = this.data.userInfo
|
||||
userInfo.avatar = tempFilePath
|
||||
this.setData({ userInfo })
|
||||
app.globalData.userInfo = userInfo
|
||||
wx.setStorageSync('userInfo', userInfo)
|
||||
|
||||
// 同步到服务器
|
||||
await app.request('/api/user/update', {
|
||||
method: 'POST',
|
||||
data: { userId: userInfo.id, avatar: tempFilePath }
|
||||
})
|
||||
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '头像已更新', icon: 'success' })
|
||||
} catch (e) {
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '上传失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 手动输入昵称
|
||||
// 点击昵称修改
|
||||
editNickname() {
|
||||
wx.showModal({
|
||||
title: '修改昵称',
|
||||
editable: true,
|
||||
placeholderText: '请输入新昵称',
|
||||
placeholderText: '请输入昵称',
|
||||
success: async (res) => {
|
||||
if (res.confirm && res.content) {
|
||||
const newNickname = res.content.trim()
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
<!-- 用户卡片 - 已登录状态 -->
|
||||
<view class="user-card card-gradient" wx:else>
|
||||
<view class="user-header-row">
|
||||
<!-- 头像可点击修改 -->
|
||||
<view class="avatar-wrapper" bindtap="editProfile">
|
||||
<!-- 头像点击获取微信头像 -->
|
||||
<button class="avatar-btn" open-type="chooseAvatar" bindchooseavatar="onChooseAvatar">
|
||||
<view class="avatar">
|
||||
<image class="avatar-img" wx:if="{{userInfo.avatar}}" src="{{userInfo.avatar}}" mode="aspectFill"/>
|
||||
<text class="avatar-text" wx:else>{{userInfo.nickname[0] || '微'}}</text>
|
||||
@@ -36,19 +36,16 @@
|
||||
<view class="avatar-edit-hint">
|
||||
<text class="edit-icon">✎</text>
|
||||
</view>
|
||||
</view>
|
||||
</button>
|
||||
|
||||
<!-- 用户信息 -->
|
||||
<!-- 用户信息 - 点击昵称修改 -->
|
||||
<view class="user-info-block">
|
||||
<view class="user-name-row">
|
||||
<view class="user-name-row" bindtap="editNickname">
|
||||
<text class="user-name">{{userInfo.nickname || '微信用户'}}</text>
|
||||
<!-- 创业伙伴标签 -->
|
||||
<view class="user-badge-small">
|
||||
<text class="badge-star">⭐</text>
|
||||
<text class="badge-label">创业伙伴</text>
|
||||
</view>
|
||||
<text class="edit-name-icon">✎</text>
|
||||
</view>
|
||||
<text class="user-id">ID: {{userIdShort}}</text>
|
||||
<text class="user-wechat" wx:if="{{userInfo.wechatId}}">微信: {{userInfo.wechatId}}</text>
|
||||
<text class="user-id" wx:else>ID: {{userIdShort}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
@@ -69,6 +69,20 @@
|
||||
margin-bottom: 36rpx;
|
||||
}
|
||||
|
||||
/* 头像按钮样式 */
|
||||
.avatar-btn {
|
||||
position: relative;
|
||||
flex-shrink: 0;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
background: transparent;
|
||||
border: none;
|
||||
line-height: normal;
|
||||
}
|
||||
.avatar-btn::after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.avatar-wrapper {
|
||||
position: relative;
|
||||
flex-shrink: 0;
|
||||
@@ -146,6 +160,18 @@
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.edit-name-icon {
|
||||
font-size: 24rpx;
|
||||
color: rgba(255,255,255,0.4);
|
||||
margin-left: 8rpx;
|
||||
}
|
||||
|
||||
.user-wechat {
|
||||
font-size: 24rpx;
|
||||
color: #00CED1;
|
||||
margin-top: 4rpx;
|
||||
}
|
||||
|
||||
.user-badge-small {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
Reference in New Issue
Block a user