feat: 未登录状态调整
This commit is contained in:
@@ -7,7 +7,7 @@ VITE_BASE_URL = https://onefeel.brother7.cn/ingress
|
||||
# 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
|
||||
|
||||
@@ -7,7 +7,7 @@ VITE_BASE_URL = https://onefeel.brother7.cn/ingress
|
||||
# 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
|
||||
@@ -7,7 +7,7 @@ VITE_BASE_URL = https://onefeel.brother7.cn/ingress
|
||||
# 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
|
||||
@@ -5,6 +5,10 @@ export const goLogin = () => uni.reLaunch({ url: "/pages/login/index" });
|
||||
|
||||
// 登录逻辑
|
||||
export const onLogin = (e) => {
|
||||
const token = uni.getStorageSync("token");
|
||||
|
||||
if (token) return;
|
||||
|
||||
const { code } = e.detail;
|
||||
console.info("onLogin code: ", code);
|
||||
|
||||
@@ -18,6 +22,9 @@ export const onLogin = (e) => {
|
||||
|
||||
// 绑定手机号
|
||||
bindPhone(params);
|
||||
|
||||
// 通知刷新
|
||||
uni.$emit("TOKEN_CHANGE");
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@
|
||||
</template>
|
||||
|
||||
<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 {
|
||||
SCROLL_TO_BOTTOM,
|
||||
@@ -353,6 +353,18 @@ onLoad(() => {
|
||||
});
|
||||
});
|
||||
|
||||
// token存在,初始化数据
|
||||
const initHandler = () => {
|
||||
console.log("initHandler");
|
||||
|
||||
loadRecentConversation();
|
||||
loadConversationMsgList();
|
||||
initWebSocket();
|
||||
};
|
||||
|
||||
// 监听token变化
|
||||
uni.$on("TOKEN_CHANGE", () => initHandler());
|
||||
|
||||
onMounted(() => {
|
||||
try {
|
||||
getMainPageData();
|
||||
@@ -360,11 +372,7 @@ onMounted(() => {
|
||||
initTypewriterManager();
|
||||
|
||||
// 有token时,加载最近会话、最近消息、初始化socket
|
||||
checkToken().then(async () => {
|
||||
await loadRecentConversation();
|
||||
loadConversationMsgList();
|
||||
initWebSocket();
|
||||
});
|
||||
checkToken().then(() => initHandler());
|
||||
} catch (error) {
|
||||
console.error("页面初始化错误:", error);
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
>
|
||||
<button
|
||||
class="reset-btn more-tips-item-title"
|
||||
open-type="getPhoneNumber"
|
||||
@getphonenumber="onLogin"
|
||||
@click="sendReply(item)"
|
||||
:open-type="needAuth ? 'getPhoneNumber' : ''"
|
||||
@getphonenumber="handleGetPhoneNumber"
|
||||
@click="handleClick(item)"
|
||||
>
|
||||
{{ item }}
|
||||
</button>
|
||||
@@ -20,10 +20,12 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { defineProps } from "vue";
|
||||
import { defineProps, ref } from "vue";
|
||||
import { onLogin, checkToken } from "@/hooks/useGoLogin";
|
||||
|
||||
const emits = defineEmits(["replySent"]);
|
||||
const needAuth = ref(true);
|
||||
let pendingText = "";
|
||||
|
||||
defineProps({
|
||||
itemList: {
|
||||
@@ -45,42 +47,38 @@ const sendReply = (text) => {
|
||||
emits("replySent", text); // 向父组件传递数据
|
||||
});
|
||||
};
|
||||
|
||||
// 处理点击事件
|
||||
const handleClick = (text) => {
|
||||
// 检查本地token
|
||||
const token = uni.getStorageSync("token");
|
||||
|
||||
if (token) {
|
||||
// 情况2:token有值,直接发送回复,此时open-type为空字符串
|
||||
needAuth.value = false;
|
||||
sendReply(text);
|
||||
} else {
|
||||
// 情况1:token没有值,设置需要授权状态,触发微信授权
|
||||
needAuth.value = true;
|
||||
pendingText = text;
|
||||
// 由于open-type已经动态绑定为'getPhoneNumber',点击会自动触发授权
|
||||
}
|
||||
};
|
||||
|
||||
// 处理微信授权回调
|
||||
const handleGetPhoneNumber = async (e) => {
|
||||
await onLogin(e);
|
||||
|
||||
// 授权成功后发送之前存储的文本
|
||||
if (pendingText) {
|
||||
sendReply(pendingText);
|
||||
pendingText = "";
|
||||
}
|
||||
|
||||
needAuth.value = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.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-family: PingFang SC, PingFang SC;
|
||||
font-weight: 500;
|
||||
font-size: 12px;
|
||||
color: #00a6ff;
|
||||
line-height: 24px;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
@import "./styles/ChatMoreTips.scss";
|
||||
</style>
|
||||
|
||||
34
pages/chat/styles/ChatMoreTips.scss
Normal file
34
pages/chat/styles/ChatMoreTips.scss
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,7 @@ const menuList = ref([
|
||||
},
|
||||
// { label: '营业资质&协议', type: 'navigate', url: '/pages/agreement/agreement' },
|
||||
{ label: "联系客服", type: "action", action: "contactService" },
|
||||
{ label: "订阅消息", type: "action", action: "subscribeMessage" },
|
||||
]);
|
||||
|
||||
// 生命周期钩子
|
||||
@@ -81,6 +82,13 @@ const handleMenuClick = (item) => {
|
||||
} else if (item.type === "action") {
|
||||
if (item.action === "contactService") {
|
||||
uni.showToast({ title: "联系客服功能待实现", icon: "none" });
|
||||
} else if (item.action === "subscribeMessage") {
|
||||
uni.requestSubscribeMessage({
|
||||
tmplIds: ["fMIt1q9GgM3Ep0DJSNgVPm4C3lCpQdz2TediETcv3iM"],
|
||||
success(res) {
|
||||
console.log(res);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user