| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- // 用户相关工具函数
- // 检查是否登录
- function isLogin() {
- const token = wx.getStorageSync('token');
- return !!token;
- }
- // 获取用户信息
- function getUserInfo() {
- return wx.getStorageSync('userInfo') || null;
- }
- // 保存用户信息
- function saveUserInfo(userInfo, token) {
- wx.setStorageSync('userInfo', userInfo);
- wx.setStorageSync('token', token);
- }
- // 清除用户信息
- function clearUserInfo() {
- const userInfo = getUserInfo();
- // 清除用户信息
- wx.removeStorageSync('userInfo');
- wx.removeStorageSync('token');
-
- // 清除该用户的聊天会话数据
- if (userInfo && userInfo.userId) {
- const chatSessionKey = `chat_sessionId_${userInfo.userId}`;
- wx.removeStorageSync(chatSessionKey);
- console.log('已清除用户聊天会话数据:', chatSessionKey);
- }
- }
- // 检查是否为管理员
- function isAdmin() {
- const userInfo = getUserInfo();
- return userInfo && userInfo.userRole === 1;
- }
- module.exports = {
- isLogin,
- getUserInfo,
- saveUserInfo,
- clearUserInfo,
- isAdmin
- };
|