index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view class="friend_list_container">
  3. <custom-nav-bar title="我的好友" />
  4. <view class="search_bar_wrap">
  5. <u-search class="search_bar" shape="square" placeholder="搜索" :showAction="false" disabled @click="toSearch" />
  6. </view>
  7. <choose-index-list
  8. v-if="getIndexData.dataList.length > 0"
  9. @itemClick="userClick"
  10. :height="`${listHeight}px`"
  11. :indexList="getIndexData.indexList"
  12. :itemArr="getIndexData.dataList"/>
  13. <u-empty v-else mode="list" />
  14. </view>
  15. </template>
  16. <script>
  17. import { mapGetters } from 'vuex';
  18. import { formatChooseData } from '../../../util/common';
  19. import CustomNavBar from '../../../components/CustomNavBar/index.vue';
  20. import ChooseIndexList from '../../../components/ChooseIndexList/index.vue';
  21. import { navigateToDesignatedConversation, callingModule } from '../../../util/imCommon';
  22. import IMSDK, { SessionType } from 'openim-uniapp-polyfill';
  23. export default {
  24. components: {
  25. CustomNavBar,
  26. ChooseIndexList
  27. },
  28. data() {
  29. return {
  30. keyword: '',
  31. listHeight: 0
  32. };
  33. },
  34. computed: {
  35. ...mapGetters(['storeFriendList']),
  36. getIndexData() {
  37. return formatChooseData(this.storeFriendList);
  38. }
  39. },
  40. mounted() {
  41. this.getListHeight();
  42. },
  43. methods: {
  44. toSearch() {
  45. console.log("qxj toSearch");
  46. uni.navigateTo({
  47. url: `/pages_im/pages/contact/searchAddedFriend/index`
  48. });
  49. //uni.$u.route('/pages_im/pages/contact/searchAddedFriend/index');
  50. },
  51. userClick(friend) {
  52. this.toDesignatedConversation(friend.userID);
  53. },
  54. toDesignatedConversation(sourceID) {
  55. navigateToDesignatedConversation(sourceID, SessionType.Single, this.memberInfo !== null).catch(() => uni.$u.toast('获取会话信息失败'));
  56. },
  57. async getListHeight() {
  58. const windowInfo = uni.getWindowInfo();
  59. const data = await this.getEl('.search_bar_wrap');
  60. const searchBarHeight = Number(data.height.toFixed());
  61. this.listHeight = windowInfo.windowHeight - windowInfo.statusBarHeight - 44 - searchBarHeight;
  62. },
  63. getEl(el) {
  64. return new Promise((resolve) => {
  65. const query = uni.createSelectorQuery().in(this);
  66. query.select(el)
  67. .boundingClientRect((data) => {
  68. // 存在data,且存在宽和高,视为渲染完毕
  69. resolve(data);
  70. })
  71. .exec();
  72. });
  73. }
  74. }
  75. };
  76. </script>
  77. <style lang="scss" scoped>
  78. .friend_list_container {
  79. .search_bar_wrap {
  80. height: 54px;
  81. padding: 12px 22px;
  82. }
  83. .u-empty {
  84. margin-top: 25vh !important;
  85. }
  86. }
  87. </style>