Browse Source

修复登录错误:添加app.js文件并增强全局数据访问健壮性

pull/1/head
徐飞洋 3 months ago
parent
commit
f346150e2c
  1. 24
      app.js
  2. 24
      server-example/server-mysql.js
  3. 4
      utils/api.js

24
app.js

@ -0,0 +1,24 @@
// app.js
App({
globalData: {
userInfo: null,
currentTab: 'index'
},
// 更新当前选中的tab
updateCurrentTab(tabName) {
this.globalData.currentTab = tabName;
},
onLaunch() {
console.log('App launched');
},
onShow() {
console.log('App shown');
},
onHide() {
console.log('App hidden');
}
});

24
server-example/server-mysql.js

@ -8096,32 +8096,14 @@ app.post('/api/chat/add', async (req, res) => {
'INSERT INTO chat_list (user_phone, manager_phone) VALUES (?, ?)', 'INSERT INTO chat_list (user_phone, manager_phone) VALUES (?, ?)',
{ replacements: [user_phone, manager_phone] } { replacements: [user_phone, manager_phone] }
); );
res.status(200).json({
// 2. 业务员手机号 -> 用户手机号 success: true,
await sequelize.query( await sequelize.query(
'INSERT INTO chat_list (user_phone, manager_phone) VALUES (?, ?)', 'INSERT INTO chat_list (user_phone, manager_phone) VALUES (?, ?)',
{ replacements: [manager_phone, user_phone] } { replacements: [manager_phone, user_phone] }
); );
console.log('✅ 成功插入两条聊天记录');
res.status(200).json({
success: true,
code: 200,
message: '聊天记录添加成功',
data: {
user_phone,
manager_phone
}
}); });
} catch (error) { console.log('✅ 成功插入两条聊天记录');
console.error('添加聊天记录失败:', error);
res.status(500).json({
success: false,
code: 500,
message: '添加聊天记录失败: ' + error.message
});
}
}); });
// 新增:获取业务员信息接口 - 根据手机号查询 // 新增:获取业务员信息接口 - 根据手机号查询

4
utils/api.js

@ -2942,7 +2942,9 @@ module.exports = {
// 更新全局数据 // 更新全局数据
const app = getApp(); const app = getApp();
app.globalData.userType = newType; if (app && app.globalData) {
app.globalData.userType = newType;
}
// 同时更新本地的userType存储 // 同时更新本地的userType存储
wx.setStorageSync('userType', newType); wx.setStorageSync('userType', newType);

Loading…
Cancel
Save