fix(buyer): 未登录联系客服时提示登录

- 将登录提示由 Message 改为 Modal
- 新增 promptLogin 方法处理登录跳转
- IMService 增加 accessToken 校验,未登录时提示登录
- 改进用户信息获取的错误处理
- 重构 IM 链接 URL 拼接,提升可读性
This commit is contained in:
田香琪
2026-07-22 18:08:42 +08:00
parent 4bcaf14bad
commit c0ca9672a1
19 changed files with 343 additions and 263 deletions

View File

@@ -3,7 +3,7 @@
</template>
<script>
import { Message } from "@/utils/message";
import { Modal } from "@/utils/message";
import { getIMDetail } from "@/api/common";
import Storage from "@/plugins/storage";
import { getMemberMsg } from "@/api/login";
@@ -15,28 +15,52 @@ export default {
};
},
methods: {
promptLogin() {
Modal.confirm({
title: "温馨提示",
content: "请登录后执行此操作",
okText: "立即登录",
cancelText: "取消",
onOk: () => {
this.$router.push({
path: "/login",
query: {
rePath: this.$route.path,
query: JSON.stringify(this.$route.query || {}),
},
});
},
});
},
// 跳转im客服
async IMService(id, goodsId, skuId) {
if (!Storage.getItem("accessToken")) {
this.promptLogin();
return;
}
// 获取访问Token
let accessToken = Storage.getItem("accessToken");
await this.getIMDetailMethods();
const userInfo = await getMemberMsg();
if (userInfo.success) {
//携带商品Id,在IM可以发送商品信息
if(goodsId && skuId){
window.open(
this.IMLink + "?token=" + accessToken + "&id=" + (id || this.storeMsg.storeId) + "&goodsId=" + goodsId + "&skuId=" + skuId
);
}else{
window.open(
this.IMLink + "?token=" + accessToken + "&id=" + (id || this.storeMsg.storeId)
);
try {
await this.getIMDetailMethods();
const userInfo = await getMemberMsg();
if (!userInfo.success) {
this.promptLogin();
return;
}
} else {
Message.error("请登录后再联系客服");
return;
const accessToken = Storage.getItem("accessToken");
const storeId = id || this.storeMsg?.storeId;
const baseUrl = `${this.IMLink}?token=${accessToken}&id=${storeId}`;
if (goodsId && skuId) {
window.open(`${baseUrl}&goodsId=${goodsId}&skuId=${skuId}`);
} else {
window.open(baseUrl);
}
} catch {
// token 过期等场景由 request 拦截器处理;未登录时避免未捕获异常
if (!Storage.getItem("accessToken")) {
this.promptLogin();
}
}
},
// 获取im信息

View File

@@ -284,7 +284,7 @@ export default {
// 跳转店铺首页
goShopPage(id) {
let routeUrl = this.$router.resolve({
path: "/Merchant",
path: "/merchant",
query: { id },
});
window.open(routeUrl.href, "_blank");

View File

@@ -177,7 +177,7 @@ export default {
let url
if (this.params.type === 'STORE') {
url = this.$router.resolve({
path: '/Merchant',
path: '/merchant',
query: { 'id': storeId }
})
} else {

View File

@@ -198,7 +198,7 @@ export default {
// 跳转店铺首页
shopPage(id) {
let routeUrl = this.$router.resolve({
path: '/Merchant',
path: '/merchant',
query: {id: id}
});
window.open(routeUrl.href, '_blank');

View File

@@ -265,7 +265,7 @@ export default {
// 跳转店铺首页
shopPage (id) {
let routeUrl = this.$router.resolve({
path: '/Merchant',
path: '/merchant',
query: { id: id }
});
window.open(routeUrl.href, '_blank');

View File

@@ -424,7 +424,7 @@ export default {
// 跳转店铺首页
shopPage(id) {
let routeUrl = this.$router.resolve({
path: "/Merchant",
path: "/merchant",
query: { id: id },
});
window.open(routeUrl.href, "_blank");

View File

@@ -71,7 +71,7 @@ export default {
// 跳转店铺首页
shopPage(id) {
let routeUrl = this.$router.resolve({
path: "/Merchant",
path: "/merchant",
query: { id: id },
});
window.open(routeUrl.href, "_blank");

View File

@@ -794,7 +794,7 @@ export default {
// 跳转店铺首页
goShopPage(id) {
let routeUrl = this.$router.resolve({
path: "/Merchant",
path: "/merchant",
query: { id: id },
});
window.open(routeUrl.href, "_blank");