feat: 登录逻辑的调整

This commit is contained in:
2025-09-20 16:13:07 +08:00
parent 67474d73a4
commit 4cdff7a594
6 changed files with 25 additions and 61 deletions

View File

@@ -1,18 +0,0 @@
<template>
<button
v-if="!hasToken"
class="reset-btn"
open-type="getPhoneNumber"
@getphonenumber="onLogin"
/>
</template>
<script setup>
import { computed, defineEmits } from "vue";
import { useAppStore } from "@/store";
import { onLogin } from "@/hooks/useGoLogin";
const emits = defineEmits(["click"]);
const hasToken = computed(() => useAppStore().hasToken);
</script>

View File

@@ -1,6 +1,6 @@
import { loginAuth, bindPhone } from "@/manager/LoginManager"; import { loginAuth, bindPhone } from "@/manager/LoginManager";
// 引入base.js中的clientId import { clientId } from "@/constant/base";
import { clientId } from "@/constant/base"; import { useAppStore } from "@/store";
// 跳转登录 // 跳转登录
export const goLogin = () => uni.navigateTo({ url: "/pages/login/index" }); export const goLogin = () => uni.navigateTo({ url: "/pages/login/index" });
@@ -26,14 +26,13 @@ export const onLogin = async (e) => {
}; };
// 检测token // 检测token
export const checkToken = async () => { export const checkToken = () => {
return new Promise((resolve) => { return new Promise((resolve) => {
const token = uni.getStorageSync("token"); const appStore = useAppStore();
if (!token) { console.log("appStore.hasToken: ", appStore.hasToken);
console.log("token不存在重新登录"); if (!appStore.hasToken) {
loginAuth().then(() => { console.log("没有token跳转到登录页");
resolve(); goLogin();
});
return; return;
} }
resolve(); resolve();

View File

@@ -181,7 +181,7 @@ import {
import WebSocketManager from "@/utils/WebSocketManager"; import WebSocketManager from "@/utils/WebSocketManager";
import TypewriterManager from "@/utils/TypewriterManager"; import TypewriterManager from "@/utils/TypewriterManager";
import { IdUtils } from "@/utils"; import { IdUtils } from "@/utils";
import { goLogin } from "@/hooks/useGoLogin"; import { goLogin, checkToken } from "@/hooks/useGoLogin";
import { useAppStore } from "@/store"; import { useAppStore } from "@/store";
const appStore = useAppStore(); const appStore = useAppStore();
@@ -297,12 +297,9 @@ const handleReply = (text) => {
}; };
// 是发送指令 // 是发送指令
const handleReplyInstruct = (item) => { const handleReplyInstruct = async (item) => {
if (!appStore.hasToken) { await checkToken();
console.log("没有token跳转到登录页");
goLogin();
return;
}
if (item.type === "MyOrder") { if (item.type === "MyOrder") {
// 订单 // 订单
uni.navigateTo({ uni.navigateTo({
@@ -632,14 +629,10 @@ const initData = () => {
}; };
// 发送消息的参数拼接 // 发送消息的参数拼接
const sendMessage = (message, isInstruct = false) => { const sendMessage = async (message, isInstruct = false) => {
console.log("发送的消息:", message); console.log("发送的消息:", message);
if (!appStore.hasToken) { await checkToken();
console.log("没有token跳转到登录页");
goLogin();
return;
}
if (!webSocketConnectStatus) { if (!webSocketConnectStatus) {
uni.showToast({ uni.showToast({

View File

@@ -13,18 +13,12 @@
<script setup> <script setup>
import { ref } from "vue"; import { ref } from "vue";
import DrawerHome from "@/pages/drawer/DrawerHome.vue"; import DrawerHome from "@/pages/drawer/DrawerHome.vue";
import { goLogin } from "@/hooks/useGoLogin"; import { checkToken } from "@/hooks/useGoLogin";
import { useAppStore } from "@/store";
const appStore = useAppStore();
const showLeft = ref(false); const showLeft = ref(false);
// 打开窗口 // 打开窗口
const showDrawer = (e) => { const showDrawer = async (e) => {
if (!appStore.hasToken) { await checkToken();
console.log("没有token跳转到登录页");
goLogin();
return;
}
showLeft.value.open(); showLeft.value.open();
// 发送抽屉显示事件 // 发送抽屉显示事件

View File

@@ -47,6 +47,7 @@
<script setup> <script setup>
import ModuleTitle from "@/components/ModuleTitle/index.vue"; import ModuleTitle from "@/components/ModuleTitle/index.vue";
import { defineProps } from "vue"; import { defineProps } from "vue";
import { checkToken } from "@/hooks/useGoLogin";
const props = defineProps({ const props = defineProps({
commodityDTO: { commodityDTO: {
@@ -57,8 +58,10 @@ const props = defineProps({
/// 去下单 /// 去下单
const placeOrderHandle = (item) => { const placeOrderHandle = (item) => {
uni.navigateTo({ checkToken().then(() => {
url: `/pages/goods/index?commodityId=${item.commodityId}`, uni.navigateTo({
url: `/pages/goods/index?commodityId=${item.commodityId}`,
});
}); });
}; };
</script> </script>

View File

@@ -1,6 +1,5 @@
import { goLogin } from "../../hooks/useGoLogin"; import { goLogin } from "../../hooks/useGoLogin";
import { BASE_URL } from "./baseUrl"; import { BASE_URL } from "./baseUrl";
import { loginAuth, checkPhone } from "@/manager/LoginManager";
const defaultConfig = { const defaultConfig = {
header: { header: {
@@ -53,13 +52,7 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
resolve(res.data); resolve(res.data);
if (res.statusCode && res.statusCode === 424) { if (res.statusCode && res.statusCode === 424) {
console.log("424错误重新登录"); console.log("424错误重新登录");
loginAuth().then(async () => { goLogin();
// 检测是否绑定手机号
const res = await checkPhone();
if (!res.data) {
goLogin();
}
});
} }
}, },
fail: (err) => { fail: (err) => {