100个openharmony开源demo:1.日历

准备用开发者手机写100个开源的demo不知道能不能实现,日拱一卒,期待蜕变。

第一个demo:日历借鉴了网上的日历算法,自己用arkts写了界面和点击事件,各位可根据此demo写自己的日历选择器等组件。

1.目录结构:

2.主页代码

import common from '@ohos.app.ability.common'
import window from '@ohos.window'

import { DataManager } from '../tools/DataManager'

@Entry
@Component
struct Index {
  currentDate: Date = new Date()
  @State dataManager: DataManager = new DataManager(
    this.currentDate.getFullYear(),
    (this.currentDate.getMonth()+1),
    this.currentDate.getDate()
  )

  private context = getContext(this) as common.UIAbilityContext

  screenWidth: number = 480
  screenHeight: number = 853.33

  aboutToAppear() {
    // 获取屏幕的宽高
    window.getLastWindow(this.context)
      .then((windowClass: window.Window) => {
        let windowProperties = windowClass.getWindowProperties()
        this.screenWidth = px2vp(windowProperties.windowRect.width)
        this.screenHeight = px2vp(windowProperties.windowRect.height)
        this.dataManager.initData()
      })
      .catch((error: Error) => {
        console.error('Failed to obtain the window size. Cause: ' + JSON.stringify(error))
      })
  }

  build() {
    Column() {
      Column() {
        Row(){
          Row(){
            Image($r('app.media.arrow_left_double'))
              .height('60%')
              .margin({left:20})
              .onClick(() => {
                this.dataManager.currentYear = this.dataManager.currentYear - 1
                this.dataManager.initData();
              })
            Image($r('app.media.arrow_left'))
              .height('52%')
              .margin({left:10})
              .onClick(() => {
                if(this.dataManager.currentMonth > 1){
                  this.dataManager.currentMonth = this.dataManager.currentMonth - 1
                }else{
                  this.dataManager.currentYear = this.dataManager.currentYear - 1
                  this.dataManager.currentMonth = 12
                }
                this.dataManager.initData();
              })
          }
          .margin({top:8})
          .width('30%')
          .height(((this.screenWidth-5*8)/7))
          .backgroundColor(0xF7F7F7)

          Text(this.dataManager.currentDateStr)
            .height('100%')
            .fontSize(((this.screenWidth-5*8)/7)/3)
            .fontWeight(FontWeight.Bold)

          Row(){
            Image($r('app.media.arrow_right'))
              .height('52%')
              .margin({right:10})
              .onClick(() => {
                if(this.dataManager.currentMonth < 12){
                  this.dataManager.currentMonth = this.dataManager.currentMonth + 1
                }else{
                  this.dataManager.currentYear = this.dataManager.currentYear + 1
                  this.dataManager.currentMonth = 1
                }
                this.dataManager.initData();
              })
            Image($r('app.media.arrow_right_double'))
              .height('60%')
              .margin({right:20})
              .onClick(() => {
                this.dataManager.currentYear = this.dataManager.currentYear + 1;
                this.dataManager.initData();
              })
          }
          .margin({top:8})
          .width('30%')
          .height(((this.screenWidth-5*8)/7))
          .backgroundColor(0xF7F7F7)
          .justifyContent(FlexAlign.End)
        }
        .width('100%')
        .height(((this.screenWidth-5*8)/7))
        .backgroundColor(0xF7F7F7)
        .justifyContent(FlexAlign.SpaceBetween)

        Grid() {
          ForEach(this.dataManager.week, (day: any) => {
            GridItem() {
              Text(day.text)
                .fontSize(((this.screenWidth-5*8)/7)/3)
                .fontColor(day.fontColor)
                .backgroundColor(day.color)
                .width('100%')
                .height('100%')
                .textAlign(TextAlign.Center)
                .borderRadius(8)
            }
            .height("100%")
          }, day => day.id)
        }
        .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr')
        .rowsTemplate('1fr')
        .backgroundColor(0xF7F7F7)
        .columnsGap(5)
        .rowsGap(5)
        .height(((this.screenWidth-5*8)/7))

        Grid() {
          ForEach(this.dataManager.days, (day: any) => {
            GridItem() {
              Column() {
                Text(day.text)
                  .fontSize(((this.screenWidth - 5 * 8) / 7) / 3)
                  .fontColor(day.fontColor)
                  .width('100%')
                  .height('42%')
                  .margin({top:8})
                  .textAlign(TextAlign.Center)
                Text(day.lunarText)
                  .fontSize(((this.screenWidth - 5 * 8) / 7) / 4)
                  .fontColor(day.lunarFontColor)
                  .width('100%')
                  .height('30%')
                  .textAlign(TextAlign.Center)
              }
              .borderRadius(day.borderRadius)
              .backgroundColor(day.color)
              .width('100%')
              .height(((this.screenWidth-5*8)/7))
            }
          }, day => day.id)
        }
        .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr')
        .rowsTemplate(this.dataManager.rowsTemplate)
        .columnsGap(5)
        .rowsGap(5)
        .height(((this.screenWidth-5*8)/7)*this.dataManager.rowsTemplateNumber)
        .margin(5)
      }
      .width('100%')
      .height('100%')
      .backgroundColor('0xFFFFFF')
      .borderRadius(8)
    }
    .width('100%')
    .height('100%')
  }
}

