亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

微信小程序實現(xiàn)聊天界面發(fā)送功能(示例代碼)

 更新時間:2024年07月30日 11:48:07   作者:令人作嘔的溏心蛋  
這篇文章主要介紹了微信小程序實現(xiàn)聊天界面發(fā)送功能,本文通過示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧

.wxml

<scroll-view scroll-y="true" style="height: {{windowHeight}}px;">
  <view wx:for="{{chatList}}" wx:for-index="index" wx:for-item="item" style="padding-top:{{index==0?30:0}}rpx">
    <!-- 左邊:對方用戶 -->
    <view style="display: flex; align-items: flex-start; margin-bottom: 10px;padding: 10rpx 20rpx;" wx:if="{{item.id != userInfo.id}}">
      <view>
        <image src="{{item.url}}" style="width: 35px; height: 35px; border-radius: 10px;"></image>
      </view>
      <view style="padding: 15rpx 20rpx;border-radius: 0 10px 10px 10px;background-color: #ffffff; margin-left: 10rpx; display: inline-block;">
        <text>{{item.content}}</text>
      </view>
    </view>
    <!-- 右邊:當前用戶 -->
    <view style="display: flex; align-items: flex-start; justify-content: flex-end;padding: 10rpx 20rpx;" wx:else>
      <view style="padding: 15rpx 20rpx; background-color: #7e66f6; border-radius: 10px 0 10px 10px; margin-right: 10rpx;color: #ffffff;">
        <text>{{item.content}}</text>
      </view>
      <view>
        <image src="{{item.url}}" style="width: 35px; height: 35px; border-radius: 10px;"></image>
      </view>
    </view>
  </view>
  <!-- 底部輸入框及發(fā)送按鈕 -->
  <view style="position: fixed; bottom: {{bottomJP}}px; width: 100%; background-color: #fff; padding:  0 10rpx; box-shadow: 0 -2px 4px rgba(202, 202, 202, 0.1);height: 130rpx;display: flex;justify-content: space-around;align-items: center;padding-bottom: 30rpx;">
    <image src="/images/yuyin.png" style="width: 30px; height: 30px; border-radius: 10px;"></image>
    <input style="height: 20rpx;width: 60%; padding: 15rpx; border: 1px solid rgb(247, 245, 245); border-radius: 10rpx;" 	confirm-type="send" adjust-position="{{false}}" bindfocus="getTelIptHeight" bindblur="getTelIptHeight" bindconfirm="sendContent" value="{{inputValue}}"/>
    <image src="/images/biaoqing.png" style="width: 30px; height: 30px; border-radius: 10px;"></image>
    <image src="/images/tupian.png" style="width: 30px; height: 30px; border-radius: 10px;margin-right: 20rpx;"></image>
    <!-- <button style="width: 150rpx; height: 80rpx; background-color: #007bff; color: #fff; border: none; border-radius: 10px; margin-left: 10rpx;">發(fā)送</button> -->
  </view>
</scroll-view>

.js

const app = getApp()
Page({
  /**
   * 頁面的初始數(shù)據(jù)
   */
  data: {
    tips: null,
    windowHeight: 0,
    windowWidtth: 0,
    bottomJP: 0,
    userInfo: {},
    inputValue: '',
    chatList: [{
        createTime: '2024-07-24 09:10:00',
        url: '/images/baochang.png',
        content: '哈哈哈',
        id: 8
      },
      {
        createTime: '2024-07-24 11:15:30',
        url: '/images/baochang.png',
        content: '你好啊',
        id: 9
      },
      {
        createTime: '2024-07-24 11:15:30',
        url: '/images/baochang.png',
        content: '你好啊',
        id: 9
      },
    ]
  },
  getTelIptHeight(e) {
    console.log("height---------", e);
    if (e.type == 'blur') {
      this.setData({
        bottomJP: 0
      })
    } else {
      this.setData({
        bottomJP: e.detail.height
      })
    }
  },
  onLoad(options) {
    let that = this
    that.setData({
      userInfo: wx.getStorageSync("userInfo")
    })
    wx.getSystemInfo({
      success: function (res) {
        console.log(res)
        that.setData({
          windowHeight: res.windowHeight,
          windowWidtth: res.windowWidth,
        });
      }
    });
    wx.setNavigationBarTitle({
      title: '動態(tài)獲取用戶昵稱',
    })
  },
  send() {
    let info = {
      senderId: wx.getStorageSync("userInfo").id,
      recipientId: 100,
      chatContent: '你好啊~',
      chatContentType: 'text'
    }
    let that = this
    app.globalData.ws.send({
      data: JSON.stringify(info),
      success: (res) => {
        console.log(res)
        that.setData({
          tips: "發(fā)送信息成功"
        })
      }
    })
  },
  sendContent(e) {
    let message = {
      createTime: '2024-07-24 11:15:30',
      url: '/images/baochang.png',
      content: e.detail.value,
      id: 9
    }
    let list = this.data.chatList
    list.push(message)
    this.setData({
      chatList: list,
      inputValue: ''
    })
  }
})

