Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
ec-report-refactor
Project
Project
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
lihuizhen
ec-report-refactor
Commits
31232f8c
Commit
31232f8c
authored
Apr 24, 2023
by
leon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: common add weekly and diffOfNow function
parent
9b466372
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
11 deletions
+46
-11
common.js
utils/common.js
+46
-11
No files found.
utils/common.js
View file @
31232f8c
...
@@ -130,6 +130,9 @@ const install = (Vue, vm) => {
...
@@ -130,6 +130,9 @@ const install = (Vue, vm) => {
if
(
paramStr
.
includes
(
'@month'
))
{
if
(
paramStr
.
includes
(
'@month'
))
{
paramStr
=
paramStr
.
replace
(
/@month/g
,
monthly
())
paramStr
=
paramStr
.
replace
(
/@month/g
,
monthly
())
}
}
if
(
paramStr
.
includes
(
'@weekly'
))
{
paramStr
=
paramStr
.
replace
(
/@weekly/g
,
mweekly
())
}
if
(
paramStr
.
includes
(
'@day'
))
{
if
(
paramStr
.
includes
(
'@day'
))
{
paramStr
=
paramStr
.
replace
(
/@day/g
,
day
())
paramStr
=
paramStr
.
replace
(
/@day/g
,
day
())
}
}
...
@@ -140,7 +143,23 @@ const install = (Vue, vm) => {
...
@@ -140,7 +143,23 @@ const install = (Vue, vm) => {
if
(
paramStr
.
includes
(
'@yesterday'
))
{
if
(
paramStr
.
includes
(
'@yesterday'
))
{
paramStr
=
paramStr
.
replace
(
/@yesterday/g
,
yesterday
())
paramStr
=
paramStr
.
replace
(
/@yesterday/g
,
yesterday
())
}
}
// 匹配以@开头,空格 或者 " 结尾的的字符串
const
pattern
=
/
((?<
=@
)
.*
?(?=\s))
|
((?<
=@
)
.*
?(?=
"
))
/g
const
match
=
paramStr
.
match
(
pattern
)
if
(
match
?.
length
)
{
match
.
forEach
((
item
)
=>
{
if
(
item
.
includes
(
'diffOfNow'
))
{
// 取出()里面的内容
const
regex
=
/
(?<
=
\()\S
+
(?=\))
/g
const
value
=
item
.
match
(
regex
)
if
(
value
?.
length
)
{
diffOfNow
(
parseInt
(
value
[
0
]))
const
str
=
'@'
+
item
paramStr
=
paramStr
.
replace
(
str
,
diffOfNow
(
parseInt
(
value
[
0
])))
}
}
})
}
return
JSON
.
parse
(
paramStr
)
return
JSON
.
parse
(
paramStr
)
}
}
...
@@ -156,6 +175,17 @@ const install = (Vue, vm) => {
...
@@ -156,6 +175,17 @@ const install = (Vue, vm) => {
return
month
return
month
}
}
const
weekly
=
()
=>
{
let
d1
=
new
Date
();
let
d2
=
new
Date
();
d2
.
setMonth
(
0
);
d2
.
setDate
(
3
);
//3 周一为本周第一天;2 周日为本周第一天;1 周六为本周第一天
let
rq
=
d1
-
d2
;
let
days
=
Math
.
ceil
(
rq
/
(
24
*
60
*
60
*
1000
));
let
weekly
=
Math
.
ceil
(
days
/
7
);
return
weekly
+
1
;
}
const
day
=
()
=>
{
const
day
=
()
=>
{
const
date
=
new
Date
();
const
date
=
new
Date
();
const
day
=
date
.
getDate
()
<
10
?
"0"
+
date
.
getDate
()
:
date
.
getDate
();
const
day
=
date
.
getDate
()
<
10
?
"0"
+
date
.
getDate
()
:
date
.
getDate
();
...
@@ -173,8 +203,12 @@ const install = (Vue, vm) => {
...
@@ -173,8 +203,12 @@ const install = (Vue, vm) => {
}
}
const
yesterday
=
()
=>
{
const
yesterday
=
()
=>
{
return
diffOfNow
(
-
1
)
}
const
diffOfNow
=
(
diff
)
=>
{
const
date
=
new
Date
()
const
date
=
new
Date
()
const
timestamp
=
date
.
getTime
()
-
1000
*
24
*
60
*
60
const
timestamp
=
date
.
getTime
()
+
diff
*
1000
*
24
*
60
*
60
date
.
setTime
(
timestamp
)
date
.
setTime
(
timestamp
)
const
year
=
date
.
getFullYear
();
const
year
=
date
.
getFullYear
();
// 在日期格式中,月份是从0开始的,因此要加0,使用三元表达式在小于10的前面加0,以达到格式统一 如 09:11:05
// 在日期格式中,月份是从0开始的,因此要加0,使用三元表达式在小于10的前面加0,以达到格式统一 如 09:11:05
...
@@ -182,6 +216,7 @@ const install = (Vue, vm) => {
...
@@ -182,6 +216,7 @@ const install = (Vue, vm) => {
const
day
=
date
.
getDate
()
<
10
?
"0"
+
date
.
getDate
()
:
date
.
getDate
();
const
day
=
date
.
getDate
()
<
10
?
"0"
+
date
.
getDate
()
:
date
.
getDate
();
// 拼接
// 拼接
return
year
+
"-"
+
month
+
"-"
+
day
;
return
year
+
"-"
+
month
+
"-"
+
day
;
}
}
vm
.
$u
.
common
=
{
vm
.
$u
.
common
=
{
...
...
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