jiuyiUniapp/jiuyi2/pages/news/news.vue

290 lines
5.9 KiB
Vue
Raw Normal View History

2024-12-18 15:46:27 +08:00
<script setup>
/**
* 消息
*/
import {
ref,
reactive,
computed,
} from 'vue'
import {
useStore,
} from 'vuex'
import {
onLoad,
} from '@dcloudio/uni-app'
// 头部导航栏
import apex from '@/components/header/apex'
// 未登录
import noLogin from '@/components/login/noLogin.vue'
// 通讯录
import book from '@/components/news/book'
// 群聊列表
import groupList from '@/components/news/groupList'
// 消息列表
import msgList from '@/components/news/msgList'
// 底部菜单
import footerMneu from '@/components/footerMenu/footerMenu'
import videoApi from '@/api/video.js';
2025-01-05 23:03:28 +08:00
// 工具库
import util from '@/common/js/util.js'
// api
import newsApi from '@/api/news.js'
// vuex
2024-12-18 15:46:27 +08:00
const store = useStore()
// 菜单列表
const menuList = reactive([{
key: 'friend',
2024-12-27 15:03:48 +08:00
name: '通讯录',
2024-12-18 15:46:27 +08:00
load: false,
},
{
key: 'group',
2024-12-27 15:03:48 +08:00
name: '即时消息',
2024-12-18 15:46:27 +08:00
load: false,
},
{
key: 'video',
name: '视讯消息',
load: false,
},
2024-12-27 15:03:48 +08:00
{
key: 'video',
name: '商城消息',
load: false,
},
2024-12-18 15:46:27 +08:00
])
// 菜单下标
const menuIndex = ref('')
// 是否显示搜索菜单
const showSearch = ref(false)
// 用户信息
const userinfo = computed(() => {
let result = store.state.userinfo
return result
})
// 当前选中的菜单
const menuCurrent = computed(() => {
let result = menuList[menuIndex.value]
return result
})
onLoad(() => {
// 初始化菜单
handleMenuIndex(2)
})
2025-01-05 23:03:28 +08:00
/**
* 切换下标
* @param {Number} index
*/
function handleMenuIndex(index) {
if (menuIndex.value === index) return
menuIndex.value = index
if (!menuList[index].load) menuList[index].load = true
// 点击通讯录时调用获取好友列表的函数
if (index === 0) {
getFriends();
}
}
const viewData = ref([])
// 获取好友列表
function getFriends() {
newsApi.getFriendList().then(response => {
if (response.success) {
viewData.value = response.data;
// 这里可以将好友列表传递给book组件进行展示
console.log('好友列表:', viewData.value);
return
}
util.alert({
content: rs.msg,
showCancel: false,
})
})
}
2024-12-18 15:46:27 +08:00
// 打开菜单
function showActionSheet() {
uni.showActionSheet({
2025-01-05 20:06:22 +08:00
itemList: ['扫一扫', '添加好友', '发起群聊', '我的二维码'],
2024-12-18 15:46:27 +08:00
success: rs => {
switch (rs.tapIndex) {
case 0:
2025-01-05 20:06:22 +08:00
util.scan()
2024-12-18 15:46:27 +08:00
break;
case 1:
uni.navigateTo({
2025-01-05 20:06:22 +08:00
// url: '/pages/news/addFriend'
url: '/pages/news/newFriend'
});
2024-12-18 15:46:27 +08:00
break;
case 2:
uni.navigateTo({
url: '/pages/news/group-chat/index'
2025-01-05 20:06:22 +08:00
});
break;
case 3:
uni.navigateTo({
url: '/pages/news/myQr'
});
2024-12-18 15:46:27 +08:00
break;
default:
break;
}
}
})
}
function getUserInfos(userRecommend) {
videoApi.getUserInfo({
query: {
userRecommend: userRecommend,
}
}).then(rs => {
if (rs.data !== null) {
uni.navigateTo({
2024-12-27 15:03:48 +08:00
url: '/pages/index/beInvited?header=' + rs.data.userPortrait + '&userId=' + rs.data
.userId + '&userNickname=' +
2024-12-18 15:46:27 +08:00
rs.data.userNickname
});
}
})
}
</script>
<template>
2024-12-27 15:03:48 +08:00
<view class="page" v-if="!userinfo.id && 0">
2024-12-18 15:46:27 +08:00
<noLogin class="f1" />
</view>
<view class="page" v-else>
<apex>
<template #left>
<view></view>
</template>
<template #content>
<!-- <view class="ver">
<image class="wh30" src="/static/read.png" mode="aspectFit" />
<text class="f20">一键已读</text>
</view> -->
</template>
<template #right>
<uni-icons type="bars" size="40rpx" @click="showActionSheet" />
</template>
</apex>
<view class="searchBox" :class="{ 'active': showSearch }">
<view class="search rows mt20 mlr20 ptb10 plr30 bfff bar">
<uni-icons type="search" />
<input type="text" placeholder="搜索" class="f1 ml10" confirm-type="search" />
</view>
</view>
<!-- 顶部菜单 -->
<view class="headMenu f24">
2024-12-27 15:03:48 +08:00
<view class="option oh df" v-for="(item, index) in menuList" :key="item.key"
:class="[item.key, { 'active': index === menuIndex }]" @click="handleMenuIndex(index)">
2024-12-18 15:46:27 +08:00
<view class="f1 fmid">{{ item.name }}</view>
</view>
</view>
<!-- 轮播图 -->
<swiper class="swiper" :current="menuIndex" disable-touch="true">
<!-- 通讯录 -->
<swiper-item>
<book v-if="menuList[0].load" />
<view class="loading" v-else>正在加载</view>
</swiper-item>
2024-12-27 15:03:48 +08:00
2024-12-18 15:46:27 +08:00
<!-- 群组 -->
<swiper-item>
<groupList v-if="menuList[1].load" />
<view class="loading" v-else>正在加载</view>
</swiper-item>
2024-12-27 15:03:48 +08:00
2024-12-18 15:46:27 +08:00
<!-- 视频消息 -->
<swiper-item>
<msgList v-if="menuList[2].load" />
<view class="loading" v-else>正在加载</view>
</swiper-item>
2024-12-27 15:03:48 +08:00
2024-12-18 15:46:27 +08:00
<!-- 商城消息 -->
<swiper-item>
<msgList />
</swiper-item>
</swiper>
</view>
2024-12-27 15:03:48 +08:00
<!-- 底部导航 -->
<footerMenu ref="footerMneuRef" page="news" />
2024-12-18 15:46:27 +08:00
</template>
<style lang="scss" scoped>
2025-01-05 23:03:28 +08:00
//
2024-12-18 15:46:27 +08:00
.headMenu {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 25rpx;
margin: 20rpx;
// 单项
.option {
height: 120rpx;
background-color: #E2E2E2;
border-radius: 15rpx;
transition: .3s;
// 激活的
&.active {
color: #fff;
// 朋友
&.friend,
&.group,
&.video {
background-image: linear-gradient(126deg, #27EFE2 0%, #A45EFF 43%, #FF004F 100%);
}
// 商城消息
&.store {
background-image: linear-gradient(270deg, #FF9B27 20%, #FDC123 103%);
}
}
}
// 卡通
.cartoon {
margin-top: -15rpx;
margin-right: -25rpx;
width: 194rpx;
height: 175rpx;
transform: rotate(-5deg);
}
}
// 搜索条
.searchBox {
overflow: hidden;
height: 0;
transition: .3s;
&.active {
height: 80rpx;
}
}
2025-01-05 23:03:28 +08:00
//
2024-12-18 15:46:27 +08:00
.swiper {
flex: 1;
}
// 正在加载
.loading {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
</style>