Vue implements sending emoticons in chat box

Vue implements sending emoticons in chat box

The specific code for sending emoticons in the vue chat box and sending emoticons in the vue interface is for your reference. The specific content is as follows

1. When sending a message, determine whether the message is an emoticon, the emoticon type: 3, content: [love], and store it in the database
2. When getting the chat history, judge type===3 and process the expression.

<img v-else-if="chatItem.type === 3" :src="emojiUrl + emojiMap[chatItem.content]" style="width:25px;height:25px" />

1.textElement.vue

<template>
  <div class="text-element-wrapper" >
    <div class="text-element">
      <div :class="isMine ? 'element-send' : 'element-received'">
        <p>{{ date }}</p>
        <!-- Text -->
        <span>{{ chatItem.content }}</span>
        <span v-if="chatItem.type === 1">{{ chatItem.content }}</span>
        <!-- Expression -->
        <img v-else-if="chatItem.type === 3" :src="emojiUrl + emojiMap[chatItem.content]" style="width:25px;height:25px" />
      </div>
      <div :class="isMine ? 'send-img' : 'received-img'">
        <img :src="chatItem.from_headimg" width="40px" height="40px"/>
      </div>
    </div>
  </div>
</template>

<script>
  // import decodeText from '../../../untils/decodeText'
  import { getFullDate } from '../../../untils/common'
  import {emojiMap, emojiUrl} from '../../../untils/emojiMap'

  export default {
    name: 'TextElement',
    props: ['chatItem', 'isMine'],
    data() {
      return {
        emojiMap: emojiMap,
        emojiUrl: emojiUrl,
      }
    },
    computed: {
      // contentList() {
      // return decodeText(this.chatItem)
      // },
      // Timestamp processing date () {
        return getFullDate(new Date(this.chatItem.time * 1000))
      },
    }
  }
</script>

<style scoped>
  .text-element-wrapper {
    position: relative;
    max-width: 360px;
    border-radius: 3px;
    word-break: break-word;
    border: 1px solid rgb(235, 235, 235);
  }

  .text-element {
    padding: 6px;
  }

  .element-received {
    max-width: 280px;
    background-color: #fff;
    float: right;
  }
  .received-img {
    float: left;
    padding-right: 6px;
  }

  .element-send {
    max-width: 280px;
    background: rgb(5, 185, 240);
    float: left;
  }
  .send-img {
    float: right;
  }
</style>

The main idea of ​​sending emoticons in the vue interface is:

<template>    
 <section class="dialogue-section clearfix" >
            <div class="row clearfix" v-for="(item,index) in msgs" :key = index>
                <img :src="item.uid == myInfo.uid ? myInfo.avatar :otherInfo.avatar" :class="item.uid == myInfo.uid ? 'headerleft' : 'headerright'">
                <p :class="item.uid == myInfo.uid ? 'textleft' : 'textright'" v-html="customEmoji(item.content)"></p>
            </div>
        </section>
         <div id="emoji-list" class="flex-column" v-if="emojiShow"> //First, use this to determine whether the emoji pop-up window should appear<div class="flex-cell flex-row" v-for="list in imgs">
                <div class="flex-cell flex-row cell" v-for="item in list" @click="inputEmoji(item)">
                  <img :src="'./emoji/' + item + '.png'">
                </div>
              </div>
            </div>
</template>
<script>
import { sendMsg } from "@/ws"; //This is a long connection import _ from "lodash"; //This is a very powerful library in js import eventBus from '@/eventBus' //This is a public file passed between child and parent console.log(emoji)
export default {
  data() {
    this.imgs = _.chunk(emoji, 6) //This is to call the chunk method of the lodash library to divide the six elements into an array, which is just a two-dimensional array in the emoji array. return {
      emojiShow: false //At the beginning, the click button is not displayed by default. To display the click button, you can write @click='emojiShow=emojiShow'};
  },
  methods: {
    customEmoji(text) { //This function is used by the server to convert the passed name into an image. return text.replace(/\[([A-Za-z0-9_]+)\]/g, '<img src="./emoji/$1.png" style="width:30px; height:30px;">')
    },
    inputEmoji(pic) {
      this.content += `[${pic}]` //The passed name is converted to a picture}
};
</script>
<style scoped>
@import '../../assets/css/dialogue.css';

#emoji-list {
  height: 230px;
  background: #fff;
}
#emoji-list .cell {
  line-height: 13vh;
  border-right: 1rpx solid #ddd;
  border-bottom: 1rpx solid #ddd;
}
.flex-row {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}
.flex-column {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
}
.flex-cell {
  flex: 1;
}
.cell img {
  width: 35px;
  height: 35px;
}
</style>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • A single-page application function imitating mobile QQ based on Vue2 (access to chatbot)

<<:  Detailed steps for adding hosts you need to monitor in zabbix

>>:  Solution to ONLY_FULL_GROUP_BY error in Mysql5.7 and above

Recommend

Three ways to achieve text flashing effect in CSS3 Example code

1. Change the transparency to achieve the gradual...

HTML Tutorial: Collection of commonly used HTML tags (6)

These introduced HTML tags do not necessarily ful...

Summary of methods to improve mysql count

I believe many programmers are familiar with MySQ...

Detailed explanation of JavaScript closure issues

Closures are one of the traditional features of p...

Use nginx to configure domain name-based virtual hosts

1. What is a virtual host? Virtual hosts use spec...

MySQL query statement simple operation example

This article uses examples to illustrate the simp...

MySQL 8.0.17 installation and simple configuration tutorial under macOS

If you don’t understand what I wrote, there may b...

Realizing the effect of carousel based on jQuery

This article shares the specific code of jQuery t...

Implementation of remote Linux development using vscode

Say goodbye to the past Before vscode had remote ...

Summary of events that browsers can register

Html event list General Events: onClick HTML: Mous...

How to install and configure MySQL and change the root password

1. Installation apt-get install mysql-server requ...

Network configuration of Host Only+NAT mode under VirtualBox

The network configuration of Host Only+NAT mode u...

Analyze the compilation and burning of Linux kernel and device tree

Table of contents 1. Prepare materials 2. Downloa...

What to do if you forget your mysql password

Forgot your MySQL password twice? At first I did ...