feat: 未登录状态调整

This commit is contained in:
duanshuwen
2025-09-13 16:09:37 +08:00
parent c03a4200be
commit 11141ae436
8 changed files with 103 additions and 48 deletions

View File

@@ -7,7 +7,7 @@ VITE_BASE_URL = https://onefeel.brother7.cn/ingress
# VITE_BASE_URL = https://biz.nianxx.cn # VITE_BASE_URL = https://biz.nianxx.cn
# 测试 # 测试
ITE_WSS_URL = wss://onefeel.brother7.cn/ingress/agent/ws/chat VITE_WSS_URL = wss://onefeel.brother7.cn/ingress/agent/ws/chat
# 生产 # 生产
# VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat # VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat

View File

@@ -7,7 +7,7 @@ VITE_BASE_URL = https://onefeel.brother7.cn/ingress
# VITE_BASE_URL = https://biz.nianxx.cn # VITE_BASE_URL = https://biz.nianxx.cn
# 测试 # 测试
ITE_WSS_URL = wss://onefeel.brother7.cn/ingress/agent/ws/chat VITE_WSS_URL = wss://onefeel.brother7.cn/ingress/agent/ws/chat
# 生产 # 生产
# VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat # VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat

View File

@@ -7,7 +7,7 @@ VITE_BASE_URL = https://onefeel.brother7.cn/ingress
# VITE_BASE_URL = https://biz.nianxx.cn # VITE_BASE_URL = https://biz.nianxx.cn
# 测试 # 测试
ITE_WSS_URL = wss://onefeel.brother7.cn/ingress/agent/ws/chat VITE_WSS_URL = wss://onefeel.brother7.cn/ingress/agent/ws/chat
# 生产 # 生产
# VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat # VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat

View File

@@ -5,6 +5,10 @@ export const goLogin = () => uni.reLaunch({ url: "/pages/login/index" });
// 登录逻辑 // 登录逻辑
export const onLogin = (e) => { export const onLogin = (e) => {
const token = uni.getStorageSync("token");
if (token) return;
const { code } = e.detail; const { code } = e.detail;
console.info("onLogin code: ", code); console.info("onLogin code: ", code);
@@ -18,6 +22,9 @@ export const onLogin = (e) => {
// 绑定手机号 // 绑定手机号
bindPhone(params); bindPhone(params);
// 通知刷新
uni.$emit("TOKEN_CHANGE");
}); });
}; };

View File

