conversation.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. <template>
  2. <view>
  3. <!-- <view>
  4. <view class="search" v-if="search_btn">
  5. <view @tap="openSearch">
  6. <icon type="search" size="12"></icon>
  7. <text>搜索</text>
  8. </view>
  9. </view>
  10. </view> -->
  11. <!-- <view class="chat_list_wraper" > -->
  12. <scroll-view scroll-y="true" :class="
  13. 'chat_list_wraper ' + (gotop ? (isIPX ? 'goTopX' : 'goTop') : 'goback')
  14. " :style="'padding-bottom: ' + (isIPX ? '270rpx' : '226rpx')">
  15. <!-- <view class="search_input" v-if="search_chats">
  16. <view>
  17. <icon type="search" size="12"></icon>
  18. <input placeholder="搜索" placeholder-style="color:#9B9B9B;line-height:21px;font-size:15px;"
  19. auto-focus confirm-type="search" type="text" @confirm="onSearch" @input="onInput"
  20. v-model="input_code" />
  21. <icon type="clear" size="12" @tap.stop="clearInput" v-if="show_clear"></icon>
  22. </view>
  23. <text @tap="cancel">取消</text>
  24. </view> -->
  25. <view v-for="(item, index) in conversationList" :key="index" class="chat_list" :data-item="item"
  26. @tap.stop="del_chat" @longpress="longpress">
  27. <swipe-delete>
  28. <!-- 通知模块 -->
  29. <!-- <view class="tap_mask" @tap.stop="into_inform" :data-item="item" v-if="item.chatType == 'INFORM'">
  30. <view class="list_box">
  31. <view class="list_left">
  32. <view class="list_pic">
  33. <view v-if="unReadTotalNotNum > 0" class="em-unread-spot2">
  34. {{ unReadTotalNotNum}}
  35. </view>
  36. <image :class="unReadTotalNotNum > 0 ? 'haveSpot' : ''" src="../static/inform.png">
  37. </image>
  38. </view>
  39. <view class="list_text">
  40. <text class="list_user"> 系统通知 </text>
  41. <text class="list_word"
  42. v-if="item.chatType == 'INFORM'">申请通知来自:{{ item.info.from }}</text>
  43. </view>
  44. </view>
  45. <view class="list_right">
  46. <text :data-username="item.username">{{ handleTime(item) }}</text>
  47. </view>
  48. </view>
  49. </view> -->
  50. <view class="tap_mask" @tap.stop="into_chatRoom" :data-item="JSON.stringify(item)">
  51. <!-- 消息列表 -->
  52. <view class="list_box ddflex">
  53. <view class="list-left fflex ddflex">
  54. <view class="list_pic">
  55. <view class="em-msgNum"
  56. v-if="item.unReadCount > 0 && !pushConfigData.includes(item.chatType === 'chat' ? item.username : item.info.to)">
  57. {{ item.unReadCount > 99 ? '99+':item.unReadCount}}
  58. </view>
  59. <image :src="showConversationAvatar(item)"></image>
  60. </view>
  61. <view class="list_texts fflex">
  62. <view class="ddflex">
  63. <text class="list_users fflex">{{ showConversationName(item) }}</text>
  64. <view class="list_rights">
  65. <text :data-username="item.username">{{ handleTime(item) }}</text>
  66. </view>
  67. </view>
  68. <view>
  69. <text class="list_words" v-if="item.msg.data[0].data">
  70. {{item.msg.data[0].data}}
  71. </text>
  72. <text class="list_words" v-else-if="item.msg.type == 'img'">[图片]</text>
  73. <text class="list_words" v-else-if="item.msg.type == 'audio'">[语音]</text>
  74. <text class="list_words" v-else-if="item.msg.type == 'file'">[附件]</text>
  75. <text class="list_words" v-else="item.msg.type == 'video'">[视频]</text>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. <!-- <view class="list_box">
  81. <view class="list_left" :data-username="item.username">
  82. <view class="list_pic">
  83. <view class="em-msgNum"
  84. v-if="item.unReadCount > 0 && !pushConfigData.includes(item.chatType === 'chat' ? item.username : item.info.to)">
  85. {{ item.unReadCount > 99 ? '99+':item.unReadCount}}
  86. </view>
  87. <image :src="showConversationAvatar(item)"></image>
  88. </view>
  89. <view class="list_text">
  90. <text class="list_user">{{ showConversationName(item) }}</text>
  91. <text class="list_word" v-if="item.msg.data[0].data">
  92. {{item.msg.data[0].data}}
  93. </text>
  94. <text class="list_word" v-if="item.msg.type == 'img'">[图片]</text>
  95. <text class="list_word" v-if="item.msg.type == 'audio'">[语音]</text>
  96. <text class="list_word" v-if="item.msg.type == 'file'">[附件]</text>
  97. <text class="list_word" v-if="item.msg.type == 'video'">[视频]</text>
  98. </view>
  99. </view>
  100. <view class="list_right">
  101. <text :data-username="item.username">{{ handleTime(item) }}</text>
  102. </view>
  103. </view> -->
  104. </view>
  105. </swipe-delete>
  106. </view>
  107. <long-press-modal :winSize="winSize" :popButton="popButton" @change="pickerMenuChange" :showPop="showPop"
  108. @hidePop="hidePop" :popStyle="popStyle" />
  109. <view v-if="conversationList && conversationList.length == 0" class="chat_noChat">
  110. <image class="ctbg" src="../static/ctbg.png"></image>
  111. 暂无聊天消息
  112. </view>
  113. <!-- </view> -->
  114. </scroll-view>
  115. <!-- bug: margin-bottom 不生效 需要加一个空标签-->
  116. <view style="height: 1px"></view>
  117. <view class="mask" @tap="close_mask" v-if="show_mask"></view>
  118. </view>
  119. </template>
  120. <script>
  121. const req = require("../../utils/request.js");
  122. let disp = require("../../hxChatSDK/utils/broadcast");
  123. let timeFormats = require("../../hxChatSDK/utils/timeFormat");
  124. var WebIM = require("../../hxChatSDK/utils/WebIM")["default"];
  125. let isfirstTime = true;
  126. import swipeDelete from "../../chat/components/chat/swipedelete/swipedelete";
  127. import longPressModal from "../../chat/components/chat/longPressModal/index";
  128. export default {
  129. data() {
  130. return {
  131. search_btn: true,
  132. search_chats: false,
  133. show_mask: false,
  134. yourname: "",
  135. unReadSpotNum: 0,
  136. unReadNoticeNum: 0,
  137. messageNum: 0,
  138. unReadTotalNotNum: 0,
  139. conversationList: [],
  140. show_clear: false,
  141. member: "",
  142. isIPX: false,
  143. gotop: false,
  144. input_code: "",
  145. groupName: {},
  146. winSize: {},
  147. popButton: ["删除该聊天"],
  148. showPop: false,
  149. popStyle: "",
  150. currentVal: '',
  151. pushConfigData: [],
  152. defaultAvatar: "../static/theme2x.png",
  153. defaultGroupAvatar: "../static/groupTheme.png"
  154. };
  155. },
  156. components: {
  157. swipeDelete,
  158. longPressModal,
  159. },
  160. props: {},
  161. onLoad() {
  162. this.getWindowSize();
  163. //监听加好友申请
  164. disp.on("em.subscribe", this.onChatPageSubscribe);
  165. //监听解散群
  166. disp.on("em.invite.deleteGroup", this.onChatPageDeleteGroup);
  167. //监听未读消息数
  168. disp.on("em.unreadspot", this.onChatPageUnreadspot);
  169. //监听未读加群“通知”
  170. disp.on("em.invite.joingroup", this.onChatPageJoingroup);
  171. //监听好友删除
  172. disp.on("em.contacts.remove", this.onChatPageRemoveContacts);
  173. //监听好友关系解除
  174. disp.on("em.unsubscribed", this.onChatPageUnsubscribed)
  175. if (!uni.getStorageSync('listGroup')) {
  176. this.listGroups()
  177. }
  178. // if (!uni.getStorageSync('member')) {
  179. this.getRoster()
  180. // }
  181. this.readJoinedGroupName()
  182. },
  183. onShow: function() {
  184. req.onNetworkStatusChangeIM()
  185. // #ifdef MP-WEIXIN
  186. uni.hideHomeButton && uni.hideHomeButton();
  187. // #endif
  188. setTimeout(() => {
  189. this.getLocalConversationlist();
  190. }, 100)
  191. this.setData({
  192. unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ?
  193. "99+" : getApp().globalData.unReadMessageNum,
  194. messageNum: getApp().globalData.saveFriendList.length,
  195. unReadNoticeNum: getApp().globalData.saveGroupInvitedList.length,
  196. unReadTotalNotNum: getApp().globalData.saveFriendList.length +
  197. getApp().globalData.saveGroupInvitedList.length,
  198. });
  199. if (getApp().globalData.isIPX) {
  200. this.setData({
  201. isIPX: true,
  202. });
  203. }
  204. },
  205. onUnload() {
  206. //页面卸载同步取消onload中的订阅,防止重复订阅事件。
  207. disp.off('em.subscribe', this.onChatPageSubscribe)
  208. disp.off("em.invite.deleteGroup", this.onChatPageDeleteGroup)
  209. disp.off("em.unreadspot", this.onChatPageUnreadspot)
  210. disp.off("em.invite.joingroup", this.onChatPageJoingroup)
  211. disp.off("em.contacts.remove", this.onChatPageRemoveContacts)
  212. disp.off("em.unsubscribed", this.onChatPageUnsubscribed)
  213. },
  214. computed: {
  215. //会话头像展示
  216. showConversationAvatar() {
  217. // const friendUserInfoMap = getApp().globalData.friendUserInfoMap;
  218. return (item) => {
  219. if (item.chatType === 'singleChat' || item.chatType === 'chat') {
  220. // if (friendUserInfoMap.has(item.username) && friendUserInfoMap.get(item.username)?.avatarurl) {
  221. // return friendUserInfoMap.get(item.username).avatarurl
  222. // } else {
  223. // return this.defaultAvatar
  224. // }
  225. const imUserInfo = uni.getStorageSync("imUserInfo_" + item.username);
  226. if (imUserInfo && imUserInfo.avatar) {
  227. return imUserInfo.avatar;
  228. } else {
  229. return this.defaultAvatar;
  230. }
  231. } else if (item.chatType === 'groupchat' || item.chatType === 'chatRoom') {
  232. return this.defaultGroupAvatar
  233. }
  234. }
  235. },
  236. //会话name展示
  237. showConversationName() {
  238. // const friendUserInfoMap = getApp().globalData.friendUserInfoMap;
  239. return (item) => {
  240. if (item.chatType === 'singleChat' || item.chatType === 'chat') {
  241. // if (friendUserInfoMap.has(item.username) && friendUserInfoMap.get(item.username)?.nickname) {
  242. // return friendUserInfoMap.get(item.username).nickname
  243. // } else {
  244. // return item.username
  245. // }
  246. const imUserInfo = uni.getStorageSync("imUserInfo_" + item.username);
  247. if (imUserInfo && imUserInfo.nickName) {
  248. return imUserInfo.nickName;
  249. } else {
  250. return item.username;
  251. }
  252. } else if (item.chatType === 'groupchat' || item.chatType === 'chatRoom') {
  253. return item.groupName
  254. }
  255. }
  256. },
  257. //处理时间显示
  258. handleTime() {
  259. return (item) => {
  260. return timeFormats.timeFormat(item.time, 'mm/dd/hh:MM')
  261. }
  262. }
  263. },
  264. methods: {
  265. listGroups() {
  266. var me = this;
  267. return WebIM.conn.getGroup({
  268. limit: 50,
  269. success: function(res) {
  270. uni.setStorage({
  271. key: "listGroup",
  272. data: res.data,
  273. });
  274. me.readJoinedGroupName()
  275. me.getLocalConversationlist();
  276. },
  277. error: function(err) {
  278. console.log(err);
  279. },
  280. });
  281. },
  282. getRoster() {
  283. let me = this;
  284. let rosters = {
  285. success(roster) {
  286. console.log('roster', roster)
  287. var member = [];
  288. for (let i = 0; i < roster.length; i++) {
  289. if (roster[i].subscription == "both") {
  290. member.push(roster[i]);
  291. }
  292. }
  293. uni.setStorage({
  294. key: "member",
  295. data: member,
  296. });
  297. me.setData({
  298. member: member
  299. });
  300. //if(!systemReady){
  301. disp.fire("em.main.ready");
  302. //systemReady = true;
  303. //}
  304. me.getLocalConversationlist()
  305. me.setData({
  306. unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ?
  307. "99+" : getApp().globalData.unReadMessageNum,
  308. });
  309. },
  310. error(err) {
  311. console.log(err);
  312. },
  313. };
  314. WebIM.conn.getContacts(rosters);
  315. },
  316. readJoinedGroupName() {
  317. const joinedGroupList = uni.getStorageSync('listGroup')
  318. const groupList = joinedGroupList?.data || joinedGroupList || []
  319. let groupName = {};
  320. groupList.forEach((item) => {
  321. groupName[item.groupid] = item.groupname;
  322. });
  323. this.setData({
  324. groupName: groupName,
  325. });
  326. },
  327. // 包含陌生人版本
  328. getLocalConversationlist() {
  329. const myName = uni.getStorageSync("myUsername");
  330. const me = this;
  331. uni.getStorageInfo({
  332. success: function(res) {
  333. let storageKeys = res.keys;
  334. let newChatMsgKeys = [];
  335. let historyChatMsgKeys = [];
  336. let len = myName.length;
  337. storageKeys.forEach((item) => {
  338. if (item.slice(-len) == myName && item.indexOf("rendered_") == -1) {
  339. newChatMsgKeys.push(item);
  340. } else if (
  341. item.slice(-len) == myName &&
  342. item.indexOf("rendered_") > -1
  343. ) {
  344. historyChatMsgKeys.push(item);
  345. } else if (item === "INFORM") {
  346. newChatMsgKeys.push(item);
  347. }
  348. });
  349. me.packageConversation(newChatMsgKeys, historyChatMsgKeys);
  350. },
  351. });
  352. },
  353. //组件会话列表方法
  354. packageConversation(newChatMsgKeys, historyChatMsgKeys) {
  355. const me = this;
  356. const myName = uni.getStorageSync("myUsername");
  357. let conversationList = [];
  358. let lastChatMsg; //最后一条消息
  359. for (let i = historyChatMsgKeys.length; i > 0, i--;) {
  360. let index = newChatMsgKeys.indexOf(historyChatMsgKeys[i].slice(9));
  361. if (index > -1) {
  362. let newChatMsgs = uni.getStorageSync(newChatMsgKeys[index]) || [];
  363. if (newChatMsgs.length) {
  364. lastChatMsg = newChatMsgs[newChatMsgs.length - 1];
  365. lastChatMsg.unReadCount = newChatMsgs.length;
  366. newChatMsgKeys.splice(index, 1);
  367. } else {
  368. let historyChatMsgs = uni.getStorageSync(historyChatMsgKeys[i]);
  369. if (historyChatMsgs.length) {
  370. lastChatMsg = historyChatMsgs[historyChatMsgs.length - 1];
  371. }
  372. }
  373. } else {
  374. let historyChatMsgs = uni.getStorageSync(historyChatMsgKeys[i]);
  375. if (historyChatMsgs.length) {
  376. lastChatMsg = historyChatMsgs[historyChatMsgs.length - 1];
  377. }
  378. }
  379. if (
  380. lastChatMsg &&
  381. (lastChatMsg.chatType == "groupchat" ||
  382. lastChatMsg.chatType == "chatRoom")
  383. ) {
  384. lastChatMsg.groupName = me.groupName[lastChatMsg.info.to];
  385. }
  386. lastChatMsg && lastChatMsg.username != myName &&
  387. conversationList.push(lastChatMsg);
  388. }
  389. for (let i = newChatMsgKeys.length; i > 0, i--;) {
  390. let newChatMsgs = uni.getStorageSync(newChatMsgKeys[i]) || [];
  391. if (newChatMsgs.length) {
  392. lastChatMsg = newChatMsgs[newChatMsgs.length - 1];
  393. lastChatMsg.unReadCount = newChatMsgs.length;
  394. if (
  395. lastChatMsg.chatType == "groupchat" ||
  396. lastChatMsg.chatType == "chatRoom"
  397. ) {
  398. lastChatMsg.groupName = me.groupName[lastChatMsg.info.to];
  399. }
  400. lastChatMsg.username != myName && conversationList.push(lastChatMsg);
  401. }
  402. }
  403. conversationList.sort((a, b) => {
  404. return b.time - a.time;
  405. });
  406. this.setData({
  407. conversationList: conversationList,
  408. });
  409. console.log('消息》》》》', this.conversationList);
  410. },
  411. openSearch: function() {
  412. this.setData({
  413. search_btn: false,
  414. search_chats: true,
  415. gotop: true,
  416. });
  417. // this.into_singleChatRoom();
  418. },
  419. onSearch: function(val) {
  420. let searchValue = val.detail.value;
  421. var myName = uni.getStorageSync("myUsername");
  422. const me = this;
  423. let serchList = [];
  424. let conversationList = [];
  425. uni.getStorageInfo({
  426. success: function(res) {
  427. let storageKeys = res.keys;
  428. let chatKeys = [];
  429. let len = myName.length;
  430. storageKeys.forEach((item) => {
  431. if (item.slice(-len) == myName) {
  432. chatKeys.push(item);
  433. }
  434. });
  435. chatKeys.forEach((item, index) => {
  436. if (item.indexOf(searchValue) != -1) {
  437. serchList.push(item);
  438. }
  439. });
  440. let lastChatMsg = "";
  441. serchList.forEach((item, index) => {
  442. let chatMsgs = uni.getStorageSync(item) || [];
  443. if (chatMsgs.length) {
  444. lastChatMsg = chatMsgs[chatMsgs.length - 1];
  445. conversationList.push(lastChatMsg);
  446. }
  447. });
  448. me.setData({
  449. conversationList: conversationList
  450. });
  451. },
  452. });
  453. },
  454. cancel: function() {
  455. this.getLocalConversationlist();
  456. this.setData({
  457. search_btn: true,
  458. search_chats: false,
  459. unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ?
  460. "99+" : getApp().globalData.unReadMessageNum,
  461. gotop: false,
  462. });
  463. },
  464. clearInput: function() {
  465. this.setData({
  466. input_code: "",
  467. show_clear: false,
  468. });
  469. },
  470. onInput: function(e) {
  471. let inputValue = e.detail.value;
  472. if (inputValue) {
  473. this.setData({
  474. show_clear: true,
  475. });
  476. } else {
  477. this.setData({
  478. show_clear: false,
  479. });
  480. }
  481. },
  482. close_mask: function() {
  483. this.setData({
  484. search_btn: true,
  485. search_chats: false,
  486. show_mask: false,
  487. });
  488. },
  489. into_chatRoom: function(event) {
  490. let detail = JSON.parse(event.currentTarget.dataset.item);
  491. if (
  492. detail.chatType == "groupchat" ||
  493. detail.chatType == "chatRoom" ||
  494. detail.groupName
  495. ) {
  496. this.into_groupChatRoom(detail);
  497. } else {
  498. this.into_singleChatRoom(detail);
  499. }
  500. },
  501. // 单聊
  502. into_singleChatRoom: function(detail) {
  503. var my = uni.getStorageSync("myUsername");
  504. var nameList = {
  505. myName: my,
  506. your: detail.username,
  507. // your: 'rs_316923182331'
  508. };
  509. const friendUserInfoMap = getApp().globalData.friendUserInfoMap;
  510. if (friendUserInfoMap.has(nameList.your) && friendUserInfoMap.get(nameList.your)?.nickname) {
  511. nameList.yourNickName = friendUserInfoMap.get(nameList.your).nickname;
  512. }
  513. console.log('JSON.stringify(nameList)》》》》', JSON.stringify(nameList));
  514. uni.navigateTo({
  515. url: "../chatroom/chatroom?username=" + JSON.stringify(nameList),
  516. });
  517. },
  518. // 群聊 和 聊天室 (两个概念)
  519. into_groupChatRoom: function(detail) {
  520. var my = uni.getStorageSync("myUsername");
  521. var nameList = {
  522. myName: my,
  523. your: detail.groupName,
  524. groupId: detail.info.to,
  525. };
  526. uni.navigateTo({
  527. url: "../groupChatRoom/groupChatRoom?username=" + JSON.stringify(nameList),
  528. });
  529. },
  530. // into_inform: function() {
  531. // uni.redirectTo({
  532. // url: "../notification/notification",
  533. // });
  534. // },
  535. removeAndRefresh: function(event) {
  536. let removeId = event.currentTarget.dataset.item.info.from
  537. let ary = getApp().globalData.saveFriendList
  538. let idx
  539. if (ary.length > 0) {
  540. ary.forEach((v, k) => {
  541. if (v.from == removeId) {
  542. idx = k
  543. }
  544. })
  545. getApp().globalData.saveFriendList.splice(idx, 1);
  546. }
  547. uni.removeStorageSync('INFORM')
  548. },
  549. del_chat: function(event) {
  550. let detail = event.currentTarget.dataset.item;
  551. let nameList = {};
  552. let me = this;
  553. // 删除当前选中群组聊天列表
  554. if (detail.chatType == "groupchat" || detail.chatType == "chatRoom") {
  555. nameList = {
  556. your: detail.info.to,
  557. };
  558. //删除当前选中通知列表
  559. } else if (detail.chatType === "INFORM") {
  560. nameList = {
  561. your: "INFORM",
  562. };
  563. }
  564. //删除当前选中好友聊天列表
  565. else {
  566. nameList = {
  567. your: detail.username,
  568. };
  569. }
  570. var myName = uni.getStorageSync("myUsername");
  571. var currentPage = getCurrentPages();
  572. uni.showModal({
  573. title: "确认删除?",
  574. confirmText: "删除",
  575. success: function(res) {
  576. if (res.confirm) {
  577. uni.removeStorageSync(nameList.your + myName);
  578. uni.removeStorageSync("rendered_" + nameList.your + myName);
  579. nameList.your === 'INFORM' && me.removeAndRefresh(event);
  580. // if (Object.keys(currentPage[0]).length>0) {
  581. // currentPage[0].onShow();
  582. // }
  583. disp.fire("em.chat.session.remove");
  584. me.getLocalConversationlist();
  585. }
  586. },
  587. fail: function(err) {
  588. console.log('删除列表', err);
  589. },
  590. });
  591. },
  592. removeLocalStorage: function(yourname) {
  593. var myName = uni.getStorageSync("myUsername");
  594. uni.removeStorageSync(yourname + myName);
  595. uni.removeStorageSync("rendered_" + yourname + myName);
  596. },
  597. longpress: function(e) {
  598. //将当前选中的值存在data中方便后续操作
  599. this.currentVal = e
  600. let [touches, style, index] = [e.touches[0], "", e.currentTarget.dataset.index, ];
  601. /* 因 非H5端不兼容 style 属性绑定 Object ,所以拼接字符 */
  602. if (touches.clientY > this.winSize.height / 2) {
  603. style = `bottom:${this.winSize.height - touches.clientY}px;`;
  604. } else {
  605. style = `top:${touches.clientY}px;`;
  606. }
  607. if (touches.clientX > this.winSize.witdh / 2) {
  608. style += `right:${this.winSize.witdh - touches.clientX}px`;
  609. } else {
  610. style += `left:${touches.clientX}px`;
  611. }
  612. this.popStyle = style;
  613. // this.pickerUserIndex = Number(index);
  614. this.showShade = true;
  615. this.$nextTick(() => {
  616. setTimeout(() => {
  617. this.showPop = true;
  618. }, 10);
  619. });
  620. },
  621. /* 获取窗口尺寸 */
  622. getWindowSize() {
  623. uni.getSystemInfo({
  624. success: (res) => {
  625. this.winSize = {
  626. witdh: res.windowWidth,
  627. height: res.windowHeight,
  628. };
  629. },
  630. });
  631. },
  632. hidePop() {
  633. this.showPop = false;
  634. },
  635. pickerMenuChange() {
  636. this.del_chat(this.currentVal)
  637. },
  638. /* disp event callback function */
  639. onChatPageSubscribe() {
  640. this.getLocalConversationlist();
  641. this.setData({
  642. messageNum: getApp().globalData.saveFriendList.length,
  643. unReadTotalNotNum: getApp().globalData.saveFriendList.length +
  644. getApp().globalData.saveGroupInvitedList.length,
  645. });
  646. },
  647. onChatPageDeleteGroup(infos) {
  648. this.listGroups();
  649. this.getRoster();
  650. this.getLocalConversationlist();
  651. this.setData({
  652. messageNum: getApp().globalData.saveFriendList.length,
  653. });
  654. //如果会话存在则执行删除会话
  655. this.removeLocalStorage(infos.gid)
  656. },
  657. onChatPageUnreadspot(message) {
  658. this.getLocalConversationlist();
  659. let currentLoginUser = WebIM.conn.context.userId;
  660. let id = message && message.chatType === 'groupchat' ? message?.to : message?.from;
  661. let pushObj = uni.getStorageSync("pushStorageData");
  662. let pushAry = pushObj[currentLoginUser] || []
  663. this.setData({
  664. pushConfigData: pushAry,
  665. });
  666. // if (message && pushValue.includes(id)) return
  667. this.setData({
  668. unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ?
  669. "99+" : getApp().globalData.unReadMessageNum,
  670. });
  671. },
  672. onChatPageJoingroup() {
  673. this.setData({
  674. unReadNoticeNum: getApp().globalData.saveGroupInvitedList.length,
  675. unReadTotalNotNum: getApp().globalData.saveFriendList.length +
  676. getApp().globalData.saveGroupInvitedList.length,
  677. });
  678. this.getLocalConversationlist();
  679. },
  680. onChatPageRemoveContacts() {
  681. this.getLocalConversationlist();
  682. this.getRoster();
  683. },
  684. onChatPageUnsubscribed(message) {
  685. uni.showToast({
  686. title: `与${message.from}好友关系解除`,
  687. icon: "none",
  688. });
  689. }
  690. },
  691. };
  692. </script>
  693. <style>
  694. @import "./chat.css";
  695. </style>