fix:显示错误

This commit is contained in:
Jafeng 2026-01-27 17:38:40 +08:00
parent 2fc385f994
commit 173b3ceb2e
2 changed files with 83 additions and 9 deletions

View File

@ -45,7 +45,7 @@
</view>
<view class="body">
<view class="content" :class="{ clamp: !expandMap[i._id] }">
{{ i.taskContentDisplay || '暂无内容' }}
{{ displayTaskContent(i) || '暂无内容' }}
</view>
<image class="pen" src="/static/icons/icon-pen.svg" @click.stop="edit(i)" />
</view>
@ -152,9 +152,33 @@ function resolveUserName(userId) {
return String(map[id] || '') || id;
}
function escapeRegExp(str) {
return String(str).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
function replaceKnownUserIds(text) {
const map = userNameMap.value || {};
const ids = Object.keys(map);
if (!ids.length) return text;
let out = text;
ids.forEach((id) => {
const name = String(map[id] || '');
if (!id || !name || name === id) return;
const re = new RegExp(`(^|[^0-9A-Za-z_])(${escapeRegExp(id)})(?=[^0-9A-Za-z_]|$)`, 'g');
out = out.replace(re, (_, p1) => `${p1}${name}`);
});
return out;
}
function formatTaskContent(text) {
if (typeof text !== 'string') return '';
return text.replace(/&&&([^&]+)&&&/g, (_, id) => resolveUserName(id)).trim();
const withPlaceholders = text.replace(/&&&([^&]+)&&&/g, (_, id) => resolveUserName(id));
return replaceKnownUserIds(withPlaceholders).trim();
}
function displayTaskContent(r) {
return formatTaskContent(String(r?.taskContent || ''));
}
async function loadTeamMembers(teamId) {
@ -196,7 +220,6 @@ function mapRow(i) {
fileType,
timeStr: i.executionTime ? dayjs(i.executionTime).format('YYYY-MM-DD HH:mm') : '--',
typeStr: getServiceTypeLabel(i.eventType),
taskContentDisplay: formatTaskContent(String(i?.taskContent || '')),
};
}

View File

@ -217,9 +217,10 @@
</template>
<script setup>
import { computed, getCurrentInstance, ref } from 'vue';
import { computed, getCurrentInstance, nextTick, ref } from 'vue';
import { onLoad, onPullDownRefresh, onReachBottom, onReady, onShow } from '@dcloudio/uni-app';
import { storeToRefs } from 'pinia';
import dayjs from 'dayjs';
import HealthProfileTab from '@/components/archive-detail/health-profile-tab.vue';
import ServiceInfoTab from '@/components/archive-detail/service-info-tab.vue';
@ -246,8 +247,14 @@ const instanceProxy = getCurrentInstance()?.proxy;
function switchTab(key) {
currentTab.value = key;
// tab tab
uni.pageScrollTo({ scrollTop: 0, duration: 0 });
// tab tab
nextTick(() => {
// tabs
measureTabsTop();
setTimeout(() => {
uni.pageScrollTo({ scrollTop: tabsScrollTop.value || 0, duration: 0 });
}, 0);
});
}
const archive = ref({
@ -326,7 +333,10 @@ async function fetchArchive() {
}
archive.value = { ...archive.value, ...normalizeArchiveFromApi(res.data) };
saveToStorage();
loadTeamMembers();
await fetchTeamGroups(true);
// tabs
nextTick(() => setTimeout(measureTabsTop, 30));
} catch (e) {
toast('获取档案失败');
} finally {
@ -334,6 +344,46 @@ async function fetchArchive() {
}
}
const userNameMap = ref({});
async function loadTeamMembers() {
const corpId = getCorpId();
const team = uni.getStorageSync(CURRENT_TEAM_STORAGE_KEY) || {};
const teamId = team?.teamId ? String(team.teamId) : '';
if (!corpId || !teamId) return;
if (Object.keys(userNameMap.value || {}).length > 0) return;
const res = await api('getTeamData', { corpId, teamId });
if (!res?.success) return;
const t = res?.data && typeof res.data === 'object' ? res.data : {};
const members = Array.isArray(t.memberList) ? t.memberList : [];
userNameMap.value = members.reduce((acc, m) => {
const uid = String(m?.userid || '');
if (!uid) return acc;
acc[uid] = String(m?.anotherName || m?.name || m?.userid || '') || uid;
return acc;
}, {});
}
function resolveUserName(userId) {
const id = String(userId || '');
if (!id) return '';
const map = userNameMap.value || {};
return String(map[id] || '') || '';
}
function formatCreateTime(v) {
if (v === null || v === undefined) return '';
const raw = typeof v === 'number' ? v : typeof v === 'string' ? v.trim() : '';
const ms =
typeof raw === 'number'
? raw
: raw && /^\d{10,13}$/.test(raw)
? Number(raw.length === 10 ? `${raw}000` : raw)
: null;
const d = ms !== null ? dayjs(ms) : dayjs(raw);
return d.isValid() ? d.format('YYYY-MM-DD HH:mm') : '';
}
const teamGroups = ref([]);
const groupNameMap = computed(() => {
const map = new Map();
@ -505,10 +555,11 @@ const idRows = computed(() => {
});
const createText = computed(() => {
const time = archive.value.createTime ? String(archive.value.createTime) : '';
const time = formatCreateTime(archive.value.createTime);
const rawCreator = archive.value.creator ? String(archive.value.creator) : '';
const creator = ['-', '—', '--'].includes(rawCreator.trim()) ? '' : rawCreator.trim();
if (time && creator) return `${time} ${creator}创建`;
const creatorId = ['-', '—', '--'].includes(rawCreator.trim()) ? '' : rawCreator.trim();
const creatorName = creatorId ? resolveUserName(creatorId) : '';
if (time && creatorName) return `${time} ${creatorName}创建`;
if (time) return `${time} 创建`;
return '';
});