diff --git a/jiuyi2/App.vue b/jiuyi2/App.vue index f3d30422..a6c3fbda 100644 --- a/jiuyi2/App.vue +++ b/jiuyi2/App.vue @@ -1,60 +1,54 @@ - \ No newline at end of file diff --git a/jiuyi2/pages/news/newFriend.vue b/jiuyi2/pages/news/newFriend.vue index 5197222e..2ca8b227 100644 --- a/jiuyi2/pages/news/newFriend.vue +++ b/jiuyi2/pages/news/newFriend.vue @@ -3,6 +3,8 @@ * 新的朋友 */ + // 腾讯云聊天 + import TencentCloudChat from '@tencentcloud/chat'; // 工具库 import util from '@/common/js/util'; // api @@ -14,11 +16,12 @@ ref, reactive, computed, + getCurrentInstance, + nextTick } from 'vue' import { onLoad, - onReachBottom, - onPullDownRefresh + onUnload, } from '@dcloudio/uni-app' // vuex const store = useStore() @@ -34,73 +37,82 @@ pageSize: 10, total: 0, }) - const keyword = ref('') + // 需要操作的好友对象 + const friend = ref({}) + // + const { + proxy + } = getCurrentInstance() onLoad(() => { getFriendList() + addListener() }) - onPullDownRefresh(() => { - getFriendList() + onUnload(() => { + offListener() }) + // 开启监听 + function addListener() { + let fn = function(event) { + getFriendList() + } + + // 开启监听 + uni.$chat.on(TencentCloudChat.EVENT.FRIEND_APPLICATION_LIST_UPDATED, fn) + } + + // 移除监听 + function offListener() { + uni.$chat.off(TencentCloudChat.EVENT.FRIEND_APPLICATION_LIST_UPDATED, () => {}) + } + // 同意好友申请 function agreeFriend(item) { - api.video.agreeFriend({ - path: [userinfo.value.userId, item.userId], - query: { + friend.value = { + ...item + } + // 打开弹窗 + proxy.$refs.friend.open() + } - } + // 确定添加好友 + function addFriendConfirm() { + // 同意好友申请 + uni.$chat.acceptFriendApplication({ + userID: friend.value.userID, + remark: friend.value.remark || '', + type: TencentCloudChat.TYPES.SNS_APPLICATION_AGREE_AND_ADD }).then(rs => { - if (rs.code === 200) { - uni.showToast({ - title: '同意成功', - icon: 'success', - duration: 1500 - }); - } else { - uni.showToast({ - title: rs.msg, - icon: 'error', - duration: 1500 - }); - } - }).finally(() => { - + // 打开弹窗 + proxy.$refs.friend.close() }) } // 拒绝好友申请 function refuseFriend(item) { - api.video.refuseFriend({ - path: [userinfo.value.userId, item.userId], + util.alert({ + content: '确认拒绝好友?', }).then(rs => { - if (rs.code === 200) { - uni.showToast({ - title: '拒绝成功', - icon: 'success', - duration: 1500 - }); - } else { - uni.showToast({ - title: rs.msg, - icon: 'error', - duration: 1500 - }); - } + if (!rs.confirm) return + // 拒绝好友申请 + uni.$chat.refuseFriendApplication({ + userID: item.userID, + }) }) } - // 获取朋友列表 + // 获取添加朋友列表 function getFriendList() { uni.$chat.getFriendApplicationList().then(rs => { if (rs.code === 0) { - console.log('rs', rs) const result = rs.data - userList.data = result.friendApplicationList + userList.data = result.friendApplicationList.map(node => { + node.formatTime = util.formatTime('yyyy-MM-dd hh:mm', node.time) + return node + }) } - }).finally(() => { - uni.stopPullDownRefresh() }) } @@ -111,10 +123,22 @@ function handleUser(item) { uni.navigateTo({ url: util.setUrl('/pages/index/videoHome', { - userId: item.userId, + userId: item.userID, }) }) } + + // 填入对方昵称 + function pushNickname() { + friend.value.remark = friend.value.nick + } + + // 我的二维码 + function myQr() { + uni.navigateTo({ + url: '/pages/news/myQr' + }) + } @@ -170,4 +227,18 @@ border-top: 1rpx solid #ddd; } } + + // 朋友弹窗 + .friendAlt { + + // + .txtplus { + background-color: #eee; + } + + // + .push { + color: #20D200; + } + } \ No newline at end of file diff --git a/jiuyi2/pages/news/news.vue b/jiuyi2/pages/news/news.vue index 45d6679b..c141f0ba 100644 --- a/jiuyi2/pages/news/news.vue +++ b/jiuyi2/pages/news/news.vue @@ -84,39 +84,28 @@ // 打开菜单 function showActionSheet() { - /* { - // 拒绝私信 拒绝添加好友 - label: '公开设置', - } */ uni.showActionSheet({ - itemList: ['扫一扫', '添加好友', '发起群聊', '我的二维码', '设置'], + itemList: ['扫一扫', '添加好友', '发起群聊', '我的二维码'], success: rs => { switch (rs.tapIndex) { case 0: - uni.scanCode({ - success: (res) => { - console.log('扫描结果:' + res.result); - getUserInfos(res.result) - }, - fail: (err) => { - console.error('扫描失败:' + err); - uni.showToast({ - title: '扫描失败', - icon: 'none' - }); - } - }) + util.scan() break; case 1: uni.navigateTo({ - url: '/pages/news/addFriend' - // url: '/pages/news/newFriend' - }) + // url: '/pages/news/addFriend' + url: '/pages/news/newFriend' + }); break; case 2: uni.navigateTo({ url: '/pages/news/group-chat/index' - }) + }); + break; + case 3: + uni.navigateTo({ + url: '/pages/news/myQr' + }); break; default: break; diff --git a/jiuyi2/vite.config.js b/jiuyi2/vite.config.js index c1243afb..1debbd56 100644 --- a/jiuyi2/vite.config.js +++ b/jiuyi2/vite.config.js @@ -1,4 +1,3 @@ - import { defineConfig } from 'vite'; @@ -15,8 +14,8 @@ export default defineConfig({ changeOrigin: true, }, "/user": { - // target: "http://192.168.1.241:8080", - target: "http://7fee92ac.r22.cpolar.top", + target: "http://192.168.1.241:8080", + // target: "http://7fee92ac.r22.cpolar.top", changeOrigin: true, }, "/coreplay": { @@ -28,8 +27,8 @@ export default defineConfig({ changeOrigin: true, }, "/video": { - // target: "http://192.168.1.241:8080", - target: "http://7fee92ac.r22.cpolar.top", + target: "http://192.168.1.241:8080", + // target: "http://7fee92ac.r22.cpolar.top", changeOrigin: true, }, }