groupList.vue 2.1 KB
Newer Older
1
<template>
2
	<view class="contacts-groupList">
3 4 5 6 7 8
		<uni-search-bar placeholder="搜索群号/群名称" :radius="100" bgColor="#eeeeee" v-model="keyword" 
			@cancel="doClear"
			@clear="doClear"
		></uni-search-bar>
		<view class="uni-list">
			<uni-im-info-card v-for="(item,index) in groupList" :key="index" 
DCloud_JSON's avatar
3.4.31  
DCloud_JSON 已提交
9 10 11
				@click="toChat(item._id)" link
				:title="item?.name"
				:avatar="item?.avatar_file?.url || '/uni_modules/uni-im/static/avatarUrl.png'">
12
			</uni-im-info-card>
DCloud_JSON's avatar
3.4.31  
DCloud_JSON 已提交
13
      <uni-im-load-state class="uni-im-load-state" :status="groupHasMore?'loading':'noMore'"></uni-im-load-state>
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
		</view>
	</view>
</template>

<script>
	import uniIm from '@/uni_modules/uni-im/sdk/index.js';
	export default {
		data() {
			return {
				keyword: '',
				groupData:false
			}
		},
		computed: {
			//是否为pc宽屏(width>960px)
			isWidescreen(){
				return uniIm.isWidescreen
			},
			groupList() {
DCloud_JSON's avatar
3.4.31  
DCloud_JSON 已提交
33
				const groupList = uniIm.group.dataList
34 35
				if(this.keyword){
					return groupList.filter(item=>{
DCloud_JSON's avatar
3.4.31  
DCloud_JSON 已提交
36
					  return item.name.includes(this.keyword) || item._id.includes(this.keyword)
37 38 39 40 41 42 43 44 45
					})
				}else{
					return groupList
				}
			},
			groupHasMore(){
				return uniIm.group.hasMore
			}
		},
DCloud_JSON's avatar
3.4.31  
DCloud_JSON 已提交
46 47 48 49 50 51 52 53 54
    mounted() {
      uni.createIntersectionObserver(this, { observeAll: true })
        .relativeTo('body', {})
        .observe('.uni-im-load-state', (res) => {
          if (res.intersectionRatio > 0) {
            uniIm.group.loadMore()
          }
        })
    },
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    async onLoad(options) {
    	this.setParam(options)
    },
		methods: {
      setParam(param = {}){
        if(param.group_id){
          this.keyword = param.group_id
        }
      },
			doClear(){
				this.keyword = ''
			},
			toChat(group_id) {
				let conversation_id = 'group_' + group_id
        uniIm.toChat({conversation_id})
			}
		}
	}
</script>

75 76 77 78 79 80
<style lang="scss">
@import "@/uni_modules/uni-im/common/baseStyle.scss";
.contacts-groupList {
  /* #ifdef H5 */
  	@media screen and (min-device-width:960px){
      .uni-list {
DCloud_JSON's avatar
3.4.31  
DCloud_JSON 已提交
81
        height: calc(100vh - 165px);
82 83 84 85 86
        overflow: auto;
      }
  	}
  /* #endif */
}
87
</style>