HarmonyOS Next 办公应用:业务页面核心功能实现(一)

HarmonyOS Next 办公应用:业务页面核心功能实现

概述

在 HarmonyOS Next 办公类应用开发中,业务页面的构建是关键环节,它需集成多种办公功能,为用户提供便捷的操作体验。下面将介绍如何构建一个包含日历、打卡、待办审批等功能的业务页面。

核心代码功能及对应代码段

1. 打卡功能

该功能用于记录用户的打卡时间,并在界面上显示首次和末次打卡时间。

typescript 复制代码
ClockIn(){
  setTimeout(()=>{
    this.getCurrentTime()
    promptAction.showToast({
      message:'打卡成功',
      duration:500
    })
  },500)
}

getCurrentTime(){
  let currentDateTime = new Date();
  let currentHour = currentDateTime.getHours();
  let currentMinute = currentDateTime.getMinutes();
  let currentSecond = currentDateTime.getSeconds();
  let currentTime = ``
  if(currentHour<=9){
    currentTime = `0${currentHour}`
  }else{
    currentTime = `${currentHour}`
  }
  if(currentMinute<=9){
    currentTime = `${currentTime}:0${currentMinute}`
  }else{
    currentTime = `${currentTime}:${currentMinute}`
  }
  if(currentSecond<=9){
    currentTime = `${currentTime}:0${currentSecond}`
  }else{
    currentTime = `${currentTime}:${currentSecond}`
  }
  let obj:ClockTimeInfo = new ClockTimeInfo(currentTime,currentHour,currentMinute,currentSecond)
  if(this.clockArr.length <=1){
    this.clockArr.push(obj)
  }else{
    this.clockArr[1] = obj
  }
}

在 ClockIn 方法中,通过 setTimeout 模拟打卡延迟,调用 getCurrentTime 方法获取当前时间并存储打卡记录,同时使用 promptAction.showToast 提示用户打卡成功。getCurrentTime 方法负责格式化当前时间,并将其存储在 clockArr 数组中。

2. 应用功能跳转

该功能实现了点击不同的应用模块,跳转到相应的页面。

typescript 复制代码
goToPage(type:number){
  let url = ''
  if(type===1){ //日历
    url = 'CalendarPage'
    this.pageInfos.pushPathByName(url,'')
    this.reminderService.addReminder({id: 1, hour: 10, minute: 30});
  }else if(type===2){ //手机打卡
    url = 'ClockInPage'
    let params = new NavInfo('手机打卡',JSON.stringify(this.clockArr))
    this.pageInfos.pushPathByName(url,params)
  }else if(type===3){ //待办审批
    url = 'ToDoPage'
    this.pageInfos.pushPathByName(url,'')
  }
}

goToPage 方法根据传入的 type 参数,判断用户点击的应用模块,然后使用 pageInfos.pushPathByName 方法跳转到相应的页面,并在跳转日历页面时添加提醒。

相关推荐
逆回6 小时前
给鸿蒙手机做一只 3D 宠物:五个把我卡住的问题
harmonyos
钉先生贾8 小时前
性能、体积与稳定性:怎样写出可信的适配结论
华为·harmonyos
笑 总不会犯错13 小时前
摆脱多端数据撕裂,鸿蒙分布式数据库同步与冲突合并
harmonyos
用户1179104883313 小时前
鸿蒙签名失败不是玄学:5 个证据点把 hapsigntool 一次排通 GitHub:swsgbl/hmharness
开源·ai编程·harmonyos
redtank200015 小时前
纯血鸿蒙小工具三件套实测:弹幕手持、爱记录与仓库管理软件
学习·华为·智能手机·harmonyos
用户86194177207411 天前
uni-app 的蓝牙 API 在鸿蒙上不生效?我写了个兼容层,让老代码零改动跑起来
harmonyos
HarmonyOS_SDK1 天前
【HarmonyOS SDK Skills】挂载 Agent Skill,轻松跑通鸿蒙应用广告变现
harmonyos
闫东阳LordGalaxy1 天前
给小艺装上数学能力:数易 App 接入智能体 FunctionComponent 与 A2A 双通路实战
harmonyos
Dream-Y.ocean1 天前
鸿蒙PC平台逻控 PLC 编辑器适配实战:基于 Electron 壳方案的纯 JavaScript 梯形图编程与仿真引擎开发
javascript·编辑器·harmonyos
OH_TPC2 天前
HarmonyOS APP开发---"好物清单"购物清单App,需要用到这个库
harmonyos