This article shares the specific code of WeChat applet to implement the chat room through examples for your reference. The specific content is as follows 1. Achieve effect display 2.room.wxml <view class="container" style="{{containerStyle}}"> <chatroom style="width: 100%; height: 100%" envId="{{chatRoomEnvId}}" collection="{{chatRoomCollection}}" groupId="{{chatRoomGroupId}}" groupName="{{chatRoomGroupName}}" userInfo="{{userInfo}}" onGetUserInfo="{{onGetUserInfo}}" getOpenID="{{getOpenID}}" ></chatroom> </view> 3.room.js const app = getApp() Page({ data: { avatarUrl: './user-unlogin.png', userInfo: null, logged: false, takeSession: false, requestResult: '', // chatRoomEnvId: 'release-f8415a', chatRoomCollection: 'chatroom', chatRoomGroupId: 'demo', chatRoomGroupName: 'Chat Room', // functions for used in chatroom components onGetUserInfo: null, getOpenID: null, }, onLoad: function() { // Get user information wx.getSetting({ success: res => { if (res.authSetting['scope.userInfo']) { // Already authorized, you can directly call getUserInfo to get the avatar nickname without a pop-up window wx.getUserInfo({ success: res => { this.setData({ avatarUrl: res.userInfo.avatarUrl, userInfo: res.userInfo }) } }) } } }) this.setData({ onGetUserInfo: this.onGetUserInfo, getOpenID: this.getOpenID, }) wx.getSystemInfo({ success: res => { console.log('system info', res) if (res.safeArea) { const { top, bottom } = res.safeArea this.setData({ containerStyle: `padding-top: ${(/ios/i.test(res.system) ? 10 : 20) + top}px; padding-bottom: ${20 + res.windowHeight - bottom}px`, }) } }, }) }, getOpenID: async function() { if (this.openid) { return this.openid } const { result } = await wx.cloud.callFunction({ name: 'login', }) return result.openid }, onGetUserInfo: function(e) { if (!this.logged && e.detail.userInfo) { this.setData({ logged: true, avatarUrl: e.detail.userInfo.avatarUrl, userInfo: e.detail.userInfo }) } }, onShareAppMessage() { return { title: 'Instant Messaging Demo', path: '/pages/im/room/room', } }, }) 4.room.json { "usingComponents": { "chatroom": "/components/chatroom/chatroom" } } 5.room.wxss .container { height: 100%; position: absolute; top: 0; bottom: 0; left: 0; right: 0; padding-top: 80rpx; padding-bottom: 30rpx; } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Tutorial on installing Docker in Windows 10 subsystem Ubuntu (WSL) (with pictures and text)
>>: Summary of MySQL common SQL statements including complex SQL queries
Table of contents 1. Dep 2. Understand obverser 3...
This article shares the specific code of jQuery t...
The MySQL version used in this example is mysql-8...
Knowing that everyone's time is precious, I w...
Table of contents Overview 1. RangeError 2. Refer...
Without further ado, let's take a look at the...
Recently I saw an article on a public account tha...
Apache SkyWalking Apache SkyWalking is an applica...
A few days ago, I discovered that my website was ...
Root directory and index file The root directive ...
The previous article wrote about how to manually ...
Table of contents 1. Install and import 2. Define...
1. Install JDK 1.1 Check whether the current virt...
VMware version: VMware-workstation-full-16 VMware...
Table of contents <template> <ul class=&...