From 44be4489f24b295329f88025649474089ad14a69 Mon Sep 17 00:00:00 2001 From: gaohui Date: Wed, 19 Jan 2022 18:14:34 +0800 Subject: [PATCH 1/2] BUGFIX JsTimer Signed-off-by: gaohui --- .../src/main/js/default/pages/index/index.css | 2 +- .../src/main/js/default/pages/index/index.hml | 4 +- .../src/main/js/default/pages/index/index.js | 85 +++++++++++++++++-- 3 files changed, 80 insertions(+), 11 deletions(-) diff --git a/UI/JsBasicComponents/entry/src/main/js/default/pages/index/index.css b/UI/JsBasicComponents/entry/src/main/js/default/pages/index/index.css index 8b135e09e2..aea3139a3f 100644 --- a/UI/JsBasicComponents/entry/src/main/js/default/pages/index/index.css +++ b/UI/JsBasicComponents/entry/src/main/js/default/pages/index/index.css @@ -173,7 +173,7 @@ color:black; font-size: 36px; height: 90px; - width: 60%; + width: 100%; font-weight: bold; text-decoration: none; margin-top: 20px; diff --git a/UI/JsTimer/entry/src/main/js/default/pages/index/index.hml b/UI/JsTimer/entry/src/main/js/default/pages/index/index.hml index 34c2c01dee..a2dc0c4c3d 100644 --- a/UI/JsTimer/entry/src/main/js/default/pages/index/index.hml +++ b/UI/JsTimer/entry/src/main/js/default/pages/index/index.hml @@ -22,8 +22,8 @@
{{ $t('strings.countdown') }} - {{ - dataTime }} + {{ dataTime }}
diff --git a/UI/JsTimer/entry/src/main/js/default/pages/index/index.js b/UI/JsTimer/entry/src/main/js/default/pages/index/index.js index 6ebce411f5..0d6c880eea 100644 --- a/UI/JsTimer/entry/src/main/js/default/pages/index/index.js +++ b/UI/JsTimer/entry/src/main/js/default/pages/index/index.js @@ -18,23 +18,91 @@ import prompt from '@system.prompt'; import systemTime from '@ohos.systemTime'; export default { + timer: undefined, data: { - dataDateTime: '2021-8-23-12-00', + dataDateTime: '', dataTime: '00:00:00', + multiText: [["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", + "18", "19", "20", "21", "22", "23", "24"], + ["0", "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"], + ["0", "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"]], timeoutID: '0', + hour: 0, + minute: 0, + second: 0, + hourStr: '', + minuteStr: '', + secondStr: '', milliSecond: 0, time: 0 }, + onInit() { + var date = new Date() + this.dataDateTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + "-" + + date.getHours() + "-" + date.getMinutes() + }, dateTimeChange(e) { this.dataDateTime = e.year + '-' + (e.month + 1) + '-' + e.day + '-' + e.hour + '-' + e.minute; var date = new Date(e.year, e.month, e.day, e.hour, e.minute); this.time = date.getTime(); }, - timeChange(e) { - this.dataTime = e.hour + ':' + e.minute + ':' + e.second; - this.milliSecond = Number(e.hour) * 3600 * 1000 + Number(e.minute) * 60 * 1000 + Number(e.second) * 1000; + multiTextChange(e) { + this.hour = e.newValue[0] + this.minute = e.newValue[1] + this.second = e.newValue[2] + this.hourStr = this.hour + '' + this.minuteStr = this.minute + '' + this.secondStr = this.second + '' + if (this.hour < 10) { + this.hourStr = '0' + this.hour + } + if (this.minute < 10) { + this.minuteStr = '0' + this.minute + } + if (this.second < 10) { + this.secondStr = '0' + this.second + } + this.dataTime = this.hourStr + ':' + this.minuteStr + ':' + this.secondStr; + this.milliSecond = this.hour * 3600 * 1000 + this.minute * 60 * 1000 + + this.second * 1000; + }, + updateTime: function () { + var hper = 60 * 60 * 1000 + var mper = 60 * 1000 + var ts = this.milliSecond + this.hour = parseInt(ts / hper) + this.hourStr = this.hour + '' + if (ts / hper < 10) { + this.hourStr = '0' + this.hour + } + ts = ts - this.hour * hper + this.minute = parseInt(ts / mper) + this.minuteStr = this.minute + '' + if (ts / mper < 10) { + this.minuteStr = '0' + this.minute + } + ts = ts - this.minute * mper + this.second = parseInt(ts / 1000) + this.secondStr = this.second + '' + if (ts / 1000 < 10) { + this.secondStr = '0' + this.second + } + this.dataTime = this.hourStr + ':' + this.minuteStr + ':' + this.secondStr; + if (this.milliSecond > 0) { + this.milliSecond = this.milliSecond - 1000 + } + if (this.hour == 0 && this.minute == 0 && this.second == 0) { + clearInterval(this.timer) + } }, setTimer() { + this.timer = setInterval(this.updateTime, 1000) prompt.showToast({ message: this.$t('strings.success'), }); @@ -44,9 +112,10 @@ export default { message: message, duration: 2000 }); - }, this.milliSecond); + }, this.milliSecond + 1000); }, clearTimer() { + clearInterval(this.timer) clearTimeout(this.timeoutID); prompt.showToast({ message: this.$t('strings.failure'), @@ -55,9 +124,9 @@ export default { }, setTime() { systemTime.setTime(this.time) - .then((value) => { - console.log(`success to systemTime.setTime: ${value}`); - }).catch((err) => { + .then((value) => { + console.log(`success to systemTime.setTime: ${value}`); + }).catch((err) => { console.error(`failed to systemTime.setTime because ${err.message}`); }); } -- Gitee From 5504c8f592966436715d0c577fde6a3e53feb8a6 Mon Sep 17 00:00:00 2001 From: gaohui Date: Wed, 19 Jan 2022 18:25:09 +0800 Subject: [PATCH 2/2] BUGFIX JsTimer Signed-off-by: gaohui --- UI/JsTimer/entry/src/main/js/default/pages/index/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UI/JsTimer/entry/src/main/js/default/pages/index/index.js b/UI/JsTimer/entry/src/main/js/default/pages/index/index.js index 0d6c880eea..fe275f595b 100644 --- a/UI/JsTimer/entry/src/main/js/default/pages/index/index.js +++ b/UI/JsTimer/entry/src/main/js/default/pages/index/index.js @@ -115,7 +115,7 @@ export default { }, this.milliSecond + 1000); }, clearTimer() { - clearInterval(this.timer) + clearInterval(this.timer) clearTimeout(this.timeoutID); prompt.showToast({ message: this.$t('strings.failure'), -- Gitee