yxh
2026-10-03 d553a4be94d4f6ee162cc353a28b220403909cfc
src/views/ecg/doctor/components/TitlePanel.vue
@@ -2,6 +2,7 @@
import {defineComponent, PropType} from "vue";
import {PatientStatisticVO, RoomBedVO} from "@/api/ecg/doctor";
import {useCheckTypeStore} from "@/store/modules/checkType";
import {useRoomStore} from "@/store/modules/room";
import {getCheckTypeName} from "../../../../utils/checkTypeFormatter";
defineComponent({
@@ -21,47 +22,162 @@
})
const checkTypeStore = useCheckTypeStore();
const roomStore = useRoomStore();
/**
 * 本工位开展的检查项目(诊断问题:"标题栏不显示检查项目")。
 *
 * 优先取页面传入的 `props.room.checkTypes`;**为空时回退到 store**。
 *
 * 为什么要兜底:`props.room` 是调用方自己的一个字面量对象
 * (如 Routine.vue 的 `const roomBedVO: RoomBedVO = { …, checkTypes: null }`),
 * 它在 `onMounted` 里才被赋值 `roomStore.room.checkTypes`。只要这条赋值链路
 * 有任何一环没走到(例如刷新后 store 恢复不完整、页面未走 onMounted 的赋值分支),
 * 标题栏就会**静默地什么都不显示**。而 store 里的诊室信息一定携带 checkTypes
 * (由「诊室选择」写入并持久化),因此用它兜底更可靠。
 */
const roomCheckTypes = computed<number[]>(() => {
  const fromProp = props.room?.checkTypes
  if (Array.isArray(fromProp) && fromProp.length > 0) {
    return fromProp
  }
  const fromStore = roomStore.room?.checkTypes
  return Array.isArray(fromStore) ? fromStore : []
})
/**
 * 把该工位支持的检查项目名拼成一串,供标题栏**一行**展示。
 *
 * 为什么用模板字符串而不是 v-for + span:原先检查项目外层套了一个块级 div,
 * 导致必然换行(el-header 只有 40px 高,两行会溢出)。
 * 拼成单个文本节点后,配合 CSS `white-space:nowrap` + `text-overflow:ellipsis`
 * 即可稳定保持一行,超长时省略号截断。
 */
const checkTypeNames = computed(() =>
  roomCheckTypes.value
    .map((checkType) => getCheckTypeName(checkType))
    .filter((name) => !!name)
    .join('  ')
)
/**
 * 诊室名 + 工位号 + 领用/安装标记。同样在 props 为空时回退到 store,
 * 避免标题栏左侧整块变空(与 roomCheckTypes 一致的兜底思路)。
 */
const roomIdentity = computed(() => {
  const fromProp = props.room
  const roomName = fromProp?.roomName || roomStore.room?.roomName || ''
  const bedNo = fromProp?.bedNo || roomStore.room?.bedNo || ''
  const opType = fromProp?.opType ?? roomStore.room?.opType
  const opTag = opType === 1 ? '领用' : opType === 2 ? '安装' : ''
  return [roomName, bedNo, opTag].filter((s) => !!s).join(' ')
})
</script>
<template>
<div class="mytitle">
    <div>
      <img v-if="titleType !== room.opType"
           src="@/assets/imgs/error.png"
           alt="禁止访问本页面,当前工位不符合要求"
           width="20px"
      />
      {{room.roomName || ''}} {{room.bedNo || ''}} {{room.opType === 1?"领用":""}} {{room.opType === 2?"安装":""}}
      <div>
        <span v-for="(checkType, subIndex) in room.checkTypes" :key="subIndex">
          {{getCheckTypeName(checkType)}} &nbsp;
        </span>
      </div>
    </div>
    <div v-if="titleType === 0">
      已检查{{patientStatistic.finishedNum??0}}
      准备中{{patientStatistic.readyNum??0}}
      过号{{patientStatistic.passedNum??0}}
      排队中{{patientStatistic.queuingNum??0}}
    </div>
    <div v-if="titleType === 1">
      已发放{{patientStatistic.receivedNum??0}}
      准备中{{patientStatistic.readyNum??0}}
      过号{{patientStatistic.passedNum??0}}
      排队中{{patientStatistic.queuingNum??0}}
    </div>
    <div v-if="titleType === 2">
      已装机{{patientStatistic.finishedNum??0}}
      待装机{{patientStatistic.receivedNum??0}}
    </div>
</div>
  <!--
    需求:标题栏的「诊室名称 / 工位号 / 检查项目」要排在**一行**(如「6号门诊 F1 平板运动心电」),
    右侧的统计信息也留在同一行。
    原先的结构是:
      <div> {{roomName}} {{bedNo}} …  <div><span v-for=检查项目/></div> </div>
    其中检查项目外面套了一个**块级 div**,因此检查项目必然换到第二行;
    而 el-header 只有 40px 高,两行会溢出。
    现改为:
      · 左侧整块用 `display:flex; align-items:center; white-space:nowrap`,全部行内排列;
      · 超长时用**省略号**截断(不换行、不撑破 40px 高度);
      · 右侧统计 flex:none 靠右,并允许自行收缩。
  -->
  <div class="mytitle">
    <!-- 左:工位标识 + 检查项目,全部一行 -->
    <div class="mytitle__left">
      <img
        v-if="titleType !== room.opType"
        class="mytitle__warn"
        src="@/assets/imgs/error.png"
        alt="禁止访问本页面,当前工位不符合要求"
      />
      <span class="mytitle__room">
        {{ roomIdentity }}
      </span>
      <!-- 检查项目:有值才渲染(避免出现一个空白占位) -->
      <span v-if="checkTypeNames" class="mytitle__checktypes">
        {{ checkTypeNames }}
      </span>
    </div>
    <!-- 右:统计信息(同一行最右) -->
    <div class="mytitle__stat">
      <template v-if="titleType === 0">
        已检查{{ patientStatistic.finishedNum ?? 0 }}
        准备中{{ patientStatistic.readyNum ?? 0 }}
        过号{{ patientStatistic.passedNum ?? 0 }}
        排队中{{ patientStatistic.queuingNum ?? 0 }}
      </template>
      <template v-else-if="titleType === 1">
        已发放{{ patientStatistic.receivedNum ?? 0 }}
        准备中{{ patientStatistic.readyNum ?? 0 }}
        过号{{ patientStatistic.passedNum ?? 0 }}
        排队中{{ patientStatistic.queuingNum ?? 0 }}
      </template>
      <template v-else-if="titleType === 2">
        已装机{{ patientStatistic.finishedNum ?? 0 }}
        待装机{{ patientStatistic.receivedNum ?? 0 }}
      </template>
    </div>
  </div>
</template>
<style scoped lang="scss">
.mytitle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  /* 标题栏只有 40px 高:整行不换行,超长用省略号 */
  overflow: hidden;
  font-size: 18px;
  line-height: 1;
}
/* 左:工位标识 + 检查项目,全部排在一行 */
.mytitle__left {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 10px;
  min-width: 0; /* 允许收缩,配合省略号 */
  white-space: nowrap;
}
.mytitle__warn {
  flex: none;
  width: 20px;
  height: 20px;
}
/* 诊室名 + 工位号:优先完整显示,实在放不下才截断 */
.mytitle__room {
  flex: none;
  font-weight: 600;
}
/* 检查项目:占满剩余空间,超长截断 */
.mytitle__checktypes {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--el-color-primary);
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* 右:统计信息 */
.mytitle__stat {
  flex: none;
  padding-left: 12px;
  white-space: nowrap;
}
</style>