1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import router from '@ohos.router'; 17 18export default { 19 data: { 20 defaultTime: '', 21 time: '', 22 }, 23 onInit() { 24 this.defaultTime = this.now(); 25 }, 26 onShow() { 27 if (this.$refs.pickerObj) { 28 this.$refs.pickerObj.rotation({ focus: true }); 29 } 30 }, 31 handleChange(data) { 32 this.time = this.concat(data.hour, data.minute); 33 }, 34 now() { 35 const date = new Date(); 36 const hours = date.getHours(); 37 const minutes = date.getMinutes(); 38 return this.concat(hours, minutes); 39 }, 40 41 fill(value) { 42 return (value > 9 ? '' : '0') + value; 43 }, 44 concat(hours, minutes) { 45 return `${this.fill(hours)}:${this.fill(minutes)}`; 46 }, 47 backPage() { 48 router.replaceUrl({ 49 uri: 'pages/index/index', 50 }); 51 } 52} 53