zhengyiming
2025-02-10 0f686ea1fe4700a909a6159efcf1fcb0e1f88a17
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<template>
  <InfiniteLoading
    scrollViewClassName="common-infinite-scroll-list-no-padding"
    v-bind="infiniteLoadingProps"
    :custom-no-data="!myBaseChatList?.length && !flattenListData?.length"
    :refetch="handleRefetch"
  >
    <template #extra>
      <MessageCard
        v-for="item in myBaseChatList"
        :key="item.chatId"
        @click="handleClick(item)"
        :avatarUrl="MessageChatTypeAvatarMap[item.chatType]"
        :latestMessageCreationTime="item.latestMessage?.creationTime"
        :latestMessageContent="item.latestMessage?.messageContent"
        :contact="item.contact"
        :chatType="item.chatType"
        :badge="item.unReadCount"
      ></MessageCard>
    </template>
    <template #renderItem="{ item }">
      <MessageCard
        :key="item.chatId"
        @click="handleClick(item)"
        :avatarUrl="item.avatarUrl ? setOSSLink(item.avatarUrl) : ''"
        :latestMessageCreationTime="item.latestMessage?.creationTime"
        :latestMessageContent="item.latestMessage?.messageContent"
        :contact="item.contact"
        :chatType="item.chatType"
        :badge="item.unReadCount"
      ></MessageCard>
    </template>
  </InfiniteLoading>
</template>
 
<script setup lang="ts">
import { useInfiniteLoading, useRefeshDidShow } from '@12333/hooks';
import * as messageServices from '@12333/services/api/Message';
import Taro from '@tarojs/taro';
import { RouterPath, MessageChatTypeAvatarMap } from '@/constants';
import { MessageChatTypeEnum } from '@12333/constants';
import { useQuery } from '@tanstack/vue-query';
import { setOSSLink } from '@12333/utils';
 
defineOptions({
  name: 'InnerPage',
});
 
useRefeshDidShow({ queryKey: ['messageCount'] });
 
const { data: myBaseChatList, refetch } = useQuery({
  queryKey: ['messageServices/getMyBaseChatList'],
  queryFn: async () => {
    return await messageServices.getMyBaseChatList({ showLoading: false });
  },
  placeholderData: () => [] as API.MassgeChatOutput[],
});
 
useRefeshDidShow({ queryKey: ['messageServices/getMyBaseChatList'] });
 
const { infiniteLoadingProps, flattenListData } = useInfiniteLoading(
  ({ pageParam }) => {
    let params: API.QueryMyMessageInput = {
      pageModel: {
        rows: 20,
        page: pageParam,
      },
    };
 
    return messageServices.getMyFriendChatPage(params, { showLoading: false });
  },
  {
    queryKey: ['messageServices/getMyFriendChatPage'],
  }
);
 
function handleRefetch(options?: any) {
  refetch(options);
  return infiniteLoadingProps.value.refetch(options);
}
 
function handleClick(item: API.MassgeChatOutput) {
  if (item.chatType === MessageChatTypeEnum.System) {
    goPage(RouterPath.systemMessage);
  } else if (item.chatType === MessageChatTypeEnum.UnfamiliarUser) {
    goPage(RouterPath.unfamiliarUserList);
  } else {
    goPage(`${RouterPath.chatRoom}?chatId=${item.chatId}`);
  }
}
 
function goPage(routeName: string) {
  Taro.navigateTo({
    url: routeName,
  });
}
</script>
 
<style lang="scss">
@import '@/styles/common.scss';
 
.message-page-top-view {
  padding: 32px 0;
  display: flex;
  justify-content: space-evenly;
  background-color: #fff;
  margin-bottom: 8px;
 
  .message-page-top-view-item {
    display: flex;
    flex-direction: column;
    align-items: center;
 
    .message-page-top-view-item-icon-wrapper {
      width: 80px;
      height: 80px;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-bottom: 8px;
      border-radius: 50%;
 
      &.like {
        background: #ffebeb;
 
        .message-page-top-view-item-icon {
          width: 56px;
          height: 54px;
        }
      }
 
      &.attention {
        background: #e3f8ff;
 
        .message-page-top-view-item-icon {
          width: 52px;
          height: 58px;
        }
      }
    }
 
    .message-page-top-view-item-text {
      font-weight: 400;
      font-size: 24px;
      color: #7c7c7c;
      line-height: 34px;
    }
  }
}
</style>