conversation.vue 22 KB

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