conversation.vue 22 KB

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