Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
xqz
/
dianDemo
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
b531092f
authored
2020-02-15 19:44:25 +0800
by
宋楠
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
readme
1 parent
7721bb62
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
45 deletions
README.md
src/filters/filter.js
src/filters/index.js
README.md
View file @
b531092
...
...
@@ -4,7 +4,7 @@
[
demo
](
https://solui.cn/vue-h5-template/#/
)
建议手机端查看
#### 介绍
[
关于项目介绍
](
https://
segmentfault.com/a/1190000019275330
)
[
关于项目介绍
](
https://
juejin.im/post/5cfefc73f265da1bba58f9f7
)
-
Vue-cli4
-
VantUI组件按需加载
...
...
src/filters/filter.js
View file @
b531092
/**
*格式化时间
*yyyy-MM-dd hh:mm:ss
*/
export
function
formatDate
(
time
,
fmt
)
{
if
(
time
===
undefined
||
''
)
{
return
}
const
date
=
new
Date
(
time
)
if
(
/
(
y+
)
/
.
test
(
fmt
))
{
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
date
.
getFullYear
()
+
''
).
substr
(
4
-
RegExp
.
$1
.
length
))
}
const
o
=
{
'M+'
:
date
.
getMonth
()
+
1
,
'd+'
:
date
.
getDate
(),
'h+'
:
date
.
getHours
(),
'm+'
:
date
.
getMinutes
(),
's+'
:
date
.
getSeconds
()
}
for
(
const
k
in
o
)
{
if
(
new
RegExp
(
`(
${
k
}
)`
).
test
(
fmt
))
{
const
str
=
o
[
k
]
+
''
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
RegExp
.
$1
.
length
===
1
?
str
:
padLeftZero
(
str
))
}
}
return
fmt
}
function
padLeftZero
(
str
)
{
return
(
'00'
+
str
).
substr
(
str
.
length
)
}
/*
* 隐藏用户手机号中间四位
*/
export
function
hidePhone
(
phone
)
{
return
phone
.
replace
(
/
(\d{3})\d{4}(\d{4})
/
,
'$1****$2'
)
}
/**
*格式化时间
*yyyy-MM-dd hh:mm:ss
*/
export
function
formatDate
(
time
,
fmt
)
{
if
(
time
===
undefined
||
''
)
{
return
}
const
date
=
new
Date
(
time
)
if
(
/
(
y+
)
/
.
test
(
fmt
))
{
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
date
.
getFullYear
()
+
''
).
substr
(
4
-
RegExp
.
$1
.
length
))
}
const
o
=
{
'M+'
:
date
.
getMonth
()
+
1
,
'd+'
:
date
.
getDate
(),
'h+'
:
date
.
getHours
(),
'm+'
:
date
.
getMinutes
(),
's+'
:
date
.
getSeconds
()
}
for
(
const
k
in
o
)
{
if
(
new
RegExp
(
`(
${
k
}
)`
).
test
(
fmt
))
{
const
str
=
o
[
k
]
+
''
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
RegExp
.
$1
.
length
===
1
?
str
:
padLeftZero
(
str
))
}
}
return
fmt
}
function
padLeftZero
(
str
)
{
return
(
'00'
+
str
).
substr
(
str
.
length
)
}
/*
* 隐藏用户手机号中间四位
*/
export
function
hidePhone
(
phone
)
{
return
phone
.
replace
(
/
(\d{3})\d{4}(\d{4})
/
,
'$1****$2'
)
}
...
...
src/filters/index.js
View file @
b531092
import
Vue
from
'vue'
import
*
as
filter
from
'./filter'
Object
.
keys
(
filter
).
forEach
(
k
=>
Vue
.
filter
(
k
,
filter
[
k
]))
Vue
.
prototype
.
$formatDate
=
Vue
.
filter
(
'formatDate'
)
Vue
.
prototype
.
$hidePhone
=
Vue
.
filter
(
'hidePhone'
)
import
Vue
from
'vue'
import
*
as
filter
from
'./filter'
Object
.
keys
(
filter
).
forEach
(
k
=>
Vue
.
filter
(
k
,
filter
[
k
]))
Vue
.
prototype
.
$formatDate
=
Vue
.
filter
(
'formatDate'
)
Vue
.
prototype
.
$hidePhone
=
Vue
.
filter
(
'hidePhone'
)
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment