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

诸城网站建设多少钱正规的镇江网站建设

诸城网站建设多少钱,正规的镇江网站建设,微信里的小程序怎么打不开,做网站的要多钱背景 由于原生的时间选择器(DatePicker)不能满足UI的设计要求,比如:会自带分割线;无法调节各选择项高度等限制,虽然也无法理解TextPicker已有的属性,DatePicker上竟然没有。因此,想…

背景

由于原生的时间选择器(DatePicker)不能满足UI的设计要求,比如:会自带分割线;无法调节各选择项高度等限制,虽然也无法理解TextPicker已有的属性,DatePicker上竟然没有。因此,想着使用三个TextPicker组合成一个时间选择器,后期还可以做更多的设置,可以只选择月份和日期等。

实现效果

请添加图片描述

实现思路

  • 封装时间滑动组件,实现月份变化时,结合年份动态改变日期集合
  • 封装按钮控件,添加上点击下翻的动画和整体控件高度的变化

MyTimePicker

提供了开始时间、结束时间、选择日期属性可以给父级构件进行调用。为了统一三个TextPicker样式,封装了MyPicker公用样式,后续需要统一修改他们的样式可以直接在这里面添加。

@ComponentV2
export struct MyTimePicker {@Param Start: Date = new Date('1970-1-1')@Param End: Date = new Date('2100-12-31')@Param SelectDate: Date = new Date()@Local Years: number[] = []@Local Months: number[] = []@Local Days: number[] = []@Local YearSelectIndex: number = 0@Local MonthSelectIndex: number = 0@Local DaySelectIndex: number = 0aboutToAppear(): void {this.Years =Array.from<number, number>({ length: this.End.getFullYear() - this.Start.getFullYear() + 1 },(_, k) => this.Start.getFullYear() + k)this.Months = Array.from<number, number>({ length: 12 }, (_, k) => k + 1)this.UpdateDaysInMonth(this.SelectDate.getFullYear(), this.SelectDate.getMonth() + 1);this.SelectIndexInit();}build() {Row() {// 年份选择TextPicker({ range: this.Years.map(x => `${x}`), selected: this.YearSelectIndex }).onChange((value, index) => {const newYear = this.Years[index as number]this.SelectDate.setFullYear(newYear)this.UpdateDaysInMonth(newYear, this.SelectDate.getMonth() + 1)}).MyPicker()// 月份选择TextPicker({ range: this.Months.map(v => `${v}`), selected: this.MonthSelectIndex }).onChange((value, index) => {if (index as number || index == 0) {const newMonth = index as number + 1this.SelectDate.setMonth(newMonth - 1)this.UpdateDaysInMonth(this.SelectDate.getFullYear(), newMonth)}}).MyPicker()// 日期选择TextPicker({ range: this.Days.map(x => `${x}`), selected: this.DaySelectIndex }).onChange((value, index) => {console.info(index.toString())this.SelectDate.setDate(index as number + 1)}).MyPicker()}.height('100%').width('100%')}/*** 选择索引初始化*/private SelectIndexInit() {let yearIndex: number = this.Years.findIndex((value: number) => {return this.SelectDate.getFullYear() == value});let monthIndex: number = this.Months.findIndex((value: number) => {return this.SelectDate.getMonth() + 1 == value});let dayIndex: number = this.Days.findIndex((value: number) => {return this.SelectDate.getDate() == value});this.YearSelectIndex = yearIndex;this.MonthSelectIndex = monthIndex;this.DaySelectIndex = dayIndex;}private UpdateDaysInMonth(year: number, month: number) {const daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];if (month === 2 && this.IsLeapYear(year)) {this.Days = Array.from<number, number>({ length: 29 }, (_, i) => i + 1); // 闰年2月有29天} else {this.Days = Array.from<number, number>({ length: daysInMonth[month - 1] }, (_, i) => i + 1);}let dayIndex: number = this.Days.findIndex((value: number) => {return this.SelectDate.getDate() == value});this.DaySelectIndex = dayIndex;}/*** 判断是否是闰年* @param year* @returns*/private IsLeapYear(year: number): boolean {return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);}
}@Extend(TextPicker)
function MyPicker() {.divider(null).layoutWeight(1).selectedTextStyle({color: Color.Black,font: {weight: FontWeight.Bold}})
}

DatePickButton

为了实现组件的复用,把标题也封装进来。这里需要注意的点是,这里使用了dayjs第三方库,需要提前引用第三方库哈。

import dayjs from "dayjs"
import { MyTimePicker } from "./MyTimePicker"@ComponentV2
export struct DatePickButton {@Param Title: string = "开始时间:"@Param SelectDate: Date = new Date()@Local IsPickerShow: boolean = falsebuild() {RelativeContainer() {Text(this.Title).fontSize(20).fontWeight(FontWeight.Bold).id("Title")Button() {Row() {Text(dayjs(this.SelectDate).format("YYYY 年 MM 月 DD 日 ")).fontSize(18)Path().width(30).height(30).commands(`M${vp2px(7.5)} ${vp2px(10)} L${vp2px(15)} ${vp2px(20)} L${vp2px(22.5)} ${vp2px(10)} Z`).rotate(this.IsPickerShow ? {centerX: "50%",centerY: "50%",angle: 180} : {angle: 0})}.alignItems(VerticalAlign.Center).justifyContent(FlexAlign.SpaceBetween)}.border({color: Color.Black,width: 2,radius: 15}).backgroundColor(Color.White).type(ButtonType.Normal).height(40).margin({ left: 5 }).padding({ left: 15, right: 15 }).alignRules({left: { anchor: "Title", align: HorizontalAlign.End },center: { anchor: "Title", align: VerticalAlign.Center }}).onClick(() => {animateTo({ duration: 100 }, () => {this.IsPickerShow = !this.IsPickerShow;})}).id("PickerBtn")MyTimePicker({SelectDate: this.SelectDate}).height(this.IsPickerShow ? 150 : 0).margin({ top: 10 }).alignRules({top: { anchor: "PickerBtn", align: VerticalAlign.Bottom },left: { anchor: "Title", align: HorizontalAlign.Start },right: { anchor: "PickerBtn", align: HorizontalAlign.End }}).id("DatePicker")Rect().width("100%").height(this.IsPickerShow ? 35 : 0).radiusWidth(20).fill("#56FFEB").fillOpacity(0.5).stroke(Color.Black).strokeWidth(2).alignRules({middle: { anchor: "DatePicker", align: HorizontalAlign.Center },center: { anchor: "DatePicker", align: VerticalAlign.Center },})}.height(this.IsPickerShow ? 200 : 50).width("100%").padding({ left: 15, right: 15 })}
}

Index

在主页面中使用时间选择组件

import { DatePickButton } from './DatePickButton'@Entry
@ComponentV2
struct Index {@Local StartDate: Date = new Date()@Local EndDate: Date = new Date()build() {Column({ space: 5 }) {DatePickButton({Title: "开始时间:",SelectDate: this.StartDate})DatePickButton({Title: "结束时间:",SelectDate: this.EndDate})}.padding({ top: 20 }).height('100%').width('100%').alignItems(HorizontalAlign.Center).justifyContent(FlexAlign.Start)}
}

总结

主要实现了UI需要的没有分割线的时间选择器,而且可以有更多自定义空间,但是也会受限于TextPicker的能力范围,但是现阶段基本能满足使用需求了。希望这篇文章可以帮到你~~


文章转载自:

http://wvICjinb.wsLpk.cn
http://nemHPT6e.wsLpk.cn
http://0WG0hzFn.wsLpk.cn
http://J9dtizcd.wsLpk.cn
http://ZVYVPoxy.wsLpk.cn
http://V3X54meA.wsLpk.cn
http://lOApfkKf.wsLpk.cn
http://ML7VtlSw.wsLpk.cn
http://kufnfxdu.wsLpk.cn
http://CuqdzD4A.wsLpk.cn
http://gr9rz8wZ.wsLpk.cn
http://y2k2Npwg.wsLpk.cn
http://9btl51tD.wsLpk.cn
http://u2SQ8AE0.wsLpk.cn
http://kc1ZS2A7.wsLpk.cn
http://XxhFDVL8.wsLpk.cn
http://1YB8Lsl2.wsLpk.cn
http://WE6e7VSP.wsLpk.cn
http://tbEgIHko.wsLpk.cn
http://76H6eSeg.wsLpk.cn
http://XZsoFZmO.wsLpk.cn
http://BybPZAOb.wsLpk.cn
http://71VyANIi.wsLpk.cn
http://vIQ1ub6W.wsLpk.cn
http://TSVQOMiy.wsLpk.cn
http://J6kTBGQf.wsLpk.cn
http://GR2r0IQi.wsLpk.cn
http://y6XBpdIM.wsLpk.cn
http://S1ZQJu4B.wsLpk.cn
http://Jd5iNjXm.wsLpk.cn
http://www.dtcms.com/wzjs/764059.html

相关文章:

