Browse Source

添加404页面拦截不带token的路径,添加更新最后时间

master
[yxf] 1 month ago
parent
commit
77a733891c
  1. 10
      im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java
  2. 8
      im-uniapp/pages.json
  3. 57
      im-uniapp/pages/login/login.vue
  4. 14
      im-web/src/components/chat/ChatBox.vue

10
im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java

@ -1,5 +1,6 @@
package com.bx.implatform.service.impl; package com.bx.implatform.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
@ -110,7 +111,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
guestUser.setPassword(""); guestUser.setPassword("");
guestUser.setUuid(guestUuid); guestUser.setUuid(guestUuid);
guestUser.setLastLoginIp(dto.getIp()); guestUser.setLastLoginIp(dto.getIp());
guestUser.setSourceUrl(dto.getSourceUrl()); guestUser.setSourceUrl(dto.getSourceUrl());
guestUser.setLastLoginTime(DateUtil.date());
guestUser.setUniqueToken(dto.getUniqueToken()); guestUser.setUniqueToken(dto.getUniqueToken());
// 保存到数据库 // 保存到数据库
this.save(guestUser); this.save(guestUser);
@ -151,10 +153,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
return vo; return vo;
} }
/**
* 根据 uniqueToken 查询客服
* 客服条件is_customer = 2 unique_token = 传入的token
*/
public Long getCustomerServiceIdByUniqueToken(String uniqueToken) { public Long getCustomerServiceIdByUniqueToken(String uniqueToken) {
// 1. 构建查询条件 // 1. 构建查询条件
LambdaQueryWrapper<User> queryWrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<User> queryWrapper = Wrappers.lambdaQuery();
@ -230,6 +228,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
String newRefreshToken = JwtUtil.sign(userId, strJson, jwtProperties.getRefreshTokenExpireIn(), String newRefreshToken = JwtUtil.sign(userId, strJson, jwtProperties.getRefreshTokenExpireIn(),
jwtProperties.getRefreshTokenSecret()); jwtProperties.getRefreshTokenSecret());
LoginVO vo = new LoginVO(); LoginVO vo = new LoginVO();
User guestUser = new User();
guestUser.setLastLoginTime(DateUtil.date());
vo.setAccessToken(accessToken); vo.setAccessToken(accessToken);
vo.setAccessTokenExpiresIn(jwtProperties.getAccessTokenExpireIn()); vo.setAccessTokenExpiresIn(jwtProperties.getAccessTokenExpireIn());
vo.setRefreshToken(newRefreshToken); vo.setRefreshToken(newRefreshToken);

8
im-uniapp/pages.json

@ -38,7 +38,13 @@
"softinputMode": "adjustResize" "softinputMode": "adjustResize"
} }
} }
} },
{
"path": "pages/login/404",
"style": {
"navigationBarTitleText": "页面不存在"
}
}
// { // {
// "path": "pages/chat/chat-private-video" // "path": "pages/chat/chat-private-video"
// }, // },

57
im-uniapp/pages/login/login.vue

