index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div style="height: 100%">
  3. <div class="sectionSearch">
  4. <the-search
  5. placeholder="请输入群聊名称"
  6. :show-search-button="false"
  7. @search="(val: any) => {
  8. noSearch(val)
  9. }"
  10. />
  11. </div>
  12. <div class="TUI-group">
  13. <div class="network" v-if="isNetwork">
  14. <i class="icon icon-error">!</i>
  15. <p>️{{ $t('TUIConversation.网络异常,请您检查网络设置') }}</p>
  16. </div>
  17. <main class="TUI-conversation-list">
  18. <aside class="TUI-contact-left">
  19. <ul class="TUI-contact-list">
  20. <li
  21. class="TUI-contact-list-item"
  22. v-for="(item, index) in groupList"
  23. :key="index"
  24. @click="handleListItem(item)"
  25. >
  26. <aside class="left">
  27. <img
  28. class="avatar"
  29. :src="
  30. item.img ||
  31. 'https://news-info.ks3-cn-beijing.ksyuncs.com/07/1690775328089.png'
  32. "
  33. onerror="this.src='https://news-info.ks3-cn-beijing.ksyuncs.com/07/1690775328089.png'"
  34. />
  35. </aside>
  36. <div class="content-header">
  37. <label>
  38. <p class="name">{{ item.name }}</p>
  39. </label>
  40. <div class="middle-box">
  41. <p>共{{ item.memberNum || 0 }}人</p>
  42. </div>
  43. </div>
  44. <div class="content-footer">
  45. <span class="time"></span>
  46. <img
  47. v-if="item.selfInfo?.messageRemindType === 'AcceptNotNotify'"
  48. class="mute-icon"
  49. src="../../assets/icon/mute.svg"
  50. />
  51. <i></i>
  52. </div>
  53. </li>
  54. </ul>
  55. </aside>
  56. </main>
  57. <!-- -->
  58. <the-empty
  59. v-if="!isNetwork && !loading && groupList.length <= 0"
  60. style="height: 90%"
  61. />
  62. </div>
  63. </div>
  64. </template>
  65. <script lang="ts">
  66. import TheEmpty from '@/components/TheEmpty';
  67. import { computed, defineComponent, onMounted, reactive, toRefs } from 'vue';
  68. import { caculateTimeago } from '../utils';
  69. import { handleAvatar, handleName, handleAt } from '../TUIChat/utils/utils';
  70. import { imGroupPage } from '/src/TUIKit/api';
  71. import TheSearch from '../../components/TheSearch';
  72. const TUIGroup = defineComponent({
  73. name: 'TUIGroup',
  74. components: { TheEmpty, TheSearch },
  75. props: {
  76. displayOnlineStatus: {
  77. type: Boolean,
  78. default: false
  79. }
  80. },
  81. setup(props) {
  82. const TUIServer: any = TUIGroup.TUIServer;
  83. const data = reactive({
  84. loading: true,
  85. page: 1,
  86. rows: 100,
  87. keyword: '',
  88. finshed: false, // 是否加载完
  89. groupList: [] as any,
  90. searchGroup: [] as any,
  91. searchID: '',
  92. currentGroup: null,
  93. netWork: '',
  94. userStatusList: new Map()
  95. });
  96. const handleItemTime = (time: number) => {
  97. if (time > 0) {
  98. return caculateTimeago(time * 1000);
  99. }
  100. return '';
  101. };
  102. const handleListItem = async (item: any) => {
  103. const name = `GROUP${item.groupId}`;
  104. TUIServer.TUICore.TUIServer.TUIConversation.getConversationProfile(
  105. name
  106. ).then((imResponse: any) => {
  107. // 通知 TUIConversation 添加当前会话
  108. TUIServer.TUICore.TUIServer.TUIConversation.handleCurrentConversation(
  109. imResponse.data.conversation
  110. );
  111. (data.currentGroup as any) = {};
  112. });
  113. };
  114. const isNetwork = computed(() => {
  115. // const disconnected =
  116. // data.netWork === TUIServer.TUICore.TIM.TYPES.NET_STATE_DISCONNECTED;
  117. // const connecting =
  118. // data.netWork === TUIServer.TUICore.TIM.TYPES.NET_STATE_CONNECTING;
  119. // return disconnected || connecting;
  120. return false;
  121. });
  122. // 获取列表
  123. const getList = async () => {
  124. data.loading = true;
  125. try {
  126. const res = await imGroupPage({
  127. keyword: data.keyword,
  128. page: data.page,
  129. rows: data.rows
  130. });
  131. data.groupList.push(...(res.data.rows || []));
  132. // 是否加载完成
  133. data.finshed = res.data.pages <= res.data.current ? true : false;
  134. } catch {
  135. //
  136. }
  137. data.loading = false;
  138. };
  139. onMounted(() => {
  140. getList();
  141. });
  142. const noSearch = (val: string) => {
  143. console.log(val, 'val');
  144. data.page = 1;
  145. data.keyword = val;
  146. data.groupList = [];
  147. getList();
  148. };
  149. return {
  150. ...toRefs(data),
  151. handleListItem,
  152. isNetwork,
  153. handleAvatar,
  154. handleName,
  155. handleAt,
  156. handleItemTime,
  157. noSearch
  158. };
  159. }
  160. });
  161. export default TUIGroup;
  162. </script>
  163. <style scoped lang="scss" src="./style/index.scss"></style>