SearchResultView.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <section class="search-result-container">
  3. <div v-if="!showEmptyView" class="search-result">
  4. <ul style="display: block">
  5. <li class="search-result-category-container" v-if="options.user && sharedSearchState.userSearchResult.length > 0">
  6. <label>{{ $t('search.new_user') }}</label>
  7. <ul>
  8. <li v-for="(user, index) in toShowUserList" :key="index">
  9. <div class="search-result-item contact">
  10. <img :src="user.portrait">
  11. <span>{{ user.displayName }}</span>
  12. <button style="margin-right: 0; margin-left: auto; border: none" size="mini" @click.stop="addFriend(user)">{{ $t('common.add') }}</button>
  13. </div>
  14. </li>
  15. </ul>
  16. <div v-if="!shouldShowAllUser && this.sharedSearchState.userSearchResult.length > 5"
  17. class="show-all"
  18. @click.stop="showAllUser">
  19. {{ $t('search.view_all') + this.sharedSearchState.userSearchResult.length }}
  20. </div>
  21. </li>
  22. <li class="search-result-category-container" v-if="options.contact && sharedSearchState.contactSearchResult.length > 0">
  23. <label>{{ $t('common.contact') }}</label>
  24. <ul>
  25. <li v-for="(contact, index) in toShowContactList" :key="index">
  26. <div class="search-result-item" @click.stop="chatToContact(contact)">
  27. <img :src="contact.portrait">
  28. <span>{{ contact._displayName }}</span>
  29. </div>
  30. </li>
  31. </ul>
  32. <div v-if="!shouldShowAllContact && this.sharedSearchState.contactSearchResult.length > 5"
  33. class="show-all"
  34. @click.stop="showAllContact">
  35. {{ $t('search.view_all') + this.sharedSearchState.contactSearchResult.length }}
  36. </div>
  37. </li>
  38. <li class="search-result-category-container" v-if="options.group && sharedSearchState.groupSearchResult.length > 0">
  39. <label>{{ $t('contact.group') }}</label>
  40. <ul>
  41. <li v-for="(group, index) in toShowGroupList" :key="index">
  42. <div class="search-result-item" @click="chatToGroup(group)">
  43. <img :src="group.portrait" alt="">
  44. <span>{{ group.remark ? group.remark : group.name }}</span>
  45. </div>
  46. </li>
  47. </ul>
  48. <div v-if="!shouldShowAllGroup && this.sharedSearchState.groupSearchResult.length > 5"
  49. class="show-all"
  50. @click.stop="showAllGroup">
  51. {{ $t('search.view_all') + this.sharedSearchState.groupSearchResult.length }}
  52. </div>
  53. </li>
  54. <li class="search-result-category-container" v-if="options.conversation && sharedSearchState.conversationSearchResult.length > 0">
  55. <label>聊天记录</label>
  56. <ul>
  57. <li v-for="(convR, index) in toShowConversationList" :key="index">
  58. <div class="search-result-item conversation" @click="onClickConversationSearchResultItem(convR)">
  59. <img :src="convR._conversationInfo.conversation._target.portrait" alt="">
  60. <div class="title-desc">
  61. <span>{{ convR._conversationInfo.conversation._target._displayName }}</span>
  62. <span class="desc">{{ conversationMatchDesc(convR) }}</span>
  63. </div>
  64. </div>
  65. </li>
  66. </ul>
  67. <div v-if="!shouldShowAllConversation&& this.sharedSearchState.conversationSearchResult.length > 5"
  68. class="show-all"
  69. @click.stop="showAllConversation">
  70. {{ $t('search.view_all') + this.sharedSearchState.conversationSearchResult.length }}
  71. </div>
  72. </li>
  73. </ul>
  74. </div>
  75. <div v-else class="empty-container">
  76. <text>没有搜索结果</text>
  77. </div>
  78. </section>
  79. </template>
  80. <script>
  81. import store from "@/store";
  82. import Conversation from "@/wfc/model/conversation";
  83. import ConversationType from "@/wfc/model/conversationType";
  84. import FriendRequestView from "@/pages/contact/FriendRequestView";
  85. import wfc from "../../wfc/client/wfc";
  86. export default {
  87. name: "SearchResultView",
  88. props: {
  89. query: {
  90. required: false,
  91. type: String,
  92. default: '',
  93. },
  94. options: {
  95. required: false,
  96. type: Object,
  97. default: () => {
  98. return {
  99. user: true,
  100. contact: true,
  101. conversation: true,
  102. group: true,
  103. }
  104. }
  105. }
  106. },
  107. data() {
  108. return {
  109. sharedSearchState: store.state.search,
  110. sharedMiscState: store.state.misc,
  111. shouldShowAllUser: false,
  112. shouldShowAllContact: false,
  113. shouldShowAllGroup: false,
  114. shouldShowAllConversation: false,
  115. }
  116. },
  117. mounted() {
  118. // do nothing
  119. let enableCount = 0;
  120. for (const key in this.options) {
  121. if (this.options[key]) {
  122. enableCount++;
  123. }
  124. }
  125. if (enableCount === 1) {
  126. this.shouldShowAllUser = this.options.user;
  127. this.shouldShowAllContact = this.options.contact;
  128. this.shouldShowAllGroup = this.options.group;
  129. this.shouldShowAllConversation = this.options.conversation;
  130. }
  131. },
  132. beforeDestroy() {
  133. store.setSearchQuery('')
  134. },
  135. watch: {
  136. // "query":function (val, oldVal){
  137. // console.log('searchView query changed:', val, oldVal)
  138. // }
  139. // or
  140. query() {
  141. console.log('searchView query changed:', this.query, this.options)
  142. // store.setSearchQuery(this.query, this.options)
  143. },
  144. },
  145. methods: {
  146. addFriend(user) {
  147. console.log('add friend', user);
  148. wfc.sendFriendRequest(user.uid, '你好', '', () => {
  149. uni.showToast({
  150. title: '发送好友请求成功',
  151. icon: 'none',
  152. });
  153. }, err => {
  154. console.log('sendFriendRequest fail', err)
  155. uni.showToast({
  156. title: ' 发送好友请求失败',
  157. icon: 'none',
  158. });
  159. })
  160. // this.$modal.show(
  161. // FriendRequestView,
  162. // {
  163. // userInfo: user,
  164. // },
  165. // {
  166. // name: 'friend-request-modal',
  167. // width: 600,
  168. // height: 250,
  169. // clickToClose: false,
  170. // }, {})
  171. },
  172. showAllUser() {
  173. this.shouldShowAllUser = true;
  174. },
  175. showAllContact() {
  176. this.shouldShowAllContact = true;
  177. },
  178. showAllGroup() {
  179. this.shouldShowAllGroup = true;
  180. },
  181. showAllConversation() {
  182. this.shouldShowAllConversation = true;
  183. },
  184. chatToContact(contact) {
  185. let conversation = new Conversation(ConversationType.Single, contact.uid, 0);
  186. store.setCurrentConversation(conversation);
  187. this.$go2ConversationPage();
  188. },
  189. chatToGroup(group) {
  190. let conversation = new Conversation(ConversationType.Group, group.target, 0);
  191. store.setCurrentConversation(conversation);
  192. this.$go2ConversationPage();
  193. },
  194. onClickConversationSearchResultItem(result) {
  195. if (result.matchMessage) {
  196. store.setCurrentConversation(result.conversation);
  197. this.$go2ConversationPage();
  198. } else {
  199. store.state.search.conversation = result.conversation;
  200. uni.navigateTo({
  201. url: '/pages/search/SearchConversationMessagePage'
  202. }
  203. );
  204. }
  205. },
  206. showMessageHistoryPage() {
  207. let hash = window.location.hash;
  208. let url = window.location.origin;
  209. if (hash) {
  210. url = window.location.href.replace(hash, '#/message-history');
  211. } else {
  212. url += "/message-history"
  213. }
  214. ipcRenderer.send(IPCRendererEventType.showMessageHistoryPage, {
  215. url: url,
  216. });
  217. console.log(IPCRendererEventType.showMessageHistoryPage, url)
  218. },
  219. conversationMatchDesc(convSearchResult) {
  220. // #ifdef APP-PLUS
  221. if (convSearchResult.matchMessage) {
  222. return convSearchResult.matchMessage.messageContent.digest(convSearchResult.matchMessage);
  223. } else {
  224. return convSearchResult.matchCount + '条相关聊天记录';
  225. }
  226. // #endif
  227. // #ifdef H5
  228. return '';
  229. // #endif
  230. },
  231. },
  232. computed: {
  233. toShowUserList: function () {
  234. return !this.shouldShowAllUser && this.sharedSearchState.userSearchResult.length > 5 ? this.sharedSearchState.userSearchResult.slice(0, 4) : this.sharedSearchState.userSearchResult;
  235. },
  236. toShowContactList: function () {
  237. return !this.shouldShowAllContact && this.sharedSearchState.contactSearchResult.length > 5 ? this.sharedSearchState.contactSearchResult.slice(0, 4) : this.sharedSearchState.contactSearchResult;
  238. },
  239. toShowGroupList: function () {
  240. return !this.shouldShowAllGroup && this.sharedSearchState.groupSearchResult.length > 5 ? this.sharedSearchState.groupSearchResult.slice(0, 4) : this.sharedSearchState.groupSearchResult;
  241. },
  242. toShowConversationList: function () {
  243. return !this.shouldShowAllConversation && this.sharedSearchState.conversationSearchResult.length > 5 ? this.sharedSearchState.conversationSearchResult.slice(0, 4) : this.sharedSearchState.conversationSearchResult;
  244. },
  245. showEmptyView() {
  246. const {userSearchResult, contactSearchResult, groupSearchResult, conversationSearchResult} = this.sharedSearchState;
  247. return userSearchResult.length + contactSearchResult.length + groupSearchResult.length + conversationSearchResult.length === 0;
  248. }
  249. },
  250. directives: {},
  251. }
  252. </script>
  253. <style lang="css" scoped>
  254. .search-result-container {
  255. margin-top: 35px;
  256. height: calc(100% - 35px);
  257. /*background-color: red;*/
  258. background-color: #f3f3f3e5;
  259. }
  260. .search-result-container .empty-container {
  261. display: flex;
  262. height: 100%;
  263. justify-content: center;
  264. align-items: center;
  265. color: grey;
  266. }
  267. .search-result-container ul {
  268. list-style: none;
  269. background-color: white;
  270. }
  271. .search-result-category-container {
  272. /*position: sticky;*/
  273. /*min-height: 40px;*/
  274. /*!* #ifndef APP-PLUS-NVUE *!*/
  275. /*position: -webkit-sticky;*/
  276. /*!* #endif *!*/
  277. /*top: 0;*/
  278. /*left: 0;*/
  279. }
  280. .search-result-category-container label {
  281. color: #828282;
  282. background: #EDEDED;
  283. display: block;
  284. padding-top: 10px;
  285. padding-bottom: 2px;
  286. padding-left: 12px;
  287. border-bottom: 1px solid #eeeeee;
  288. }
  289. .search-result-item {
  290. background-color: white;
  291. padding: 10px 12px;
  292. display: flex;
  293. align-items: center;
  294. }
  295. .search-result-item:active {
  296. background-color: #d9d9d9;
  297. }
  298. .search-result-item img {
  299. width: 34px;
  300. height: 34px;
  301. border-radius: 2px;
  302. }
  303. .search-result-item span {
  304. font-size: 14px;
  305. padding-left: 10px;
  306. }
  307. .search-result-item.conversation .title-desc {
  308. display: flex;
  309. flex-direction: column;
  310. }
  311. .search-result-item.conversation .title-desc .desc {
  312. font-size: 12px;
  313. color: grey;
  314. display: -webkit-box;
  315. -webkit-line-clamp: 3;
  316. -webkit-box-orient: vertical;
  317. overflow: hidden;
  318. }
  319. .search-result-item.contact button {
  320. margin-left: auto;
  321. padding: 3px 10px;
  322. border-radius: 3px;
  323. border: 1px solid #cccccc;
  324. outline: none;
  325. }
  326. .search-result-item.contact button:active {
  327. background: #cccccc;
  328. }
  329. .search-result-item.message {
  330. height: 54px;
  331. display: flex;
  332. align-items: center;
  333. }
  334. .show-all {
  335. padding-left: 12px;
  336. color: #66789d;
  337. font-size: 12px;
  338. }
  339. </style>