diff --git a/miniprogram/app.wxss b/miniprogram/app.wxss index 0482564238cdbe3f69c0ceae2414b893a085acb5..6c6bcca6ce4ae63107af052d88c7cb3caaf518d7 100644 --- a/miniprogram/app.wxss +++ b/miniprogram/app.wxss @@ -143,3 +143,16 @@ .text-light { font-weight: 300; } + +.reset_btn { + margin:0; + padding:0; + border-radius:0; + border:none; + font-size:1em; + background-color:transparent; +} + +.reset_btn::after{ + border: none; +} \ No newline at end of file diff --git a/miniprogram/pages/chat-room/chat-room.js b/miniprogram/pages/chat-room/chat-room.js index 3a2abe0486afa8fd715930f2f5b5c0428da82647..372228ca3f595d21eb56d117e704df4e81da6a08 100644 --- a/miniprogram/pages/chat-room/chat-room.js +++ b/miniprogram/pages/chat-room/chat-room.js @@ -14,10 +14,13 @@ Page({ socket: null, // websocket对象 watcherIndex: null, // 监听器下标 targetUid: null, // 当前聊天对象uid + selfUid: null,// 自己uid msgCount: 20, // 默认拉取的消息数 chatList: [], // 聊天消息列表 targetUserInfo: null, // 当前聊天对象信息 - selfUserInfo: null // 用户自己的信息 + selfUserInfo: null, // 用户自己的信息 + isFocus: false, + clearValue: "", }, onLoad: function (options) { @@ -34,6 +37,7 @@ Page({ socket: socket, finish_load: true, targetUid: targetUid, + selfUid: selfUid }); // 获取缓存最后的chatId,拉取历史聊天记录,跟websocket收到的消息重排序,防止消息乱序 let chatId = wx.getStorageSync('lastChat:' + targetUid); @@ -44,6 +48,20 @@ Page({ this.getHistoryMsgList(chatId, type); // 这一步之后,新来的websocket消息如果id大于历史最大id则直接尾插,不再排序 }, + onShow: function(options) { + this.onMessage(); + }, + + // 页面返回事件 + onUnload: function() { + app.$notify.delWatcher(this.data.watcherIndex); + app.$notify.setNotHandleUid(null); + this.setData({ + watcherIndex: null + }); + console.log('关闭页面监听的websocket'); + }, + // 获取用户信息 getUserInfo: function(uid, self) { let that = this; @@ -134,7 +152,8 @@ Page({ let msgType = config.MSG_TYPE; if( type == msgType.SINGLE_TEXT_MSG.type || - type == msgType.SINGLE_IMG_MSG.type + type == msgType.SINGLE_IMG_MSG.type || + type == msgType.SERVER_ACK.type ) { return true; } @@ -157,9 +176,14 @@ Page({ // 处理消息 handleMessage: function(data, pageObj) { if ( - (!this.data.open_listen && this.data.targetUid != data.fromUid) || - data.fromUid != pageObj.data.targetUid + this.data.open_listen && + ( + (data.toUid == this.data.selfUid && data.fromUid == this.data.targetUid) || + (data.fromUid == this.data.selfUid && data.toUid == this.data.targetUid) + ) ) { + // none + } else { return } let type = data.type; @@ -168,22 +192,74 @@ Page({ this.setData({ chatList: this.data.chatList.concat([data]) }) + this.pageScrollToBottom(); console.log("页面监听消息,id:" + chatId + ",内容:" + data.content); } app.$notify.ack(chatId, pageObj.data.targetUid); }, - onShow: function(options) { - this.onMessage(); - }, - - // 页面返回事件 - onUnload: function() { - app.$notify.delWatcher(this.data.watcherIndex); - app.$notify.setNotHandleUid(null); + // 文本框聚焦回调 + focusInput() { this.setData({ - watcherIndex: null + isFocus: true }); - console.log('关闭页面监听的websocket'); - } + }, + + // 文本框取消聚焦回调 + blurInput() { + let that = this; + setTimeout(function() { + that.setData({ + isFocus: false + }) + }, 200); + }, + + // 发送文本消息 + sendTextMsg(e) { + if(!app.checkedUserLoading()){ + return; + } + let params = e.detail.value; + if(typeof params !== 'object'){ + let content = params; + params = { content }; + } + params.type = config.MSG_TYPE.SINGLE_TEXT_MSG.type; + params.toUid = this.data.targetUid; + params.timeStamp = new Date().getTime().toString(); + let msg = JSON.stringify(params); + this.sendMsg(msg); + }, + + // 发送消息 + sendMsg(msg) { + let that = this; + // todo 成功和失败都要重试 + this.data.socket.send({ + data: msg, + success: function (res) { + console.log("发送消息成功,消息内容:" + msg); + that.setData({ + clearValue: "" + }); + }, + fail: function (res) { + console.warn("发送消息失败,消息内容:" + msg) + } + }) + }, + + // 获取容器高度,使页面滚动到容器底部 + pageScrollToBottom: function() { + wx.createSelectorQuery().select('#chat_panel').boundingClientRect(function(rect) { + if (rect){ + // 使页面滚动到底部 + console.log(rect.height); + wx.pageScrollTo({ + scrollTop: rect.height + }) + } + }).exec() + }, }) \ No newline at end of file diff --git a/miniprogram/pages/chat-room/chat-room.wxml b/miniprogram/pages/chat-room/chat-room.wxml index cca52518ea10c607cf8e15f70b4d7fe92a7a629f..ac3faa9f52751f3dae684ecf0a2a885059be2ed8 100644 --- a/miniprogram/pages/chat-room/chat-room.wxml +++ b/miniprogram/pages/chat-room/chat-room.wxml @@ -3,22 +3,27 @@ - - - - +
+ + + + + + + + + + + + - - - - - - - - +
- + diff --git a/miniprogram/pages/chat-room/chat-room.wxss b/miniprogram/pages/chat-room/chat-room.wxss index 3cca79aabf937fc8b381026191db54a8cd3c4032..7d686a4fcc9e7571781626388389075d7cb10c87 100644 --- a/miniprogram/pages/chat-room/chat-room.wxss +++ b/miniprogram/pages/chat-room/chat-room.wxss @@ -58,8 +58,10 @@ page { } .tui-input-box { - width: 78%; + width: 85%; justify-content: flex-start; + margin-left: 10px; + margin-right: 10px; } .tui-chat-input { diff --git a/miniprogram/pages/post/post.js b/miniprogram/pages/post/post.js index 7bfc3cecc16d731d6d9c543a16400689762af949..9d0d70705b1523e3702d356457e6f5ca535f35c6 100644 --- a/miniprogram/pages/post/post.js +++ b/miniprogram/pages/post/post.js @@ -239,9 +239,12 @@ Page({ * 评论文本框失去焦点 */ blurComment(){ - this.setData({ - isFocus: false - }) + let that = this; + setTimeout(function() { + that.setData({ + isFocus: false + }) + }, 200); }, /** diff --git a/miniprogram/pages/user-center/manage-team/manage-team-info/manage-team-info.js b/miniprogram/pages/user-center/manage-team/manage-team-info/manage-team-info.js index a5077b0a046cb3297e3e5111cf061318a6149a3e..4616b72c0c96d81d91c6b2758f691c1082877bbd 100644 --- a/miniprogram/pages/user-center/manage-team/manage-team-info/manage-team-info.js +++ b/miniprogram/pages/user-center/manage-team/manage-team-info/manage-team-info.js @@ -257,9 +257,9 @@ Page({ /** * 保存职位信息 */ - saveRecruitment(e){ + saveRecruitment(e) { let params = e.detail.value; - params.teamId = this.data.teamId - '0'; + params.teamId = this.data.teamId + ""; if(!params.id){ delete params.id; }; diff --git a/miniprogram/utils/Notify.js b/miniprogram/utils/Notify.js index d2a820a383cb99e385d20d71b9ecc40ce37f5a52..0475b348ea1e308c42014ffa2828af5bfd3ae595 100644 --- a/miniprogram/utils/Notify.js +++ b/miniprogram/utils/Notify.js @@ -176,7 +176,7 @@ export default class Notify { } }); // 缓存最新聊天id todo 暂时注释掉,便于测试 - wx.setStorageSync('lastChat:' + targetUid, chatId); + // wx.setStorageSync('lastChat:' + targetUid, chatId); console.log("注意目前关闭了最新chatId缓存,请注意试验完后打开"); } diff --git a/project.config.json b/project.config.json index 06fd218c014593235be0f18cb9b080eda3621100..ca2875e1430531d55ef1523bb7211266349b53a5 100644 --- a/project.config.json +++ b/project.config.json @@ -13,7 +13,7 @@ "minified": true, "newFeature": true, "coverView": true, - "nodeModules": false, + "nodeModules": true, "autoAudits": false, "showShadowRootInWxmlPanel": true, "scopeDataCheck": false, @@ -31,7 +31,6 @@ "outputPath": "" }, "enableEngineNative": false, - "bundle": false, "useIsolateContext": true, "useCompilerModule": false, "userConfirmedUseCompilerModuleSwitch": false,