Wire consultation page to dialogue API

This commit is contained in:
JiXinHui 2025-12-16 14:29:02 +08:00
parent 217d0bd20f
commit 38154d6306
1 changed files with 114 additions and 81 deletions

View File

@ -13,8 +13,8 @@
<!-- 聊天会话列表 --> <!-- 聊天会话列表 -->
<view <view
class="chat-item" class="chat-item"
v-for="(item, index) in chatList" v-for="(item, index) in displayChatList"
:key="item.id" :key="item.id || index"
@click="openChat(item)" @click="openChat(item)"
> >
<view class="chat-avatar-wrapper"> <view class="chat-avatar-wrapper">
@ -28,10 +28,10 @@
<view class="chat-content"> <view class="chat-content">
<view class="chat-header"> <view class="chat-header">
<text class="chat-name">{{ item.name }}</text> <text class="chat-name">{{ item.name }}</text>
<text class="chat-time">{{ item.lastMessageTime }}</text> <text class="chat-time">{{ item.displayTime }}</text>
</view> </view>
<view class="chat-preview"> <view class="chat-preview">
<text class="preview-text">{{ item.lastMessage }}</text> <text class="preview-text">{{ item.displayPreview }}</text>
</view> </view>
</view> </view>
</view> </view>
@ -61,76 +61,38 @@ export default {
TabBar, TabBar,
PageHeader, PageHeader,
}, },
computed: {
// 使
displayChatList() {
return (this.chatList || []).map((item) => ({
...item,
displayTime: item.lastMessageTime || "",
displayPreview: item.lastMessage || "暂无消息",
}));
},
},
data() { data() {
return { return {
// //
chatList: [ chatList: [],
{ totalCount: 0,
id: 1, isLoading: false,
userId: 'user_001', hasLoaded: false,
name: '山东考生1',
avatar: '/static/avatar/default-avatar.png',
lastMessage: '你好,在吗',
lastMessageTime: '09:50',
unreadCount: 2,
},
{
id: 2,
userId: 'user_002',
name: '河北考生2',
avatar: '/static/avatar/default-avatar.png',
lastMessage: '我是保研的是否了解到了后续计划,谁信谁的呢们爱国士...',
lastMessageTime: '09:50',
unreadCount: 0,
},
{
id: 3,
userId: 'user_003',
name: '山东考生34523',
avatar: '/static/avatar/default-avatar.png',
lastMessage: '请问,学校宿舍几人间?',
lastMessageTime: '09:50',
unreadCount: 1,
},
{
id: 4,
userId: 'user_004',
name: '招办王老师',
avatar: '/static/avatar/default-avatar.png',
lastMessage: '你好,在吗',
lastMessageTime: '09:50',
unreadCount: 0,
},
{
id: 5,
userId: 'user_005',
name: '山东考生34523',
avatar: '/static/avatar/default-avatar.png',
lastMessage: '请问,学校宿舍几人间?',
lastMessageTime: '09:50',
unreadCount: 3,
},
{
id: 6,
userId: 'user_006',
name: '招办王老师',
avatar: '/static/avatar/default-avatar.png',
lastMessage: '你好,在吗',
lastMessageTime: '09:50',
unreadCount: 0,
},
],
}; };
}, },
onLoad() { onLoad() {
// //
this.loadChatList(); this.loadChatList().finally(() => {
this.hasLoaded = true;
});
}, },
onShow() { onShow() {
// //
this.refreshChatList(); if (this.hasLoaded) {
this.refreshChatList();
}
}, },
methods: { methods: {
@ -147,19 +109,87 @@ export default {
}, },
// //
loadChatList() { async loadChatList() {
// TODO: API if (this.isLoading) return;
// this.$u.api.getChatList().then(res => { this.isLoading = true;
// this.chatList = res.data;
// }); try {
const res = await this.$u.api.GetDialogueListApi();
console.log('[在线咨询] 加载聊天列表'); const list = (res && res.data && res.data.item1) || [];
this.chatList = this.normalizeDialogueList(list);
this.totalCount = res?.data?.item2 || list.length;
} catch (error) {
console.error("[在线咨询] 获取会话列表失败", error);
uni.showToast({
title: "获取会话列表失败",
icon: "none",
});
} finally {
this.isLoading = false;
}
}, },
// //
refreshChatList() { refreshChatList() {
console.log('[在线咨询] 刷新聊天列表'); this.loadChatList();
// TODO: },
//
normalizeDialogueList(list = []) {
//
return list.map((item, index) => {
const unread =
typeof item?.unReadCount === "number"
? item.unReadCount
: item?.unreadCount || 0;
return {
id: item?.dialogueManagementId || item?.dialogueId || item?.id || index,
userId: item?.receiverId || item?.friendId || item?.userId || "",
name:
item?.receiverName ||
item?.friendName ||
item?.userName ||
item?.title ||
"",
avatar: this.buildAvatarUrl(
item?.receiverHeadSculptureUrl ||
item?.avatar ||
item?.friendAvatar
),
lastMessage: item?.title || item?.lastMessage || item?.content || "暂无消息",
lastMessageTime: this.formatTime(
item?.lastMessageTime || item?.lastSendTime || item?.startTime
),
unreadCount: unread,
};
});
},
//
buildAvatarUrl(url) {
const fallback = "/static/avatar/default-avatar.png";
if (!url) return fallback;
if (/^https?:\/\//i.test(url)) return url;
const baseUrl = this.$u?.http?.config?.baseUrl || "";
if (baseUrl) return `${baseUrl}/${url}`;
return url.startsWith("/") ? url : `/${url}`;
},
//
formatTime(timeStr) {
if (!timeStr) return "";
const date = new Date(timeStr);
if (!isNaN(date.getTime())) {
const month = (date.getMonth() + 1).toString().padStart(2, "0");
const day = date.getDate().toString().padStart(2, "0");
const hours = date.getHours().toString().padStart(2, "0");
const minutes = date.getMinutes().toString().padStart(2, "0");
return `${month}/${day} ${hours}:${minutes}`;
}
// 退
return String(timeStr).replace("T", " ").slice(5, 16);
}, },
}, },
}; };
@ -234,19 +264,23 @@ export default {
/* ===== 聊天列表项 ===== */ /* ===== 聊天列表项 ===== */
.chat-item { .chat-item {
display: flex; display: flex;
padding: 15px; align-items: center;
background: #fff; padding: 14px 16px;
border-bottom: 1rpx solid #f0f0f0; background-color: #fff;
border-bottom: 1rpx solid #f1f1f1;
transition: background-color 0.2s; transition: background-color 0.2s;
} }
.chat-item:active { .chat-item:active {
background-color: #f5f5f5; background-color: #f8f8f8;
} }
.chat-avatar-wrapper { .chat-avatar-wrapper {
position: relative; position: relative;
margin-right: 12px; margin-right: 12px;
width: 50px;
height: 50px;
flex-shrink: 0;
} }
.chat-avatar { .chat-avatar {
@ -290,8 +324,8 @@ export default {
.chat-name { .chat-name {
font-size: 16px; font-size: 16px;
font-weight: 500; font-weight: 500;
color: #333; color: #1f1f1f;
max-width: 200px; max-width: 70%;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
@ -299,7 +333,7 @@ export default {
.chat-time { .chat-time {
font-size: 12px; font-size: 12px;
color: #999; color: #9b9b9b;
flex-shrink: 0; flex-shrink: 0;
} }
@ -310,7 +344,7 @@ export default {
.preview-text { .preview-text {
font-size: 13px; font-size: 13px;
color: #999; color: #9b9b9b;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
@ -343,4 +377,3 @@ export default {
color: #999; color: #999;
} }
</style> </style>