1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
| // pages/bookServices/examination/questionSchedule/questionSchedule.js
| Component({
| /**
| * 组件的属性列表
| */
| 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() {
| },
| detached() {
| },
|
| /**
| * 组件的初始数据
| */
| data: {
| showTime: '', //
| percentage: 0,
| ready: 0
| },
| observers: {
| 'countdownTime': function (newValue) {
| const showTime = this.formatTime(this.properties.countdownTime)
| this.setData({
| showTime: 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()
| .padStart(2, '0')
| const minutes = Math.floor((ms / (1000 * 60)) % 60)
| .toString()
| .padStart(2, '0')
| const seconds = Math.floor((ms / 1000) % 60)
| .toString()
| .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)
| // })
|
| // }
| }
| })
|
|