From cd98c69ff835643f518337ee9ab532885c647efb Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期五, 15 三月 2024 18:48:39 +0800 Subject: [PATCH] 合并代码 --- pages/bookServices/examination/questionSchedule/index.js | 186 ++++++++++++++++++++++++++++------------------ 1 files changed, 114 insertions(+), 72 deletions(-) diff --git a/pages/bookServices/examination/questionSchedule/index.js b/pages/bookServices/examination/questionSchedule/index.js index 04dcf5d..311ed8a 100644 --- a/pages/bookServices/examination/questionSchedule/index.js +++ b/pages/bookServices/examination/questionSchedule/index.js @@ -5,45 +5,87 @@ * 缁勪欢鐨勫睘鎬у垪琛� */ properties: { - + questionList: { + type: Array, + value: [] + }, + submitStatus: { + type: Boolean, + value: false + }, + currentIndex: { + type: Number, + value: 1 + }, + countdownTime: { + type: Number, + value: 0 + }, + answerType: { + type: String, + value: '' + } }, created() { - // if (props.answerType == 'option') { - // this.startCountdown() - this.setData({ - countdownTime: 2 * 60 * 60 * 1000 - }) - // } }, detached() { - if (this.data.countdownInterval !== null) { - clearInterval(this.data.countdownInterval) - } }, /** * 缁勪欢鐨勫垵濮嬫暟鎹� */ data: { - countdownInterval: null, // 璁℃椂鍣� - isCountdownRunning: true, // 鏄惁鍊掕鏃� - countdownTime: "", // 鏃堕棿 - showTime: '', + showTime: '', // + percentage: 0, + ready: 0 }, observers: { - 'countdownTime': function (newValue, oldValue) { - const showTime = this.formatTime(this.data.countdownTime) + 'countdownTime': function (newValue) { + const showTime = this.formatTime(this.properties.countdownTime) this.setData({ showTime: showTime }) - console.log(this.data.showTime); + }, + 'questionList': function (newValue) { + this.setData({ + ready: 0 + }) + for (let index = 0; index < newValue.length; index++) { + const item = newValue[index]; + if (this, this.isHaveAnswer(item.userAnswer)) { + this.setData({ + ready: this.data.ready + 1 + }) + } + } } }, /** * 缁勪欢鐨勬柟娉曞垪琛� */ methods: { - // 鏍煎紡鍖栨椂闂� + // 鍒ゆ柇鏄惁鏈夌敤鎴风瓟妗� + isHaveAnswer(data) { + if (typeof data == 'string') { + data = data + .replace(/<[^>]*>/g, '') + .replace(/ /g, '') + .trim() + if (data.length) { + return true + } else { + return false + } + } else { + const answer = data.find((item) => item.length > 0) + if (answer) { + return true + } else { + return false + } + } + }, + // // 鏍煎紡鍖栨椂闂� formatTime(ms) { const hours = Math.floor((ms / (1000 * 60 * 60)) % 24) .toString() @@ -56,60 +98,60 @@ .padStart(2, '0') return `${hours}:${minutes}:${seconds}` }, - // 鑾峰彇淇濆瓨鐨勫�掕鏃舵椂闂� - getSavedTime() { - const savedTime = wx.getStorageSync('countdownTime') - return savedTime ? parseInt(savedTime) : null - }, - // 淇濆瓨鍊掕鏃舵椂闂村埌鏈湴瀛樺偍 - saveTime() { - wx.setStorageSync('countdownTime', this.data.countdownTime.toString()) - }, - clearTime() { - this.setData({ - countdownTime: 2 * 60 * 60 * 1000 - }) - }, - // 鏆傚仠鎴栫户缁�掕鏃� - toggleCountdown() { - if (countdownInterval) { - clearInterval(this.data.countdownInterval) - this.setData({ - countdownInterval: null, - isCountdownRunning: false - }) - } else { - this.startCountdown() - this.setData({ - isCountdownRunning: true - }) - } - }, - // 寮�濮嬪�掕鏃� - startCountdown() { - // 濡傛灉璁℃椂鍣ㄥ凡缁忓瓨鍦紝鍏堟竻闄や箣鍓嶇殑璁℃椂鍣� - if (this.data.countdownInterval) { - clearInterval(this.data.countdownInterval) - this.setData({ - countdownInterval: null - }) - } - this.setData({ - countdownInterval: setInterval(() => { - this.setData({ - countdownTime: this.data.countdownTime - 1000 - }) - if (this.data.countdownTime <= 0) { - clearInterval(this.data.countdownInterval) - this.setData({ - countdownTime: 0, - isCountdownRunning: false - }) - } - this.saveTime() - }, 1000) - }) + // // 鑾峰彇淇濆瓨鐨勫�掕鏃舵椂闂� + // getSavedTime() { + // const savedTime = wx.getStorageSync('countdownTime') + // return savedTime ? parseInt(savedTime) : null + // }, + // // 淇濆瓨鍊掕鏃舵椂闂村埌鏈湴瀛樺偍 + // saveTime() { + // wx.setStorageSync('countdownTime', this.data.countdownTime.toString()) + // }, + // clearTime() { + // this.setData({ + // countdownTime: 2 * 60 * 60 * 1000 + // }) + // }, + // // 鏆傚仠鎴栫户缁�掕鏃� + // toggleCountdown() { + // if (countdownInterval) { + // clearInterval(this.data.countdownInterval) + // this.setData({ + // countdownInterval: null, + // isCountdownRunning: false + // }) + // } else { + // this.startCountdown() + // this.setData({ + // isCountdownRunning: true + // }) + // } + // }, + // // 寮�濮嬪�掕鏃� + // startCountdown() { + // // 濡傛灉璁℃椂鍣ㄥ凡缁忓瓨鍦紝鍏堟竻闄や箣鍓嶇殑璁℃椂鍣� + // if (this.data.countdownInterval) { + // clearInterval(this.data.countdownInterval) + // this.setData({ + // countdownInterval: null + // }) + // } + // this.setData({ + // countdownInterval: setInterval(() => { + // this.setData({ + // countdownTime: this.data.countdownTime - 1000 + // }) + // if (this.data.countdownTime <= 0) { + // clearInterval(this.data.countdownInterval) + // this.setData({ + // countdownTime: 0, + // isCountdownRunning: false + // }) + // } + // this.saveTime() + // }, 1000) + // }) - } + // } } }) -- Gitblit v1.9.1