3.显示效果

4.卡片显示(每晚00:01刷新)

5.源码地址

九流下半/openharmony_100_projects

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/486371.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Go——map操作及原理

一.map介绍和使用 map是一种无序的基于key-value的数据结构&#xff0c;Go语言的map是引用类型&#xff0c;必须初始化才可以使用。 1. 定义 Go语言中&#xff0c;map类型语法如下&#xff1a; map[KeyType]ValueType KeyType表示键类型ValueType表示值类型 map类型的变量默认…

python总结-Linux系统使用

设置变量并输出 [rootldpbzhaonan py]$ cat var01.py str1hello str2worldprintf "${str1} ${str2} \n" printf ${str1} ${str2} \n\n就是代表换行&#xff0c;使用printf输出的话&#xff0c;没有自动换行。 不使用换行如下图显示 [rootldpbzhaonan py]$ cat var0…

C语言学习 五、一维数组与字符数组

5.1一维数组 5.1.1数组的定义 数组特点&#xff1a; 具有相同的数据类型使用过程中需要保存原始数据 C语言为了方便操作这些数据&#xff0c;提供了一种构造数据类型——数组&#xff0c;数组是指一组具有相同数据类型的数据的有序集合。 一维数组的定义格式为 数据类型 数…

虚拟+现实,刷新线上直播的“打开方式”

近年来&#xff0c;短视频和线上直播大热&#xff0c;成为我们看世界的途径之一&#xff0c;我们渐渐习惯了看屏幕里面的虚拟世界。随着AIGC技术的不断革新&#xff0c;让虚拟直播间的体验感越来越真实&#xff0c;给我们带来了不同寻常的体验。 虚实融合&#xff0c;超越传统…

将ORB-SLAM3用图像增强的方式打开

ORB-SLAM3在复杂光照环境下&#xff0c;特征提取和特征匹配的性能明显下降&#xff0c;其准确性和鲁棒性收到很大影响&#xff0c;尤其是当周围环境获取的ORB特征点数量不足时&#xff0c;位姿的估计过程无法进行&#xff0c;甚至或导致初始化和跟踪失败的情况&#xff0c;目前…

03、Lua 基本语法

Lua 基本语法 Lua 基本语法第一个 Lua 程序交互式编程脚本式编程 注释单行注释多行注释 标示符关键词全局变量 Lua 基本语法 Lua学习起来非常简单&#xff0c;我们可以创建第一个 Lua 程序&#xff01; 第一个 Lua 程序 交互式编程 Lua提供了交互式编程模式。我们可以在命令…

开始喜欢上了runnergo,JMeter out了?

RunnerGo是一款基于Go语言、国产自研的测试平台。它支持高并发、分布式性能测试。和JMeter不一样的是&#xff0c;它采用了B/S架构&#xff0c;更灵活、更方便。而且&#xff0c;除了API测试和性能测试&#xff0c;RunnerGo还加上了UI测试和项目管理等实用功能&#xff0c;让测…

蓝桥杯刷题-串的处理

串的处理 代码 s input().split() l_new [] for i in s:i list(i)new""for j in range(len(i)-1): # 遍历newi[j]if i[j].isdigit() and i[j1].isalpha(): # 在字母和数字之间添加“_”new_if i[j].isalpha() and i[j1].isdigit(): # 同上new_newi[-1]l_new.appe…

K3 计划订单投放时,将“关联物料”传递到采购和生产订单的“组部件”字段

参考K/3 WISE 中MRP计算投放过程中 销售订单自定义字段怎么携带到任务单这篇文章&#xff0c;进行优化。 在表ICMrpDestBills下增加触发器&#xff0c;代码如下 CREATE TRIGGER [dbo].[ICMrpDestBills_update]ON [dbo].[ICMrpDestBills]AFTER INSERT,UPDATE AS BEGINSET NO…

mysql 设置初始密码

