Files
tk-mini-program/components/tabBar/tabBar.vue

312 lines
7.0 KiB
Vue
Raw Normal View History

2025-05-12 21:23:37 +08:00
<template>
2025-05-13 16:03:28 +08:00
<view class="tab-block">
<ul
class="tab-list flex flex-center"
:class="showMiddleButton === true ? 'tab-list-middle' : 'tab-list-default'"
>
<li
v-for="(item, index) in tabList"
:class="'list-item flex flex-column flex-middle ' + item.middleClass"
@click="handlePush(item, index)"
:key="index"
>
<view class="item-img-box">
<image
class="item-img"
:src="tabIndex == index ? item.selectedIconPath : item.iconPath"
/>
2025-06-18 16:01:55 +08:00
<view class="Unreadcss" v-if="index === 3 && Unread > 0">{{ Unread > 99 ? '99+':Unread }}</view>
2025-05-13 16:03:28 +08:00
</view>
<view
class="item-text font-20"
:style="{ color: tabIndex == index ? '#1DD2F9' : '#A7A3A3' }"
>{{ item.text }}</view
>
</li>
</ul>
<view @touchmove.stop.prevent="disabledScroll"> </view>
2025-06-18 22:04:59 +08:00
<NewAddedPk class="createModule" ref="createModule" @publishSuccess="publishSuccesss"></NewAddedPk>
2025-05-13 16:03:28 +08:00
</view>
2025-05-12 21:23:37 +08:00
</template>
<script setup>
2025-06-10 23:06:51 +08:00
import NewAddedPk from "../../pages/NewAddedPk/NewAddedPk.vue";
import VerifyLogin from "../VerifyLogin.js";
2025-06-17 22:04:18 +08:00
import { getCurrentInstance, defineProps, onMounted,onUnmounted,reactive, ref } from "vue";
import { TUIStore,StoreName } from '@tencentcloud/chat-uikit-engine';
2025-06-18 16:01:55 +08:00
require.async('../../TUIKit/components/TUIConversation/entry.js');
2025-05-13 16:03:28 +08:00
let showMiddleButton = ref(false);
2025-06-17 22:04:18 +08:00
const conversationList = ref([]);
2025-06-18 16:01:55 +08:00
let Unread = ref(0);
// 监听会话列表变化
2025-06-17 22:04:18 +08:00
onMounted(() => {
TUIStore.watch(StoreName.CONV, {
conversationList: onConversationListUpdated,
});
});
//conversationList[0].unreadCount
2025-06-18 16:01:55 +08:00
// 组件销毁时取消监听
2025-06-17 22:04:18 +08:00
onUnmounted(() => {
TUIStore.unwatch(StoreName.CONV, {
conversationList: onConversationListUpdated,
});
});
2025-06-18 16:01:55 +08:00
// 监听会话列表变化
2025-06-17 22:04:18 +08:00
function onConversationListUpdated(list) {
conversationList.value = list;
2025-06-18 16:01:55 +08:00
Unread.value = calculateUnreadCount(list);
2025-06-17 22:04:18 +08:00
}
2025-06-18 22:04:59 +08:00
const emit = defineEmits(['publishSucces']);
function publishSuccesss() {
emit('publishSucces');
}
2025-06-18 16:01:55 +08:00
// 计算未读消息总数
function calculateUnreadCount(arr) {
let total = 0;
for (const item of arr) {
// 检查对象是否包含 unreadCount 属性
if (!item.hasOwnProperty('unreadCount')) {
return null;
}
const count = item.unreadCount;
// 检查值是否为有效数值类型
if (typeof count !== 'number' || !Number.isFinite(count)) {
return null;
}
total += count;
}
return total;
}
2025-05-13 16:03:28 +08:00
const props = defineProps({
tabIndex: Number,
});
let tabList = reactive([
{
2025-06-10 23:06:51 +08:00
iconPath: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Pk.png",
2025-06-11 22:16:44 +08:00
selectedIconPath: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/PKClick.png",
2025-05-13 16:03:28 +08:00
text: "PK",
2025-05-14 16:09:14 +08:00
pagePath: "/pages/Home/Home",
2025-05-13 16:03:28 +08:00
middleClass: "",
},
{
2025-06-10 23:06:51 +08:00
iconPath: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Forum.png",
selectedIconPath: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Forumclick.png",
2025-06-24 14:46:01 +08:00
text: "站内信",
2025-06-06 22:36:41 +08:00
pagePath: "/pages/Forum/Forum",
2025-05-13 16:03:28 +08:00
middleClass: "",
},
{
2025-06-10 23:06:51 +08:00
iconPath: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/jiahao.png",
selectedIconPath: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/jiahao.png",
2025-05-13 16:03:28 +08:00
text: "",
pagePath: "/pages/c/c",
middleClass: "",
},
{
2025-06-10 23:06:51 +08:00
iconPath: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Message.png",
selectedIconPath: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Messageclick.png",
2025-05-13 16:03:28 +08:00
text: "消息",
},
{
2025-06-10 23:06:51 +08:00
iconPath: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Mine.png",
selectedIconPath: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Mineclick.png",
2025-05-13 16:03:28 +08:00
text: "我的",
2025-05-20 00:10:07 +08:00
pagePath: "/pages/Mine/Mine",
2025-05-13 16:03:28 +08:00
middleClass: "",
},
]);
onMounted(() => {
setTabBar();
// getSystemInfo()
});
uni.getSystemInfo({
success: function (res) {
if (res.safeArea.top > 40) {
}
},
});
//判断中间按钮是否突出显示
function setTabBar() {
let tabLength = tabList.length;
if (tabLength % 2) {
showMiddleButton.value = true;
let middleIndex = Math.floor(tabLength / 2);
tabList[middleIndex].middleClass = "mid-button";
}
}
2025-06-10 23:06:51 +08:00
const createModule = ref();
2025-05-13 16:03:28 +08:00
2025-06-10 23:06:51 +08:00
function openPopupQuantity() {
createModule.value.open();
}
2025-05-13 16:03:28 +08:00
//组件返回关闭指令
function closeSuccess() {
// addSuccess.value.close();
}
//解决弹出层后页面还可以滚动
const disabledScroll = () => {
return false;
};
//tab点击事件
function handlePush(item, index) {
2025-06-10 23:06:51 +08:00
if (index === 3) {
VerifyLogin().then((res) => {
if (res) {
2025-06-12 22:16:09 +08:00
uni.redirectTo({
2025-06-10 23:06:51 +08:00
url: "/TUIKit/components/TUIConversation/index",
animationType: "none",
});
}
});
} else if (index === 2) {
//打开弹窗
VerifyLogin().then((res) => {
if (res) {
openPopupQuantity();
return;
}
});
} else if (index === 4) {
VerifyLogin().then((res) => {
if (res) {
uni.switchTab({
url: "/pages/Mine/Mine",
animationType: "none",
});
}
});
} else {
2025-05-13 16:03:28 +08:00
uni.switchTab({
url: item.pagePath,
});
}
}
2025-05-12 21:23:37 +08:00
</script>
<style lang="scss" scoped>
2025-05-13 16:03:28 +08:00
.flex {
display: flex;
flex-flow: row wrap;
}
.flex-center {
align-items: center;
justify-content: center;
}
.flex-column {
flex-direction: column;
align-items: center;
}
.flex-middle {
align-items: center;
}
.font-20 {
font-size: 20rpx;
}
.tab-block {
position: relative;
position: fixed;
bottom: 0;
2025-06-12 22:16:09 +08:00
z-index: 2;
2025-05-13 16:03:28 +08:00
background-size: contain;
width: 100vw;
background-color: #ffffff;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
.tab-list {
height: 100rpx;
padding: 0; //解决偏移
z-index: 0;
}
2025-06-10 23:06:51 +08:00
.createModule {
2025-05-21 17:03:19 +08:00
position: fixed;
bottom: 0;
right: 0;
z-index: 998;
width: 100vw;
}
2025-05-13 16:03:28 +08:00
.tab-list-default {
background-color: #ffffff;
border-top: 1px #dddddd solid;
}
.tab-list-middle {
position: relative;
background-size: cover;
}
.list-item {
flex: 1;
.item-img-box {
width: 38rpx;
height: 38rpx;
margin-bottom: 9rpx;
position: relative;
}
.item-img {
// width: 44rpx;
// height: 42rpx;
width: 38rpx;
height: 38rpx;
color: red;
}
}
.mid-button {
position: relative;
.item-img-box {
width: 150rpx;
height: 150rpx;
margin-bottom: 9rpx;
position: absolute;
z-index: 10;
top: -104rpx;
}
.item-img {
width: 150rpx;
height: 150rpx;
}
.item-text {
font-size: 20rpx;
position: absolute;
z-index: 1002;
bottom: -40rpx;
color: #393a41;
}
}
.tab-bar {
height: 30rpx;
background-color: #ffffff;
}
}
2025-06-18 16:01:55 +08:00
.Unreadcss{
2025-06-18 22:04:59 +08:00
position: absolute;
2025-06-18 16:01:55 +08:00
background-color: #ff0000;
margin-top: -65rpx;
width: 30rpx;
height: 30rpx;
border-radius: 50%;
text-align: center;
font-weight: bold;
font-size: 18rpx;
color: #ffffff;
line-height: 30rpx;
margin-left: 30rpx;
z-index: 1001;
}
2025-05-13 16:03:28 +08:00
</style>