Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ant-design-pro-vue
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
tianzhuanghu
ant-design-pro-vue
Commits
554835f5
Unverified
Commit
554835f5
authored
Mar 14, 2019
by
Sendya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: component util fix
parent
e107eeb2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
26 deletions
+35
-26
Ellipsis.vue
src/components/Ellipsis/Ellipsis.vue
+1
-1
StringUtil.js
src/components/_util/StringUtil.js
+0
-25
util.js
src/components/_util/util.js
+34
-0
No files found.
src/components/Ellipsis/Ellipsis.vue
View file @
554835f5
<
script
>
<
script
>
import
Tooltip
from
'ant-design-vue/es/tooltip'
import
Tooltip
from
'ant-design-vue/es/tooltip'
import
{
cutStrByFullLength
,
getStrFullLength
}
from
'@/components/_util/
StringU
til'
import
{
cutStrByFullLength
,
getStrFullLength
}
from
'@/components/_util/
u
til'
/*
/*
const isSupportLineClamp = document.body.style.webkitLineClamp !== undefined;
const isSupportLineClamp = document.body.style.webkitLineClamp !== undefined;
...
...
src/components/_util/StringUtil.js
deleted
100644 → 0
View file @
e107eeb2
export
const
getStrFullLength
=
(
str
=
''
)
=>
str
.
split
(
''
).
reduce
((
pre
,
cur
)
=>
{
const
charCode
=
cur
.
charCodeAt
(
0
)
if
(
charCode
>=
0
&&
charCode
<=
128
)
{
return
pre
+
1
}
return
pre
+
2
},
0
)
export
const
cutStrByFullLength
=
(
str
=
''
,
maxLength
)
=>
{
let
showLength
=
0
return
str
.
split
(
''
).
reduce
((
pre
,
cur
)
=>
{
const
charCode
=
cur
.
charCodeAt
(
0
)
if
(
charCode
>=
0
&&
charCode
<=
128
)
{
showLength
+=
1
}
else
{
showLength
+=
2
}
if
(
showLength
<=
maxLength
)
{
return
pre
+
cur
}
return
pre
},
''
)
}
src/components/_util/util.js
View file @
554835f5
...
@@ -10,3 +10,37 @@
...
@@ -10,3 +10,37 @@
export
function
filterEmpty
(
children
=
[])
{
export
function
filterEmpty
(
children
=
[])
{
return
children
.
filter
(
c
=>
c
.
tag
||
(
c
.
text
&&
c
.
text
.
trim
()
!==
''
))
return
children
.
filter
(
c
=>
c
.
tag
||
(
c
.
text
&&
c
.
text
.
trim
()
!==
''
))
}
}
/**
* 获取字符串长度,英文字符 长度1,中文字符长度2
* @param {*} str
*/
export
const
getStrFullLength
=
(
str
=
''
)
=>
str
.
split
(
''
).
reduce
((
pre
,
cur
)
=>
{
const
charCode
=
cur
.
charCodeAt
(
0
)
if
(
charCode
>=
0
&&
charCode
<=
128
)
{
return
pre
+
1
}
return
pre
+
2
},
0
)
/**
* 截取字符串,根据 maxLength 截取后返回
* @param {*} str
* @param {*} maxLength
*/
export
const
cutStrByFullLength
=
(
str
=
''
,
maxLength
)
=>
{
let
showLength
=
0
return
str
.
split
(
''
).
reduce
((
pre
,
cur
)
=>
{
const
charCode
=
cur
.
charCodeAt
(
0
)
if
(
charCode
>=
0
&&
charCode
<=
128
)
{
showLength
+=
1
}
else
{
showLength
+=
2
}
if
(
showLength
<=
maxLength
)
{
return
pre
+
cur
}
return
pre
},
''
)
}
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