|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 | // pages/message/message.js
  data: {
    statsuBarHeight: app.globalData.statsuBarHeight,
    headHeight: 40,
    chatListHeight: 0,
    keyboardHeight: 0,
    inutPanelHeight: 50,
    curMessage: "",
  },
  //设置聊天窗高度
  setChatListHeight() {
    this.setData({
      chatListHeight: app.globalData.sysHeight - app.globalData.statsuBarHeight - this.data.headHeight - this.data.keyboardHeight - this.data.inutPanelHeight
    })
  },
  //隐藏键盘
  hideKeyboard() {
    wx.hideKeyboard();
    //this.hideMediaPanel();
  },
  onLoad: function (options) {
    var that = this;
    that.getMessage();
    this.setChatListHeight();
    wx.onKeyboardHeightChange(res => { //监听键盘高度变化
      this.setData({
        keyboardHeight: res.height
      });
      this.setChatListHeight();
      //this.scroll2Bottom();
    });
  },
  /**
   * 消息获取
   */
  inputMessage: function (e) {
    this.setData({
      inputMessage: e.detail.value,
    })
  },
  /**
   * 消息发送 
   */
  setMessage: function () {
    var that = this;
    var curMessage = that.data.inputMessage;
    if (curMessage.trim() === "") {
      app.showFail("不可以发送空消息")
      return;
    }
    wx.request({
      url: app.buildUrl("/message/setMess"),
      header: app.getRequestHeader(),
      data: {
        message: this.data.inputMessage,
      },
      success: function (res) {
        if (res.data.code == 200) {
          //清空输入框
          that.setData({
            inputMessage: ''
          })
          app.showSuccess("发送成功!")
          that.onLoad();
        }else{
          app.showFail("发送失败!")
        }
      }  
    })
  },
 |