diff --git a/.DS_Store b/.DS_Store index 29b9dbd..0dbc7d9 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/apis/interfaces/im.js b/apis/interfaces/im.js index e760bc9..a251af5 100644 --- a/apis/interfaces/im.js +++ b/apis/interfaces/im.js @@ -7,8 +7,8 @@ import store from '@/store' import { request -} from '../index' - +} from '../index' + // 获取好友列表 const getFriends = () => { return request({ @@ -92,62 +92,17 @@ const pedingFriend = (recipient) => { }) } -/** - * 好友申请数量 - */ -const getPendingCount = () => { +// 以下是群组相关业务的接口 +const getMyGroups = () => { return request({ - url: 'im/friends/pending/count' - }) -} - -/** - * 上传聊天附件 - * 图片 - * 语音 - * 视频 - */ -// 基础配置 -const config = { - apiUrl: 'http://api.zh.shangkelian.cn/api/', // 正式环境 - timeout: 60000 -} - -const uploadMessageFile = (file, type) => { - config.header = { - 'Accept': 'application/json', - 'Authorization': store.getters.getToken || '' - } - return new Promise((resolve, reject) => { - uni.uploadFile({ - url: config.apiUrl + 'im/upload', - filePath: file, - name: 'upload', - formData: { - type - }, - header: config.header || {}, - success: (res) => { - if (res.statusCode === 200) { - let updData = JSON.parse(res.data) - if (updData.status_code === 200) { - resolve(updData.data) - } else { - reject(updData) - } - } - }, - fail: (err) => { - console.log('ERR', err); - } - }) + url: 'im/groups' }) } export { getImToken, deleteFriend, - getFriends, + getFriends, getFriendsLetter, getUserInfo, getFriendInfo, @@ -156,6 +111,5 @@ export { rejectFriend, searchFriend, pedingFriend, - getPendingCount, - uploadMessageFile + getMyGroups } diff --git a/pages.json b/pages.json index 0918bda..baf22cd 100644 --- a/pages.json +++ b/pages.json @@ -373,6 +373,15 @@ "navigationStyle": "custom" } }, + { + "path": "pages/im/private/chat", + "style": { + "disableScroll": true, + "navigationBarTitleText": "聊天", + "enablePullDownRefresh": false, + "navigationBarBackgroundColor": "#F3F6FB" + } + }, { "path": "pages/im/private/call", "name": "imPrivateCall", @@ -431,13 +440,56 @@ "navigationBarTextStyle": "white" } }, + { + "path": "pages/im/group/index", + "name": "imGroups", + "style": { + "navigationBarTitleText": "我的群聊", + "app-plus": { + "titleNView": { + "type": "default", + "buttons": [{ + "float": "right", + "fontSrc": "/static/iconfont.ttf", + "text": "\ue60a", + "fontSize": "20px" + }] + } + } + } + }, { "path": "pages/im/group/chat", "name": "imGroupChat", "style": { - "navigationBarTitleText": "我的群聊" + "navigationBarTitleText": "群聊", + "app-plus": { + "titleNView": { + "type": "default", + "buttons": [{ + "float": "right", + "fontSrc": "/static/iconfont.ttf", + "text": "\ue607", + "fontSize": "20px" + }] + } + } } }, + { + "path": "pages/im/group/info", + "name": "imGroupInfo", + "style": { + "navigationBarTitleText": "群信息" + } + }, + { + "path": "pages/im/group/create", + "name": "imGroupCreate", + "style": { + "navigationBarTitleText": "创建群聊" + } + }, { "path": "pages/wallet/add", "name": "WalletAdd", @@ -548,14 +600,6 @@ "navigationBarBackgroundColor": "#34CE98", "navigationBarTextStyle": "white" } - }, { - "path": "pages/im/private/chat", - "style": { - "disableScroll": true, - "navigationBarTitleText": "聊天", - "enablePullDownRefresh": false, - "navigationBarBackgroundColor": "#F3F6FB" - } } ], "tabBar": { diff --git a/pages/im/components/conversationGroup.vue b/pages/im/components/conversationGroup.vue deleted file mode 100644 index 6e7d222..0000000 --- a/pages/im/components/conversationGroup.vue +++ /dev/null @@ -1,156 +0,0 @@ - - - - - diff --git a/pages/im/components/conversationPrivate.vue b/pages/im/components/conversationList.vue similarity index 89% rename from pages/im/components/conversationPrivate.vue rename to pages/im/components/conversationList.vue index eec0df9..cf3eeca 100644 --- a/pages/im/components/conversationPrivate.vue +++ b/pages/im/components/conversationList.vue @@ -18,8 +18,8 @@ + + diff --git a/pages/im/group/index.nvue b/pages/im/group/index.nvue new file mode 100644 index 0000000..2a836ff --- /dev/null +++ b/pages/im/group/index.nvue @@ -0,0 +1,79 @@ + + + + + diff --git a/pages/im/group/info.nvue b/pages/im/group/info.nvue new file mode 100644 index 0000000..6f021b8 --- /dev/null +++ b/pages/im/group/info.nvue @@ -0,0 +1,33 @@ + + + + + diff --git a/pages/im/index.vue b/pages/im/index.vue index a260de3..8ac9edb 100644 --- a/pages/im/index.vue +++ b/pages/im/index.vue @@ -5,20 +5,13 @@ - - 私聊 - - - - 群聊 - - + 聊聊 - + @@ -28,10 +21,7 @@ - - + @@ -48,26 +38,20 @@ import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index' import im from '@/utils/im/index.js' import userAuth from '@/public/userAuth' - import conversationPrivate from './components/conversationPrivate' - import conversationGroup from './components/conversationGroup' + import conversationList from './components/conversationList' export default { data() { return { - showType: 1, // 0 单聊,1 群聊 conversations: [], // 会话列表 - groupConversations: [], connection: 0, - privateUnread: 0, - groupUnread: 0, hasNewFriends: 0 } }, components: { - conversationPrivate, - conversationGroup + conversationList }, - onLoad() { + onLoad() { // 好友申请数量 this.checkNewFriendPending() uni.$on('onConnectionStatusChange', (status) => { @@ -75,50 +59,19 @@ }) uni.$on('onContactNotification', this.checkNewFriendPending) }, - onShow() { + onShow() { if (this.$store.state.token !== '') { - this.getPrivateConversationList() - this.getGroupConversationList() - } - - console.log('开始监听'); + this.getConversationList() + } // 监听新消息 - uni.$on('onReceivePrivateMessage', (msg) => { - this.getPrivateConversationList() - }) - uni.$on('onReceiveGroupMessage', (msg) => { - this.getGroupConversationList() - }) + uni.$on('onReceiveMessage', (msg) => { + this.getConversationList() + }) }, onHide() { - uni.$off('onReceivePrivateMessage') - uni.$off('onReceiveGroupMessage') - console.log('index 隐藏'); - }, - onNavigationBarButtonTap(e) { - if (e.index == 0) { - uni.showToast({ - title: '开发中暂未开放,敬请期待', - icon: 'none' - }) - } - if (e.index == 1) { - if (this.toLogin()) { - this.$Router.push({ - name: 'imFriends' - }) - } - } + uni.$off('onReceiveMessage') }, methods: { - showPrivate() { - console.log('切换到单聊'); - this.showType = 0 - }, - showGroup() { - console.log('切换到群聊'); - this.showType = 1 - }, checkNewFriendPending() { // 获取是否有新的好友申请 RongIMLib.getConversationList([RongIMLib.ConversationType.SYSTEM], 1000, 0, (res) => { @@ -139,41 +92,16 @@ return true }, // 获取私聊的会话列表 - getPrivateConversationList() { + getConversationList() { const count = 1000 const timestamp = 0 - RongIMLib.getConversationList([RongIMLib.ConversationType.PRIVATE], count, timestamp, (res) => { + RongIMLib.getConversationList([1, 3], count, timestamp, (res) => { if (res.code === 0) { this.conversations = res.conversations + console.log(res.conversations); } }) }, - // 获取群组会话列表 - getGroupConversationList() { - const count = 1000 - const timestamp = 0 - RongIMLib.getConversationList([RongIMLib.ConversationType.GROUP], count, timestamp, (res) => { - if (res.code === 0) { - this.groupConversations = res.conversations - } - }) - }, - // 点击按钮 - onNav(name, params) { - if (this.toLogin) { - if (name === '') { - uni.showToast({ - title: '开发中,敬请期待', - icon: 'none' - }) - return - } - this.$Router.push({ - name, - params - }) - } - }, // 调起扫码 scanQrCode() { uni.scanCode({ @@ -186,62 +114,17 @@ } } }) + }, + toFriendList() { + uni.navigateTo({ + url: '/pages/im/friends/index' + }) } } }