微信小程序 扩展组件仿微信表情组件


本文整理自网络,侵删。

emoji

仿微信表情组件。使用前需将文档下方提供的表情雪碧图上传 CDN,再传入表情组件。为提升首次加载表情图片的性能,可通过 image 组件提前触发雪碧图的下载,利用浏览器的缓存机制。在不使用表情面板的页面,可将 emoji 组件隐藏或移出屏幕外,仅使用 parseEmoji 的功能。

属性列表

属性类型默认值必填说明
sourcestring表情雪碧图地址
heightnumber300表情盘高度
background-colorstring#EDEDED表情盘背景色
show-sendbooleantrue是否显示发送按钮
show-delbooleantrue是否显示删除按钮
show-historybooleantrue是否显示最近使用
bindinsertemojieventhandle插入表情,e.detail={emotionName}
binddelemojieventhandle点击删除按钮
bindsendeventhandle点击发送按钮

示例代码:

{
  "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>


使用方式

点击表情图标将会获得对应的中文含义,例如????->[微笑]。在实际输入过程中,我们通常仅展示中文含义即可。

阅读剩余部分

相关阅读 >>

微信小程序api中,使用drawimage完成绘制图像,图像保持原始尺寸

微信小程序云开发sdk文档 常量

微信小程序api 背景音频-监听播放事件

sdk数据库 aggregate索引

微信小程序api nfc-nfcv标签

微信小程序 小程序使用mockupdateorder

微信小程序云开发api 在集合上新增记录

微信小程序 小程序使用precancelorder

微信小程序api 绘图beginpath(开始一个路径)

微信小程序 全局配置

更多相关阅读请进入《微信小程序》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...