feat: 实现退出登录时调用后端接口

在多个组件和工具文件中添加了doLogout调用,确保用户退出时通知后端
更新环境配置文件中的API地址
This commit is contained in:
zzp 2025-11-08 12:05:24 +08:00
parent a464d256a2
commit a9eef0d69f
9 changed files with 74 additions and 42 deletions

View File

@ -2,8 +2,8 @@
ENV = development ENV = development
# 本地环境接口地址 # 本地环境接口地址
# VITE_API_URL = http://123.60.153.169:8040/apih5 VITE_API_URL = http://123.60.153.169:8040/apih5
VITE_API_URL = http://4155gf93ll13.vicp.fun/apih5 # VITE_API_URL = http://4155gf93ll13.vicp.fun/apih5
# VITE_API_URL = http://123.60.79.143:8041/apih5 # VITE_API_URL = http://123.60.79.143:8041/apih5
# VITE_API_URL =http://localhost:8040/apih5 # VITE_API_URL =http://localhost:8040/apih5
# VITE_API_URL = https://cankao.cs.com.cn/apih5 # VITE_API_URL = https://cankao.cs.com.cn/apih5

View File

@ -3,8 +3,8 @@ ENV = production
# 线上环境接口地址 # 线上环境接口地址
# VITE_API_URL = https://cankao.cs.com.cn/mini # VITE_API_URL = https://cankao.cs.com.cn/mini
# VITE_API_URL = http://123.60.153.169:8040/apih5 VITE_API_URL = http://123.60.153.169:8040/apih5
VITE_API_URL = https://cankao.cs.com.cn/apih5 # VITE_API_URL = https://cankao.cs.com.cn/apih5
# VITE_API_URL = http://123.60.79.143:8041/apih5 # VITE_API_URL = http://123.60.79.143:8041/apih5

View File

@ -55,13 +55,11 @@ export const getUnlockList = (data: any) => {
return Request.post("/user/unlockList", data); return Request.post("/user/unlockList", data);
}; };
// 全文搜索 // 全文搜索
export const searchNews = (data: any) => { export const searchNews = (data: any) => {
return Request.post("/news/search", data); return Request.post("/news/search", data);
}; };
// 已发布列表 // 已发布列表
export const getReleaseList = (data: any) => { export const getReleaseList = (data: any) => {
return Request.post("/news/top_news_release_h5_d", data); return Request.post("/news/top_news_release_h5_d", data);
@ -76,3 +74,9 @@ export const editTopNews = (data: any) => {
export const sendToken = (data: any) => { export const sendToken = (data: any) => {
return Request.post("/common/forward/financial", data); return Request.post("/common/forward/financial", data);
}; };
// 退出登录
export const doLogout = (data: any) => {
console.log("🚀 ~ doLogout ~ data:", data);
return Request.post("/common/logout", data);
};

View File

@ -4,11 +4,7 @@
<view class="userContainer"> <view class="userContainer">
<u-avatar :src="avatarImg" size="60"></u-avatar> <u-avatar :src="avatarImg" size="60"></u-avatar>
<view class="userData"> <view class="userData">
<text class="phone">{{ <text class="phone">{{ !isLoginStatus ? "未登录用户" : maskPhoneNumber(Session.get("userPhone")) }}</text>
!isLoginStatus
? "未登录用户"
: maskPhoneNumber(Session.get("userPhone"))
}}</text>
<!-- <view class="setUserData"> <!-- <view class="setUserData">
编辑我的个人资料 编辑我的个人资料
<u-icon size="12" name="arrow-right"></u-icon> <u-icon size="12" name="arrow-right"></u-icon>
@ -98,9 +94,7 @@
<!-- 退出登录的按钮 --> <!-- 退出登录的按钮 -->
<view class="loginOut" :class="!isLoginStatus && 'loginBtn'"> <view class="loginOut" :class="!isLoginStatus && 'loginBtn'">
<u-button type="danger" size="large" @click="loginBtnStatus">{{ <u-button type="danger" size="large" @click="loginBtnStatus">{{ !isLoginStatus ? "点击登录" : "退出登录" }}</u-button>
!isLoginStatus ? "点击登录" : "退出登录"
}}</u-button>
</view> </view>
<!-- 登录弹框 --> <!-- 登录弹框 -->
@ -127,6 +121,8 @@ import like from "@/assets/images/like.png";
import time from "@/assets/images/time.png"; import time from "@/assets/images/time.png";
import vip from "@/assets/images/vip.png"; import vip from "@/assets/images/vip.png";
import { useShareStore } from "@/stores/shareStore"; import { useShareStore } from "@/stores/shareStore";
import { doLogout } from "@/api";
const stores = useShareStore(); const stores = useShareStore();
const curPages = getCurrentPages(); const curPages = getCurrentPages();
@ -177,6 +173,9 @@ const loginOut = () => {
icon: "none", icon: "none",
duration: 1500, duration: 1500,
}); });
doLogout({
financialAccount: Session.get("userPhone"),
});
// cookie // cookie
Session.clear(); Session.clear();
uni.removeStorageSync("subStatus"); uni.removeStorageSync("subStatus");

View File

@ -58,8 +58,7 @@
<indexMenuTitle title="资讯评分分布区间"></indexMenuTitle> <indexMenuTitle title="资讯评分分布区间"></indexMenuTitle>
<Line style="margin-top: 30rpx" :data="lineData"></Line> <Line style="margin-top: 30rpx" :data="lineData"></Line>
<view <view style="display: flex; flex-direction: column; text-align: center; justify-content: center; align-items: center; padding-bottom: 30rpx">
style="display: flex; flex-direction: column; text-align: center; justify-content: center; align-items: center; padding-bottom: 30rpx">
<InfoSummary style="width: 85%" :count="newsNum"></InfoSummary> <InfoSummary style="width: 85%" :count="newsNum"></InfoSummary>
</view> </view>
</view> </view>
@ -67,9 +66,7 @@
<view style="background-color: white; margin-top: 40rpx"> <view style="background-color: white; margin-top: 40rpx">
<div style="display: flex; justify-content: space-between; align-items: center"> <div style="display: flex; justify-content: space-between; align-items: center">
<indexMenuTitle title="资讯头条 Top20"></indexMenuTitle> <indexMenuTitle title="资讯头条 Top20"></indexMenuTitle>
<view <view style="display: flex; align-items: center; margin-right: 15rpx; font-size: 30rpx; gap: 10rpx; margin-top: 10rpx" @click="showCalendar">
style="display: flex; align-items: center; margin-right: 15rpx; font-size: 30rpx; gap: 10rpx; margin-top: 10rpx"
@click="showCalendar">
{{ chooseDate.startDate.split(" ")[0] }} {{ chooseDate.startDate.split(" ")[0] }}
<u-icon name="calendar" size="26" style="margin-right: 10rpx"></u-icon> <u-icon name="calendar" size="26" style="margin-right: 10rpx"></u-icon>
</view> </view>
@ -84,8 +81,7 @@
</view> </view>
<view style="background-color: white; margin-top: 40rpx"> <view style="background-color: white; margin-top: 40rpx">
<view <view style="display: flex; justify-content: space-between; align-items: center; padding-right: 30rpx; height: 100rpx">
style="display: flex; justify-content: space-between; align-items: center; padding-right: 30rpx; height: 100rpx">
<indexMenuTitle title="热门行业池 Top10"></indexMenuTitle> <indexMenuTitle title="热门行业池 Top10"></indexMenuTitle>
<view style="display: flex; gap: 3rpx"> <view style="display: flex; gap: 3rpx">
<text class="view-all" @click="onViewAll(0)">查看全部</text> <text class="view-all" @click="onViewAll(0)">查看全部</text>
@ -97,8 +93,7 @@
</view> </view>
<view style="background-color: white; margin-top: 40rpx"> <view style="background-color: white; margin-top: 40rpx">
<view <view style="display: flex; justify-content: space-between; align-items: center; padding-right: 30rpx; height: 100rpx">
style="display: flex; justify-content: space-between; align-items: center; padding-right: 30rpx; height: 100rpx">
<indexMenuTitle title="风口概念池 Top10"></indexMenuTitle> <indexMenuTitle title="风口概念池 Top10"></indexMenuTitle>
<view style="display: flex; gap: 3rpx"> <view style="display: flex; gap: 3rpx">
<text class="view-all" @click="onViewAll(1)">查看全部</text> <text class="view-all" @click="onViewAll(1)">查看全部</text>
@ -111,12 +106,24 @@
<view class="logout" @click="loginOut" v-if="Session.get('token')">退出登录</view> <view class="logout" @click="loginOut" v-if="Session.get('token')">退出登录</view>
<LoginPopup :show="LoginShow" @handlePopupClose="handlePopupClose" <LoginPopup
@handlePopupSuccessCallback="handlePopupSuccessCallback" @handlePopupErrorCallback="handlePopupErrorCallback" /> :show="LoginShow"
@handlePopupClose="handlePopupClose"
@handlePopupSuccessCallback="handlePopupSuccessCallback"
@handlePopupErrorCallback="handlePopupErrorCallback"
/>
<u-calendar :show="calendarShow" min-date="2025-01-01" closeOnClickOverlay :max-date="maxDate" <u-calendar
:default-date="chooseDate.startDate" monthNum="12" :key="chooseDate.startDate" @confirm="calendarConfirm" :show="calendarShow"
@close="calendarShow = false"> min-date="2025-01-01"
closeOnClickOverlay
:max-date="maxDate"
:default-date="chooseDate.startDate"
monthNum="12"
:key="chooseDate.startDate"
@confirm="calendarConfirm"
@close="calendarShow = false"
>
</u-calendar> </u-calendar>
</view> </view>
</template> </template>
@ -284,8 +291,12 @@ const handlePopupSuccessCallback = () => {
const handlePopupErrorCallback = () => { const handlePopupErrorCallback = () => {
console.log("登录失败"); console.log("登录失败");
}; };
import { doLogout } from "@/api";
function loginOut() { function loginOut() {
doLogout({
financialAccount: Session.get("userPhone"),
});
Session.clear(); Session.clear();
window.location.reload(); window.location.reload();
} }
@ -305,8 +316,8 @@ onMounted(async () => {
const { aplus_queue } = window; const { aplus_queue } = window;
aplus_queue.push({ aplus_queue.push({
action: 'aplus.sendPV', action: "aplus.sendPV",
arguments: [{ is_auto: false }] // arguments: [{ is_auto: false }], //
}); });
}); });