link 1.首先输入以下指令&#xff1a; sudo cat /etc/mysql/debian.cnf运行截图如下&#xff1a; 2. 再输入以下指令&#xff1a; mysql -u debian-sys-maint -p//注意! //这条指令的密码输入是输入第一条指令获得的信息中的 password ZCt7QB7d8O3rFKQZ 得来。//请根据自己的实…

【CKA模拟题】如何发布一个SVC资源

题干 For this question, please set this context (In exam, diff cluster name) kubectl config use-context kubernetes-adminkubernetesYou have an existing Nginx pod named nginx-pod . Perform the following steps: Expose the nginx-pod internally within the cl…

Linux系统部署Paperless-Ngx文档管理系统结合内网穿透实现公网访问

文章目录 1. 部署Paperless-ngx2. 本地访问Paperless-ngx3. Linux安装Cpolar4. 配置公网地址5. 远程访问6. 固定Cpolar公网地址7. 固定地址访问 Paperless-ngx是一个开源的文档管理系统&#xff0c;可以将物理文档转换成可搜索的在线档案&#xff0c;从而减少纸张的使用。它内置…

二手车交易网站|基于JSP技术+ Mysql+Java+ B/S结构的二手车交易网站设计与实现(可运行源码+数据库+设计文档)

推荐阅读100套最新项目 最新ssmjava项目文档视频演示可运行源码分享 最新jspjava项目文档视频演示可运行源码分享 最新Spring Boot项目文档视频演示可运行源码分享 2024年56套包含java&#xff0c;ssm&#xff0c;springboot的平台设计与实现项目系统开发资源&#xff08;可…

一些恶意样本的流量分析学习

Trickbot Trickbot 是一种自 2016 年以来一直在感染受害者的信息窃取者和银行恶意软件。Trickbot通过恶意垃圾邮件&#xff08;malspam&#xff09;分发&#xff0c;也由其他恶意软件&#xff08;如Emotet&#xff0c;IcedID或Ursnif&#xff09;分发。 分析来自恶意垃圾邮件…

Frida 官方手册 中文版 ( 机翻+人翻 )

Frida 英文文档&#xff1a;https://frida.re/docs/home/ Frida 中文文档&#xff1a;https://pypi.org/project/frida-zhongwen-wendang/ 目的&#xff1a;给自己一个认真阅读文档的机会&#xff01;&#xff01;&#xff01; 部分名词找不到合适的中文表达&#xff0c;直接使…

计算机视觉技术:美颜SDK在直播平台的集成与优化

当下&#xff0c;美颜技术在直播平台中的应用变得愈发重要。接下俩&#xff0c;小编将深度讲解计算机视觉技术在美颜SDK集成与优化方面的应用&#xff0c;以提升直播平台的用户体验。 一、美颜技术的发展 传统的美颜功能只是简单地对图像进行柔化处理&#xff0c;而现在的美颜…

你真的会数据结构吗:堆

❀❀❀ 文章由不准备秃的大伟原创 ❀❀❀ ♪♪♪ 若有转载&#xff0c;请联系博主哦~ ♪♪♪ ❤❤❤ 致力学好编程的宝藏博主&#xff0c;代码兴国&#xff01;❤❤❤ 好久不见&#xff0c;甚是想念&#xff0c;不知道大家有没有察觉到大伟的头像和名字变了鸭 <(*&#xffe…

RK3568驱动指南|第十三篇 输入子系统-第151章 通用事件处理层read和write函数分析

瑞芯微RK3568芯片是一款定位中高端的通用型SOC&#xff0c;采用22nm制程工艺&#xff0c;搭载一颗四核Cortex-A55处理器和Mali G52 2EE 图形处理器。RK3568 支持4K 解码和 1080P 编码&#xff0c;支持SATA/PCIE/USB3.0 外围接口。RK3568内置独立NPU&#xff0c;可用于轻量级人工…

Leetcode第26题:删除有序数组中的重复项

代码实现 注意:该题要求原地删除&#xff0c;不能引入额外的连续内存空间 class Solution:def removeDuplicates(self, nums: List[int]) -> int:not_sorted_lengthlen(nums)while(not_sorted_length>0):numnums.pop(0)not_sorted_length-1if num not in nums:nums.appe…

【二十三】【算法分析与设计】三柱汉诺塔详解,计算子移动次数,正常递归计算,观察数据得出数学规律,递归图得出数学规律,将递归函数转化为递推式

目录 汉诺塔递归 汉诺塔子移动次数的计算 牛牛的汉诺塔 选择正常的递归模拟计算子移动次数 根据具体数据得出数学规律 根据递归图得出数学规律 将递归函数转化为递推式 结尾 汉诺塔递归 汉诺塔是一个经典问题&#xff0c;相传在古印度圣庙中&#xff0c;有一种被称为汉…