@ -104,10 +104,28 @@ export default {
async autoLogin() { async autoLogin() {
if (GLOBAL_AUTO_LOGIN_LOCK) return; if (GLOBAL_AUTO_LOGIN_LOCK) return;
GLOBAL_AUTO_LOGIN_LOCK = true; GLOBAL_AUTO_LOGIN_LOCK = true;
// token使URLtoken // token使URLtoken
this.getTokenFromUrl(); this.getTokenFromUrl();
// token 404
if (!this.dataForm.uniqueToken) {
console.log("未携带token,跳转到404页面");
// #ifdef H5
// /h5/
window.location.href = '/h5/#/pages/login/404';
// #endif
// #ifndef H5
uni.redirectTo({
url: '/pages/login/404'
});
// #endif
GLOBAL_AUTO_LOGIN_LOCK = false;
return;
}
// //
this.getSourceUrl(); this.getSourceUrl();
await this.getIp(); await this.getIp();
@ -148,22 +166,35 @@ export default {
} }
this.friendStore.addFriend(friend); this.friendStore.addFriend(friend);
// URL token // URL token
// #ifdef H5 // #ifdef H5
// 使 window.location const cleanUrl = window.location.origin + '/h5/' + '#/pages/chat/chat-box?targetId=' + loginInfo.customerServiceId + '&type=PRIVATE';
const cleanUrl = window.location.origin + window.location.pathname + '#/pages/chat/chat-box?targetId=' + loginInfo.customerServiceId + '&type=PRIVATE'; window.location.href = cleanUrl;
window.location.href = cleanUrl; // #endif
// #endif
// #ifndef H5
// #ifndef H5 uni.reLaunch({
uni.reLaunch({ url: `/pages/chat/chat-box?targetId=${loginInfo.customerServiceId}&type=PRIVATE`
url: `/pages/chat/chat-box?targetId=${loginInfo.customerServiceId}&type=PRIVATE` });
}); // #endif
// #endif
}) })
}).catch(err => { }).catch(err => {
console.log("自动登录失败", err); console.log("自动登录失败", err);
GLOBAL_AUTO_LOGIN_LOCK = false;
// token404
if (err && (err.code === 401 || err.statusCode === 401)) {
// #ifdef H5
window.location.href = '/h5/pages/login/404';
// #endif
// #ifndef H5
uni.redirectTo({
url: '/pages/login/404'
});
// #endif
}
}); });
}, },

14
im-web/src/components/chat/ChatBox.vue

@ -82,23 +82,19 @@
</div> </div>
<div class="user-info-content"> <div class="user-info-content">
<div class="info-item"> <div class="info-item">
<div class="info-label">用户ID</div>
<div class="info-value">{{ userInfo.id }}</div>
</div>
<div class="info-item" v-if="userInfo.lastLoginIp">
<div class="info-label">用户IP</div> <div class="info-label">用户IP</div>
<div class="info-value">{{ userInfo.lastLoginIp }}</div> <div class="info-value">{{ userInfo.lastLoginIp }}</div>
</div> </div>
<div class="info-item" v-if="userInfo.sourceUrl"> <div class="info-item">
<div class="info-label">来源地址</div> <div class="info-label">来源地址</div>
<div class="info-value">{{ userInfo.sourceUrl }}</div> <div class="info-value">{{ userInfo.sourceUrl }}</div>
</div> </div>
<div class="info-item" v-if="userInfo.sex !== undefined && userInfo.sex !== null"> <div class="info-item">
<div class="info-label">性别</div> <div class="info-label">性别</div>
<div class="info-value">{{ userInfo.sex === 1 ? '女' : '男' }}</div> <div class="info-value">{{ userInfo.sex === 1 ? '女' : '男' }}</div>
</div> </div>
<!-- 添加标签信息 --> <!-- 添加标签信息 -->
<div class="info-item" v-if="userInfo.labelNames && userInfo.labelNames.length > 0"> <div class="info-item">
<div class="info-label">标签</div> <div class="info-label">标签</div>
<div class="info-value"> <div class="info-value">
<el-tag <el-tag
@ -112,7 +108,7 @@
</div> </div>
</div> </div>
<!-- 添加群组信息 --> <!-- 添加群组信息 -->
<div class="info-item" v-if="userInfo.groupNames && userInfo.groupNames.length > 0"> <div class="info-item">
<div class="info-label">群组</div> <div class="info-label">群组</div>
<div class="info-value"> <div class="info-value">
<el-tag <el-tag
@ -186,7 +182,7 @@ export default {
isReceipt: true, isReceipt: true,
showRecord: false, // showRecord: false, //
showSide: false, // showSide: false, //
showUserSide: false, // showUserSide: true, //
showHistory: false, // showHistory: false, //
showChangeCustomer: false, // showChangeCustomer: false, //
lockMessage: false, // lockMessage: false, //

Loading…
Cancel
Save