index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <page-meta root-font-size="system" />
  3. <view class="contact_container">
  4. <uv-index-list :index-list="indexList">
  5. <template v-for="(items, index) in itemArr" :key="index">
  6. <uv-index-item>
  7. <uv-index-anchor :text="indexList[index]" size="16"></uv-index-anchor>
  8. <view class="chat_list">
  9. <uni-list :border="true">
  10. <uni-list-chat v-for="(item, index) in items" @click="clickChat(item)" :title="item.name"
  11. :avatar="item.avatar || config.baseUrlPre+config.defaultAvatarPath" :note="item.desktop_phone" :clickable="true"
  12. :avatar-circle="true" :key="index">
  13. <view class="chat-custom-right">
  14. <text class="chat-custom-text" v-text="item.dept"></text>
  15. </view>
  16. </uni-list-chat>
  17. </uni-list>
  18. </view>
  19. </uv-index-item>
  20. </template>
  21. </uv-index-list>
  22. </view>
  23. </template>
  24. <script setup lang="ts">
  25. import { onMounted, ref } from 'vue'
  26. import $tab from '@/plugins/tab.js'
  27. import { getContactAllUser } from '@/api/contacts.js'
  28. import { useUserStore } from '@/store/user.js'
  29. import { onShow } from '@dcloudio/uni-app'
  30. import config from '@/config';
  31. const userStore = useUserStore()
  32. onMounted(() => {
  33. // 获取 通讯录 索引列表
  34. let unitId = userStore.user.unitId
  35. if ( unitId === 0 ) unitId = userStore.user.groupid
  36. // getContactAllUser(userStore.user.groupid).then(res => {
  37. getContactAllUser(unitId).then(res => {
  38. getContactList(res.returnParams)
  39. })
  40. })
  41. onShow(()=>{
  42. uni.$emit('showTabBarBadge')
  43. })
  44. // 索引列表
  45. const indexList = ref([])
  46. const itemArr = ref([])
  47. function getContactList(data) {
  48. for (let key in data) {
  49. // hasOwnProperty 排除 __proto__等数据
  50. if (data.hasOwnProperty(key)) {
  51. // 过滤 userState 为 0 的 user
  52. data[key] = data[key].filter(user => user.userState !== '0' && user.name.slice(-3) !== '管理员')
  53. } else {
  54. continue
  55. }
  56. // 删除 过滤后 数据为0的 索引
  57. if (data[key].length === 0) delete data[key]
  58. }
  59. // 获取索引
  60. indexList.value = Object.keys(data)
  61. // 获取索引数据
  62. itemArr.value = Object.values(data)
  63. }
  64. // function clickTop() {
  65. // console.log('clickTop');
  66. // }
  67. // 点击通讯录列表
  68. function clickChat(e) {
  69. $tab.navigateTo('/pages/mine/personal_message/personal_message?useId=' + e.useId)
  70. }
  71. </script>
  72. <style lang="scss">
  73. ::v-deep .contact_container {
  74. .uv-index-list {
  75. .uv-index-list__letter {
  76. .uv-index-list__letter__item {
  77. width: calc(16px + .5*(1rem - 16px)) !important;
  78. height: calc(16px + .5*(1rem - 16px)) !important;
  79. }
  80. }
  81. .uv-index-item {
  82. .uv-index-anchor {
  83. height: calc(32px + .5*(1rem - 16px)) !important;
  84. .uv-index-anchor__text {
  85. font-size: calc(1.5rem + 0px) !important;
  86. }
  87. }
  88. .chat_list {
  89. .uni-list-chat {
  90. .uni-list-chat__header-warp {
  91. .uni-list-chat__header {
  92. width: calc(45px + .5*(1rem - 16px)) !important;
  93. height: calc(45px + .5*(1rem - 16px)) !important;
  94. }
  95. }
  96. .uni-list-chat__content {
  97. .uni-list-chat__content-title {
  98. font-size: calc(1rem + 0px) !important;
  99. }
  100. .uni-list-chat__content-note {
  101. font-size: calc(0.75rem + 0px) !important;
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. // .top {
  109. // .top_slot_container {
  110. // height: 100%;
  111. // width: 100%;
  112. // ::v-deep .uni-icons {
  113. // background-color: #468bf0;
  114. // border-radius: 50%;
  115. // }
  116. // .top_text {
  117. // font-size: calc(1.5rem + 0px);
  118. // }
  119. // }
  120. // }
  121. .chat_list {
  122. .chat-custom-right {
  123. .chat-custom-text {
  124. margin-right: 10px;
  125. }
  126. }
  127. }
  128. }
  129. </style>