import common from '../../utils/util'; import main from '../../utils/main'; import constant from '../../utils/constant'; const app = getApp(); const arrStudyPlan = ["日常", "紧急"]; var innerAudioContext1; var listTaskFinished = []; //完成的任务 var timeStart; //计算时长 var timeHistory = 0; //已经过去的时间 var TaskList = []; //任务列表 var FolderList = []; //卡单列表 var arrImage = [], arrImage2 = []; var intervalSound = 0, intervalRefresh = 0; var isCollecting = false; var isExit = true; var isPlaying = false; var currentFolderID = -1; //当前练习卡单ID,没有时为-1 var currentFolderStart = false; var timeoutPlayAudio; var tempPlayUrl = ""; var tempPlayUrlLocal = ""; var timeoutEveryCard = 0; var timeoutHide = 0; var arrAutoAudio = []; Page({ data: { ImagePath: app.globalData.uploadImageUrl, NumberNew: 10, NumberReview: 0, NumberHistory: 30, IsShowNumberInfo: false, IsMore: false, IsShowFolder: false, StudyPlanArray: arrStudyPlan, TaskInfo: {}, Color: { ID: 1 }, IsAutoSound: false, //是否设置了自动播放 IsAutoSoundStart: false, //是否开始自动播放 Title: "", FontSizeArray: constant.arrFontSize, IsBuildReport:false, }, onReady: function () { var that = this; innerAudioContext1 = wx.createInnerAudioContext(); innerAudioContext1.onPlay(() => { //console.log('开始播放') }); innerAudioContext1.onError((res) => { console.log("innerAudioContext1.errMsg:" + res.errMsg); console.log("innerAudioContext1.errCode:" + res.errCode); that.audioCtx.setSrc(tempPlayUrl); that.audioCtx.play(); }); innerAudioContext1.onEnded((res) => { that.audioBindEnded(); }); common.getStorageValue(that, "HasSound", true, function () { wx.setStorageSync("HasSound", that.data.HasSound); }); }, onLoad: function (options) { var that = this; var height = app.globalData.systemInfo.screenHeight * 2 - 90; var height2 = 750; if (app.globalData.IsIPad) { height = app.globalData.systemInfo.screenHeight; height2 = 670; that.setData({ IsIPad: "_iPad", }); } that.setData({ IsBuildReport:false, Containnerheight: height, Containnerheight2: height - height2, IsShowAnswer: [0, 0], CanUndo: 1, TaskInfo: {}, ClickType: app.globalData.ClickType, Color: main.getDetailColor(app.globalData.ColorIndex), }); if (that.data.IsShowOtherButton) that.closeOtherButton(); this.audioCtx = wx.createAudioContext('myAudio'); this.startTask(); this.getList(); this.getColor(); this.getMemoryLevel(); if (app.globalData.BaiduToken === "") main.getBaiduToken(); if (app.globalData.IsOppo) { that.setData({ TextSpace: "nbsp", }); } }, onShow: function () { var that = this; if (that.data.NumberNew == 0 && that.data.NumberReview == 0 && that.data.NumberHistory == 0) { that.setData({ CanUndo: 0, TaskInfo: {}, }); listTaskFinished = []; that.getTaskTime(); } else { that.setSoundFile(-1); var list = app.globalData.CardList; if (list && list.length > 0) { for (var i = 0; i < list.length; i++) { if (TaskList && TaskList[0] && TaskList[0].MiaoguoCardID == list[i].MiaoguoCardID) { TaskList[0].Content = list[i].Content; TaskList[0].ContentNew = main.changeStringToView(list[i].Content); that.setData({ TaskInfo: TaskList[0], }); app.globalData.CardList = []; break; } } } } if (that.data.IsMore) { //关于更改学习计划后处理 if (app.globalData.IsUpdateStudyPlan == 1) { that.gotoNext({ currentTarget: { dataset: { btnnumber: -2 } } }); app.globalData.IsUpdateStudyPlan = 0; } that.setData({ IsMore: false, }); } clearTimeout(timeoutHide); //console.log("显示"); }, startTask: function () { var url = 'StartMiaoguoTask?UserID=' + app.globalData.userInfo.UserID; main.getData(url, function (data) {}); }, onUnload: function () { clearInterval(intervalSound); clearTimeout(timeoutEveryCard); clearTimeout(timeoutHide); listTaskFinished = []; isPlaying = false; if (innerAudioContext1) { innerAudioContext1.stop(); } }, onHide: function (e) { console.log("隐藏"); var that = this; if (isExit) { timeoutHide = setTimeout(function () { that.onClose(); }, 200000); } isExit = true; }, onPullDownRefresh: function () { this.onShowAnswer({ currentTarget: { dataset: { start: true } } }); wx.stopPullDownRefresh(); }, setSoundFile: function (isFinish) { //isFinish=3搁置 =2撤退 =1结束 =0正常 =-1开始 var that = this; if (that.data.HasSound) { var url = "/pages/sounds/"; if (isFinish == 1) { url += "end.mp3"; } else if (isFinish == 2) { url += "short3.mp3"; } else if (isFinish == 3) { url += "short1.mp3"; } else { url += "short2.mp3"; } if (isFinish >= 0) { innerAudioContext1.src = url; innerAudioContext1.play(); } } wx.pageScrollTo({ scrollTop: 0, }); }, getColor: function () { var that = this; if (wx.setBackgroundColor) { wx.setBackgroundColor({ backgroundColor: that.data.Color.BackColor, backgroundColorTop: that.data.Color.BackColor, backgroundColorBottom: that.data.Color.BackColor, }); } if (wx.setNavigationBarColor) { wx.setNavigationBarColor({ frontColor: "#ffffff", backgroundColor: that.data.Color.BackColor, }) } }, getList: function () { var task = app.globalData.TaskToday; FolderList = task.FolderName; var that = this; var arrNew = task.ListNew || []; var arrHistory = task.ListHistory || []; var listTaskReview = task.ListReview || []; var nMax = [1, 1]; if (arrNew.length == 0 || arrHistory.length == 0) { if (arrNew.length == 0) { nMax[0] = 0; } if (arrHistory.length == 0) { nMax[1] = 0; } } else if (arrNew.length >= arrHistory.length) { nMax[0] = Math.floor(arrNew.length / arrHistory.length); } else if (arrNew.length < arrHistory.length) { nMax[1] = Math.floor(arrHistory.length / arrNew.length); } arrNew = common.randomArray(arrNew); arrHistory = common.randomArray(arrHistory); var Len = arrNew.length + arrHistory.length; TaskList = []; var indexNew = 0, indexHistory = 0; for (var i = 0; i < Len; i++) { for (var j = 0; j < nMax[0]; j++) { if (indexNew < arrNew.length) { arrNew[indexNew].IsNew = true; delete arrNew[indexNew].IsHistory; TaskList.push(arrNew[indexNew++]); } } for (var j = 0; j < nMax[1]; j++) { if (indexHistory < arrHistory.length) { arrHistory[indexHistory].IsHistory = true; delete arrHistory[indexHistory].IsNew; TaskList.push(arrHistory[indexHistory++]); } } } that.data.NumberReview = listTaskReview.length; for (var i = 0; i < listTaskReview.length; i++) { listTaskReview[i].IsReview = true; delete listTaskReview[i].IsNew; delete listTaskReview[i].IsHistory; TaskList.push(listTaskReview[i]); } TaskList = updateNumberStr(TaskList); //处理列表 TaskList = formatList(TaskList); var taskInfo = {}; if (TaskList.length > 0) { arrImage = TaskList[0].ContentNew.Images; arrImage2 = TaskList[0].ContentNew.Images2; that.autoAudioPlayInit(); taskInfo = TaskList[0]; common.getStorageValue(that, "IsFolderPractice", 0, function () { if (that.data.IsFolderPractice == 1) that.onShowFolder(); }); } that.setData({ NumberNew: arrNew.length, NumberReview: that.data.NumberReview, NumberHistory: arrHistory.length, TaskInfo: taskInfo, CanUndo: 0, }); listTaskFinished = []; that.timeCompute(); //起始时间 function formatList(list) { for (var i = 0; i < list.length; i++) { if (list[i].Content) { list[i].ContentNew = main.changeStringToView(list[i].Content); list[i].TagWidth = 0; if (list[i].ContentNew.Tags && list[i].ContentNew.Tags.length > 0) { list[i].TagWidth = 92 + (list[i].ContentNew.Tags.length - 1) * 122; for (var j = 0; j < list[i].ContentNew.Tags.length; j++) { if (list[i].ContentNew.Tags[j].length > 2) { list[i].TagWidth += 46 * (list[i].ContentNew.Tags[j].length - 2); } } } } } return list; } function updateNumberStr(list) { for (var i = 0; i < list.length; i++) { if (list[i].Number0) list[i].Number0Str = main.getMemoryLevel(app.globalData.MemoryLevel, 0, list[i].Number0); if (list[i].Number1) list[i].Number1Str = main.getMemoryLevel(app.globalData.MemoryLevel, 1, list[i].Number1); if (list[i].Number2) list[i].Number2Str = main.getMemoryLevel(app.globalData.MemoryLevel, 2, list[i].Number2); if (list[i].Number3) list[i].Number3Str = main.getMemoryLevel(app.globalData.MemoryLevel, 3, list[i].Number3);; } return list; } }, onShowAnswer: function (e) { var that = this; var clicktype = e.currentTarget.dataset.type; if (!(clicktype && clicktype == "all" && app.globalData.ClickType == 0)) { var start = e.currentTarget.dataset.start; if (!(that.data.NumberNew == 0 && that.data.NumberReview == 0 && that.data.NumberHistory == 0) && !that.data.IsShowNumberInfo) { if (!that.data.IsShowAnswer) that.data.IsShowAnswer = [0, 0]; var recommend = 0; if (start) { that.data.IsShowAnswer[0] = 0; that.data.IsShowAnswer[1] = 0; } else { if (!that.data.IsShowAnswer) { that.data.IsShowAnswer = [0, 0]; } if (that.data.IsShowAnswer[0] == 0 && that.data.IsShowAnswer[1] == 0) { that.data.IsShowAnswer[0] = 1; if (TaskList[0].ContentNew && TaskList[0].ContentNew.Field && TaskList[0].ContentNew.Field.length > 0) { if (TaskList[0].ContentNew.Field[3].length == 0) { that.data.IsShowAnswer[1] = 1; if (!that.data.TaskInfo.IsNew) recommend = getRecommendTime(); that.setData({ Recommend: recommend, }); } } } else if (that.data.IsShowAnswer[0] && !that.data.IsShowAnswer[1]) { that.data.IsShowAnswer[1] = 1; if (!that.data.TaskInfo.IsNew) recommend = getRecommendTime(); that.setData({ Recommend: recommend, }); } } that.setData({ IsShowAnswer: that.data.IsShowAnswer, }); that.autoAudioPlayInit(); if (that.data.IsShowAnswer[0] == 1 && that.data.IsShowAnswer[1] == 0) { startScroll(2); } else if (that.data.IsShowAnswer[0] == 1 && that.data.IsShowAnswer[1] == 1) { if (that.data.TaskInfo.Content[3].Content) { startScroll(3); } else { startScroll(2); } } } function startScroll(t) { var num = 0; setHeight("#ViewField1", function (h1) { num += h1; setHeight("#ViewFieldTag", function (hTag) { if (hTag > 0) num += hTag + 60; //console.log("hTag:"+(hTag)); setHeight("#ViewField2", function (h2) { if (t == 2) { if (h2 > (app.globalData.systemInfo.screenHeight / 3)) scroll(num); } else { num += h2 + 20; scroll(num); } }); }); }); } function setHeight(obj, callback) { var query = wx.createSelectorQuery().in(that); query.select(obj).boundingClientRect(function (res) { if (res && res.height) { //console.log(obj+".height:"+res.height); callback(res.height); } else { callback(0); } }).exec(); } function scroll(top) { wx.pageScrollTo({ scrollTop: top, }); } function getRecommendTime() { if (app.globalData.SecondConfigArray[0] > 0) { var duration = common.diffDate("s", timeStart, new Date()); if (duration <= app.globalData.SecondConfigArray[0]) return 3; else if (duration <= app.globalData.SecondConfigArray[1]) return 2; else if (duration <= app.globalData.SecondConfigArray[2]) return 1; else return 0; } else return 0; } } }, gotoEdit: function () { var that = this; //console.log(res.tapIndex); var list = []; list.push(TaskList[0]); app.globalData.CardList = list; wx.navigateTo({ url: './add?type=edit1&id=' + TaskList[0].MiaoguoCardID, }); isExit = false; clearTimeout(timeoutEveryCard); }, //回到上一张题卡 gotoPrev: function () { var that = this; if (listTaskFinished.length > 0) { var card = listTaskFinished.pop(); wx.setStorageSync("ListTaskFinished", listTaskFinished); timeHistory = 0; that.timeCompute(); card.Card.Number0 = card.Number0Old; card.Card.Number0Str = card.Number0StrOld; card.Card.Number1 = card.Number1Old; card.Card.Number1Str = card.Number1StrOld; card.Card.Number2 = card.Number2Old; card.Card.Number2Str = card.Number2StrOld; card.Card.Number3 = card.Number3Old; card.Card.Number3Str = card.Number3StrOld; delete card.Card.IsNew; delete card.Card.IsHistory; delete card.Card.IsReview; if (card.IsNewOld) card.Card.IsNew = card.IsNewOld; else if (card.IsHistoryOld) card.Card.IsHistory = card.IsHistoryOld; else if (card.IsReviewOld) card.Card.IsReview = card.IsReviewOld; //去除重复 for (var i = 0; i < TaskList.length; i++) { if (TaskList[i].MiaoguoCardID == card.Card.MiaoguoCardID) { TaskList.splice(i, 1); } } TaskList.unshift(card.Card); var canUndo = 1; if (listTaskFinished.length == 0) canUndo = 0; arrImage = TaskList[0].ContentNew.Images; arrImage2 = TaskList[0].ContentNew.Images2; that.setData({ IsShowAnswer: [0, 0], TaskInfo: TaskList[0], NumberNew: card.NumberNew, NumberReview: card.NumberReview, NumberHistory: card.NumberHistory, CanUndo: canUndo, Recommend: 0, }); if (that.data.IsShowOtherButton) that.closeOtherButton(); that.autoAudioPlayInit(); wx.showToast({ title: '回到上一张', image: "../images/universalpic_undo_white_120x90.png", }); that.setSoundFile(2); } }, //进入下一张题卡 gotoNext: function (e) { var that = this; //btnnumber可以有 5:秒过 4正常 3困难 2挪到最后 1搁置 0不过 -1今天要练 -2更改计划 -3卡单练习 var btnnumber = e.currentTarget.dataset.btnnumber; //若是“挪到最后” if (btnnumber == 2) { if (TaskList.length > 0) { var card = TaskList.splice(0, 1); card[0].IsFinally = true; card[0].LimitTime = common.formatTime(new Date(), "/", true) + " 23:59:59"; TaskList.push(card[0]); if (currentFolderID >= 0) { that.setCurrentFolder({ currentTarget: { dataset: { folderid: currentFolderID } } }); } that.setData({ IsShowAnswer: [0, 0], TaskInfo: TaskList[0], CanUndo: 1, Recommend: 0, Title: "", }); if (that.data.IsShowOtherButton) that.closeOtherButton(); wx.showToast({ title: '挪到最后', mask: true, image: "../images/universalpic_movetoend_white_120x120.png", }); that.setSoundFile(3); } else { that.setFinallyResult(); } } else { //若是没有选择了卡单,或者刚刚选择卡单 if (currentFolderID == -1 || !currentFolderStart) { var time = e.currentTarget.dataset.time; //处理当前卡片进入历史数组 var finishCard = {}; finishCard.Card = TaskList[0]; finishCard.NumberNew = this.data.NumberNew; finishCard.NumberReview = this.data.NumberReview; finishCard.NumberHistory = this.data.NumberHistory; finishCard.Number0Old = TaskList[0].Number0; finishCard.Number0StrOld = TaskList[0].Number0Str; finishCard.Number1Old = TaskList[0].Number1; finishCard.Number1StrOld = TaskList[0].Number1Str; finishCard.Number2Old = TaskList[0].Number2; finishCard.Number2StrOld = TaskList[0].Number2Str; finishCard.Number3Old = TaskList[0].Number3; finishCard.Number3StrOld = TaskList[0].Number3Str; if (TaskList[0].IsNew) finishCard.IsNewOld = TaskList[0].IsNew; if (TaskList[0].IsHistory) finishCard.IsHistoryOld = TaskList[0].IsHistory; if (TaskList[0].IsReview) finishCard.IsReviewOld = TaskList[0].IsReview; //若是当前题卡更改学习计划 if (btnnumber == -2) { for (var i = 0, flag = true; i < listTaskFinished.length; flag ? i++ : i) { if (listTaskFinished[i].Card.MiaoguoCardID == finishCard.Card.MiaoguoCardID) { listTaskFinished.splice(i, 1); flag = false; } else flag = true; } } else { //若不是搁置 //算出下一次的时间 if (btnnumber != "1") { //若是分钟,则进入复习列表 if (time.lastIndexOf("m") == time.length - 1) { var minute = Number(time.substr(0, time.indexOf("m"))); TaskList[0].LimitTime = common.formatTime(common.addDate("n", minute, new Date())); //若是新建,则10m 1d 4d if (TaskList[0].IsNew || TaskList[0].IsReview) { if (minute == 1) { TaskList[0].Number0 = "1m"; TaskList[0].Number2 = "10m"; } else { TaskList[0].Number0 = "10m"; TaskList[0].Number2 = "1d"; } TaskList[0].Number0Str = main.getMemoryLevel(app.globalData.MemoryLevel, 0, TaskList[0].Number0); TaskList[0].Number2Str = main.getMemoryLevel(app.globalData.MemoryLevel, 2, TaskList[0].Number2); delete TaskList[0].Number1; delete TaskList[0].Number1Str; delete TaskList[0].Number3; delete TaskList[0].Number3Str; TaskList[0].FirstTime = null; TaskList[0].LastTime = null; } //若是历史的,则10m 1d else if (TaskList[0].IsHistory) { TaskList[0].Number0 = "10m"; TaskList[0].Number0Str = main.getMemoryLevel(app.globalData.MemoryLevel, 0, TaskList[0].Number0); delete TaskList[0].Number1; delete TaskList[0].Number1Str; TaskList[0].Number2 = "1d"; TaskList[0].Number2Str = main.getMemoryLevel(app.globalData.MemoryLevel, 2, TaskList[0].Number2); delete TaskList[0].Number3; delete TaskList[0].Number3Str; } TaskList[0].IsReview = true; delete TaskList[0].IsNew; delete TaskList[0].IsHistory; TaskList.push(TaskList[0]); } //若是天月年 else { var dayNum = Number(time.substr(0, time.indexOf("d"))); var date = common.addDate("d", dayNum, new Date()); TaskList[0].LimitTime = common.formatTime(date); } } //修改学习任务个数 var learningType = 0; if (TaskList[0].IsReview) { learningType = 2; } if (TaskList[0].IsNew) { learningType = 0; } else if (TaskList[0].IsHistory) { learningType = 1; } if (btnnumber == "1") { learningType = 3; } finishCard.IntervalTime = time; finishCard.BtnNumber = btnnumber; finishCard.LearningType = learningType; var duration = common.diffDate("s", timeStart, new Date()); if (finishCard.btnnumber == 1) duration = 0; finishCard.Duration = timeHistory + duration; //console.log("CardTime:" + finishCard.Duration); timeHistory = 0; that.timeCompute(); finishCard.LastTime = common.formatTime(new Date()); //添加完成列表,去掉任务列表数据 listTaskFinished.push(finishCard); } wx.setStorageSync("ListTaskFinished", listTaskFinished); TaskList.shift(); } that.data.NumberNew = 0; that.data.NumberHistory = 0; that.data.NumberReview = 0; for (var i = 0; i < TaskList.length; i++) { if (TaskList[i].IsReview) { that.data.NumberReview++; } else if (TaskList[i].IsNew) { that.data.NumberNew++; } else if (TaskList[i].IsHistory) { that.data.NumberHistory++; } } //到时题卡马上显示 for (var i = 0; i < TaskList.length; i++) { if (TaskList[i].IsReview) { if (TaskList[i].LimitTime < common.formatTime(new Date())) { var card = TaskList.splice(i, 1); TaskList.unshift(card[0]); } } } currentFolderStart = false; //若选择了卡单 var bFolder = false; if (currentFolderID >= 0) { for (var i = 0; i < TaskList.length; i++) { if (TaskList[i].FolderID == currentFolderID && !TaskList[i].IsFinally) { var card = TaskList.splice(i, 1); TaskList.unshift(card[0]); bFolder = true; break; } } } //挪到最后题卡继续挪到最后 for (var i = 0; i < TaskList.length; i++) { if (TaskList[i].IsFinally) { var card = TaskList.splice(i, 1); TaskList.push(card[0]); } } //console.log(JSON.stringify(TaskList[0])); //如果所有任务完成 if (that.data.NumberNew == 0 && that.data.NumberReview == 0 && that.data.NumberHistory == 0) { that.setFinallyResult(); } //没有完成任务 else { //如果卡单内题卡已经练习完毕,则重新选择卡单 if (currentFolderID >= 0 && !bFolder) { currentFolderID = -1; that.onShowFolder(); } arrImage = TaskList[0].ContentNew.Images; arrImage2 = TaskList[0].ContentNew.Images2; //任务没有完成,下一张卡片 that.setData({ IsShowAnswer: [0, 0], TaskInfo: TaskList[0], NumberNew: that.data.NumberNew, NumberReview: that.data.NumberReview, NumberHistory: that.data.NumberHistory, CanUndo: 1, Recommend: 0, IsMore: false, }); if (that.data.IsShowOtherButton) that.closeOtherButton(); //console.log("MiaoguoCardID:"+TaskList[0].MiaoguoCardID); //console.log("FolderID:"+TaskList[0].FolderID); that.autoAudioPlayInit(); if (btnnumber == "1") { that.setSoundFile(3); if (time == "1d") { wx.showToast({ title: '搁置一天', mask: true, image: "../images/universalpic_bell_white_120x120.png", }); } } else that.setSoundFile(0); } } }, timeCompute: function () { var that = this; timeStart = new Date(); clearTimeout(timeoutEveryCard); timeoutEveryCard = setTimeout(function () { //计算暂停时已经用掉的时长 timeHistory += common.diffDate("s", timeStart, new Date()); console.log("timeHistory:" + timeHistory); if (!(that.data.NumberNew == 0 && that.data.NumberReview == 0 && that.data.NumberHistory == 0)) { wx.showModal({ title: '提醒', content: '您已等待了' + app.globalData.CardWaitTimeMax + '分钟', showCancel: false, confirmText: "知道了", success(res) { clearTimeout(timeoutEveryCard); clearTimeout(timeoutHide); if (res.confirm) { that.timeCompute(); } }, }); } }, app.globalData.CardWaitTimeMax * 60 * 1000); }, setFinallyResult: function () { var that = this; that.setData({ IsShowAnswer: [0, 0], NumberNew: 0, NumberReview: 0, NumberHistory: 0, CanUndo: 1, Recommend: 0, IsMore: false, }); clearTimeout(timeoutEveryCard); that.setSoundFile(1); main.UpdateMiaoguoCardTodayAll(true, function () { listTaskFinished = []; that.getTaskTime(); }); }, gotoCollect: function () { var that = this; if (!isCollecting) { isCollecting = true; setTimeout(function () { isCollecting = false; }, 3000); var that = this; if (!TaskList[0].IsCollect) { TaskList[0].IsCollect = 1; } else { TaskList[0].IsCollect = 0; } that.setData({ TaskInfo: TaskList[0], }); main.setCollect(TaskList[0].MiaoguoCardID, TaskList[0].IsCollect); } }, getTaskTime: function () { var that = this; var url = "GetMiaoguoTaskTime?"; url += "UserID=" + app.globalData.userInfo.UserID; main.getData(url, function (data) { if (data) { var duration = data.Duration; if (duration > 0) { duration = Math.round(duration / 60); } var speed1 = 0; if (data.Duration > 0) speed1 = Math.round(100 * data.Count / (data.Duration / 60)) / 100; var speed2 = 0 + "秒"; if (data.Count > 0) speed2 = common.getMinuteSecond(Math.round(data.Duration / data.Count), true); app.globalData.TaskToday.DayNumber = data.DayNumber; that.setData({ TodayTime: duration, Speed1: speed1 + "张题卡", Speed2: speed2, Title: "报告", }); if (speed1 == "0张题卡" && speed2 == "0秒" && duration.toString() == "1") { wx.showModal({ title: '提醒', showCancel: false, confirmText: '知道了', content: "也许您已经发现「报告」上的数据有些异样。这是由于本次练习从昨天开始到今天结束,发生了「跨天」的情况。虽然报告内容不够正确,但练习数据不会受到影响,这个问题将在日后得到改善。请不用担心。" }); } } }); }, showNumberContainner: function () { if (!this.data.Title) { this.setData({ IsShowNumberInfo: true, IsMore: false, IsShowFolder: false, }); this.setData({ Title: "进度", }); clearTimeout(timeoutEveryCard); } }, closeNumberContainner: function () { this.setData({ IsShowNumberInfo: false, IsMore: false, IsShowFolder: false, }); this.setData({ Title: "", }); this.timeCompute(); }, showImage: function (e) { var name = e.currentTarget.dataset.name; if (name && name.length > 5) { if (name.indexOf("tmp") >= 0) { wx.previewImage({ current: name, urls: [name], }); } else { wx.previewImage({ current: name, urls: arrImage }); } } }, onFontSize: function (e) { var value = e.currentTarget.dataset.value; TaskList[0].FontSize = value; this.setData({ TaskInfo: TaskList[0], IsMore: false, Title: "", }); }, onBindError: function (e) { var that = this; var serverUrl = e.currentTarget.dataset.serverurl; var oldTempUrl = e.currentTarget.dataset.name; //console.log("serverUrl1:" + serverUrl); wx.downloadFile({ url: serverUrl, // 仅为示例,并非真实的资源 success(res) { // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容 if (res.statusCode === 200) { //console.log("serverUrl2:" + serverUrl); //console.log(res.tempFilePath); main.saveTempImage(serverUrl, res.tempFilePath); for (var i = 0; i < arrImage.length; i++) { if (arrImage[i] == oldTempUrl) { arrImage[i] = res.tempFilePath; } } } } }); clearTimeout(intervalRefresh); intervalRefresh = setTimeout(function () { if (TaskList && TaskList[0]) { TaskList[0].ContentNew = main.changeStringToView(TaskList[0].Content); that.setData({ TaskInfo: TaskList[0], }); } }, 1000); for (var i = 1; i < this.data.TaskInfo.ContentNew.Field.length; i++) { for (var j = 0; j < this.data.TaskInfo.ContentNew.Field[i].length; j++) { if (this.data.TaskInfo.ContentNew.Field[i][j].Type == "image") { this.data.TaskInfo.ContentNew.Field[i][j].Url = this.data.TaskInfo.ContentNew.Field[i][j].Content; } } } this.setData({ TaskInfo: this.data.TaskInfo, }); }, onMore: function () { for (var i = 0; i < this.data.FontSizeArray.length; i++) { if (this.data.FontSizeArray[i].Value == this.data.TaskInfo.FontSize) this.data.FontSizeArray[i].CSS = "color:#1E1E1E;background-color:" + this.data.Color.LineColor + ";border:3rpx solid " + this.data.Color.LineColor + ";"; else this.data.FontSizeArray[i].CSS = ""; } this.setData({ IsMore: true, FontSizeArray: this.data.FontSizeArray, Title: "调节", }); clearTimeout(timeoutEveryCard); }, showOtherButton: function () { var animation = wx.createAnimation(); this.animation = animation; animation.translate(-710 + 'rpx', 0).step({ duration: 200 }); this.setData({ animationData: animation.export(), IsShowOtherButton: true, }); }, closeOtherButton: function () { var animation = wx.createAnimation(); this.animation = animation; animation.translate(0, 0).step({ duration: 200 }); this.setData({ animationData: animation.export(), IsShowOtherButton: false, }); }, onShowFolder: function () { for (var j = 0; j < FolderList.length; j++) { FolderList[j].Total = 0; for (var i = 0; i < TaskList.length; i++) { if (TaskList[i].FolderID == FolderList[j].FolderID && !TaskList[i].IsFinally) { FolderList[j].Total++; } } } var FolderListLength = FolderList.length; for (var j = 0; j < FolderList.length; j++) { if (FolderList[j].Total == 0) { FolderListLength--; } } var IsFinallyCount = 0; for (var j = 0; j < TaskList.length; j++) { if (TaskList[j].IsFinally) { IsFinallyCount++; } } this.setData({ IsShowFolder: true, IsShowNumberInfo: false, IsMore: false, FolderList: FolderList, FolderListLength: FolderListLength, IsFinallyCount: IsFinallyCount, Title: " ", }); }, setCurrentFolder: function (e) { currentFolderID = e.currentTarget.dataset.folderid; currentFolderStart = true; this.gotoNext({ currentTarget: { dataset: { btnnumber: -3 } } }); this.closeNumberContainner(); }, onClose: function () { console.log("close"); wx.navigateBack({ delta: 1, }); }, getMemoryLevel: function () { var index = wx.getStorageSync("MemoryLevel"); if (!index) { index = 0; } if (index > 1) index = 1; app.globalData.MemoryLevel = index; this.setData({ MemoryLevel: index, }); }, buildShareImage: function () { var that = this; that.setData({ IsBuildReport:true, }); wx.showLoading({ title: '生成中', }); setTimeout(function () { wx.hideLoading(); }, 5000); //console.log(app.globalData.userInfo.AvatarUrl); var avatarUrl = app.globalData.userInfo.AvatarUrl; avatarUrl = avatarUrl.substring(0, avatarUrl.lastIndexOf("/") + 1); avatarUrl = avatarUrl + "0"; //console.log(avatarUrl); wx.downloadFile({ url: avatarUrl, success(resDownload) { // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容 if (resDownload.statusCode === 200) { const query = wx.createSelectorQuery(); query.select('#shareCanvas') .fields({ node: true, size: true }) .exec((res) => { const canvas = res[0].node; const ctx = canvas.getContext('2d'); const dpr = wx.getSystemInfoSync().pixelRatio; canvas.width = res[0].width * dpr; canvas.height = res[0].height * dpr; ctx.scale(dpr, dpr); var img = canvas.createImage(); img.src = resDownload.tempFilePath; img.onerror = err =>{ console.log(err); }; img.onload = e => { ctx.drawImage(img, 0, 0, 360, 360); var img2 = canvas.createImage(); img2.src = "../images/universalpic_screenshot_jl_bgimage_360x360.png"; img2.onload = e => { ctx.drawImage(img2, 0, 0, 360, 360); ctx.fillStyle = main.getShareImageBackColor(); ctx.fillRect(360, 0, 240, 360); ctx.fillStyle = "#ffffff"; ctx.font = "24px"; ctx.fillText(app.globalData.userInfo.NickName, 30, 306); var today = common.formatTime(new Date(), ".", true); ctx.font = "18px"; ctx.fillText(today, 30, 335); ctx.font = "20px"; ctx.fillText("秒过学习", 390, 40); ctx.font = "44px"; ctx.fillText("勤勉接力", 390, 88); ctx.font = "20px"; ctx.fillText("见证成长", 390, 140); ctx.font = "68px"; if (!that.data.TodayTime) that.data.TodayTime = 0; ctx.fillText(that.data.TodayTime, 390, 209); ctx.font = "normal 500 68px caption"; var metrics = ctx.measureText(that.data.TodayTime.toString()); //console.log(JSON.stringify(metrics)); var h = 209; if (app.globalData.IsIOS) h = 206; ctx.font = "normal 500 32px caption"; ctx.fillText("分钟", 393 + Math.round(metrics.width), h); ctx.font = "20px"; ctx.fillText("迄今已接力", 390, 295); ctx.font = "32px"; ctx.fillText(app.globalData.TaskToday.DayNumber + "次", 390, 333); //console.log("生成前"); setTimeout(function () { //console.log("生成后1"); wx.canvasToTempFilePath({ x: 0, y: 0, width: 600, height: 360, destWidth: 600, destHeight: 360, canvas: canvas, success: function (res2) { wx.hideLoading(); //console.log("生成后2"); wx.previewImage({ current: res2.tempFilePath, // 当前显示图片的http链接 urls: [res2.tempFilePath] // 需要预览的图片http链接列表 }); main.getData("ShareMiaoguoTask?UserID=" + app.globalData.userInfo.UserID, function (data) {}); }, fail: function (e) { wx.hideLoading(); //console.log("生成错误:"+e); } }) }, 500); }; }; }); // var canvas = wx.createCanvasContext("shareCanvas", that); // canvas.setFillStyle(main.getShareImageBackColor()); // canvas.fillRect(360, 0, 600, 360); // canvas.drawImage(res.tempFilePath, 0, 0, 360, 360); // canvas.drawImage("../images/universalpic_screenshot_jl_bgimage_360x360.png", 0, 0, 360, 360); // canvas.fillStyle = "#ffffff"; // canvas.setTextBaseline('top'); // canvas.setFontSize(24); // canvas.fillText(app.globalData.userInfo.NickName, 30, 282); // var today = common.formatTime(new Date(), ".", true); // canvas.setFontSize(18); // canvas.fillText(today, 30, 315); // canvas.setFontSize(20); // canvas.fillText("秒过学习", 390, 30); // canvas.setFontSize(44); // canvas.fillText("勤勉接力", 390, 58); // canvas.setFontSize(20); // canvas.fillText("见证成长", 390, 120); // canvas.setFontSize(68); // if (!that.data.TodayTime) // that.data.TodayTime = 0; // canvas.fillText(that.data.TodayTime, 390, 148); // canvas.font = "normal 500 68px caption"; // var metrics = canvas.measureText(that.data.TodayTime.toString()); // //console.log(JSON.stringify(metrics)); // var h = 179; // if (app.globalData.IsIOS) // h = 176; // canvas.font = "normal 500 32px caption"; // canvas.fillText("分钟", 393 + Math.round(metrics.width), h); // canvas.setFontSize(20); // canvas.fillText("迄今已接力", 390, 267); // canvas.setFontSize(32); // canvas.fillText(app.globalData.TaskToday.DayNumber + "次", 390, 295); // //console.log("生成前"); // canvas.draw(1, function (n) { // //console.log("生成后1"); // wx.canvasToTempFilePath({ // x: 0, // y: 0, // width: 600, // height: 360, // destWidth: 600, // destHeight: 360, // canvasId: 'shareCanvas', // success: function (res2) { // wx.hideLoading(); // //console.log("生成后2"); // wx.previewImage({ // current: res2.tempFilePath, // 当前显示图片的http链接 // urls: [res2.tempFilePath] // 需要预览的图片http链接列表 // }); // main.getData("ShareMiaoguoTask?UserID=" + app.globalData.userInfo.UserID, function (data) {}); // }, // fail: function (e) { // wx.hideLoading(); // //console.log("生成错误:"+e); // } // }) // }); } else { wx.hideLoading(); } }, fail: function (e) { wx.hideLoading(); } }); }, saveCardType: function (event) { var that = this; var foldertype = event.currentTarget.dataset.foldertype; var url = 'UpdateMiaoguoCardType?UserID=' + app.globalData.userInfo.UserID; url += "&CardType=-1"; url += "&FolderType=" + foldertype; url += "&ID=" + TaskList[0].MiaoguoCardID; main.getData(url, function (data) { TaskList.splice(0, 1); if (TaskList.length > 0) { that.setData({ TaskInfo: TaskList[0], IsShowAnswer: [0, 0], }); if (that.data.IsShowOtherButton) that.closeOtherButton(); that.closeNumberContainner(); if (foldertype == 1) { wx.showToast({ title: '不练习', mask: true, image: "../images/universalpic_exclamation_white_120x120.png", }); app.globalData.FolderList = []; } else { wx.showToast({ title: '归档成功', mask: true, image: "../images/universalpic_cupboard_white_120x120.png", }); } that.setSoundFile(3); } else { that.setFinallyResult(); } }); }, saveIsFolderPractice: function (e) { var that = this; var IsFolderPractice = that.data.IsFolderPractice == 0 ? 1 : 0; that.setData({ IsFolderPractice: IsFolderPractice, }); wx.setStorageSync('IsFolderPractice', IsFolderPractice); main.UploadUserConfig(); }, switchSound: function (e) { var that = this; var autoAudio = !that.data.IsAutoSound; that.setData({ IsAutoSound: autoAudio, }); if (autoAudio) { wx.setStorageSync('IsAutoSound', 1); wx.showModal({ title: '提醒', content: '如果题卡里有朗读和录音内容,开启后会按段落顺序逐个自动播放。界面右侧有停止按键。如不想被声音干扰,请关闭该功能。', showCancel: false, confirmText: "知道了", success(res) { }, }); } else { wx.setStorageSync('IsAutoSound', 0); } main.UploadUserConfig(); }, autoAudioPlayInit: function () { var that = this; common.getStorageValue(that, "IsAutoSound", 1, function () { if (that.data.IsAutoSound == 1) { var taskInfo = that.data.TaskInfo; var field = []; var fieldNumber = 1; if (that.data.IsShowAnswer[0] == 1) fieldNumber = 2; if (that.data.IsShowAnswer[1] == 1 && taskInfo.ContentNew.Field[3].length > 0) fieldNumber = 3; if (taskInfo.ContentNew && taskInfo.ContentNew.Field && taskInfo.ContentNew.Field.length > 0) field = taskInfo.ContentNew.Field[fieldNumber]; arrAutoAudio = []; for (var i = 0; i < field.length; i++) { if (field[i].Type == "sound" || field[i].Type == "recorder") { field[i].FieldNumber = fieldNumber; arrAutoAudio.push(field[i]); } } if (arrAutoAudio.length > 0) { that.setData({ IsAutoSoundStart: true, }); that.autoAudioPlayStart(); } } }); }, autoAudioPlayStart: function () { var that = this; if (arrAutoAudio.length > 0) { var item = arrAutoAudio[0]; if (item.Type == "recorder") item.Content = item.Type; that.playSound({ currentTarget: { dataset: { content: item.Content, soundmark: item.SoundMark, fieldid: item.FieldNumber, } } }); arrAutoAudio.splice(0, 1); } }, autoAudioPlayEnd: function () { var that = this; arrAutoAudio = []; if (innerAudioContext1) { innerAudioContext1.stop(); } that.audioCtx.pause(); that.setData({ IsAutoSoundStart: false, }); }, //音频播放结束 audioBindEnded: function () { var that = this; isPlaying = false; if (arrAutoAudio.length > 0) { that.autoAudioPlayStart(); } else { that.setData({ IsAutoSoundStart: false, }); } }, audioBindError: function (err) { //console.log(err); if (innerAudioContext1 && innerAudioContext1.src) { innerAudioContext1.src = tempPlayUrlLocal; innerAudioContext1.play(); } }, playSound: function (e) { clearTimeout(timeoutPlayAudio); var that = this; var str = e.currentTarget.dataset.content; var url; if (str == "recorder") { url = e.currentTarget.dataset.soundmark; } else if (str.indexOf("英 [") >= 0 || str.indexOf("美 [") >= 0) { str = str.replace("英 [", "["); str = str.replace("美 [", "["); url = e.currentTarget.dataset.soundmark; } else if (e.currentTarget.dataset.soundmark && e.currentTarget.dataset.soundmark != "undefined") { var soundmark = e.currentTarget.dataset.soundmark; if (soundmark && soundmark.indexOf("http") < 0) { url = app.globalData.audioUrlBaidu; url = url.replace("[token]", app.globalData.BaiduToken); url = url.replace("[word]", soundmark); } else { url = soundmark; } } else { url = app.globalData.audioUrlBaidu; url = url.replace("[token]", app.globalData.BaiduToken); url = url.replace("[word]", str); } if (url.indexOf("http") > 0) url = url.substr(url.indexOf("http")); if (url.indexOf("'") > 0) url = common.ReplaceAllString(url, "'", ""); url = url.replace("http://", "https://"); url = encodeURI(url); if (!isPlaying || tempPlayUrl == "" || url != tempPlayUrl) { isPlaying = true; timeoutPlayAudio = setTimeout(function () { isPlaying = false; }, 60000); wx.showLoading({ title: '音频下载中', mask: true, }); setTimeout(function () { wx.hideLoading(); }, 30000); wx.downloadFile({ url: url, success(res) { wx.hideLoading(); tempPlayUrlLocal = res.tempFilePath; that.audioCtx.setSrc(res.tempFilePath); that.audioCtx.play(); tempPlayUrl = url; }, fail(err) { wx.hideLoading(); if (url.indexOf("sp0.baidu.com") > 0) { var soundmark = url.substring(url.indexOf("text=") + 5, url.indexOf("&spd")); url = app.globalData.audioUrlYoudao; url = url.replace("[word]", soundmark); tempPlayUrlLocal = url; that.audioCtx.setSrc(url); that.audioCtx.play(); tempPlayUrl = url; } } }); } else { this.audioCtx.pause(); if (innerAudioContext1) innerAudioContext1.stop(); isPlaying = false; } }, showBishunOrKaiti: function (e) { var that = this; main.downloadBishunKaitiImage( e.currentTarget.dataset.url, e.currentTarget.dataset.serverurl, e.currentTarget.dataset.type, that.data.TaskInfo.ContentNew.Field, function (fields) { that.data.TaskInfo.ContentNew.Field = fields; that.setData({ TaskInfo: that.data.TaskInfo, }); }); }, goto: function (e) { var url = e.currentTarget.dataset.url; wx.navigateTo({ url: url, }); }, getNull: function () { }, //获取导航栏高度 getBarInfo(e) { var h = e.detail.topBarHeight; h = h * 2; if (app.globalData.IsIPad) { h += 25; } this.setData({ topBarHeight: h, }) }, onShareAppMessage: function () { return { title: app.globalData.ShareTitle, path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID, imageUrl: app.globalData.ShareImage, } }, });