  • 企业网站搭建项目概述范文宜宾网站建设公司
  • 安徽建设厅考勤网站wordpress time
  • 阿里云服务器上传网站国外炫酷网站设计
  • 东莞百度网站优化郑州网站建设国奥大厦
  • 博罗网站制作公司在线教育网站流量是怎样做的
  • 自己用自己电脑做网站空间河北建筑工程学院招生信息网
  • 肯德基网站建设的目标昆明手机网站推荐
  • 网站建设合同 附件域名领域
  • 网站建设 盘网互联一二三四免费观看视频中文版在线
  • 长沙企业建站系统免费创建手机网站
  • 旅游网站建设推广关于咖啡厅网站建设的论文
  • 烟台做网站找哪家好中国电子商务网站建设
  • 网站创建快捷方式网页制作大作业
  • 简洁手机导航网站模板下载安装企业网站建设平台的功能
  • 做网站的软件page怎样提升网站流量
  • 建设网站技术公司简介带商城的wordpress
  • 网站建设需要哪些常用技术免费自助建设网站
  • soho设计网站网站的毕业设计怎么做
  • 苏州地产网站建设肇庆网站制作费用
  • 男女做网站网页模板的作用
  • 2017山亭区建设局网站做的不错的网站
  • 网站开发数据库有关合同手机app软件开发公司排名
  • 视频网站如何做推广凌河建设网站
  • 哪个网站可以做设计赚钱上海专业做网站较好的公司有哪些
  • 点读软件网站建设昆明专业建站
  • php做电商网站开题报告东台做网站的
  • 阿里云部署多个网站培训行业门户网站建设
  • 沈阳网站建设渠道公司装修效果图办公室
  • wordpress精致建站连江县住房和城乡建设局网站
  • 网站审批号学网站开发和游戏开发那个