Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-3
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
office
haoban-3
Commits
80ec8766
Commit
80ec8766
authored
Aug 02, 2021
by
caoyanzhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复农历显示异常的bug
parent
8e9815f3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
62 deletions
+17
-62
index.vue
src/views/index/index.vue
+17
-62
No files found.
src/views/index/index.vue
View file @
80ec8766
...
...
@@ -72,7 +72,7 @@
<div
class=
"serve-info"
>
<div
class=
"serve-date-info"
>
<div
class=
"font-14 color-909399 p-t-10 m-b-13"
style=
"font-weight:300;"
>
{{
new
Date
().
getTime
()
|
timeStampToYm
}}
</div>
<div
class=
"font-12 color-909399"
>
农历
{{
getLunarDay
(
new
Date
().
getFullYear
(),
new
Date
().
getMonth
()
+
1
,
new
Date
().
getDate
()
)
}}
</div>
<div
class=
"font-12 color-909399"
>
农历
{{
getLunarDay
()
}}
</div>
<div
class=
"serve-date-day"
>
<div
class=
"serve-date-day_inner "
>
<div
class=
"color-fff font-26 p-t-10"
style=
"letter-spacing: 2px;"
>
{{
new
Date
().
getDate
()
}}
</div>
...
...
@@ -217,68 +217,23 @@ export default {
window
.
open
(
'https://notes.dingtalk.com/p/dy0mVP0g7lQPjz89/docs/dy0mV1QLjwErWX89'
);
},
/* eslint-disable */
getLunarDay
(
solarYear
,
solarMonth
,
solarDay
)
{
// 拷贝别人又自己调整过的获取农历日期的代码,想要原来的代码估计百度一下就有了
const
madd
=
[
0
,
31
,
59
,
90
,
120
,
151
,
181
,
212
,
243
,
273
,
304
,
334
];
// const tgString = '甲乙丙丁戊己庚辛壬癸'
// const dzString = '子丑寅卯辰巳午未申酉戌亥'
const
numString
=
'一二三四五六七八九十'
;
const
monString
=
'正二三四五六七八九十冬腊'
;
const
CalendarData
=
[
0xa4b
,
0x5164b
,
0x6a5
,
0x6d4
,
0x415b5
,
0x2b6
,
0x957
,
0x2092f
,
0x497
,
0x60c96
,
0xd4a
,
0xea5
,
0x50da9
,
0x5ad
,
0x2b6
,
0x3126e
,
0x92e
,
0x7192d
,
0xc95
,
0xd4a
,
0x61b4a
,
0xb55
,
0x56a
,
0x4155b
,
0x25d
,
0x92d
,
0x2192b
,
0xa95
,
0x71695
,
0x6ca
,
0xb55
,
0x50ab5
,
0x4da
,
0xa5b
,
0x30a57
,
0x52b
,
0x8152a
,
0xe95
,
0x6aa
,
0x615aa
,
0xab5
,
0x4b6
,
0x414ae
,
0xa57
,
0x526
,
0x31d26
,
0xd95
,
0x70b55
,
0x56a
,
0x96d
,
0x5095d
,
0x4ad
,
0xa4d
,
0x41a4d
,
0xd25
,
0x81aa5
,
0xb54
,
0xb6a
,
0x612da
,
0x95b
,
0x49b
,
0x41497
,
0xa4b
,
0xa164b
,
0x6a5
,
0x6d4
,
0x615b4
,
0xab6
,
0x957
,
0x5092f
,
0x497
,
0x64b
,
0x30d4a
,
0xea5
,
0x80d65
,
0x5ac
,
0xab6
,
0x5126d
,
0x92e
,
0xc96
,
0x41a95
,
0xd4a
,
0xda5
,
0x20b55
,
0x56a
,
0x7155b
,
0x25d
,
0x92d
,
0x5192b
,
0xa95
,
0xb4a
,
0x416aa
,
0xad5
,
0x90ab5
,
0x4ba
,
0xa5b
,
0x60a57
,
0x52b
,
0xa93
,
0x40e95
];
if
(
!
(
solarYear
<
1921
||
solarYear
>
2100
))
{
solarMonth
=
parseInt
(
solarMonth
)
>
0
?
solarMonth
-
1
:
11
;
const
timeArr
=
[
solarYear
,
solarMonth
,
solarDay
];
let
TheDate
=
timeArr
.
length
!==
3
?
new
Date
()
:
new
Date
(
timeArr
[
0
],
timeArr
[
1
],
timeArr
[
2
]);
let
total
;
let
m
;
let
n
;
let
k
;
let
isEnd
=
false
;
let
theDateYear
=
TheDate
.
getFullYear
();
total
=
(
theDateYear
-
1921
)
*
365
+
Math
.
floor
((
theDateYear
-
1921
)
/
4
)
+
madd
[
TheDate
.
getMonth
()]
+
TheDate
.
getDate
()
-
38
;
if
(
theDateYear
%
4
===
0
&&
TheDate
.
getMonth
()
>
1
)
{
total
++
;
}
for
(
m
=
0
;
;
m
++
)
{
k
=
CalendarData
[
m
]
<
0xfff
?
11
:
12
;
for
(
n
=
k
;
n
>=
0
;
n
--
)
{
if
(
total
<=
this
.
getBit
(
CalendarData
[
m
],
n
))
{
isEnd
=
true
;
break
;
}
total
=
total
-
this
.
getBit
(
CalendarData
[
m
],
n
);
}
if
(
isEnd
)
{
break
;
}
}
let
cMonth
;
let
cDay
;
// cYear,
// cYear = 1921 + m
cMonth
=
k
-
n
+
1
;
cDay
=
total
;
if
(
k
===
12
)
{
if
(
cMonth
===
Math
.
floor
(
CalendarData
[
m
]
/
0x10000
)
+
1
)
{
cMonth
=
1
-
cMonth
;
}
if
(
cMonth
>
Math
.
floor
(
CalendarData
[
m
]
/
0x10000
)
+
1
)
{
cMonth
--
;
}
}
// let run = ''
let
cDayStr
=
numString
.
charAt
(
cDay
-
1
);
/* if (cMonth < 1) {
run = '(闰)'
} */
if
(
cDay
%
10
!==
0
||
cDay
===
10
)
{
cDayStr
=
numString
.
charAt
((
cDay
-
1
)
%
10
);
}
return
cDay
===
1
?
monString
.
charAt
(
cMonth
-
1
)
+
'月初一'
:
monString
.
charAt
(
cMonth
-
1
)
+
'月'
+
(
cDay
<
11
?
'初'
:
cDay
<
20
?
'十'
:
cDay
<
30
?
'廿'
:
'三十'
)
+
cDayStr
;
// tgString.charAt((cYear - 4) % 10) + dzString.charAt((cYear - 4) % 12) + '年 ' + run + monString.charAt(cMonth - 1) + '月' +
getLunarDay
()
{
const
ones
=
'一二三四五六七八九十'
;
const
tens
=
'十廿'
;
// date格式为 "2021年六月24 下午4:59:02"
const
now
=
new
Date
().
toLocaleString
(
'zh-Hans-u-ca-chinese'
);
// 解析date得到 六月廿四 的农历格式
const
month
=
now
.
match
(
/年
(
.*
)
月/
)[
1
];
let
date
=
now
.
match
(
/月
(\d
*
)\s
/
)[
1
];
if
(
Number
(
date
)
<=
10
)
{
// 初几
date
=
`初
${
ones
.
charAt
(
date
-
1
)}
`
;
}
else
{
date
=
date
.
split
(
''
);
// 二十几 三十
date
=
date
[
1
]
==
0
?
`
${
ones
.
charAt
(
date
[
0
]
-
1
)}
十`
:
`
${
tens
.
charAt
(
date
[
0
]
-
1
)}${
ones
.
charAt
(
date
[
1
]
-
1
)}
`
;
}
},
getBit
(
m
,
n
)
{
// 也是拷贝的,不是很明白这段代码干嘛的,不过很明显是处理二进制数据的
return
29
+
((
m
>>
n
)
&
1
);
return
`
${
month
}${
date
}
`
;
},
/**
* 帮助中心跳转
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment