HarmonyOS ArkTS 中DatePicker先择时间 路由跳转并传值到其它页

news/2024/7/21 11:20:55 标签: harmonyos, java, 华为, ArkTS

效果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

代码

代码里有TextTimerController 这一种例用方法较怪,Text ,Button Datepicker 的使用。
import router from '@ohos.router’则是引入路由模块。


import router from '@ohos.router'
@Entry
@Component
struct TextnewClock {
  textTimerController: TextTimerController = new TextTimerController()
  @State format: string = 'mm:ss.SS'
  @State value: string =''
  @State isLunar: boolean = false
  private selectedDate: Date = new Date('2021-08-08')
  @State getDate:string=""
  build() {
    Column() {


      TextTimer({ isCountDown: true, count: 30000, controller: this.textTimerController })
        .format(this.format)
        .fontColor(Color.Black)
        .fontSize(50)
        .onTimer((utc: number, elapsedTime: number) => {
          this.value=elapsedTime.toString()
          console.info('textTimer notCountDown utc is:' + utc + ', elapsedTime: ' + elapsedTime)
        })
      Row() {
        Button("开始").onClick(() => {
          this.textTimerController.start()
        })
        Button("停止").onClick(() => {
          this.textTimerController.pause()
        })
        Button("重置").onClick(() => {
          this.textTimerController.reset()
        })

      }
      TextInput({text: this.value,placeholder:'时间'}).backgroundColor('#fff').type(InputType.Normal).onChange(value=>{

      })

      Button('跳转'+ this.value, { type: ButtonType.Capsule, stateEffect: true }).backgroundColor(0x317aff).width(200).onClick(()=>{
        router.pushUrl({
          url:"pages/TimePage",
          params:{
            params: this.value
          }
        })
      })


      TextInput({text:  this.getDate,placeholder:'时间'}).backgroundColor('#fff').type(InputType.Normal).onChange(value=>{

      })
      Button('跳转'+  this.getDate, { type: ButtonType.Capsule, stateEffect: true }).backgroundColor(0x317aff).width(200).onClick(()=>{
        router.pushUrl({
          url:"pages/TimePage",
          params:{
            params: this.getDate
          }
        })
      })
      DatePicker({
        start: new Date('1970-1-1'),
        end: new Date('2100-1-1'),
        selected: this.selectedDate
      })
        .lunar(this.isLunar)
        .onChange((value: DatePickerResult) => {
          this.selectedDate.setFullYear(value.year, value.month, value.day)
          console.info('select current date is: ' + JSON.stringify(value))
          this.getDate= value.year.toString()+"-"+ value.month.toString()+"-"+value.day.toString()
        })
    }.justifyContent(FlexAlign.Center).width('100%').height('100%')
  }
}

跳转的页TimePage, private content:string =router.getParams()?.[“params”]这一段是获取传过来的参数。

import router from '@ohos.router'
@Entry
@Component
struct TimePage {

  private  content:string =router.getParams()?.["params"]
  build() {
    Row() {
      Column() {
        Text(this.content)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
      }
      .width('100%')
    }
    .height('100%')
  }
}

http://www.niftyadmin.cn/n/5278252.html

相关文章

Guava自加载缓存LoadingCache使用指南

第1章:引言 大家好,我是小黑,今天我们来聊聊缓存。在Java世界里,高效的缓存机制对于提升应用性能、降低数据库负担至关重要。想象一下,如果每次数据请求都要跑到数据库里取,那服务器岂不是要累趴了&#x…

【深度学习】注意力机制(七)Agent Attention

本文介绍Agent Attention注意力机制,Transformer中的Attention模块可以提取全局语义信息,但是计算量太大,Agent Attention是一种计算非常有效的Attention模块。 论文:Agent Attention: On the Integration of Softmax and Linear…

利用SQL 来重启计算机

服务器(windows)的远程出错无法连接, SQL端口开放, 利用SQL语句来重启计算机,调用外部命令 EXEC master..xp_cmdshell shutdown -r -t 0 如果SQL Server 阻止了对组件 xp_cmdshell 的 过程 sys.xp_cmdshell 的访问 问题: SQL Server 阻止了对组件 xp_cmdshell 的…

Lucene

目录 1. Lucene概述 1.1 什么是Lucene 1.2 Lucene的原理 2. Lucene的使用 2.1 准备 2.2 生成索引 2.3 全文检索 2.4 多Field检索 2.5 中文分词器 2.6 停用词 2.7 是否索引,是否储存 1. Lucene概述 1.1 什么是Lucene Lucene是一个全文搜索框架,而不是应用…

R语言【base】——inherits判断R对象是否继承某类

Package base version 4.3.2 inherits(x, what, which FALSE) 参数【x】:一个R语言对象。 参数【what】:命名类的字符向量。也可以是带有 nameOfClass() 方法的非字符 R 对象。 参数【which】:影响返回值的逻辑值。 inherits 表示其第一…

LeetCode2828. Check if a String Is an Acronym of Words

文章目录 一、题目二、题解 一、题目 Given an array of strings words and a string s, determine if s is an acronym of words. The string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in o…

制造行业定制软件解决方案——工业信息采集平台

摘要:针对目前企业在线检测数据信号种类繁多,缺乏统一监控人员和及时处置措施等问题。蓝鹏测控开发针对企业工业生产的在线数据的集中采集分析平台,通过该工业信息采集平台可将企业日常各种仪表设备能够得到数据进行集中分析处理存储&#xf…

mysql:查看由于客户端未正确关闭连接而中止的连接数

https://dev.mysql.com/doc/refman/8.2/en/server-status-variables.html#statvar_Aborted_clients 执行命令show global status like Aborted_clients;查看由于客户端未正确关闭连接而中止的连接数。 例如: