diff --git a/pages/message/hooks/use-group-chat.js b/pages/message/hooks/use-group-chat.js index e550907..73d7a8e 100644 --- a/pages/message/hooks/use-group-chat.js +++ b/pages/message/hooks/use-group-chat.js @@ -1,5 +1,7 @@ import { ref, computed } from 'vue' import { onShow, onUnload } from '@dcloudio/uni-app' +import api from '@/utils/api.js' +import useTeamStore from '@/store/team.js' /** * 简单的群聊hook @@ -8,6 +10,9 @@ import { onShow, onUnload } from '@dcloudio/uni-app' export default function useGroupChat(groupID) { const groupInfo = ref({}) const members = ref([]) + const teamMemberIds = ref([]) // 存储团队成员的userId列表 + const patientId = ref('') // 存储患者ID + const teamStore = useTeamStore() // 群聊成员映射 const chatMember = computed(() => { @@ -15,30 +20,79 @@ export default function useGroupChat(groupID) { members.value.forEach(member => { res[member.id] = { name: member.name, - avatar: member.avatar || '/static/default-avatar.png' + avatar: member.avatar, + isTeamMember: member.isTeamMember // 标记是否为团队成员 } }) return res }) - // 获取群聊信息 + // 判断某个userId是否为团队成员 + const isTeamMember = (userId) => { + return teamMemberIds.value.includes(userId) + } + + // 获取用户头像(根据是否为团队成员返回不同的默认头像) + const getUserAvatar = (userId) => { + const member = chatMember.value[userId] + if (!member) { + // 如果找不到成员信息,根据是否为团队成员返回默认头像 + return isTeamMember(userId) ? '/static/home/avatar.svg' : '/static/default-patient-avatar.png' + } + + // 如果有头像且不为空字符串,返回头像 + if (member.avatar && member.avatar.trim() !== '') { + return member.avatar + } + + // 否则根据是否为团队成员返回默认头像 + return member.isTeamMember ? '/static/home/avatar.svg' : '/static/default-patient-avatar.png' + } + + // 获取群聊信息和成员头像 async function getGroupInfo() { const gid = typeof groupID === 'string' ? groupID : groupID.value if (!gid) return try { - // 这里可以调用API获取群聊信息 - // const res = await getGroupDetail(gid) - // if (res && res.success) { - // groupInfo.value = res.data - // members.value = res.data.members || [] - // } + // 1. 获取群聊基本信息 + const groupResult = await api('getGroupListByGroupId', { groupId: gid }) - // 暂时使用本地数据 - groupInfo.value = { - groupID: gid, - name: '群聊', - status: 'active' + if (groupResult && groupResult.success && groupResult.data) { + groupInfo.value = { + groupID: gid, + name: groupResult.data.team?.name || '群聊', + status: groupResult.data.orderStatus || 'active', + teamId: groupResult.data.teamId + } + + // 2. 如果有teamId,获取团队成员头像 + if (groupResult.data.teamId) { + const avatarMap = await teamStore.getTeamMemberAvatars(groupResult.data.teamId) + + // 3. 存储团队成员ID列表 + teamMemberIds.value = Object.keys(avatarMap) + + // 4. 构建团队成员列表 + members.value = teamMemberIds.value.map(userId => ({ + id: userId, + name: userId, // 这里可以从其他地方获取真实姓名 + avatar: avatarMap[userId] || '', + isTeamMember: true + })) + + // 5. 添加患者信息(使用默认患者头像) + if (groupResult.data.patient) { + const pid = groupResult.data.patientId?.toString() || '' + patientId.value = pid + members.value.push({ + id: pid, + name: groupResult.data.patient.name || '患者', + avatar: '', // 患者不设置头像,使用默认 + isTeamMember: false + }) + } + } } } catch (error) { console.error('获取群聊信息失败:', error) @@ -57,6 +111,8 @@ export default function useGroupChat(groupID) { groupInfo, members, chatMember, - getGroupInfo + getGroupInfo, + isTeamMember, + getUserAvatar } } diff --git a/pages/message/index.vue b/pages/message/index.vue index f817983..a2d1c8f 100644 --- a/pages/message/index.vue +++ b/pages/message/index.vue @@ -65,23 +65,16 @@ - - - @@ -222,7 +215,7 @@ const { initIMAfterLogin } = useAccountStore(); const chatInputRef = ref(null); const groupId = ref(""); -const { chatMember, getGroupInfo } = useGroupChat(groupId); +const { chatMember, getGroupInfo, getUserAvatar } = useGroupChat(groupId); // 动态设置导航栏标题 const updateNavigationTitle = (title = "群聊") => { diff --git a/pages/work/profile.vue b/pages/work/profile.vue index 06bd33a..3124fa1 100644 --- a/pages/work/profile.vue +++ b/pages/work/profile.vue @@ -2,23 +2,59 @@ - + - - - + + + - - + + - - + + {{ jobStr }} @@ -39,12 +75,24 @@ - + @@ -58,46 +106,56 @@ import api from "@/utils/api.js"; import { upload } from "@/utils/http.js"; import { toast } from "@/utils/widget"; -import buttonFooter from '@/components/button-footer.vue'; +import buttonFooter from "@/components/button-footer.vue"; import commonCell from "@/components/form-template/common-cell.vue"; import FormInput from "@/components/form-template/form-cell/form-input.vue"; import FormSelect from "@/components/form-template/form-cell/form-select.vue"; import FormTextarea from "@/components/form-template/form-cell/form-textarea.vue"; -import fullPage from '@/components/full-page.vue'; +import fullPage from "@/components/full-page.vue"; const { account, doctorInfo } = storeToRefs(useAccountStore()); const { useLoad, useShow } = useGuard(); const { getDoctorInfo } = useAccountStore(); -const job = { assistant: '医生助理', doctor: '医生' }; +const job = { assistant: "医生助理", doctor: "医生" }; const form = ref({}); -const inviteTeamId = ref('') -const type = ref(''); +const inviteTeamId = ref(""); +const type = ref(""); -const formData = computed(() => ({ ...(doctorInfo.value || {}), ...form.value, mobile: account.value?.mobile })); -const cancelText = computed(() => doctorInfo.value ? '取消' : '暂不填写'); -const confirmText = computed(() => type.value === 'cert' ? '下一步' : '保存'); +const formData = computed(() => ({ + ...(doctorInfo.value || {}), + ...form.value, + mobile: account.value?.mobile, +})); +const cancelText = computed(() => (doctorInfo.value ? "取消" : "暂不填写")); +const confirmText = computed(() => (type.value === "cert" ? "下一步" : "保存")); const jobStr = computed(() => { - const jobs = formData.value && Array.isArray(formData.value.job) ? formData.value.job.filter(i => i === 'assistant' || i === 'doctor') : []; - return jobs[0] && job[jobs[0]] ? job[jobs[0]] : ''; -}) + const jobs = + formData.value && Array.isArray(formData.value.job) + ? formData.value.job.filter((i) => i === "assistant" || i === "doctor") + : []; + return jobs[0] && job[jobs[0]] ? job[jobs[0]] : ""; +}); const rule = computed(() => { - if (doctorInfo.value && ['verified', 'verifying'].includes(doctorInfo.value.verifyStatus)) { + if ( + doctorInfo.value && + ["verified", "verifying"].includes(doctorInfo.value.verifyStatus) + ) { return { - anotherName: { name: '姓名 (不可修改)', required: false, disabled: true }, - job: { name: '岗位 (不可修改)', disabled: true }, - title: { name: '职称 (不可修改)', disabled: true }, - dept: { name: '科室 (不可修改)', disabled: true }, - } + anotherName: { name: "姓名 (不可修改)", required: false, disabled: true }, + job: { name: "岗位 (不可修改)", disabled: true }, + title: { name: "职称 (不可修改)", disabled: true }, + dept: { name: "科室 (不可修改)", disabled: true }, + }; } return { - anotherName: { name: '姓名', required: true, disabled: false }, - job: { name: '岗位', disabled: false }, - title: { name: '职称', disabled: false }, - dept: { name: '科室', disabled: false }, - } -}) + anotherName: { name: "姓名", required: true, disabled: false }, + job: { name: "岗位", disabled: false }, + title: { name: "职称", disabled: false }, + dept: { name: "科室", disabled: false }, + }; +}); // 选项数据 const genderOptions = [ @@ -139,55 +197,60 @@ function chooseAvatar() { if (url) { form.value.avatar = url; } else { - toast('上传失败') + toast("上传失败"); } - } - }) + }, + }); } function onChange({ title, value }) { - form.value[title] = value + form.value[title] = value; } function selectJob() { if (rule.value.job.disabled) return; uni.showActionSheet({ - itemList: ['医生', '医生助理', '无'], + itemList: ["医生", "医生助理", "无"], success: ({ tapIndex }) => { - const job = ['doctor', 'assistant',][tapIndex]; + const job = ["doctor", "assistant"][tapIndex]; form.value.job = job ? [job] : []; - } - }) + }, + }); } function toCert() { - if (jobStr.value === '医生') { + if (jobStr.value === "医生") { uni.navigateTo({ - url: '/pages/work/verify/doctor' - }) - } else if (jobStr.value === '医生助理') { + url: "/pages/work/verify/doctor", + }); + } else if (jobStr.value === "医生助理") { uni.navigateTo({ - url: '/pages/work/verify/assistant' - }) + url: "/pages/work/verify/assistant", + }); } else { - toast('请选择岗位信息') + toast("请选择岗位信息"); } } async function save() { - if (typeof formData.value.anotherName !== 'string' || !formData.value.anotherName.trim()) { - return toast('请输入姓名') + if ( + typeof formData.value.anotherName !== "string" || + !formData.value.anotherName.trim() + ) { + return toast("请输入姓名"); } - if (type.value === 'cert' && !jobStr.value) { - return toast('请选择岗位信息') + if (type.value === "cert" && !jobStr.value) { + return toast("请选择岗位信息"); } - const apiName = doctorInfo.value ? 'updateCorpMemberFromWxapp' : 'addCorpMemberFromWxapp'; + const apiName = doctorInfo.value + ? "updateCorpMemberFromWxapp" + : "addCorpMemberFromWxapp"; const data = { ...form.value, weChatOpenId: account.value.openid, mobile: account.value.mobile, corpId: account.value.corpId, - } + }; if (doctorInfo.value) { data.id = doctorInfo.value._id; } @@ -196,30 +259,29 @@ async function save() { } const res = await api(apiName, data); if (res && res.success) { - await getDoctorInfo() + await getDoctorInfo(); form.value = {}; - if (type.value === 'cert') { - toCert() + if (type.value === "cert") { + toCert(); } else { - await toast('保存成功'); - back() + await toast("保存成功"); + back(); } } else { - await toast(res?.message || '保存失败'); + await toast(res?.message || "保存失败"); } } -useLoad(opts => { +useLoad((opts) => { type.value = opts?.type; - if (type.value === 'joinTeam' && opts.teamId) { - inviteTeamId.value = opts.teamId + if (type.value === "joinTeam" && opts.teamId) { + inviteTeamId.value = opts.teamId; } -}) - -useShow(() => { - getDoctorInfo() }); +useShow(() => { + getDoctorInfo(); +});