| 主機參考:VPS測評參考推薦/專注分享VPS服務器優惠信息!若您是商家可以在本站進行投稿,查看詳情!此外我們還提供軟文收錄、PayPal代付、廣告贊助等服務,查看詳情! |
| 我們發布的部分優惠活動文章可能存在時效性,購買時建議在本站搜索商家名稱可查看相關文章充分了解該商家!若非中文頁面可使用Edge瀏覽器同步翻譯!PayPal代付/收錄合作 |

可以創建群,邀請群成員,顯示群成員列表,發送圖片,設置群公告,踢人,禁所有人,禁個人,發送語音消息等功能。
效果圖:
實施代碼:
頁面結構
ltview class = 博 gt ltview class = top _ bo gt lt視圖bindtap = 數字 gt群({ { user number } })</view gt; lt視圖bindtap = 上傳 wx:if = ;{ {禁止= = # 39;0'} } gt發送圖片</view gt; lt視圖bindtap = 禁令 wx:if = ;{ {禁止= = # 39;1'} } gt發送圖片</view gt; lt視圖bindtap = 注意 gt團體公告
page { background:# f2f2f 2;}.top_bo {顯示:flex背景:白色;flex -方向:row}.top_bo視圖{ flex:1;font -size:28 rpx;text-align:居中;邊框:1rpx實心# cccline -高度:80rpx} scroll -view { height:82vh;/* padding -bottom:30 rpx;*/}.noList {背景:白色;margin -top:30 rpx;/*身高:230rpx*/寬度:100%;劃-頂:25%;}.noMsg { text -align:center;顏色:# 999;font -size:28 rpx;}.inp {位置:絕對;底部:0;寬度:100%;背景:白色;高度:100rpx}.inp輸入{背景:# d0d0d0border -半徑:15rpx劃-左:20rpx身高:84rpxmargin -top:10 rpx;寬度:94%;margin -left:2%;}.禁止{背景:# d0d0d0border -半徑:15rpx劃-左:20rpx身高:84rpxmargin -top:10 rpx;寬度:94%;margin -left:2%;text-align:居中;line -高度:84rpx顏色:rgb(34,34,34);}.plaCC { margin -left:5 rpx;}.p_r {顯示:flexflex -方向:row}.flex roe { display:flex;flex -方向:row}.正文{寬度:100%;位置:相對;/* border:1 rpx solid # CCC;*//*高度:200rpx */}。right _ body { width:100%;/*邊框:1rpx純紅;*/padding:20 rpx;margin -top:50 rpx;}.left _ body { margin -top:50 rpx;}.posRit { right:20 rpx;}.text bo { width:620 rpx;text -align:right;}.lfBo { margin -left:10 rpx;}.ritTxt {背景:# 44426a填充:10 rpx 20 rpx 10 rpx 20 rpx;顏色:白色;border -radius:15 rpx 0 15 rpx 15 rpx;margin -top:20 rpx;浮動:對;max -寬度:500rpxword -wrap:break -word;text -align:left;}.ritTxt2 {背景:白色;顏色:白色;border -radius:15 rpx 0 15 rpx 15 rpx;填充:0 rpx 20 rpx 10 rpx 20 rpx;margin -top:20 rpx;浮動:對;max -寬度:500rpxword -wrap:break -word;text -align:left;}.lftTxt {背景:# 44426a填充:10 rpx 20 rpx 10 rpx 20 rpx;顏色:白色;border -radius:0 rpx 15 rpx 15 rpx 15 rpx;margin -top:20 rpx;浮動:左;max -寬度:500rpxword -wrap:break -word;text -align:left;}.lftTxt2 {背景:# fff填充:0 rpx 20 rpx 10 rpx 20 rpx;顏色:白色;border -radius:0 rpx 15 rpx 15 rpx 15 rpx;margin -top:20 rpx;浮動:左;max -寬度:500rpxword -wrap:break -word;text -align:left;}.my _ audio { height:60 rpx;寬度:60rpxz-指數:2;位置:相對;top:10 rpx;左:20rpxmargin -right:30 rpx;}.data time { font -size:28 rpx;}.text img { width:200 rpx;margin -top:5 rpx;}.head { width:80 rpx;身高:80rpx}._ {身高:130rpx寬度:100%;背景:# ccc}.inppo { display:flex;flex -方向:row}.余音{ flex:1;line -高度:104rpxtext-align:居中;}.input { flex:5;}js
const DB = wx . cloud . database()var util = require( # 39;../../utils/util . js # 39;);var recorder = wx . getrecordermanager();constinneraudicontext = wx . createinneraudiocontext()//獲取回放對象var qunId,即;Page({ /** *頁面的初始數據*/data: {list: [],用戶號: # 39;0',用戶列表:[],c: ;",禁止: # 39;'},//點擊錄音開始播放事件my _ audio _ Click:function(e){ var src = e . current target . dataset . src;console . log( # 39;網址 # 39;,src);inneraudiocontext . src = src inneraudiocontext . seek(0);inneraudiocontext . play();},//Home GoHome(){ wx . switch tab({ URL: # 39;../group/group # 39;}}},//group member number(){ let userlist = JSON . stringify(this . data . userlist)wx . navigate to({ URL: # 39;../會員/會員?qunId = # 39+ qunId,}) },bottom:function(){ var that = this;this . setdata({ scroll top:100000 })},//動態監控禁止狀態forbidden(){ console . log( # 39;8888888888888',qunId)const watcher = db . collection( # 39;qunList # 39) .其中({ _id: qunId })。watch({ onChange:function(RES){ let arr = RES . docs[0]console . log( # 39;禁態的動態監控 # 39;,arr。_ openId+ # 39;:'+wx . getstoragesync( # 39;openId # 39))設opid = arr。_ openId if(arr . prohibit = = # 39;1'){ if (arr。_ openId = = wx . getstoragesync( # 39;openId # 39)){ that.setData({禁止: # 39;0'}) } else { that.setData({禁止: # 39;1'})} } else { const watcher = db . collection( # 39;qunUserList # 39) .其中({ qunId: qunId,_ openId:wx . getstoragesync( # 39;openId # 39) }) .watch({ onChange:function(RES){ let arrr = RES . docs[0]console . log( # 39;禁態的動態監控 # 39;,arrr。_ openId+ # 39;:'+wx . getstoragesync( # 39;openId # 39))if(arrr . prohibit = = # 39;1'){ if (arrr。_ openId = = opid){ that . setdata({ prohibit: # 39;0'}) } else { that.setData({禁止: # 39;1'}) } } else { that.setData({禁止: # 39;0'}) } },on error:function(err){//console . error( # 39;--------------錯誤 # 39;,err) } }) } },on error:function(err){//console . error( # 39;--------------錯誤 # 39;,err)}}},//禁詞提示prohibit tis(){ wx . show toast({ title: # 39;禁語...',圖標: # 39;無 # 39;}}},//獲取成員消息on msg(qunId){ console . log( # 39;2222222',qunId)const watcher = db . collection( # 39;新聞 # 39;)//按進度降序//。order by( # 39;進步 # 39;, 'desc # 39;)//取前10//。極限(10)。其中({_ qunid: qunid})。watch({ onchange:function(snapshot){ console . log( # 39;快照 # 39;,snapshot)var list arr = snapshot . docs;console . log( # 39;---',listArr) listArr.forEach((item,idx)= gt;{ console . log( # 39;---',item)console . log(wx . getstoragesync( # 39;openId # 39) + ':'+項。_ openId)item . type = wx . getstoragesync( # 39;openId # 39)==項。_openId?1 : 2;item . send outname = wx . getstoragesync( # 39;openId # 39)==項。_openId?'我 # 39;: '';})that . setdata({ list:list arr })setTimeout(()= gt;{ that.bottom() },500)console . log( # 39;----------------------s # 39;,listArr) },on error:function(err){ console . error( # 39;--------------錯誤 # 39;,err)}},//發送圖片上傳(){var that = this //讓用戶選擇一張圖片wx . choose image({ success:choose result = >;{ //將圖片上傳到云存儲空間wx.cloud.uploadFile({ //指定上傳到的云路徑:util . imgname()+ # 39;textImg.png # 39,//指定要上傳文件的applet臨時文件路徑file path:choose result . tempfile paths[0],//success:RES = >;{ console . log( # 39;上傳成功 # 39;,RES)let imgUrl = RES . fileid wx . cloud . call function({ name: ;新聞 ,// data: { // imgUrl: imgUrl // },data: { _qunId: qunId,_ openId:wx . getstoragesync( # 39;openId # 39),//消息正文: # 39;',//message img: imgur,//time dataTime: util.nowTime(),//avatar send outhand:wx . getstoragesync( # 39;userInfo # 39).avatarUrl,//昵稱send outname:wx . getstoragesync( # 39;userInfo # 39).昵稱},成功(RES){ console . log( # 39;圖片發送成功 # 39;,res) },fail(RES){ console . log( # 39;退貨失敗 # 39;,res) } }) },}) },})})},onLoad:function(options){ console . log(options)that = this qunId = options . qunId this . on msg(options . qunId);that . user fun()that . forbidden()},//獲取群成員user fun(){ db . collection( # 39;qunUserList # 39).where({ qunId: qunId })。get({ success:function(Res){ console . log(666666666,Res)that . setdata({ user number:Res . data . length,userlist: res.data}}}},//群公告notice(){ wx . show modal({ title: # 39;集團公告 # 39;,內容:this.data.userList[0]。qunTitle,showCancel: false,success(RES){ if(RES . confirm){//console . log( # 39;用戶點擊OK # 39}}}}},//發送消息sendout (e) {console.log (1111,e)let title = e . detail . value if(title = = # 39;'){ wx . show toast({ title: # 39;請輸入聊天內容 # 39;,圖標: # 39;無 # 39;,}) } else { var data = { _qunId: qunId,_ openId:wx . getstoragesync( # 39;openId # 39),//消息正文:標題,//消息img: # 39;',//time dataTime: util.nowTime(),//avatar send outhand:wx . getstoragesync( # 39;userInfo # 39).avatarUrl,//昵稱send outname:wx . getstoragesync( # 39;userInfo # 39).昵稱} console . log(data)wx . cloud . call function({ name: ;新聞 ,data: data,success(RES){ console . log( # 39;發送消息 # 39;,RES)that . setdata({ title: # 39;'}) },fail(RES){ console . log( # 39;登錄失敗 # 39;,res)}}},/* *用戶點擊右上角分享*/onshareappmessage:function(){ },//手指點擊錄音voice _ ing _ start:function(){ console . log( # 39;用手指點擊錄音 # 39;)wx . show toast({ title: # 39;按住錄音并釋放發送 # 39;,圖標: # 39;無 # 39;})this . setdata({ voice _ ing _ start _ date:new date()。gettime(),//記錄開始點擊的時間}) constoptions = {duration: 10000,//指定記錄的持續時間,單位ms sleRate: 8000,//采樣率numberOfChannels: 1,//記錄通道號encodibrate:24000,//編碼比特率格式: # 39;mp3 # 39,//音頻格式,有效值aac/mp3音頻源: # 39;auto # 39,frameSize: 12,//以KB為單位指定幀大小} recorder.start(options) //開始錄制this . animation = wx . create animation({ duration:1200,})//播放按鈕動畫this . animation . scale(0.8,0.8);//還原that . setdata({ spreading animation:that . animation . export()})},on ready:function(){ this . on _ recorder();},//記錄監控事件on _ recorder:function(){ console . log( # 39;聽事件 # 39;);recorder . onstart((RES)= gt;{ console . log( # 39;開始錄制 # 39;);})recorder . onstop((RES)= gt;{ let { tempFilePath } = resconsole . log( # 39;停止錄制,臨時路徑 # 39;,tempfile path);var x =新日期()。getTime()-this . data . voice _ ing _ start _ date if(x gt;1000) {讓時間戳=新日期()。getTime();wx . cloud . uploadfile({ cloudPath: ;聲音/ ;+時間戳+ # 39;. mp3 # 39,filePath: tempFilePath,success:RES = gt;{ console . log( # 39;上傳成功 # 39;,RES)that . setdata({ sound URL:RES . fileid,})var data = { _ qunId: # 39;fb16 f 7905 E4 BFA 24009098 DC 34 b 910 c 8 # 39;,_ openId:wx . getstoragesync( # 39;openId # 39),//消息正文: # 39;',voice: res.fileID,img: # 39;',//time dataTime: util.nowTime(),//avatar send outhand:wx . getstoragesync( # 39;userInfo # 39).avatarUrl,//昵稱send outname:wx . getstoragesync( # 39;userInfo # 39).昵稱} console . log(data)wx . cloud . call function({ name: ;新聞 ,data: data,success(RES){ console . log( # 39;發送語音發送 # 39;,res) },fail(RES){ console . log( # 39;發送語音失敗 # 39;,res) } }) },})} })recorder . onframerecorded((RES)= gt;{ return console . log( # 39;on frame recorded RES . frame buffer # 39;RES . frame buffer);string _ base64 = wx . arraybuffertobase 64(RES . frame buffer)console . log( # 39;string _ base64-- # 39;,string _ base64)}}},//釋放錄音voice _ ing _ end:function(){ console . log( # 39;松開手指進行錄制 # 39;)that . setdata({ voice _ icon _ click:false,animation data:{ } })this . animation = ;";var x =新日期()。getTime()-this . data . voice _ ing _ start _ date if(x lt;1000){ console . log( # 39;停止錄音,通話不到1秒!')wx . show modal({ title: # 39;提示 # 39;,內容: # 39;說話超過1秒!',})recorder . stop();} else {//錄音停止,recorder.stop()開始上傳;}},//點擊語音圖片voice _ icon _ Click:function(){ this . setdata({ voice _ icon _ Click:!This.data.voice _ icon _ click})}})以上是小程序聊天群的詳情,發送語音、文字、圖片。更多請關注主機參考其他相關文章!
這幾篇文章你可能也喜歡:
本文由主機參考刊發,轉載請注明:介紹小程序聊天群,發語音、文字、圖片(微信群發語音、圖片) http://www.k2270.com/79109.html
主機參考
















評論前必須登錄!
注冊