@aks-dev/easyui 1.0.75 → 1.0.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/DottedLine/DottedLine.tsx +66 -0
- package/lib/DottedLine/index.ts +18 -0
- package/lib/RichText/RichText.tsx +82 -0
- package/lib/RichText/index.ts +21 -0
- package/package.json +1 -1
- package/src/index.d.ts +4 -2
- package/src/index.ts +8 -10
- package/utils/index.ts +33 -5
- package/utils/lazy.ts +283 -3
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: shiguo
|
|
3
|
+
* @Date: 2022-07-12 15:30:19
|
|
4
|
+
* @LastEditors: shiguo
|
|
5
|
+
* @LastEditTime: 2022-07-12 15:33:06
|
|
6
|
+
* @FilePath: /@aks-dev/easyui/lib/DottedLine/DottedLine.tsx
|
|
7
|
+
*/
|
|
8
|
+
import React from 'react'
|
|
9
|
+
import { StyleSheet, View } from 'react-native'
|
|
10
|
+
import type { DottedLineProps } from '.'
|
|
11
|
+
export default (props: DottedLineProps) => {
|
|
12
|
+
const {
|
|
13
|
+
vertical = false,
|
|
14
|
+
dottedColor,
|
|
15
|
+
dottedCount = 200,
|
|
16
|
+
...rest
|
|
17
|
+
} = props
|
|
18
|
+
const arrs = Array.from({ length: dottedCount }, (k, v) => v)
|
|
19
|
+
return (
|
|
20
|
+
<View style={{ ...styles.container, flexDirection: vertical ? 'column' : 'row', ...rest.style as any }}>
|
|
21
|
+
{
|
|
22
|
+
arrs.map((item, index) => {
|
|
23
|
+
return <View
|
|
24
|
+
key={`dotted-${index}`}
|
|
25
|
+
style={{
|
|
26
|
+
...(vertical ? styles.dotted_vertical : styles.dotted_horizontal),
|
|
27
|
+
...(dottedColor && { backgroundColor: dottedColor })
|
|
28
|
+
}} />
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
</View>
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const styles = StyleSheet.create({
|
|
41
|
+
container: {
|
|
42
|
+
display: 'flex',
|
|
43
|
+
flexGrow: 1,
|
|
44
|
+
overflow: 'hidden',
|
|
45
|
+
flexDirection: 'row',
|
|
46
|
+
flexWrap: 'nowrap',
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
dotted_horizontal: {
|
|
50
|
+
flexGrow: 0,
|
|
51
|
+
flexShrink: 0,
|
|
52
|
+
width: 2,
|
|
53
|
+
height: 1,
|
|
54
|
+
marginRight: 2,
|
|
55
|
+
backgroundColor: '#cccccc',
|
|
56
|
+
},
|
|
57
|
+
dotted_vertical: {
|
|
58
|
+
flexGrow: 0,
|
|
59
|
+
flexShrink: 0,
|
|
60
|
+
width: 1,
|
|
61
|
+
height: 2,
|
|
62
|
+
marginBottom: 2,
|
|
63
|
+
backgroundColor: '#cccccc',
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: shiguo
|
|
3
|
+
* @Date: 2022-07-12 15:30:28
|
|
4
|
+
* @LastEditors: shiguo
|
|
5
|
+
* @LastEditTime: 2022-07-12 15:31:31
|
|
6
|
+
* @FilePath: /@aks-dev/easyui/lib/DottedLine/index.ts
|
|
7
|
+
*/
|
|
8
|
+
import React from 'react'
|
|
9
|
+
import { ViewProps } from 'react-native'
|
|
10
|
+
|
|
11
|
+
export type DottedLineProps = {
|
|
12
|
+
vertical?: boolean,
|
|
13
|
+
dottedColor?: string,
|
|
14
|
+
dottedCount?: number
|
|
15
|
+
} & ViewProps
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export declare const DottedLine: React.FC<DottedLineProps>
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: shiguo
|
|
3
|
+
* @Date: 2022-07-11 15:42:16
|
|
4
|
+
* @LastEditors: shiguo
|
|
5
|
+
* @LastEditTime: 2022-07-11 16:15:02
|
|
6
|
+
* @FilePath: /@aks-dev/easyui/lib/RichText/RichText.tsx
|
|
7
|
+
*/
|
|
8
|
+
import React from 'react'
|
|
9
|
+
import { StyleSheet, Text } from 'react-native'
|
|
10
|
+
import type { RichTextProps } from '.'
|
|
11
|
+
import { px2sp } from '../../screen/px2sp'
|
|
12
|
+
import * as utils from '../../utils/lazy'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export default (props: RichTextProps) => {
|
|
18
|
+
const { rich, richStyle, text, suffix, prefix, ...rest } = props
|
|
19
|
+
let textStr = ''
|
|
20
|
+
let richStr = ''
|
|
21
|
+
if (utils.isString(text) || utils.isNumber(text)) {
|
|
22
|
+
textStr = String(text)
|
|
23
|
+
}
|
|
24
|
+
if (utils.isString(rich) || utils.isNumber(rich)) {
|
|
25
|
+
richStr = String(rich)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let positionStart = 0
|
|
29
|
+
let positionEnd = 0
|
|
30
|
+
if (textStr?.indexOf(richStr) >= 0) {
|
|
31
|
+
positionStart = textStr.indexOf(richStr)
|
|
32
|
+
positionEnd = positionStart + richStr.length
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (prefix) {
|
|
36
|
+
return (
|
|
37
|
+
<Text style={styles.container} {...rest}>
|
|
38
|
+
<Text style={{ ...styles.defaultRich, ...richStyle }}>{richStr}</Text>
|
|
39
|
+
{textStr}
|
|
40
|
+
</Text>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if (suffix) {
|
|
47
|
+
return (
|
|
48
|
+
<Text style={styles.container} {...rest}>
|
|
49
|
+
{textStr}
|
|
50
|
+
<Text style={{ ...styles.defaultRich, ...richStyle }}>{richStr}</Text>
|
|
51
|
+
</Text>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Text style={styles.container} {...rest}>
|
|
58
|
+
{textStr.substring(0, positionStart)}
|
|
59
|
+
{
|
|
60
|
+
positionEnd > 0 &&
|
|
61
|
+
<Text style={{ ...styles.defaultRich, ...richStyle }}>{richStr}</Text>
|
|
62
|
+
}
|
|
63
|
+
{textStr.substring(positionEnd, textStr.length)}
|
|
64
|
+
</Text>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
const styles = StyleSheet.create({
|
|
73
|
+
container: {
|
|
74
|
+
color: '#333333',
|
|
75
|
+
fontSize: px2sp(14)
|
|
76
|
+
},
|
|
77
|
+
defaultRich: {
|
|
78
|
+
color: 'red',
|
|
79
|
+
fontSize: px2sp(14),
|
|
80
|
+
// fontWeight: 'bold'
|
|
81
|
+
}
|
|
82
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: shiguo
|
|
3
|
+
* @Date: 2022-07-11 15:42:08
|
|
4
|
+
* @LastEditors: shiguo
|
|
5
|
+
* @LastEditTime: 2022-07-11 16:14:12
|
|
6
|
+
* @FilePath: /@aks-dev/easyui/lib/RichText/index.ts
|
|
7
|
+
*/
|
|
8
|
+
import react from 'react'
|
|
9
|
+
import { TextStyle, TextProps } from 'react-native'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export type RichTextProps = {
|
|
13
|
+
rich?: string | number,
|
|
14
|
+
richStyle?: TextStyle,
|
|
15
|
+
text?: string | number,
|
|
16
|
+
suffix?: boolean,
|
|
17
|
+
prefix?: boolean,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export declare const RichText: react.FC<RichTextProps & TextProps>
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* @Author: shiguo
|
|
3
3
|
* @Date: 2022-04-26 11:44:22
|
|
4
4
|
* @LastEditors: shiguo
|
|
5
|
-
* @LastEditTime: 2022-
|
|
6
|
-
* @FilePath: /@aks/easyui/src/index.d.ts
|
|
5
|
+
* @LastEditTime: 2022-07-12 15:33:26
|
|
6
|
+
* @FilePath: /@aks-dev/easyui/src/index.d.ts
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
|
|
@@ -37,8 +37,10 @@ export * from '../lib/Echarts'
|
|
|
37
37
|
export * from '../screen'
|
|
38
38
|
|
|
39
39
|
|
|
40
|
+
export * from '../lib/RichText'
|
|
40
41
|
|
|
41
42
|
|
|
43
|
+
export * from '../lib/DottedLine'
|
|
42
44
|
|
|
43
45
|
/// 工具
|
|
44
46
|
import * as utils from '../utils'
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @Author: shiguo
|
|
4
4
|
* @Date: 2022-04-13 12:47:34
|
|
5
5
|
* @LastEditors: shiguo
|
|
6
|
-
* @LastEditTime: 2022-
|
|
6
|
+
* @LastEditTime: 2022-07-12 16:15:34
|
|
7
7
|
* @FilePath: /@aks-dev/easyui/src/index.ts
|
|
8
8
|
*/
|
|
9
9
|
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
export * from '../lib/Badge/Badge'
|
|
16
|
-
export type { BadgeProps } from '../lib/Badge'
|
|
16
|
+
// export type { BadgeProps } from '../lib/Badge'
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
export { Hud, showLoading, hideLoading, showToast, showAlertModal } from '../lib/Hud/Hud'
|
|
@@ -25,30 +25,28 @@ export { default as MutiPictureView } from '../lib/MutiPictureView/MutiPictureVi
|
|
|
25
25
|
export { PictureViewer } from '../lib/PictureViewer/PictureViewer'
|
|
26
26
|
|
|
27
27
|
export { default as RefreshList } from '../lib/RefreshList/RefreshList'
|
|
28
|
-
export
|
|
28
|
+
// export { RefreshListProps, RefreshState } from '../lib/RefreshList'
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
export { default as TableCell } from '../lib/TableCell/TableCell'
|
|
32
|
-
export type { TableCellProps } from '../lib/TableCell'
|
|
32
|
+
// export type { TableCellProps } from '../lib/TableCell'
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
export { default as TextInputArea } from '../lib/TextInputArea/TextInputArea'
|
|
36
|
-
export type { TextInputAreaCurrent, TextInputAreaProps } from '../lib/TextInputArea'
|
|
36
|
+
// export type { TextInputAreaCurrent, TextInputAreaProps } from '../lib/TextInputArea'
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
export { default as WithLoadingContainer } from '../lib/WithLoadingContainer/WithLoadingContainer'
|
|
40
40
|
export { WithLoadingContainerProps, Status } from '../lib/WithLoadingContainer'
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
export * from '../lib/StickHeaderView/StickHeaderView'
|
|
45
|
-
export type { StickHeaderViewProps } from '../lib/StickHeaderView'
|
|
46
|
-
|
|
43
|
+
export { default as StickHeaderView } from '../lib/StickHeaderView/StickHeaderView'
|
|
47
44
|
|
|
48
45
|
export { default as EchartsView } from '../lib/Echarts/EchartsView'
|
|
49
46
|
export { echarts } from '../lib/Echarts'
|
|
50
|
-
export type { EchartsViewProps } from '../lib/Echarts'
|
|
51
47
|
|
|
48
|
+
export { default as RichText } from '../lib/RichText/RichText'
|
|
49
|
+
export { default as DottedLine } from '../lib/DottedLine/DottedLine'
|
|
52
50
|
|
|
53
51
|
/// 全局适配
|
|
54
52
|
export * from '../screen/px2dp'
|
package/utils/index.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* @Author: shiguo
|
|
3
3
|
* @Date: 2022-04-19 10:25:43
|
|
4
4
|
* @LastEditors: shiguo
|
|
5
|
-
* @LastEditTime: 2022-07-
|
|
5
|
+
* @LastEditTime: 2022-07-11 16:09:15
|
|
6
6
|
* @FilePath: /@aks-dev/easyui/utils/index.ts
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
import { number } from 'echarts';
|
|
10
10
|
import * as rn from 'react-native'
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -14,8 +14,8 @@ import * as rn from 'react-native'
|
|
|
14
14
|
* @param {*}毫秒值
|
|
15
15
|
* @return {*}
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
type TArgs = (args: void) => void;
|
|
18
|
+
export declare const sleep: (msec?: number) => Promise<TArgs>;
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -58,4 +58,32 @@ export type SyncLoopCallBack = (item: any, index: number) => void;
|
|
|
58
58
|
* @param {*} dataList:数据源
|
|
59
59
|
* @return {*}
|
|
60
60
|
*/
|
|
61
|
-
export declare const syncLoop: (dataList: any[], callback: SyncLoopCallBack) => Promise<string>;
|
|
61
|
+
export declare const syncLoop: (dataList: any[], callback: SyncLoopCallBack) => Promise<string>;
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @description: 对11位手机号码加*
|
|
66
|
+
* @return {*}
|
|
67
|
+
*/
|
|
68
|
+
export declare const encryptMobilePhoneNumber: (text: string) => string;
|
|
69
|
+
/**
|
|
70
|
+
* @description: 判断对象
|
|
71
|
+
* @return {*}
|
|
72
|
+
*/
|
|
73
|
+
export declare const isObject: (exp: any) => boolean;
|
|
74
|
+
export declare const isArray: (exp: any) => boolean;
|
|
75
|
+
export declare const isString: (exp: any) => boolean;
|
|
76
|
+
export declare const isNumber: (exp: any) => boolean;
|
|
77
|
+
export declare const isNull: (exp: any) => boolean;
|
|
78
|
+
export declare const isNullObject: (obj: any) => boolean;
|
|
79
|
+
export declare const isUndefined: (exp: any) => boolean;
|
|
80
|
+
export declare const isObjectValueEqual: (a: any, b: any) => boolean;
|
|
81
|
+
export declare const deepEqual: (x: any, y: any) => boolean;
|
|
82
|
+
export declare function deepClone(target: any): any;
|
|
83
|
+
export declare const isPhoneNumber: (str: string) => boolean;
|
|
84
|
+
export declare const toDateFriendly: (dateStr: string) => string;
|
|
85
|
+
export declare const isChainChar: (str: string) => boolean;
|
|
86
|
+
export declare const isHaveChartCount: (str: string) => number;
|
|
87
|
+
export declare const isHaveNumberCount: (str: string) => number;
|
|
88
|
+
export declare const isHaveChinese: (text: string) => boolean;
|
|
89
|
+
export declare const isHaveEmojiCharact: (substring: string) => boolean;
|
package/utils/lazy.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* @Author: shiguo
|
|
3
3
|
* @Date: 2022-04-27 18:17:54
|
|
4
4
|
* @LastEditors: shiguo
|
|
5
|
-
* @LastEditTime: 2022-
|
|
6
|
-
* @FilePath: /@aks/easyui/utils/lazy.
|
|
5
|
+
* @LastEditTime: 2022-07-11 15:59:49
|
|
6
|
+
* @FilePath: /@aks-dev/easyui/utils/lazy.ts
|
|
7
7
|
*/
|
|
8
8
|
import type { SyncLoopCallBack } from '.'
|
|
9
9
|
|
|
@@ -37,4 +37,284 @@ export const syncLoop = async (dataList: any[], callback: SyncLoopCallBack) => {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
return Promise.resolve('SyncForeach loop over')
|
|
40
|
-
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
export const encryptMobilePhoneNumber = (text: string) => {
|
|
45
|
+
if (text && text.length == 11) {
|
|
46
|
+
let y1 = text.slice(0, 3);
|
|
47
|
+
let y2 = text.slice(7);
|
|
48
|
+
return y1 + '****' + y2
|
|
49
|
+
}
|
|
50
|
+
return text;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//判断是否为对象(仅为对象,不是数组也不是null)
|
|
54
|
+
export const isObject = (exp: any) => {
|
|
55
|
+
return Object.prototype.toString.call(exp) == '[object Object]'
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//判断是否为数组(仅为数组,不是对象也不是null)
|
|
59
|
+
export const isArray = (exp: any) => {
|
|
60
|
+
return Object.prototype.toString.call(exp) == '[object Array]'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//判断是否为字符串
|
|
64
|
+
export const isString = (exp: any) => {
|
|
65
|
+
return Object.prototype.toString.call(exp) == '[object String]'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//判断是否为数字(包括整数和实数)
|
|
69
|
+
export const isNumber = (exp: any) => {
|
|
70
|
+
return Object.prototype.toString.call(exp) == '[object Number]'
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//判断是否为null
|
|
74
|
+
export const isNull = (exp: any) => {
|
|
75
|
+
return Object.prototype.toString.call(exp) == '[object Null]'
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//判断是否为空对象
|
|
79
|
+
export const isNullObject = (obj: any) => {
|
|
80
|
+
if (obj == null || obj == undefined)
|
|
81
|
+
return true;
|
|
82
|
+
|
|
83
|
+
if (Object.keys(obj).length > 0) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//判断是否为undefined
|
|
91
|
+
export const isUndefined = (exp: any) => {
|
|
92
|
+
return Object.prototype.toString.call(exp) == '[object Undefined]'
|
|
93
|
+
}
|
|
94
|
+
/**判断两个对象是否相同 */
|
|
95
|
+
export const isObjectValueEqual = (a: any, b: any) => {
|
|
96
|
+
// Object.getOwnPropertyNames()方法返回一个由指定对象的所有自身属性的属性名(包括不可枚举属性但不包括Symbol值作为名称的属性)组成的数组
|
|
97
|
+
// 换句话来说 Object.getOwnPropertyNames()方法返回的是对象所有 key 组成的数组 list
|
|
98
|
+
let aProps = Object.getOwnPropertyNames(a)
|
|
99
|
+
let bProps = Object.getOwnPropertyNames(b)
|
|
100
|
+
if (aProps.length != bProps.length) {
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
for (let i = 0; i < aProps.length; i++) {
|
|
105
|
+
let propName = aProps[i]
|
|
106
|
+
if (typeof a[propName] === 'object') {
|
|
107
|
+
let judge = isObjectValueEqual(a[propName], b[propName])
|
|
108
|
+
if (!judge) {
|
|
109
|
+
return false
|
|
110
|
+
}
|
|
111
|
+
} else if (a[propName] !== b[propName]) {
|
|
112
|
+
return false
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return true
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const deepEqual = (x: any, y: any) => {
|
|
119
|
+
let prototype_x = Object.prototype.toString.call(x)
|
|
120
|
+
let prototype_y = Object.prototype.toString.call(y)
|
|
121
|
+
|
|
122
|
+
if (prototype_x == '[object Undefined]') {
|
|
123
|
+
prototype_x = '[object Null]'
|
|
124
|
+
}
|
|
125
|
+
if (prototype_y == '[object Undefined]') {
|
|
126
|
+
prototype_y = '[object Null]'
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (prototype_x != prototype_y) {
|
|
130
|
+
return false
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**以下类型相同比较 */
|
|
134
|
+
if (prototype_x == '[object Object]') {
|
|
135
|
+
if (Object.keys(x).length != Object.keys(y).length) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
for (var key in x) {
|
|
140
|
+
if (!deepEqual(x[key], y[key])) {
|
|
141
|
+
return false
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} else if (prototype_x == '[object Array]') {
|
|
145
|
+
if (x.length != y.length) {
|
|
146
|
+
return false
|
|
147
|
+
}
|
|
148
|
+
for (let index = 0; index < x.length; index++) {
|
|
149
|
+
if (!deepEqual(x[index], y[index])) {
|
|
150
|
+
return false
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**过滤对函数的深比较 */
|
|
156
|
+
else if (prototype_x == '[object Function]') {
|
|
157
|
+
return true
|
|
158
|
+
} else {
|
|
159
|
+
/**其它类型值比较 */
|
|
160
|
+
return x == y
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return true
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 定义一个深拷贝函数 接收目标target参数
|
|
167
|
+
export function deepClone(target: any): any {
|
|
168
|
+
// 定义一个变量
|
|
169
|
+
let result: any;
|
|
170
|
+
// 如果当前需要深拷贝的是一个对象的话
|
|
171
|
+
if (typeof target === 'object') {
|
|
172
|
+
// 如果是一个数组的话
|
|
173
|
+
if (Array.isArray(target)) {
|
|
174
|
+
result = []; // 将result赋值为一个数组,并且执行遍历
|
|
175
|
+
for (let i in target) {
|
|
176
|
+
// 递归克隆数组中的每一项
|
|
177
|
+
result.push(deepClone(target[i]))
|
|
178
|
+
}
|
|
179
|
+
// 判断如果当前的值是null的话;直接赋值为null
|
|
180
|
+
} else if (target === null) {
|
|
181
|
+
result = null;
|
|
182
|
+
// 判断如果当前的值是一个RegExp对象的话,直接赋值
|
|
183
|
+
} else if (target.constructor === RegExp) {
|
|
184
|
+
result = target;
|
|
185
|
+
} else {
|
|
186
|
+
// 否则是普通对象,直接for in循环,递归赋值对象的所有值
|
|
187
|
+
result = {};
|
|
188
|
+
for (let i in target) {
|
|
189
|
+
result[i] = deepClone(target[i]);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// 如果不是对象的话,就是基本数据类型,那么直接赋值
|
|
193
|
+
} else {
|
|
194
|
+
result = target;
|
|
195
|
+
}
|
|
196
|
+
// 返回最终结果
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export const isPhoneNumber = (str: string) => {
|
|
201
|
+
var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
|
|
202
|
+
if (!myreg.test(str)) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
*
|
|
212
|
+
* @param dateStr yyyy-MM-dd HH:mm:ss
|
|
213
|
+
* @returns {string}
|
|
214
|
+
*/
|
|
215
|
+
export const toDateFriendly = (dateStr: string) => {
|
|
216
|
+
//af-测试可用
|
|
217
|
+
if (!dateStr) {
|
|
218
|
+
return ''
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
let dateTimeStamp = Date.parse(dateStr.replace(/-/gi, "/"));
|
|
222
|
+
let minute = 1000 * 60;
|
|
223
|
+
let hour = minute * 60;
|
|
224
|
+
let day = hour * 24;
|
|
225
|
+
let halfamonth = day * 15;
|
|
226
|
+
let month = day * 30;
|
|
227
|
+
let now = new Date().getTime();
|
|
228
|
+
let diffValue = now - dateTimeStamp;
|
|
229
|
+
if (diffValue < 0) {
|
|
230
|
+
return '';
|
|
231
|
+
}
|
|
232
|
+
let monthC = diffValue / month;
|
|
233
|
+
let weekC = diffValue / (7 * day);
|
|
234
|
+
let dayC = diffValue / day;
|
|
235
|
+
let hourC = diffValue / hour;
|
|
236
|
+
let minC = diffValue / minute;
|
|
237
|
+
let result = '';
|
|
238
|
+
if (monthC >= 1) {
|
|
239
|
+
result = "" + parseInt(monthC.toString()) + "月前";
|
|
240
|
+
} else if (weekC >= 1) {
|
|
241
|
+
result = "" + parseInt(weekC.toString()) + "周前";
|
|
242
|
+
} else if (dayC >= 1) {
|
|
243
|
+
result = "" + parseInt(dayC.toString()) + "天前";
|
|
244
|
+
} else if (hourC >= 1) {
|
|
245
|
+
result = "" + parseInt(hourC.toString()) + "小时前";
|
|
246
|
+
} else if (minC >= 1) {
|
|
247
|
+
result = "" + parseInt(minC.toString()) + "分钟前";
|
|
248
|
+
} else
|
|
249
|
+
result = "刚刚";
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export const isChainChar = (str: string) => {
|
|
254
|
+
var index = escape(str).indexOf("%u");
|
|
255
|
+
if (index < 0)
|
|
256
|
+
return false;
|
|
257
|
+
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export const isHaveChartCount = (str: string) => {
|
|
262
|
+
if (/[a-z]/i.test(str)) {
|
|
263
|
+
return str.match(/[a-z]/ig)?.length;
|
|
264
|
+
}
|
|
265
|
+
return 0;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export const isHaveNumberCount = (str: string) => {
|
|
269
|
+
if (/[0-9]/i.test(str)) {
|
|
270
|
+
return str.match(/[0-9]/ig)?.length;
|
|
271
|
+
}
|
|
272
|
+
return 0;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
export const isHaveChinese = (text: string) => {
|
|
278
|
+
var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
|
|
279
|
+
if (reg.test(text)) {
|
|
280
|
+
return true;
|
|
281
|
+
} else {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
export const isHaveEmojiCharact = (substring: string) => {
|
|
286
|
+
for (var i = 0; i < substring.length; i++) {
|
|
287
|
+
var hs = substring.charCodeAt(i);
|
|
288
|
+
if (0xd800 <= hs && hs <= 0xdbff) {
|
|
289
|
+
if (substring.length > 1) {
|
|
290
|
+
var ls = substring.charCodeAt(i + 1);
|
|
291
|
+
var uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
|
|
292
|
+
if (0x1d000 <= uc && uc <= 0x1f77f) {
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
} else if (substring.length > 1) {
|
|
298
|
+
var ls = substring.charCodeAt(i + 1);
|
|
299
|
+
if (ls == 0x20e3) {
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
} else {
|
|
303
|
+
if (0x2100 <= hs && hs <= 0x27ff) {
|
|
304
|
+
return true;
|
|
305
|
+
} else if (0x2B05 <= hs && hs <= 0x2b07) {
|
|
306
|
+
return true;
|
|
307
|
+
} else if (0x2934 <= hs && hs <= 0x2935) {
|
|
308
|
+
return true;
|
|
309
|
+
} else if (0x3297 <= hs && hs <= 0x3299) {
|
|
310
|
+
return true;
|
|
311
|
+
} else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030
|
|
312
|
+
|| hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b
|
|
313
|
+
|| hs == 0x2b50) {
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return false
|
|
320
|
+
}
|