generated from ccsens_fe/uni-vue3-template
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.3 KiB
54 lines
1.3 KiB
import { computed, onUnmounted, ref } from 'vue'
|
|
|
|
import { onUnload } from '@dcloudio/uni-app'
|
|
import { useServiceStore } from '@/store/modules/service'
|
|
|
|
export interface INextNode {
|
|
countDownInSeconds: string
|
|
firstAidId: number
|
|
nextStepCode: string
|
|
nextStepName: string
|
|
nextStepType: string // 0 仅显示 1 弹窗询问是否进入下个环节
|
|
}
|
|
|
|
export function useNextNode() {
|
|
const serviceStore = useServiceStore()
|
|
const nextNode = ref<null | INextNode>(null)
|
|
const currentFirstAidId = computed(() => serviceStore.currentFirstAidId)
|
|
let timer: number
|
|
|
|
async function getNextNode() {
|
|
if (!currentFirstAidId.value) {
|
|
uni.$u.alertError('没有急救id信息')
|
|
return
|
|
}
|
|
try {
|
|
nextNode.value = await uni.$u.api.getNextNode(currentFirstAidId.value)
|
|
} catch (error) {
|
|
nextNode.value = null
|
|
uni.$u.alertError(error)
|
|
}
|
|
}
|
|
|
|
// 循环查下个节点
|
|
function intervalGetNextCode() {
|
|
timer && clearInterval(timer)
|
|
timer = setInterval(() => {
|
|
getNextNode()
|
|
}, 1000)
|
|
}
|
|
|
|
onUnmounted(() => {
|
|
console.log('on unmounted')
|
|
|
|
timer && clearInterval(timer)
|
|
timer = 0
|
|
})
|
|
|
|
onUnload(() => {
|
|
console.log('on unload')
|
|
timer && clearInterval(timer)
|
|
timer = 0
|
|
})
|
|
return { nextNode, getNextNode, intervalGetNextCode }
|
|
}
|
|
|