ConversationListPage.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="conversation-list" @scroll="onScroll">
  3. <view v-if="connectionStatusDesc" style="text-align: center; padding: 5px 0">{{ connectionStatusDesc}}</view>
  4. <uni-list :border="true" @scroll="onScroll">
  5. <view
  6. @click="showConversation(conversationInfo)"
  7. v-for="conversationInfo in sharedConversationState.conversationInfoList"
  8. :key="conversationInfoKey(conversationInfo)"
  9. v-bind:class="{top:conversationInfo.top }"
  10. >
  11. <ConversationItemView :conversation-info="conversationInfo" @longpress.native="showConversationContextMenu($event, conversationInfo)"/>
  12. </view>
  13. </uni-list>
  14. <chunLei-popups v-model="showContextMenu" :popData="contextMenuItems" @tapPopup="onContextMenuItemSelect" :x="contextMenuX" :y="contextMenuY" direction="column" theme="dark" :triangle="false" dynamic/>
  15. <main-action-menu ref="mainActionMenu"></main-action-menu>
  16. </view>
  17. </template>
  18. <script>
  19. import ConversationItemView from "./ConversationItemView";
  20. import store from "../../store";
  21. import wfc from "../../wfc/client/wfc";
  22. import ConnectionStatus from "../../wfc/client/connectionStatus";
  23. export default {
  24. name: 'ConversationListPage',
  25. data() {
  26. return {
  27. sharedConversationState: store.state.conversation,
  28. sharedMiscState: store.state.misc,
  29. showContextMenu: false,
  30. contextMenuX: 0,
  31. contextMenuY: 0,
  32. contextMenuItems: [],
  33. };
  34. },
  35. onShow() {
  36. console.log('conversationList onShow', this.sharedConversationState.conversationInfoList.length)
  37. },
  38. onNavigationBarButtonTap(e) {
  39. console.log('onNavigationBarButtonTap')
  40. switch (e.index) {
  41. case 0:
  42. this.$refs.mainActionMenu.show();
  43. break;
  44. case 1:
  45. uni.navigateTo({
  46. url: '/pages/search/SearchPortalPage'
  47. });
  48. break;
  49. default:
  50. break;
  51. }
  52. },
  53. methods: {
  54. showConversation(conversationInfo) {
  55. store.setCurrentConversationInfo(conversationInfo);
  56. this.$go2ConversationPage();
  57. },
  58. removeConversation(conversationInfo) {
  59. store.removeConversation(conversationInfo.conversation);
  60. },
  61. conversationInfoKey(conversationInfo) {
  62. let conv = conversationInfo.conversation;
  63. return conv.target + '-' + conv.type + '-' + conv.line;
  64. },
  65. scrollActiveElementCenter() {
  66. let el = this.$el.getElementsByClassName("active")[0];
  67. el && el.scrollIntoView({behavior: "instant", block: "center"});
  68. },
  69. onScroll() {
  70. // TODO
  71. },
  72. showConversationContextMenu(e, conversationInfo) {
  73. this.contextMenuX = e.touches[0].clientX;
  74. this.contextMenuY = e.touches[0].clientY;
  75. this.contextMenuItems = [];
  76. this.contextMenuItems.push({
  77. title: conversationInfo.top ? '取消置顶' : '置顶',
  78. tag: 'top',
  79. conversationInfo: conversationInfo,
  80. })
  81. this.contextMenuItems.push({
  82. title: conversationInfo.isSilent ? '取消静音' : '静音',
  83. tag: 'silent',
  84. conversationInfo: conversationInfo,
  85. })
  86. this.contextMenuItems.push({
  87. title: '删除会话',
  88. tag: 'delete',
  89. conversationInfo: conversationInfo,
  90. })
  91. this.contextMenuItems.push({
  92. title: conversationInfo._unread === 0 ? '标记为未读' : '标记为已读',
  93. tag: 'mark',
  94. conversationInfo: conversationInfo,
  95. })
  96. this.showContextMenu = true;
  97. },
  98. onContextMenuItemSelect(t) {
  99. switch (t.tag) {
  100. case 'delete':
  101. store.removeConversation(t.conversationInfo.conversation);
  102. break;
  103. case 'top':
  104. store.setConversationTop(t.conversationInfo.conversation, t.conversationInfo.top > 0 ? 0 : 1);
  105. break;
  106. case 'silent':
  107. store.setConversationSilent(t.conversationInfo.conversation, !t.conversationInfo.isSilent);
  108. break;
  109. case 'mark':
  110. let conversation = t.conversationInfo.conversation;
  111. if (t.conversationInfo._unread === 0) {
  112. wfc.markConversationAsUnread(conversation, true);
  113. } else {
  114. wfc.clearConversationUnreadStatus(conversation);
  115. }
  116. break;
  117. default:
  118. uni.showToast({
  119. title: 'TODO ' + t.title,
  120. icon: 'none'
  121. })
  122. break;
  123. }
  124. }
  125. },
  126. activated() {
  127. this.scrollActiveElementCenter();
  128. },
  129. computed: {
  130. connectionStatusDesc() {
  131. let desc = '';
  132. switch (this.sharedMiscState.connectionStatus) {
  133. case ConnectionStatus.ConnectionStatusConnecting:
  134. desc = '正在连接...';
  135. break;
  136. case ConnectionStatus.ConnectionStatusReceiveing:
  137. desc = '正在同步...';
  138. break;
  139. case ConnectionStatus.ConnectionStatusConnected:
  140. desc = '';
  141. break;
  142. case ConnectionStatus.ConnectionStatusUnconnected:
  143. desc = '连接失败';
  144. break;
  145. }
  146. return desc;
  147. }
  148. },
  149. components: {
  150. ConversationItemView,
  151. },
  152. };
  153. </script>
  154. <style lang="css" scoped>
  155. .conversation-list {
  156. height: 100vh;
  157. overflow: auto;
  158. background: #f3f3f3;
  159. }
  160. .conversation-list .top {
  161. background-color: #f1f1f1;
  162. }
  163. </style>