|
|
@@ -28,7 +28,8 @@ Page({
|
|
|
mobile: '', //手机号
|
|
|
verilyCode: '', //验证码
|
|
|
s: 0, //获取验证码倒计时 秒/s
|
|
|
- countDown: false
|
|
|
+ countDown: false,
|
|
|
+ avatarKey: Date.now() // 用于强制刷新头像显示
|
|
|
},
|
|
|
onLoad: async function (options) {
|
|
|
let Company = new Parse.Query('Company')
|
|
|
@@ -95,23 +96,42 @@ Page({
|
|
|
},
|
|
|
/* 判断是否绑定手机号 */
|
|
|
async getUserProfile() {
|
|
|
- if (!Parse.User.current()?.id) {
|
|
|
- await getApp().checkAuth(true)
|
|
|
+ // 检查用户是否已登录
|
|
|
+ let currentUser = Parse.User.current();
|
|
|
+
|
|
|
+ if (!currentUser?.id) {
|
|
|
+ console.log('⚠️ 用户未登录,需要先登录');
|
|
|
+ // 不要在这里调用 checkAuth(true),因为它会触发微信官方的强制授权弹窗
|
|
|
+ // 应该在外层(index.js)处理登录逻辑
|
|
|
+ return false;
|
|
|
}
|
|
|
- let currentUser = Parse.User.current()
|
|
|
+
|
|
|
/* 如果手机号存在,已注册过判断是否上传过头像昵称信息 */
|
|
|
if (currentUser?.get('mobile')) {
|
|
|
wx.setStorageSync("userLogin", currentUser.id);
|
|
|
- if (currentUser.get('nickname') == '微信用户' || currentUser.get('nickname') == '' || !currentUser.get('nickname')) {
|
|
|
+
|
|
|
+ // 检查是否需要完善信息(可选)
|
|
|
+ // 如果用户没有昵称或昵称是默认的,提示完善信息
|
|
|
+ const needProfile = !currentUser.get('nickname') ||
|
|
|
+ currentUser.get('nickname') === '微信用户' ||
|
|
|
+ currentUser.get('nickname') === '';
|
|
|
+
|
|
|
+ if (needProfile) {
|
|
|
+ // 显示自定义的完善信息弹窗(允许跳过)
|
|
|
+ console.log('ℹ️ 显示自定义头像昵称弹窗');
|
|
|
this.setData({
|
|
|
wxModel: true
|
|
|
- })
|
|
|
- return
|
|
|
+ });
|
|
|
+ return false;
|
|
|
}
|
|
|
- this.backLoad()
|
|
|
- return
|
|
|
+
|
|
|
+ // 用户信息完整,返回上一页
|
|
|
+ this.backLoad();
|
|
|
+ return false;
|
|
|
}
|
|
|
- return true
|
|
|
+
|
|
|
+ // 用户已登录但没有手机号,允许继续
|
|
|
+ return true;
|
|
|
},
|
|
|
/* 短信验证码登录弹窗 */
|
|
|
async showDialogBtn() {
|
|
|
@@ -164,20 +184,43 @@ Page({
|
|
|
this.backLoad()
|
|
|
return
|
|
|
})
|
|
|
- .catch(err => {
|
|
|
- console.log('登录失败:', err);
|
|
|
- wx.setStorageSync("sessionToken", null);
|
|
|
+ .catch(async err => {
|
|
|
+ console.log('❌ Parse.User.become 失败:', err);
|
|
|
+
|
|
|
+ // 不要直接退出,而是尝试重新登录
|
|
|
wx.showModal({
|
|
|
title: '提示',
|
|
|
- content: '登录信息过期,请退出重新进入小程序',
|
|
|
- showCancel: false,
|
|
|
+ content: '登录状态异常,是否重新登录?',
|
|
|
+ showCancel: true,
|
|
|
cancelText: '取消',
|
|
|
- cancelColor: '#000000',
|
|
|
- confirmText: '确定',
|
|
|
- confirmColor: '#3CC51F',
|
|
|
- success: (result) => {
|
|
|
+ confirmText: '重新登录',
|
|
|
+ success: async (result) => {
|
|
|
if (result.confirm) {
|
|
|
- wx.exitMiniProgram()
|
|
|
+ // 清除登录状态
|
|
|
+ wx.removeStorageSync("sessionToken");
|
|
|
+ wx.removeStorageSync("userLogin");
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 尝试重新登录
|
|
|
+ await Parse.User.logOut();
|
|
|
+ await getApp().checkAuth(true);
|
|
|
+
|
|
|
+ // 重新获取用户信息
|
|
|
+ const currentUser = Parse.User.current();
|
|
|
+ if (currentUser && currentUser.get('mobile')) {
|
|
|
+ wx.setStorageSync("userLogin", currentUser.id);
|
|
|
+ this.backLoad();
|
|
|
+ }
|
|
|
+ } catch (reloginErr) {
|
|
|
+ console.error('❌ 重新登录失败:', reloginErr);
|
|
|
+ wx.showToast({
|
|
|
+ title: '登录失败,请稍后重试',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 用户取消,返回上一页
|
|
|
+ wx.navigateBack();
|
|
|
}
|
|
|
},
|
|
|
});
|
|
|
@@ -386,15 +429,113 @@ Page({
|
|
|
})
|
|
|
},
|
|
|
backLoad() {
|
|
|
+ console.log('===========================================');
|
|
|
+ console.log('======= backLoad 方法调用 =======');
|
|
|
+
|
|
|
let pages = getCurrentPages();
|
|
|
+ console.log('当前页面栈层数:', pages.length);
|
|
|
+ console.log('当前页面路由:', pages[pages.length - 1]?.route);
|
|
|
+
|
|
|
+ // 如果页面栈只有1层或没有上一页,直接跳转到首页
|
|
|
+ if (pages.length <= 1) {
|
|
|
+ console.log('⚠️ 没有上一个页面,直接跳转到首页');
|
|
|
+ this.goToHome();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 有上一个页面
|
|
|
let beforePage = pages[pages.length - 2];
|
|
|
- let options = {
|
|
|
- isInit: true
|
|
|
+ console.log('上一个页面路由:', beforePage.route);
|
|
|
+
|
|
|
+ // 尝试调用上一个页面的 onLoad 方法(如果存在)
|
|
|
+ if (beforePage && typeof beforePage.onLoad === 'function') {
|
|
|
+ try {
|
|
|
+ let options = beforePage.options || { isInit: true };
|
|
|
+ beforePage.onLoad(options);
|
|
|
+ console.log('✅ 已调用上一个页面的 onLoad');
|
|
|
+ } catch (err) {
|
|
|
+ console.warn('⚠️ 调用上一个页面 onLoad 失败:', err);
|
|
|
+ }
|
|
|
}
|
|
|
- beforePage?.onLoad(options)
|
|
|
+
|
|
|
+ // 返回上一页
|
|
|
+ console.log('🔙 执行 navigateBack...');
|
|
|
wx.navigateBack({
|
|
|
delta: 1,
|
|
|
- })
|
|
|
+ success: () => {
|
|
|
+ console.log('✅ navigateBack 成功');
|
|
|
+ console.log('===========================================');
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('❌ navigateBack 失败:', err);
|
|
|
+ console.log('⚠️ 尝试使用 reLaunch 跳转到首页');
|
|
|
+ this.goToHome();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 跳转到首页
|
|
|
+ goToHome() {
|
|
|
+ console.log('===========================================');
|
|
|
+ console.log('======= goToHome 方法调用 =======');
|
|
|
+
|
|
|
+ const app = getApp();
|
|
|
+ console.log('globalData.rootPage:', app.globalData.rootPage);
|
|
|
+ console.log('globalData.defaultTabBar:', app.globalData.defaultTabBar);
|
|
|
+
|
|
|
+ // 尝试多个可能的首页路径
|
|
|
+ let rootPage = app.globalData.rootPage
|
|
|
+ || app.globalData.defaultTabBar?.list?.[0]?.pagePath
|
|
|
+ || '/pages/index/index'
|
|
|
+ || '/index/index';
|
|
|
+
|
|
|
+ // 确保路径以 / 开头
|
|
|
+ if (!rootPage.startsWith('/')) {
|
|
|
+ rootPage = '/' + rootPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('准备跳转到:', rootPage);
|
|
|
+
|
|
|
+ wx.reLaunch({
|
|
|
+ url: rootPage,
|
|
|
+ success: () => {
|
|
|
+ console.log('✅ reLaunch 成功');
|
|
|
+ console.log('===========================================');
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('❌ reLaunch 失败:', err);
|
|
|
+ console.log('⚠️ 尝试使用 switchTab');
|
|
|
+
|
|
|
+ // 如果是 tabBar 页面,尝试使用 switchTab
|
|
|
+ wx.switchTab({
|
|
|
+ url: rootPage,
|
|
|
+ success: () => {
|
|
|
+ console.log('✅ switchTab 成功');
|
|
|
+ console.log('===========================================');
|
|
|
+ },
|
|
|
+ fail: (err2) => {
|
|
|
+ console.error('❌ switchTab 也失败:', err2);
|
|
|
+ console.log('⚠️ 最后尝试:直接 navigateBack');
|
|
|
+
|
|
|
+ // 最后的兜底:直接返回
|
|
|
+ wx.navigateBack({
|
|
|
+ delta: 1,
|
|
|
+ fail: (err3) => {
|
|
|
+ console.error('❌ 所有跳转方式都失败了:', err3);
|
|
|
+ console.log('===========================================');
|
|
|
+
|
|
|
+ // 显示错误提示
|
|
|
+ wx.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '页面跳转失败,请手动返回',
|
|
|
+ showCancel: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
goBack: function () {
|
|
|
wx.navigateBack({
|
|
|
@@ -404,53 +545,203 @@ Page({
|
|
|
|
|
|
//手动获取微信头像
|
|
|
onChooseAvatar(e) {
|
|
|
- console.log(e);
|
|
|
- let {
|
|
|
- avatarUrl
|
|
|
- } = e.detail
|
|
|
- console.log(avatarUrl);
|
|
|
- this.setData({
|
|
|
- avatarUrl
|
|
|
- })
|
|
|
+ console.log('=== onChooseAvatar 触发 ===');
|
|
|
+ console.log('事件对象:', e);
|
|
|
+
|
|
|
+ const { avatarUrl } = e.detail;
|
|
|
+ console.log('获取到的头像URL:', avatarUrl);
|
|
|
+ console.log('头像URL类型:', typeof avatarUrl);
|
|
|
+ console.log('头像URL长度:', avatarUrl ? avatarUrl.length : 0);
|
|
|
+
|
|
|
+ if (avatarUrl) {
|
|
|
+ // 微信头像URL可能是临时路径,需要先下载
|
|
|
+ // 临时路径格式:http://tmp/xxx.jpg
|
|
|
+ // 相机拍照路径格式:wxfile://tmp_xxx.jpg
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ avatarUrl: avatarUrl,
|
|
|
+ avatarKey: Date.now() // 更新key强制刷新
|
|
|
+ }, () => {
|
|
|
+ console.log('✅ 头像URL已更新到data:', this.data.avatarUrl);
|
|
|
+ console.log('✅ avatarKey已更新:', this.data.avatarKey);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ console.error('❌ 未获取到头像URL');
|
|
|
+ wx.showToast({
|
|
|
+ title: '获取头像失败,请重试',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
//获取昵称
|
|
|
onChangeName(e) {
|
|
|
- console.log('1111');
|
|
|
- console.log(e);
|
|
|
+ console.log('=== 昵称输入事件 ===');
|
|
|
+ console.log('事件对象:', e);
|
|
|
+
|
|
|
+ // 注意:type="nickname" 的 input 会在用户输入时自动更新 model:value
|
|
|
+ // 这里只是记录日志,实际的值更新由 model:value 自动处理
|
|
|
+ if (e.detail && e.detail.value !== undefined) {
|
|
|
+ console.log('昵称值:', e.detail.value);
|
|
|
+ }
|
|
|
},
|
|
|
//确定头像昵称
|
|
|
async onComplete() {
|
|
|
+ console.log('=== onComplete 方法被调用 ===');
|
|
|
+
|
|
|
let {
|
|
|
nickname,
|
|
|
avatarUrl
|
|
|
} = this.data
|
|
|
- // console.log(nickname, avatarUrl);
|
|
|
- if (!nickname || !avatarUrl) {
|
|
|
+
|
|
|
+ console.log('昵称:', nickname);
|
|
|
+ console.log('头像URL:', avatarUrl);
|
|
|
+
|
|
|
+ let user = Parse.User.current();
|
|
|
+
|
|
|
+ if (!user) {
|
|
|
+ console.error('❌ 用户未登录,无法保存信息');
|
|
|
wx.showToast({
|
|
|
- title: '请填写完整信息',
|
|
|
- icon: 'none',
|
|
|
- image: '',
|
|
|
- duration: 1500,
|
|
|
- mask: false,
|
|
|
+ title: '用户未登录',
|
|
|
+ icon: 'none'
|
|
|
});
|
|
|
- return
|
|
|
+ return;
|
|
|
}
|
|
|
- //关键注释: https://up-z2.qiniup.com 合法域名必须配置
|
|
|
+
|
|
|
+ console.log('当前用户ID:', user.id);
|
|
|
+
|
|
|
+ // 显示加载提示
|
|
|
+ wx.showLoading({
|
|
|
+ title: '保存中...',
|
|
|
+ mask: true
|
|
|
+ });
|
|
|
+
|
|
|
try {
|
|
|
- let avatar = await this.updataAvatar(avatarUrl)
|
|
|
- let user = Parse.User.current()
|
|
|
- user.set("avatar", avatar)
|
|
|
- user.set("nickname", nickname)
|
|
|
- user.save().then(res => {
|
|
|
- this.onClose()
|
|
|
- this.backLoad()
|
|
|
- })
|
|
|
+ // 如果用户填写了信息,则更新
|
|
|
+ if (nickname || avatarUrl) {
|
|
|
+ console.log('ℹ️ 用户填写了信息,开始更新');
|
|
|
+
|
|
|
+ // 如果有头像,上传头像
|
|
|
+ if (avatarUrl) {
|
|
|
+ console.log('📤 开始上传头像...');
|
|
|
+ let avatar = await this.updataAvatar(avatarUrl);
|
|
|
+ if (avatar) {
|
|
|
+ user.set("avatar", avatar);
|
|
|
+ console.log('✅ 头像上传成功:', avatar);
|
|
|
+ } else {
|
|
|
+ console.warn('⚠️ 头像上传失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果有昵称,更新昵称
|
|
|
+ if (nickname) {
|
|
|
+ user.set("nickname", nickname);
|
|
|
+ console.log('✅ 昵称已设置:', nickname);
|
|
|
+ }
|
|
|
+
|
|
|
+ await user.save();
|
|
|
+ console.log('✅ 用户信息保存成功');
|
|
|
+ } else {
|
|
|
+ // 用户没有填写任何信息,使用默认值
|
|
|
+ console.log('ℹ️ 用户跳过头像昵称设置,使用默认值');
|
|
|
+
|
|
|
+ // 如果用户没有昵称,设置默认昵称
|
|
|
+ if (!user.get('nickname') || user.get('nickname') === '微信用户') {
|
|
|
+ const defaultNickname = '用户' + user.id.substring(0, 6);
|
|
|
+ user.set('nickname', defaultNickname);
|
|
|
+ await user.save();
|
|
|
+ console.log('✅ 已设置默认昵称:', defaultNickname);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ wx.hideLoading();
|
|
|
+
|
|
|
+ // 关闭弹窗
|
|
|
+ this.onClose();
|
|
|
+
|
|
|
+ // 延迟一下再跳转,确保弹窗关闭动画完成
|
|
|
+ setTimeout(() => {
|
|
|
+ console.log('🚀 准备跳转...');
|
|
|
+ this.backLoad();
|
|
|
+ }, 300);
|
|
|
+
|
|
|
+ } catch (err) {
|
|
|
+ wx.hideLoading();
|
|
|
+ console.error('❌ 保存用户信息失败:', err);
|
|
|
+
|
|
|
+ wx.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '保存失败,是否继续?',
|
|
|
+ showCancel: true,
|
|
|
+ cancelText: '重试',
|
|
|
+ confirmText: '继续',
|
|
|
+ success: (result) => {
|
|
|
+ if (result.confirm) {
|
|
|
+ // 用户选择继续,直接跳转
|
|
|
+ this.onClose();
|
|
|
+ setTimeout(() => {
|
|
|
+ this.backLoad();
|
|
|
+ }, 300);
|
|
|
+ }
|
|
|
+ // 用户选择重试,留在当前页面
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ //跳过头像昵称设置
|
|
|
+ async onSkip() {
|
|
|
+ console.log('=== onSkip 方法被调用 ===');
|
|
|
+
|
|
|
+ let user = Parse.User.current();
|
|
|
+
|
|
|
+ if (!user) {
|
|
|
+ console.error('❌ 用户未登录');
|
|
|
+ wx.showToast({
|
|
|
+ title: '用户未登录',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('当前用户ID:', user.id);
|
|
|
+
|
|
|
+ wx.showLoading({
|
|
|
+ title: '处理中...',
|
|
|
+ mask: true
|
|
|
+ });
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 设置默认昵称(如果没有)
|
|
|
+ if (!user.get('nickname') || user.get('nickname') === '微信用户') {
|
|
|
+ const defaultNickname = '用户' + user.id.substring(0, 6);
|
|
|
+ user.set('nickname', defaultNickname);
|
|
|
+ await user.save();
|
|
|
+ console.log('✅ 已设置默认昵称:', defaultNickname);
|
|
|
+ } else {
|
|
|
+ console.log('ℹ️ 用户已有昵称:', user.get('nickname'));
|
|
|
+ }
|
|
|
+
|
|
|
+ wx.hideLoading();
|
|
|
+
|
|
|
+ // 关闭弹窗
|
|
|
+ this.onClose();
|
|
|
+
|
|
|
+ // 延迟一下再跳转
|
|
|
+ setTimeout(() => {
|
|
|
+ console.log('🚀 准备跳转...');
|
|
|
+ this.backLoad();
|
|
|
+ }, 300);
|
|
|
+
|
|
|
} catch (err) {
|
|
|
- console.warn('https://up-z2.qiniup.com 合法域名必须配置');
|
|
|
- console.log(err);
|
|
|
- this.onClose()
|
|
|
- this.backLoad()
|
|
|
+ wx.hideLoading();
|
|
|
+ console.error('❌ 设置默认昵称失败:', err);
|
|
|
+
|
|
|
+ // 即使失败也允许继续
|
|
|
+ this.onClose();
|
|
|
+ setTimeout(() => {
|
|
|
+ this.backLoad();
|
|
|
+ }, 300);
|
|
|
}
|
|
|
},
|
|
|
//关闭头像昵称填写弹窗
|