优化性能,有节假日的可翻页可点选带农历的日历

此版本构建日历的思路为计算日历表格第一天(左上角第一格)的时间戳,以数组的形式依次排列日期,通过开屏时和月份切换时给当月农历和日期赋值,达到减少计算量的目的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?xml version="1.0" encoding="utf-8"?>
<Lockscreen version="1" frameRate="60" displayDesktop="true" screenWidth="1080">
	<!-- 年、月、日、星期初始化赋值 -->
	<Var name="datetime_year" expression="#year" const="true"/>
	<Var name="datetime_month" expression="#month+1" const="true"/>
	<Var name="datetime_day" expression="#date" const="true"/>
	<Var name="datetime_day1" expression="#date" const="true"/>
	<Var name="datetime_week" expression="#day_of_week" const="true"/>
 
	<!-- 初始化给日历赋值 -->
	<Var name="datetime_d" type="string[]" size="42" const="true"/>
	<Var name="datetime_M" type="string[]" size="42" const="true"/>
	<Var name="datetime_e" type="string[]" size="42" const="true"/>
	<Var name="datetime_t" type="string[]" size="42" const="true"/>
	<Var name="datetime_N" type="string[]" size="42" const="true"/>
	<Var name="datetime_c" type="string[]" size="42" const="true"/>
	<Var name="lunar_festival" type="string[]" size="42" const="true"/>
	<Var name="lunar_format" type="string[]" size="42" const="true"/>
 
	<Var  expression="len(@datetime_d[0])" threshold="0" >
		<Trigger>
			<!-- 判断每月第一天是周几 -->
			<VariableCommand name="day_week" expression="ifelse(#datetime_week+(1-#datetime_day1)%7{=0,#datetime_week+(1-#date)%7+7,#datetime_week+(1-#date)%7)"/>
			<!-- 判断当月最大天数 -->
			<VariableCommand name="month_max_day" expression="ifelse(#datetime_month==1||#datetime_month==3||#datetime_month==5||#datetime_month==7||#datetime_month==8||#datetime_month==10||#datetime_month==12,31,#datetime_month==4||#datetime_month==6||#datetime_month==9||#datetime_month==11,30,(#datetime_month==2)*#leap_year,29,28)" />
			<!-- 上个月最大天数 -->
			<VariableCommand name="last_month_max_day" expression="ifelse(#datetime_month==5||#datetime_month==7||#datetime_month==10||#datetime_month==12,30,#datetime_month==1||#datetime_month==2||#datetime_month==4||#datetime_month==6||#datetime_month==8||#datetime_month==9||#datetime_month==11,31,(#datetime_month==3)*#leap_year,29,28)" />
			<!-- 判断是否闰年 -->
			<VariableCommand name="leap_year" expression="#datetime_year%4==0*(#datetime_year%100!=0||#datetime_year%400==0)"/>
			<VariableCommand name="datetime_format" expression="#time_sys+(#datetime_go-#day_week+2-#date)*86400000)" />
			<LoopCommand count="42" indexName="LunarNum">
				<VariableCommand name="datetime_d" type="string[]" index="#LunarNum" expression="formatDate('d',#datetime_format+#LunarNum*86400000)" />
				<VariableCommand name="datetime_M" type="string[]" index="#LunarNum" expression="formatDate('M',#datetime_format+#LunarNum*86400000)" />
				<VariableCommand name="datetime_e" type="string[]" index="#LunarNum" expression="formatDate('e',#datetime_format+#LunarNum*86400000)" />
				<VariableCommand name="datetime_t" type="string[]" index="#LunarNum" expression="formatDate('t',#datetime_format+#LunarNum*86400000)" />
				<VariableCommand name="datetime_N" type="string[]" index="#LunarNum" expression="formatDate('N',#datetime_format+#LunarNum*86400000)" />
				<VariableCommand name="lunar_format" type="string[]" index="#LunarNum" expression="ifelse(len(@datetime_t[#LunarNum])!=0,'t',eqs(@datetime_e[#LunarNum],'初一'),'N月','e')" />
				<VariableCommand name="lunar_festival" type="string[]" index="#LunarNum" expression="ifelse(
					eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'1'),'元旦节',
					eqs(@datetime_d[#LunarNum],'14')*eqs(@datetime_M[#LunarNum],'2'),'情人节',
					eqs(@datetime_d[#LunarNum],'8')*eqs(@datetime_M[#LunarNum],'3'),'妇女节',
					eqs(@datetime_d[#LunarNum],'12')*eqs(@datetime_M[#LunarNum],'3'),'植树节',
					eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'4'),'愚人节',
					eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'5'),'劳动节',
					eqs(@datetime_d[#LunarNum],'4')*eqs(@datetime_M[#LunarNum],'5'),'青年节',
					eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'6'),'儿童节',
					eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'7'),'建党节',
					eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'8'),'建军节',
					eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'9'),'开学日',
					eqs(@datetime_d[#LunarNum],'10')*eqs(@datetime_M[#LunarNum],'9'),'教师节',
					eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'10'),'国庆节',
					eqs(@datetime_d[#LunarNum],'11')*eqs(@datetime_M[#LunarNum],'11'),'光棍节',
					eqs(@datetime_d[#LunarNum],'31')*eqs(@datetime_M[#LunarNum],'10'),'万圣节',
					eqs(@datetime_d[#LunarNum],'24')*eqs(@datetime_M[#LunarNum],'12'),'平安夜',
					eqs(@datetime_d[#LunarNum],'25')*eqs(@datetime_M[#LunarNum],'12'),'圣诞节',
					eqs(@datetime_e[#LunarNum],'初一')*eqs(@datetime_N[#LunarNum],'正'),'春节',
					eqs(@datetime_e[#LunarNum],'十五')*eqs(@datetime_N[#LunarNum],'正'),'元宵节',
					eqs(@datetime_e[#LunarNum],'初二')*eqs(@datetime_N[#LunarNum],'二'),'龙抬头',
					eqs(@datetime_e[#LunarNum],'初五')*eqs(@datetime_N[#LunarNum],'五'),'端午节',
					eqs(@datetime_e[#LunarNum],'初七')*eqs(@datetime_N[#LunarNum],'七'),'七夕节',
					eqs(@datetime_e[#LunarNum],'十五')*eqs(@datetime_N[#LunarNum],'七'),'中元节',
					eqs(@datetime_e[#LunarNum],'十五')*eqs(@datetime_N[#LunarNum],'八'),'中秋节',
					eqs(@datetime_e[#LunarNum],'初九')*eqs(@datetime_N[#LunarNum],'九'),'重阳节',
					eqs(@datetime_e[#LunarNum],'初八')*eqs(@datetime_N[#LunarNum],'腊'),'腊八节',
					eqs(@datetime_e[#LunarNum],'廿三')*eqs(@datetime_N[#LunarNum],'腊'),'小年',
					eqs(@datetime_e[#LunarNum],'三十')*eqs(@datetime_N[#LunarNum],'腊'),'除夕',
					#LunarNum==ifelse(#datetime_week==1,7,14)**eqs(@datetime_M[#LunarNum],'5'),'母情节',
					#LunarNum==ifelse(#datetime_week==1,14,21)**eqs(@datetime_M[#LunarNum],'6'),'父亲节','')" />
					<VariableCommand name="datetime_c" type="string[]" index="#LunarNum" expression="ifelse(len(@lunar_festival[#LunarNum])!=0,@lunar_festival[#LunarNum],formatDate(@lunar_format[#LunarNum],#datetime_format+#LunarNum*86400000)) " />
				</LoopCommand>
			</Trigger>
		</Var>
		<!-- datetime_go变量每变化一次农历时间重现赋值,达到日历翻页给日历重新赋值的目的 -->
		<Var  expression="#datetime_go" threshold="1">
			<Trigger>
				<!-- 判断每月第一天是周几 -->
				<VariableCommand name="day_week" expression="ifelse(#datetime_week+(1-#datetime_day1)%7{=0,#datetime_week+(1-#date)%7+7,#datetime_week+(1-#date)%7)"/>
				<!-- 判断当月最大天数 -->
				<VariableCommand name="month_max_day" expression="ifelse(#datetime_month==1||#datetime_month==3||#datetime_month==5||#datetime_month==7||#datetime_month==8||#datetime_month==10||#datetime_month==12,31,#datetime_month==4||#datetime_month==6||#datetime_month==9||#datetime_month==11,30,(#datetime_month==2)*#leap_year,29,28)" />
				<!-- 上个月最大天数 -->
				<VariableCommand name="last_month_max_day" expression="ifelse(#datetime_month==5||#datetime_month==7||#datetime_month==10||#datetime_month==12,30,#datetime_month==1||#datetime_month==2||#datetime_month==4||#datetime_month==6||#datetime_month==8||#datetime_month==9||#datetime_month==11,31,(#datetime_month==3)*#leap_year,29,28)" />
				<!-- 判断是否闰年 -->
				<VariableCommand name="leap_year" expression="#datetime_year%4==0*(#datetime_year%100!=0||#datetime_year%400==0)"/>
				<VariableCommand name="datetime_format" expression="#time_sys+(#datetime_go-#day_week+2-#date)*86400000)" />
				<LoopCommand count="42" indexName="LunarNum">
					<VariableCommand name="datetime_d" type="string[]" index="#LunarNum" expression="formatDate('d',#datetime_format+#LunarNum*86400000)" />
					<VariableCommand name="datetime_M" type="string[]" index="#LunarNum" expression="formatDate('M',#datetime_format+#LunarNum*86400000)" />
					<VariableCommand name="datetime_e" type="string[]" index="#LunarNum" expression="formatDate('e',#datetime_format+#LunarNum*86400000)" />
					<VariableCommand name="datetime_t" type="string[]" index="#LunarNum" expression="formatDate('t',#datetime_format+#LunarNum*86400000)" />
					<VariableCommand name="datetime_N" type="string[]" index="#LunarNum" expression="formatDate('N',#datetime_format+#LunarNum*86400000)" />
					<VariableCommand name="lunar_format" type="string[]" index="#LunarNum" expression="ifelse(eqs(@datetime_e[#LunarNum],'初一'),'N月','e')" />
					<VariableCommand name="lunar_festival" type="string[]" index="#LunarNum" expression="ifelse(
						eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'1'),'元旦节',
						eqs(@datetime_d[#LunarNum],'14')*eqs(@datetime_M[#LunarNum],'2'),'情人节',
						eqs(@datetime_d[#LunarNum],'8')*eqs(@datetime_M[#LunarNum],'3'),'妇女节',
						eqs(@datetime_d[#LunarNum],'12')*eqs(@datetime_M[#LunarNum],'3'),'植树节',
						eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'4'),'愚人节',
						eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'5'),'劳动节',
						eqs(@datetime_d[#LunarNum],'4')*eqs(@datetime_M[#LunarNum],'5'),'青年节',
						eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'6'),'儿童节',
						eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'7'),'建党节',
						eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'8'),'建军节',
						eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'9'),'开学日',
						eqs(@datetime_d[#LunarNum],'10')*eqs(@datetime_M[#LunarNum],'9'),'教师节',
						eqs(@datetime_d[#LunarNum],'1')*eqs(@datetime_M[#LunarNum],'10'),'国庆节',
						eqs(@datetime_d[#LunarNum],'11')*eqs(@datetime_M[#LunarNum],'11'),'光棍节',
						eqs(@datetime_d[#LunarNum],'31')*eqs(@datetime_M[#LunarNum],'10'),'万圣节',
						eqs(@datetime_d[#LunarNum],'24')*eqs(@datetime_M[#LunarNum],'12'),'平安夜',
						eqs(@datetime_d[#LunarNum],'25')*eqs(@datetime_M[#LunarNum],'12'),'圣诞节',
						eqs(@datetime_e[#LunarNum],'初一')*eqs(@datetime_N[#LunarNum],'正'),'春节',
						eqs(@datetime_e[#LunarNum],'十五')*eqs(@datetime_N[#LunarNum],'正'),'元宵节',
						eqs(@datetime_e[#LunarNum],'初二')*eqs(@datetime_N[#LunarNum],'二'),'龙抬头',
						eqs(@datetime_e[#LunarNum],'初五')*eqs(@datetime_N[#LunarNum],'五'),'端午节',
						eqs(@datetime_e[#LunarNum],'初七')*eqs(@datetime_N[#LunarNum],'七'),'七夕节',
						eqs(@datetime_e[#LunarNum],'十五')*eqs(@datetime_N[#LunarNum],'七'),'中元节',
						eqs(@datetime_e[#LunarNum],'十五')*eqs(@datetime_N[#LunarNum],'八'),'中秋节',
						eqs(@datetime_e[#LunarNum],'初九')*eqs(@datetime_N[#LunarNum],'九'),'重阳节',
						eqs(@datetime_e[#LunarNum],'初八')*eqs(@datetime_N[#LunarNum],'腊'),'腊八节',
						eqs(@datetime_e[#LunarNum],'廿三')*eqs(@datetime_N[#LunarNum],'腊'),'小年',
						eqs(@datetime_e[#LunarNum],'三十')*eqs(@datetime_N[#LunarNum],'腊'),'除夕',
						#LunarNum==ifelse(#datetime_week==1,7,14)**eqs(@datetime_M[#LunarNum],'5'),'母情节',
						#LunarNum==ifelse(#datetime_week==1,14,21)**eqs(@datetime_M[#LunarNum],'6'),'父亲节','')" />
						<VariableCommand name="datetime_c" type="string[]" index="#LunarNum" expression="ifelse(len(@lunar_festival[#LunarNum])!=0,@lunar_festival[#LunarNum],formatDate(@lunar_format[#LunarNum],#datetime_format+#LunarNum*86400000)) " />
					</LoopCommand>
				</Trigger>
			</Var>
 
			<!-- 间距 -->
			<Var name="gw" expression="110"/>
			<Var name="gh" expression="140"/>
 
			<Text x="#screen_width/2-250" y="300" align="center" alignV="center" color="#ffffff" size="32"  text="上一月" alpha="250"/>
			<Text x="#screen_width/2+250" y="300" align="center" alignV="center" color="#ffffff" size="32"  text="下一月" alpha="250"/>
			<DateTime x="#screen_width/2" y="300" align="center" alignV="center" color="#ffffff" size="35" format="yyyy年M月d日" value="#time_sys+86400000*(#datetime_day-#date+#datetime_go)"/>
			<!-- 选定日期跟今天日期相差天数 -->
			<Var name="datetime_ratio"  expression="#datetime_day+#datetime_go-#date"/>
			<Text x="#screen_width/2" y="1620"  align="center" alignV="center" size="36" color="#ffffff" textExp="ifelse(#datetime_year==#year**#datetime_month==#month+1**#datetime_day==#date,'所选日期为今天','所选日期距离今天'+ifelse(#datetime_ratio}0,'还有','已过去')+abs(#datetime_ratio)+'天')"/>
 
 
 
			<!-- 上个月按钮 -->
			<Button x="#screen_width/2-250-80" y="250" w="160" h="100" >
				<Triggers>
					<Trigger action="up">
						<VariableCommand name="datetime_year" expression="ifelse(#datetime_month==1,#datetime_year-1,#datetime_year)"/>
						<VariableCommand name="datetime_month" expression="ifelse(#datetime_month==1,12,#datetime_month-1)"/>
						<VariableCommand name="month_max_day" expression="ifelse((#datetime_month==1)+(#datetime_month==3)+(#datetime_month==5)+(#datetime_month==7)+(#datetime_month==8)+(#datetime_month==10)+(#datetime_month==12),31,(#datetime_month==4)+(#datetime_month==6)+(#datetime_month==9)+(#datetime_month==11),30,(#datetime_month==2)*#leap_year,29,28)"/>
						<VariableCommand name="datetime_week" expression="ifelse((#datetime_week-#month_max_day%7){0,#datetime_week-#month_max_day%7+7,#datetime_week-#month_max_day%7)"/>
						<VariableCommand name="datetime_go" expression="#datetime_go-#last_month_max_day" />
					</Trigger>
				</Triggers>
			</Button>
 
			<!-- 返回本月 -->
			<Button x="#screen_width/2-80" y="250" w="160" h="100" >
				<Triggers>
					<Trigger action="up">
						<VariableCommand name="datetime_week" expression="#day_of_week"/>
						<VariableCommand name="datetime_year" expression="#year"/>
						<VariableCommand name="datetime_day" expression="#date"/>
						<VariableCommand name="datetime_month" expression="#month+1"/>
						<VariableCommand name="datetime_go" expression="0" />
					</Trigger>
				</Triggers>
			</Button>
 
			<!-- 下个月按钮 -->
			<Button x="#screen_width/2+250-80" y="250" w="160" h="100">
				<Triggers>
					<Trigger action="up">
						<VariableCommand name="datetime_week" expression="ifelse(#datetime_week+#month_max_day%7}7,(#datetime_week+#month_max_day%7)-7,#datetime_week+#month_max_day%7)"/>
						<VariableCommand name="datetime_year" expression="ifelse(#datetime_month==12,#datetime_year+1,#datetime_year)"/>
						<VariableCommand name="datetime_month" expression="ifelse(#datetime_month==12,1,#datetime_month+1)"/>
						<VariableCommand name="datetime_go" expression="#datetime_go+#month_max_day" />
					</Trigger>
				</Triggers>
			</Button>
 
			<Array count="7" indexName="weekNum" x="#screen_width/2-#gw*3" y="450">
				<Text textExp="substr('日一二三四五六',#weekNum,1)" size="36" x="#weekNum*#gw" color="#ffffff" align="center" />
			</Array>
			<Array count="42" indexName="datenum" x="#screen_width/2-#gw*3" y="600" >
				<!-- 当前日期背景 -->
				<Circle x="(#datenum)%7*#gw" y="int(#datenum/7)*#gh" r="40" fillColor="#ffd647" visibility="eq(#date-1+#day_week,#datenum+1)*eq(#datetime_month,#month+1)*eq(#datetime_year,#year)" />
				<!-- 选中日期背景 -->
				<Circle x="(#datenum)%7*#gw" y="int(#datenum/7)*#gh" r="41" fillColor="#ff477b"  visibility="eq(#datenum+1-#day_week+1,#datetime_day)" />
				<!-- 日期排列 -->
				<Text x="(#datenum)%7*#gw" y="int(#datenum/7)*#gh" align="center" alignV="center" size="40" color="#ffffff" alpha="ifelse(ge(#datenum,#day_week-1)*lt(#datenum,#day_week-1+#month_max_day),255,100)" textExp="@datetime_d[#datenum]"/>
				<!-- 农历 -->
				<Text x="(#datenum)%7*#gw" y="int(#datenum/7)*#gh+60" align="center" alignV="center" size="20" color="#ffffff" alpha="ifelse(ge(#datenum,#day_week-1)*lt(#datenum,#day_week-1+#month_max_day),255,100)" textExp="@datetime_c[#datenum])"/>
				<!-- 点选按钮 -->
				<Button x="(#datenum)%7*#gw" y="int(#datenum/7)*#gh" w="100" h="100" align="center" alignV="center" >
					<Triggers>
						<Trigger action="up">
							<VariableCommand name="datetime_day" expression="#datenum + 1-#day_week+1"  />
						</Trigger>
					</Triggers>
				</Button>
			</Array>
		</Lockscreen>

11 条评论

  • 匿名 2018年3月3日 回复

    开屏后不显示,需要先点击上一个月或者下一个月,但是可以做切换:



    如果不想出现按钮连点,日历模块频繁刷新的话可以加condition来控制

  • 匿名 2017年12月11日 回复

    开屏后不显示,需要点击下一月再点回来才会显示

  • 匿名 2017年9月20日 回复

    日历大神6666

  • 匿名 2017年6月5日 回复

    好卡,不知道怎么回事

    • dzane 2017年7月11日 回复 作者

      重新优化了下,应该不卡了

  • 匿名 2017年4月30日 回复

    卡出翔了咋办?

    • dzane 2017年7月11日 回复 作者

      重新优化了下,应该不卡了

  • 匿名 2017年4月30日 回复

    截图上的日期显示错了哦,比如23号是星期日,并不是截图上的星期六

  • 黄明江 2017年4月24日 回复

    节假日显示功能我做了,主题都很没有上线,居然被人抢先了,不开心……

  • Sunny 2017年4月23日 回复

    日历大神6666

  • 匿名 2017年4月23日 回复

    日历6666

发表评论

电子邮件地址不会被公开。

©2015-2016 zhutidasai.com. 版权所有 京ICP备16041368号-3