49 lines
1.7 KiB
Vue
Raw Normal View History

2026-09-01 15:21:46 +08:00
<template>
<text>{{ displayName }}</text>
</template>
<script setup>
import { computed, onMounted, reactive } from 'vue';
import api from '@/utils/api';
import useAccountStore from '@/store/account';
const props = defineProps({
openid: { type: String, default: '' },
fallback: { type: String, default: '' },
});
const SPECIAL_NAMES = { system: '系统', none: '咨询公共池', not: '无' };
const sharedUserNameMap = reactive({});
let sharedLoadingPromise = null;
const accountStore = useAccountStore();
const displayName = computed(() => {
const id = String(props.openid || '').trim();
if (!id) return props.fallback || '';
return SPECIAL_NAMES[id] || sharedUserNameMap[id] || props.fallback || id;
});
async function loadMembers() {
if (sharedLoadingPromise) return sharedLoadingPromise;
const team = uni.getStorageSync('ykt_case_current_team') || {};
const corpId = String(team.corpId || accountStore.doctorInfo?.corpId || accountStore.account?.corpId || '');
if (!corpId) return;
sharedLoadingPromise = api('getCorpMember', { corpId, page: 1, pageSize: 1000 }, false)
.then((res) => {
const list = res?.data?.data || res?.data?.list || res?.data || res?.list || [];
if (!Array.isArray(list)) return;
const map = {};
list.forEach((member) => {
const userid = String(member?.userid || member?.userId || member?.corpUserId || '').trim();
const name = String(member?.anotherName || member?.name || '').trim();
if (userid && name) map[userid] = name;
});
Object.assign(sharedUserNameMap, map);
})
.catch(() => {})
.finally(() => { sharedLoadingPromise = null; });
return sharedLoadingPromise;
}
onMounted(loadMembers);
</script>