...
|
...
|
@@ -15,10 +15,12 @@ Page({ |
|
|
uploaderNum: 0,
|
|
|
showUpload: true,
|
|
|
imglist: [],
|
|
|
http_url:'',
|
|
|
|
|
|
Count:0,//总题数
|
|
|
current:0,//当前题号
|
|
|
today_id:'',//今日任务id
|
|
|
match_id:'',//比赛任务id
|
|
|
all_data:[],//全部题目
|
|
|
today_data:{
|
|
|
"today_subject_id": 4,//题目ID
|
...
|
...
|
@@ -43,28 +45,31 @@ Page({ |
|
|
'type':0,//题目类型:1=用户上传图片,2=用户上传音频,
|
|
|
'file_url': [] //'图片/音频 【多张图 , 分割 拼接字符串】'
|
|
|
},
|
|
|
alterType:false,//弹窗状态
|
|
|
alterData:{},//弹窗数据
|
|
|
taskType:'',//任务类型 比赛任务 今日任务
|
|
|
TodayTaskType:''//1 打卡 0 补卡
|
|
|
},
|
|
|
changePlayState(){
|
|
|
this.selectComponent("audio").changePlayState
|
|
|
PlayState(){
|
|
|
this.selectComponent("#audio").changePlayState()
|
|
|
},
|
|
|
//下一题
|
|
|
gotoday(){
|
|
|
|
|
|
if(this.data.answer.type == 1 || this.data.imglist.length == 0 ){//图片
|
|
|
if(this.data.answer.type == 1 && this.data.imglist.length == 0 ){//图片
|
|
|
wx.showToast({
|
|
|
title: "请上传图片完成答题",
|
|
|
icon: 'none'
|
|
|
})
|
|
|
return;
|
|
|
}
|
|
|
if(this.data.answer.type == 2 || this.data.musicHttp == ''){//录音文件
|
|
|
if(this.data.answer.type == 2 && this.data.musicHttp == ''){//录音文件
|
|
|
wx.showToast({
|
|
|
title: "请录音完成答题",
|
|
|
icon: 'none'
|
|
|
})
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
var index = this.data.current
|
|
|
var current = this.data.current*1+1;//答题题号
|
|
|
|
|
|
var file = [];//答题文件
|
...
|
...
|
@@ -77,28 +82,41 @@ Page({ |
|
|
this.data.answer.file_url = file
|
|
|
|
|
|
var data = this.data.answer;//当前做完的题目答案
|
|
|
var arr = this.data.allAnswer.push(data)//全部做完的题目答案
|
|
|
this.data.allAnswer.push(data)//全部做完的题目答案
|
|
|
|
|
|
if(this.data.current == this.data.Count){//判断题目是否全部答完
|
|
|
this.TodayTask()
|
|
|
return
|
|
|
}
|
|
|
//下一题答案
|
|
|
if(this.data.taskType == "today"){ //今日任务
|
|
|
let answer = {
|
|
|
'today_subject_id': this.data.all_data[current].today_subject_id, //'题目ID',
|
|
|
'today_subject_id': this.data.all_data[index].today_subject_id, //'题目ID',
|
|
|
'type':0,//题目类型:1=用户上传图片,2=用户上传音频,
|
|
|
'file_url': [] //'图片/音频 【多张图 , 分割 拼接字符串】'
|
|
|
}
|
|
|
}else if(this.data.taskType == "match"){//比赛任务
|
|
|
let answer = {
|
|
|
'match_subject_id': res.data.List[0].match_subject_id, //'题目ID',
|
|
|
'type':0,//题目类型:1=用户上传图片,2=用户上传音频,
|
|
|
'file_url': [] //'图片/音频 【多张图 , 分割 拼接字符串】'
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if(this.data.all_data[current].type == 2){ // 需要用户上传图片
|
|
|
if(this.data.all_data[index].type == 2){ // 需要用户上传图片
|
|
|
answer.type = 1
|
|
|
}else if(this.data.all_data[current].type == 3){ // 需要用户上传录音
|
|
|
}else if(this.data.all_data[index].type == 3){ // 需要用户上传录音
|
|
|
answer.type = 2
|
|
|
}else{
|
|
|
answer.type = 0
|
|
|
answer.type = ''
|
|
|
}
|
|
|
|
|
|
this.setData({
|
|
|
today_data:this.data.all_data[current],//下一题
|
|
|
today_data:this.data.all_data[index],//下一题
|
|
|
current:current,
|
|
|
answer:answer,
|
|
|
allAnswer:arr,
|
|
|
allAnswer:this.data.allAnswer,
|
|
|
uploaderList:[],//下一题后图片置空
|
|
|
imglist:[],//下一题后图片置空
|
|
|
musicHttp:'',//下一题后录音文件置空
|
...
|
...
|
@@ -111,10 +129,27 @@ Page({ |
|
|
//答题提交
|
|
|
TodayTask(){
|
|
|
clearInterval(time)
|
|
|
var temporary = (time_num/60).toFixed(2);
|
|
|
app.post("today/TodayTask", {today_id:this.data.today_id,json:this.data.allAnswer,learn_time:temporary,type:1}).then(res => {
|
|
|
var data = {}//提交参数
|
|
|
var url = '' //接口地址
|
|
|
//判断任务类型
|
|
|
if(this.data.taskType == "today"){ //今日任务
|
|
|
url = 'today/TodayTask'
|
|
|
data = {today_id:this.data.today_id,json:all_data,learn_time:temporary,type:this.data.TodayTaskType}
|
|
|
}else if(this.data.taskType == "match"){//比赛任务
|
|
|
url = 'match/MatchTask'
|
|
|
data = {match_id:this.data.match_id,json:all_data,learn_time:temporary}
|
|
|
}
|
|
|
var temporary = Math.ceil(time_num/60);//学习事件
|
|
|
var all_data = JSON.stringify(this.data.allAnswer)
|
|
|
app.post(url,data ).then(res => {
|
|
|
if(res.code == 1){
|
|
|
console.log(res)
|
|
|
this.TodayTaskWindow()
|
|
|
}else{
|
|
|
wx.showToast({
|
|
|
title: res.msg,
|
|
|
icon: 'none'
|
|
|
})
|
|
|
}
|
|
|
}).catch(err => {
|
|
|
wx.showToast({
|
...
|
...
|
@@ -127,22 +162,68 @@ Page({ |
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
this.data.today_id = options.id
|
|
|
|
|
|
if(options.type == "today"){//今日任务
|
|
|
this.setData({
|
|
|
today_id:options.id,
|
|
|
})
|
|
|
this.TodayQuestion()
|
|
|
}else if(options.type == "match"){//比赛任务
|
|
|
this.setData({
|
|
|
match_id:options.id,
|
|
|
})
|
|
|
this.TodayQuestion()
|
|
|
const innerAudioContext = wx.createInnerAudioContext()
|
|
|
innerAudioContext.autoplay = true
|
|
|
}
|
|
|
this.setData({
|
|
|
innerAudioContext,
|
|
|
taskType:options.type,
|
|
|
TodayTaskType:options.type,
|
|
|
http_url:app.globalData.imgBaseUrl,
|
|
|
today_id:options.id,
|
|
|
})
|
|
|
var that = this;
|
|
|
time = setInterval(function(){
|
|
|
time_num++
|
|
|
},1000)
|
|
|
},
|
|
|
//提交完成弹窗
|
|
|
TodayTaskWindow(){
|
|
|
var data = {}//提交参数
|
|
|
var url = '' //接口地址
|
|
|
if(this.data.taskType == "today"){ //今日任务
|
|
|
url = 'today/TodayTaskWindow'
|
|
|
data = {TodayClockId:this.data.today_id}
|
|
|
}else if(this.data.taskType == "match"){//比赛任务
|
|
|
url = 'match/MatchTask'
|
|
|
data = {MatchClockId:this.data.match_id}
|
|
|
}
|
|
|
app.post(url,data).then(res => {
|
|
|
if(res.code == 1){
|
|
|
console.log(res)
|
|
|
this.setData({
|
|
|
alterData:res.data
|
|
|
})
|
|
|
this.setData({
|
|
|
alterType:true
|
|
|
})
|
|
|
}
|
|
|
}).catch(err => {
|
|
|
wx.showToast({
|
|
|
title: err.msg,
|
|
|
icon: 'none'
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
//完成任务返回首页
|
|
|
gototram(){
|
|
|
|
|
|
wx.switchTab({
|
|
|
url: '/pages/index/index',
|
|
|
})
|
|
|
},
|
|
|
//获取今日任务列表
|
|
|
TodayQuestion(){
|
|
|
var that = this;
|
|
|
app.post("today/TodayQuestion", {today_id:this.data.today_id}).then(res => {
|
|
|
app.post("match/MatchQuestion", {today_id:this.data.match_id}).then(res => {
|
|
|
if(res.code == 1){
|
|
|
console.log(res)
|
|
|
|
...
|
...
|
@@ -151,13 +232,46 @@ Page({ |
|
|
'type':0,//题目类型:1=用户上传图片,2=用户上传音频,
|
|
|
'file_url': [] //'图片/音频 【多张图 , 分割 拼接字符串】'
|
|
|
}
|
|
|
if( res.data.List[0].type == 2){ // 需要用户上传图片
|
|
|
answer.type = 1
|
|
|
}else if( res.data.List[0].type == 3){ // 需要用户上传录音
|
|
|
answer.type = 2
|
|
|
}else{
|
|
|
answer.type = ''
|
|
|
}
|
|
|
this.setData({
|
|
|
today_data:res.data.List[0],//第一题
|
|
|
all_data:res.data.List,//全部题
|
|
|
Count:res.data.Count,//总题数
|
|
|
current:1,//当前题数
|
|
|
answer,
|
|
|
})
|
|
|
}
|
|
|
}).catch(err => {
|
|
|
wx.showToast({
|
|
|
title: err.msg,
|
|
|
icon: 'none'
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
//比赛任务
|
|
|
TodayQuestion(){
|
|
|
var that = this;
|
|
|
app.post("match/MatchQuestion", {match_id:this.data.today_id}).then(res => {
|
|
|
if(res.code == 1){
|
|
|
console.log(res)
|
|
|
|
|
|
let answer = {
|
|
|
'match_subject_id': res.data.List[0].match_subject_id, //'题目ID',
|
|
|
'type':0,//题目类型:1=用户上传图片,2=用户上传音频,
|
|
|
'file_url': [] //'图片/音频 【多张图 , 分割 拼接字符串】'
|
|
|
}
|
|
|
if( res.data.List[0].type == 2){ // 需要用户上传图片
|
|
|
answer.type = 1
|
|
|
}else if( res.data.List[0].type == 3){ // 需要用户上传录音
|
|
|
answer.type = 2
|
|
|
}else{
|
|
|
answer.type = 0
|
|
|
answer.type = ''
|
|
|
}
|
|
|
this.setData({
|
|
|
today_data:res.data.List[0],//第一题
|
...
|
...
|
@@ -318,9 +432,14 @@ Page({ |
|
|
}
|
|
|
})
|
|
|
},
|
|
|
//上传请求
|
|
|
//文件上传请求
|
|
|
upload_file(data,type){
|
|
|
var that = this;
|
|
|
wx.uploadFile({
|
|
|
header:{
|
|
|
'content-type': 'application/json',
|
|
|
'token': wx.getStorageSync('token') ? wx.getStorageSync('token') : ''
|
|
|
},
|
|
|
url: app.globalData.baseUrl + 'common/upload', //接口地址
|
|
|
filePath: data, //要上传文件资源的路径 (本地路径)
|
|
|
name: 'file', //文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容
|
...
|
...
|
@@ -329,16 +448,17 @@ Page({ |
|
|
},
|
|
|
success(res) {
|
|
|
wx.hideLoading();
|
|
|
console.log(res.data)
|
|
|
var str = res.data
|
|
|
var file = JSON.parse(str);
|
|
|
if(type == 'img'){
|
|
|
let imglist = that.data.imglist.concat(file.data.save_path)
|
|
|
if(type == 'img'){ //图片文件
|
|
|
let imglist = that.data.imglist.concat(file.data.url)
|
|
|
that.setData({
|
|
|
imglist: imglist
|
|
|
})
|
|
|
}else{
|
|
|
}else{//mp3文件
|
|
|
that.setData({
|
|
|
musicHttp: file.data.save_path
|
|
|
musicHttp: file.data.url
|
|
|
})
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -378,12 +498,12 @@ Page({ |
|
|
that.upload_file(res.tempFilePath)//上传录音文件
|
|
|
})
|
|
|
},
|
|
|
//录音播放事件
|
|
|
play_voice(){
|
|
|
// console.log("播放录音")
|
|
|
this.setData({
|
|
|
soundType:3,//录音结束
|
|
|
})
|
|
|
|
|
|
innerAudioContext.src = this.data.musicUrl
|
|
|
innerAudioContext.onPlay(() => { // 监听音频播放事件
|
|
|
console.log('开始播放')
|
...
|
...
|
@@ -393,16 +513,17 @@ Page({ |
|
|
console.log(res.errCode)
|
|
|
})
|
|
|
},
|
|
|
//录音暂停事件
|
|
|
pause_voice(){
|
|
|
this.setData({
|
|
|
soundType:2,//录音结束
|
|
|
})
|
|
|
console.log("暂停录音")
|
|
|
InnerAudioContext.pause()
|
|
|
InnerAudioContext.onPause(() => { // 监听音频暂停事件
|
|
|
innerAudioContext.pause()
|
|
|
innerAudioContext.onPause(() => { // 监听音频暂停事件
|
|
|
console.log('暂停播放')
|
|
|
})
|
|
|
InnerAudioContext.offError((res) => { // 取消监听音频加载中事件
|
|
|
innerAudioContext.offError((res) => { // 取消监听音频加载中事件
|
|
|
console.log(res.errMsg)
|
|
|
console.log(res.errCode)
|
|
|
})
|
...
|
...
|
|