Files
soul/miniprogram/pages/settings/settings.js
卡若 b60edb3d47 feat: 完整重构小程序匹配功能 + 修复UI对齐 + 文章数据API
主要更新:
1. 按H5网页端完全重构匹配功能(match页面)
   - 4种匹配类型: 创业合伙/资源对接/导师顾问/团队招募
   - 资源对接等类型弹出手机号/微信号输入框
   - 去掉重新匹配按钮,改为返回按钮

2. 修复所有卡片对齐和宽度问题
   - 目录页附录卡片居中
   - 首页阅读进度卡片满宽度
   - 我的页面菜单卡片对齐
   - 推广中心分享卡片统一宽度

3. 修复目录页图标和文字对齐
   - section-icon固定40rpx宽高
   - section-title与图标垂直居中

4. 更新真实完整文章标题(62篇)
   - 从book目录读取真实markdown文件名
   - 替换之前的简化标题

5. 新增文章数据API
   - /api/db/chapters - 获取完整书籍结构
   - 支持按ID获取单篇文章内容
2026-01-21 15:49:12 +08:00

193 lines
4.6 KiB
JavaScript

/**
* Soul创业实验 - 设置页
* 账号绑定功能
*/
const app = getApp()
Page({
data: {
statusBarHeight: 44,
isLoggedIn: false,
userInfo: null,
version: '1.0.0',
// 绑定信息
phoneNumber: '',
wechatId: '',
alipayAccount: '',
// 绑定弹窗
showBindModal: false,
bindType: '', // phone | wechat | alipay
bindValue: ''
},
onLoad() {
this.setData({
statusBarHeight: app.globalData.statusBarHeight,
isLoggedIn: app.globalData.isLoggedIn,
userInfo: app.globalData.userInfo
})
this.loadBindingInfo()
},
onShow() {
this.loadBindingInfo()
},
// 加载绑定信息
loadBindingInfo() {
const { userInfo, isLoggedIn } = app.globalData
if (isLoggedIn && userInfo) {
// 从本地存储或用户信息中获取绑定数据
const phoneNumber = wx.getStorageSync('user_phone') || userInfo.phone || ''
const wechatId = wx.getStorageSync('user_wechat') || userInfo.wechat || ''
const alipayAccount = wx.getStorageSync('user_alipay') || userInfo.alipay || ''
this.setData({
isLoggedIn: true,
userInfo,
phoneNumber,
wechatId,
alipayAccount
})
}
},
// 绑定手机号
bindPhone() {
this.setData({
showBindModal: true,
bindType: 'phone',
bindValue: ''
})
},
// 绑定微信号
bindWechat() {
this.setData({
showBindModal: true,
bindType: 'wechat',
bindValue: ''
})
},
// 绑定支付宝
bindAlipay() {
this.setData({
showBindModal: true,
bindType: 'alipay',
bindValue: ''
})
},
// 输入绑定值
onBindInput(e) {
let value = e.detail.value
if (this.data.bindType === 'phone') {
value = value.replace(/\D/g, '').slice(0, 11)
}
this.setData({ bindValue: value })
},
// 确认绑定
confirmBind() {
const { bindType, bindValue } = this.data
if (!bindValue) {
wx.showToast({ title: '请输入内容', icon: 'none' })
return
}
// 验证
if (bindType === 'phone' && !/^1[3-9]\d{9}$/.test(bindValue)) {
wx.showToast({ title: '请输入正确的手机号', icon: 'none' })
return
}
if (bindType === 'wechat' && bindValue.length < 6) {
wx.showToast({ title: '微信号至少6位', icon: 'none' })
return
}
if (bindType === 'alipay' && !bindValue.includes('@') && !/^1[3-9]\d{9}$/.test(bindValue)) {
wx.showToast({ title: '请输入正确的支付宝账号', icon: 'none' })
return
}
// 保存绑定信息
if (bindType === 'phone') {
wx.setStorageSync('user_phone', bindValue)
this.setData({ phoneNumber: bindValue })
} else if (bindType === 'wechat') {
wx.setStorageSync('user_wechat', bindValue)
this.setData({ wechatId: bindValue })
} else if (bindType === 'alipay') {
wx.setStorageSync('user_alipay', bindValue)
this.setData({ alipayAccount: bindValue })
}
this.setData({ showBindModal: false })
wx.showToast({ title: '绑定成功', icon: 'success' })
},
// 关闭绑定弹窗
closeBindModal() {
this.setData({ showBindModal: false })
},
// 清除缓存
clearCache() {
wx.showModal({
title: '清除缓存',
content: '确定要清除本地缓存吗?',
success: (res) => {
if (res.confirm) {
// 保留登录信息,只清除其他缓存
const token = wx.getStorageSync('token')
const userInfo = wx.getStorageSync('userInfo')
wx.clearStorageSync()
if (token) wx.setStorageSync('token', token)
if (userInfo) wx.setStorageSync('userInfo', userInfo)
wx.showToast({ title: '缓存已清除', icon: 'success' })
}
}
})
},
// 退出登录
handleLogout() {
wx.showModal({
title: '退出登录',
content: '确定要退出登录吗?',
success: (res) => {
if (res.confirm) {
app.logout()
this.setData({
isLoggedIn: false,
userInfo: null,
phoneNumber: '',
wechatId: '',
alipayAccount: ''
})
wx.showToast({ title: '已退出登录', icon: 'success' })
setTimeout(() => wx.navigateBack(), 1500)
}
}
})
},
// 联系客服
contactService() {
wx.setClipboardData({
data: '28533368',
success: () => wx.showToast({ title: '客服微信已复制', icon: 'success' })
})
},
// 阻止冒泡
stopPropagation() {},
goBack() { wx.navigateBack() }
})