优化数据库初始化,新增用户收货地址表以支持多地址管理;更新章节页面和我的页面,整合底部导航组件,提升用户体验;调整小程序设置页面,增加收货地址管理功能,优化样式与布局。
This commit is contained in:
@@ -15,7 +15,7 @@ Page({
|
||||
phoneNumber: '',
|
||||
wechatId: '',
|
||||
alipayAccount: '',
|
||||
address: '',
|
||||
addressSummary: '管理收货地址',
|
||||
|
||||
// 自动提现(默认开启)
|
||||
autoWithdrawEnabled: true,
|
||||
@@ -47,7 +47,6 @@ Page({
|
||||
const phoneNumber = wx.getStorageSync('user_phone') || userInfo.phone || ''
|
||||
const wechatId = wx.getStorageSync('user_wechat') || userInfo.wechat || ''
|
||||
const alipayAccount = wx.getStorageSync('user_alipay') || userInfo.alipay || ''
|
||||
const address = wx.getStorageSync('user_address') || userInfo.address || ''
|
||||
// 默认开启自动提现
|
||||
const autoWithdrawEnabled = wx.getStorageSync('auto_withdraw_enabled') !== false
|
||||
|
||||
@@ -57,73 +56,37 @@ Page({
|
||||
phoneNumber,
|
||||
wechatId,
|
||||
alipayAccount,
|
||||
address,
|
||||
autoWithdrawEnabled
|
||||
})
|
||||
this.loadAddressSummary()
|
||||
}
|
||||
},
|
||||
|
||||
// 一键获取收货地址
|
||||
getAddress() {
|
||||
wx.chooseAddress({
|
||||
success: (res) => {
|
||||
console.log('[Settings] 获取地址成功:', res)
|
||||
const fullAddress = `${res.provinceName || ''}${res.cityName || ''}${res.countyName || ''}${res.detailInfo || ''}`
|
||||
|
||||
if (fullAddress.trim()) {
|
||||
wx.setStorageSync('user_address', fullAddress)
|
||||
this.setData({ address: fullAddress })
|
||||
|
||||
// 更新用户信息
|
||||
if (app.globalData.userInfo) {
|
||||
app.globalData.userInfo.address = fullAddress
|
||||
wx.setStorageSync('userInfo', app.globalData.userInfo)
|
||||
}
|
||||
|
||||
// 同步到服务器
|
||||
this.syncAddressToServer(fullAddress)
|
||||
|
||||
wx.showToast({ title: '地址已获取', icon: 'success' })
|
||||
}
|
||||
},
|
||||
fail: (e) => {
|
||||
console.log('[Settings] 获取地址失败:', e)
|
||||
if (e.errMsg?.includes('cancel')) {
|
||||
// 用户取消,不提示
|
||||
return
|
||||
}
|
||||
if (e.errMsg?.includes('auth deny') || e.errMsg?.includes('authorize')) {
|
||||
wx.showModal({
|
||||
title: '需要授权',
|
||||
content: '请在设置中允许获取收货地址',
|
||||
confirmText: '去设置',
|
||||
success: (res) => {
|
||||
if (res.confirm) wx.openSetting()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
wx.showToast({ title: '获取失败,请重试', icon: 'none' })
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 同步地址到服务器
|
||||
async syncAddressToServer(address) {
|
||||
// 加载地址摘要(共 N 个地址)
|
||||
async loadAddressSummary() {
|
||||
try {
|
||||
const userId = app.globalData.userInfo?.id
|
||||
if (!userId) return
|
||||
|
||||
await app.request('/api/user/update', {
|
||||
method: 'POST',
|
||||
data: { userId, address }
|
||||
})
|
||||
console.log('[Settings] 地址已同步到服务器')
|
||||
const res = await app.request('/api/user/addresses', { data: { userId } })
|
||||
if (res.success && res.list && res.list.length > 0) {
|
||||
this.setData({ addressSummary: `共${res.list.length}个收货地址` })
|
||||
} else {
|
||||
this.setData({ addressSummary: '管理收货地址' })
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('[Settings] 同步地址失败:', e)
|
||||
this.setData({ addressSummary: '管理收货地址' })
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// 跳转收货地址列表(增删改查),未登录时提示先登录
|
||||
goToAddressList() {
|
||||
if (!app.globalData.isLoggedIn || !app.globalData.userInfo) {
|
||||
wx.showToast({ title: '请先登录', icon: 'none' })
|
||||
return
|
||||
}
|
||||
wx.navigateTo({ url: '/pages/address-list/address-list' })
|
||||
},
|
||||
|
||||
// 切换自动提现
|
||||
async toggleAutoWithdraw(e) {
|
||||
const enabled = e.detail.value
|
||||
|
||||
Reference in New Issue
Block a user