微信小程序即时聊天对话窗口静态源码[通俗易懂]

微信小程序即时聊天对话窗口静态源码[通俗易懂]实例描述:静态的源码,需要自己二次开发适用范围:所有版本微信小程序库日期:2019/9/2前端:<scroll-viewstyle=”height:{{height}}vh;width:100vw;display:flex;position:relative;flex-direction:column;top:{{top?top:0}}px;”…

大家好,又见面了,我是你们的朋友全栈君。

实例描述:静态的源码,需要自己二次开发
适用范围:所有版本微信小程序
日期 :2019/9/2

前端:

<scroll-view
        style="height:{
  
  {height}}vh;width: 100vw;display: flex;  position: relative;flex-direction: column;top:{
  
  {top?top:0}}px;"
        scroll-y="true"
        scroll-top="{
  
  {scrollTopVal}}"
        bindtap="resetInputStatus">

        <view class="chat-item-row">
          <view class="chat-item-me">
              <image class="chat-avatar" src="/static/img/avatar.png"></image>
              <view class="message-body-me">
                  <view class="message-text">文本消息 记住是三种类型哦</view>
              </view>
          </view> 
        </view>
        <view class="chat-item-row">
            <view class="chat-item-time">星期一 12:54</view>
        </view>
        <view class="chat-item-row">
          <view class="chat-item-he">
              <image class="chat-avatar" src="/static/img/avatar.png"></image>
              <view class="im-msg-box">
                  <view class="user-name">昵称</view>
                  <view class="message-body">
                    <image class="message-image" src="{
  
  {style}}/upload/image/0100.png"></image>
                  </view>              
              </view>
          </view>
        </view>

        <view class="chat-item-row">
          <view class="chat-item-he">
              <image class="chat-avatar" src="/static/img/avatar.png"></image>
              <view class="im-msg-box">
                  <view class="user-name">昵称</view>
                  <view class="message-body">
                    <view class="message-text">文本消息 记住是三种类型哦</view>
                  </view>              
              </view>
          </view>
        </view>

        <view class="chat-item-row">
          <view class="chat-item-he">
              <image class="chat-avatar" src="/static/img/avatar.png"></image>
              <view class="im-msg-box">
                  <view class="user-name">昵称</view>
                  <view class="message-body">
                     <view class="message-voice">
                        <image class="voice-play-size"
           src="{
  
  {isPlaying?'data:image/gif;base64,R0lGODlhFgAgAIABAJmZmQAAACH/C05FVFNDQVBFMi4wAwEAAAAh/wtYTVAgRGF0YVhNUDw/eH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vX08/Lx8O/u7ezr6uno5+bl5OPi4eDf3t3c29rZ2NfW1dTT0tHQz87NzMvKycjHxsXEw8LBwL++vby7urm4t7a1tLOysbCvrq2sq6qpqKempaSjoqGgn56dnJuamZiXlpWUk5KRkI+OjYyLiomIh4aFhIOCgYB/fn18e3p5eHd2dXRzcnFwb25tbGtqaWhnZmVkY2JhYF9eXVxbWllYV1ZVVFNSUVBPTk1MS0pJSEdGRURDQkFAPz49PDs6OTg3NjU0MzIxMC8uLSwrKikoJyYlJCMiISAfHh0cGxoZGBcWFRQTEhEQDw4NDAsKCQgHBgUEAwIBAAAh+QQFIQABACwAAAAAFgAgAAACJYyPqcvtD6OctNqLs54A3O5RYCeOpGSe6PiplbvF8kzX9o3nQQEAIfkEBSEAAQAsCAAGAAYAFAAAAhcMEHmXxrpahEg+V7HNU9P9hUs1jVZTAAAh+QQJIQABACwIAAAADgAgAAACN4wfgHvgvNyDRipaJc4X251MnraRY0d9pZiykNmir8vAsxzZOY3o+8prBDm43jA0VMWKQmaPUQAAIfkEBSEAAQAsAAAAABYAIAAAAhmMj6nL7Q+jnLTai7PevPsPhuJIluaJpkEBACH5BAUhAAEALAgABgAGABQAAAIXDBB5l8a6WoRIPlexzVPT/YVLNY1WUwAAIfkEBSEAAQAsDgAAAAgAIAAAAigMggmbuKxeM7LVCPF8x2b3UeEFdppnltv4cWhKii86n6XpYnBoTEEBADs=':'/static/chat/voice_other.png'}}" />

                      <text> 15'</text>
                     </view>
                  </view>              
              </view>
          </view>
        </view>

        <view class="chat-item-row">
          <view class="chat-item-me">
              <image class="chat-avatar" src="/static/img/avatar.png"></image>
                <view class="im-msg-box">
                  <view class="message-body-me">
                      <view class="message-voice">
                        <text> 15'</text>
                        <image class="voice-play-size"
              src="{
  
  {isPlaying?'data:image/gif;base64,R0lGODlhFgAgAIABAHenywAAACH/C05FVFNDQVBFMi4wAwEAAAAh/wtYTVAgRGF0YVhNUDw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVN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c29rZ2NfW1dTT0tHQz87NzMvKycjHxsXEw8LBwL++vby7urm4t7a1tLOysbCvrq2sq6qpqKempaSjoqGgn56dnJuamZiXlpWUk5KRkI+OjYyLiomIh4aFhIOCgYB/fn18e3p5eHd2dXRzcnFwb25tbGtqaWhnZmVkY2JhYF9eXVxbWllYV1ZVVFNSUVBPTk1MS0pJSEdGRURDQkFAPz49PDs6OTg3NjU0MzIxMC8uLSwrKikoJyYlJCMiISAfHh0cGxoZGBcWFRQTEhEQDw4NDAsKCQgHBgUEAwIBAAAh+QQFIQABACwAAAAAFgAgAAACJYyPqcvtD6OctNqLs94IAOx9VuhRZDidZUpW6Chy8kzX9o3nUgEAIfkEBSEAAQAsCAAGAAYAFAAAAhaMARaI18tckrTCeVW0O+vnXVjHjEkBACH5BAklAAEALAAAAAAOACAAAAI1jA+nC73c0kNxmihttQHz7nCeGJLZNGqleqKr2z6b+YEx9OK3MrN16vsAYb8ebHcxynKySQEAIfkEBR4AAQAsAAAAABYAIAAAAhmMj6nL7Q+jnLTai7PevPsPhuJIluaJpkEBACH5BAUhAAEALAgABgAGABQAAAIWjAEWiNfLXJK0wnlVtDvr511Yx4xJAQAh+QQFJQABACwAAAAACAAgAAACKIwPh5DLyp6JbUp7Q4TbKZ1RXIV9nTeaGUiypJjGTnti9ArP491qQQEAOw==':'/static/chat/voice_mine.png'}}" />
                      
                      </view>
                  </view>
              </view> 
          </view> 
        </view>



