Browse Source

text不为空

lyn7568 6 years ago
parent
commit
50d47d0b12
1 changed files with 27 additions and 30 deletions
  1. 27 30
      src/pages/index/views/MiniChat/components/text.vue

+ 27 - 30
src/pages/index/views/MiniChat/components/text.vue

1
<!-- 文本输入框 -->
1
<!-- 文本输入框 -->
2
<template>
2
<template>
3
  <div class="text">
3
  <div class="text">
4
    <textarea ref="text" v-model="content" @keyup="onKeyup"></textarea>
4
    <textarea ref="text" v-model="content" @keyup="keyEnter"></textarea>
5
    <div class="send" @click="send">
5
    <div class="send" @click="send">
6
    	<span>发送(Enter)</span>
6
    	<span>发送(Enter)</span>
7
    </div>
7
    </div>
32
  },
32
  },
33
  watch: {
33
  watch: {
34
    ifFirstChat(val) {
34
    ifFirstChat(val) {
35
      console.log(val)
36
      this.ifFirstChat = val
35
      this.ifFirstChat = val
37
    }
36
    }
38
  },
37
  },
39
  methods: {
38
  methods: {
40
    onKeyup (e) {
39
    keyEnter(e) {
41
      if (e.keyCode === 13) {
40
      if (e.keyCode === 13) {
42
        this.send()
41
        this.send()
43
      }
42
      }
44
    },
43
    },
45
    send () {
44
    send() {
46
      var that = this
45
      var that = this
47
      if (that.content.length === 0) {
46
      if (that.content.length <= 1) {
48
        that.warn = true
47
        that.warn = true
49
        that.content = ''
48
        that.content = ''
50
        setTimeout(() => {
49
        setTimeout(() => {
51
          that.warn = false
50
          that.warn = false
52
        }, 1000)
51
        }, 1000)
53
      } else {
54
        var url = '/ajax/msg/fsend'
55
        console.log(that.ifFirstChat)
56
        if (that.ifFirstChat) {
57
          url = '/ajax/msg/send'
58
        }
59
        that.$axios.post(url, {
60
          pid: that.selectChatId,
61
          cnt: that.content
62
        }, function(res) {
63
          if (res.success && res.data) {
64
            var msg = {
65
              cnt: that.content,
66
              opTime: DateFormat('yyyyMMddhhmmss'),
67
              msgType: '1',
68
            }
69
            that.chatDetailLocal.push(msg)
70
            that.chatDetailLocal.sort(function(a, b) {
71
              return a.opTime > b.opTime ? 1 : (a.opTime === b.opTime ? 0 : -1)
72
            })
73
            that.$store.dispatch('chatDetailAction', that.chatDetailLocal)
74
            that.content = ''
75
          }
76
        })
77
        
52
        return
53
      }
54
      var url = '/ajax/msg/fsend'
55
      if (that.ifFirstChat) {
56
        url = '/ajax/msg/send'
78
      }
57
      }
58
      that.$axios.post(url, {
59
        pid: that.selectChatId,
60
        cnt: that.content
61
      }, function(res) {
62
        if (res.success && res.data) {
63
          var msg = {
64
            cnt: that.content,
65
            opTime: DateFormat('yyyyMMddhhmmss'),
66
            msgType: '1',
67
          }
68
          that.chatDetailLocal.push(msg)
69
          that.chatDetailLocal.sort(function(a, b) {
70
            return a.opTime > b.opTime ? 1 : (a.opTime === b.opTime ? 0 : -1)
71
          })
72
          that.$store.dispatch('chatDetailAction', that.chatDetailLocal)
73
          that.content = ''
74
        }
75
      })
79
    }
76
    }
80
  },
77
  },
81
  mounted() {
78
  mounted() {