uni-im-choose-user.vue 2.9 KB
Newer Older
DCloud_JSON's avatar
3.4.31  
DCloud_JSON 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
<template>
  <view class="user-list">
    <text class="title" v-if="title">{{title}}</text>
    <view class="item" v-for="(user,index) in userList" :key="index">
      <uni-im-img class="avatar" width="20" height="20" borderRadius="100%"
        :src="user?.avatar_file?.url || '/uni_modules/uni-im/static/avatarUrl.png'"></uni-im-img>
      <text class="nickname">{{user.nickname}}</text>
      <uni-im-icons class="delete" @click="deleteItem(index)" code="e61a" color="#888" size="10px"></uni-im-icons>
    </view>
    <view class="add-icon" v-if="multiple || userList.length === 0">
      <uni-icons @click="showMemberList" color="#aaa" size="16px" type="plusempty"></uni-icons>
    </view>
    <uni-im-member-list ref="member-list" :conversationId="conversationId" :memberListData="memberListData"></uni-im-member-list>
  </view>
</template>

<script>
  import uniIm from '@/uni_modules/uni-im/sdk/index.js';
  export default {
    emits: ['update:modelValue'],
    props: {
      modelValue: {
        type: Array,
        default: []
      },
      filterUids: {
        type: [Array,null],
        default: null
      },
      conversationId: {
        default: '',
      },
      memberListData: {
        type: [Array,null],
        default: null
      },
      title: {
        type: [String,null],
        default: null
      },
      multiple: {
        type: Boolean,
        default: true
      }
    },
    data() {
      return {
        
      }
    },
    computed: {
      userList() {
        return uniIm.users.find(this.modelValue)
      }
    },
    methods: {
      deleteItem(index) {
        this.$emit('update:modelValue', this.modelValue.filter((_, i) => i !== index))
      },
      showMemberList() {
        this.$refs['member-list'].show({
          title: '添加话题成员',
          forceShowSearch: true,
          filter: member => !(this.filterUids || this.modelValue).includes(member.users._id),
          confirm: (uid) => {
            console.log('uid--showMenberList-*', uid)
            this.$emit('update:modelValue', this.modelValue.concat(uid))
          }
        })
      },
    }
  }
</script>

<style lang="scss">
.user-list {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;

  .title {
    font-size: 14px;
    color: #555;
    font-weight: unset;
  }

  .item {
    font-size: 14px;
    padding: 0 3px;
    margin-left: 6px;
    margin-top: 5px;
    border: 1px solid #eee;
    border-radius: 5px;
    flex-direction: row;
    justify-content: center;
    align-items: center;

    .avatar {
      margin-right: 5px;
    }

    .nickname {
      color: #333;
    }

    .delete {
      margin: 0 5px;
      opacity: 0.7;

      &:hover {
        opacity: 1;
      }
    }

    height: 26px;
  }
  .add-icon {
    cursor: pointer;
    border: 1px #aaa dashed;
    height: 26px;
    width: 26px;
    justify-content: center;
    margin-left: 10px;
  }
}
</style>