fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<template>
  <div class="emojiInput">
    <div class="chatIcon">
      <el-popover placement="top-start" width="400" trigger="click" class="emoBox">
        <div class="emotionList">
          <span @click="getEmo(index)" v-for="(item,index) in faceList" :key="index"
                class="emotionItem">{{item}}</span>
        </div>
        <img class="emotionSelect" slot="reference" src="../../assets/img/biaoqing.png" />
      </el-popover>
    </div>
    <el-input v-model="textarea" class="chatText" resize="none" type="textarea" id='textarea'
              :autosize="{minRows:4,maxRows:8}" @keyup.enter.native="sendInfo"
              :maxlength="maxlength" show-word-limit></el-input>
  </div>
</template>
 
<script>
import emoji from '@/utils/emoji.js'
export default {
  props: {
    // 设置输入框字体
    maxlength: {
      type: Number,
      default: 1000
    },
    content: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      faceList: [],
      textarea: null
    }
  },
  mounted() {
    for (const i in emoji) {
      this.faceList.push(emoji[i].char)
    }
  },
  watch: {
    content(newValue, oldValue) {
      this.textarea = newValue
    },
    textarea(newValue, oldValue) {
      this.$emit('update:content', newValue)
    }
  },
  methods: {
    getEmo(index) {
      var textArea = document.getElementById('textarea')
      function changeSelectedText(obj, str) {
        if (window.getSelection) {
          // 非IE浏览器
          textArea.setRangeText(str)
          // 在未选中文本的情况下,重新设置光标位置
          textArea.selectionStart += str.length
          textArea.focus()
        } else if (document.selection) {
          // IE浏览器
          obj.focus()
          var sel = document.selection.createRange()
          sel.text = str
        }
      }
      changeSelectedText(textArea, this.faceList[index])
      this.textarea = textArea.value// 要同步data中的数据
    },
    // 回车健事件
    sendInfo() {
    }
  }
}
</script>
 
<style lang="scss">
.emojiInput {
  .el-popover {
    height: 200px;
    width: 400px;
    overflow: scroll;
    overflow-x: auto;
  }
  .chatIcon {
    font-size: 25px;
    .emotionSelect {
      cursor: pointer;
    }
  }
  .el-textarea {
    .el-input__count {
      bottom: -30px;
    }
  }
}
.emotionList {
  display: flex;
  flex-wrap: wrap;
  padding: 5px;
}
.emotionItem {
  width: 10%;
  font-size: 20px;
  text-align: center;
  cursor: pointer !important;
  &:hover {
    background: #f56c6c;
  }
}
</style>