File tree Expand file tree Collapse file tree 3 files changed +35
-26
lines changed Expand file tree Collapse file tree 3 files changed +35
-26
lines changed Original file line number Diff line number Diff line change 1
1
<script >
2
2
import Tooltip from ' ant-design-vue/es/tooltip'
3
- import { cutStrByFullLength , getStrFullLength } from ' @/components/_util/StringUtil '
3
+ import { cutStrByFullLength , getStrFullLength } from ' @/components/_util/util '
4
4
/*
5
5
const isSupportLineClamp = document.body.style.webkitLineClamp !== undefined;
6
6
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 10
10
export function filterEmpty ( children = [ ] ) {
11
11
return children . filter ( c => c . tag || ( c . text && c . text . trim ( ) !== '' ) )
12
12
}
13
+
14
+ /**
15
+ * 获取字符串长度,英文字符 长度1,中文字符长度2
16
+ * @param {* } str
17
+ */
18
+ export const getStrFullLength = ( str = '' ) =>
19
+ str . split ( '' ) . reduce ( ( pre , cur ) => {
20
+ const charCode = cur . charCodeAt ( 0 )
21
+ if ( charCode >= 0 && charCode <= 128 ) {
22
+ return pre + 1
23
+ }
24
+ return pre + 2
25
+ } , 0 )
26
+
27
+ /**
28
+ * 截取字符串,根据 maxLength 截取后返回
29
+ * @param {* } str
30
+ * @param {* } maxLength
31
+ */
32
+ export const cutStrByFullLength = ( str = '' , maxLength ) => {
33
+ let showLength = 0
34
+ return str . split ( '' ) . reduce ( ( pre , cur ) => {
35
+ const charCode = cur . charCodeAt ( 0 )
36
+ if ( charCode >= 0 && charCode <= 128 ) {
37
+ showLength += 1
38
+ } else {
39
+ showLength += 2
40
+ }
41
+ if ( showLength <= maxLength ) {
42
+ return pre + cur
43
+ }
44
+ return pre
45
+ } , '' )
46
+ }
You can’t perform that action at this time.
0 commit comments