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

Tomcat server security settings method

Tomcat is an HTTP server that is the official ref...

uniapp implements date and time picker

This article example shares the specific code of ...

Webpack file packaging error exception

Before webpack packaging, we must ensure that the...

JS implements circular progress bar drag and slide

This article example shares the specific code of ...

Detailed use of Echarts in vue2 vue3

Table of contents 1. Installation 2. Use Echarts ...

Introduction to general_log log knowledge points in MySQL

The following operation demonstrations are all ba...

Tutorial on how to quickly deploy clickhouse using docker-compose

ClickHouse is an open source column-oriented DBMS...

Detailed explanation of MySQL transactions and MySQL logs

Transactional Characteristics 1. Atomicity: After...

Simple steps to configure Nginx reverse proxy with SSL

Preface A reverse proxy is a server that receives...

Summary of solutions for MySQL not supporting group by

I downloaded and installed the latest version of ...

Use h1, h2, and h3 tags appropriately

In the process of making web pages, it is inevita...

Solution to index failure caused by MySQL implicit type conversion

Table of contents question Reproduction Implicit ...

Docker-compose steps to configure the spring environment

Recently, I need to package the project for membe...