feat: 登录逻辑的调整
This commit is contained in:
@@ -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>
|
||||
@@ -1,6 +1,6 @@
|
||||
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" });
|
||||
@@ -26,14 +26,13 @@ export const onLogin = async (e) => {
|
||||
};
|
||||
|
||||
// 检测token
|
||||
export const checkToken = async () => {
|
||||
export const checkToken = () => {
|
||||
return new Promise((resolve) => {
|
||||
const token = uni.getStorageSync("token");
|
||||
if (!token) {
|
||||
console.log("token不存在,重新登录");
|
||||
loginAuth().then(() => {
|
||||
resolve();
|
||||
});
|
||||
const appStore = useAppStore();
|
||||
console.log("appStore.hasToken: ", appStore.hasToken);
|
||||
if (!appStore.hasToken) {
|
||||
console.log("没有token,跳转到登录页");
|
||||
goLogin();
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
|
||||
@@ -181,7 +181,7 @@ import {
|
||||
import WebSocketManager from "@/utils/WebSocketManager";
|
||||
import TypewriterManager from "@/utils/TypewriterManager";
|
||||
import { IdUtils } from "@/utils";
|
||||
import { goLogin } from "@/hooks/useGoLogin";
|
||||
import { goLogin, checkToken } from "@/hooks/useGoLogin";
|
||||
|
||||
import { useAppStore } from "@/store";
|
||||
const appStore = useAppStore();
|
||||
@@ -297,12 +297,9 @@ const handleReply = (text) => {
|
||||
};
|
||||
|
||||
// 是发送指令
|
||||
const handleReplyInstruct = (item) => {
|
||||
if (!appStore.hasToken) {
|
||||
console.log("没有token,跳转到登录页");
|
||||
goLogin();
|
||||
return;
|
||||
}
|
||||
const handleReplyInstruct = async (item) => {
|
||||
await checkToken();
|
||||
|
||||
if (item.type === "MyOrder") {
|
||||
// 订单
|
||||
uni.navigateTo({
|
||||
@@ -632,14 +629,10 @@ const initData = () => {
|
||||
};
|
||||
|
||||
// 发送消息的参数拼接
|
||||
const sendMessage = (message, isInstruct = false) => {
|
||||
const sendMessage = async (message, isInstruct = false) => {
|
||||
console.log("发送的消息:", message);
|
||||
|
||||
if (!appStore.hasToken) {
|
||||
console.log("没有token,跳转到登录页");
|
||||
goLogin();
|
||||
return;
|
||||
}
|
||||
await checkToken();
|
||||
|
||||
if (!webSocketConnectStatus) {
|
||||
uni.showToast({
|
||||
|
||||
@@ -13,18 +13,12 @@
|
||||
<script setup>
|
||||
import { ref } from "vue";
|
||||
import DrawerHome from "@/pages/drawer/DrawerHome.vue";
|
||||
import { goLogin } from "@/hooks/useGoLogin";
|
||||
import { useAppStore } from "@/store";
|
||||
const appStore = useAppStore();
|
||||
import { checkToken } from "@/hooks/useGoLogin";
|
||||
const showLeft = ref(false);
|
||||
|
||||
// 打开窗口
|
||||
const showDrawer = (e) => {
|
||||
if (!appStore.hasToken) {
|
||||
console.log("没有token,跳转到登录页");
|
||||
goLogin();
|
||||
return;
|
||||
}
|
||||
const showDrawer = async (e) => {
|
||||
await checkToken();
|
||||
|
||||
showLeft.value.open();
|
||||
// 发送抽屉显示事件
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
<script setup>
|
||||
import ModuleTitle from "@/components/ModuleTitle/index.vue";
|
||||
import { defineProps } from "vue";
|
||||
import { checkToken } from "@/hooks/useGoLogin";
|
||||
|
||||
const props = defineProps({
|
||||
commodityDTO: {
|
||||
@@ -57,9 +58,11 @@ const props = defineProps({
|
||||
|
||||
/// 去下单
|
||||
const placeOrderHandle = (item) => {
|
||||
checkToken().then(() => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/goods/index?commodityId=${item.commodityId}`,
|
||||
});
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { goLogin } from "../../hooks/useGoLogin";
|
||||
import { BASE_URL } from "./baseUrl";
|
||||
import { loginAuth, checkPhone } from "@/manager/LoginManager";
|
||||
|
||||
const defaultConfig = {
|
||||
header: {
|
||||
@@ -53,14 +52,8 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
|
||||
resolve(res.data);
|
||||
if (res.statusCode && res.statusCode === 424) {
|
||||
console.log("424错误,重新登录");
|
||||
loginAuth().then(async () => {
|
||||
// 检测是否绑定手机号
|
||||
const res = await checkPhone();
|
||||
if (!res.data) {
|
||||
goLogin();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error("请求失败:", err);
|
||||
|
||||
Reference in New Issue
Block a user