feat: 退出登录

This commit is contained in:
2025-09-20 15:24:40 +08:00
parent dc8b939ff3
commit 67474d73a4
4 changed files with 43 additions and 17 deletions

View File

@@ -1,8 +1,11 @@
// 退出登录
export const NOTICE_EVENT_LOGOUT = "NOTICE_EVENT_LOGOUT";
// 滚动到底部
export const SCROLL_TO_BOTTOM = 'SCROLL_TO_BOTTOM'
export const SCROLL_TO_BOTTOM = "SCROLL_TO_BOTTOM";
// 推荐帖子
export const RECOMMEND_POSTS_TITLE = 'RECOMMEND_POSTS_TITLE'
export const RECOMMEND_POSTS_TITLE = "RECOMMEND_POSTS_TITLE";
// 发送命令
export const SEND_COMMAND_TEXT = 'SEND_COMMAND_TEXT'
export const SEND_COMMAND_TEXT = "SEND_COMMAND_TEXT";

View File

@@ -151,6 +151,7 @@ import {
SCROLL_TO_BOTTOM,
RECOMMEND_POSTS_TITLE,
SEND_COMMAND_TEXT,
NOTICE_EVENT_LOGOUT,
} from "@/constant/constant";
import { WSS_URL } from "@/request/base/baseUrl";
import { MessageRole, MessageType, CompName } from "../../model/ChatModel";
@@ -189,7 +190,7 @@ const statusBarHeight = ref(20);
/// 输入框组件引用
const inputAreaRef = ref(null);
const timer = ref(null);
const holdKeyboardTimer = ref(null);
/// focus时点击页面的时候不收起键盘
const holdKeyboard = ref(false);
/// 是否在键盘弹出,点击界面时关闭键盘
@@ -235,8 +236,8 @@ const openDrawer = () => emits("openDrawer");
/// =============事件函数↓================
const handleTouchEnd = () => {
clearTimeout(timer.value);
timer.value = setTimeout(() => {
clearTimeout(holdKeyboardTimer.value);
holdKeyboardTimer.value = setTimeout(() => {
// 键盘弹出时点击界面则关闭键盘
if (holdKeyboardFlag.value && isKeyboardShow.value) {
uni.hideKeyboard();
@@ -338,6 +339,13 @@ const sendMessageAction = (inputText) => {
/// 添加通知
const addNoticeListener = () => {
uni.$on(NOTICE_EVENT_LOGOUT, () => {
resetConfig();
uni.showToast({
title: "退出登录成功",
});
});
uni.$on(SCROLL_TO_BOTTOM, () => {
setTimeout(() => {
scrollToBottom();
@@ -773,7 +781,12 @@ onUnmounted(() => {
uni.$off(SCROLL_TO_BOTTOM);
uni.$off(RECOMMEND_POSTS_TITLE);
uni.$off(SEND_COMMAND_TEXT);
uni.$off(NOTICE_EVENT_LOGOUT);
resetConfig();
});
const resetConfig = () => {
// 清理WebSocket连接
if (webSocketManager) {
webSocketManager.destroy();
@@ -790,11 +803,11 @@ onUnmounted(() => {
resetMessageState();
// 清理定时器
if (timer.value) {
clearTimeout(timer.value);
timer.value = null;
if (holdKeyboardTimer.value) {
clearTimeout(holdKeyboardTimer.value);
holdKeyboardTimer.value = null;
}
});
};
</script>
<style lang="scss" scoped>

View File

@@ -11,7 +11,7 @@
<text class="title">我的</text>
</view>
<MineSetting v-if="isDrawerVisible" />
<MineSetting v-if="isDrawerVisible" @closeDrawer="closeDrawer" />
</view>
</template>
@@ -23,6 +23,7 @@ const emits = defineEmits(["closeDrawer"]);
const isDrawerVisible = ref(false);
const closeDrawer = () => {
console.log("关闭抽屉");
isDrawerVisible.value = false;
emits("closeDrawer");
};

View File

@@ -36,8 +36,13 @@
</template>
<script setup>
import { ref, onMounted } from "vue";
import { ref, onMounted, defineEmits } from "vue";
import { getLoginUserPhone } from "@/request/api/LoginApi";
import { NOTICE_EVENT_LOGOUT } from "@/constant/constant";
import { useAppStore } from "@/store";
const appStore = useAppStore();
const emits = defineEmits(["closeDrawer"]);
// 假数据
const userInfo = ref({
@@ -51,12 +56,12 @@ const menuList = ref([
// { label: '修改手机号', type: 'navigate', url: '/pages/change-phone/change-phone' },
{
label: "账号注销",
type: "navigate",
url: "/pages/cancel-account/cancel-account",
type: "action",
url: "cancelAccount",
},
// { label: '营业资质&协议', type: 'navigate', url: '/pages/agreement/agreement' },
{ label: "联系客服", type: "action", action: "contactService" },
{ label: "订阅消息", type: "action", action: "subscribeMessage" },
// { label: "联系客服", type: "action", action: "contactService" },
// { label: "订阅消息", type: "action", action: "subscribeMessage" },
]);
// 组件挂载时调用
@@ -79,6 +84,8 @@ const handleMenuClick = (item) => {
} else if (item.type === "action") {
if (item.action === "contactService") {
uni.showToast({ title: "联系客服功能待实现", icon: "none" });
} else if (item.action === "cancelAccount") {
handleLogout();
} else if (item.action === "subscribeMessage") {
uni.requestSubscribeMessage({
tmplIds: ["fMIt1q9GgM3Ep0DJSNgVPm4C3lCpQdz2TediETcv3iM"],
@@ -98,7 +105,9 @@ const handleLogout = () => {
success: (res) => {
if (res.confirm) {
uni.clearStorageSync();
uni.reLaunch({ url: "/pages/login/index" });
appStore.setHasToken(false);
emits("closeDrawer");
uni.$emit(NOTICE_EVENT_LOGOUT);
}
},
});