chat.vue 40 KB

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