Files
kenyang d780f905bb feat(user-merge): 双用户体系行为合并 — 会员资料计入共拆分析 + 等级统一「非会员」标注
后端:
- /ai/collaboration-analysis 平台资料不足时自动合并拆书帮会员资料
  (tags/description/分舵/城市计入完善度,AI prompt 附会员身份)
  修复:杨珂鸣分析刘艳红误报「资料不足」,现 78 分推荐
- /chaishu/members/:uid 详情路由补 boundUserId/boundNickname/boundAvatar/boundPosition
- 等级措辞统一:非拆书家→非会员(AI prompt + 存量数据已修正)

前端:
- 新增 pages/chaishu-member-detail 会员名片页:未入驻→「邀请 TA 使用拆约」分享;
  已入驻→「邀请 TA 共拆」跳协作分析
- home onBuddyTap / chaishu-members onMemberTap:未绑定会员跳名片页(原误跳会员列表/toast)
- profile/activity-detail:非会员灰显「非会员」无徽章;edit-profile 选项更新
- app.js verifyUserExists 网络异常不再清登录态;clearLoginInfo 对齐 clearLoginState
- home/more-activities handleQuickJoin catch 补 silent 检查,修「报名误弹请登录」
2026-11-15 05:32:18 +08:00

154 lines
4.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// app.js - 拆约小程序入口
const { config } = require('./config');
App({
globalData: {
// API 基础地址(从 config.js 统一读取)
apiBaseUrl: config.apiBaseUrl,
// 用户信息
userInfo: null,
// token
token: null,
// 用户ID
userId: null,
// 是否为活动管理员(可创建/编辑/删除活动)
isAdmin: false,
},
onLaunch(options) {
// 小程序启动时执行
console.log('App launched', options);
// 检查版本更新
this.checkUpdate();
// 检查登录状态
this.checkLoginStatus();
// 验证当前用户是否在数据库中存在
this.verifyUserExists();
},
onShow(options) {
// 小程序显示时执行
console.log('App showed', options);
},
// 验证当前登录用户是否在数据库中存在,不存在则清除登录状态
async verifyUserExists() {
const token = wx.getStorageSync('token');
const userId = wx.getStorageSync('userId');
if (!token || !userId) return;
try {
const { config } = require('./config');
const res = await new Promise((resolve, reject) => {
wx.request({
url: `${config.apiBaseUrl}/user/profile`,
method: 'GET',
header: {
'Authorization': `Bearer ${token}`,
'x-user-id': userId,
},
timeout: 5000,
success: resolve,
fail: reject,
});
});
if (res.statusCode !== 200 || !res.data || !res.data.success) {
// 仅明确"用户不存在"(success:false)才清登录态;网络异常走 catch 保留
console.log('用户不存在于当前数据库,清除登录状态');
this.clearLoginInfo();
} else if (res.data.data) {
// 同步管理员身份(后台可随时调整用户角色,每次启动刷新)
const isAdmin = !!res.data.data.isAdmin;
if (this.globalData.isAdmin !== isAdmin) {
console.log('管理员状态已更新:', isAdmin);
}
this.globalData.isAdmin = isAdmin;
wx.setStorageSync('isAdmin', isAdmin);
}
} catch (err) {
// 网络超时/断网等异常不能等同于"用户不存在",误清会导致报名时误弹登录提示
console.log('验证用户存在性失败(网络异常,保留登录状态)', err);
}
},
onHide() {
// 小程序隐藏时执行
},
// 检查小程序版本更新
checkUpdate() {
if (!wx.getUpdateManager) return;
const updateManager = wx.getUpdateManager();
updateManager.onCheckForUpdate((res) => {
if (res.hasUpdate) console.log('检测到新版本');
});
updateManager.onUpdateReady(() => {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: (res) => {
if (res.confirm) updateManager.applyUpdate();
},
});
});
updateManager.onUpdateFailed(() => {
wx.showModal({
title: '更新提示',
content: '新版本下载失败,请删除当前小程序后重新搜索打开',
showCancel: false,
});
});
},
// 检查登录状态
checkLoginStatus() {
const token = wx.getStorageSync('token');
const userId = wx.getStorageSync('userId');
if (token && userId) {
this.globalData.token = token;
this.globalData.userId = userId;
}
this.globalData.isAdmin = wx.getStorageSync('isAdmin') || false;
},
// 设置用户信息
setUserInfo(userInfo) {
this.globalData.userInfo = userInfo;
if (userInfo && typeof userInfo.isAdmin !== 'undefined') {
this.globalData.isAdmin = !!userInfo.isAdmin;
wx.setStorageSync('isAdmin', !!userInfo.isAdmin);
}
},
// 设置 token
setToken(token) {
this.globalData.token = token;
wx.setStorageSync('token', token);
},
// 设置用户ID
setUserId(userId) {
this.globalData.userId = userId;
wx.setStorageSync('userId', userId);
},
// 清除登录信息(与 utils/auth.js clearLoginState 对齐:含 isLoggedIn,防止半清态)
clearLoginInfo() {
this.globalData.token = null;
this.globalData.userId = null;
this.globalData.userInfo = null;
this.globalData.isAdmin = false;
wx.removeStorageSync('token');
wx.removeStorageSync('userId');
wx.removeStorageSync('isLoggedIn');
wx.removeStorageSync('isAdmin');
wx.removeStorageSync('userInfo');
},
// 检查是否已登录
isLoggedIn() {
return !!this.globalData.token && !!this.globalData.userId;
},
});