eight
2024-09-12 659bff41eef235e4adb7fce892a768c52c5f1ea5
src/views/ecg/callingscreen/bigscreen.vue
@@ -1,5 +1,6 @@
<script setup lang="ts">
import dayjs from 'dayjs'
import {ScreenApi, statusMap, CallingVO} from "@/api/ecg/screen";
defineOptions({ name: 'bigscreen' })
@@ -7,6 +8,10 @@
const listReady = ref<CallingVO[]>([]) // 列表的数据
const listWaiting = ref<CallingVO[]>([]) // 列表的数据
const listPassed = ref<CallingVO[]>([]) //
let curSpeakPat : CallingVO | undefined = undefined;
let curSpeakSeqNum : number = 0
let curWorkDay : Date | undefined = undefined
const getList = async () => {
  const data = await ScreenApi.getBigScreenData()
@@ -17,18 +22,52 @@
const startScrolling = () => {
  setInterval(() => {
    // console.info("...")
    getList();
  }, 3000); // 每两秒滚动一次
    if ( curSpeakPat === undefined ) {
      initiateSpeak()
    }
  }, 5000); // 每X秒滚动一次
}
onMounted( () => {
  startScrolling()
})
const onSpeachEndEvent = async (event) => {
  console.log("Speech ended" + event);
  await ScreenApi.markCalled(curSpeakPat!.patId)
  initiateSpeak()
}
const getNextSpeak = () => {
  if (listReady.value.length === 0) {
    return undefined;
  }
  // TODO 处理每天 反转的情况
  if ( curWorkDay === undefined) {
    curSpeakSeqNum = 0;
    curWorkDay = new Date()
  } else if (!isSameDate(dayjs(listReady.value[0].bookDate).toDate(), curWorkDay)) {
    curSpeakSeqNum = 0;
    curWorkDay = dayjs(listReady.value[0].bookDate).toDate()
  }
  return listReady.value.find( item => item.status === 30 && item.called === 0 && item.seqNum > curSpeakSeqNum)
}
const initiateSpeak = () => {
  const queuePat = getNextSpeak()
  if (queuePat !== undefined) {
    curSpeakPat = queuePat
    curSpeakSeqNum = curSpeakPat.seqNum
    speak(queuePat.patName + queuePat.roomName);
  } else {
    curSpeakPat = undefined
  }
}
const speak = (msg) => {
  //const msg = new SpeechSynthesisUtterance(`请${this.currentNumber}号就诊`);
  const repeatNum = 3
  var speech = new SpeechSynthesisUtterance()
  speech.text = msg
  speech.pitch = 1 // 获取并设置话语的音调(0-2 默认1,值越大越尖锐,越低越低沉)
@@ -36,17 +75,17 @@
  speech.volume = 100 // 获取并设置说话的音量
  speech.lang = 'zh-CN' // 设置播放语言
  utterance.onend = function() {
    console.log("Speech ended");
  };
  // 增加控制播放次数
  let count = 1
  speech.onend = onSpeachEndEvent
  speechSynthesis.speak(speech)
  while (count < repeatNum) {
    speechSynthesis.speak(speech)
    count++
  }
}
const isSameDate = ( date1: Date, date2 : Date) => {
  if (date1.getFullYear() === date2.getFullYear()
      && date1.getMonth() === date2.getMonth()
      && date1.getDate() === date2.getDate())
    return true
  else
    return false
}
</script>
@@ -90,7 +129,7 @@
            </el-table-column>
          </el-table>
        </el-main>
        <el-footer>
        <el-footer height="100px">
          <el-table
            :data="listPassed"
            stripe