当前位置: 首页 > news >正文

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.UIAbilityContextscreenWidth: number = 480screenHeight: number = 853.33aboutToAppear() {// 获取屏幕的宽高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 - 1this.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 - 1this.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 + 1this.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

相关文章:

  • ReactNative项目构建分析与思考之RN组件化
  • Git的使用记录+坑的处理
  • VTK9.2.0+Qt5.14.0 绘制点云
  • STM32F103 CubeMX 使用USB生成键盘设备
  • 蓝桥杯刷题(十四)
  • 分布式系统面试全集通第一篇(dubbo+redis+zookeeper----分布式+CAP+BASE+分布式事务+分布式锁)
  • 千益畅行 || 共享旅游卡推广运营怎么做?
  • YOLOv8融入低照度图像增强算法---传统算法篇
  • EtherCAT转RS232网关在风电领域的应用
  • 虹科Pico汽车示波器 | 免拆诊断案例 | 2018款东风风神AX7车发动机怠速抖动、加速无力
  • Q_STATIC_ASSERT_X作用
  • 一些常见的与 Vim 相关的文件类型及其描述
  • 服务器呀服务器,一个虚拟专用服务器的使用教程
  • hadoop基本概念
  • 影视类视频片段分割
  • Asm.js的简单介绍
  • CSS 专业技巧
  • docker-consul
  • exif信息对照
  • HTML中设置input等文本框为不可操作
  • Intervention/image 图片处理扩展包的安装和使用
  • Javascript设计模式学习之Observer(观察者)模式
  • Java面向对象及其三大特征
  • Js基础——数据类型之Null和Undefined
  • laravel with 查询列表限制条数
  • Nodejs和JavaWeb协助开发
  • node和express搭建代理服务器(源码)
  • NSTimer学习笔记
  • python docx文档转html页面
  • Ruby 2.x 源代码分析:扩展 概述
  • SegmentFault 2015 Top Rank
  • Sublime Text 2/3 绑定Eclipse快捷键
  • yii2权限控制rbac之rule详细讲解
  • 关键词挖掘技术哪家强(一)基于node.js技术开发一个关键字查询工具
  • 湖南卫视:中国白领因网络偷菜成当代最寂寞的人?
  • 如何借助 NoSQL 提高 JPA 应用性能
  • 想写好前端,先练好内功
  • 写代码的正确姿势
  • 学习笔记:对象,原型和继承(1)
  • #define与typedef区别
  • (+4)2.2UML建模图
  • (ZT)薛涌:谈贫说富
  • (八)Docker网络跨主机通讯vxlan和vlan
  • (二十四)Flask之flask-session组件
  • (三)终结任务
  • (推荐)叮当——中文语音对话机器人
  • (转)树状数组
  • .NET 8.0 中有哪些新的变化?
  • .NET Core工程编译事件$(TargetDir)变量为空引发的思考
  • .NET DevOps 接入指南 | 1. GitLab 安装
  • .Net 访问电子邮箱-LumiSoft.Net,好用
  • .NET关于 跳过SSL中遇到的问题
  • .NET使用HttpClient以multipart/form-data形式post上传文件及其相关参数
  • :not(:first-child)和:not(:last-child)的用法
  • [ vulhub漏洞复现篇 ] JBOSS AS 4.x以下反序列化远程代码执行漏洞CVE-2017-7504