Compare commits
4 Commits
dc4d8f9b1b
...
2d10c5d7cb
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d10c5d7cb | |||
| f00383034d | |||
| 6b31ad9067 | |||
| 865dea432a |
@ -119,10 +119,10 @@
|
|||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view v-if="showBindWechat" class="footer">
|
<view v-if="showGoChat" class="footer">
|
||||||
<button class="bind-btn" @click="bindWechat">
|
<button class="bind-btn" @click="goChat">
|
||||||
<uni-icons type="email" size="18" color="#fff" />
|
<uni-icons type="chat-filled" size="18" color="#fff" />
|
||||||
<text class="bind-text">关联患者微信</text>
|
<text class="bind-text">去聊天</text>
|
||||||
</button>
|
</button>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@ -262,6 +262,7 @@ const archive = ref({
|
|||||||
creator: '',
|
creator: '',
|
||||||
createdByDoctor: true,
|
createdByDoctor: true,
|
||||||
hasBindWechat: false,
|
hasBindWechat: false,
|
||||||
|
chatGroupId: '',
|
||||||
notes: '',
|
notes: '',
|
||||||
groupIds: []
|
groupIds: []
|
||||||
});
|
});
|
||||||
@ -283,6 +284,17 @@ function getCorpId() {
|
|||||||
return String(d.corpId || a.corpId || team.corpId || '') || '';
|
return String(d.corpId || a.corpId || team.corpId || '') || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCurrentTeamId() {
|
||||||
|
const team = uni.getStorageSync(CURRENT_TEAM_STORAGE_KEY) || {};
|
||||||
|
return String(team?.teamId || team?._id || team?.id || '') || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeGroupId(v) {
|
||||||
|
const s = String(v || '').trim();
|
||||||
|
if (!s) return '';
|
||||||
|
return s.startsWith('GROUP') ? s.slice(5) : s;
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeArchiveFromApi(raw) {
|
function normalizeArchiveFromApi(raw) {
|
||||||
const r = raw && typeof raw === 'object' ? raw : {};
|
const r = raw && typeof raw === 'object' ? raw : {};
|
||||||
const next = {
|
const next = {
|
||||||
@ -302,6 +314,7 @@ function normalizeArchiveFromApi(raw) {
|
|||||||
creator: r.creator || '',
|
creator: r.creator || '',
|
||||||
notes: r.notes || r.remark || '',
|
notes: r.notes || r.remark || '',
|
||||||
groupIds: Array.isArray(r.groupIds) ? r.groupIds : [],
|
groupIds: Array.isArray(r.groupIds) ? r.groupIds : [],
|
||||||
|
chatGroupId: normalizeGroupId(r.chatGroupId || r.groupId || r.groupID || r.imGroupId || r.imGroupID || r.consultGroupId || ''),
|
||||||
};
|
};
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
@ -330,6 +343,23 @@ async function fetchArchive() {
|
|||||||
saveToStorage();
|
saveToStorage();
|
||||||
loadTeamMembers();
|
loadTeamMembers();
|
||||||
await fetchTeamGroups(true);
|
await fetchTeamGroups(true);
|
||||||
|
chatGroupId.value = normalizeGroupId(archive.value.chatGroupId || '');
|
||||||
|
if (!chatGroupId.value) {
|
||||||
|
refreshChatRoom();
|
||||||
|
} else {
|
||||||
|
const meta = await getChatRoomMeta(chatGroupId.value);
|
||||||
|
const ok = isChatRoomForArchive(meta, archiveId.value);
|
||||||
|
const currentTeamId = getCurrentTeamId();
|
||||||
|
const metaTeamId = String(meta?.teamId || meta?.team?.teamId || meta?.team?._id || '');
|
||||||
|
if (!ok || (currentTeamId && metaTeamId && metaTeamId !== currentTeamId)) {
|
||||||
|
chatGroupId.value = '';
|
||||||
|
archive.value.chatGroupId = '';
|
||||||
|
refreshChatRoom();
|
||||||
|
} else {
|
||||||
|
archive.value.chatGroupId = chatGroupId.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveToStorage();
|
||||||
// 档案信息刷新后,tabs 的位置可能变化,重新测量
|
// 档案信息刷新后,tabs 的位置可能变化,重新测量
|
||||||
nextTick(() => setTimeout(measureTabsTop, 30));
|
nextTick(() => setTimeout(measureTabsTop, 30));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -473,16 +503,20 @@ onLoad((options) => {
|
|||||||
fromChat.value = options?.fromChat === 'true' || options?.fromChat === true;
|
fromChat.value = options?.fromChat === 'true' || options?.fromChat === true;
|
||||||
|
|
||||||
const cached = uni.getStorageSync(STORAGE_KEY);
|
const cached = uni.getStorageSync(STORAGE_KEY);
|
||||||
if (cached && typeof cached === 'object') {
|
const cachedObj = cached && typeof cached === 'object' ? cached : null;
|
||||||
|
const cachedId = cachedObj ? String(cachedObj._id || cachedObj.id || '') : '';
|
||||||
|
const canUseCached = Boolean(cachedObj && (!cachedId || !archiveId.value || cachedId === archiveId.value));
|
||||||
|
if (canUseCached) {
|
||||||
archive.value = {
|
archive.value = {
|
||||||
...archive.value,
|
...archive.value,
|
||||||
...cached,
|
...cached,
|
||||||
groupIds: Array.isArray(cached.groupIds) ? cached.groupIds : archive.value.groupIds
|
groupIds: Array.isArray(cached.groupIds) ? cached.groupIds : archive.value.groupIds
|
||||||
};
|
};
|
||||||
|
chatGroupId.value = normalizeGroupId(archive.value.chatGroupId || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!archive.value.mobile) {
|
if (!archive.value.mobile) {
|
||||||
const mobiles = cached && Array.isArray(cached.mobiles) ? cached.mobiles : [];
|
const mobiles = canUseCached && cachedObj && Array.isArray(cachedObj.mobiles) ? cachedObj.mobiles : [];
|
||||||
if (mobiles.length) archive.value.mobile = String(mobiles[0]);
|
if (mobiles.length) archive.value.mobile = String(mobiles[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -512,12 +546,14 @@ onReady(() => {
|
|||||||
|
|
||||||
onShow(() => {
|
onShow(() => {
|
||||||
const cached = uni.getStorageSync(STORAGE_KEY);
|
const cached = uni.getStorageSync(STORAGE_KEY);
|
||||||
if (cached && typeof cached === 'object') {
|
const cachedId = cached && typeof cached === 'object' ? String(cached._id || cached.id || '') : '';
|
||||||
|
if (cached && typeof cached === 'object' && (!cachedId || !archiveId.value || cachedId === archiveId.value)) {
|
||||||
archive.value = {
|
archive.value = {
|
||||||
...archive.value,
|
...archive.value,
|
||||||
...cached,
|
...cached,
|
||||||
groupIds: Array.isArray(cached.groupIds) ? cached.groupIds : archive.value.groupIds,
|
groupIds: Array.isArray(cached.groupIds) ? cached.groupIds : archive.value.groupIds,
|
||||||
};
|
};
|
||||||
|
chatGroupId.value = normalizeGroupId(archive.value.chatGroupId || '');
|
||||||
}
|
}
|
||||||
setTimeout(measureTabsTop, 30);
|
setTimeout(measureTabsTop, 30);
|
||||||
fetchArchive();
|
fetchArchive();
|
||||||
@ -556,12 +592,16 @@ const createText = computed(() => {
|
|||||||
const creatorId = ['-', '—', '--'].includes(rawCreator.trim()) ? '' : rawCreator.trim();
|
const creatorId = ['-', '—', '--'].includes(rawCreator.trim()) ? '' : rawCreator.trim();
|
||||||
const creatorName = creatorId ? resolveUserName(creatorId) : '';
|
const creatorName = creatorId ? resolveUserName(creatorId) : '';
|
||||||
if (time && creatorName) return `${time} ${creatorName}创建`;
|
if (time && creatorName) return `${time} ${creatorName}创建`;
|
||||||
|
if (time && !rawCreator.trim()) return `${time} 患者创建`;
|
||||||
if (time) return `${time} 创建`;
|
if (time) return `${time} 创建`;
|
||||||
|
if (!rawCreator.trim()) return '患者创建';
|
||||||
return '';
|
return '';
|
||||||
});
|
});
|
||||||
|
|
||||||
const showBindWechat = computed(() => Boolean(archive.value.createdByDoctor && !archive.value.hasBindWechat));
|
const chatGroupId = ref('');
|
||||||
const floatingBottom = computed(() => (showBindWechat.value ? 90 : 16));
|
const currentChatGroupId = computed(() => normalizeGroupId(chatGroupId.value || ''));
|
||||||
|
const showGoChat = computed(() => Boolean(currentChatGroupId.value));
|
||||||
|
const floatingBottom = computed(() => (showGoChat.value ? 90 : 16));
|
||||||
|
|
||||||
// const contactTitle = computed(() => (archive.value.mobile ? '联系方式' : '添加联系电话'));
|
// const contactTitle = computed(() => (archive.value.mobile ? '联系方式' : '添加联系电话'));
|
||||||
// const notesTitle = computed(() => (archive.value.notes ? '备注' : '添加备注'));
|
// const notesTitle = computed(() => (archive.value.notes ? '备注' : '添加备注'));
|
||||||
@ -575,10 +615,140 @@ const goEdit = () => {
|
|||||||
uni.navigateTo({ url: `/pages/case/archive-edit?archiveId=${encodeURIComponent(archiveId.value || '')}` });
|
uni.navigateTo({ url: `/pages/case/archive-edit?archiveId=${encodeURIComponent(archiveId.value || '')}` });
|
||||||
};
|
};
|
||||||
|
|
||||||
const bindWechat = () => {
|
const goChat = async () => {
|
||||||
uni.showToast({ title: '关联患者微信功能待接入', icon: 'none' });
|
let gid = normalizeGroupId(currentChatGroupId.value || '');
|
||||||
|
if (!gid) {
|
||||||
|
await refreshChatRoom();
|
||||||
|
gid = normalizeGroupId(currentChatGroupId.value || '');
|
||||||
|
}
|
||||||
|
if (!gid) {
|
||||||
|
toast('暂无可进入的会话');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const meta = await getChatRoomMeta(gid);
|
||||||
|
const ok = isChatRoomForArchive(meta, archiveId.value);
|
||||||
|
const currentTeamId = getCurrentTeamId();
|
||||||
|
const metaTeamId = String(meta?.teamId || meta?.team?.teamId || meta?.team?._id || '');
|
||||||
|
if (!ok || (currentTeamId && metaTeamId && metaTeamId !== currentTeamId)) {
|
||||||
|
chatGroupId.value = '';
|
||||||
|
archive.value.chatGroupId = '';
|
||||||
|
saveToStorage();
|
||||||
|
await refreshChatRoom();
|
||||||
|
gid = normalizeGroupId(currentChatGroupId.value || '');
|
||||||
|
}
|
||||||
|
if (!gid) {
|
||||||
|
toast('暂无可进入的会话');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const conversationID = `GROUP${gid}`;
|
||||||
|
uni.navigateTo({
|
||||||
|
url: `/pages/message/index?conversationID=${encodeURIComponent(conversationID)}&groupID=${encodeURIComponent(gid)}&fromCase=true`,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isRefreshingChatRoom = ref(false);
|
||||||
|
let lastRefreshChatRoomAt = 0;
|
||||||
|
|
||||||
|
function isChatRoomForArchive(meta, customerId) {
|
||||||
|
const cid = String(meta?.customerId || '');
|
||||||
|
const pid = String(meta?.patientId || '');
|
||||||
|
const id = String(customerId || '');
|
||||||
|
if (!meta || !id) return false;
|
||||||
|
return (cid && cid === id) || (pid && pid === id);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getChatRoomMeta(groupId) {
|
||||||
|
const gid = normalizeGroupId(groupId || '');
|
||||||
|
if (!gid) return null;
|
||||||
|
try {
|
||||||
|
const res = await api('getGroupListByGroupId', { groupId: gid }, false);
|
||||||
|
if (!res?.success || !res?.data) return null;
|
||||||
|
return res.data;
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseAnyTimeMs(v) {
|
||||||
|
if (v === null || v === undefined) return 0;
|
||||||
|
if (typeof v === 'number') return v;
|
||||||
|
const s = String(v).trim();
|
||||||
|
if (!s) return 0;
|
||||||
|
if (/^\d{10,13}$/.test(s)) return Number(s.length === 10 ? `${s}000` : s);
|
||||||
|
const d = dayjs(s);
|
||||||
|
return d.isValid() ? d.valueOf() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshChatRoom() {
|
||||||
|
const customerId = String(archiveId.value || '');
|
||||||
|
if (!customerId) return;
|
||||||
|
if (isRefreshingChatRoom.value) return;
|
||||||
|
const now = Date.now();
|
||||||
|
if (now - lastRefreshChatRoomAt < 5000) return;
|
||||||
|
lastRefreshChatRoomAt = now;
|
||||||
|
|
||||||
|
isRefreshingChatRoom.value = true;
|
||||||
|
try {
|
||||||
|
const corpId = getCorpId();
|
||||||
|
const teamId = getCurrentTeamId();
|
||||||
|
|
||||||
|
const baseQuery = {
|
||||||
|
corpId,
|
||||||
|
customerId,
|
||||||
|
page: 1,
|
||||||
|
pageSize: 50,
|
||||||
|
};
|
||||||
|
|
||||||
|
const queryWithTeam = teamId ? { ...baseQuery, teamId } : baseQuery;
|
||||||
|
let detailRes = await api('getGroupList', queryWithTeam, false);
|
||||||
|
let details = Array.isArray(detailRes?.data?.list) ? detailRes.data.list : [];
|
||||||
|
|
||||||
|
if (!details.length && teamId) {
|
||||||
|
detailRes = await api('getGroupList', baseQuery, false);
|
||||||
|
details = Array.isArray(detailRes?.data?.list) ? detailRes.data.list : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!detailRes?.success || !details.length) {
|
||||||
|
chatGroupId.value = '';
|
||||||
|
archive.value.chatGroupId = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentTeamId = getCurrentTeamId();
|
||||||
|
const detailsForCurrentTeam = currentTeamId
|
||||||
|
? details.filter((g) => String(g?.teamId || g?.team?._id || g?.team?.teamId || '') === currentTeamId)
|
||||||
|
: [];
|
||||||
|
const candidates = detailsForCurrentTeam.length ? detailsForCurrentTeam : details;
|
||||||
|
|
||||||
|
const statusRank = (s) => (s === 'processing' ? 3 : s === 'pending' ? 2 : 1);
|
||||||
|
candidates.sort((a, b) => {
|
||||||
|
const ra = statusRank(String(a?.orderStatus || ''));
|
||||||
|
const rb = statusRank(String(b?.orderStatus || ''));
|
||||||
|
if (rb !== ra) return rb - ra;
|
||||||
|
const ta = parseAnyTimeMs(a?.updatedAt) || parseAnyTimeMs(a?.createdAt);
|
||||||
|
const tb = parseAnyTimeMs(b?.updatedAt) || parseAnyTimeMs(b?.createdAt);
|
||||||
|
return tb - ta;
|
||||||
|
});
|
||||||
|
|
||||||
|
const best = candidates[0] || {};
|
||||||
|
const gid = normalizeGroupId(best.groupId || best.groupID || best.group_id || '');
|
||||||
|
if (gid) {
|
||||||
|
chatGroupId.value = String(gid);
|
||||||
|
archive.value.chatGroupId = chatGroupId.value;
|
||||||
|
saveToStorage();
|
||||||
|
} else {
|
||||||
|
chatGroupId.value = '';
|
||||||
|
archive.value.chatGroupId = '';
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
} finally {
|
||||||
|
isRefreshingChatRoom.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const makeCall = () => {
|
const makeCall = () => {
|
||||||
if (archive.value.mobile) {
|
if (archive.value.mobile) {
|
||||||
uni.makePhoneCall({ phoneNumber: archive.value.mobile });
|
uni.makePhoneCall({ phoneNumber: archive.value.mobile });
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
<view class="manage-container">
|
<view class="manage-container">
|
||||||
<view class="group-list">
|
<view class="group-list">
|
||||||
<scroll-view scroll-y class="sort-scroll">
|
<scroll-view scroll-y class="sort-scroll">
|
||||||
<movable-area class="drag-area" :style="{ height: dragAreaHeight + 'px' }">
|
<movable-area :key="areaKey" class="drag-area" :style="{ height: dragAreaHeight + 'px' }">
|
||||||
<movable-view
|
<movable-view
|
||||||
v-for="(item, index) in groups"
|
v-for="(item, index) in groups"
|
||||||
:key="item._id"
|
:key="item._id"
|
||||||
@ -81,7 +81,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed } from 'vue';
|
import { ref, computed, nextTick } from 'vue';
|
||||||
import { onLoad } from '@dcloudio/uni-app';
|
import { onLoad } from '@dcloudio/uni-app';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import api from '@/utils/api';
|
import api from '@/utils/api';
|
||||||
@ -91,6 +91,8 @@ import { hideLoading, loading, toast } from '@/utils/widget';
|
|||||||
// State
|
// State
|
||||||
const groups = ref([]);
|
const groups = ref([]);
|
||||||
const originalGroups = ref([]);
|
const originalGroups = ref([]);
|
||||||
|
const areaKey = ref(0);
|
||||||
|
const loadSeq = ref(0);
|
||||||
|
|
||||||
const ITEM_HEIGHT = 74; // px,需与样式保持一致
|
const ITEM_HEIGHT = 74; // px,需与样式保持一致
|
||||||
const draggingId = ref('');
|
const draggingId = ref('');
|
||||||
@ -151,6 +153,7 @@ async function ensureDoctor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadGroups() {
|
async function loadGroups() {
|
||||||
|
const seq = (loadSeq.value += 1);
|
||||||
await ensureDoctor();
|
await ensureDoctor();
|
||||||
const corpId = getCorpId();
|
const corpId = getCorpId();
|
||||||
const teamId = getTeamId();
|
const teamId = getTeamId();
|
||||||
@ -166,9 +169,17 @@ async function loadGroups() {
|
|||||||
}
|
}
|
||||||
const list = Array.isArray(res.data) ? res.data : Array.isArray(res.data?.data) ? res.data.data : [];
|
const list = Array.isArray(res.data) ? res.data : Array.isArray(res.data?.data) ? res.data.data : [];
|
||||||
const sorted = sortGroupList(list);
|
const sorted = sortGroupList(list);
|
||||||
groups.value = sorted.map((i, idx) => ({ ...i, _y: idx * ITEM_HEIGHT }));
|
if (seq !== loadSeq.value) return;
|
||||||
originalGroups.value = sorted.map((i, idx) => ({ ...i, _y: idx * ITEM_HEIGHT }));
|
const next = sorted.map((i, idx) => ({ ...i, _y: idx * ITEM_HEIGHT }));
|
||||||
|
|
||||||
|
// movable-view 在频繁新增后偶发错位:清空再赋值,并通过 key 强制重建 movable-area
|
||||||
|
groups.value = [];
|
||||||
|
await nextTick();
|
||||||
|
if (seq !== loadSeq.value) return;
|
||||||
|
groups.value = next;
|
||||||
|
originalGroups.value = next.map((i) => ({ ...i }));
|
||||||
lastSavedOrderKey.value = getOrderKey(groups.value);
|
lastSavedOrderKey.value = getOrderKey(groups.value);
|
||||||
|
areaKey.value += 1;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast('获取分组失败');
|
toast('获取分组失败');
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@ -80,8 +80,7 @@
|
|||||||
<view class="card-row-bottom">
|
<view class="card-row-bottom">
|
||||||
<template v-if="currentTabKey === 'new'"> <!-- New Patient Tab -->
|
<template v-if="currentTabKey === 'new'"> <!-- New Patient Tab -->
|
||||||
<text class="record-text">
|
<text class="record-text">
|
||||||
{{ patient.createTime || '-' }} {{ resolveCreatorName(patient) ? resolveCreatorName(patient) +
|
{{ resolveRecentAddTime(patient) }} {{ resolveRecentAddMeta(patient) }}
|
||||||
'创建' : '-' }}
|
|
||||||
</text>
|
</text>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
@ -264,6 +263,32 @@ function resolveCreatorName(patient) {
|
|||||||
return userNameMap.value[val] || val;
|
return userNameMap.value[val] || val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveRecentAddTime(patient) {
|
||||||
|
return patient?.recentAddTime || patient?.createTime || '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveRecentAddOperatorName(patient) {
|
||||||
|
const uid = patient?.recentAddOperatorUserId || patient?.creator || '';
|
||||||
|
if (!uid) return '';
|
||||||
|
return userNameMap.value[uid] || uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveRecentAddAction(patient) {
|
||||||
|
const t = String(patient?.recentAddType || '').trim();
|
||||||
|
if (!t || t === 'create') return '创建';
|
||||||
|
if (t === 'share') return '共享';
|
||||||
|
if (t.startsWith('transfer')) return '转移';
|
||||||
|
return '创建';
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveRecentAddMeta(patient) {
|
||||||
|
const name = resolveRecentAddOperatorName(patient);
|
||||||
|
const action = resolveRecentAddAction(patient);
|
||||||
|
if (name) return `${name}${action}`;
|
||||||
|
if (action === '创建') return '患者创建';
|
||||||
|
return '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function applyVerifyStatus(status, reason) {
|
function applyVerifyStatus(status, reason) {
|
||||||
verifyStatus.value = status || '';
|
verifyStatus.value = status || '';
|
||||||
@ -382,6 +407,14 @@ function formatPatient(raw) {
|
|||||||
const createTimeStr = createTime ? createTime.format('YYYY-MM-DD HH:mm') : '';
|
const createTimeStr = createTime ? createTime.format('YYYY-MM-DD HH:mm') : '';
|
||||||
const createTimeTs = createTime ? createTime.valueOf() : 0;
|
const createTimeTs = createTime ? createTime.valueOf() : 0;
|
||||||
|
|
||||||
|
// 最近一次“新增到当前团队”的时间(后端计算:创建/转移/共享),没有则退化为 createTime
|
||||||
|
const recentAddTimeRaw = raw?.recentAddTime ?? raw?.recentAddAt ?? raw?.recentTime;
|
||||||
|
const recentAddTime = parseCreateTime(recentAddTimeRaw) || createTime;
|
||||||
|
const recentAddTimeStr = recentAddTime ? recentAddTime.format('YYYY-MM-DD HH:mm') : '';
|
||||||
|
const recentAddTimeTs = recentAddTime ? recentAddTime.valueOf() : 0;
|
||||||
|
const recentAddType = String(raw?.recentAddType || (recentAddTimeRaw ? '' : 'create') || '');
|
||||||
|
const recentAddOperatorUserId = String(raw?.recentAddOperatorUserId || raw?.recentAddOperator || raw?.creator || '');
|
||||||
|
|
||||||
// 优先使用后端返回的 tagNames(标签名称数组)
|
// 优先使用后端返回的 tagNames(标签名称数组)
|
||||||
const rawTagNames = asArray(raw?.tagNames).filter((i) => typeof i === 'string' && i.trim());
|
const rawTagNames = asArray(raw?.tagNames).filter((i) => typeof i === 'string' && i.trim());
|
||||||
// 其次使用 tags(如果是字符串数组)
|
// 其次使用 tags(如果是字符串数组)
|
||||||
@ -420,6 +453,10 @@ function formatPatient(raw) {
|
|||||||
mobile,
|
mobile,
|
||||||
createTime: createTimeStr,
|
createTime: createTimeStr,
|
||||||
createTimeTs,
|
createTimeTs,
|
||||||
|
recentAddTime: recentAddTimeStr,
|
||||||
|
recentAddTimeTs,
|
||||||
|
recentAddType,
|
||||||
|
recentAddOperatorUserId,
|
||||||
creator: raw?.creatorName || raw?.creator || '',
|
creator: raw?.creatorName || raw?.creator || '',
|
||||||
hospitalId: raw?.customerNumber || raw?.hospitalId || '',
|
hospitalId: raw?.customerNumber || raw?.hospitalId || '',
|
||||||
record,
|
record,
|
||||||
@ -510,8 +547,10 @@ async function reload(reset = true) {
|
|||||||
} else if (currentTab.value.kind === 'new') {
|
} else if (currentTab.value.kind === 'new') {
|
||||||
const start = dayjs().subtract(7, 'day').startOf('day').valueOf();
|
const start = dayjs().subtract(7, 'day').startOf('day').valueOf();
|
||||||
const end = dayjs().endOf('day').valueOf();
|
const end = dayjs().endOf('day').valueOf();
|
||||||
query.startCreateTime = start;
|
// “新患者”= 最近7天新增到当前团队:创建 + 转移/共享(时间来自服务记录)
|
||||||
query.endCreateTime = end;
|
query.startRecentTime = start;
|
||||||
|
query.endRecentTime = end;
|
||||||
|
query.includeRecentAddTime = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
@ -578,9 +617,13 @@ const patientList = computed(() => {
|
|||||||
if (currentTab.value.kind === 'new') {
|
if (currentTab.value.kind === 'new') {
|
||||||
const sevenDaysAgo = dayjs().subtract(7, 'day').startOf('day').valueOf();
|
const sevenDaysAgo = dayjs().subtract(7, 'day').startOf('day').valueOf();
|
||||||
const flatList = all
|
const flatList = all
|
||||||
.filter((p) => Number(p?.createTimeTs || 0) >= sevenDaysAgo)
|
.filter((p) => Number(p?.recentAddTimeTs || p?.createTimeTs || 0) >= sevenDaysAgo)
|
||||||
.slice()
|
.slice()
|
||||||
.sort((a, b) => Number(b?.createTimeTs || 0) - Number(a?.createTimeTs || 0));
|
.sort(
|
||||||
|
(a, b) =>
|
||||||
|
Number(b?.recentAddTimeTs || b?.createTimeTs || 0) -
|
||||||
|
Number(a?.recentAddTimeTs || a?.createTimeTs || 0)
|
||||||
|
);
|
||||||
return [{ letter: '最近7天新增', data: flatList }];
|
return [{ letter: '最近7天新增', data: flatList }];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,6 +639,7 @@ const indexList = computed(() => {
|
|||||||
const totalPatients = computed(() => {
|
const totalPatients = computed(() => {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
patientList.value.forEach(g => count += g.data.length);
|
patientList.value.forEach(g => count += g.data.length);
|
||||||
|
if (currentTab.value.kind === 'new') return count;
|
||||||
return totalFromApi.value || count;
|
return totalFromApi.value || count;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -636,7 +636,7 @@ const handleClickConversation = (conversation) => {
|
|||||||
|
|
||||||
// 跳转到聊天页面
|
// 跳转到聊天页面
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages/message/index?conversationID=${conversation.conversationID}&groupID=${conversation.groupID}`,
|
url: `/pages/message/index?conversationID=${encodeURIComponent(conversation.conversationID)}&groupID=${encodeURIComponent(conversation.groupID)}`,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -863,4 +863,4 @@ onHide(() => {
|
|||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -367,23 +367,35 @@ function getBubbleClass(message) {
|
|||||||
return message.flow === "out" ? "user-bubble" : "doctor-bubble";
|
return message.flow === "out" ? "user-bubble" : "doctor-bubble";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 页面加载
|
// 页面加载
|
||||||
onLoad((options) => {
|
onLoad((options) => {
|
||||||
groupId.value = options.groupID || "";
|
const decodeQueryValue = (v) => {
|
||||||
messageList.value = [];
|
const s = typeof v === "string" ? v : String(v || "");
|
||||||
isLoading.value = false;
|
if (!s) return "";
|
||||||
if (options.conversationID) {
|
try {
|
||||||
chatInfo.value.conversationID = options.conversationID;
|
return decodeURIComponent(s);
|
||||||
timChatManager.setConversationID(options.conversationID);
|
} catch (e) {
|
||||||
console.log("设置当前会话ID:", options.conversationID);
|
return s;
|
||||||
}
|
}
|
||||||
if (options.userID) {
|
};
|
||||||
chatInfo.value.userID = options.userID;
|
|
||||||
}
|
const rawGroupId = decodeQueryValue(options.groupID || "");
|
||||||
|
groupId.value = rawGroupId.startsWith("GROUP") ? rawGroupId.replace(/^GROUP/, "") : rawGroupId;
|
||||||
checkLoginAndInitTIM();
|
messageList.value = [];
|
||||||
updateNavigationTitle();
|
isLoading.value = false;
|
||||||
});
|
if (options.conversationID) {
|
||||||
|
const cid = decodeQueryValue(options.conversationID);
|
||||||
|
chatInfo.value.conversationID = cid;
|
||||||
|
timChatManager.setConversationID(cid);
|
||||||
|
console.log("设置当前会话ID:", cid);
|
||||||
|
}
|
||||||
|
if (options.userID) {
|
||||||
|
chatInfo.value.userID = decodeQueryValue(options.userID);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkLoginAndInitTIM();
|
||||||
|
updateNavigationTitle();
|
||||||
|
});
|
||||||
|
|
||||||
// 检查登录状态并初始化IM
|
// 检查登录状态并初始化IM
|
||||||
const checkLoginAndInitTIM = async () => {
|
const checkLoginAndInitTIM = async () => {
|
||||||
|
|||||||
796
pages/message/message.vue
Normal file
796
pages/message/message.vue
Normal file
@ -0,0 +1,796 @@
|
|||||||
|
<template>
|
||||||
|
<view class="message-page">
|
||||||
|
<!-- 头部组件 -->
|
||||||
|
<message-header
|
||||||
|
v-model:activeTab="activeTab"
|
||||||
|
@team-change="handleTeamChange"
|
||||||
|
@add-patient="handleAddPatient"
|
||||||
|
/>
|
||||||
|
<!-- 消息列表 -->
|
||||||
|
<scroll-view
|
||||||
|
class="message-list"
|
||||||
|
scroll-y="true"
|
||||||
|
refresher-enabled
|
||||||
|
:refresher-triggered="refreshing"
|
||||||
|
@refresherrefresh="handleRefresh"
|
||||||
|
@scrolltolower="handleLoadMore"
|
||||||
|
>
|
||||||
|
<!-- 消息列表项 -->
|
||||||
|
<view
|
||||||
|
v-for="conversation in filteredConversationList"
|
||||||
|
:key="conversation.groupID || conversation.conversationID"
|
||||||
|
class="message-item"
|
||||||
|
@click="handleClickConversation(conversation)"
|
||||||
|
>
|
||||||
|
<view class="avatar-container">
|
||||||
|
<image
|
||||||
|
class="avatar"
|
||||||
|
:src="conversation.avatar || '/static/default-patient-avatar.png'"
|
||||||
|
mode="aspectFill"
|
||||||
|
/>
|
||||||
|
<view v-if="conversation.unreadCount > 0" class="unread-badge">
|
||||||
|
<text class="unread-text">{{
|
||||||
|
conversation.unreadCount > 99 ? "99+" : conversation.unreadCount
|
||||||
|
}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="content">
|
||||||
|
<view class="header">
|
||||||
|
<view class="name-info">
|
||||||
|
<text class="name">{{ formatPatientName(conversation) }}</text>
|
||||||
|
<text
|
||||||
|
v-if="conversation.patientSex || conversation.patientAge"
|
||||||
|
class="patient-info"
|
||||||
|
>
|
||||||
|
{{ formatPatientInfo(conversation) }}
|
||||||
|
</text>
|
||||||
|
</view>
|
||||||
|
<text class="time">{{
|
||||||
|
formatMessageTime(conversation.lastMessageTime)
|
||||||
|
}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="message-preview">
|
||||||
|
<text class="preview-text">{{
|
||||||
|
conversation.lastMessage || "暂无消息"
|
||||||
|
}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 空状态 -->
|
||||||
|
<view
|
||||||
|
v-if="!loading && conversationList.length === 0"
|
||||||
|
class="empty-container"
|
||||||
|
>
|
||||||
|
<image class="empty-image" src="/static/empty.svg" mode="aspectFit" />
|
||||||
|
<text class="empty-text">医生信息未获取,请稍后重试</text>
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
v-else-if="
|
||||||
|
!loading &&
|
||||||
|
filteredConversationList.length === 0
|
||||||
|
"
|
||||||
|
class="empty-container"
|
||||||
|
>
|
||||||
|
<image class="empty-image" src="/static/empty.svg" mode="aspectFit" />
|
||||||
|
<text class="empty-text">{{
|
||||||
|
activeTab === "processing" ? "暂无处理中的会话" : "暂无已结束的会话"
|
||||||
|
}}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 加载更多 -->
|
||||||
|
<view
|
||||||
|
v-if="hasMore && filteredConversationList.length > 0"
|
||||||
|
class="load-more"
|
||||||
|
>
|
||||||
|
<text class="load-more-text">{{
|
||||||
|
loadingMore ? "加载中..." : "上拉加载更多"
|
||||||
|
}}</text>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, computed } from "vue";
|
||||||
|
import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
|
||||||
|
import { storeToRefs } from "pinia";
|
||||||
|
import useAccountStore from "@/store/account.js";
|
||||||
|
import useTeamStore from "@/store/team.js";
|
||||||
|
import useInfoCheck from "@/hooks/useInfoCheck.js";
|
||||||
|
import { globalTimChatManager } from "@/utils/tim-chat.js";
|
||||||
|
import { mergeConversationWithGroupDetails } from "@/utils/conversation-merger.js";
|
||||||
|
import MessageHeader from "../home/components/message-header.vue";
|
||||||
|
|
||||||
|
// 获取登录状态
|
||||||
|
const { account, openid, isIMInitialized } = storeToRefs(useAccountStore());
|
||||||
|
const { initIMAfterLogin } = useAccountStore();
|
||||||
|
|
||||||
|
// 获取团队信息
|
||||||
|
const teamStore = useTeamStore();
|
||||||
|
const { getTeams } = teamStore;
|
||||||
|
|
||||||
|
// 信息完善检查
|
||||||
|
const { withInfo } = useInfoCheck();
|
||||||
|
|
||||||
|
// 团队相关状态
|
||||||
|
const currentTeamId = ref(""); // 空字符串表示"全部会话消息"
|
||||||
|
|
||||||
|
// 状态
|
||||||
|
const conversationList = ref([]);
|
||||||
|
const loading = ref(false);
|
||||||
|
const loadingMore = ref(false);
|
||||||
|
const hasMore = ref(false);
|
||||||
|
const refreshing = ref(false);
|
||||||
|
const activeTab = ref("processing");
|
||||||
|
|
||||||
|
// 根据 orderStatus 过滤会话列表
|
||||||
|
const filteredConversationList = computed(() => {
|
||||||
|
let filtered = [];
|
||||||
|
|
||||||
|
if (activeTab.value === "processing") {
|
||||||
|
// 处理中:pending(待处理) 和 processing(处理中)
|
||||||
|
filtered = conversationList.value.filter(
|
||||||
|
(conv) =>
|
||||||
|
conv.orderStatus === "pending" || conv.orderStatus === "processing"
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// 已结束:cancelled(已取消)、completed(已完成)、finished(已结束)
|
||||||
|
filtered = conversationList.value.filter(
|
||||||
|
(conv) =>
|
||||||
|
conv.orderStatus === "cancelled" ||
|
||||||
|
conv.orderStatus === "completed" ||
|
||||||
|
conv.orderStatus === "finished"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果选择了团队,进一步过滤
|
||||||
|
if (currentTeamId.value) {
|
||||||
|
filtered = filtered.filter((conv) => conv.teamId === currentTeamId.value);
|
||||||
|
}
|
||||||
|
return filtered;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 处理团队切换
|
||||||
|
const handleTeamChange = (teamId) => {
|
||||||
|
currentTeamId.value = teamId;
|
||||||
|
console.log("切换到团队ID:", teamId);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 邀请患者 - 使用 withInfo 包装,确保信息完善后才能使用
|
||||||
|
const handleAddPatient = withInfo(() => {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: "/pages/work/team/invite/invite-patient",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 初始化IM
|
||||||
|
const initIM = async () => {
|
||||||
|
if (!isIMInitialized.value) {
|
||||||
|
uni.showLoading({
|
||||||
|
title: "连接中...",
|
||||||
|
});
|
||||||
|
const success = await initIMAfterLogin();
|
||||||
|
uni.hideLoading();
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
// 显示重试提示
|
||||||
|
uni.showModal({
|
||||||
|
title: "IM连接失败",
|
||||||
|
content:
|
||||||
|
"连接失败,请检查网络后重试。如果IM连接失败,请重新登陆IM再连接",
|
||||||
|
confirmText: "重新登陆",
|
||||||
|
cancelText: "取消",
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
// 重新登陆
|
||||||
|
handleReloginIM();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (globalTimChatManager && !globalTimChatManager.isLoggedIn) {
|
||||||
|
uni.showLoading({
|
||||||
|
title: "重连中...",
|
||||||
|
});
|
||||||
|
const reconnected = await globalTimChatManager.ensureIMConnection();
|
||||||
|
uni.hideLoading();
|
||||||
|
|
||||||
|
if (!reconnected) {
|
||||||
|
// 显示重试提示
|
||||||
|
uni.showModal({
|
||||||
|
title: "IM连接失败",
|
||||||
|
content:
|
||||||
|
"连接失败,请检查网络后重试。如果IM连接失败,请重新登陆IM再连接",
|
||||||
|
confirmText: "重新登陆",
|
||||||
|
cancelText: "取消",
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
// 重新登陆
|
||||||
|
handleReloginIM();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 重新登陆IM
|
||||||
|
const handleReloginIM = async () => {
|
||||||
|
try {
|
||||||
|
uni.showLoading({
|
||||||
|
title: "重新登陆中...",
|
||||||
|
});
|
||||||
|
|
||||||
|
// 清理旧的IM实例
|
||||||
|
if (globalTimChatManager) {
|
||||||
|
await globalTimChatManager.cleanupOldInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重新初始化IM
|
||||||
|
const { initIMAfterLogin } = useAccountStore();
|
||||||
|
const success = await initIMAfterLogin();
|
||||||
|
uni.hideLoading();
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
uni.showToast({
|
||||||
|
title: "IM连接成功",
|
||||||
|
icon: "success",
|
||||||
|
});
|
||||||
|
// 重新加载会话列表
|
||||||
|
await loadConversationList();
|
||||||
|
setupConversationListener();
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
title: "IM连接失败,请检查网络",
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
uni.hideLoading();
|
||||||
|
console.error("重新登陆IM失败:", error);
|
||||||
|
uni.showToast({
|
||||||
|
title: "重新登陆失败",
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 加载会话列表
|
||||||
|
const loadConversationList = async () => {
|
||||||
|
if (loading.value) return;
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
console.log("开始加载群聊列表");
|
||||||
|
|
||||||
|
// 确保 IM 已连接
|
||||||
|
if (!globalTimChatManager) {
|
||||||
|
throw new Error("IM管理器未初始化");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查 TIM 实例是否存在
|
||||||
|
if (!globalTimChatManager.tim) {
|
||||||
|
console.warn("TIM实例不存在,尝试重新初始化IM");
|
||||||
|
const reinitialized = await initIMAfterLogin();
|
||||||
|
if (!reinitialized) {
|
||||||
|
throw new Error("IM重新初始化失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否已登录
|
||||||
|
if (!globalTimChatManager.isLoggedIn) {
|
||||||
|
console.warn("IM未登录,尝试重新连接");
|
||||||
|
const reconnected = await globalTimChatManager.ensureIMConnection();
|
||||||
|
if (!reconnected) {
|
||||||
|
throw new Error("IM重新连接失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!globalTimChatManager.getGroupList) {
|
||||||
|
throw new Error("IM管理器方法不可用");
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await globalTimChatManager.getGroupList();
|
||||||
|
if (result && result.success && result.groupList) {
|
||||||
|
// 合并后端群组详细信息(已包含格式化和排序)
|
||||||
|
conversationList.value = await mergeConversationWithGroupDetails(
|
||||||
|
result.groupList
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("=== 会话列表加载完成 ===");
|
||||||
|
console.log("总会话数:", conversationList.value.length);
|
||||||
|
// 打印前3个会话的 orderStatus
|
||||||
|
conversationList.value.slice(0, 3).forEach((conv, index) => {
|
||||||
|
console.log(
|
||||||
|
`会话 ${index} - orderStatus: ${conv.orderStatus}, 名称: ${conv.name}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"群聊列表加载成功,共",
|
||||||
|
conversationList.value.length,
|
||||||
|
"个会话"
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.error("加载群聊列表失败:", result);
|
||||||
|
uni.showToast({
|
||||||
|
title: "加载失败,请重试",
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("加载会话列表失败:", error);
|
||||||
|
uni.showToast({
|
||||||
|
title: error.message || "加载失败,请重试",
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 防抖更新定时器
|
||||||
|
let updateTimer = null;
|
||||||
|
|
||||||
|
// 设置会话列表监听,实时更新列表
|
||||||
|
const setupConversationListener = () => {
|
||||||
|
if (!globalTimChatManager) return;
|
||||||
|
|
||||||
|
// 监听会话列表更新事件
|
||||||
|
globalTimChatManager.setCallback("onConversationListUpdated", (eventData) => {
|
||||||
|
console.log("会话列表更新事件:", eventData);
|
||||||
|
|
||||||
|
// 处理单个会话更新(标记已读的情况)
|
||||||
|
if (eventData && !Array.isArray(eventData) && eventData.conversationID) {
|
||||||
|
const conversationID = eventData.conversationID;
|
||||||
|
const existingIndex = conversationList.value.findIndex(
|
||||||
|
(conv) => conv.conversationID === conversationID
|
||||||
|
);
|
||||||
|
|
||||||
|
if (existingIndex !== -1) {
|
||||||
|
// 直接更新未读数,避免触发整个对象的响应式更新
|
||||||
|
if (eventData.unreadCount !== undefined) {
|
||||||
|
conversationList.value[existingIndex].unreadCount =
|
||||||
|
eventData.unreadCount;
|
||||||
|
console.log(
|
||||||
|
`已清空会话未读数: ${conversationList.value[existingIndex].name}, unreadCount: ${eventData.unreadCount}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!eventData || !Array.isArray(eventData)) {
|
||||||
|
console.warn("会话列表更新事件数据格式错误");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 防抖处理:避免频繁更新导致闪动
|
||||||
|
if (updateTimer) {
|
||||||
|
clearTimeout(updateTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTimer = setTimeout(async () => {
|
||||||
|
// 过滤出群聊会话
|
||||||
|
const groupConversations = eventData.filter(
|
||||||
|
(conv) => conv.conversationID && conv.conversationID.startsWith("GROUP")
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(`收到 ${groupConversations.length} 个群聊会话更新`);
|
||||||
|
|
||||||
|
// 使用 TimChatManager 的格式化方法转换为标准格式
|
||||||
|
const formattedConversations = groupConversations.map((conv) =>
|
||||||
|
globalTimChatManager.formatConversationData(conv)
|
||||||
|
);
|
||||||
|
|
||||||
|
// 合并后端群组详细信息(已包含格式化和排序)
|
||||||
|
const mergedConversations = await mergeConversationWithGroupDetails(
|
||||||
|
formattedConversations
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!mergedConversations || mergedConversations.length === 0) {
|
||||||
|
console.log("合并后的会话数据为空,跳过更新");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let needSort = false;
|
||||||
|
// 更新会话列表
|
||||||
|
mergedConversations.forEach((conversationData) => {
|
||||||
|
const conversationID = conversationData.conversationID;
|
||||||
|
const existingIndex = conversationList.value.findIndex(
|
||||||
|
(conv) => conv.conversationID === conversationID
|
||||||
|
);
|
||||||
|
|
||||||
|
if (existingIndex !== -1) {
|
||||||
|
const existing = conversationList.value[existingIndex];
|
||||||
|
if (
|
||||||
|
existing.lastMessage !== conversationData.lastMessage ||
|
||||||
|
existing.lastMessageTime !== conversationData.lastMessageTime ||
|
||||||
|
existing.unreadCount !== conversationData.unreadCount ||
|
||||||
|
existing.patientName !== conversationData.patientName ||
|
||||||
|
existing.patientSex !== conversationData.patientSex ||
|
||||||
|
existing.patientAge !== conversationData.patientAge
|
||||||
|
) {
|
||||||
|
// 只更新变化的字段,保持头像和未读数稳定
|
||||||
|
conversationList.value[existingIndex] = {
|
||||||
|
...conversationData,
|
||||||
|
// 保持原有头像,避免闪动
|
||||||
|
avatar: existing.avatar || conversationData.avatar,
|
||||||
|
// 保留较大的未读数(避免被后端数据覆盖)
|
||||||
|
unreadCount: Math.max(
|
||||||
|
existing.unreadCount || 0,
|
||||||
|
conversationData.unreadCount || 0
|
||||||
|
),
|
||||||
|
};
|
||||||
|
needSort = true;
|
||||||
|
console.log(
|
||||||
|
`已更新会话: ${conversationData.name}, unreadCount: ${conversationList.value[existingIndex].unreadCount}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 添加新会话
|
||||||
|
conversationList.value.push(conversationData);
|
||||||
|
needSort = true;
|
||||||
|
console.log(`已添加新会话: ${conversationData.name}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 只在需要时才排序
|
||||||
|
if (needSort) {
|
||||||
|
conversationList.value.sort(
|
||||||
|
(a, b) => b.lastMessageTime - a.lastMessageTime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, 100); // 100ms 防抖延迟
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听消息接收事件(用于更新未读数)
|
||||||
|
globalTimChatManager.setCallback("onMessageReceived", (message) => {
|
||||||
|
console.log("消息列表页面收到新消息:", message);
|
||||||
|
|
||||||
|
// 找到对应的会话
|
||||||
|
const conversationID = message.conversationID;
|
||||||
|
const conversationIndex = conversationList.value.findIndex(
|
||||||
|
(conv) => conv.conversationID === conversationID
|
||||||
|
);
|
||||||
|
|
||||||
|
if (conversationIndex !== -1) {
|
||||||
|
const conversation = conversationList.value[conversationIndex];
|
||||||
|
|
||||||
|
// 检查当前页面栈,判断用户是否正在查看该会话的聊天详情页
|
||||||
|
const pages = getCurrentPages();
|
||||||
|
const currentPage = pages[pages.length - 1];
|
||||||
|
|
||||||
|
// 获取当前页面的 groupID 参数(如果在聊天详情页)
|
||||||
|
const currentGroupID = currentPage?.options?.groupID;
|
||||||
|
const isViewingThisConversation =
|
||||||
|
currentPage?.route === "pages/message/index" &&
|
||||||
|
currentGroupID === conversation.groupID;
|
||||||
|
|
||||||
|
// 如果用户正在查看这个具体的会话,不增加未读数
|
||||||
|
if (isViewingThisConversation) {
|
||||||
|
console.log("用户正在查看该会话,不增加未读数");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 只在用户不在该会话的聊天页面时才增加未读数
|
||||||
|
conversation.unreadCount = (conversation.unreadCount || 0) + 1;
|
||||||
|
console.log(
|
||||||
|
"已更新会话未读数:",
|
||||||
|
conversation.name,
|
||||||
|
"unreadCount:",
|
||||||
|
conversation.unreadCount
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化患者姓名
|
||||||
|
const formatPatientName = (conversation) => {
|
||||||
|
return conversation.patientName || "未知患者";
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化患者信息(性别 + 年龄)
|
||||||
|
const formatPatientInfo = (conversation) => {
|
||||||
|
const parts = [];
|
||||||
|
|
||||||
|
// 性别
|
||||||
|
if (conversation.patientSex === "男") {
|
||||||
|
parts.push("男");
|
||||||
|
} else if (conversation.patientSex === "女") {
|
||||||
|
parts.push("女");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 年龄
|
||||||
|
if (conversation.patientAge) {
|
||||||
|
parts.push(`${conversation.patientAge}岁`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts.join(" ");
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化消息时间
|
||||||
|
const formatMessageTime = (timestamp) => {
|
||||||
|
if (!timestamp) return "";
|
||||||
|
|
||||||
|
const now = Date.now();
|
||||||
|
const diff = now - timestamp;
|
||||||
|
const date = new Date(timestamp);
|
||||||
|
|
||||||
|
// 1分钟内
|
||||||
|
if (diff < 60 * 1000) {
|
||||||
|
return "刚刚";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1小时内
|
||||||
|
if (diff < 60 * 60 * 1000) {
|
||||||
|
return `${Math.floor(diff / (60 * 1000))}分钟前`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 今天
|
||||||
|
const today = new Date();
|
||||||
|
if (date.toDateString() === today.toDateString()) {
|
||||||
|
return `${String(date.getHours()).padStart(2, "0")}:${String(
|
||||||
|
date.getMinutes()
|
||||||
|
).padStart(2, "0")}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 昨天
|
||||||
|
const yesterday = new Date(today);
|
||||||
|
yesterday.setDate(yesterday.getDate() - 1);
|
||||||
|
if (date.toDateString() === yesterday.toDateString()) {
|
||||||
|
return "昨天";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 今年
|
||||||
|
if (date.getFullYear() === today.getFullYear()) {
|
||||||
|
return `${date.getMonth() + 1}月${date.getDate()}日`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 其他
|
||||||
|
return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 点击会话
|
||||||
|
const handleClickConversation = (conversation) => {
|
||||||
|
console.log("点击会话:", conversation);
|
||||||
|
|
||||||
|
// 立即清空本地未读数(优化用户体验)
|
||||||
|
const conversationIndex = conversationList.value.findIndex(
|
||||||
|
(conv) => conv.conversationID === conversation.conversationID
|
||||||
|
);
|
||||||
|
if (conversationIndex !== -1) {
|
||||||
|
conversationList.value[conversationIndex].unreadCount = 0;
|
||||||
|
console.log("已清空本地未读数:", conversation.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 跳转到聊天页面
|
||||||
|
uni.navigateTo({
|
||||||
|
url: `/pages/message/index?conversationID=${encodeURIComponent(conversation.conversationID)}&groupID=${encodeURIComponent(conversation.groupID)}`,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 加载更多
|
||||||
|
const handleLoadMore = () => {
|
||||||
|
if (loadingMore.value || !hasMore.value) return;
|
||||||
|
|
||||||
|
loadingMore.value = true;
|
||||||
|
// TODO: 实现分页加载
|
||||||
|
setTimeout(() => {
|
||||||
|
loadingMore.value = false;
|
||||||
|
}, 1000);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 下拉刷新
|
||||||
|
const handleRefresh = async () => {
|
||||||
|
refreshing.value = true;
|
||||||
|
try {
|
||||||
|
await loadConversationList();
|
||||||
|
} finally {
|
||||||
|
refreshing.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 页面加载
|
||||||
|
onLoad(() => {
|
||||||
|
console.log("消息列表页面加载");
|
||||||
|
});
|
||||||
|
|
||||||
|
// 页面显示
|
||||||
|
onShow(async () => {
|
||||||
|
try {
|
||||||
|
// 加载团队列表
|
||||||
|
await getTeams();
|
||||||
|
|
||||||
|
// 初始化IM
|
||||||
|
const imReady = await initIM();
|
||||||
|
if (!imReady) {
|
||||||
|
console.error("IM初始化失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载会话列表
|
||||||
|
await loadConversationList();
|
||||||
|
|
||||||
|
// 设置监听器,后续通过事件更新列表
|
||||||
|
setupConversationListener();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("页面初始化失败:", error);
|
||||||
|
uni.showToast({
|
||||||
|
title: "初始化失败,请重试",
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 页面隐藏
|
||||||
|
onHide(() => {
|
||||||
|
// 清除防抖定时器
|
||||||
|
if (updateTimer) {
|
||||||
|
clearTimeout(updateTimer);
|
||||||
|
updateTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移除消息监听
|
||||||
|
if (globalTimChatManager) {
|
||||||
|
globalTimChatManager.setCallback("onConversationListUpdated", null);
|
||||||
|
globalTimChatManager.setCallback("onMessageReceived", null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.message-page {
|
||||||
|
width: 100%;
|
||||||
|
height: 100vh;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-list {
|
||||||
|
width: 100%;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-container,
|
||||||
|
.empty-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 100rpx 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-text {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-image {
|
||||||
|
width: 200rpx;
|
||||||
|
height: 200rpx;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-text {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 24rpx 32rpx;
|
||||||
|
background-color: #fff;
|
||||||
|
border-bottom: 1rpx solid #f0f0f0;
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar-container {
|
||||||
|
position: relative;
|
||||||
|
margin-right: 24rpx;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar {
|
||||||
|
width: 96rpx;
|
||||||
|
height: 96rpx;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.unread-badge {
|
||||||
|
position: absolute;
|
||||||
|
top: -8rpx;
|
||||||
|
right: -8rpx;
|
||||||
|
min-width: 32rpx;
|
||||||
|
height: 32rpx;
|
||||||
|
padding: 0 8rpx;
|
||||||
|
background-color: #ff4d4f;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.unread-text {
|
||||||
|
font-size: 20rpx;
|
||||||
|
color: #fff;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name-info {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name {
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #333;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
flex-shrink: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.patient-info {
|
||||||
|
font-size: 26rpx;
|
||||||
|
padding-left: 12rpx;
|
||||||
|
color: #999;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #999;
|
||||||
|
margin-left: 16rpx;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-preview {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-text {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #999;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.load-more {
|
||||||
|
padding: 20rpx 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.load-more-text {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Loading…
x
Reference in New Issue
Block a user