@@ -136,7 +136,7 @@
</template> </template>
<script setup> <script setup>
import { onMounted, nextTick, onUnmounted, ref, defineEmits } from "vue"; import { onMounted, nextTick, onUnmounted, ref, defineEmits, watch } from "vue";
import { onLoad } from "@dcloudio/uni-app"; import { onLoad } from "@dcloudio/uni-app";
import { import {
SCROLL_TO_BOTTOM, SCROLL_TO_BOTTOM,
@@ -353,6 +353,18 @@ onLoad(() => {
}); });
}); });
// token存在初始化数据
const initHandler = () => {
console.log("initHandler");
loadRecentConversation();
loadConversationMsgList();
initWebSocket();
};
// 监听token变化
uni.$on("TOKEN_CHANGE", () => initHandler());
onMounted(() => { onMounted(() => {
try { try {
getMainPageData(); getMainPageData();
@@ -360,11 +372,7 @@ onMounted(() => {
initTypewriterManager(); initTypewriterManager();
// 有token时加载最近会话、最近消息、初始化socket // 有token时加载最近会话、最近消息、初始化socket
checkToken().then(async () => { checkToken().then(() => initHandler());
await loadRecentConversation();
loadConversationMsgList();
initWebSocket();
});
} catch (error) { } catch (error) {
console.error("页面初始化错误:", error); console.error("页面初始化错误:", error);
} }

View File

@@ -8,9 +8,9 @@
> >
<button <button
class="reset-btn more-tips-item-title" class="reset-btn more-tips-item-title"
open-type="getPhoneNumber" :open-type="needAuth ? 'getPhoneNumber' : ''"
@getphonenumber="onLogin" @getphonenumber="handleGetPhoneNumber"
@click="sendReply(item)" @click="handleClick(item)"
> >
{{ item }} {{ item }}
</button> </button>
@@ -20,10 +20,12 @@
</template> </template>
<script setup> <script setup>
import { defineProps } from "vue"; import { defineProps, ref } from "vue";
import { onLogin, checkToken } from "@/hooks/useGoLogin"; import { onLogin, checkToken } from "@/hooks/useGoLogin";
const emits = defineEmits(["replySent"]); const emits = defineEmits(["replySent"]);
const needAuth = ref(true);
let pendingText = "";
defineProps({ defineProps({
itemList: { itemList: {
@@ -45,42 +47,38 @@ const sendReply = (text) => {
emits("replySent", text); // 向父组件传递数据 emits("replySent", text); // 向父组件传递数据
}); });
}; };
// 处理点击事件
const handleClick = (text) => {
// 检查本地token
const token = uni.getStorageSync("token");
if (token) {
// 情况2token有值直接发送回复此时open-type为空字符串
needAuth.value = false;
sendReply(text);
} else {
// 情况1token没有值设置需要授权状态触发微信授权
needAuth.value = true;
pendingText = text;
// 由于open-type已经动态绑定为'getPhoneNumber',点击会自动触发授权
}
};
// 处理微信授权回调
const handleGetPhoneNumber = async (e) => {
await onLogin(e);
// 授权成功后发送之前存储的文本
if (pendingText) {
sendReply(pendingText);
pendingText = "";
}
needAuth.value = false;
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.more-tips { @import "./styles/ChatMoreTips.scss";
width: 100%;
&-scroll {
display: flex;
flex-direction: row;
overflow-x: auto;
white-space: nowrap;
-webkit-overflow-scrolling: touch;
padding-bottom: 12px;
box-sizing: border-box;
}
.more-tips-item {
border-radius: 8px;
margin: 4px;
box-shadow: 0 2px 5px 0px rgba(0, 0, 0, 0.1);
background-color: #ffffff;
padding: 2px 12px;
display: flex;
flex-direction: column;
flex-shrink: 0;
white-space: nowrap;
.more-tips-item-title {
font-family: PingFang SC, PingFang SC;
font-weight: 500;
font-size: 12px;
color: #00a6ff;
line-height: 24px;
text-align: center;
white-space: nowrap;
}
}
}
</style> </style>

View File

@@ -0,0 +1,34 @@
.more-tips {
width: 100%;
&-scroll {
display: flex;
flex-direction: row;
overflow-x: auto;
white-space: nowrap;
-webkit-overflow-scrolling: touch;
padding-bottom: 12px;
box-sizing: border-box;
}
.more-tips-item {
border-radius: 8px;
margin: 4px;
box-shadow: 0 2px 5px 0px rgba(0, 0, 0, 0.1);
background-color: #ffffff;
padding: 2px 12px;
display: flex;
flex-direction: column;
flex-shrink: 0;
white-space: nowrap;
.more-tips-item-title {
font-weight: 500;
font-size: 12px;
color: #00a6ff;
line-height: 24px;
text-align: center;
white-space: nowrap;
}
}
}

View File

@@ -57,6 +57,7 @@ const menuList = ref([
}, },
// { label: '营业资质&协议', type: 'navigate', url: '/pages/agreement/agreement' }, // { label: '营业资质&协议', type: 'navigate', url: '/pages/agreement/agreement' },
{ label: "联系客服", type: "action", action: "contactService" }, { label: "联系客服", type: "action", action: "contactService" },
{ label: "订阅消息", type: "action", action: "subscribeMessage" },
]); ]);
// 生命周期钩子 // 生命周期钩子
@@ -81,6 +82,13 @@ const handleMenuClick = (item) => {
} else if (item.type === "action") { } else if (item.type === "action") {
if (item.action === "contactService") { if (item.action === "contactService") {
uni.showToast({ title: "联系客服功能待实现", icon: "none" }); uni.showToast({ title: "联系客服功能待实现", icon: "none" });
} else if (item.action === "subscribeMessage") {
uni.requestSubscribeMessage({
tmplIds: ["fMIt1q9GgM3Ep0DJSNgVPm4C3lCpQdz2TediETcv3iM"],
success(res) {
console.log(res);
},
});
} }
} }
}; };