.wxss

page {
  background-color: #f4f5f7;
}

.json

{
  "usingComponents": {},
  "navigationBarTitleText": ""
}

到此這篇關于微信小程序實現(xiàn)聊天界面,發(fā)送功能的文章就介紹到這了,更多相關小程序聊天發(fā)送功能內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • js 采用delete實現(xiàn)繼承示例代碼

    js 采用delete實現(xiàn)繼承示例代碼

    這篇文章主要介紹了js如何采用delete實現(xiàn)所謂的繼承,下面有個不錯的示例,大家可以參考下
    2014-05-05
  • JavaScript實現(xiàn)文本目標字符替換和一鍵全部替換

    JavaScript實現(xiàn)文本目標字符替換和一鍵全部替換

    這篇文章主要介紹了JavaScript實現(xiàn)文本目標字符替換和一鍵全部替換,文章圍繞主題展開詳細的內容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-06-06
  • JS 事件延遲執(zhí)行說明分析

    JS 事件延遲執(zhí)行說明分析

    為了避免用戶鼠標無意識劃過,而觸發(fā)事件。浪費客戶端資源。
    2010-05-05
  • JavaScript如何將base64圖片轉化為URL格式

    JavaScript如何將base64圖片轉化為URL格式

    這篇文章主要給大家介紹了關于JavaScript如何將base64圖片轉化為URL格式的相關資料,Base64是一種編碼方式,而不是真正的加密方式,即使算Base64也僅用作一個簡單的加密來保護某些數(shù)據(jù),而真正的加密通常都比較繁瑣,需要的朋友可以參考下
    2023-07-07
  • 詳解webpack 最簡打包結果分析

    詳解webpack 最簡打包結果分析

    這篇文章主要介紹了詳解webpack 最簡打包結果分析,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-02-02
  • postMessage的兩種使用方式

    postMessage的兩種使用方式

    這篇文章主要介紹了使用postMessage實現(xiàn)iframe跨域通信,第一種使用postMessage在irfame中實現(xiàn)跨域數(shù)據(jù)傳遞,第二種使用postMessage在window.open()中的使用,本文結合示例代碼給大家詳細講解,需要的朋友跟隨小編一起看看吧
    2022-03-03
  • JS實現(xiàn)固定在右下角可展開收縮DIV層的方法

    JS實現(xiàn)固定在右下角可展開收縮DIV層的方法

    這篇文章主要介紹了JS實現(xiàn)固定在右下角可展開收縮DIV層的方法,右下角的div層可實現(xiàn)收縮與展開的功能,非常具有實用價值,需要的朋友可以參考下
    2015-02-02
  • JavaScript如何實現(xiàn)圖片懶加載(lazyload) 提高用戶體驗(增強版)

    JavaScript如何實現(xiàn)圖片懶加載(lazyload) 提高用戶體驗(增強版)

    這篇文章主要介紹了JavaScript如何實現(xiàn)圖片懶加載(lazyload) 提高用戶體驗(增強版)的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-11-11
  • javascript實現(xiàn)禁止鼠標滾輪事件

    javascript實現(xiàn)禁止鼠標滾輪事件

    這篇文章主要介紹了javascript實現(xiàn)禁止鼠標滾輪事件的相關資料,需要的朋友可以參考下
    2015-07-07
  • 詳解使用Next.js構建服務端渲染應用

    詳解使用Next.js構建服務端渲染應用

    這篇文章主要介紹了詳解使用Next.js構建服務端渲染應用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07

最新評論