diff --git a/App.vue b/App.vue index c8dffaf6..491a1ce9 100644 --- a/App.vue +++ b/App.vue @@ -6,6 +6,8 @@ let msgType = require("./components/chat/msgtype"); let disp = require("./utils/broadcast"); let logout = false; +import { onGetSilentConfig } from './components/chat/pushStorage' + function ack(receiveMsg) { // 处理未读消息回执 var bodyId = receiveMsg.id; // 需要发送已读回执的消息id @@ -36,6 +38,8 @@ function getCurrentRoute() { return "/"; } + + // // 不包含陌生人版本(不接收陌生人消息) // function calcUnReadSpot(message) { // let myName = uni.getStorageSync("myUsername"); @@ -63,6 +67,8 @@ function getCurrentRoute() { // 包含陌生人版本 function calcUnReadSpot(message) { let myName = uni.getStorageSync("myUsername"); + let pushObj = uni.getStorageSync("pushStorageData") + let pushAry = pushObj[myName] || [] uni.getStorageInfo({ success: function (res) { let storageKeys = res.keys; @@ -74,11 +80,12 @@ function calcUnReadSpot(message) { } }); let count = newChatMsgKeys.reduce(function (result, curMember, idx) { + let newName = curMember.split(myName)[0] let chatMsgs; chatMsgs = uni.getStorageSync(curMember) || []; + if (pushAry.includes(newName)) return result return result + chatMsgs.length; }, 0); - getApp().globalData.unReadMessageNum = count; disp.fire("em.unreadspot", message); }, @@ -242,6 +249,8 @@ export default { }); me.globalData.conn.closed = true; WebIM.conn.close(); + // uni.removeStorageSync('pushStorageData'); + // uni.clearStorageSync(); }, onInviteMessage(message) { @@ -263,7 +272,6 @@ export default { //onPresence为旧版 ,建议参考最新增删好友api文档 :http://docs-im.easemob.com/im/web/basics/buddy onPresence(message) { - switch (message.type) { case "unsubscribe": break; @@ -276,7 +284,7 @@ export default { return; } } - msgStorage.saveReceiveMsg(message, 'INFORM'); //存添加好友消息,方便展示通知 + msgStorage.saveReceiveMsg(message, "INFORM"); //存添加好友消息,方便展示通知 me.globalData.saveFriendList.push(message); disp.fire("em.subscribe"); @@ -309,16 +317,20 @@ export default { break; case "invite": // 防止重复添加 - for (let i = 0; i < me.globalData.saveGroupInvitedList.length; i++) { + for ( + let i = 0; + i < me.globalData.saveGroupInvitedList.length; + i++ + ) { if (me.globalData.saveGroupInvitedList[i].from === message.from) { me.globalData.saveGroupInvitedList[i] = message; - disp.fire("em.invite.joingroup") + disp.fire("em.invite.joingroup"); return; } } me.globalData.saveGroupInvitedList.push(message); disp.fire("em.invite.joingroup"); - msgStorage.saveReceiveMsg(message, 'INFORM'); //存添加好友消息,方便展示通知 + msgStorage.saveReceiveMsg(message, "INFORM"); //存添加好友消息,方便展示通知 break; case "unavailable": disp.fire("em.contacts.remove"); @@ -358,6 +370,7 @@ export default { calcUnReadSpot(message); ack(message); + onGetSilentConfig(message); }, onAudioMessage(message) { @@ -370,6 +383,7 @@ export default { calcUnReadSpot(message); ack(message); + onGetSilentConfig(message); } }, @@ -383,6 +397,7 @@ export default { calcUnReadSpot(message); ack(message); + onGetSilentConfig(message); } }, @@ -402,6 +417,7 @@ export default { calcUnReadSpot(message); ack(message); + onGetSilentConfig(message); } }, @@ -415,6 +431,7 @@ export default { calcUnReadSpot(message); ack(message); + onGetSilentConfig(message); } }, @@ -428,6 +445,7 @@ export default { calcUnReadSpot(message); ack(message); + onGetSilentConfig(message); } }, @@ -441,6 +459,7 @@ export default { calcUnReadSpot(message); ack(message); + onGetSilentConfig(message); } }, diff --git a/components/chat/pushStorage.js b/components/chat/pushStorage.js new file mode 100644 index 00000000..2c9468f2 --- /dev/null +++ b/components/chat/pushStorage.js @@ -0,0 +1,45 @@ + +var WebIM = require("../../utils/WebIM")["default"]; +export function pushStorageSave(data) { + // JSON.parse(uni.getStorageSync("pushStorageData")) || + let currentLoginUser = WebIM.conn.context.userId + let newObj = uni.getStorageSync("pushStorageData") || {}; + let newAry = newObj[currentLoginUser] || []; + const { userId, type } = data; + if (!newAry.includes(userId) && type === "add") { + newAry = newAry.concat(userId); + } else if (newAry.includes(userId) && type === "remove") { + newAry = newAry.filter(item => item !== userId); + } + newObj[currentLoginUser] = newAry; + uni.setStorage({ + key: 'pushStorageData', + data: newObj, + success: function (params) { + console.log('uni.setStorage>>>', uni.getStorageSync("pushStorageData")); + } + }); +}; + +export function onGetSilentConfig(message) { + const currentLoginUser = WebIM.conn.context.userId; + const { from, to, type } = message; + let pushObj = uni.getStorageSync('pushStorageData') || {}; + let pushAry = pushObj[currentLoginUser] || []; + const option = { + conversationId: type === "chat" ? from : to, + type: type === "chat" ? "singleChat" : "groupChat", + }; + WebIM.conn.getSilentModeForConversation(option).then((res) => { + if (res.data.type === "NONE") { + if (!pushAry.includes(option.conversationId)) { + pushAry.push(option.conversationId) + } + } + pushObj.pushAry = pushAry; + uni.setStorage({ + key: 'pushStorageData', + data: pushObj + }); + }); +} \ No newline at end of file diff --git a/pages.json b/pages.json index ab578c62..1cdd91a5 100644 --- a/pages.json +++ b/pages.json @@ -48,7 +48,17 @@ "style": { "navigationBarTitleText": "chatting", "backgroundTextStyle": "dark", - "enablePullDownRefresh": true + "enablePullDownRefresh": true, + "app-plus": { + "titleNView":{ + "buttons":[{ + "text":"...", + "fontSrc": "./static/iconfont/iconfont.ttf", + "fontSize": "24", + "float": "right" + }] + } + } } }, { @@ -135,7 +145,19 @@ "navigationBarBackgroundColor": "#f2f2f2", "navigationBarTextStyle": "black", "navigationBarTitleText": "群聊", - "enablePullDownRefresh": true + "enablePullDownRefresh": true, + "app-plus": { + "titleNView": { + "buttons": [ + { + "text": "...", + "fontSrc": "./static/iconfont/iconfont.ttf", + "fontSize": "24", + "float": "right" + } + ] + } + } } // "style": { // "navigationBarTitleText": "uni-app", @@ -172,6 +194,22 @@ "navigationBarTextStyle": "black", "navigationBarTitleText": "emedia" } + }, + { + "path": "pages/moreMenu/moreMenu", + "style": { + "navigationBarBackgroundColor": "#f2f2f2", + "navigationBarTextStyle": "black", + "navigationBarTitleText": "好友配置" + } + }, + { + "path": "pages/searchMsg/searchMsg", + "style": { + "navigationBarBackgroundColor": "#f2f2f2", + "navigationBarTextStyle": "black", + "navigationBarTitleText": "历史记录" + } } ], "globalStyle": { diff --git a/pages/chat/chat.vue b/pages/chat/chat.vue index 81668dc9..115c5408 100644 --- a/pages/chat/chat.vue +++ b/pages/chat/chat.vue @@ -52,8 +52,8 @@ - {{ item.unReadCount - }} + + {{ item.unReadCount}} + + + + 配置推送免打扰 + + + + + + + 查看历史记录 + + + + + + + diff --git a/pages/searchMsg/searchMsg.css b/pages/searchMsg/searchMsg.css new file mode 100644 index 00000000..8bec9657 --- /dev/null +++ b/pages/searchMsg/searchMsg.css @@ -0,0 +1,222 @@ + +.search, +.search_input { + width: 100%; + height: 88rpx; + background-color: #f2f2f2; + display: flex; + align-items: center; + top: 0; + left: 0; +} + + +.search { + justify-content: space-around; +} + +.search_input { + justify-content: space-around; +} + +.search view, +.search_input view { + height: 64rpx; + line-height: 64rpx; + background-color: #fff; + border-radius: 17px; + text-align: center; + display: flex; + align-items: center; + margin: 0 32rpx; +} + +.search view { + width: 100%; + justify-content: center; + align-items: center; + background-color: #fff; +} + +.search image { + display: block; + width: 5%; + height: 50%; +} + +.search_input view { + padding-left: 24rpx; + text-align: left; + flex: 1; + margin: 0 28rpx 0 32rpx; +} + +.search icon, +.search_input icon { + display: inline-block; + margin: 8rpx 12rpx 0; + font-size: 24rpx; +} + +.search text { + font-size: 30rpx; + color: #9B9B9B; +} + +.search_input text { + display: inline-block; + height: 60rpx; + line-height: 60rpx; + font-size: 30rpx; + color: #0873DE; + margin-right: 32rpx; +} + +.search_input input { + font-size: 28rpx; + width: 90%; +} + +.mask { + background-color: black; + opacity: 0.4; + position: fixed; + top: 80rpx; + left: 0; + right: 0; + bottom: 0; +} + + + +.scroll_view, +.scroll_view_change { + background-color: #FAFAFA; + padding-bottom: 100rpx; +} + +.scroll_view_X, +.scroll_view_change_X { + padding-bottom: 230rpx; +} + + +.message { + width: 100%; + height: auto; + padding: 0 30rpx; + position: relative; + +} + +.time { + margin: 14rpx 0; + text-align: center; +} + +.time .time-text { + display: inline-block; + padding: 6rpx 20rpx 0 20rpx; + font-size: 24rpx; + color: #fff; + line-height: 28rpx; + border-radius: 4rpx; + background-color: #dcdcdc; +} + +.user .user-text { + margin: auto 100rpx 8rpx; + font-size: 20rpx; + color: #dcdcdc; + display: block; +} + +.avatar { + width: 72rpx; + height: 72rpx; + margin: 0 20rpx 0 0; + border-radius: 6rpx; + float: left; +} + +.msg { + display: inline-block; + padding: 20rpx; + max-width: calc(85% - 80rpx); + min-height: 40rpx; + font-size: 24rpx; + /*overflow: hidden;*/ + text-align: left; + word-break: break-all; + background-color: #fff; + border-radius: 26rpx; + position: relative; + margin-top: 24rpx; +} + +.msg .msg_poprightarrow { + position: absolute; + right: -10rpx; + height: 18rpx; + width: 18rpx; + margin-top: -10rpx; +} + +.msg .msg_popleftarrow { + position: absolute; + left: -14rpx; + height: 18rpx; + width: 18rpx; + margin-top: -10rpx; +} + +.msg .msg-text { + line-height: 40rpx; + font-size: 32rpx; + margin: 0; +} + +.self { + text-align: right; +} + +.self .avatar { + float: right; + margin: 0 0 0 20rpx; +} + +.user { + position: relative; + bottom: -30rpx; +} + +.self .msg { + background-color: #0873DE; + color: #fff; +} + +.self .msg:before { + right: inherit; + left: 100%; + border-right-color: transparent; + border-left-color: #b2e281; +} + +.template { + display: inline; +} + +.err { + width: 32rpx; + height: 32rpx; + position: absolute; + left: -40rpx; +} + +.hide { + display: none; +} + +.show { + display: block; +} diff --git a/pages/searchMsg/searchMsg.vue b/pages/searchMsg/searchMsg.vue new file mode 100644 index 00000000..2af743fb --- /dev/null +++ b/pages/searchMsg/searchMsg.vue @@ -0,0 +1,220 @@ + + + diff --git a/static/iconfont/iconfont.ttf b/static/iconfont/iconfont.ttf new file mode 100644 index 00000000..f17b95e7 Binary files /dev/null and b/static/iconfont/iconfont.ttf differ