chatGroup.vue 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606
  1. <template>
  2. <view class="app">
  3. <view id="app-top">
  4. <uni-nav-bar statusBar backgroundColor="#f8f8f8" left-icon="left" @clickLeft="utils.navigateBack()" fixed >
  5. <view slot="right" @tap="tapMore">
  6. <image style="width: 30px;" src="/static/chat/chat-more.png" mode="widthFix"></image>
  7. </view>
  8. <view class="fx-r fx-bc fx-ac" style="width: 100%;">
  9. <view class="fx-r fx-bc fx-ac" v-if="isNetwork">
  10. <u-loading-icon size="18"></u-loading-icon>
  11. <text style="font-size: 14px;margin-left: 4px;">链接中..</text>
  12. </view>
  13. <text v-else style="text-overflow: ellipsis;white-space: nowrap;overflow: hidden;font-size: 14px;">
  14. {{chatUser == null ? '加载中..' : ( chatUser.name + '(' + chatUser.count + ')') }}
  15. </text>
  16. </view>
  17. </uni-nav-bar>
  18. </view>
  19. <view class="pop-alert" v-if="remindAr.length > 0" @tap="tapReminClose">
  20. <u-alert type="error" :description="getRemind()"></u-alert>
  21. <view class="t"><u-icon name="close"></u-icon></view>
  22. </view>
  23. <scroll-view class="wechat-body" :style="'height:calc(100vh - ' + barheight + 'px - ' + fotInputheight + 'px - ' + inputBottom + 'px)'" scroll-y="true" @scrolltoupper="tapTupper" :scroll-with-animation="scrollAnimation" :scroll-into-view="'view_' + scrollMsgId">
  24. <view class="loading fx-r fx-ac fx-bc" v-if="loaData.isLoad">
  25. <image src="/static/chat/xloading.png"></image>
  26. </view>
  27. <view style="height: 10px;"></view>
  28. <view class="chat-item" :id="'view_' + item.msgId" v-for="(item,index) in data">
  29. <view class='fx-h fx-bc fx-ac' v-if="item.isShowTime == 1">
  30. <view class="msg-time">{{utils.timeLastdate(item.time,true)}}</view>
  31. </view>
  32. <!-- 文字内容 -->
  33. <chatMsg v-if="item.type =='text'" @longUserItem="tapLongUserItem" @userItem="tapUserItem" @longItem="tapLongItem" @rsend="tapRsend(item.msgId)" :item="item"></chatMsg>
  34. <!--发送图片-->
  35. <chatImg v-if="item.type =='img'" @longUserItem="tapLongUserItem" @userItem="tapUserItem" @longItem="tapLongItem" @openImg="tapOpenImg" @rsend="tapRsend(item.msgId)" :item="item"></chatImg>
  36. <!--发送红包-->
  37. <chatRed :key="theKey" @userItem="tapUserItem" v-if="item.type =='red_envelope'" @redItem="tapRedItem" :item="item"></chatRed>
  38. <!--语音消息-->
  39. <chatVoice v-if="item.type =='voice'" @longUserItem="tapLongUserItem" @userItem="tapUserItem" @rsend="tapRsend(item.msgId)" :item="item"></chatVoice>
  40. <!--群公告-->
  41. <chatGroupMsg v-if="item.type =='group_text'" @userItem="tapUserItem" @rsend="tapRsend(item.msgId)" :item="item"></chatGroupMsg>
  42. <!--红包情况-->
  43. <chatTip v-if="['red_envelope_tip','tip','group_del','withdraw'].indexOf(item.type) >= 0" :item="item"></chatTip>
  44. </view>
  45. </scroll-view>
  46. <view class="foot-view-info" id="foot-view-info">
  47. <view class="foot-view fx-r fx-bc">
  48. <image class="icon" src="/static/chat/voice.svg" @tap="tapRecord"></image>
  49. <textarea auto-height maxlength="-1" @input="tapInput" class="fx-g1 limited-height" v-model="msg" :focus="focus" @focus="tapFoucus" :confirm-hold="true" :hold-keyboard="true" :adjust-position="false" @blur="tapBlur" ></textarea>
  50. <image @tap="tapCkFace(true)" class="icon" src="/static/chat/face.svg" v-if="!isFace"></image>
  51. <image @tap="tapCkFace(false)" class="icon" src="/static/chat/cmore.svg" v-else></image>
  52. <image @tap="tapOpenGroup" class="icon" style="width: 28px;height: 28px;" v-if="msg == ''" src="/static/chat/cadd.svg"></image>
  53. <view class="send-btn" @tap="tapSend" v-else>发送</view>
  54. </view>
  55. <!--表情-->
  56. <view class="face-view" :hidden="!isFace">
  57. <swiper class="swiper" circular :indicator-dots="true">
  58. <swiper-item v-for="item in faceAr">
  59. <view class="face-items fx-r fx-bc">
  60. <view class="item fx-h fx-bc fx-ac" v-for="(item2,index) in item">
  61. <image @tap="tapFaceSet(item2)" :src="'../../static/face/face_' + item2.key + '.png'" mode="widthFix"></image>
  62. </view>
  63. </view>
  64. </swiper-item>
  65. </swiper>
  66. </view>
  67. <recording ref="recording" @end="tapRecordH5"></recording>
  68. <!--收藏-->
  69. <view class="group-view" :hidden="!isGroup">
  70. <scroll-view scroll-y>
  71. <view class="group-items fx-r fx-bc" >
  72. <view class="item fx-h fx-bc fx-ac" @tap="tapPhoto">
  73. <view class="item-bg fx-h fx-bc fx-ac"><image src="../../static/chat/chat-phone.svg"></image></view>
  74. <view class="text">相册</view>
  75. </view>
  76. <view class="item fx-h fx-bc fx-ac" @tap="tapCamera">
  77. <view class="item-bg fx-h fx-bc fx-ac"><image src="../../static/chat/chat-camera.svg"></image></view>
  78. <view class="text">拍摄</view>
  79. </view>
  80. <view class="item fx-h fx-bc fx-ac" @tap="tapOpen" :data-url="'./redpack/red?groupId=' + groupId + '&type=chat_group'">
  81. <view class="item-bg fx-h fx-bc fx-ac"><image src="../../static/chat/chat-reg.svg"></image></view>
  82. <view class="text">红包</view>
  83. </view>
  84. <view class="item fx-h fx-bc fx-ac" @tap="tapCollectList">
  85. <view class="item-bg fx-h fx-bc fx-ac"><image src="../../static/chat/chat-collect.svg"></image></view>
  86. <view class="text">收藏</view>
  87. </view>
  88. </view>
  89. </scroll-view>
  90. </view>
  91. </view>
  92. <view class="red-lq fx-h fx-bc fx-ac" v-if="isOpenRed">
  93. <view class="bg fx-h fx-bc">
  94. <image class="bg-img" src="../../static/chat/group_award_background.png" ></image>
  95. <view class="red-close" @tap="isOpenRed = false">
  96. <u-icon name="close" color="#ffffff" size="18"></u-icon>
  97. </view>
  98. <view class="red-tip fx-h fx-bc">
  99. <image :src="utils.getAvatar(lqRed.sendUser.avatar,'chat')" mode="aspectFill"></image>
  100. <text>{{lqRed.sendUser.nickname}}的红包</text>
  101. </view>
  102. <view class="red-lv" v-if="lqRed.state == 1" :class="redAnim" @tap="tapOpenLv">
  103. <image src="../../static/chat/open_group_award_icon.png" mode="widthFix"></image>
  104. </view>
  105. <view class="red-lm" v-if="lqRed.state == 2" >
  106. <view class="red-sm">手慢了,红包派完了</view>
  107. <view class="red-look" @tap="tapOpen" :data-url="'redpack/look?id=' + lqRed.data.id" >查看红包详情></view>
  108. </view>
  109. </view>
  110. </view>
  111. <view class="pop-win" v-if="isPopAt">
  112. <view class="bg" @tap="tapHidePopAt"></view>
  113. <view class="pop-body" :style="{transform : isPopAt2 ? 'translateY(0)' : 'translateY(100%)'}">
  114. <view class="key_main fx-h">
  115. <view class="nav-top">
  116. <u-icon name="arrow-down" @tap="tapHidePopAt"></u-icon>
  117. <view class="title">请选择提醒的人</view>
  118. </view>
  119. <view class="search-view">
  120. <u--input
  121. placeholder="搜索联系人"
  122. prefixIcon="search"
  123. clearable
  124. border="none"
  125. prefixIconStyle="font-size: 22px;color: #909399"
  126. v-model="popKeyword"
  127. @input="tapPopKeyWord"
  128. ></u--input>
  129. </view>
  130. <scroll-view class="pop-win-scroll" scroll-y :scroll-into-view="toView" scroll-with-animation='true' show-scrollbar="false" >
  131. <view class="item fx-r fx-bc" @tap="taopPopItem(item2)" v-for="(item2,index2) in chatUserList">
  132. <image :src="item2.avatar" mode="aspectFill"></image>
  133. <view class="info fx-h fx-ac">
  134. <rich-text class="title" :nodes="getRanValue(item2.nickname)"></rich-text>
  135. </view>
  136. </view>
  137. <view class="loading fx-r fx-ac fx-bc" v-if="user.isFrite && !user.isFoot">
  138. <image src="/static/chat/xloading.png"></image>
  139. <text>正在载入更多...</text>
  140. </view>
  141. <view class="loading complete" :hidden="!user.isFoot">已加载全部</view>
  142. </scroll-view>
  143. </view>
  144. </view>
  145. </view>
  146. <view class="mb2-tip" v-if="showOpen">
  147. <view class="bg" @tap="showOpen = false"></view>
  148. <view class="pop-view" :style="'left:' + showLeft+ 'px;top:' + showTop + 'px'">
  149. <view class="pop-lv"></view>
  150. <view v-if="showData.type == 'text'">
  151. <view class="item fx-r fx-bc" @tap="tapCopy">复制</view>
  152. <view class="item fx-r fx-bc" @tap="tapAddCollection">收藏</view>
  153. <view class="item fx-r fx-bc" @tap="tapZf">转发</view>
  154. <view class="item fx-r fx-bc" v-if="showData.sendUser.uid == user.uid && (utils.strtotime() - showData.time ) < 60 * 5" @tap="tapWithdraw">撤回</view>
  155. </view>
  156. <view v-if="showData.type == 'img'">
  157. <view class="item fx-r fx-bc" @tap="tapAddCollection">收藏</view>
  158. <view class="item fx-r fx-bc" @tap="tapDown">下载图片</view>
  159. <view class="item fx-r fx-bc" @tap="tapZf">转发</view>
  160. <view class="item fx-r fx-bc" v-if="showData.sendUser.uid == user.uid && (utils.strtotime() - showData.time ) < 60 * 5" @tap="tapWithdraw">撤回</view>
  161. </view>
  162. <view v-if="showData.type == 'voice'">
  163. <view class="item fx-r fx-bc" @tap="tapAddCollection">收藏</view>
  164. <view class="item fx-r fx-bc" @tap="tapZf">转发</view>
  165. <view class="item fx-r fx-bc" v-if="showData.sendUser.uid == user.uid && (utils.strtotime() - showData.time ) < 60 * 2" @tap="tapWithdraw">撤回</view>
  166. </view>
  167. </view>
  168. </view>
  169. </view>
  170. </template>
  171. <style lang="scss">
  172. .pop-win{position: fixed;width: 100%;height: 100%;left: 0;top: 0;}
  173. .pop-win .bg{position: absolute;width: 100%;height: 100%;left: 0;top: 0;background: rgba(0, 0, 0, 0.5);}
  174. .pop-body{width:100vw;height: 100vh;position: fixed;bottom: 0px;top:0px;left:0px;right:0px;z-index:100;display: flex;flex-direction: column;justify-content: flex-end;transform: translateY(100%);transition:all 0.4s;}
  175. .key_main{ width:100vw;height: 900rpx;background: #fff;box-sizing: border-box;display: flex;flex-direction: column;}
  176. .key_main .nav-top{height: 40px;position: relative;}
  177. .key_main .nav-top .title{text-align: center;font-size: 14px;color: #000;line-height: 40px;}
  178. .key_main .u-icon{position: absolute;left: 10px;top: 20px;}
  179. .key_main .search-view{height: 40px;padding: 10px;}
  180. .key_main scroll-view{height:calc(100% - 90px);}
  181. .pop-win-scroll .item{background: #fff;padding:0 10px;position: relative;}
  182. .pop-win-scroll .item:active{background: #f1f1f1;}
  183. .pop-win-scroll .item image{width: 40px;height: 40px;border-radius: 50%;}
  184. .pop-win-scroll .item .info{width: calc(100% - 70px);margin-left: 10px;font-size: 14px;color:#787878;border-bottom: 1px solid #f1f1f1;height: 60px;}
  185. .pop-win-scroll .item .flg{background: #ff5857;width: 20px;height: 20px;border-radius: 50%;font-size: 10px;text-align: center;line-height: 20px;color: #fff;}
  186. .pop-win-scroll .item:last-child .info{border-bottom: 0;}
  187. .pop-win-scroll .letter{padding: 10px;background: #F8F6F6;}
  188. .limited-height{
  189. height: 300rpx;
  190. }
  191. .red-lq{position: fixed;height: 100%;width: 100%;background: rgba(0, 0, 0, 0.5);left: 0;top: 0;z-index: 10;}
  192. .red-lq .bg{position: relative;width: 100%;}
  193. .red-lq .bg image.bg-img{width: 80%;height: 70vh;}
  194. .red-tip{position: absolute;color: #ffdfb0;margin-top: 30px;font-weight: 14px;}
  195. .red-tip image{width: 50px;height: 50px;border-radius: 50px;}
  196. .red-tip text{margin-top: 10px;}
  197. .red-lq .red-close{position: absolute;left: 55px;top: 14px;}
  198. .red-lv{position: absolute;bottom: 25%;}
  199. .red-lv image{width: 100px;}
  200. .anim-rotate {
  201. transform-style: preserve-3d;
  202. animation: rotate 1s linear infinite;
  203. }
  204. @keyframes rotate{
  205. 0%{
  206. transform: rotateY(0deg);
  207. }
  208. 100%{
  209. transform: rotateY(360deg);
  210. }
  211. }
  212. .red-lm{position: absolute;bottom: 15%;font-size: 14px;color: #ffdfb0;}
  213. .red-look{padding: 6px 0; }
  214. .wechat-body{background: #F1F1F1;position: relative;}
  215. .foot-view{padding:10px;background: #fff;width: calc(100% - 20px);bottom: 0;min-height: 40px;}
  216. .foot-view .icon{width: 30px;height: 30px;margin: 0px 4px;}
  217. .foot-view textarea{width: auto;background: #f1f1f1;border-radius: 6px;height: 20px;margin: 0px 4px;padding: 10px 10px;font-size: 14px;}
  218. .foot-view-info{background: #fff;}
  219. .msg-time{font-size: 14px;color: #ccc;}
  220. .send-btn{background: $ic-appcolor;color: #fff;font-size: 12px;padding:6px 10px;border-radius: 6px;margin-left: 2px ;}
  221. .send-btn:active{background: #dddddd;}
  222. .face-view{width: 100%;z-index: 9;background: #fff;height: 250px;}
  223. .face-view swiper{height: 250px;}
  224. .face-view .face-items{padding: 10px;}
  225. .face-view .face-items .item{width: 12.5%;height: calc((100vw - 20px) / 8 );}
  226. .face-view .face-items .item image{width: 50%;}
  227. .group-view{width: 100%;z-index: 9;background: #F1F1F1;}
  228. .group-view scroll-view{height: 100%;}
  229. .group-view .group-items{padding: 10px;}
  230. .group-view .group-items .item{width: 25%;padding: 10px 0;}
  231. .group-view .group-items .item .item-bg{width: 50px;height:50px;background: #fff;border-radius: 10px;}
  232. .group-view .group-items .item .item-bg image{width: 20px;height: 20px;}
  233. .group-view .group-items .item .text{font-size: 12px;margin-top: 4px;color: $ic-default-text;}
  234. .mb2-tip{position: fixed;width: 100%;height: 100%;top: 0;left: 0;z-index: 999;}
  235. .mb2-tip .bg{width: 100%;height: 100%;top: 0;left: 0;position: absolute;}
  236. .mb2-tip .pop-view{position: absolute;background: #fff;border-radius: 6px;border: 1px solid #f1f1f1;padding: 10px 20px;top: 56px;z-index: 9;left: 20px;}
  237. .mb2-tip .pop-view .item{padding:10px 0;}
  238. .mb2-tip .pop-view .item:active{background: #f1f1f1;}
  239. .pop-alert{position: relative;}
  240. .pop-alert .t{position: absolute;z-index: 99;top: 10px;right: 10px;}
  241. </style>
  242. <script>
  243. import {mapState,mapMutations } from 'vuex';
  244. import chatMsg from "@/components/tm-public/chat/msg.vue";
  245. import chatImg from "@/components/tm-public/chat/cimg.vue";
  246. import chatRed from "@/components/tm-public/chat/red.vue";
  247. import chatTip from "@/components/tm-public/chat/tip.vue";
  248. import chatRedTranfer from "@/components/tm-public/chat/redTransfer.vue";
  249. import chatRedEnvelopeTransfer from "@/components/tm-public/chat/redEnvelopeTransfer.vue";
  250. import chatRedEnvelopeTransferRefund from "@/components/tm-public/chat/redEnvelopeTransferRefund.vue";
  251. import chatGroupMsg from "@/components/tm-public/chat/chatGroupMsg.vue";
  252. import chatVoice from "@/components/tm-public/chat/voice.vue";
  253. // #ifdef H5
  254. import recording from '@/components/tm-public/recording/recordingH5.vue';//H5
  255. // #endif
  256. // #ifdef APP
  257. import recording from '@/components/tm-public/recording/recordingApp.vue';//APP
  258. // #endif
  259. import Message from "@/library/socket/Message.js";
  260. import face from "@/library/utils/Face.js";
  261. var LetterList = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','#'];
  262. const inputHeight = 260;
  263. export default {
  264. computed: mapState(['user','sysData']),
  265. components:{
  266. chatMsg,
  267. chatImg,
  268. chatRed,
  269. chatTip,
  270. chatRedTranfer,
  271. chatRedEnvelopeTransfer,
  272. chatRedEnvelopeTransferRefund,
  273. chatGroupMsg,
  274. chatVoice,
  275. recording
  276. },
  277. data() {
  278. return {
  279. isNetwork : false,
  280. data : [],
  281. chatUser : null,
  282. msg : "",
  283. barheight : 0,
  284. groupId : 0,
  285. usercode : "",
  286. showOpen : false,
  287. showData : {},
  288. showLeft : "",
  289. showTop : "",
  290. theKey : 0,
  291. inputBottom : 0,
  292. keyHeight : 0,
  293. isShowTop : false,
  294. scrollMsgId : "",
  295. showInput : false,
  296. scrollAnimation : false,
  297. focus : false,
  298. isFace : false,
  299. faceAr : [],
  300. isGroup : false,
  301. loaData:{
  302. isFrite : true,
  303. isFoot : false,
  304. isLoad : false,
  305. page : 1,
  306. },
  307. tempFilePaths : [],
  308. redAnim : "",
  309. isOpenRed : false,
  310. lqRed : {},
  311. redLqBack : [],
  312. fotInputheight : 0,
  313. /**提醒人**/
  314. isPopAt : false,
  315. isPopAt2 : false,
  316. toView : "",
  317. chatUserList: [],
  318. letter : [],
  319. popKeyword : "",
  320. popItemIn : [],
  321. msgId : "",
  322. nid : 0,
  323. userGroup : {
  324. isFirst:false,
  325. isLoad:false,
  326. isFoot:false,
  327. page:1
  328. },
  329. mbAr : {},
  330. remindAr : []
  331. }
  332. },
  333. onLoad(option){
  334. this.groupId = option.groupId;
  335. this.usercode = option.usercode || "";
  336. this.msgId = option.msgId || "";
  337. this.nid = option.nid || 0;
  338. var strRed = uni.getStorageSync("chat_red_" + this.groupId);
  339. if(strRed != null && strRed != '') {
  340. this.redLqBack = JSON.parse(strRed);
  341. }
  342. this.$nextTick(() => {
  343. uni.createSelectorQuery().select("#app-top").boundingClientRect(res=>{
  344. this.barheight = res == null ? 40 : (res.height + 10);
  345. if(this.$device.platform == 'ios') {
  346. this.barheight = res.height + 60;
  347. }
  348. }).exec();
  349. uni.createSelectorQuery().select("#foot-view-info").boundingClientRect(res=>{
  350. this.fotInputheight = res.height;
  351. }).exec();
  352. });
  353. uni.$on('socketMessage',this.socketMessage);
  354. uni.$on('redTransferCheck',this.redTransferCheck);
  355. uni.$on('chatClear',this.chatClear);
  356. uni.$on('chatDel',this.chatDel);
  357. uni.$on('glRkName',this.glRkName);
  358. uni.$on('socketOpen',this.socketOpen);
  359. uni.$on('socketClose',this.socketClose);
  360. let faceAr = [];
  361. let nI = 0;
  362. let index = 0;
  363. faceAr[0] = [];
  364. for(let i in face.face) {
  365. if(nI <= faceAr.length && index == 0) {
  366. faceAr[nI] = [];
  367. }
  368. faceAr[nI].push({
  369. key : i,
  370. value : face.face[i].value
  371. });
  372. index ++;
  373. if(index >= 40) {
  374. index = 0;
  375. nI++;
  376. }
  377. }
  378. this.faceAr = faceAr;
  379. this.getInit();
  380. },
  381. onUnload() {
  382. uni.$off('socketMessage',this.socketMessage);
  383. uni.$off('redTransferCheck',this.redTransferCheck);
  384. uni.$off('chatClear',this.chatClear);
  385. uni.$off('chatDel',this.chatDel);
  386. uni.$off('glRkName',this.glRkName);
  387. uni.$off('socketOpen',this.socketOpen);
  388. uni.$off('socketClose',this.socketClose);
  389. },
  390. onShow() {
  391. this.onKeyboardHeight();
  392. this.isNetwork = !this.webSocket.socketOpen;
  393. },
  394. methods: {
  395. ...mapMutations(['checkUserLogin','setSys','setTxbagenum']),
  396. /**
  397. * 基本数据
  398. */
  399. getInit:function(){
  400. this
  401. .request
  402. .post("chatGroupInit",{groupId:this.groupId})
  403. .then(res=>{
  404. if(res.code == 200) {
  405. this.chatUser = res.data;
  406. this.getData(true);
  407. this.chatRead(true);
  408. } else {
  409. uni.navigateBack({ delta:1});
  410. uni.showModal({title: '系统提示',content:res.msg,showCancel: false});
  411. }
  412. })
  413. .catch(err=>{
  414. uni.navigateBack({ delta:1});
  415. uni.showModal({title: '系统提示',content:"加载失败",showCancel: false});
  416. });
  417. this
  418. .request
  419. .post("GroupRemind",{groupId:this.groupId})
  420. .then(res => {
  421. if(res.code == 200) {
  422. this.remindAr = res.data;
  423. }
  424. })
  425. .catch(err=>{});
  426. },
  427. /**
  428. *
  429. */
  430. getData:function(isPull = false){
  431. if(this.user == null){
  432. return;
  433. }
  434. this
  435. .request
  436. .post("chatMsg",{group_id:this.groupId,page:this.loaData.page,nid:this.nid})
  437. .then(res=>{
  438. if(res.code == 200) {
  439. this.loaData.isLoad = false;
  440. this.isDisabled = false;
  441. if (isPull) {
  442. this.data = res.data.list;
  443. if(res.data.list.length > 0)
  444. if(this.msgId != '') {
  445. this.setScrollInto(this.msgId);
  446. } else {
  447. this.setScrollInto(res.data.list[res.data.list.length - 1].msgId);
  448. }
  449. } else {
  450. this.getDescData(res.data.list,'down');
  451. }
  452. if (res.data.list.length != res.data.pageSize) {
  453. this.loaData.isFoot = true;
  454. }
  455. this.loaData.isFrite = false;
  456. this.getwcTime();
  457. } else {
  458. uni.showModal({title: '系统提示',content: res.msg,showCancel: false});
  459. }
  460. });
  461. },
  462. /**
  463. * 上拉加载
  464. */
  465. tapTupper:function(){
  466. if(this.loaData.isFoot || this.loaData.isLoad || this.loaData.isFrite) {
  467. return;
  468. }
  469. this.loaData.isLoad = true;
  470. this.loaData.page ++;
  471. this.getData();
  472. },
  473. /**
  474. * 得到焦点
  475. * @param {Object} e
  476. */
  477. tapFoucus:function(e){
  478. this.showInput = true;
  479. var bfn = ()=>{
  480. this.isFace = false;
  481. this.isGroup = false;
  482. this.isRecord = false;
  483. this.$refs['recording'].hide();
  484. //this.inputBottom = 0;
  485. this.lastScrollInto();
  486. };
  487. setTimeout(()=>{
  488. bfn()
  489. },100);
  490. },
  491. /**
  492. * 失去焦点
  493. * @param {Object} e
  494. */
  495. tapBlur:function(e){
  496. setTimeout(()=>{
  497. this.showInput = false;
  498. },100);
  499. },
  500. onKeyboardHeight: function() {
  501. uni.onKeyboardHeightChange(res => {
  502. this.$set(this,'inputBottom',res.height);
  503. if(res.height > this.keyHeight) this.keyHeight = res.height;
  504. });
  505. },
  506. /**
  507. * 计算时间
  508. */
  509. getwcTime:function(){
  510. var time = 0;
  511. for(var i in this.data){
  512. var d = this.data[i];
  513. if(time == 0 || (d.time - time) > 3 * 60) {
  514. this.data[i].isShowTime = 1;
  515. time = d.time;
  516. } else {
  517. this.data[i].isShowTime = 0;
  518. }
  519. if(['red_envelope_transfer','red_envelope'].indexOf(d.type) >= 0) {
  520. if(this.redLqBack.indexOf(this.data[i].msgId) >= 0) {
  521. d.isReceiveRed = true;
  522. this.$set(this.data,i,d);
  523. } else {
  524. this.data[i].isReceiveRed = false;
  525. }
  526. } else {
  527. this.data[i].isReceiveRed = false;
  528. }
  529. }
  530. this.theKey ++;
  531. },
  532. /**
  533. *
  534. * @param {Object} data
  535. */
  536. getDescData:function(data,desc = 'down'){
  537. var msgId = "";
  538. if(desc == 'down') {
  539. if(this.data.length > 0) {
  540. msgId = this.data[0].msgId;
  541. }
  542. var newData = [];
  543. for(var i in data) {
  544. var d = data[i];
  545. if(!this.findData(d.msgId)) {
  546. newData.push(d);
  547. }
  548. }
  549. this.$forceUpdate();
  550. this.data = newData.concat(this.data);
  551. this.scrollAnimation = false;
  552. this.setScrollInto(msgId);
  553. }
  554. //
  555. if(desc == 'up') {
  556. var newData = [];
  557. for(var i in data) {
  558. var d = data[i];
  559. if(!this.findData(d.msgId)) {
  560. newData.push(d);
  561. msgId = d.msgId;
  562. }
  563. }
  564. this.$forceUpdate();
  565. this.data = this.data.concat(newData);
  566. this.scrollAnimation = true;
  567. this.setScrollInto(msgId);
  568. }
  569. },
  570. /**
  571. * 设置滚动位置
  572. * @param {Object} msgId
  573. */
  574. setScrollInto:function(msgId){
  575. if(msgId == "") return ;
  576. setTimeout(()=>{ this.scrollMsgId = msgId; },200);
  577. },
  578. /**
  579. * 弹出上去到底
  580. */
  581. lastScrollInto:function(){
  582. this.scrollMsgId = "1";
  583. if(this.data.length <= 2) return;
  584. setTimeout(()=>{
  585. this.scrollMsgId = this.data[this.data.length - 1].msgId;
  586. },200);
  587. },
  588. /**
  589. * 打开图片
  590. * @param {Object} img
  591. */
  592. tapOpenImg:function(img) {
  593. var imgs = [];
  594. for(var i in this.data) {
  595. if(this.data[i].type == 'img') imgs.push(this.data[i].data);
  596. }
  597. uni.previewImage({current:img,urls:imgs});
  598. },
  599. /**
  600. * 查询重复数据
  601. * @param {Object} msgId
  602. */
  603. findData:function(msgId) {
  604. for(var i in this.data) {
  605. if(this.data[i].msgId == msgId) return true;
  606. }
  607. return false;
  608. },
  609. /**
  610. * 发送消息
  611. */
  612. tapSend:function(){
  613. if(this.msg == '') {
  614. return;
  615. }
  616. var bb = this.msg.match(/\@(.*?) /g);
  617. var ddAr = [];
  618. for(var i in bb) {
  619. var nickname = bb[i].trim();
  620. nickname = nickname.substr(1,nickname.length - 1);
  621. for(var i in this.chatUserList) {
  622. if(this.chatUserList[i].nickname == nickname) {
  623. ddAr.push(this.chatUserList[i].uid);
  624. }
  625. }
  626. }
  627. //消息发送
  628. var msgId = this.webSocket.createMsgId();
  629. var sendPack = {};
  630. sendPack.data = this.msg;
  631. sendPack.type = "text";
  632. sendPack.chat_id = "";
  633. sendPack.f_uid = "";
  634. sendPack.msg_id = msgId;
  635. sendPack.group_id = this.groupId;
  636. sendPack.remind_id = ddAr.length > 0 ? ddAr.join(',') : '';
  637. var mess = new Message(JSON.stringify(sendPack),"groupChat",true,1,true);
  638. mess.id = msgId;
  639. //消息添加
  640. var data = {};
  641. data.chat = this.chatUser.chat;
  642. data.sendUser = {
  643. nickname : this.chatUser.meUser.nickname,
  644. avatar : this.user.avatar,
  645. uid : this.user.uid
  646. };
  647. data.group_type = 'group_chat';
  648. data.type = 'text';
  649. data.data = this.msg;
  650. data.is_remind = 0;
  651. data.isSend = 0;
  652. data.time = this.utils.strtotime();
  653. data.nid = 0;
  654. data.msgId = msgId;
  655. var bool = this.webSocket.send(mess,(res)=>{
  656. for(var i in this.data) {
  657. if(this.data[i].msgId == msgId) {
  658. this.$set(this.data[i],'isSend',1);
  659. this.chatRead();
  660. break;
  661. }
  662. }
  663. },err=>{
  664. for(var i in this.data) {
  665. if(this.data[i].msgId == msgId) {
  666. this.$set(this.data[i],'isSend',-1);
  667. break;
  668. }
  669. }
  670. });
  671. this.data.push(data);
  672. this.getwcTime();
  673. this.setScrollInto(msgId);
  674. this.msg = '';
  675. },
  676. tapRsend:function(msgId){
  677. var item = null;
  678. for(var i in this.data) {
  679. if(this.data[i].msgId == msgId) {
  680. this.$set(this.data[i],'isSend',0);
  681. item =this.data[i];
  682. break;
  683. }
  684. }
  685. if(item == null) return;
  686. var sendPack = {};
  687. sendPack.data = item.data;
  688. sendPack.type = item.type;
  689. sendPack.chat_id = "";
  690. sendPack.f_uid = "";
  691. sendPack.msg_id = item.msgId;
  692. sendPack.group_id = this.groupId;
  693. sendPack.remind_id = "";
  694. var mess = new Message(JSON.stringify(sendPack),"groupChat",true,1,true);
  695. mess.id = data.msgId;
  696. var bool = this.webSocket.send(mess,(res)=>{
  697. let isSend = false;
  698. if(this.utils.isJSON(res)) {
  699. let rAr = JSON.parse(res);
  700. if(rAr.code == 1) {
  701. isSend = true;
  702. } else {
  703. this.utils.Tip(rAr.msg);
  704. }
  705. }
  706. for(var i in this.data) {
  707. if(this.data[i].msgId == msgId) {
  708. this.$set(this.data[i],'isSend',isSend ? 1 : -1);
  709. if(isSend) this.chatRead();
  710. break;
  711. }
  712. }
  713. },err=>{
  714. for(var i in this.data) {
  715. if(this.data[i].msgId == msgId) {
  716. this.$set(this.data[i],'isSend',-1);
  717. break;
  718. }
  719. }
  720. });
  721. },
  722. /**
  723. * 选择相机
  724. */
  725. tapPhoto:function(){
  726. // #ifdef APP-PLUS
  727. this.$store.dispatch('permission/requestPermissions', 'WRITE_EXTERNAL_STORAGE').then(res => {
  728. console.log(res);
  729. if(res !== 1) return;
  730. uni.chooseImage({
  731. count: 10,
  732. sizeType: ['compressed'], // 原图还是压缩图
  733. sourceType: ['album'], // 相册还是相机
  734. success: (res)=> {
  735. var tempFilePaths = res.tempFilePaths;//图片列表
  736. this.upFileImg(tempFilePaths);
  737. }
  738. });
  739. });
  740. return;
  741. // #endif
  742. uni.chooseImage({
  743. count: 10,
  744. sizeType: ['compressed'], // 原图还是压缩图
  745. sourceType: ['album'], // 相册还是相机
  746. success: (res)=> {
  747. var tempFilePaths = res.tempFilePaths;//图片列表
  748. this.upFileImg(tempFilePaths);
  749. }
  750. });
  751. },
  752. /**
  753. * 选择拍摄
  754. */
  755. tapCamera:function(){
  756. // #ifdef APP-PLUS
  757. this.$store.dispatch('permission/requestPermissions', 'WRITE_EXTERNAL_STORAGE').then(res => {
  758. console.log(res);
  759. if(res !== 1) return;
  760. uni.chooseImage({
  761. count: 1,
  762. sizeType: ['compressed'],
  763. sourceType: ['camera'],
  764. success:(res) => {
  765. var tempFilePaths = res.tempFilePaths;
  766. this.upFileImg(tempFilePaths);
  767. }
  768. });
  769. });
  770. return;
  771. // #endif
  772. uni.chooseImage({
  773. count: 1,
  774. sizeType: ['compressed'],
  775. sourceType: ['camera'],
  776. success:(res) => {
  777. var tempFilePaths = res.tempFilePaths;
  778. this.upFileImg(tempFilePaths);
  779. }
  780. });
  781. },
  782. /**
  783. * 切换表情
  784. */
  785. tapCkFace:function(bool){
  786. var bfn = ()=>{
  787. this.isFace = bool;
  788. if(bool){
  789. this.isGroup = false;
  790. this.isRecord = false;
  791. this.$refs['recording'].hide();
  792. this.inputBottom = this.keyHeight > 0 ? this.keyHeight : inputHeight;
  793. this.lastScrollInto();
  794. } else {
  795. this.inputBottom = 0;
  796. }
  797. uni.hideKeyboard();
  798. };
  799. if(this.showInput) {
  800. setTimeout(()=>{
  801. bfn()
  802. },100);
  803. } else {
  804. bfn();
  805. }
  806. },
  807. /**
  808. * 切换更多
  809. */
  810. tapOpenGroup:function(){
  811. this.isFace = false;
  812. this.isRecord = false;
  813. this.$refs['recording'].hide();
  814. var bfn = ()=>{
  815. this.isGroup = ! this.isGroup;
  816. if(this.isGroup){
  817. this.inputBottom = this.keyHeight > 0 ? this.keyHeight : inputHeight;
  818. this.lastScrollInto();
  819. } else {
  820. this.inputBottom = 0;
  821. }
  822. uni.hideKeyboard();
  823. };
  824. if(this.showInput) {
  825. setTimeout(()=>{
  826. bfn()
  827. },100);
  828. } else {
  829. bfn();
  830. }
  831. },
  832. /**
  833. * 设置face
  834. * @param {Object} index
  835. */
  836. tapFaceSet:function(item) {
  837. console.log(item);
  838. this.msg += item.value;
  839. },
  840. /**
  841. * 通讯数据
  842. * @param {Object} res
  843. */
  844. socketMessage:function(res){
  845. if(res.code == null) return;
  846. var uData = JSON.parse(res.data);
  847. if(this.groupId == uData.group_id) {
  848. for(var i in this.data) {
  849. if(this.data[i].msgId == uData.msgId) return;
  850. }
  851. if(uData.is_remind == 1) {
  852. let isAdd = true;
  853. for(let i in this.remindAr) {
  854. if(this.remindAr[i].uid == uData.sendUser.uid) {
  855. isAdd = false;
  856. }
  857. }
  858. if(isAdd) {
  859. this.remindAr.push({
  860. uid : uData.sendUser.uid,
  861. nickname : uData.sendUser.nickname
  862. });
  863. }
  864. }
  865. if(uData.type == "withdraw") {
  866. for(var i in this.data) {
  867. if(uData.data == this.data[i].msgId) {
  868. this.$delete(this.data,i);
  869. }
  870. }
  871. }
  872. if(!this.getRepeat(this.data,uData.msgId)) {
  873. this.data.push(uData);
  874. setTimeout(()=>{ this.scrollMsgId = uData.msgId; },200);
  875. this.chatRead();
  876. }
  877. }
  878. },
  879. /**
  880. * 网络链接成功
  881. */
  882. socketOpen:function(){
  883. this.isNetwork = false;
  884. },
  885. /**
  886. * 网络关闭 | 需重新链接
  887. */
  888. socketClose:function(){
  889. //console.log('xxx');
  890. this.isNetwork = true;
  891. },
  892. /**
  893. * 清理数据
  894. * @param {Object} group_id
  895. */
  896. chatClear:function(group_id){
  897. if(group_id == this.groupId) {
  898. this.data = [];
  899. this.$forceUpdate();
  900. }
  901. },
  902. /**
  903. * 清理数据
  904. * @param {Object} group_id
  905. */
  906. chatDel:function(group_id){
  907. uni.navigateBack({fail:1});
  908. },
  909. /**
  910. * 上传图片
  911. * @param {Object} tempFilePaths
  912. */
  913. upFileImg:function(tempFilePaths) {
  914. var msgId = "";
  915. for (var i in tempFilePaths) {
  916. msgId = this.webSocket.createMsgId();
  917. var data = {};
  918. data.chat = this.chatUser.chat;
  919. data.sendUser = {
  920. nickname : this.chatUser.meUser.nickname,
  921. avatar : this.user.avatar,
  922. uid : this.user.uid
  923. };
  924. data.group_type = 'group_chat';
  925. data.type = "img";
  926. data.data = tempFilePaths[i];
  927. data.is_remind = 0;
  928. data.isSend = 0;
  929. data.time = this.utils.strtotime();
  930. data.nid = 0;
  931. data.msgId = msgId;
  932. this.data.push(data);
  933. this.tempFilePaths.push(data);
  934. }
  935. this.upActionImg();
  936. setTimeout(()=>{
  937. this.scrollMsgId = msgId;
  938. },200);
  939. this.getwcTime()
  940. },
  941. /**
  942. * 上传图片
  943. * @param {Object} data
  944. */
  945. upActionImg:function() {
  946. if(this.tempFilePaths.length <= 0) {
  947. this.isUpImg = false;
  948. return;
  949. }
  950. this.isUpImg = true;
  951. var tmpData = this.tempFilePaths[0];
  952. this
  953. .request
  954. .post(this.request.getApi("qiniu"),{type:"jpg"})
  955. .then(res=>{
  956. uni.uploadFile({
  957. url: 'https://up-z0.qiniup.com',
  958. filePath: tmpData.data,
  959. name: 'file',
  960. formData: {
  961. 'key': res.data.mk_str,
  962. 'token': res.data.token
  963. },
  964. success: (uploadFileRes) => {
  965. var sendPack = {};
  966. sendPack.data = res.data.url;
  967. sendPack.type = "img";
  968. sendPack.chat_id = "";
  969. sendPack.f_uid = "";
  970. sendPack.group_id = this.groupId;
  971. sendPack.msg_id = tmpData.msgId;
  972. this.webSocket.send((new Message(JSON.stringify(sendPack),"groupChat",true,1,true)),
  973. (res) => {
  974. var data = JSON.parse(res);
  975. if(data.code == 1) {
  976. this.inUpAction(tmpData.msgId,1);
  977. this.chatRead();
  978. } else {
  979. this.inUpAction(tmpData.msgId,-1);
  980. }
  981. },
  982. error=>{
  983. this.inUpAction(tmpData.msgId,-1);
  984. });
  985. },
  986. fail:()=>{
  987. this.inUpAction(msgId,-1);
  988. }
  989. });
  990. })
  991. .catch(err=>{
  992. this.inUpAction(msgId,-1);
  993. });
  994. },
  995. /**
  996. * 执行状态
  997. */
  998. inUpAction:function(msgId,type) {
  999. for(var i in this.data) {
  1000. if(this.data[i].msgId == msgId) this.$set(this.data[i],"isSend",type);
  1001. }
  1002. this.tempFilePaths.splice(0,1);
  1003. this.upActionImg();
  1004. },
  1005. /**
  1006. * 打开
  1007. * @param {Object} ev
  1008. */
  1009. tapOpen: function(ev) {
  1010. let url = ev.currentTarget.dataset.url;
  1011. this.utils.navigateTo(url);
  1012. },
  1013. /**
  1014. * 领取红包页面
  1015. * @param {Object} ev
  1016. */
  1017. tapRedItem:function(ev){
  1018. this.lqRed.data = JSON.parse(ev.data);
  1019. console.log(this.lqRed);
  1020. uni.showLoading({ title:"加载中.." });
  1021. this.lqRed.sendUser = ev.sendUser;
  1022. this.lqRed.msgId = ev.msgId;
  1023. this.lqRed.state = 1;
  1024. this
  1025. .request
  1026. .post("chatRedEvelope",{id:this.lqRed.data.id})
  1027. .then(res=>{
  1028. uni.hideLoading();
  1029. if(res.code == 200) {
  1030. console.log(res);
  1031. if(!res.data.is_receive && this.user.uid != ev.data.send_uid) {
  1032. this.isOpenRed = true;
  1033. } else {
  1034. this.redTransferCheck(this.lqRed.msgId);
  1035. uni.navigateTo({ url:"redpack/look?id=" + this.lqRed.data.id});
  1036. }
  1037. } else {
  1038. uni.hideLoading();
  1039. uni.showModal({title: '系统提示',content: res.msg,showCancel: false});
  1040. }
  1041. })
  1042. .catch(err=>{
  1043. uni.hideLoading();
  1044. uni.showModal({title: '系统提示',content: "加载失败",showCancel: false});
  1045. });
  1046. },
  1047. /**
  1048. * 确认领取红包
  1049. */
  1050. tapOpenLv:function(){
  1051. this.redAnim = "anim-rotate";
  1052. this
  1053. .request
  1054. .post("drwReceive",{
  1055. id : this.lqRed.data.id
  1056. })
  1057. .then(res=>{
  1058. this.redAnim = "";
  1059. if(res.code == 200) {
  1060. if(res.data.status == 200) {
  1061. this.isOpenRed = false;
  1062. let music = uni.createInnerAudioContext();
  1063. music.src = "/static/img/red_receive.mp3";
  1064. music.play();
  1065. this.redTransferCheck(this.lqRed.msgId);
  1066. uni.navigateTo({ url:"redpack/look?id=" + this.lqRed.data.id});
  1067. }
  1068. if(res.data.status == 100) {
  1069. this.lqRed.state = 2;
  1070. this.redTransferCheck(this.lqRed.msgId);
  1071. }
  1072. } else {
  1073. uni.showModal({title: '系统提示',content:res.msg,showCancel: false});
  1074. }
  1075. })
  1076. .catch(err=>{
  1077. this.redAnim = "";
  1078. uni.showModal({title: '系统提示',content:"领取失败,请重新尝试!",showCancel: false});
  1079. });
  1080. },
  1081. /**
  1082. * 验证码
  1083. *
  1084. */
  1085. tapZc:function(){
  1086. uni.navigateTo({
  1087. url:"redpack/groupUserSend?groupId=" + this.groupId + "&type=transfer"
  1088. });
  1089. },
  1090. /**
  1091. * 打开转账数据
  1092. * @param {Object} ev
  1093. */
  1094. tapRedTransferItem:function(ev){
  1095. var data = JSON.parse(ev.data);
  1096. uni.navigateTo({
  1097. url:"redpack/transferLook?id=" + data.id + "&msgId=" + ev.msgId
  1098. });
  1099. },
  1100. /**
  1101. * 转账阅读
  1102. * @param {Object} msgId
  1103. */
  1104. redTransferCheck:function(msgId){
  1105. this.redMsg(msgId);
  1106. setTimeout(()=>{this.getwcTime();},200);
  1107. },
  1108. /**
  1109. * 红包阅读/存
  1110. * @param {Object} msgId
  1111. */
  1112. redMsg:function(msgId){
  1113. for(var i in this.redLqBack) {
  1114. if(this.redLqBack[i] == msgId) return;
  1115. }
  1116. this.redLqBack.push(msgId);
  1117. if(this.redLqBack.length > 500) {
  1118. this.redLqBack.splice(0,10);
  1119. }
  1120. uni.setStorage({
  1121. key : "chat_red_" + this.groupId,
  1122. data : JSON.stringify(this.redLqBack)
  1123. })
  1124. },
  1125. tapInput:function(ev){
  1126. var value = ev.detail.value;
  1127. if(value == '') return;
  1128. if(value[value.length - 1] == '@') {
  1129. this.isPopAt = true;
  1130. setTimeout(()=>{
  1131. this.isPopAt2 = true;
  1132. },200);
  1133. this.userGroup.page = 1;
  1134. this.tapLxInit(true);
  1135. uni.hideKeyboard();
  1136. }
  1137. //var bb = value.match(/\@(.*?) /g);
  1138. },
  1139. tapHidePopAt:function(){
  1140. this.isPopAt2 = false;
  1141. setTimeout(()=>{
  1142. this.isPopAt = false;
  1143. },200);
  1144. },
  1145. /**
  1146. * 搜索观察家
  1147. */
  1148. tapPopKeyWord:function(){
  1149. this.page = {page:1,isLoad:false,isFoot:false};
  1150. if(this.mbAr[this.popKeyword] != null) {
  1151. this.data = this.mbAr[this.popKeyword];
  1152. } else {
  1153. this.tapLxInit(true);
  1154. }
  1155. },
  1156. /**
  1157. * 遍历字符串
  1158. */
  1159. getRanValue:function(str) {
  1160. let value = str;
  1161. if (value.indexOf(this.popKeyword)!==-1) {
  1162. let reg = new RegExp(this.popKeyword, 'gi')
  1163. return value.replace(reg, `<font style="color:#2fbec0">${this.popKeyword}</font>`)
  1164. } else {
  1165. return value
  1166. }
  1167. },
  1168. /**
  1169. * 点击事件
  1170. */
  1171. taopPopItem:function(item){
  1172. this.msg += item.nickname + " ";
  1173. this.tapHidePopAt();
  1174. this.focus = true;
  1175. },
  1176. tapLongUserItem:function(item){
  1177. this.msg += "@"+item.data.sendUser.nickname + " ";
  1178. this.chatUserList.push({
  1179. uid : item.data.sendUser.uid,
  1180. nickname : item.data.sendUser.nickname
  1181. });
  1182. },
  1183. /**
  1184. * 获取提醒人数据
  1185. */
  1186. tapLxInit:function(isPull){
  1187. uni.showLoading({ title:"加载中.."});
  1188. this
  1189. .request
  1190. .post("chatGroupUser",{
  1191. groupId : this.groupId,
  1192. page : this.userGroup.page,
  1193. keyword : this.popKeyword
  1194. })
  1195. .then(res=>{
  1196. uni.hideLoading();
  1197. if(res.code == 200) {
  1198. this.userGroup.isFrite = true;
  1199. this.userGroup.isLoad = false;
  1200. if(isPull) {
  1201. this.chatUserList = res.data.list;
  1202. } else {
  1203. this.chatUserList = this.chatUserList.concat(res.data.list);
  1204. }
  1205. //是否到底
  1206. if(res.data.list.length != res.data.pageSize) {
  1207. this.userGroup.isFoot = true;
  1208. }
  1209. if(this.userGroup.page == 1 && this.popKeyword != ''){
  1210. this.mbAr[this.popKeyword] = res.data.list;
  1211. }
  1212. } else {
  1213. this.utils.Tip(res.msg);
  1214. }
  1215. })
  1216. .catch(err=>{
  1217. console.log(err);
  1218. uni.hideLoading();
  1219. this.utils.Tip("加载失败");
  1220. });
  1221. },
  1222. /**
  1223. * 更多
  1224. */
  1225. tapMore:function(){
  1226. uni.navigateTo({
  1227. url:"group/info/groupInfo?groupId=" + this.groupId
  1228. })
  1229. },
  1230. chatRead:function(bool = false){
  1231. this
  1232. .request
  1233. .post("chatRead",{groupId:this.groupId})
  1234. .then(res=>{
  1235. if(res.code == 200) {
  1236. uni.$emit('chatRead',{groupId:this.groupId,bool:bool});
  1237. } else {
  1238. uni.showModal({title: '系统提示',content: res.msg,showCancel: false});
  1239. }
  1240. });
  1241. },
  1242. /**
  1243. * 查看收藏
  1244. */
  1245. tapCollectList:function(){
  1246. uni.navigateTo({
  1247. url:"collection/collect?groupId=" + this.groupId + "&nickname=" + encodeURIComponent(this.chatUser.name) + "&avatar="
  1248. + (this.chatUser.img == '' ? '/static/img/logo.png' : encodeURIComponent(this.chatUser.img))
  1249. });
  1250. },
  1251. /**
  1252. * 长安效果
  1253. */
  1254. tapLongItem:function(ev){
  1255. var index = ev.dom.currentTarget.dataset.id;
  1256. var left = ev.dom.touches[0].pageX;
  1257. var top = ev.dom.touches[0].clientY;
  1258. var leftW = this.$device.screenWidth - left;
  1259. var topW = this.$device.screenHeight - top;
  1260. this.showLeft = leftW < 190 ? (left - (190 - leftW)): left;
  1261. this.showTop = topW < 250 ? (top - (250 - topW)) : top;
  1262. this.showOpen = true;
  1263. this.showData = ev.data;
  1264. },
  1265. /**
  1266. * 复制内容
  1267. */
  1268. tapCopy:function(){
  1269. this.showOpen = false;
  1270. uni.setClipboardData({
  1271. data: this.showData.data,
  1272. success: data => {
  1273. this.utils.showAlert({
  1274. title: "复制成功!",
  1275. icon: "none",
  1276. mask: true
  1277. })
  1278. },
  1279. fail: err => {
  1280. this.utils.showAlert({
  1281. title: "复制失败,请重新复制",
  1282. icon: "none",
  1283. mask: true
  1284. })
  1285. },
  1286. });
  1287. },
  1288. tapAddCollection:function(){
  1289. this.showOpen = false;
  1290. uni.showLoading({ title:"操作中.." });
  1291. this
  1292. .request
  1293. .post("collectAdd",{
  1294. msg_id : this.showData.msgId,
  1295. data : this.showData.data,
  1296. nickname : this.showData.user.nickname
  1297. })
  1298. .then(res=>{
  1299. uni.hideLoading();
  1300. if( res.code== 200){
  1301. this.utils.Tip("操作成功");
  1302. } else {
  1303. uni.showModal({title: '系统提示',content: res.msg,showCancel: false});
  1304. }
  1305. })
  1306. .catch(err=>{
  1307. uni.hideLoading();
  1308. uni.showModal({title: '系统提示',content:"操作失败!",showCancel: false});
  1309. })
  1310. },
  1311. tapDown:function(){
  1312. this.showOpen = false;
  1313. uni.downloadFile({
  1314. url : this.showData.data,
  1315. success:(resFile)=>{
  1316. if (resFile.statusCode === 200) {
  1317. uni.saveImageToPhotosAlbum({
  1318. filePath: resFile.tempFilePath,
  1319. success: (res)=> {
  1320. this.utils.Tip("保存图片成功");
  1321. },
  1322. fail:(res)=> {
  1323. this.utils.showAlert("保存失败,请重新操作");
  1324. },
  1325. complete: function(res) {},
  1326. })
  1327. } else {
  1328. this.isDown = false;
  1329. this.utils.showAlert("保存失败,请重新操作");
  1330. }
  1331. },
  1332. fail:()=>{
  1333. this.isDown = false;
  1334. this.utils.showAlert("保存失败,请重新操作");
  1335. }
  1336. });
  1337. },
  1338. tapRecord:function(){
  1339. this.isRecord = !this.isRecord;
  1340. if(this.isRecord) {
  1341. this.isGroup = false;
  1342. this.isFace = false;
  1343. this.inputBottom = 150;
  1344. this.$refs['recording'].open();
  1345. } else {
  1346. this.inputBottom = 0;
  1347. this.$refs['recording'].hide();
  1348. }
  1349. },
  1350. /**
  1351. * @param {Object} pm
  1352. */
  1353. tapRecordH5:function(recAr){
  1354. uni.showLoading({ title:"发送中.."});
  1355. this
  1356. .request
  1357. .post("chatUpVoice",recAr)
  1358. .then( res => {
  1359. uni.hideLoading();
  1360. if(res.code == 200) {
  1361. var msgId = this.webSocket.createMsgId();
  1362. //消息添加
  1363. var data = {};
  1364. data.chat = this.chatUser.chat;
  1365. data.sendUser = {
  1366. nickname : this.chatUser.meUser.nickname,
  1367. avatar : this.user.avatar,
  1368. uid : this.user.uid
  1369. };
  1370. data.group_type = 'group_chat';
  1371. data.type = 'voice';
  1372. data.data = JSON.stringify({time:recAr.duration,filePath:res.data.msgFile});
  1373. data.is_remind = 0;
  1374. data.isSend = 0;
  1375. data.time = this.utils.strtotime();
  1376. data.nid = 0;
  1377. data.msgId = msgId;
  1378. this.data.push(data);
  1379. this.getwcTime();
  1380. this.setScrollInto(msgId);
  1381. var sendPack = {};
  1382. sendPack.data = JSON.stringify({time:recAr.duration,filePath:res.data.msgFile});
  1383. sendPack.type = "voice";
  1384. sendPack.chat_id = "";
  1385. sendPack.f_uid = "";
  1386. sendPack.group_id = this.groupId;
  1387. sendPack.msg_id = msgId;
  1388. this.webSocket.send((new Message(JSON.stringify(sendPack),"groupChat",true,1,true)),
  1389. (res) => {
  1390. var data = JSON.parse(res);
  1391. if(data.code == 1) {
  1392. this.inUpAction(msgId,1);
  1393. this.chatRead();
  1394. } else {
  1395. this.inUpAction(msgId,-1);
  1396. }
  1397. },
  1398. error=>{
  1399. this.inUpAction(msgId,-1);
  1400. });
  1401. } else {
  1402. uni.showModal({title: '系统提示',content:res.msg,showCancel: false});
  1403. }
  1404. })
  1405. .catch(err=>{
  1406. console.log(err);
  1407. uni.hideLoading();
  1408. uni.showModal({title: '系统提示',content:"发送失败,请重新尝试!",showCancel: false});
  1409. });
  1410. },
  1411. /**
  1412. * 撤回
  1413. */
  1414. tapWithdraw:function(){
  1415. this.showOpen = false;
  1416. uni.showLoading({ title:"撤回中..."});
  1417. this
  1418. .request
  1419. .post("withdraw",{groupId : this.groupId,msg_id:this.showData.msgId})
  1420. .then(res=>{
  1421. uni.hideLoading();
  1422. if(res.code == 200) {
  1423. for(var i in this.data) {
  1424. if(this.data[i].msgId == this.showData.msgId) {
  1425. var data = this.data[i];
  1426. data.type = "tip";
  1427. data.data = "你撤回了一条消息";
  1428. this.$set(this.data,i,data);
  1429. }
  1430. }
  1431. } else {
  1432. this.utils.Tip(res.msg);
  1433. }
  1434. })
  1435. .catch(err=>{
  1436. uni.hideLoading();
  1437. this.utils.Tip("加载失败");
  1438. });
  1439. },
  1440. /**
  1441. * 我要转发
  1442. */
  1443. tapZf:function(){
  1444. this.showOpen = false;
  1445. uni.navigateTo({
  1446. url:"transmit?msgId=" + this.showData.msgId + "&data=" + this.showData.data + "&type=" + this.showData.type
  1447. });
  1448. },
  1449. /**
  1450. * 查看用户信息
  1451. */
  1452. tapUserItem:function(uid){
  1453. uni.navigateTo({
  1454. url:"/pages/chat/friend/info?usercode=" + uid
  1455. })
  1456. },
  1457. glRkName:function(data){
  1458. if(this.groupId == data.groupId) {
  1459. this.getData(true);
  1460. }
  1461. },
  1462. /**
  1463. * 是否判断重复msgId
  1464. */
  1465. getRepeat:function(data,msgId){
  1466. for(var i in data) {
  1467. if(data[i].msgId == msgId) return true;
  1468. }
  1469. return false;
  1470. },
  1471. tapReminClose:function(){
  1472. this.remindAr = [];
  1473. //更新提醒时间
  1474. this.request.post("GroupRemindOk",{groupId : this.groupId}).then(res=>{}).catch(err=>{});
  1475. },
  1476. /**
  1477. * @你
  1478. */
  1479. getRemind:function(){
  1480. let reStr = "";
  1481. for(let i in this.remindAr) {
  1482. let d = this.remindAr[i];
  1483. if(reStr == "") {
  1484. reStr += d.nickname + "@你";
  1485. } else {
  1486. reStr += "," + d.nickname + "@你";
  1487. }
  1488. }
  1489. return reStr;
  1490. }
  1491. }
  1492. }
  1493. </script>
  1494. <style>
  1495. </style>