</scroll-view>


<view class="footer-input-box">
    <view class="footer-input-body">
      <image src="/static/chat/voice.png" class="mp3-btn" bindtap="showLy"></image>
      <button class="luyingBtn" wx:if="{
  
  {luYing}}">按住说话</button>
      <input class="chat-input-style" bindinput="setMessage" wx:else></input>
      <view class="chat-input-send-button-style" wx:if="{
  
  {textMessage}}" bindtap="sendJsonText">发送</view>
      <image src="/static/chat/extra.png" class="more-btn" wx:else bindtap="showBox"></image>
    </view>
    <view class="extra-super" wx:if="{
  
  {isShow}}">
        <view class="flex-column" bindtap="sendImg">
          <image class="extra-image-size" src="/static/chat/choose_picture.png" ></image>
          <text class="extra-text-size">图片</text>
        </view>
    </view>
</view>

后端:

Page({
  /**
   * 页面的初始数据
   */
  data: {
    ...common.data,
    textMessage: '',
    chatItems: [],
    type:'',
    height:100,
    isShow:false,
    luYing:false
  },
  ...common.method,
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getPage(options);
  },
  setMessage(e){
    let {value} = e.detail;
    this.setData({
      textMessage:value
    })
  },
  getPage(options){
    let {type,top} = options;

    this.setData({
      type: type,
      top:top
    })

    //获取对方和我方信息



  },
  sendJsonText(data){
    //发送消息并执行更新页面数据


  },
  //显示和隐藏上传图片的功能
  showBox(e){
    let {isShow} = this.data;
    if(isShow){
       isShow=false;
       }else{
      isShow = true;
    }
    this.setData({
      isShow:isShow
    });
  },
  showLy(e){
    let { luYing } = this.data;
    if (luYing) {
      luYing = false;
    } else {
      luYing = true;
    }
    this.setData({
      luYing: luYing
    });
  },
  //开始录音
  startRecording(){

    //录音及检测

  },
  //结束录音并上传
  endRecording() {

    //上传完毕后返回路径并发送消息

  },
  //上传并发送图片
  sendImg(){

  }

});

样式:

.chat-item-row{
  padding: 15rpx;
  display: flex;
}

.chat-item-me{
  width: 100%;
  display: flex;
  flex-direction: row-reverse;
}

.chat-item-he{
  float: left;
  display: flex;
  flex-direction: row;
}

.chat-avatar{
  width: 90rpx;
  height: 90rpx;
  border-radius: 50%;
  overflow: hidden;
}

.message-body-me{
  background: #8FCBF7;
  padding: 15rpx;
  text-align: left;
  border-radius: 10rpx;
  margin: 0rpx 15rpx;
  color: #FFFFFF;
  font-size: 25rpx;
  margin-top: 8rpx;
}

