index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div style="height: 100%">
  3. <div class="sectionSearch">
  4. <n-input
  5. class="TheSearch"
  6. style="--n-font-size: 12px; --n-height: 32px; --n-caret-color: #198cfe; --n-border-hover: 1px solid #198cfe; --n-border-focus: 1px solid #198cfe; --n-loading-color: #198cfe; --n-box-shadow-focus: 0 0 0 2px rgba(25 140 254, 0.2)"
  7. round
  8. clearable
  9. placeholder="请输入名称"
  10. v-model:value="keyword"
  11. @clear="
  12. () => {
  13. debouncedRequest('');
  14. }
  15. "
  16. @keyup="onKeyup"
  17. >
  18. <template #prefix>
  19. <span class="icon-search-input"></span>
  20. </template>
  21. </n-input>
  22. </div>
  23. <div class="TUI-person">
  24. <main class="TUI-conversation-list">
  25. <aside class="TUI-contact-left">
  26. <ul class="TUI-contact-list">
  27. <li class="TUI-contact-list-item" v-for="(item, index) in friendList" :key="index" @click="handleListItem(item)">
  28. <aside class="left">
  29. <img class="avatar" :src="item.friendAvatar || 'https://oss.dayaedu.com/news-info/07/1690787574969.png'" onerror="this.src='https://oss.dayaedu.com/news-info/07/1690787574969.png'" />
  30. </aside>
  31. <div class="content-header">
  32. <label>
  33. <p class="name">{{ item.friendNickname }}</p>
  34. </label>
  35. <div class="middle-box">
  36. <p>{{ item.subjectName }}</p>
  37. </div>
  38. </div>
  39. </li>
  40. </ul>
  41. </aside>
  42. </main>
  43. <div class="theEmtpy" v-if="!loading && friendList.length <= 0" style="height: 90%">
  44. <img class="emptyImg" src="../../assets/nomore.png" />
  45. <p>暂无数据</p>
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script lang="ts">
  51. import { defineComponent, reactive, toRefs, onMounted } from "vue";
  52. import { imUserFriendPage } from "../../../api";
  53. import { useThrottleFn } from "@vueuse/core";
  54. const TUIPerson = defineComponent({
  55. name: "TUIPerson",
  56. setup(props) {
  57. const TUIServer: any = TUIPerson.TUIServer;
  58. const data = reactive({
  59. loading: true,
  60. page: 1,
  61. rows: 100,
  62. keyword: "",
  63. finshed: false, // 是否加载完
  64. friendList: [] as any,
  65. searchGroup: [],
  66. searchID: "",
  67. currentGroup: null,
  68. });
  69. // 获取列表
  70. const getList = async () => {
  71. data.loading = true;
  72. try {
  73. const res = await imUserFriendPage({
  74. search: data.keyword,
  75. page: data.page,
  76. rows: data.rows,
  77. });
  78. data.friendList.push(...(res.data || []));
  79. // 是否加载完成;
  80. data.finshed = true; //res.data.pages <= res.data.current ? true : false;
  81. } catch {
  82. //
  83. }
  84. data.loading = false;
  85. };
  86. const handleListItem = async (item: any) => {
  87. const name = `C2C${item.imFriendId}`;
  88. console.log(item, "item", TUIServer.TUICore);
  89. TUIServer.TUICore.TUIServer.TUIConversation.getConversationProfile(name).then((imResponse: any) => {
  90. // 通知 TUIConversation 添加当前会话
  91. TUIServer.TUICore.TUIServer.TUIConversation.handleCurrentConversation(imResponse.data.conversation);
  92. (data.currentGroup as any) = {};
  93. });
  94. };
  95. const noSearch = (val: string) => {
  96. data.page = 1;
  97. data.keyword = val;
  98. data.friendList = [];
  99. getList();
  100. };
  101. onMounted(() => {
  102. getList();
  103. });
  104. const debouncedRequest = useThrottleFn((val: string) => {
  105. noSearch(val);
  106. }, 500);
  107. const onKeyup = (e: any) => {
  108. e.stopPropagation();
  109. if (e.code === "Enter") {
  110. debouncedRequest(data.keyword);
  111. }
  112. };
  113. return {
  114. ...toRefs(data),
  115. handleListItem,
  116. noSearch,
  117. onKeyup,
  118. debouncedRequest,
  119. };
  120. },
  121. });
  122. export default TUIPerson;
  123. </script>
  124. <style scoped lang="scss" src="./style/index.scss"></style>