users.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view>
  3. <cu-custom bgImage="/static/bg.png" :isBack="true">
  4. <template v-slot:content>
  5. <text class="text-black">部门用户</text>
  6. </template>
  7. </cu-custom>
  8. <uni-easyinput placeholder="请输入姓名拼音搜索" type="text" v-model="keyword" :clearable="true" @clear="clear"/>
  9. <index-bar :index-map="map" v-if="map.size > 0">
  10. <view v-for="(item,key) in map.keys()" :key="key">
  11. <view :class="'indexItem-' + item" :id="'indexes-' + item" :data-index="item">
  12. <view class="padding">{{ item }}</view>
  13. <view class="cu-list menu-avatar no-padding">
  14. <view class="cu-item" v-for="(user) in keywordFilter(map.get(item),keyword)" :key="user.id" @tap="showUser(user.id)">
  15. <vim-avatar :img="user.avatar" :name="user.name" />
  16. <view class="content">
  17. <view class="text-grey">{{ user.name }}</view>
  18. <view class="text-gray text-sm">
  19. {{ user.name }}
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </index-bar>
  27. <no-data v-if="map.size === 0 && hidden"/>
  28. </view>
  29. </template>
  30. <script setup lang="ts">
  31. import {getCurrentInstance, ref} from "vue";
  32. import Tools from "@/utils/Tools";
  33. import CuCustom from '@/colorui/components/cu-custom.vue'
  34. import IndexBar from '@/components/IndexBar.vue'
  35. import DeptApi from "@/api/DeptApi";
  36. import {onLoad} from '@dcloudio/uni-app';
  37. import NoData from "@/components/NoData.vue";
  38. import VimAvatar from "@/components/VimAvatar.vue";
  39. import { match } from 'pinyin-pro'
  40. import type User from "@/mode/User";
  41. import UniEasyinput from "@/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue";
  42. const {proxy} = getCurrentInstance();
  43. const map = ref(new Map());
  44. const hidden = ref(false);
  45. const keyword = ref('');
  46. const deptId = ref('');
  47. /**
  48. * 聊天过滤器
  49. * @param items 聊天列表
  50. * @param keyword 关键词
  51. */
  52. const keywordFilter = (items: User[], keyword: string): User[] => {
  53. return items.filter((item) => {
  54. return !!(keyword.trim() === '' || match(item.name, keyword))
  55. })
  56. }
  57. const clear = () => {
  58. keyword.value = '';
  59. }
  60. const loadUsers = () => {
  61. uni.showLoading();
  62. hidden.value = false
  63. DeptApi.users(deptId.value).then((res) => {
  64. map.value = Tools.listToMap(res.data);
  65. }).finally(() => {
  66. uni.hideLoading();
  67. hidden.value = true
  68. })
  69. }
  70. onLoad((opt) => {
  71. deptId.value = opt?.id;
  72. loadUsers();
  73. })
  74. const showUser = (id: string) => {
  75. uni.navigateTo({
  76. url: '/pages/pub/user?id=' + id
  77. })
  78. }
  79. </script>
  80. <style scoped></style>