chat.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <view class="main">
  3. <view class="main">
  4. <chatSuitAudio
  5. ref="chatSuitAudio"
  6. :username="username"
  7. :chatType="chatType"
  8. @newAudioMsg="saveSendMsg"
  9. ></chatSuitAudio>
  10. <chatMsglist
  11. ref="chatMsglist"
  12. :username="username"
  13. @msglistTap="normalScroll"
  14. @clickMsg="clickMsg"
  15. id="chat-msglist"
  16. ></chatMsglist>
  17. </view>
  18. <chatInputbar
  19. ref="chatInputbar"
  20. :username="username"
  21. :chatType="chatType"
  22. @newTextMsg="saveSendMsg"
  23. @newImageMsg="saveSendMsg"
  24. @newLocationMsg="saveSendMsg"
  25. @newVideoMsg="saveSendMsg"
  26. @tapSendAudio="toggleRecordModal"
  27. @inputFocused="shortScroll"
  28. @inputBlured="normalScroll"
  29. @makeVideoCall="onMakeVideoCall"
  30. @makeAudioCall="onMakeAudioCall"
  31. v-show="!showEmediaInvite"
  32. ></chatInputbar>
  33. <chatEmediaInvite
  34. :username="username"
  35. :action="action"
  36. @onStartConfr="onStartConfr"
  37. @goBack="onGoBack"
  38. v-if="showEmediaInvite"/>
  39. <!-- <chatMultiEmedia
  40. style="{display: multiEmediaVisible}"
  41. :username="username"
  42. :groupId="groupId"
  43. :action="emediaAction"
  44. @inviteMember="onInviteMember"
  45. @createConfrSuccess="onCreateConfrSuccess"
  46. @hangup="onHangup"
  47. v-if="showmultiEmedia"/> -->
  48. </view>
  49. </template>
  50. <script>
  51. let msgStorage = require("./msgstorage");
  52. let msgType = require("./msgtype");
  53. import chatMsglist from "./msglist/msglist";
  54. import chatInputbar from "./inputbar/inputbar";
  55. import chatSuitAudio from "./inputbar/suit/audio/audio";
  56. import chatEmediaInvite from "./emediaInvite/emediaInvite.vue"
  57. import chatMultiEmedia from "./multiemedia/index.nvue"
  58. export default {
  59. data() {
  60. return {
  61. __comps__: {
  62. msglist: null,
  63. inputbar: null,
  64. audio: null,
  65. },
  66. inputbarVisible: 'block',
  67. action: null,
  68. pubUrl: '',
  69. subUrl: '',
  70. showEmedia: false,
  71. showmultiEmedia: false,
  72. showEmediaInvite: false,
  73. emediaAction: null,
  74. multiEmediaVisible: 'block',
  75. confrId: '',
  76. groupId: '',
  77. confrMember: []
  78. };
  79. },
  80. components: {
  81. chatMsglist,
  82. chatInputbar,
  83. chatSuitAudio,
  84. chatEmediaInvite,
  85. chatMultiEmedia
  86. },
  87. props: {
  88. username: {
  89. type: Object,
  90. default: () => ({}),
  91. },
  92. chatType: {
  93. type: String,
  94. default: msgType.chatType.SINGLE_CHAT,
  95. },
  96. },
  97. computed: {
  98. computedUserName(){
  99. return this.username
  100. }
  101. },
  102. mounted() {
  103. this.username = uni.username;
  104. uni.$on('createConfrSuccess', this.onCreateConfrSuccess)
  105. },
  106. moved() {},
  107. destroyed() {},
  108. methods: {
  109. toggleRecordModal() {
  110. this.$refs.chatSuitAudio.toggleRecordModal();
  111. },
  112. normalScroll() {
  113. this.$refs.chatMsglist.normalScroll();
  114. this.$refs.chatInputbar.cancelEmoji();
  115. this.$refs.chatInputbar.closeFunModal();
  116. },
  117. clickMsg(msg){
  118. this.$emit('onClickInviteMsg', msg)
  119. console.log('点击消息上一级', msg)
  120. },
  121. shortScroll() {
  122. this.$refs.chatMsglist.shortScroll();
  123. },
  124. saveSendMsg(evt) {
  125. msgStorage.saveMsg(evt.msg, evt.type);
  126. this.$refs.chatInputbar.cancelEmoji();
  127. this.$refs.chatInputbar.closeFunModal()
  128. },
  129. getMore() {
  130. this.$refs.chatMsglist.getHistoryMsg();
  131. },
  132. onMakeVideoCall(){
  133. this.showEmediaInvite= true
  134. this.inputbarVisible= 'none'
  135. this.action= 'create'
  136. console.log(this.showEmediaInvite)
  137. },
  138. onStartConfr(data){
  139. console.log('发起邀请的回调', data)
  140. this.showEmediaInvite= false
  141. this.showmultiEmedia= true
  142. this.multiEmediaVisible= 'block'
  143. this.inputbarVisible= 'none'
  144. this.confrMember= data.confrMember
  145. this.emediaAction={
  146. action: 'create'
  147. }
  148. this.$emit('onMakeVideoCall', {
  149. confrMember: data.confrMember,
  150. groupId: this.username.groupId
  151. })
  152. },
  153. onCreateConfrSuccess(data){
  154. console.log('创建会成功议回调', data)
  155. this.sconfrId= data.confrId
  156. getApp().globalData.confrId = data.confrId
  157. this.sendInviteMsg(this.confrMember, data.confrId, data)
  158. },
  159. onGoBack(){
  160. this.showEmediaInvite= false
  161. this.showmultiEmedia= true
  162. this.multiEmediaVisible= 'block'
  163. this.inputbarVisible= 'none'
  164. this.confrMember= []
  165. },
  166. onInviteMember(e){
  167. let username = this.username;
  168. if(!this.username.groupId){
  169. username.groupId = e.detail
  170. }
  171. this.action= 'invite'
  172. this.showEmediaInvite= true
  173. this.inputbarVisible= 'none'
  174. //showmultiEmedia: false
  175. this.multiEmediaVisible= 'none'
  176. },
  177. onMakeAudioCall(){
  178. this.showEmediaInvite= true
  179. this.showmultiEmedia= false
  180. this.inputbarVisible= 'none'
  181. },
  182. onClickInviteMsg(data){
  183. console.log('收到邀请消息')
  184. console.log(data)
  185. let confrId = data.conferenceId
  186. let msg_extension = typeof(data.msg_extension) == 'string'?JSON.parse(data.msg_extension):data.msg_extension
  187. let password = data.password || ''
  188. this.emediaAction= {
  189. action: 'join',
  190. confrId: confrId,
  191. password: password,
  192. roomName: data.roomName || ''
  193. },
  194. this.showEmediaInvite= false,
  195. this.showmultiEmedia= true,
  196. this.inputbarVisible= 'none',
  197. this.groupId= msg_extension.group_id
  198. },
  199. onHangup(){
  200. this.showEmediaInvite= false,
  201. this.showmultiEmedia= false,
  202. this.inputbarVisible= 'block'
  203. getApp().globalData.confrId = ''
  204. },
  205. sendInviteMsg(members, confrId, data){
  206. console.log("%c members","background: green")
  207. console.log(members)
  208. console.log('进入发邀请的函数', members)
  209. console.log('this.username.groupId----', this.username.groupId)
  210. console.log('confrId', confrId)
  211. console.log('data', data)
  212. members&&members.forEach((value) => {
  213. let id = uni.WebIM.conn.getUniqueId();
  214. let msg = new uni.WebIM.message('txt', id);
  215. msg.set({
  216. msg: wx.WebIM.conn.context.userId + ' invite you to video call',
  217. from: wx.WebIM.conn.context.userId,
  218. to: value,
  219. roomType: false,
  220. chatType: 'singleChat',
  221. ext: {
  222. msg_extension: JSON.stringify({
  223. inviter: wx.WebIM.conn.context.userId,
  224. group_id: this.username.groupId
  225. }),
  226. // roomName: data&&data.roomName || '',
  227. password: '123456',
  228. conferenceId: getApp().globalData.confrId
  229. },
  230. success(id, serverMsgId){
  231. console.log('发送邀请消息成功 to: '+value)
  232. //disp.fire('em.chat.sendSuccess', id, me.data.userMessage);
  233. },
  234. fail(id, serverMsgId){
  235. console.log('发送邀请消息失败了')
  236. }
  237. });
  238. // if(this.chatType == msgType.chatType.CHAT_ROOM){
  239. // msg.setGroup("groupchat");
  240. // }
  241. console.log('发送邀请', msg.body)
  242. uni.WebIM.conn.send(msg.body);
  243. })
  244. },
  245. },
  246. };
  247. </script>
  248. <style>
  249. @import "./chat.css";
  250. </style>