From be1027eb38aef056e566849d1f55ab88759eda72 Mon Sep 17 00:00:00 2001 From: sx <2427911852@qq.com> Date: Mon, 6 Jan 2025 09:45:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jiuyi2/App.vue | 3 +- jiuyi2/api/news.js | 1 + jiuyi2/common/js/util.js | 12 +++-- jiuyi2/components/news/book.vue | 32 ++++++++++-- jiuyi2/pages/news/news.vue | 90 ++++++++++++++++++--------------- jiuyi2/vite.config.js | 8 +-- 6 files changed, 92 insertions(+), 54 deletions(-) diff --git a/jiuyi2/App.vue b/jiuyi2/App.vue index 828b95d3..98b15d27 100644 --- a/jiuyi2/App.vue +++ b/jiuyi2/App.vue @@ -32,7 +32,8 @@ }) // 腾讯im登录 - // util.loginTencent(userinfo) + util.loginTencent(userinfo) + // util.getUserinfo() } } diff --git a/jiuyi2/api/news.js b/jiuyi2/api/news.js index b6611e7a..ca4d5d58 100644 --- a/jiuyi2/api/news.js +++ b/jiuyi2/api/news.js @@ -128,6 +128,7 @@ export const news = { query: param }) }, + //获取好友列表 getFriendList() { return util.request({ diff --git a/jiuyi2/common/js/util.js b/jiuyi2/common/js/util.js index c65b5683..9cf01232 100644 --- a/jiuyi2/common/js/util.js +++ b/jiuyi2/common/js/util.js @@ -1445,13 +1445,16 @@ const util = { // 登录腾讯聊天 loginTencent(userinfo) { api.login.getIMToken({}).then(rs => { + // + const imSig = rs.msg + + // #ifdef APP + // 音视频登录 const loginParams = { SDKAppID: util.config.TChat.SDKAppID, userID: userinfo.id + '', - userSig: rs.msg, + userSig: imSig, } - - // #ifdef APP uni.$TUICallKit.login(loginParams, res => { if (res.code === 0) { console.log('[TUICallKit] login success.'); @@ -1463,7 +1466,7 @@ const util = { uni.$chat.login({ userID: userinfo.id + '', - userSig: rs.msg, + userSig: imSig, }).then(rs => { console.log('im login success', rs) }) @@ -1480,6 +1483,7 @@ const util = { api.mine.getUserinfo().then(rs => { if (rs.code === 200) { reslove(rs.data) + const userinfo = rs.data // 提交 store.commit('setState', { key: 'userinfo', diff --git a/jiuyi2/components/news/book.vue b/jiuyi2/components/news/book.vue index ebe2462e..a7193767 100644 --- a/jiuyi2/components/news/book.vue +++ b/jiuyi2/components/news/book.vue @@ -18,7 +18,10 @@ import util from '@/common/js/util.js' // 腾讯云聊天 import TencentCloudChat from '@tencentcloud/chat'; + // import api from '@/api/index.js' + // api + import newsApi from '@/api/news.js' import pinyin from 'js-pinyin' const { proxy @@ -191,6 +194,8 @@ removelistener() }) + const viewData = ref([]) + // 添加加好友监听 function addlistener() { let onFriendListUpdated = (event) => { @@ -209,14 +214,30 @@ function getFriendList() { // 验证sdk是否准备完毕 let isReady = uni.$chat.isReady(); + console.log('isReady', isReady) if (!isReady) { setTimeout(function() { getFriendList() - }, 200); + }, 1000); return } + newsApi.getFriendList().then(rs => { + if (rs.code == 200) { + viewData.value = rs.data; + // 这里可以将好友列表传递给book组件进行展示 + console.log('好友列表:', viewData.value); + return + } + util.alert({ + content: rs.msg, + showCancel: false, + }) + }) + + return + uni.$chat.getFriendList().then(rs => { console.log('friend', rs) if (rs.code == 0) { @@ -376,7 +397,8 @@ {{ item.letter }} - + {{user.remark || user.profile.nick}} @@ -391,8 +413,10 @@ - - {{ item.name }} + + {{ item.name }} diff --git a/jiuyi2/pages/news/news.vue b/jiuyi2/pages/news/news.vue index 0505be54..bff601c6 100644 --- a/jiuyi2/pages/news/news.vue +++ b/jiuyi2/pages/news/news.vue @@ -13,7 +13,10 @@ } from 'vuex' import { onLoad, + onUnload, } from '@dcloudio/uni-app' + // 腾讯云聊天 + import TencentCloudChat from '@tencentcloud/chat'; // 头部导航栏 import apex from '@/components/header/apex' @@ -27,12 +30,9 @@ import msgList from '@/components/news/msgList' // 底部菜单 import footerMneu from '@/components/footerMenu/footerMenu' - import videoApi from '@/api/video.js'; - // 工具库 - import util from '@/common/js/util.js' - // api - import newsApi from '@/api/news.js' - // vuex + // 工具库 + import util from '@/common/js/util.js' + // vuex const store = useStore() // 菜单列表 const menuList = reactive([{ @@ -60,51 +60,55 @@ const menuIndex = ref('') // 是否显示搜索菜单 const showSearch = ref(false) + // im加载 + const imLoad = ref(false) // 用户信息 const userinfo = computed(() => { - let result = store.state.userinfo - return result + return store.state.userinfo }) // 当前选中的菜单 const menuCurrent = computed(() => { - let result = menuList[menuIndex.value] - return result + return menuList[menuIndex.value] }) onLoad(() => { // 初始化菜单 - handleMenuIndex(2) + handleMenuIndex(0) + + // 开启监听 + addListener() }) - /** - * 切换下标 - * @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, - }) - }) - } + onUnload(() => { + // 移除监听 + removeListener() + }) + + // 开启监听 + function addListener() { + uni.$chat.on(TencentCloudChat.EVENT.SDK_READY, imLoading); + } + + // im加载完成 + function imLoading() { + imLoad.value = true + } + + // 移除监听 + function removeListener() { + uni.$chat.off(TencentCloudChat.EVENT.SDK_READY); + } + + /** + * 切换下标 + * @param {Number} index + */ + function handleMenuIndex(index) { + if (menuIndex.value === index) return + menuIndex.value = index + if (!menuList[index].load) menuList[index].load = true + } + // 打开菜单 function showActionSheet() { uni.showActionSheet({ @@ -155,10 +159,14 @@