chore: 清理敏感与开发文档,仅同步代码
- 永久忽略并从仓库移除 开发文档/ - 移除并忽略 .env 与小程序私有配置 - 同步小程序/管理端/API与脚本改动 Made-with: Cursor
This commit is contained in:
@@ -10,6 +10,12 @@ Page({
|
||||
isLoggedIn: false,
|
||||
userInfo: null,
|
||||
version: '1.0.0',
|
||||
isDevMode: false, // 是否开发版(用于显示切换账号入口)
|
||||
|
||||
// 切换账号(开发)
|
||||
showSwitchAccountModal: false,
|
||||
switchAccountUserId: '',
|
||||
switchAccountLoading: false,
|
||||
|
||||
// 绑定信息
|
||||
phoneNumber: '',
|
||||
@@ -28,10 +34,13 @@ Page({
|
||||
|
||||
onLoad() {
|
||||
wx.showShareMenu({ withShareTimeline: true })
|
||||
const accountInfo = wx.getAccountInfoSync ? wx.getAccountInfoSync() : null
|
||||
const envVersion = accountInfo?.miniProgram?.envVersion || ''
|
||||
this.setData({
|
||||
statusBarHeight: app.globalData.statusBarHeight,
|
||||
isLoggedIn: app.globalData.isLoggedIn,
|
||||
userInfo: app.globalData.userInfo
|
||||
userInfo: app.globalData.userInfo,
|
||||
isDevMode: envVersion === 'develop'
|
||||
})
|
||||
this.loadBindingInfo()
|
||||
},
|
||||
@@ -236,85 +245,66 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
// 获取微信头像(新版授权)
|
||||
async getWechatAvatar() {
|
||||
// 微信原生 chooseAvatar 回调
|
||||
async onChooseAvatar(e) {
|
||||
const tempAvatarUrl = e.detail?.avatarUrl
|
||||
if (!tempAvatarUrl) return
|
||||
wx.showLoading({ title: '上传中...', mask: true })
|
||||
try {
|
||||
const res = await wx.getUserProfile({
|
||||
desc: '用于完善会员资料'
|
||||
})
|
||||
|
||||
if (res.userInfo) {
|
||||
const { nickName, avatarUrl: tempAvatarUrl } = res.userInfo
|
||||
|
||||
wx.showLoading({ title: '上传中...', mask: true })
|
||||
|
||||
// 1. 先上传图片到服务器
|
||||
console.log('[Settings] 开始上传头像:', tempAvatarUrl)
|
||||
|
||||
const uploadRes = await new Promise((resolve, reject) => {
|
||||
wx.uploadFile({
|
||||
url: app.globalData.baseUrl + '/api/miniprogram/upload',
|
||||
filePath: tempAvatarUrl,
|
||||
name: 'file',
|
||||
formData: {
|
||||
folder: 'avatars'
|
||||
},
|
||||
success: (uploadResult) => {
|
||||
try {
|
||||
const data = JSON.parse(uploadResult.data)
|
||||
if (data.success) {
|
||||
resolve(data)
|
||||
} else {
|
||||
reject(new Error(data.error || '上传失败'))
|
||||
}
|
||||
} catch (err) {
|
||||
reject(new Error('解析响应失败'))
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err)
|
||||
const uploadRes = await new Promise((resolve, reject) => {
|
||||
wx.uploadFile({
|
||||
url: app.globalData.baseUrl + '/api/miniprogram/upload',
|
||||
filePath: tempAvatarUrl,
|
||||
name: 'file',
|
||||
formData: { folder: 'avatars' },
|
||||
success: (uploadResult) => {
|
||||
try {
|
||||
const data = JSON.parse(uploadResult.data)
|
||||
if (data.success) resolve(data)
|
||||
else reject(new Error(data.error || '上传失败'))
|
||||
} catch (err) {
|
||||
reject(new Error('解析响应失败'))
|
||||
}
|
||||
})
|
||||
},
|
||||
fail: reject
|
||||
})
|
||||
|
||||
// 2. 获取上传后的完整URL
|
||||
const avatarUrl = app.globalData.baseUrl + uploadRes.data.url
|
||||
console.log('[Settings] 头像上传成功:', avatarUrl)
|
||||
|
||||
// 3. 更新本地
|
||||
this.setData({
|
||||
userInfo: {
|
||||
...this.data.userInfo,
|
||||
nickname: nickName,
|
||||
avatar: avatarUrl
|
||||
}
|
||||
})
|
||||
|
||||
const rawUrl = uploadRes.data.url || ''
|
||||
const avatarUrl = rawUrl.startsWith('http://') || rawUrl.startsWith('https://')
|
||||
? rawUrl
|
||||
: app.globalData.baseUrl + rawUrl
|
||||
const nickname = this.data.userInfo?.nickname || app.globalData.userInfo?.nickname || ''
|
||||
|
||||
this.setData({
|
||||
userInfo: {
|
||||
...this.data.userInfo,
|
||||
nickname,
|
||||
avatar: avatarUrl
|
||||
}
|
||||
})
|
||||
|
||||
const userId = app.globalData.userInfo?.id
|
||||
if (userId) {
|
||||
await app.request('/api/miniprogram/user/profile', {
|
||||
method: 'POST',
|
||||
data: { userId, nickname, avatar: avatarUrl }
|
||||
})
|
||||
|
||||
// 4. 同步到服务器数据库
|
||||
const userId = app.globalData.userInfo?.id
|
||||
if (userId) {
|
||||
await app.request('/api/miniprogram/user/profile', {
|
||||
method: 'POST',
|
||||
data: { userId, nickname: nickName, avatar: avatarUrl }
|
||||
})
|
||||
}
|
||||
|
||||
// 5. 更新全局
|
||||
if (app.globalData.userInfo) {
|
||||
app.globalData.userInfo.nickname = nickName
|
||||
app.globalData.userInfo.avatar = avatarUrl
|
||||
wx.setStorageSync('userInfo', app.globalData.userInfo)
|
||||
}
|
||||
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '头像更新成功', icon: 'success' })
|
||||
}
|
||||
|
||||
if (app.globalData.userInfo) {
|
||||
app.globalData.userInfo.avatar = avatarUrl
|
||||
wx.setStorageSync('userInfo', app.globalData.userInfo)
|
||||
}
|
||||
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '头像更新成功', icon: 'success' })
|
||||
} catch (e) {
|
||||
wx.hideLoading()
|
||||
console.error('[Settings] 获取头像失败:', e)
|
||||
wx.showToast({
|
||||
title: e.message || '获取头像失败',
|
||||
icon: 'none'
|
||||
console.error('[Settings] 更新头像失败:', e)
|
||||
wx.showToast({
|
||||
title: e.message || '上传失败,请重试',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
@@ -379,6 +369,66 @@ Page({
|
||||
this.setData({ showBindModal: false })
|
||||
},
|
||||
|
||||
// 打开切换账号弹窗(开发)
|
||||
openSwitchAccountModal() {
|
||||
this.setData({
|
||||
showSwitchAccountModal: true,
|
||||
switchAccountUserId: app.globalData.userInfo?.id || ''
|
||||
})
|
||||
},
|
||||
|
||||
// 关闭切换账号弹窗
|
||||
closeSwitchAccountModal() {
|
||||
if (this.data.switchAccountLoading) return
|
||||
this.setData({ showSwitchAccountModal: false, switchAccountUserId: '' })
|
||||
},
|
||||
|
||||
// 切换账号 userId 输入
|
||||
onSwitchAccountUserIdInput(e) {
|
||||
this.setData({ switchAccountUserId: e.detail.value.trim() })
|
||||
},
|
||||
|
||||
// 确认切换账号
|
||||
async confirmSwitchAccount() {
|
||||
const userId = this.data.switchAccountUserId.trim()
|
||||
if (!userId || this.data.switchAccountLoading) return
|
||||
this.setData({ switchAccountLoading: true })
|
||||
try {
|
||||
const res = await app.request('/api/miniprogram/dev/login-as', {
|
||||
method: 'POST',
|
||||
data: { userId }
|
||||
})
|
||||
if (res && res.success && res.data) {
|
||||
const { token, user } = res.data
|
||||
const openId = res.data.openId || ''
|
||||
wx.setStorageSync('token', token)
|
||||
wx.setStorageSync('userInfo', user)
|
||||
app.globalData.userInfo = user
|
||||
app.globalData.isLoggedIn = true
|
||||
app.globalData.purchasedSections = user.purchasedSections || []
|
||||
app.globalData.hasFullBook = user.hasFullBook || false
|
||||
app.globalData.isVip = user.isVip || false
|
||||
app.globalData.vipExpireDate = user.vipExpireDate || ''
|
||||
if (openId) {
|
||||
app.globalData.openId = openId
|
||||
wx.setStorageSync('openId', openId)
|
||||
}
|
||||
this.setData({
|
||||
showSwitchAccountModal: false,
|
||||
switchAccountUserId: '',
|
||||
switchAccountLoading: false
|
||||
})
|
||||
this.loadBindingInfo()
|
||||
wx.showToast({ title: '已切换为 ' + (user.nickname || userId), icon: 'success' })
|
||||
} else {
|
||||
throw new Error(res?.error || '切换失败')
|
||||
}
|
||||
} catch (e) {
|
||||
this.setData({ switchAccountLoading: false })
|
||||
wx.showToast({ title: e.message || '切换失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
// 清除缓存
|
||||
clearCache() {
|
||||
wx.showModal({
|
||||
|
||||
Reference in New Issue
Block a user