Commit 5ddfb0f0 authored by marsandheart's avatar marsandheart

修改了切换上一步/下一步时候的继续播放问题

parent b24b77ec
......@@ -13,20 +13,15 @@ import QuestionItem from './DoubleRecord.components/QuestionItem';
const defaultPdfPath = 'https://gitee.com/JYWan/JYWeiBo/raw/master/aia_doc-1.pdf';
// 调用app的展示PDF方法,合同展示节点使用
const showPDF = (pdfPath, pdfName) => {
if (!window.webkit) {
alert('window.webkit 未定义');
return;
}
window.webkit.messageHandlers.aiaPDFPreView.postMessage({
pdfPath,
pdfName
});
// 为什么这个放在useState里面就不能生效,放在外面就可以生效?useState看来也不能用,后面还是用redux吧
let isPlaying = 'N';
const setIsPlaying = (val) => {
isPlaying = val;
};
// question不一定都是问题,也可能是答案,其实分为需要读/不需要读 和 需要操作/不需要操作
const defaultSteps = [
export default function(props) {
// question不一定都是问题,也可能是答案,其实分为需要读/不需要读 和 需要操作/不需要操作
const defaultSteps = [
{
id: '1',
label: '节点一',
......@@ -368,15 +363,14 @@ const defaultSteps = [
}
]
}
];
];
export default function(props) {
const [steps, updateSteps] = useState(defaultSteps);
const [imgSrc1, setImgSrc1] = useState('');
const [imgSrc2, setImgSrc2] = useState('');
const [stepId, setStepId] = useState('1');
const [questionId, setQuestionId] = useState('1');
// const [signVisible, setSignVisible] = useState(false);
// const [isPlaying, setIsPlaying] = useState('N');
const currentStep = steps.find((s) => s.id === stepId);
......@@ -395,7 +389,7 @@ export default function(props) {
return;
} else if (!targetQuestion.needPlay) {
setPlayStatus(questionId, '3');
} else {
} else if(targetQuestion.playStatus !== '2'){
setPlayStatus(questionId, '1');
voiceStart(targetQuestion.voice);
}
......@@ -515,8 +509,25 @@ export default function(props) {
setQuestionId(nextQuestionId); // 设置完之后触发useEffect,由useEffect调用app的朗读
};
// 调用app的展示PDF方法,合同展示节点使用
const showPDF = (pdfPath, pdfName) => {
console.log('show pdf');
if (isPlaying === 'Y') {
return;
}
if (!window.webkit) {
alert('window.webkit 未定义');
return;
}
window.webkit.messageHandlers.aiaPDFPreView.postMessage({
pdfPath,
pdfName
});
};
// 调用app的语音播报,监听语音结束,在刚进入页面时自动调用一次,每一个问题结束后判断是否自动调用
const voiceStart = (voiceContent) => {
setIsPlaying('Y');
console.log(`播放: ${voiceContent}`);
// setTimeout(() => {
......@@ -532,6 +543,7 @@ export default function(props) {
window.aiaVoiceFinish = () => {
console.log('finish one step');
setIsPlaying('N');
finishOneVoice();
};
};
......@@ -559,6 +571,7 @@ export default function(props) {
// 调用app的语音停止,在跳转、翻页的时候调用,避免翻页后继续播放
const voiceStop = () => {
console.log('停止播放');
setIsPlaying('N');
if (!window.webkit) {
alert('window.webkit 未定义');
return;
......@@ -605,18 +618,34 @@ export default function(props) {
// );
};
// 查找最后一个未读的问题,用于跳转上一步、下一步之后回到刚才的问题。
const findLastUnreadQuestion = (sId) => {
const questions = steps.find((s) => s.id === sId).questions;
const len = questions.length;
let questionId = '';
for (let i = 0; i < len; i++) {
questionId = questions[i].questionId;
if (!questions[i].checked) {
break;
}
}
return questionId;
};
// 上一个节点,如果是第一节点则回到上一页
const lastStep = () => {
setPlayStatus(questionId, '3');
voiceStop();
if (stepId === '1') {
voiceStop();
setPlayStatus(questionId, '3');
window.history.go(-1);
} else {
const currentStepIdx = steps.findIndex((s) => s.id === stepId);
const lastStepId = steps[currentStepIdx - 1].id;
voicePause();
setPlayStatus(questionId, '2');
setStepId(lastStepId);
setQuestionId('1');
setQuestionId(findLastUnreadQuestion(lastStepId));
}
};
......@@ -627,7 +656,7 @@ export default function(props) {
return;
}
setPlayStatus(questionId, '3');
voiceStop();
// voiceStop();
if (stepId === 7) {
// setSignVisible(true);
return;
......@@ -636,7 +665,7 @@ export default function(props) {
const nextStepId = steps[currentStepIdx + 1].id;
setStepId(nextStepId);
setQuestionId('1');
setQuestionId(findLastUnreadQuestion(nextStepId));
}
};
......@@ -649,7 +678,14 @@ export default function(props) {
return (
<div className={styles.page}>
<div className={styles.header}>
<img src={Logo} alt="logo" className={styles.aiaLogo}></img>
<img
src={Logo}
alt="logo"
className={styles.aiaLogo}
onClick={() => {
console.log(JSON.stringify({ stepId, questionId, isPlaying }));
}}
></img>
<div>双录指引</div>
<div className={styles.homeIcon}>
<img src={IconHome} alt="logo"></img>
......
......@@ -98,6 +98,10 @@ const InsuredInfo = (props) => {
};
const removeTableData = async (key) => {
if (key === '1') {
return;
}
showLoading();
await sleep(500);
hideLoading();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment