index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <view class="page_container">
  3. <view class="search_bar_wrap">
  4. <img
  5. @click="back"
  6. class="back_icon"
  7. width="12"
  8. height="20"
  9. src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/common_left_arrow.png"
  10. alt=""
  11. srcset=""/>
  12. <u-search
  13. class="search_bar"
  14. shape="square"
  15. placeholder="搜索"
  16. v-model="keyword"
  17. :show-action="false"
  18. @search="enterSearch"/>
  19. </view>
  20. <u-tabs
  21. class="top_tab"
  22. lineColor="#1B72EC"
  23. :activeStyle="{ color: '#1B72EC' }"
  24. :inactiveStyle="{ color: '#ADADAD' }"
  25. :scrollable="false"
  26. :list="tabList.slice(0, storeSelfInfo.members.length ? 6 : 5)"
  27. :current="currentTab"
  28. @click="clickTab"
  29. ></u-tabs>
  30. <comprehensive-panel
  31. v-show="currentTab === 0"
  32. :data="dataSource"
  33. @toggleTab="clickTab"
  34. />
  35. <generic-panel
  36. v-show="currentTab > 0 && genericDataSource.length > 0"
  37. :generic-list="genericDataSource"
  38. @scrolltolower="scrolltolower"
  39. :isFile="currentTab === 4"
  40. />
  41. <u-empty
  42. icon="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/global_search_empty.png"
  43. v-show="currentTab > 0 && genericDataSource.length === 0"
  44. text="没有更多搜索结果"
  45. />
  46. </view>
  47. </template>
  48. <script>
  49. import { mapGetters } from "vuex";
  50. import IMSDK, { MessageType } from "openim-uniapp-polyfill";
  51. import ComprehensivePanel from "./components/ComprehensivePanel.vue";
  52. import GenericPanel from "./components/GenericPanel.vue";
  53. import { searchInOrganization } from "../../../api/orgnizaition";
  54. import { parseMessageByType } from "../../../util/imCommon";
  55. import { businessSearchUser } from "../../../api/login";
  56. export default {
  57. components: {
  58. ComprehensivePanel,
  59. GenericPanel,
  60. },
  61. data() {
  62. return {
  63. currentTab: 0,
  64. keyword: "",
  65. tabList: [
  66. {
  67. name: "综合",
  68. },
  69. {
  70. name: "联系人",
  71. },
  72. {
  73. name: "群组",
  74. },
  75. {
  76. name: "聊天记录",
  77. },
  78. {
  79. name: "文件",
  80. },
  81. {
  82. name: "组织架构",
  83. },
  84. ],
  85. dataSource: {
  86. contacts: [],
  87. groups: [],
  88. chatLogs: [],
  89. documents: [],
  90. org:[],
  91. },
  92. documentsPageIndex: 1,
  93. documentsHasMore: true,
  94. documentsLoading: false,
  95. };
  96. },
  97. computed: {
  98. ...mapGetters(["storeSelfInfo"]),
  99. genericDataSource() {
  100. switch (this.currentTab) {
  101. case 1:
  102. return this.dataSource.contacts;
  103. case 2:
  104. return this.dataSource.groups;
  105. case 3:
  106. return this.dataSource.chatLogs;
  107. case 4:
  108. return this.dataSource.documents;
  109. case 5:
  110. return this.dataSource.org;
  111. default:
  112. return [];
  113. }
  114. },
  115. },
  116. methods: {
  117. clickTab({ index }) {
  118. this.currentTab = index;
  119. },
  120. back() {
  121. uni.navigateBack();
  122. },
  123. enterSearch() {
  124. setTimeout(() => {
  125. this.documentsPageIndex = 1;
  126. this.documentsHasMore = true;
  127. this.searchUser();
  128. this.searchGroup();
  129. this.searchChatLogs();
  130. this.searchFileLogs();
  131. this.searchOrg();
  132. }, 300);
  133. },
  134. scrolltolower() {
  135. if (this.currentTab !== 4 || this.documentsLoading || !this.documentsHasMore) {
  136. return;
  137. }
  138. this.searchFileLogs();
  139. },
  140. searchUser() {
  141. const options = {
  142. keywordList: [this.keyword],
  143. isSearchUserID: false,
  144. isSearchNickname: true,
  145. isSearchRemark: true,
  146. }
  147. IMSDK.asyncApi(IMSDK.IMMethods.SearchFriends, IMSDK.uuid(), options)
  148. .then(({
  149. data
  150. }) => {
  151. this.dataSource.contacts = data
  152. })
  153. },
  154. searchGroup() {
  155. const options = {
  156. keywordList: [this.keyword],
  157. isSearchGroupID: true,
  158. isSearchGroupName: true,
  159. };
  160. IMSDK.asyncApi(IMSDK.IMMethods.SearchGroups, IMSDK.uuid(), options).then(
  161. ({ data }) => {
  162. this.dataSource.groups = data;
  163. },
  164. );
  165. },
  166. searchChatLogs() {
  167. const options = {
  168. conversationID: "",
  169. keywordList: [this.keyword],
  170. keywordListMatchType: 0,
  171. senderUserIDList: [],
  172. messageTypeList: [],
  173. searchTimePosition: 0,
  174. searchTimePeriod: 0,
  175. pageIndex: 0,
  176. count: 0,
  177. };
  178. IMSDK.asyncApi(
  179. IMSDK.IMMethods.SearchLocalMessages,
  180. IMSDK.uuid(),
  181. options,
  182. ).then(({ data }) => {
  183. const searchData = data.searchResultItems ?? [];
  184. searchData.map((item) => {
  185. item.groupID = item.messageList[0].groupID;
  186. item.sendTime = item.messageList[0].sendTime;
  187. item.latestMsg =
  188. item.messageCount > 1
  189. ? `${item.messageCount}条相关聊天记录`
  190. : parseMessageByType(item.messageList[0]);
  191. });
  192. this.dataSource.chatLogs = [...searchData];
  193. });
  194. },
  195. searchFileLogs() {
  196. const options = {
  197. conversationID: "",
  198. keywordList: [this.keyword],
  199. keywordListMatchType: 0,
  200. senderUserIDList: [],
  201. messageTypeList: [MessageType.FileMessage],
  202. searchTimePosition: 0,
  203. searchTimePeriod: 0,
  204. pageIndex: this.documentsPageIndex,
  205. count: 20,
  206. };
  207. IMSDK.asyncApi(
  208. IMSDK.IMMethods.SearchLocalMessages,
  209. IMSDK.uuid(),
  210. options,
  211. ).then(({ data }) => {
  212. const searchData = data.searchResultItems
  213. ? data.searchResultItems[0].messageList
  214. : [];
  215. const prevData =
  216. this.documentsPageIndex === 1 ? [] : this.dataSource.documents;
  217. this.dataSource.documents = [...prevData, ...searchData];
  218. this.documentsHasMore = searchData.length === 20;
  219. this.documentsPageIndex += 1;
  220. });
  221. },
  222. async searchOrg() {
  223. const res = await searchInOrganization(this.keyword)
  224. this.dataSource.org = res.users || []
  225. },
  226. },
  227. };
  228. </script>
  229. <style lang="scss">
  230. .page_container {
  231. background-color: #f8f8f8;
  232. overflow: hidden;
  233. margin-top: var(--status-bar-height);
  234. .search_bar_wrap {
  235. display: flex;
  236. justify-content: center;
  237. align-items: center;
  238. height: 34px;
  239. padding: 12px 22px 0;
  240. background-color: #fff;
  241. .search_bar {
  242. margin-left: 26rpx !important;
  243. }
  244. }
  245. .u-tabs {
  246. background-color: #fff;
  247. border-bottom: 1px solid #eaeaea;
  248. ::v-deep .u-tabs__wrapper__nav__item__text {
  249. word-break: keep-all;
  250. }
  251. ::v-deep .u-tabs__wrapper__nav__line {
  252. bottom: 0;
  253. }
  254. }
  255. .u-empty {
  256. margin-top: 20vh !important;
  257. }
  258. }
  259. </style>