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.
261 lines
6.0 KiB
261 lines
6.0 KiB
<template>
|
|
<view class="video-wrapper" id="video-container">
|
|
<view style="position:relative;width:100%;" :style="{'height':videoHeight+'px'}">
|
|
<video ref="video_p" :initial-time="play_time" id="video_play" :src="videoObj.videoUrl" @ended="videoEnded()" :autoplay="auto" :show-fullscreen-btn="false" :loop="isLoop" style="width: 100%;height: 90%;"></video>
|
|
<view class="question"></view>
|
|
<view class="popup-layer-back" v-if="!start" v-show="question">
|
|
<!-- <view class="popup-layer-close" @click="question=false">关闭</view> -->
|
|
<view class="popup-layer">
|
|
<!-- <h2>请选择</h2> -->
|
|
<view>{{ask}}</view>
|
|
<view class="anitem" @click="nextQuestion(item.outs[0], item)" v-for="(item, index) in answerList">
|
|
<image class="animg" src="/static/videos/skin_bg_1a.png"></image>
|
|
<view class="antxt">{{item.channel}}</view>
|
|
<view class="judd jdok"><image class="judimg" src="/static/images/icon-ok.png"></image></view>
|
|
<view class="judd jderr"><image class="judimg" src="/static/images/icon-err.png"></image></view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<!-- <view class="popup-layer-back" v-if="start">
|
|
<view class="popup-layer" @click="nextQuestion(2, null)">
|
|
<p>开始</p>
|
|
</view>
|
|
</view> -->
|
|
<!-- <view class="popup-layer-back" v-if="end">
|
|
<view class="popup-layer" @click="getBindJson()">
|
|
<p>重新开始</p>
|
|
</view>
|
|
</view> -->
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import { mapMutations, mapState } from 'vuex'
|
|
export default {
|
|
name: "s-video",
|
|
data() {
|
|
return {
|
|
isLoop: false,
|
|
play_time: 0,
|
|
videoHeight: 300,
|
|
videoObjList: [],
|
|
videoObj:{},
|
|
answerList: [],
|
|
start: true,
|
|
end: false,
|
|
auto: true,
|
|
question: false,
|
|
questionFreId: "",
|
|
preQuestionId: "",
|
|
correct: "",
|
|
ask: "",
|
|
};
|
|
},
|
|
computed: {
|
|
...mapState('m_user', ['userId'])
|
|
},
|
|
watch:{
|
|
jsonId:{
|
|
handler:function(){
|
|
this.getBindJson();
|
|
}
|
|
}
|
|
},
|
|
props:{
|
|
jsonId: {
|
|
type: String,
|
|
default: "",
|
|
}
|
|
},
|
|
created() {
|
|
uni.getSystemInfo({
|
|
success: (res) => {
|
|
this.videoHeight = res.screenHeight;
|
|
}
|
|
});
|
|
|
|
this.videoContext = uni.createVideoContext("video_play");
|
|
this.videoContext.requestFullScreen();
|
|
// this.getBindJson();
|
|
},
|
|
methods: {
|
|
videoEnded() {
|
|
this.auto = false;
|
|
this.question = true;
|
|
// 出答案
|
|
if(this.videoObj.outs.length>0) {
|
|
this.answerList =[];
|
|
for(var i=0; i<this.videoObj.outs.length; i++) {
|
|
this.getAnswer(this.videoObj.outs[i])
|
|
}
|
|
} else {
|
|
this.end = true;
|
|
this.answerList = [];
|
|
this.question = false;
|
|
uni.navigateTo({
|
|
url: '/subpkg/complete/complete?questionFreId='+this.questionFreId+'&roleId='+this.jsonId
|
|
})
|
|
}
|
|
},
|
|
nextQuestion(outId, obj) {
|
|
if(2==outId) {
|
|
this.$api.addQuestionFre({
|
|
roleId : this.jsonId,
|
|
// userId : this.userId
|
|
userId : '007'
|
|
})
|
|
.then(res => {
|
|
this.questionFreId = res.data;
|
|
}).catch((e) => console.log(e)); //捕获异常
|
|
}
|
|
|
|
var isCorrect = 0;
|
|
// 先提交所选答案
|
|
if(null!=obj) {
|
|
// 判断答题是否正确
|
|
if(this.correct == obj.channel.slice(0, 1)) {
|
|
isCorrect = 1
|
|
}
|
|
var param = {
|
|
answer : obj.channel,
|
|
ask : this.ask,
|
|
questionFreId : this.questionFreId,
|
|
questionId : this.preQuestionId,
|
|
correctAnswer : this.correct,
|
|
correct : isCorrect,
|
|
}
|
|
this.$api.addAnswer(param)
|
|
.then(res => {
|
|
console.log(res);
|
|
}).catch((e) => console.log(e)); //捕获异常
|
|
}
|
|
|
|
// 答案错误则重播当前视频
|
|
if(isCorrect == 0 && 2 != outId) {
|
|
this.play_time = 0;
|
|
this.auto = true;
|
|
} else {
|
|
// 播放下一视频
|
|
this.hasNodeId(outId);
|
|
this.videoObj.videoUrl = uni.$http.baseUrl + this.videoObj.videoUrl
|
|
this.start = false;
|
|
this.question = false;
|
|
this.auto = true;
|
|
}
|
|
},
|
|
getBindJson() {
|
|
this.start = true;
|
|
this.end = false;
|
|
this.videoObjList = [];
|
|
this.$api.getBindJson(this.jsonId)
|
|
.then(res => {
|
|
this.videoObjList.push(...res.data);
|
|
this.hasNodeId(1);
|
|
}).catch((e) => console.log(e)); //捕获异常
|
|
},
|
|
hasNodeId(nodeId) {
|
|
for(var i=0; i<this.videoObjList.length; i++) {
|
|
if(nodeId == this.videoObjList[i].nodeId) {
|
|
this.videoObj = this.videoObjList[i];
|
|
this.correct = this.videoObjList[i].correct;
|
|
this.ask = this.videoObjList[i].ask;
|
|
}
|
|
}
|
|
this.preQuestionId = this.videoObj.questionId;
|
|
// 直接自动开始播放
|
|
if(nodeId == 1) {
|
|
this.nextQuestion(2, null)
|
|
}
|
|
},
|
|
getAnswer(outId) {
|
|
for(var i=0; i<this.videoObjList.length; i++) {
|
|
if(outId == this.videoObjList[i].nodeId) {
|
|
this.answerList.push(this.videoObjList[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
/* 首先设置背景层 */
|
|
.popup-layer-back {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
z-index: 9998;
|
|
}
|
|
|
|
/* 然后设置弹出层 */
|
|
.popup-layer {
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
/* background-color: #fff; */
|
|
color: #fff;
|
|
padding: 20px;
|
|
z-index: 9999;
|
|
}
|
|
|
|
.popup-layer .anitem {
|
|
position: relative;
|
|
margin: 80rpx;
|
|
width: 600rpx;
|
|
height: 100rpx;
|
|
text-align: center;
|
|
}
|
|
|
|
.popup-layer .anitem .animg {
|
|
width: 100%;
|
|
height: 160rpx;
|
|
}
|
|
|
|
.popup-layer .anitem .antxt {
|
|
position: absolute;
|
|
top: 60%;
|
|
width: 100%;
|
|
font-size: 1.2rem;
|
|
}
|
|
|
|
.judd {
|
|
position: absolute;
|
|
top: -20rpx;
|
|
right: -50rpx;
|
|
width: 100rpx;
|
|
height: 100rpx;
|
|
border-radius: 50%;
|
|
}
|
|
|
|
.jdok {
|
|
background-color: rgba(3, 173, 55, .35);
|
|
}
|
|
|
|
.jderr {
|
|
background-color: rgba(249, 21, 43, .35);
|
|
}
|
|
|
|
.judd .judimg {
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 50%;
|
|
-webkit-transform: translate(-50%, -50%);
|
|
transform: translate(-50%, -50%);
|
|
width: 50%;
|
|
height: 50%;
|
|
}
|
|
|
|
|
|
/* 设置关闭按钮 */
|
|
.popup-layer-close {
|
|
position: absolute;
|
|
top: 5px;
|
|
right: 5px;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|