.message-body{
  padding: 15rpx;
  text-align: left;
  background: #FFFFFF;
  border-radius: 10rpx;
  margin: 0rpx 15rpx;
  font-size: 25rpx;
}

.chat-item-time{
  width: 100vw;
  color: #999999;
  text-align: center;
  font-size: 23rpx;
}

.im-msg-box{
  display: flex;
  flex-direction: column;
}

.im-msg-box .user-name{
  font-size: 23rpx;
  color: #999999;
  margin-left: 15rpx;
  padding: 10rpx 20rpx;
}



.voice-play-size{
 width: 22rpx;
 height: 32rpx;
 margin: 10rpx;
}

.message-voice{
  line-height: 50rpx;
  height: 50rpx;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.message-voice text{
  line-height: 50rpx;
  height: 50rpx;
}


.footer-input-box{
  width: 100%;
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  bottom: 0;
}

.footer-input-body{
  display: flex;
  flex-direction: row;
  background-color: #E6EAEB;
  width: 100%;
  align-items: center;
  height: 100rpx;
}

.mp3-btn{
  width: 50rpx;
  height: 50rpx;
  padding: 25rpx 15rpx;
  display: flex;
  flex-shrink: 0;
}

.chat-input-style{
    border-radius:10rpx;
    border:1rpx solid transparent;
    margin-top:14rpx;
    margin-bottom: 13rpx;
    padding:10rpx;
    min-height: 51rpx;
    background-color: #FFFFFF;
    color: #000000;
    width: 100%;
}

.message-image{
  width: 60vw;
  height: 24vh;
}

.chat-input-send-button-style{
    width: 100rpx;
    padding: 15rpx 0;
    text-align: center;
    margin: 0 10rpx;
    border-radius: 10rpx;
    background: #5087E5;
    color: #FFFFFF;
    font-size: 25rpx;
}

.more-btn{
  width: 50rpx;
  height: 50rpx;
  padding: 25rpx 15rpx;
  display: flex;
  flex-shrink: 0;
}


.extra-super{
    display: flex;
    padding-top: 25rpx;
    height: 234rpx;
    width: 100%;
    background-color: white
}


.flex-column{
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 25%;
}

.extra-text-size{
  color: #666666;
  font-size: 24rpx;
  margin-top: 10rpx;
}

.extra-image-size{
  width: 114rpx;
  height: 114rpx;
}

.luyingBtn{
  font-size: 32rpx;
  width: 100%;
  line-height: 74rpx;
  margin-top: 15rpx;
  margin-bottom: 15rpx;
}

注意:附件自行百度了,仅供参考与学习,商用需要二次开发。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/146737.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • qt 5.12.1 下载安装详细教程

    qt 5.12.1 下载安装详细教程前言:Qt是一个跨平台的C++图形界面应用程序框架。它提供给开发者建立图形用户界面所需的功能,广泛用于开发GUI程序,也可用于开发非GUI程序。Qt很容易扩展,并且允许真正地组件编程。基本上,Qt同XWindow上的Motif,Openwin,GTK等图形界面库以及Windows平台上的MFC、OWL、VCL、ATL是同类型的东西。一:下载地址http://download.qt.io/of…

  • MessageDigest详解

    MessageDigest详解一、概述java.security.MessageDigest类用于为应用程序提供信息摘要算法的功能,如MD5或SHA算法。简单点说就是用于生成散列码。信息摘要是安全的单向哈希函数,它接收任意大小的数据,输出固定长度的哈希值。关于信息摘要和散列码请参照《数字证书简介》MessageDigest 通过其getInstance系列静态函数来进行实例化和初始化。MessageDigest对象通…

  • python怎么运行ipynb文件_jupyter如何打开D盘的文件

    python怎么运行ipynb文件_jupyter如何打开D盘的文件2019独角兽企业重金招聘Python工程师标准>>>…

  • 进程、线程、协程

    进程、线程、协程

    2021年10月14日
  • docker 镜像构建_docker生成镜像

    docker 镜像构建_docker生成镜像前言如果我们已经安装了一个python3的环境,如果另一台机器也需要安装同样的环境又要敲一遍,很麻烦,这里可以配置Dockerfile文件,让其自动安装,类似shell脚本Dockerfile编写

  • 视觉slam和激光slam结合_视觉slam和激光slam

    视觉slam和激光slam结合_视觉slam和激光slam激光SLAM:早在2005年的时候,激光SLAM就已经被研究的比较透彻,框架也已初步确定。激光SLAM,是目前最稳定、最主流的定位导航方法。激光SLAM地图构建VSLAM(基于视觉的定位与建图):随着计算机视觉的迅速发展,视觉SLAM因为信息量大,适用范围广等优点受到广泛关注。视觉SLAM地图构建,图片来源:百度AI(1)基于深度摄像机的Vslam,跟…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号