Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
aace64f0
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
aace64f0
编写于
8月 01, 2023
作者:
M
mehaotian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 修复日历示例在低端机上卡顿的问题
上级
0abbee84
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
28 deletion
+43
-28
pages/template/calendar/calendar.uts
pages/template/calendar/calendar.uts
+33
-21
pages/template/calendar/calendar.uvue
pages/template/calendar/calendar.uvue
+4
-3
pages/template/calendar/index.uts
pages/template/calendar/index.uts
+6
-4
未找到文件。
pages/template/calendar/calendar.uts
浏览文件 @
aace64f0
...
...
@@ -43,8 +43,8 @@ const lunarYears = [
0x0d520, 0x0daa0, 0x16aa6, 0x056d0, 0x04ae0, 0x0a9d4, 0x0a2d0, 0x0d150, 0x0f252, 0x0d520
]
// ['月','正','一','二','三','四','五','六','七','八','九','十','冬','腊'];
const N_STR_3 = ["\u6708","\u6b63", "\u4e8c", "\u4e09", "\u56db", "\u4e94", "\u516d", "\u4e03", "\u516b", "\u4e5d", "\u5341", "\u51ac", "\u814a"]
// ['月','正','一','二','三','四','五','六','七','八','九','十','冬','腊'];
const N_STR_3 = ["\u6708",
"\u6b63", "\u4e8c", "\u4e09", "\u56db", "\u4e94", "\u516d", "\u4e03", "\u516b", "\u4e5d", "\u5341", "\u51ac", "\u814a"]
// ['日','一','二','三','四','五','六','七','八','九','十']
const N_STR_1 = ["\u65e5", "\u4e00", "\u4e8c", "\u4e09", "\u56db", "\u4e94", "\u516d", "\u4e03", "\u516b", "\u4e5d", "\u5341"]
...
...
@@ -82,6 +82,8 @@ export type LunarInfoType = {
export class Lunar {
private lunarYearDaysMap = new Map<number, number>()
private lunarMonthDaysMap = new Map<number, number[]>()
constructor() { }
/**
* 传入农历数字月份返回汉语通俗表示法
...
...
@@ -90,10 +92,6 @@ export class Lunar {
* @eg:let cnMonth = calendar.toChinaMonth(12) ;//cnMonth='腊月'
*/
toChinaMonth(m : number, leap : boolean = false) : string { // 月 => \u6708
// if (m > 12 || m < 1) { return '' } // 若参数错误 返回-1
// let s = N_STR_3[m - 1]
// s += '\u6708'// 加上月字
// return s
return leap ? (N_STR_3[4] + N_STR_3[m] + N_STR_3[0]) : (N_STR_3[m] + N_STR_3[0]);
}
...
...
@@ -148,27 +146,43 @@ export class Lunar {
// 某年份农历各月天数
lunarMonthDays(year : number) : number[] {
let lunarYear = lunarYears[year - 1900];
let monthDays : number[] = [];
for (let i = 4; i < 16; i++) {
let monthDay = (lunarYear >> i & 0x1) != 0 ? 30 : 29;
monthDays.push(monthDay);
}
monthDays.reverse();
// 添加闰月
let leapM = this.leapMonth(year);
if (leapM > 0) monthDays.splice(leapM, 0, leapDays(year));
return monthDays;
let monthDays = this.lunarMonthDaysMap.get(year)
if (monthDays != null) {
return monthDays
}
monthDays = [];
let lunarYear = lunarYears[year - 1900];
for (let i = 15; i >= 4; i--) {
let monthDay = (lunarYear >> i & 0x1) != 0 ? 30 : 29;
monthDays.push(monthDay);
}
// 添加闰月
let leapM = this.leapMonth(year);
if (leapM > 0) monthDays.splice(leapM, 0, leapDays(year));
this.lunarMonthDaysMap.set(year, monthDays)
return monthDays;
}
// 某年农历天数
lunarYearDays(year : number) : number {
if (this.lunarYearDaysMap.has(year)) {
return this.lunarYearDaysMap.get(year)!
}
let num = 0;
this.lunarMonthDays(year).forEach(item => {
num += item;
});
this.lunarYearDaysMap.set(year, num)
return num;
}
...
...
@@ -188,8 +202,8 @@ export class Lunar {
let isLeap = moonDay.isLeap
// 计算农历日期
const IMonthCn = this.toChinaMonth(lMonth, isLeap)
const IMonthCn = this.toChinaMonth(lMonth, isLeap)
let IDayCn = lDay == 1 ? IMonthCn : this.toChinaDay(lDay)
// 是否今天
...
...
@@ -280,6 +294,4 @@ export class Lunar {
return info
}
}
\ No newline at end of file
pages/template/calendar/calendar.uvue
浏览文件 @
aace64f0
...
...
@@ -167,9 +167,10 @@
drawWeek(weeks : Array<Array<DateType>>, time : string) {
const start_time = Date.now()
const refs = this.$refs['draw-weeks'] as INode
let ctx = refs.getDrawableContext()
const width = refs.getBoundingClientRect().width
const height = refs.getBoundingClientRect().height
let ctx = refs.getDrawableContext()
const dom = refs.getBoundingClientRect()
const width = dom.width
const height = dom.height
let week_len = weeks.length
const one_width = width / weeks[0].length
const one_height = height / week_len
...
...
pages/template/calendar/index.uts
浏览文件 @
aace64f0
...
...
@@ -12,8 +12,11 @@ export type DateType = {
data ?: LunarInfoType
}
export class Calendar {
constructor() { }
export class Calendar {
private lunar:Lunar
constructor() {
this.lunar =new Lunar()
}
getDateInfo(time : string = '') : DateType {
const nowDate = this.getDate(time)
...
...
@@ -121,8 +124,7 @@ export class Calendar {
* 计算阴历日期显示
*/
getlunar(year : number, month : number, date : number) : LunarInfoType {
const lunar = new Lunar()
return lunar.solar2lunar(year, month, date)
return this.lunar.solar2lunar(year, month, date)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录