conversation.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view class="container-conversation">
  3. <view class="scroll-box">
  4. <view class="uni-list margintop-bar">
  5. <view v-for="item in conversationList" :key="item.conversationID" @tap="handleRoute(item.conversationID)">
  6. <TUI-conversation-item :data-type="item.type" :conversation="item"></TUI-conversation-item>
  7. </view>
  8. </view>
  9. </view>
  10. <view class="bottom-back">
  11. <view class="bottom-area">
  12. <view v-if="showSelectTag" class="conversation-bubble" @tap.stop="handleEditToggle">
  13. <view v-for="(item, index) in array" :key="index" class="picker" :data-name="item.name" @tap="handleOnTap">{{ item.name }}</view>
  14. </view>
  15. <image @tap="showMore" class="btn-show-more" src="/static/static/assets/add.svg"></image>
  16. <view @tap="learnMore" class="im-link">了解更多IM功能</view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <!-- 这里有个加载的补丁逻辑待优化,页面向SDK请求conversationList的时候会有时延,
  22. 造成页面的一个抖动,这里加一个if逻辑打一个补丁,后续继续优化 -->
  23. <script>
  24. import logger from '../../../utils/logger';
  25. import TUIConversationItem from '../../../components/tui-conversation/conversation-item/index';
  26. import TUIMessageList from '../../../components/tui-chat/message-list/index';
  27. export default {
  28. data() {
  29. return {
  30. conversationList: [],
  31. showSelectTag: false,
  32. array: [
  33. {
  34. name: '发起会话'
  35. },
  36. {
  37. name: '发起群聊'
  38. },
  39. {
  40. name: '加入群聊'
  41. }
  42. ]
  43. };
  44. },
  45. components: {
  46. TUIConversationItem,
  47. TUIMessageList
  48. },
  49. props: {},
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. onLoad() {
  54. // 登入后拉去会话列表
  55. this.getConversationList();
  56. uni.$TUIKit.on(uni.$TUIKitEvent.CONVERSATION_LIST_UPDATED, this.onConversationListUpdated);
  57. },
  58. /**
  59. * 生命周期函数--监听页面卸载
  60. */
  61. onUnload() {
  62. uni.$TUIKit.off(uni.$TUIKitEvent.SDK_READY, this.onConversationListUpdated);
  63. },
  64. methods: {
  65. handleRoute(id) {
  66. const url = `../../TUI-Chat/chat?conversationID=${id}`;
  67. uni.navigateTo({
  68. url
  69. });
  70. },
  71. onConversationListUpdated(event) {
  72. logger.log('TUI-conversation | onConversationListUpdated |ok');
  73. this.setData({
  74. conversationList: event.data
  75. });
  76. },
  77. getConversationList() {
  78. uni.$TUIKit.getConversationList().then(imResponse => {
  79. logger.log(`TUI-conversation | getConversationList | getConversationList-length: ${imResponse.data.conversationList.length}`);
  80. this.setData({
  81. conversationList: imResponse.data.conversationList
  82. });
  83. });
  84. },
  85. showMore() {
  86. this.setData({
  87. showSelectTag: !this.showSelectTag
  88. });
  89. },
  90. learnMore() {
  91. uni.navigateTo({
  92. url: '../../TUI-User-Center/webview/webview?url=https://cloud.tencent.com/product/im'
  93. });
  94. },
  95. handleOnTap(event) {
  96. this.setData(
  97. {
  98. showSelectTag: false
  99. },
  100. () => {
  101. switch (event.currentTarget.dataset.name) {
  102. case '发起会话':
  103. this.$createConversation();
  104. break;
  105. case '发起群聊':
  106. this.$createGroup();
  107. break;
  108. case '加入群聊':
  109. this.$joinGroup();
  110. default:
  111. break;
  112. }
  113. }
  114. );
  115. },
  116. goHomePage() {
  117. // uni.navigateTo 不能跳转到 tabbar 页面,使用 uni.switchTab 代替
  118. uni.switchTab({
  119. url: '../../TUI-Index/index'
  120. });
  121. },
  122. handleEditToggle() {
  123. this.setData({
  124. showSelectTag: false
  125. });
  126. },
  127. $createConversation() {
  128. uni.navigateTo({
  129. url: '../create-conversation/create'
  130. });
  131. },
  132. $createGroup() {
  133. uni.navigateTo({
  134. url: '../../TUI-Group/create-group/create'
  135. });
  136. },
  137. $joinGroup() {
  138. uni.navigateTo({
  139. url: '../../TUI-Group/join-group/join'
  140. });
  141. }
  142. }
  143. };
  144. </script>
  145. <style scoped>
  146. @import './conversation.css';
  147. </style>