chat.vue 40 KB

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