本文整理自网络,侵删。
emoji
仿微信表情组件。使用前需将文档下方提供的表情雪碧图上传 CDN,再传入表情组件。为提升首次加载表情图片的性能,可通过 image 组件提前触发雪碧图的下载,利用浏览器的缓存机制。在不使用表情面板的页面,可将 emoji 组件隐藏或移出屏幕外,仅使用 parseEmoji 的功能。
属性列表
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
source | string | 是 | 表情雪碧图地址 | |
height | number | 300 | 否 | 表情盘高度 |
background-color | string | #EDEDED | 否 | 表情盘背景色 |
show-send | boolean | true | 否 | 是否显示发送按钮 |
show-del | boolean | true | 否 | 是否显示删除按钮 |
show-history | boolean | true | 否 | 是否显示最近使用 |
bindinsertemoji | eventhandle | 否 | 插入表情,e.detail={emotionName} | |
binddelemoji | eventhandle | 否 | 点击删除按钮 | |
bindsend | eventhandle | 否 | 点击发送按钮 |
示例代码:
{
"disableScroll": true,
"navigationBarTitleText": "",
"usingComponents": {
"mp-emoji": "../components/emoji/emoji"
}
}
<scroll-view scroll-y style="height: {{layoutHeight}}px" scroll-into-view="{{historyList[historyList.length - 1].id}}">
<block wx:for="{{historyList}}" wx:for-index="idx" wx:for-item="historyItem">
<view class="record" hidden="{{historyItem.length === 0}}" id="{{historyItem.id}}">
<view class="avator"></view>
<view class="comment">
<block wx:for="{{historyItem.emoji}}" wx:key="*this">
<block wx:if="{{item.type === 1}}">{{item.content}}</block>
<view
wx:if="{{item.type === 2}}"
style="display: inline-block; width: {{lineHeight}}px; height: {{lineHeight}}px">
<view
class="{{item.imageClass}}"
style="background-image: url({{emojiSource}});transform-origin: 0 0; transform: scale({{lineHeight / 64}});"></view>
</view>
</block>
</view>
</view>
</block></scroll-view>
<view class="reply_wrp" style="bottom: {{keyboardHeight}}px">
<view class="reply_tool">
<view hover-class="active" class="reply_button replay_quick_button">
<image src="./images/reply_tool_keyboard.svg" mode='aspectFit' class="reply_tool_pic"></image>
</view>
<view class="reply_form_wrp">
<label for="" class="reply_label">
<input
class="reply_input"
cursor-spacing="8px"
confirm-type="send"
adjust-position="{{false}}"
confirm-hold value="{{comment}}"
cursor="{{cursor}}"
focus="{{focus}}"
bindblur="onBlur"
bindfocus="onFocus"
bindinput="onInput"
bindconfirm="onConfirm"
bindkeyboardheightchange="onkeyboardHeightChange"
/>
</label>
</view>
<view hover-class="active" class="reply_button replay_emotion_button" bindtap="showEmoji">
<image src="./images/reply_tool_emoji.svg" mode='aspectFit' class="reply_tool_pic"></image>
</view>
<view hover-class="active" class="reply_button replay_media_button" bindtap="showFunction">
<image src="./images/reply_tool_add.png" mode='aspectFit' class="reply_tool_pic"></image>
</view>
</view>
<view class="reply_panel_wrp" style="height: {{emojiShow ? 300 : 200}}px;" hidden="{{!emojiShow && !functionShow}}">
<view class="reply_panel {{emojiShow ? 'show': ''}}" hidden="{{!emojiShow}}">
<mp-emoji source="{{emojiSource}}" class="mp-emoji" bindinsertemoji="insertEmoji" binddelemoji="deleteEmoji" bindsend="onsend"></mp-emoji>
</view>
<view class="reply_panel {{functionShow ? 'show': ''}}" hidden="{{!functionShow}}">
<swiper indicator-dots="{{true}}" indicator-color="#bbbbbb" indicator-active-color="#8c8c8c">
<swiper-item>
<view class="function_list">
<view class="function_item" bindtap="chooseImage">
<image src="./images/reply_function_image.svg" class="reply_function_pic"></image>
</view>
</view>
</swiper-item>
</swiper>
</view>
</view>
</view>
<scroll-view scroll-y style="height: {{layoutHeight}}px" scroll-into-view="{{historyList[historyList.length - 1].id}}">
<block wx:for="{{historyList}}" wx:for-index="idx" wx:for-item="historyItem">
<view class="record" hidden="{{historyItem.length === 0}}" id="{{historyItem.id}}">
<view class="avator"></view>
<view class="comment">
<block wx:for="{{historyItem.emoji}}" wx:key="*this">
<block wx:if="{{item.type === 1}}">{{item.content}}</block>
<view
wx:if="{{item.type === 2}}"
style="display: inline-block; width: {{lineHeight}}px; height: {{lineHeight}}px">
<view
class="{{item.imageClass}}"
style="background-image: url({{emojiSource}});transform-origin: 0 0; transform: scale({{lineHeight / 64}});"></view>
</view>
</block>
</view>
</view>
</block></scroll-view>
<view class="reply_wrp" style="bottom: {{keyboardHeight}}px">
<view class="reply_tool">
<view hover-class="active" class="reply_button replay_quick_button">
<image src="./images/reply_tool_keyboard.svg" mode='aspectFit' class="reply_tool_pic"></image>
</view>
<view class="reply_form_wrp">
<label for="" class="reply_label">
<input
class="reply_input"
cursor-spacing="8px"
confirm-type="send"
adjust-position="{{false}}"
confirm-hold value="{{comment}}"
cursor="{{cursor}}"
focus="{{focus}}"
bindblur="onBlur"
bindfocus="onFocus"
bindinput="onInput"
bindconfirm="onConfirm"
bindkeyboardheightchange="onkeyboardHeightChange"
/>
</label>
</view>
<view hover-class="active" class="reply_button replay_emotion_button" bindtap="showEmoji">
<image src="./images/reply_tool_emoji.svg" mode='aspectFit' class="reply_tool_pic"></image>
</view>
<view hover-class="active" class="reply_button replay_media_button" bindtap="showFunction">
<image src="./images/reply_tool_add.png" mode='aspectFit' class="reply_tool_pic"></image>
</view>
</view>
<view class="reply_panel_wrp" style="height: {{emojiShow ? 300 : 200}}px;" hidden="{{!emojiShow && !functionShow}}">
<view class="reply_panel {{emojiShow ? 'show': ''}}" hidden="{{!emojiShow}}">
<mp-emoji source="{{emojiSource}}" class="mp-emoji" bindinsertemoji="insertEmoji" binddelemoji="deleteEmoji" bindsend="onsend"></mp-emoji>
</view>
<view class="reply_panel {{functionShow ? 'show': ''}}" hidden="{{!functionShow}}">
<swiper indicator-dots="{{true}}" indicator-color="#bbbbbb" indicator-active-color="#8c8c8c">
<swiper-item>
<view class="function_list">
<view class="function_item" bindtap="chooseImage">
<image src="./images/reply_function_image.svg" class="reply_function_pic"></image>
</view>
</view>
</swiper-item>
</swiper>
</view>
</view>
</view>
使用方式
点击表情图标将会获得对应的中文含义,例如????->[微笑]。在实际输入过程中,我们通常仅展示中文含义即可。
相关阅读 >>
微信小程序api中,使用drawimage完成绘制图像,图像保持原始尺寸
更多相关阅读请进入《微信小程序》频道 >>

Vue.js 设计与实现 基于Vue.js 3 深入解析Vue.js 设计细节
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者