Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
WebPublic
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
前端开发小组
WebPublic
Commits
0862669d
提交
0862669d
authored
2月 21, 2022
作者:
钟是志
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
解决安全漏洞问题. 保证用户输入的新密码至少包含数字和字符 且不少于8位
上级
2e9a8cd2
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
214 行增加
和
183 行删除
+214
-183
utils.js
zyd_public/utils/utils.js
+214
-183
没有找到文件。
zyd_public/utils/utils.js
浏览文件 @
0862669d
...
@@ -2,99 +2,99 @@
...
@@ -2,99 +2,99 @@
* 一站式正在使用此文件
* 一站式正在使用此文件
* 请谨慎使用
* 请谨慎使用
* */
* */
import
React
from
'react'
;
import
React
from
"react"
;
import
moment
from
'moment'
;
import
moment
from
"moment"
;
import
{
Icon
,
message
,
notification
}
from
'antd'
;
import
{
Icon
,
message
,
notification
}
from
"antd"
;
import
{
getOnestopKey
}
from
'../../Services'
;
import
{
getOnestopKey
}
from
"../../Services"
;
import
FormdataWrapper
from
'./object-to-formdata-custom'
;
import
FormdataWrapper
from
"./object-to-formdata-custom"
;
let
messageTime
=
new
Date
().
getTime
()
-
3000
;
let
messageTime
=
new
Date
().
getTime
()
-
3000
;
/**
/**
* 校验 开始时间必须在结束时间之前的函数
* 校验 开始时间必须在结束时间之前的函数
* */
* */
export
function
checkDate
(
endTime
=
'2019-01-01'
,
startTime
=
'2018-12-31'
)
{
export
function
checkDate
(
endTime
=
"2019-01-01"
,
startTime
=
"2018-12-31"
)
{
return
moment
(
endTime
).
isAfter
(
moment
(
startTime
));
return
moment
(
endTime
).
isAfter
(
moment
(
startTime
));
}
}
/**
/**
* 去除字符串中的所有html 标签
* 去除字符串中的所有html 标签
* */
* */
export
function
matchReg
(
str
)
{
export
function
matchReg
(
str
)
{
let
reg
=
/<
\/?
.+
?\/?
>/g
;
let
reg
=
/<
\/?
.+
?\/?
>/g
;
return
str
.
replace
(
reg
,
''
).
replace
(
/ /g
,
' '
);
return
str
.
replace
(
reg
,
""
).
replace
(
/ /g
,
" "
);
}
}
export
function
htmlFormat
(
str
)
{
export
function
htmlFormat
(
str
)
{
if
(
typeof
str
!==
'string'
)
{
if
(
typeof
str
!==
"string"
)
{
return
''
;
return
""
;
}
}
const
newTxt
=
str
.
replace
(
/
\s
+
([^
<>
]
+
)(?=
<
)
/g
,
function
(
match
)
{
const
newTxt
=
str
.
replace
(
/
\s
+
([^
<>
]
+
)(?=
<
)
/g
,
function
(
match
)
{
return
match
.
replace
(
/
\s
/g
,
' '
);
return
match
.
replace
(
/
\s
/g
,
" "
);
});
});
return
newTxt
;
return
newTxt
;
}
}
export
function
countSpecialField
(
filedSpanBig
,
nameSpanBig
)
{
export
function
countSpecialField
(
filedSpanBig
,
nameSpanBig
)
{
let
style
=
{};
let
style
=
{};
if
(
document
.
body
.
clientWidth
>
1400
)
{
if
(
document
.
body
.
clientWidth
>
1400
)
{
if
(
filedSpanBig
===
5
)
{
if
(
filedSpanBig
===
5
)
{
// 当设置一行排列5个字段时 自定义宽度为20%
// 当设置一行排列5个字段时 自定义宽度为20%
style
=
{
width
:
'20%'
};
style
=
{
width
:
"20%"
};
}
}
if
(
filedSpanBig
===
1
&&
nameSpanBig
===
2
)
{
if
(
filedSpanBig
===
1
&&
nameSpanBig
===
2
)
{
// 当一行显示一个字段 然后名字又特别长时 使用这个width
// 当一行显示一个字段 然后名字又特别长时 使用这个width
style
=
{
width
:
'6%'
};
style
=
{
width
:
"6%"
};
}
}
}
}
return
style
;
return
style
;
}
}
/**
/**
* 深拷贝函数
* 深拷贝函数
* */
* */
export
function
deepCopy
(
obj
,
parent
=
null
)
{
export
function
deepCopy
(
obj
,
parent
=
null
)
{
if
(
React
.
isValidElement
(
obj
))
{
if
(
React
.
isValidElement
(
obj
))
{
return
React
.
cloneElement
(
obj
);
return
React
.
cloneElement
(
obj
);
}
}
if
([
'boolean'
,
'string'
,
'number'
].
indexOf
(
typeof
obj
)
>
-
1
||
!
obj
)
{
if
([
"boolean"
,
"string"
,
"number"
].
indexOf
(
typeof
obj
)
>
-
1
||
!
obj
)
{
return
obj
;
return
obj
;
}
}
let
result
;
let
result
;
if
(
obj
.
constructor
===
Array
)
{
if
(
obj
.
constructor
===
Array
)
{
result
=
[];
result
=
[];
}
else
{
}
else
{
result
=
{};
result
=
{};
}
}
let
keys
=
Object
.
keys
(
obj
),
let
keys
=
Object
.
keys
(
obj
),
key
=
null
,
key
=
null
,
temp
=
null
,
temp
=
null
,
_parent
=
parent
;
_parent
=
parent
;
// 该字段有父级则需要追溯该字段的父级
// 该字段有父级则需要追溯该字段的父级
while
(
_parent
)
{
while
(
_parent
)
{
// 如果该字段引用了它的父级则为循环引用
// 如果该字段引用了它的父级则为循环引用
if
(
_parent
.
originalParent
===
obj
)
{
if
(
_parent
.
originalParent
===
obj
)
{
// 循环引用直接返回同级的新对象
// 循环引用直接返回同级的新对象
return
_parent
.
currentParent
;
return
_parent
.
currentParent
;
}
}
_parent
=
_parent
.
parent
;
_parent
=
_parent
.
parent
;
}
}
for
(
let
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
key
=
keys
[
i
];
key
=
keys
[
i
];
temp
=
obj
[
key
];
temp
=
obj
[
key
];
// 如果字段的值也是一个对象
// 如果字段的值也是一个对象
if
(
temp
&&
typeof
temp
===
'object'
)
{
if
(
temp
&&
typeof
temp
===
"object"
)
{
// 递归执行深拷贝 将同级的待拷贝对象与新对象传递给 parent 方便追溯循环引用
// 递归执行深拷贝 将同级的待拷贝对象与新对象传递给 parent 方便追溯循环引用
result
[
key
]
=
deepCopy
(
temp
,
{
result
[
key
]
=
deepCopy
(
temp
,
{
originalParent
:
obj
,
originalParent
:
obj
,
currentParent
:
result
,
currentParent
:
result
,
parent
:
parent
,
parent
:
parent
});
});
}
else
{
}
else
{
result
[
key
]
=
temp
;
result
[
key
]
=
temp
;
}
}
}
}
return
result
;
return
result
;
}
}
/**
/**
...
@@ -105,76 +105,76 @@ export function deepCopy(obj, parent = null) {
...
@@ -105,76 +105,76 @@ export function deepCopy(obj, parent = null) {
* @returns {*|boolean}
* @returns {*|boolean}
*/
*/
export
function
getFormElemValue
(
type
,
e
,
other
)
{
export
function
getFormElemValue
(
type
,
e
,
other
)
{
let
value
=
e
;
let
value
=
e
;
switch
(
type
)
{
switch
(
type
)
{
case
'input'
:
case
"input"
:
value
=
e
.
target
.
value
;
value
=
e
.
target
.
value
;
break
;
break
;
case
'checkbox'
:
case
"checkbox"
:
value
=
e
.
target
.
checked
;
value
=
e
.
target
.
checked
;
break
;
break
;
case
'textarea'
:
case
"textarea"
:
value
=
e
.
target
.
value
;
value
=
e
.
target
.
value
;
break
;
break
;
case
'buttonUpload'
:
case
"buttonUpload"
:
value
=
e
.
url
;
value
=
e
.
url
;
break
;
break
;
case
'upload'
:
case
"upload"
:
value
=
Array
.
isArray
(
e
)
?
e
.
join
(
','
)
:
''
;
value
=
Array
.
isArray
(
e
)
?
e
.
join
(
","
)
:
""
;
break
;
break
;
default
:
default
:
break
;
break
;
}
}
return
value
;
return
value
;
}
}
/**
/**
* 生成随机字符串
* 生成随机字符串
* */
* */
export
function
randomStr
()
{
export
function
randomStr
()
{
return
Math
.
random
()
return
Math
.
random
()
.
toString
(
36
)
.
toString
(
36
)
.
substr
(
2
);
.
substr
(
2
);
}
}
export
function
isJSON
(
str
)
{
export
function
isJSON
(
str
)
{
if
(
typeof
str
==
'string'
)
{
if
(
typeof
str
==
"string"
)
{
try
{
try
{
JSON
.
parse
(
str
);
JSON
.
parse
(
str
);
if
(
typeof
JSON
.
parse
(
str
)
===
'number'
)
{
if
(
typeof
JSON
.
parse
(
str
)
===
"number"
)
{
return
false
;
return
false
;
}
}
return
true
;
return
true
;
}
catch
(
e
)
{
}
catch
(
e
)
{
return
false
;
return
false
;
}
}
}
}
}
}
export
function
checkMustHaveValue
(
configFileds
,
data
)
{
export
function
checkMustHaveValue
(
configFileds
,
data
)
{
for
(
let
item
of
configFileds
)
{
for
(
let
item
of
configFileds
)
{
if
(
!
data
[
item
.
key
]
&&
data
[
item
.
key
]
!==
false
&&
data
[
item
.
key
]
!==
0
)
{
if
(
!
data
[
item
.
key
]
&&
data
[
item
.
key
]
!==
false
&&
data
[
item
.
key
]
!==
0
)
{
return
false
;
return
false
;
}
}
}
}
return
true
;
return
true
;
}
}
export
function
mustHaveValue
(
configFields
,
data
)
{
export
function
mustHaveValue
(
configFields
,
data
)
{
for
(
let
item
of
configFields
)
{
for
(
let
item
of
configFields
)
{
if
(
!
item
.
required
)
continue
;
if
(
!
item
.
required
)
continue
;
if
(
Array
.
isArray
(
data
[
item
.
key
])
&&
data
[
item
.
key
].
length
<
1
)
{
if
(
Array
.
isArray
(
data
[
item
.
key
])
&&
data
[
item
.
key
].
length
<
1
)
{
message
.
warning
(
`
${
item
.
name
}
是必填项请填写`
);
message
.
warning
(
`
${
item
.
name
}
是必填项请填写`
);
return
false
;
return
false
;
}
}
if
(
!
data
[
item
.
key
]
&&
data
[
item
.
key
]
!==
false
&&
data
[
item
.
key
]
!==
0
)
{
if
(
!
data
[
item
.
key
]
&&
data
[
item
.
key
]
!==
false
&&
data
[
item
.
key
]
!==
0
)
{
message
.
warning
(
`
${
item
.
name
}
是必填项请填写`
);
message
.
warning
(
`
${
item
.
name
}
是必填项请填写`
);
return
false
;
return
false
;
}
}
}
}
return
true
;
return
true
;
}
}
/**
/**
...
@@ -182,88 +182,88 @@ export function mustHaveValue(configFields, data) {
...
@@ -182,88 +182,88 @@ export function mustHaveValue(configFields, data) {
* 通过数组排序,比较临近元素
* 通过数组排序,比较临近元素
* */
* */
export
function
isRepeat
(
ary
)
{
export
function
isRepeat
(
ary
)
{
if
(
ary
.
length
<=
1
)
{
if
(
ary
.
length
<=
1
)
{
return
false
;
return
false
;
}
}
let
nary
=
ary
.
sort
();
let
nary
=
ary
.
sort
();
for
(
let
i
=
0
;
i
<
ary
.
length
-
1
;
i
++
)
{
for
(
let
i
=
0
;
i
<
ary
.
length
-
1
;
i
++
)
{
if
(
nary
[
i
]
===
nary
[
i
+
1
])
{
if
(
nary
[
i
]
===
nary
[
i
+
1
])
{
return
nary
[
i
];
return
nary
[
i
];
// alert("数组重复内容:" + nary[i]);
// alert("数组重复内容:" + nary[i]);
}
}
}
}
return
false
;
return
false
;
}
}
export
function
displayRender
(
label
)
{
export
function
displayRender
(
label
)
{
if
(
label
&&
label
.
length
)
{
if
(
label
&&
label
.
length
)
{
return
label
[
label
.
length
-
1
];
return
label
[
label
.
length
-
1
];
}
else
{
}
else
{
return
''
;
return
""
;
}
}
}
}
export
function
isEmptyValue
(
value
)
{
export
function
isEmptyValue
(
value
)
{
return
typeof
value
===
'undefined'
||
value
===
null
||
value
===
''
;
return
typeof
value
===
"undefined"
||
value
===
null
||
value
===
""
;
}
}
// 全局的通知消息组件
// 全局的通知消息组件
export
function
controlNotification
(
props
)
{
export
function
controlNotification
(
props
)
{
const
nowTime
=
new
Date
().
getTime
();
const
nowTime
=
new
Date
().
getTime
();
if
(
nowTime
-
messageTime
<
3000
)
{
if
(
nowTime
-
messageTime
<
3000
)
{
return
;
return
;
}
}
messageTime
=
nowTime
;
messageTime
=
nowTime
;
notification
.
info
({
notification
.
info
({
...
props
,
...
props
,
icon
:
<
Icon
type
=
"info-circle"
style
=
{{
color
:
'#fa8c16'
}}
/>
,
icon
:
<
Icon
type
=
"info-circle"
style
=
{{
color
:
"#fa8c16"
}}
/
>
});
});
return
true
;
return
true
;
}
}
export
function
setOneStopConfig
(
value
)
{
export
function
setOneStopConfig
(
value
)
{
if
(
typeof
value
!==
'string'
)
{
if
(
typeof
value
!==
"string"
)
{
value
=
JSON
.
stringify
(
value
);
value
=
JSON
.
stringify
(
value
);
}
}
localStorage
.
setItem
(
'oneStopConfig'
,
value
);
localStorage
.
setItem
(
"oneStopConfig"
,
value
);
}
}
export
function
getOneStopConfig
(
key
)
{
export
function
getOneStopConfig
(
key
)
{
let
configList
=
localStorage
.
getItem
(
'oneStopConfig'
);
let
configList
=
localStorage
.
getItem
(
"oneStopConfig"
);
if
(
configList
&&
isJSON
(
configList
))
{
if
(
configList
&&
isJSON
(
configList
))
{
let
data
=
JSON
.
parse
(
configList
);
let
data
=
JSON
.
parse
(
configList
);
if
(
data
&&
typeof
data
===
'object'
)
{
if
(
data
&&
typeof
data
===
"object"
)
{
if
(
typeof
data
===
'undefined'
)
{
if
(
typeof
data
===
"undefined"
)
{
return
''
;
return
""
;
}
}
return
data
[
key
]
||
false
;
return
data
[
key
]
||
false
;
}
}
}
else
{
}
else
{
return
getOnestopKey
(
key
);
return
getOnestopKey
(
key
);
}
}
}
}
export
function
diGuiTree
(
treeData
=
[],
i
=
0
)
{
export
function
diGuiTree
(
treeData
=
[],
i
=
0
)
{
// for (let item of treeData) {
// for (let item of treeData) {
// if(i === 2){
// if(i === 2){
// item.selectable = true;
// item.selectable = true;
// }
// }
// if (item.children && item.children.length) {
// if (item.children && item.children.length) {
// i += 1;
// i += 1;
// diGuiTree(item.children, i);
// diGuiTree(item.children, i);
// }
// }
// }
// }
return
treeData
;
return
treeData
;
}
}
export
function
downloadFile
(
url
,
params
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
)
{
export
function
downloadFile
(
url
,
params
,
fileName
=
"导出文件"
,
ext
=
"xlsx"
)
{
fetch
(
url
,
{
fetch
(
url
,
{
method
:
'POST'
,
method
:
"POST"
,
body
:
FormdataWrapper
(
params
)
,
body
:
FormdataWrapper
(
params
)
})
})
.
then
((
res
)
=>
{
.
then
((
res
)
=>
{
if
(
res
.
status
+
''
!==
'200'
)
{
if
(
res
.
status
+
""
!==
"200"
)
{
return
res
.
json
();
return
res
.
json
();
}
else
{
}
else
{
return
res
.
blob
();
return
res
.
blob
();
...
@@ -271,9 +271,9 @@ export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx
...
@@ -271,9 +271,9 @@ export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx
})
})
.
then
((
data
)
=>
{
.
then
((
data
)
=>
{
if
(
data
instanceof
Blob
)
{
if
(
data
instanceof
Blob
)
{
let
a
=
document
.
createElement
(
'a'
);
let
a
=
document
.
createElement
(
"a"
);
let
url
=
window
.
URL
.
createObjectURL
(
data
);
let
url
=
window
.
URL
.
createObjectURL
(
data
);
let
filename
=
fileName
+
'.'
+
ext
;
let
filename
=
fileName
+
"."
+
ext
;
a
.
href
=
url
;
a
.
href
=
url
;
a
.
download
=
filename
;
a
.
download
=
filename
;
a
.
click
();
a
.
click
();
...
@@ -282,16 +282,47 @@ export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx
...
@@ -282,16 +282,47 @@ export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx
}
else
{
}
else
{
notification
.
error
({
notification
.
error
({
message
:
`文件导出错误`
,
message
:
`文件导出错误`
,
description
:
data
.
errMsg
,
description
:
data
.
errMsg
});
});
}
}
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
notification
.
error
({
notification
.
error
({
message
:
`网络请求超时`
,
message
:
`网络请求超时`
});
});
})
})
.
finally
(()
=>
{
.
finally
(()
=>
{
return
true
;
return
true
;
});
});
}
}
export
default
function
CheckPassWord
(
password
=
""
)
{
console
.
log
(
password
);
if
(
!
password
||
password
.
length
<
8
)
{
// message.warning("密码过于简单, 请输入不小于8位的密码 且必须包含数字和字母!");
console
.
log
(
'位数不够'
);
return
false
;
}
let
includeNumber
=
false
;
let
includeWord
=
false
;
for
(
let
i
=
0
;
i
<=
password
.
length
;
i
++
)
{
let
iN
=
password
.
charCodeAt
(
i
);
//数字
if
(
iN
>=
48
&&
iN
<=
57
)
{
includeNumber
=
true
;
}
// 大写 // 小写
if
((
iN
>=
65
&&
iN
<=
90
)
||
(
iN
>=
97
&&
iN
<=
122
))
{
includeWord
=
true
;
}
if
(
includeWord
&&
includeNumber
){
return
true
;
}
}
if
(
includeWord
&&
includeNumber
){
}
else
{
// message.warning("密码过于简单, 请输入不小于8位的密码 且必须包含数字和字母!");
return
false
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论