zb-admin/src/views/chat/components/u-toolbar/index.vue

159 lines
3.9 KiB
Vue
Raw Normal View History

2022-03-24 04:15:14 +00:00
<template>
<div class="g-layout-content-chat-util">
<div class="item-left">
<div class="emoje" title="选择表情" @click.stop="selectEmojiAction">
<img src="static/face/emoji-after.png" alt="" style="width: 20px" />
2022-03-24 04:15:14 +00:00
</div>
<div class="upload-picture" title="上传图片">
<el-upload action multiple :show-file-list="false" :before-upload="beforeUploadAction">
<el-icon style="font-size: 20px"><FolderOpened /></el-icon>
2022-03-24 04:15:14 +00:00
</el-upload>
</div>
<div class="emoje-border-wrap" v-show="isShowEmoji">
<div
class="title-emoje"
v-for="(item, index) in emojis"
@click.stop="selectSigleEmojeAction($event, item)"
:key="index"
>
<img :src="`static/face/${item}.png`" :title="item" />
2022-03-24 04:15:14 +00:00
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, defineEmits, onMounted } from 'vue'
import { FolderOpened } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
2022-03-24 04:15:14 +00:00
import emoji from '@/utils/emojis'
const emojis = ref<string[]>(emoji.imgs)
const isShowEmoji = ref<boolean>(false)
const emit = defineEmits(['insert', 'upload'])
2022-03-24 04:15:14 +00:00
const selectSigleEmojeAction = (e, item) => {
2022-03-24 04:15:14 +00:00
if (e.target.tagName === 'IMG') {
let node = e.target.cloneNode(true)
node.title = item
emit('insert', node, 'IMG')
2022-03-24 04:15:14 +00:00
} else {
emit('insert', node)
2022-03-24 04:15:14 +00:00
}
}
const selectEmojiAction = () => {
2022-03-24 04:15:14 +00:00
isShowEmoji.value = true
emit('insert', null, null)
2022-03-24 04:15:14 +00:00
}
const beforeUploadAction = (file, fileList) => {
2022-03-24 04:15:14 +00:00
return new Promise((resolve, reject) => {
var reader = new FileReader()
let reg = /\.jpg$|\.jpeg$|\.gif$|\.png$/i
2022-03-24 04:15:14 +00:00
reader.readAsDataURL(file)
let name = file.name
if (reg.test(name)) {
reader.onload = (e: FileReader) => {
2022-03-24 04:15:14 +00:00
resolve(e.target.result)
emit('upload', e.target.result)
2022-03-24 04:15:14 +00:00
}
} else {
2022-03-24 04:15:14 +00:00
ElMessage.error('请上传图片')
reject()
}
})
}
onMounted(() => {
2022-03-24 04:15:14 +00:00
window.onclick = function (event) {
isShowEmoji.value = false
}
})
</script>
<style lang="scss" scoped>
.g-layout-content-chat-util {
height: 46px;
2022-03-24 04:15:14 +00:00
display: flex;
flex-shrink: 0;
justify-content: space-between;
2022-03-24 04:15:14 +00:00
position: relative;
border-bottom: 1px solid #ebebeb;
background: white;
.item-left {
display: flex;
align-items: center;
}
.upload-picture {
2022-03-24 04:15:14 +00:00
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
height: 100%;
width: 40px;
}
.screenshot-upload {
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
height: 100%;
width: 40px;
}
.recoding-chatbox {
position: relative;
}
.emoje {
display: flex;
align-items: center;
height: 100%;
justify-content: center;
width: 40px;
font-size: 25px;
cursor: pointer;
color: grey;
}
.upload-picture {
cursor: pointer;
display: flex;
align-items: center;
height: 100%;
width: 40px;
justify-content: center;
}
.emoje-border-wrap {
top: -121px;
left: 0;
position: absolute;
width: 372px;
padding: 10px;
z-index: 9;
border: 1px solid #d9d9d9;
background-color: #fff;
overflow: hidden;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
.title-emoje {
cursor: pointer;
float: left;
border: 1px solid #e8e8e8;
height: 32px;
width: 32px;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
margin: -1px 0 0 -1px;
//padding: 4px 2px;
text-align: center;
/*img{*/
/* width: 100%;*/
/* height: 100%;*/
/*}*/
}
2022-03-24 04:15:14 +00:00
}
}
</style>