proCompound() {
let that = this
let json = JSON.parse(JSON.stringify(that.data.projectjson))
console.log(json);
textToWav({
id: json.character.voiceId,
text: json.ppt.pages[0].text,
language: '中文',
})
.then((res) => {
this.setData({
syntheticVideo: false
})
this.checkStatusInterval = setInterval(() => {
this.wavStatuss(res.data.taskId);
}, 5000);
})
.catch((err) => {
Message.error(err);
});}
wavStatuss(params) {
wavPath({
taskId: params
}).then((res) => {
if (res.code == 200) {
clearCheckStatusInterval();
this.$message.success(res.msg);
}
if (res.code == 201) {
clearCheckStatusInterval();
this.$message.error(res.msg);
}
});
},
clearCheckStatusInterval() {
if (this.checkStatusInterval) {
clearInterval(this.checkStatusInterval);
this.checkStatusInterval = null;
}
}, 为什么200的时候没有清除定时器
这里少了this吧?????
我记得没错的话,你不得用this.clearCheckStatusInterval()吗?
还有就是checkStatusInterval 你需要页面参数里声明一下的
你确定调用方法成功了
let that = this
let json = JSON.parse(JSON.stringify(that.data.projectjson))
console.log(json);
textToWav({
id: json.character.voiceId,
text: json.ppt.pages[0].text,
language: '中文',
})
.then((res) => {
that .setData({
syntheticVideo: false
})
that .checkStatusInterval = setInterval(() => {
that .wavStatuss(res.data.taskId);
}, 5000); // 60000毫秒即1分钟
})
.catch((err) => {
Message.error(err);
});} //合成语音状态
wavStatuss(params) {
let that = this;
wavPath({
taskId: params
}).then((res) => {
if (res.code == 200) {
that.clearCheckStatusInterval(); // 当code为200时,停止定时器
that.$message.success(res.msg);
}
if (res.code == 201) {
that.clearCheckStatusInterval(); // 当code为201时,停止定时器
that.$message.error(res.msg);
}
});
},
// 定义清理定时器的方法
clearCheckStatusInterval() {
if (this.checkStatusInterval) {
clearInterval(this.checkStatusInterval);
this.checkStatusInterval = null; // 清理后重置定时器引用
}
}