View File

@ -98,8 +98,12 @@
<view class="logout" @click="loginOut" v-if="Session.get('token')">退出登录</view> <view class="logout" @click="loginOut" v-if="Session.get('token')">退出登录</view>
<LoginPopup :show="LoginShow" @handlePopupClose="handlePopupClose" <LoginPopup
@handlePopupSuccessCallback="handlePopupSuccessCallback" @handlePopupErrorCallback="handlePopupErrorCallback" /> :show="LoginShow"
@handlePopupClose="handlePopupClose"
@handlePopupSuccessCallback="handlePopupSuccessCallback"
@handlePopupErrorCallback="handlePopupErrorCallback"
/>
</view> </view>
</template> </template>
@ -243,8 +247,11 @@ const handlePopupSuccessCallback = () => {
const handlePopupErrorCallback = () => { const handlePopupErrorCallback = () => {
console.log("登录失败"); console.log("登录失败");
}; };
import { doLogout } from "@/api";
function loginOut() { function loginOut() {
doLogout({
financialAccount: Session.get("userPhone"),
});
Session.clear(); Session.clear();
window.location.reload(); window.location.reload();
} }
@ -260,7 +267,7 @@ async function getLineDataFn() {
if (lineTabIndex.value == 0) { if (lineTabIndex.value == 0) {
// //
getTopIndustryPeriod({ getTopIndustryPeriod({
start_time: dayjs().subtract(7, 'day').format("YYYY-MM-DD"), start_time: dayjs().subtract(7, "day").format("YYYY-MM-DD"),
end_time: dayjs().format("YYYY-MM-DD"), end_time: dayjs().format("YYYY-MM-DD"),
limit_num: 10, limit_num: 10,
}).then((res) => { }).then((res) => {
@ -269,7 +276,7 @@ async function getLineDataFn() {
} else if (lineTabIndex.value == 1) { } else if (lineTabIndex.value == 1) {
// //
getTopConceptPeriod({ getTopConceptPeriod({
start_time: dayjs().subtract(7, 'day').format("YYYY-MM-DD"), start_time: dayjs().subtract(7, "day").format("YYYY-MM-DD"),
end_time: dayjs().format("YYYY-MM-DD"), end_time: dayjs().format("YYYY-MM-DD"),
limit_num: 10, limit_num: 10,
}).then((res) => { }).then((res) => {
@ -278,7 +285,7 @@ async function getLineDataFn() {
} else if (lineTabIndex.value == 2) { } else if (lineTabIndex.value == 2) {
// //
getTopSourcePeriod({ getTopSourcePeriod({
start_time: dayjs().subtract(7, 'day').format("YYYY-MM-DD"), start_time: dayjs().subtract(7, "day").format("YYYY-MM-DD"),
end_time: dayjs().format("YYYY-MM-DD"), end_time: dayjs().format("YYYY-MM-DD"),
limit_num: 10, limit_num: 10,
}).then((res) => { }).then((res) => {
@ -308,10 +315,9 @@ onMounted(async () => {
} }
getLineDataFn(); getLineDataFn();
aplus_queue.push({ aplus_queue.push({
action: 'aplus.sendPV', action: "aplus.sendPV",
arguments: [{ is_auto: false }] // arguments: [{ is_auto: false }], //
}); });
}); });
</script> </script>

View File

@ -34,7 +34,7 @@
import { ref, onMounted, onUnmounted, reactive } from "vue"; import { ref, onMounted, onUnmounted, reactive } from "vue";
import { onLoad, onShow } from "@dcloudio/uni-app"; import { onLoad, onShow } from "@dcloudio/uni-app";
import { Session } from "@/utils/storage"; import { Session } from "@/utils/storage";
import { doLogout } from "@/api";
const tabIndex = ref(0); const tabIndex = ref(0);
function tabChange(type) { function tabChange(type) {
@ -45,7 +45,11 @@ function tabChange(type) {
}); });
} }
function logout() { async function logout() {
await doLogout({
financialAccount: Session.get("userPhone"),
});
Session.clear(); Session.clear();
window.location.reload(); window.location.reload();
} }

View File

@ -3,6 +3,7 @@ import type { AxiosResponse } from "axios";
// import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'; // import { ElMessage, ElMessageBox, ElNotification } from 'element-plus';
import { Session } from "@/utils/storage"; import { Session } from "@/utils/storage";
import qs from "qs"; import qs from "qs";
import { doLogout } from "@/api";
// 配置新建一个 axios 实例 // 配置新建一个 axios 实例
const service = axios.create({ const service = axios.create({
@ -52,6 +53,9 @@ service.interceptors.response.use(
// `token` 过期或者账号已在别处登录 // `token` 过期或者账号已在别处登录
if (res.code === 401 || res.code === 4001) { if (res.code === 401 || res.code === 4001) {
doLogout({
financialAccount: Session.get("userPhone"),
});
Session.clear(); // 清除浏览器全部临时缓存 Session.clear(); // 清除浏览器全部临时缓存
window.location.href = "/"; // 去登录页 window.location.href = "/"; // 去登录页
console.log("你已被登出,请重新登录"); console.log("你已被登出,请重新登录");

View File

@ -3,6 +3,7 @@ import type { AxiosResponse } from "axios";
// import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'; // import { ElMessage, ElMessageBox, ElNotification } from 'element-plus';
import { Session } from "@/utils/storage"; import { Session } from "@/utils/storage";
import qs from "qs"; import qs from "qs";
import { doLogout } from "@/api";
// 配置新建一个 axios 实例 // 配置新建一个 axios 实例
const service = axios.create({ const service = axios.create({
@ -52,6 +53,9 @@ service.interceptors.response.use(
// `token` 过期或者账号已在别处登录 // `token` 过期或者账号已在别处登录
if (res.status === 401 || res.status === 4001) { if (res.status === 401 || res.status === 4001) {
doLogout({
financialAccount: Session.get("userPhone"),
});
Session.clear(); // 清除浏览器全部临时缓存 Session.clear(); // 清除浏览器全部临时缓存
window.location.href = "/"; // 去登录页 window.location.href = "/"; // 去登录页
console.log("你已被登出,请重新登录"); console.log("你已被登出,请重新登录");