fix(realtimeInfo): 修复页面导航和登录逻辑问题
修复导航菜单条件渲染错误,优化登录流程处理token逻辑 移除多余的空行和console.log,格式化代码样式
This commit is contained in:
parent
a9eef0d69f
commit
d25f87a889
|
|
@ -3,22 +3,22 @@
|
|||
<view class="r_menu">
|
||||
<image src="@/assets/images/logo.png" class="logo"></image>
|
||||
|
||||
<view class="r_menu_item" @click="tabChange(1)" v-if="tabIndex != 4">
|
||||
<view class="r_menu_item" @click="tabChange(1)">
|
||||
<text class="menu_item">资讯头条榜</text>
|
||||
<view class="line" v-if="tabIndex == 1"></view>
|
||||
</view>
|
||||
|
||||
<view class="r_menu_item" @click="tabChange(2)" v-if="tabIndex != 4">
|
||||
<view class="r_menu_item" @click="tabChange(2)">
|
||||
<text class="menu_item">热门行业</text>
|
||||
<view class="line" v-if="tabIndex == 2"></view>
|
||||
</view>
|
||||
|
||||
<view class="r_menu_item" @click="tabChange(3)" v-if="tabIndex != 4">
|
||||
<view class="r_menu_item" @click="tabChange(3)">
|
||||
<text class="menu_item">风口概念</text>
|
||||
<view class="line" v-if="tabIndex == 3"></view>
|
||||
</view>
|
||||
|
||||
<view class="r_menu_item" @click="tabChange(4)" v-if="tabIndex == 4">
|
||||
<view class="r_menu_item" @click="tabChange(4)">
|
||||
<text class="menu_item">编辑精选</text>
|
||||
<view class="line" v-if="tabIndex == 4"></view>
|
||||
</view>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, onUnmounted, reactive } from "vue";
|
||||
import { ref, onMounted, onUnmounted, reactive, nextTick } from "vue";
|
||||
import { onLoad, onShow } from "@dcloudio/uni-app";
|
||||
import { Session } from "@/utils/storage";
|
||||
import { doLogout } from "@/api";
|
||||
|
|
@ -45,17 +45,41 @@ function tabChange(type) {
|
|||
});
|
||||
}
|
||||
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
async function logout() {
|
||||
if (Session.get("userPhone")) {
|
||||
await doLogout({
|
||||
financialAccount: Session.get("userPhone"),
|
||||
});
|
||||
}
|
||||
|
||||
Session.clear();
|
||||
|
||||
// 解构路由参数,排除token
|
||||
const { token, ...otherQuery } = route.query;
|
||||
// 若存在token,替换路由清除参数
|
||||
if (token) {
|
||||
router.replace({
|
||||
path: route.path, // 保持当前路径不变
|
||||
query: otherQuery, // 保留其他参数
|
||||
});
|
||||
}
|
||||
|
||||
nextTick(() => {
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
});
|
||||
}
|
||||
|
||||
onLoad((e) => {
|
||||
if (e.type) tabIndex.value = e.type;
|
||||
|
||||
console.log("🚀 ~ route.query.token:", route.query.token);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import { ref, onMounted, defineAsyncComponent, reactive } from "vue";
|
|||
import PageTop from "@/pages/realtimeInfo/pc/components/PageTop.vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const layoutName = ref();
|
||||
|
|
@ -21,7 +20,7 @@ onMounted(async () => {
|
|||
infoId.value = route.query.id;
|
||||
}
|
||||
// 如果过来的链接里有token说明是财保过来的
|
||||
console.log("🚀 ~ route.query:", route.query)
|
||||
console.log("🚀 ~ route.query:", route.query);
|
||||
|
||||
if (route.query.type) {
|
||||
switch (route.query.type) {
|
||||
|
|
@ -41,11 +40,7 @@ onMounted(async () => {
|
|||
case "3":
|
||||
layoutName.value = "top10";
|
||||
uni.navigateTo({
|
||||
url:
|
||||
"/pages/realtimeInfo/pc/top10?type=" +
|
||||
route.query.type +
|
||||
"&name=" +
|
||||
route.query.name,
|
||||
url: "/pages/realtimeInfo/pc/top10?type=" + route.query.type + "&name=" + route.query.name,
|
||||
});
|
||||
break;
|
||||
case "4":
|
||||
|
|
|
|||
|
|
@ -7,10 +7,14 @@
|
|||
<text class="pageTitle" v-if="pageType != 4">资讯头条榜</text>
|
||||
<text class="pageTitle" v-if="pageType == 4">编辑精选</text>
|
||||
<image src="@/assets/zixun/top20_icon.png" class="title_icon" v-if="pageType != 4"></image>
|
||||
<u-input v-if="pageType == 4" placeholder="请输入搜索内容" v-model="form.keyword" prefixIcon="search"
|
||||
<u-input
|
||||
v-if="pageType == 4"
|
||||
placeholder="请输入搜索内容"
|
||||
v-model="form.keyword"
|
||||
prefixIcon="search"
|
||||
prefixIconStyle="font-size: 22px;color: #909399"
|
||||
style="margin-left: 40rpx;margin-top: 5rpx;border-radius: 20rpx;">
|
||||
|
||||
style="margin-left: 40rpx; margin-top: 5rpx; border-radius: 20rpx"
|
||||
>
|
||||
<template #suffix>
|
||||
<u-button @tap="getNewsList" text="搜索" size="mini"></u-button>
|
||||
</template>
|
||||
|
|
@ -36,12 +40,8 @@
|
|||
<view class="item_bottom">
|
||||
<view>
|
||||
<text class="time">{{ item.source }}</text>
|
||||
<text class="time" style="margin-left: 30rpx" v-if="pageType != 4">{{
|
||||
dayjs(item.publish_time).format("YYYY-MM-DD HH:MM:ss")
|
||||
}}</text>
|
||||
<text class="time" style="margin-left: 30rpx" v-if="pageType == 4">{{
|
||||
item.time
|
||||
}}</text>
|
||||
<text class="time" style="margin-left: 30rpx" v-if="pageType != 4">{{ dayjs(item.publish_time).format("YYYY-MM-DD HH:MM:ss") }}</text>
|
||||
<text class="time" style="margin-left: 30rpx" v-if="pageType == 4">{{ item.time }}</text>
|
||||
</view>
|
||||
|
||||
<text class="score" v-if="pageType != 4">{{ item.news_score }}</text>
|
||||
|
|
@ -50,15 +50,24 @@
|
|||
</view>
|
||||
</view>
|
||||
|
||||
<div style="width: 100%;display: flex;justify-content: center;"
|
||||
v-if="pageType == 4 && newsList && newsList.length > 0">
|
||||
<el-pagination v-model:current-page="currentPage" :page-size="form.size" layout="prev, pager, next"
|
||||
:total="form.total" @current-change="currentChange" @size-change="sizeChange" />
|
||||
<div style="width: 100%; display: flex; justify-content: center" v-if="pageType == 4 && newsList && newsList.length > 0">
|
||||
<el-pagination
|
||||
v-model:current-page="currentPage"
|
||||
:page-size="form.size"
|
||||
layout="prev, pager, next"
|
||||
:total="form.total"
|
||||
@current-change="currentChange"
|
||||
@size-change="sizeChange"
|
||||
/>
|
||||
</div>
|
||||
|
||||
</view>
|
||||
<LoginPopup :show="LoginShow" mode="center" @handlePopupClose="handlePopupClose"
|
||||
@handlePopupSuccessCallback="handlePopupSuccessCallback" @handlePopupErrorCallback="handlePopupErrorCallback" />
|
||||
<LoginPopup
|
||||
:show="LoginShow"
|
||||
mode="center"
|
||||
@handlePopupClose="handlePopupClose"
|
||||
@handlePopupSuccessCallback="handlePopupSuccessCallback"
|
||||
@handlePopupErrorCallback="handlePopupErrorCallback"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
|
|
@ -78,7 +87,7 @@ const form = reactive({
|
|||
keyword: "",
|
||||
page: 1,
|
||||
size: 10,
|
||||
total: 10
|
||||
total: 10,
|
||||
});
|
||||
const currentPage = ref(form.page);
|
||||
|
||||
|
|
@ -88,19 +97,18 @@ const router = useRouter();
|
|||
const pageType = ref(route.query.type);
|
||||
const newsList = ref([]);
|
||||
|
||||
|
||||
async function getNewsList() {
|
||||
if (pageType.value == 4) {
|
||||
// 编辑精选
|
||||
let { code, data } = await editTopNews({
|
||||
...form
|
||||
...form,
|
||||
});
|
||||
if (code == 200) {
|
||||
newsList.value = data.list;
|
||||
form.total = data.total;
|
||||
data.list.forEach((item) => {
|
||||
item.summary = item.summary.replace(form.keyword, "<span style='color: #007aff'>" + form.keyword + '</span>');
|
||||
item.title = item.title.replace(form.keyword, "<span style='color: #007aff'>" + form.keyword + '</span>');
|
||||
item.summary = item.summary.replace(form.keyword, "<span style='color: #007aff'>" + form.keyword + "</span>");
|
||||
item.title = item.title.replace(form.keyword, "<span style='color: #007aff'>" + form.keyword + "</span>");
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
|
@ -110,11 +118,11 @@ async function getNewsList() {
|
|||
}
|
||||
|
||||
function goDetail(item) {
|
||||
let id = null
|
||||
let id = null;
|
||||
if (pageType.value != 4) {
|
||||
id = item.news_id
|
||||
id = item.news_id;
|
||||
} else {
|
||||
id = item.id
|
||||
id = item.id;
|
||||
}
|
||||
uni.navigateTo({
|
||||
url: "/pages/realtimeInfo/pc/indexPC?id=" + id + "&type=" + pageType.value,
|
||||
|
|
@ -127,24 +135,25 @@ function currentChange(page) {
|
|||
}
|
||||
|
||||
onMounted(async (e) => {
|
||||
|
||||
console.log("🚀 ~ route.query:", route.query)
|
||||
if (route.query?.token && !Session.get("token")) {
|
||||
console.log("🚀 ~ route.query:", route.query);
|
||||
if (route.query?.token && (!Session.get("token") || Session.get("token") == "undefined")) {
|
||||
uni.showLoading({
|
||||
title: '加载中',
|
||||
mask: true
|
||||
})
|
||||
title: "加载中",
|
||||
mask: true,
|
||||
});
|
||||
sendToken({
|
||||
token: route.query.token,
|
||||
}).then((res) => {
|
||||
uni.hideLoading()
|
||||
uni.hideLoading();
|
||||
if (res.code == 200) {
|
||||
Session.set("token", res.data.token);
|
||||
Session.set("userPhone", res.data.phone);
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
}
|
||||
})
|
||||
});
|
||||
} else {
|
||||
if (!Session.get("token")) {
|
||||
LoginShow.value = true;
|
||||
|
|
@ -152,8 +161,6 @@ onMounted(async (e) => {
|
|||
}
|
||||
|
||||
getNewsList();
|
||||
|
||||
|
||||
});
|
||||
|
||||
const LoginShow = ref(false);
|
||||
|
|
@ -293,7 +300,6 @@ const handlePopupErrorCallback = () => {
|
|||
color: #333333;
|
||||
margin-top: 20rpx;
|
||||
|
||||
|
||||
/* 必须:限制内容不溢出容器 */
|
||||
overflow: hidden;
|
||||
/* 必须:超出部分显示省略号 */
|
||||
|
|
|
|||
Loading…
Reference in New Issue